aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2010-02-28 22:23:06 -0500
committerDavid S. Miller <davem@davemloft.net>2010-02-28 22:23:06 -0500
commit47871889c601d8199c51a4086f77eebd77c29b0b (patch)
tree40cdcac3bff0ee40cc33dcca61d0577cdf965f77 /drivers
parentc16cc0b464b8876cfd57ce1c1dbcb6f9a6a0bce3 (diff)
parent30ff056c42c665b9ea535d8515890857ae382540 (diff)
Merge branch 'master' of /home/davem/src/GIT/linux-2.6/
Conflicts: drivers/firmware/iscsi_ibft.c
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/acpica/acevents.h10
-rw-r--r--drivers/acpi/acpica/aclocal.h2
-rw-r--r--drivers/acpi/acpica/acobject.h2
-rw-r--r--drivers/acpi/acpica/evgpe.c161
-rw-r--r--drivers/acpi/acpica/evgpeblk.c87
-rw-r--r--drivers/acpi/acpica/evmisc.c12
-rw-r--r--drivers/acpi/acpica/evxface.c189
-rw-r--r--drivers/acpi/acpica/evxfevnt.c96
-rw-r--r--drivers/acpi/button.c15
-rw-r--r--drivers/acpi/dock.c1
-rw-r--r--drivers/acpi/ec.c28
-rw-r--r--drivers/acpi/internal.h2
-rw-r--r--drivers/acpi/pci_bind.c14
-rw-r--r--drivers/acpi/pci_root.c9
-rw-r--r--drivers/acpi/processor_idle.c36
-rw-r--r--drivers/acpi/processor_pdc.c14
-rw-r--r--drivers/acpi/processor_perflib.c6
-rw-r--r--drivers/acpi/scan.c65
-rw-r--r--drivers/acpi/sleep.c15
-rw-r--r--drivers/acpi/system.c4
-rw-r--r--drivers/acpi/tables.c4
-rw-r--r--drivers/acpi/wakeup.c84
-rw-r--r--drivers/ata/ahci.c12
-rw-r--r--drivers/base/power/main.c143
-rw-r--r--drivers/base/power/power.h6
-rw-r--r--drivers/base/power/runtime.c45
-rw-r--r--drivers/base/power/sysfs.c100
-rw-r--r--drivers/block/ataflop.c2
-rw-r--r--drivers/block/swim.c4
-rw-r--r--drivers/block/viodasd.c86
-rw-r--r--drivers/block/virtio_blk.c61
-rw-r--r--drivers/char/Kconfig8
-rw-r--r--drivers/char/agp/intel-agp.c15
-rw-r--r--drivers/char/hvc_beat.c4
-rw-r--r--drivers/char/hvc_console.c9
-rw-r--r--drivers/char/hvc_console.h9
-rw-r--r--drivers/char/hvc_iseries.c2
-rw-r--r--drivers/char/hvc_iucv.c2
-rw-r--r--drivers/char/hvc_rtas.c2
-rw-r--r--drivers/char/hvc_udbg.c2
-rw-r--r--drivers/char/hvc_vio.c2
-rw-r--r--drivers/char/hvc_xen.c2
-rw-r--r--drivers/char/hw_random/Kconfig12
-rw-r--r--drivers/char/hw_random/Makefile1
-rw-r--r--drivers/char/hw_random/nomadik-rng.c103
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c2
-rw-r--r--drivers/char/virtio_console.c1578
-rw-r--r--drivers/char/vme_scc.c12
-rw-r--r--drivers/clocksource/cs5535-clockevt.c2
-rw-r--r--drivers/clocksource/sh_cmt.c32
-rw-r--r--drivers/clocksource/sh_mtu2.c6
-rw-r--r--drivers/clocksource/sh_tmu.c6
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.c2
-rw-r--r--drivers/crypto/geode-aes.c8
-rw-r--r--drivers/crypto/talitos.c2
-rw-r--r--drivers/dma/shdma.c411
-rw-r--r--drivers/dma/shdma.h7
-rw-r--r--drivers/firmware/iscsi_ibft.c8
-rw-r--r--drivers/gpu/drm/drm_edid.c47
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c30
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c7
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.c7
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_bios.h2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.h1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_mem.c113
-rw-r--r--drivers/gpu/drm/nouveau/nv04_dac.c6
-rw-r--r--drivers/gpu/drm/nouveau/nv17_tv.c2
-rw-r--r--drivers/gpu/drm/nouveau/nv50_instmem.c58
-rw-r--r--drivers/gpu/drm/radeon/atom.c2
-rw-r--r--drivers/gpu/drm/radeon/r600_blit_kms.c3
-rw-r--r--drivers/gpu/drm/radeon/r600_cp.c9
-rw-r--r--drivers/gpu/drm/radeon/radeon.h9
-rw-r--r--drivers/gpu/drm/radeon/radeon_atombios.c9
-rw-r--r--drivers/gpu/drm/radeon/radeon_combios.c44
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c5
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c10
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.h3
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c36
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.h4
-rw-r--r--drivers/gpu/drm/radeon/radeon_ring.c107
-rw-r--r--drivers/gpu/drm/radeon/rv770.c9
-rw-r--r--drivers/gpu/drm/ttm/ttm_tt.c18
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c49
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c108
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_fb.c3
-rw-r--r--drivers/gpu/vga/Kconfig8
-rw-r--r--drivers/gpu/vga/vgaarb.c29
-rw-r--r--drivers/hid/Kconfig54
-rw-r--r--drivers/hid/Makefile9
-rw-r--r--drivers/hid/hid-3m-pct.c290
-rw-r--r--drivers/hid/hid-apple.c17
-rw-r--r--drivers/hid/hid-core.c23
-rw-r--r--drivers/hid/hid-debug.c6
-rw-r--r--drivers/hid/hid-ids.h37
-rw-r--r--drivers/hid/hid-input.c12
-rw-r--r--drivers/hid/hid-lg.c7
-rw-r--r--drivers/hid/hid-lg.h6
-rw-r--r--drivers/hid/hid-lg3ff.c176
-rw-r--r--drivers/hid/hid-lgff.c1
-rw-r--r--drivers/hid/hid-magicmouse.c449
-rw-r--r--drivers/hid/hid-mosart.c273
-rw-r--r--drivers/hid/hid-ntrig.c212
-rw-r--r--drivers/hid/hid-ortek.c56
-rw-r--r--drivers/hid/hid-quanta.c260
-rw-r--r--drivers/hid/hid-sony.c23
-rw-r--r--drivers/hid/hid-stantum.c283
-rw-r--r--drivers/hid/hid-wacom.c28
-rw-r--r--drivers/hid/hidraw.c2
-rw-r--r--drivers/hid/usbhid/hid-core.c42
-rw-r--r--drivers/hid/usbhid/hid-quirks.c3
-rw-r--r--drivers/hid/usbhid/usbhid.h2
-rw-r--r--drivers/hwmon/ams/ams-core.c11
-rw-r--r--drivers/hwmon/ams/ams-i2c.c2
-rw-r--r--drivers/hwmon/ams/ams-pmu.c2
-rw-r--r--drivers/hwmon/ams/ams.h1
-rw-r--r--drivers/i2c/busses/Kconfig10
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-octeon.c651
-rw-r--r--drivers/ide/au1xxx-ide.c21
-rw-r--r--drivers/input/input-polldev.c6
-rw-r--r--drivers/input/serio/i8042.c8
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c8
-rw-r--r--drivers/isdn/hisax/Kconfig18
-rw-r--r--drivers/isdn/hisax/avm_pci.c6
-rw-r--r--drivers/isdn/hisax/bkm_a4t.c2
-rw-r--r--drivers/isdn/hisax/bkm_a8.c2
-rw-r--r--drivers/isdn/hisax/diva.c14
-rw-r--r--drivers/isdn/hisax/elsa.c8
-rw-r--r--drivers/isdn/hisax/enternow_pci.c2
-rw-r--r--drivers/isdn/hisax/gazel.c8
-rw-r--r--drivers/isdn/hisax/hfc_pci.c2
-rw-r--r--drivers/isdn/hisax/hisax.h23
-rw-r--r--drivers/isdn/hisax/niccy.c6
-rw-r--r--drivers/isdn/hisax/nj_s.c2
-rw-r--r--drivers/isdn/hisax/nj_u.c2
-rw-r--r--drivers/isdn/hisax/sedlbauer.c6
-rw-r--r--drivers/isdn/hisax/telespci.c2
-rw-r--r--drivers/isdn/hisax/w6692.c2
-rw-r--r--drivers/macintosh/adb.c10
-rw-r--r--drivers/macintosh/therm_adt746x.c36
-rw-r--r--drivers/macintosh/therm_pm72.c8
-rw-r--r--drivers/macintosh/therm_windtunnel.c2
-rw-r--r--drivers/macintosh/via-cuda.c74
-rw-r--r--drivers/macintosh/via-pmu-backlight.c8
-rw-r--r--drivers/macintosh/via-pmu.c8
-rw-r--r--drivers/macintosh/windfarm_core.c6
-rw-r--r--drivers/macintosh/windfarm_cpufreq_clamp.c6
-rw-r--r--drivers/macintosh/windfarm_lm75_sensor.c6
-rw-r--r--drivers/macintosh/windfarm_max6690_sensor.c6
-rw-r--r--drivers/macintosh/windfarm_pm112.c2
-rw-r--r--drivers/macintosh/windfarm_pm121.c2
-rw-r--r--drivers/macintosh/windfarm_pm81.c4
-rw-r--r--drivers/macintosh/windfarm_pm91.c2
-rw-r--r--drivers/macintosh/windfarm_smu_sensors.c6
-rw-r--r--drivers/media/IR/Makefile2
-rw-r--r--drivers/media/IR/ir-functions.c2
-rw-r--r--drivers/media/IR/ir-keymaps.c99
-rw-r--r--drivers/media/IR/ir-keytable.c61
-rw-r--r--drivers/media/IR/ir-sysfs.c211
-rw-r--r--drivers/media/common/saa7146_fops.c11
-rw-r--r--drivers/media/common/tuners/tuner-types.c21
-rw-r--r--drivers/media/common/tuners/tuner-xc2028.c79
-rw-r--r--drivers/media/dvb/Kconfig4
-rw-r--r--drivers/media/dvb/Makefile3
-rw-r--r--drivers/media/dvb/bt8xx/bt878.c21
-rw-r--r--drivers/media/dvb/bt8xx/dst.c12
-rw-r--r--drivers/media/dvb/dm1105/Kconfig1
-rw-r--r--drivers/media/dvb/dm1105/dm1105.c505
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c12
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c1
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ringbuffer.c1
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig12
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile3
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.c351
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.h1
-rw-r--r--drivers/media/dvb/dvb-usb/az6027.c1151
-rw-r--r--drivers/media/dvb/dvb-usb/az6027.h14
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c3
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h1
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c197
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c160
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h9
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c1
-rw-r--r--drivers/media/dvb/dvb-usb/dw2102.c95
-rw-r--r--drivers/media/dvb/dvb-usb/friio-fe.c2
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.c141
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.h2
-rw-r--r--drivers/media/dvb/dvb-usb/opera1.c2
-rw-r--r--drivers/media/dvb/firewire/firedtv-1394.c19
-rw-r--r--drivers/media/dvb/firewire/firedtv-avc.c514
-rw-r--r--drivers/media/dvb/firewire/firedtv-dvb.c1
-rw-r--r--drivers/media/dvb/firewire/firedtv-fw.c2
-rw-r--r--drivers/media/dvb/firewire/firedtv.h6
-rw-r--r--drivers/media/dvb/frontends/af9013.h1
-rw-r--r--drivers/media/dvb/frontends/atbm8830.c16
-rw-r--r--drivers/media/dvb/frontends/dib0090.c2
-rw-r--r--drivers/media/dvb/frontends/dib8000.c2
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.c2
-rw-r--r--drivers/media/dvb/frontends/l64781.c4
-rw-r--r--drivers/media/dvb/frontends/lnbp21.c3
-rw-r--r--drivers/media/dvb/frontends/si21xx.c38
-rw-r--r--drivers/media/dvb/frontends/stv0900.h2
-rw-r--r--drivers/media/dvb/frontends/stv0900_core.c109
-rw-r--r--drivers/media/dvb/frontends/stv0900_priv.h11
-rw-r--r--drivers/media/dvb/frontends/stv0900_reg.h6
-rw-r--r--drivers/media/dvb/frontends/stv0900_sw.c54
-rw-r--r--drivers/media/dvb/frontends/stv090x.c486
-rw-r--r--drivers/media/dvb/frontends/stv090x.h13
-rw-r--r--drivers/media/dvb/frontends/stv090x_priv.h17
-rw-r--r--drivers/media/dvb/frontends/stv6110x.c188
-rw-r--r--drivers/media/dvb/frontends/stv6110x.h1
-rw-r--r--drivers/media/dvb/frontends/stv6110x_priv.h1
-rw-r--r--drivers/media/dvb/frontends/tda665x.c2
-rw-r--r--drivers/media/dvb/frontends/tda8261.c2
-rw-r--r--drivers/media/dvb/frontends/zl10036.c2
-rw-r--r--drivers/media/dvb/frontends/zl10039.c1
-rw-r--r--drivers/media/dvb/mantis/mantis_hif.c2
-rw-r--r--drivers/media/dvb/mantis/mantis_input.c2
-rw-r--r--drivers/media/dvb/mantis/mantis_pci.c5
-rw-r--r--drivers/media/dvb/ngene/Kconfig9
-rw-r--r--drivers/media/dvb/ngene/Makefile11
-rw-r--r--drivers/media/dvb/ngene/ngene-core.c2024
-rw-r--r--drivers/media/dvb/ngene/ngene.h859
-rw-r--r--drivers/media/dvb/siano/sms-cards.c1
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c7
-rw-r--r--drivers/media/dvb/siano/smscoreapi.h77
-rw-r--r--drivers/media/dvb/siano/smsdvb.c318
-rw-r--r--drivers/media/dvb/siano/smsir.c6
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c14
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c2
-rw-r--r--drivers/media/dvb/ttpci/budget.c4
-rw-r--r--drivers/media/radio/Kconfig23
-rw-r--r--drivers/media/radio/Makefile2
-rw-r--r--drivers/media/radio/radio-timb.c244
-rw-r--r--drivers/media/radio/saa7706h.c451
-rw-r--r--drivers/media/radio/si470x/radio-si470x-common.c2
-rw-r--r--drivers/media/radio/si470x/radio-si470x-usb.c8
-rw-r--r--drivers/media/video/Kconfig36
-rw-r--r--drivers/media/video/Makefile2
-rw-r--r--drivers/media/video/bt819.c10
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c8
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c8
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c4
-rw-r--r--drivers/media/video/bt8xx/bttvp.h1
-rw-r--r--drivers/media/video/cafe_ccic.c6
-rw-r--r--drivers/media/video/cpia.c3
-rw-r--r--drivers/media/video/cx18/Kconfig11
-rw-r--r--drivers/media/video/cx18/Makefile2
-rw-r--r--drivers/media/video/cx18/cx18-alsa-main.c293
-rw-r--r--drivers/media/video/cx18/cx18-alsa-mixer.c175
-rw-r--r--drivers/media/video/cx18/cx18-alsa-mixer.h23
-rw-r--r--drivers/media/video/cx18/cx18-alsa-pcm.c354
-rw-r--r--drivers/media/video/cx18/cx18-alsa-pcm.h27
-rw-r--r--drivers/media/video/cx18/cx18-alsa.h75
-rw-r--r--drivers/media/video/cx18/cx18-cards.c2
-rw-r--r--drivers/media/video/cx18/cx18-driver.c70
-rw-r--r--drivers/media/video/cx18/cx18-driver.h50
-rw-r--r--drivers/media/video/cx18/cx18-dvb.c22
-rw-r--r--drivers/media/video/cx18/cx18-fileops.c205
-rw-r--r--drivers/media/video/cx18/cx18-fileops.h3
-rw-r--r--drivers/media/video/cx18/cx18-ioctl.c135
-rw-r--r--drivers/media/video/cx18/cx18-mailbox.c45
-rw-r--r--drivers/media/video/cx18/cx18-queue.c3
-rw-r--r--drivers/media/video/cx18/cx18-streams.c72
-rw-r--r--drivers/media/video/cx18/cx18-streams.h10
-rw-r--r--drivers/media/video/cx18/cx18-version.h2
-rw-r--r--drivers/media/video/cx18/cx23418.h3
-rw-r--r--drivers/media/video/cx231xx/cx231xx-dvb.c8
-rw-r--r--drivers/media/video/cx231xx/cx231xx-input.c2
-rw-r--r--drivers/media/video/cx23885/cx23885-417.c4
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c32
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c17
-rw-r--r--drivers/media/video/cx23885/cx23885-input.c2
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c13
-rw-r--r--drivers/media/video/cx23885/cx23885.h1
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c54
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c10
-rw-r--r--drivers/media/video/cx88/cx88-cards.c23
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c214
-rw-r--r--drivers/media/video/cx88/cx88-input.c4
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c3
-rw-r--r--drivers/media/video/cx88/cx88.h1
-rw-r--r--drivers/media/video/dabusb.c2
-rw-r--r--drivers/media/video/davinci/Makefile1
-rw-r--r--drivers/media/video/davinci/dm355_ccdc.c410
-rw-r--r--drivers/media/video/davinci/dm644x_ccdc.c361
-rw-r--r--drivers/media/video/davinci/isif.c1172
-rw-r--r--drivers/media/video/davinci/isif_regs.h269
-rw-r--r--drivers/media/video/davinci/vpfe_capture.c131
-rw-r--r--drivers/media/video/davinci/vpss.c289
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c80
-rw-r--r--drivers/media/video/em28xx/em28xx-core.c19
-rw-r--r--drivers/media/video/em28xx/em28xx-dvb.c3
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c113
-rw-r--r--drivers/media/video/em28xx/em28xx-reg.h4
-rw-r--r--drivers/media/video/em28xx/em28xx-vbi.c17
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c58
-rw-r--r--drivers/media/video/em28xx/em28xx.h6
-rw-r--r--drivers/media/video/et61x251/Kconfig6
-rw-r--r--drivers/media/video/gspca/Kconfig46
-rw-r--r--drivers/media/video/gspca/Makefile8
-rw-r--r--drivers/media/video/gspca/benq.c322
-rw-r--r--drivers/media/video/gspca/coarse_expo_autogain.h116
-rw-r--r--drivers/media/video/gspca/conex.c4
-rw-r--r--drivers/media/video/gspca/cpia1.c2022
-rw-r--r--drivers/media/video/gspca/etoms.c4
-rw-r--r--drivers/media/video/gspca/gl860/gl860.c10
-rw-r--r--drivers/media/video/gspca/gspca.c259
-rw-r--r--drivers/media/video/gspca/gspca.h30
-rw-r--r--drivers/media/video/gspca/m5602/m5602_mt9m111.c4
-rw-r--r--drivers/media/video/gspca/m5602/m5602_ov7660.c2
-rw-r--r--drivers/media/video/gspca/m5602/m5602_ov7660.h2
-rw-r--r--drivers/media/video/gspca/m5602/m5602_ov9650.c2
-rw-r--r--drivers/media/video/gspca/m5602/m5602_po1030.c2
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k4aa.c2
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k83a.c2
-rw-r--r--drivers/media/video/gspca/mars.c2
-rw-r--r--drivers/media/video/gspca/mr97310a.c226
-rw-r--r--drivers/media/video/gspca/ov519.c151
-rw-r--r--drivers/media/video/gspca/ov534.c1253
-rw-r--r--drivers/media/video/gspca/ov534_9.c1477
-rw-r--r--drivers/media/video/gspca/pac207.c25
-rw-r--r--drivers/media/video/gspca/pac7302.c411
-rw-r--r--drivers/media/video/gspca/pac7311.c251
-rw-r--r--drivers/media/video/gspca/pac_common.h9
-rw-r--r--drivers/media/video/gspca/sn9c2028.c757
-rw-r--r--drivers/media/video/gspca/sn9c2028.h51
-rw-r--r--drivers/media/video/gspca/sn9c20x.c33
-rw-r--r--drivers/media/video/gspca/sonixb.c451
-rw-r--r--drivers/media/video/gspca/sonixj.c341
-rw-r--r--drivers/media/video/gspca/spca500.c4
-rw-r--r--drivers/media/video/gspca/spca501.c2
-rw-r--r--drivers/media/video/gspca/spca505.c2
-rw-r--r--drivers/media/video/gspca/spca506.c4
-rw-r--r--drivers/media/video/gspca/spca508.c2
-rw-r--r--drivers/media/video/gspca/spca561.c4
-rw-r--r--drivers/media/video/gspca/sq905c.c45
-rw-r--r--drivers/media/video/gspca/stk014.c2
-rw-r--r--drivers/media/video/gspca/stv0680.c16
-rw-r--r--drivers/media/video/gspca/stv06xx/stv06xx.c32
-rw-r--r--drivers/media/video/gspca/sunplus.c186
-rw-r--r--drivers/media/video/gspca/t613.c51
-rw-r--r--drivers/media/video/gspca/tv8532.c2
-rw-r--r--drivers/media/video/gspca/vc032x.c694
-rw-r--r--drivers/media/video/gspca/zc3xx.c679
-rw-r--r--drivers/media/video/hdpvr/hdpvr-core.c5
-rw-r--r--drivers/media/video/hdpvr/hdpvr-video.c5
-rw-r--r--drivers/media/video/hdpvr/hdpvr.h1
-rw-r--r--drivers/media/video/hexium_gemini.c9
-rw-r--r--drivers/media/video/hexium_orion.c4
-rw-r--r--drivers/media/video/ir-kbd-i2c.c5
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.c48
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.h4
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c1
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.c14
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.c9
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.h3
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c6
-rw-r--r--drivers/media/video/ivtv/ivtv-udma.c1
-rw-r--r--drivers/media/video/mt9t112.c2
-rw-r--r--drivers/media/video/mt9v022.c17
-rw-r--r--drivers/media/video/mxb.c10
-rw-r--r--drivers/media/video/ov772x.c22
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h12
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c53
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.h1
-rw-r--r--drivers/media/video/pwc/pwc-ctrl.c2
-rw-r--r--drivers/media/video/pxa_camera.c10
-rw-r--r--drivers/media/video/rj54n1cb0c.c12
-rw-r--r--drivers/media/video/saa7115.c27
-rw-r--r--drivers/media/video/saa7127.c47
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c52
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c7
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c2
-rw-r--r--drivers/media/video/saa7134/saa7134.h3
-rw-r--r--drivers/media/video/saa7164/saa7164-api.c2
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c18
-rw-r--r--drivers/media/video/sn9c102/Kconfig5
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h6
-rw-r--r--drivers/media/video/soc_camera.c36
-rw-r--r--drivers/media/video/soc_mediabus.c48
-rw-r--r--drivers/media/video/tlg2300/Kconfig16
-rw-r--r--drivers/media/video/tlg2300/Makefile9
-rw-r--r--drivers/media/video/tlg2300/pd-alsa.c332
-rw-r--r--drivers/media/video/tlg2300/pd-common.h282
-rw-r--r--drivers/media/video/tlg2300/pd-dvb.c593
-rw-r--r--drivers/media/video/tlg2300/pd-main.c539
-rw-r--r--drivers/media/video/tlg2300/pd-radio.c420
-rw-r--r--drivers/media/video/tlg2300/pd-video.c1667
-rw-r--r--drivers/media/video/tlg2300/vendorcmds.h243
-rw-r--r--drivers/media/video/tuner-core.c1
-rw-r--r--drivers/media/video/tveeprom.c5
-rw-r--r--drivers/media/video/tvp7002.c1187
-rw-r--r--drivers/media/video/tvp7002_reg.h150
-rw-r--r--drivers/media/video/tw9910.c8
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c2
-rw-r--r--drivers/media/video/uvc/uvc_ctrl.c242
-rw-r--r--drivers/media/video/uvc/uvc_driver.c74
-rw-r--r--drivers/media/video/uvc/uvc_queue.c1
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c4
-rw-r--r--drivers/media/video/uvc/uvc_video.c10
-rw-r--r--drivers/media/video/uvc/uvcvideo.h19
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c5
-rw-r--r--drivers/media/video/videobuf-dma-sg.c2
-rw-r--r--drivers/media/video/videobuf-vmalloc.c2
-rw-r--r--drivers/media/video/vivi.c2
-rw-r--r--drivers/media/video/zc0301/Kconfig6
-rw-r--r--drivers/media/video/zoran/zoran_device.c6
-rw-r--r--drivers/media/video/zoran/zoran_driver.c4
-rw-r--r--drivers/media/video/zr364xx.c37
-rw-r--r--drivers/message/fusion/mptbase.c5
-rw-r--r--drivers/message/fusion/mptbase.h4
-rw-r--r--drivers/message/fusion/mptctl.c4
-rw-r--r--drivers/message/fusion/mptfc.c17
-rw-r--r--drivers/message/fusion/mptsas.c211
-rw-r--r--drivers/message/fusion/mptscsih.c9
-rw-r--r--drivers/mfd/Kconfig10
-rw-r--r--drivers/mfd/Makefile3
-rw-r--r--drivers/mfd/timberdale.c727
-rw-r--r--drivers/mfd/timberdale.h130
-rw-r--r--drivers/mmc/host/au1xmmc.c12
-rw-r--r--drivers/mtd/maps/Kconfig6
-rw-r--r--drivers/mtd/maps/Makefile1
-rw-r--r--drivers/mtd/maps/alchemy-flash.c166
-rw-r--r--drivers/mtd/nand/Kconfig4
-rw-r--r--drivers/mtd/nand/au1550nd.c4
-rw-r--r--drivers/mtd/nand/sh_flctl.c69
-rw-r--r--drivers/net/au1000_eth.c441
-rw-r--r--drivers/net/au1000_eth.h9
-rw-r--r--drivers/net/cpmac.c10
-rw-r--r--drivers/net/irda/au1k_ir.c14
-rw-r--r--drivers/net/mace.c2
-rw-r--r--drivers/net/macmace.c33
-rw-r--r--drivers/net/macsonic.c33
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c6
-rw-r--r--drivers/of/Kconfig8
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/base.c318
-rw-r--r--drivers/of/fdt.c590
-rw-r--r--drivers/of/gpio.c13
-rw-r--r--drivers/of/of_i2c.c4
-rw-r--r--drivers/of/of_mdio.c8
-rw-r--r--drivers/of/of_spi.c6
-rw-r--r--drivers/pci/Kconfig11
-rw-r--r--drivers/pci/Makefile5
-rw-r--r--drivers/pci/bus.c56
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c2
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c6
-rw-r--r--drivers/pci/hotplug/cpcihp_generic.c1
-rw-r--r--drivers/pci/hotplug/cpqphp.h2
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c57
-rw-r--r--drivers/pci/hotplug/cpqphp_ctrl.c27
-rw-r--r--drivers/pci/hotplug/ibmphp_core.c106
-rw-r--r--drivers/pci/hotplug/ibmphp_ebda.c13
-rw-r--r--drivers/pci/hotplug/ibmphp_hpc.c1
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c132
-rw-r--r--drivers/pci/hotplug/pciehp_core.c25
-rw-r--r--drivers/pci/hotplug/pciehp_ctrl.c1
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c72
-rw-r--r--drivers/pci/hotplug/pciehp_pci.c23
-rw-r--r--drivers/pci/hotplug/rpaphp_core.c24
-rw-r--r--drivers/pci/hotplug/shpchp.h2
-rw-r--r--drivers/pci/hotplug/shpchp_core.c35
-rw-r--r--drivers/pci/hotplug/shpchp_ctrl.c14
-rw-r--r--drivers/pci/hotplug/shpchp_hpc.c149
-rw-r--r--drivers/pci/hotplug/shpchp_sysfs.c9
-rw-r--r--drivers/pci/legacy.c34
-rw-r--r--drivers/pci/pci-acpi.c211
-rw-r--r--drivers/pci/pci-driver.c160
-rw-r--r--drivers/pci/pci.c183
-rw-r--r--drivers/pci/pci.h16
-rw-r--r--drivers/pci/pcie/Kconfig4
-rw-r--r--drivers/pci/pcie/Makefile2
-rw-r--r--drivers/pci/pcie/pme/Makefile8
-rw-r--r--drivers/pci/pcie/pme/pcie_pme.c505
-rw-r--r--drivers/pci/pcie/pme/pcie_pme.h28
-rw-r--r--drivers/pci/pcie/pme/pcie_pme_acpi.c54
-rw-r--r--drivers/pci/pcie/portdrv.h17
-rw-r--r--drivers/pci/pcie/portdrv_core.c13
-rw-r--r--drivers/pci/pcie/portdrv_pci.c27
-rw-r--r--drivers/pci/probe.c293
-rw-r--r--drivers/pci/quirks.c14
-rw-r--r--drivers/pci/setup-bus.c506
-rw-r--r--drivers/pci/slot.c55
-rw-r--r--drivers/pcmcia/Kconfig30
-rw-r--r--drivers/pcmcia/Makefile16
-rw-r--r--drivers/pcmcia/at91_cf.c2
-rw-r--r--drivers/pcmcia/au1000_db1x00.c305
-rw-r--r--drivers/pcmcia/au1000_generic.c10
-rw-r--r--drivers/pcmcia/au1000_generic.h18
-rw-r--r--drivers/pcmcia/au1000_pb1x00.c119
-rw-r--r--drivers/pcmcia/au1000_xxs1500.c188
-rw-r--r--drivers/pcmcia/bfin_cf_pcmcia.c2
-rw-r--r--drivers/pcmcia/cardbus.c175
-rw-r--r--drivers/pcmcia/cistpl.c606
-rw-r--r--drivers/pcmcia/cs.c312
-rw-r--r--drivers/pcmcia/cs_internal.h89
-rw-r--r--drivers/pcmcia/db1xxx_ss.c623
-rw-r--r--drivers/pcmcia/ds.c333
-rw-r--r--drivers/pcmcia/electra_cf.c2
-rw-r--r--drivers/pcmcia/i82365.h4
-rw-r--r--drivers/pcmcia/m32r_cfc.c2
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c4
-rw-r--r--drivers/pcmcia/o2micro.h45
-rw-r--r--drivers/pcmcia/omap_cf.c2
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c42
-rw-r--r--drivers/pcmcia/pcmcia_resource.c169
-rw-r--r--drivers/pcmcia/rsrc_mgr.c61
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c310
-rw-r--r--drivers/pcmcia/socket_sysfs.c196
-rw-r--r--drivers/pcmcia/xxs1500_ss.c350
-rw-r--r--drivers/pcmcia/yenta_socket.c10
-rw-r--r--drivers/platform/x86/Kconfig1
-rw-r--r--drivers/platform/x86/acer-wmi.c2
-rw-r--r--drivers/platform/x86/classmate-laptop.c31
-rw-r--r--drivers/platform/x86/compal-laptop.c247
-rw-r--r--drivers/platform/x86/dell-laptop.c256
-rw-r--r--drivers/platform/x86/hp-wmi.c1
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c2
-rw-r--r--drivers/platform/x86/toshiba_acpi.c206
-rw-r--r--drivers/ps3/ps3av.c2
-rw-r--r--drivers/rtc/Kconfig10
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-mpc5121.c387
-rw-r--r--drivers/s390/block/dasd.c48
-rw-r--r--drivers/s390/block/dasd_devmap.c13
-rw-r--r--drivers/s390/block/dasd_genhd.c1
-rw-r--r--drivers/s390/block/dasd_int.h1
-rw-r--r--drivers/s390/block/dasd_proc.c109
-rw-r--r--drivers/s390/char/zcore.c163
-rw-r--r--drivers/s390/cio/ccwreq.c2
-rw-r--r--drivers/s390/cio/chsc.c2
-rw-r--r--drivers/s390/cio/chsc_sch.c4
-rw-r--r--drivers/s390/cio/cio.c14
-rw-r--r--drivers/s390/cio/crw.c29
-rw-r--r--drivers/s390/cio/css.c79
-rw-r--r--drivers/s390/cio/css.h5
-rw-r--r--drivers/s390/cio/device.c160
-rw-r--r--drivers/s390/cio/device.h3
-rw-r--r--drivers/s390/cio/device_fsm.c43
-rw-r--r--drivers/s390/cio/qdio.h92
-rw-r--r--drivers/s390/cio/qdio_debug.c23
-rw-r--r--drivers/s390/cio/qdio_main.c28
-rw-r--r--drivers/s390/cio/qdio_setup.c20
-rw-r--r--drivers/s390/cio/qdio_thinint.c4
-rw-r--r--drivers/s390/crypto/zcrypt_api.c158
-rw-r--r--drivers/s390/kvm/kvm_virtio.c4
-rw-r--r--drivers/s390/scsi/zfcp_aux.c90
-rw-r--r--drivers/s390/scsi/zfcp_ccw.c11
-rw-r--r--drivers/s390/scsi/zfcp_dbf.c20
-rw-r--r--drivers/s390/scsi/zfcp_dbf.h34
-rw-r--r--drivers/s390/scsi/zfcp_def.h114
-rw-r--r--drivers/s390/scsi/zfcp_erp.c36
-rw-r--r--drivers/s390/scsi/zfcp_ext.h9
-rw-r--r--drivers/s390/scsi/zfcp_fc.c23
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c163
-rw-r--r--drivers/s390/scsi/zfcp_qdio.c50
-rw-r--r--drivers/s390/scsi/zfcp_qdio.h109
-rw-r--r--drivers/s390/scsi/zfcp_reqlist.h183
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c38
-rw-r--r--drivers/s390/scsi/zfcp_sysfs.c37
-rw-r--r--drivers/sbus/char/openprom.c10
-rw-r--r--drivers/scsi/FlashPoint.c2
-rw-r--r--drivers/scsi/arm/fas216.c2
-rw-r--r--drivers/scsi/be2iscsi/be.h21
-rw-r--r--drivers/scsi/be2iscsi/be_cmds.c88
-rw-r--r--drivers/scsi/be2iscsi/be_cmds.h14
-rw-r--r--drivers/scsi/be2iscsi/be_iscsi.c136
-rw-r--r--drivers/scsi/be2iscsi/be_iscsi.h2
-rw-r--r--drivers/scsi/be2iscsi/be_main.c488
-rw-r--r--drivers/scsi/be2iscsi/be_main.h27
-rw-r--r--drivers/scsi/be2iscsi/be_mgmt.c139
-rw-r--r--drivers/scsi/be2iscsi/be_mgmt.h6
-rw-r--r--drivers/scsi/bnx2i/bnx2i_iscsi.c5
-rw-r--r--drivers/scsi/constants.c20
-rw-r--r--drivers/scsi/cxgb3i/cxgb3i_iscsi.c17
-rw-r--r--drivers/scsi/cxgb3i/cxgb3i_offload.c7
-rw-r--r--drivers/scsi/cxgb3i/cxgb3i_pdu.c6
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c2
-rw-r--r--drivers/scsi/eata.c2
-rw-r--r--drivers/scsi/esp_scsi.c14
-rw-r--r--drivers/scsi/fcoe/fcoe.c18
-rw-r--r--drivers/scsi/fcoe/libfcoe.c2
-rw-r--r--drivers/scsi/fnic/fnic.h2
-rw-r--r--drivers/scsi/fnic/fnic_main.c4
-rw-r--r--drivers/scsi/fnic/vnic_devcmd.h2
-rw-r--r--drivers/scsi/gdth.c430
-rw-r--r--drivers/scsi/gdth.h952
-rw-r--r--drivers/scsi/gdth_ioctl.h366
-rw-r--r--drivers/scsi/gdth_proc.c42
-rw-r--r--drivers/scsi/gdth_proc.h4
-rw-r--r--drivers/scsi/hosts.c4
-rw-r--r--drivers/scsi/hpsa.c793
-rw-r--r--drivers/scsi/hpsa.h136
-rw-r--r--drivers/scsi/hpsa_cmd.h204
-rw-r--r--drivers/scsi/ibmmca.c2
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c2
-rw-r--r--drivers/scsi/iscsi_tcp.c8
-rw-r--r--drivers/scsi/libfc/fc_exch.c2
-rw-r--r--drivers/scsi/libfc/fc_fcp.c3
-rw-r--r--drivers/scsi/libfc/fc_lport.c3
-rw-r--r--drivers/scsi/libfc/fc_rport.c2
-rw-r--r--drivers/scsi/libiscsi.c53
-rw-r--r--drivers/scsi/libiscsi_tcp.c8
-rw-r--r--drivers/scsi/libsrp.c8
-rw-r--r--drivers/scsi/lpfc/lpfc.h14
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c118
-rw-r--r--drivers/scsi/lpfc/lpfc_bsg.c2473
-rw-r--r--drivers/scsi/lpfc/lpfc_bsg.h98
-rw-r--r--drivers/scsi/lpfc/lpfc_crtn.h22
-rw-r--r--drivers/scsi/lpfc/lpfc_ct.c15
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c145
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c735
-rw-r--r--drivers/scsi/lpfc/lpfc_hw.h23
-rw-r--r--drivers/scsi/lpfc/lpfc_hw4.h265
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c547
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c111
-rw-r--r--drivers/scsi/lpfc/lpfc_nl.h22
-rw-r--r--drivers/scsi/lpfc/lpfc_nportdisc.c85
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c46
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.h1
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c329
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.h10
-rw-r--r--drivers/scsi/lpfc/lpfc_sli4.h82
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h4
-rw-r--r--drivers/scsi/lpfc/lpfc_vport.c7
-rw-r--r--drivers/scsi/mac_esp.c152
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c264
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h36
-rw-r--r--drivers/scsi/mpt2sas/Kconfig1
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2.h16
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h25
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_history.txt93
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_init.h24
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_ioc.h77
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_sas.h6
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.c18
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.h14
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_config.c51
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_ctl.c13
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_scsih.c266
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_transport.c196
-rw-r--r--drivers/scsi/pm8001/pm8001_init.c2
-rw-r--r--drivers/scsi/qla1280.c4
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c732
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h155
-rw-r--r--drivers/scsi/qla2xxx/qla_fw.h33
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h7
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c32
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c120
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c110
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c151
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c135
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h6
-rw-r--r--drivers/scsi/qla4xxx/ql4_init.c14
-rw-r--r--drivers/scsi/raid_class.c1
-rw-r--r--drivers/scsi/scsi.c40
-rw-r--r--drivers/scsi/scsi_lib.c10
-rw-r--r--drivers/scsi/scsi_sas_internal.h2
-rw-r--r--drivers/scsi/scsi_scan.c9
-rw-r--r--drivers/scsi/scsi_sysfs.c22
-rw-r--r--drivers/scsi/scsi_transport_fc.c26
-rw-r--r--drivers/scsi/scsi_transport_sas.c103
-rw-r--r--drivers/scsi/sd.c54
-rw-r--r--drivers/scsi/ses.c10
-rw-r--r--drivers/scsi/u14-34f.c2
-rw-r--r--drivers/scsi/vmw_pvscsi.c3
-rw-r--r--drivers/serial/8250.c15
-rw-r--r--drivers/serial/Kconfig12
-rw-r--r--drivers/serial/mpc52xx_uart.c251
-rw-r--r--drivers/serial/pmac_zilog.c246
-rw-r--r--drivers/serial/pmac_zilog.h34
-rw-r--r--drivers/serial/serial_cs.c7
-rw-r--r--drivers/serial/sh-sci.h220
-rw-r--r--drivers/sh/intc.c266
-rw-r--r--drivers/sh/pfc.c37
-rw-r--r--drivers/spi/Kconfig23
-rw-r--r--drivers/spi/Makefile3
-rw-r--r--drivers/spi/au1550_spi.c6
-rw-r--r--drivers/spi/coldfire_qspi.c640
-rw-r--r--drivers/spi/davinci_spi.c1255
-rw-r--r--drivers/spi/dw_spi.c111
-rw-r--r--drivers/spi/dw_spi_mmio.c147
-rw-r--r--drivers/spi/dw_spi_pci.c2
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c2
-rw-r--r--drivers/spi/mpc52xx_spi.c2
-rw-r--r--drivers/spi/spi_imx.c2
-rw-r--r--drivers/spi/spi_mpc8xxx.c8
-rw-r--r--drivers/spi/spi_ppc4xx.c2
-rw-r--r--drivers/spi/spi_s3c64xx.c89
-rw-r--r--drivers/spi/spi_sh_msiof.c2
-rw-r--r--drivers/spi/spi_stmp.c2
-rw-r--r--drivers/spi/xilinx_spi.c28
-rw-r--r--drivers/spi/xilinx_spi_of.c2
-rw-r--r--drivers/staging/go7007/s2250-board.c2
-rw-r--r--drivers/staging/octeon/Makefile1
-rw-r--r--drivers/staging/octeon/ethernet-defines.h34
-rw-r--r--drivers/staging/octeon/ethernet-mdio.c6
-rw-r--r--drivers/staging/octeon/ethernet-mdio.h1
-rw-r--r--drivers/staging/octeon/ethernet-mem.c124
-rw-r--r--drivers/staging/octeon/ethernet-proc.c144
-rw-r--r--drivers/staging/octeon/ethernet-proc.h29
-rw-r--r--drivers/staging/octeon/ethernet-rgmii.c56
-rw-r--r--drivers/staging/octeon/ethernet-rx.c384
-rw-r--r--drivers/staging/octeon/ethernet-rx.h25
-rw-r--r--drivers/staging/octeon/ethernet-sgmii.c1
-rw-r--r--drivers/staging/octeon/ethernet-spi.c1
-rw-r--r--drivers/staging/octeon/ethernet-tx.c441
-rw-r--r--drivers/staging/octeon/ethernet-tx.h29
-rw-r--r--drivers/staging/octeon/ethernet-util.h13
-rw-r--r--drivers/staging/octeon/ethernet-xaui.c1
-rw-r--r--drivers/staging/octeon/ethernet.c254
-rw-r--r--drivers/staging/octeon/octeon-ethernet.h58
-rw-r--r--drivers/staging/sm7xx/smtc2d.c2
-rw-r--r--drivers/staging/sm7xx/smtc2d.h2
-rw-r--r--drivers/staging/sm7xx/smtcfb.c2
-rw-r--r--drivers/staging/sm7xx/smtcfb.h2
-rw-r--r--drivers/usb/core/driver.c8
-rw-r--r--drivers/usb/core/endpoint.c1
-rw-r--r--drivers/usb/core/hcd-pci.c127
-rw-r--r--drivers/usb/core/hub.c1
-rw-r--r--drivers/usb/core/message.c1
-rw-r--r--drivers/usb/storage/usb.c2
-rw-r--r--drivers/video/aty/aty128fb.c14
-rw-r--r--drivers/video/aty/atyfb_base.c10
-rw-r--r--drivers/video/aty/radeon_backlight.c6
-rw-r--r--drivers/video/efifb.c11
-rw-r--r--drivers/video/fsl-diu-fb.c5
-rw-r--r--drivers/video/macfb.c736
-rw-r--r--drivers/video/macmodes.c80
-rw-r--r--drivers/video/pvr2fb.c2
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c88
-rw-r--r--drivers/video/valkyriefb.c6
-rw-r--r--drivers/video/valkyriefb.h31
-rw-r--r--drivers/virtio/virtio_balloon.c109
-rw-r--r--drivers/virtio/virtio_pci.c2
-rw-r--r--drivers/virtio/virtio_ring.c34
-rw-r--r--drivers/watchdog/ar7_wdt.c18
-rw-r--r--drivers/watchdog/bfin_wdt.c13
741 files changed, 54238 insertions, 14934 deletions
diff --git a/drivers/acpi/acpica/acevents.h b/drivers/acpi/acpica/acevents.h
index 0bba148a2c61..4ced54f7a5d9 100644
--- a/drivers/acpi/acpica/acevents.h
+++ b/drivers/acpi/acpica/acevents.h
@@ -76,12 +76,9 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node *node,
76 * evgpe - GPE handling and dispatch 76 * evgpe - GPE handling and dispatch
77 */ 77 */
78acpi_status 78acpi_status
79acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info, 79acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info);
80 u8 type);
81 80
82acpi_status 81acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info);
83acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
84 u8 write_to_hardware);
85 82
86acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info); 83acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info);
87 84
@@ -122,9 +119,6 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info,
122u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list); 119u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list);
123 120
124acpi_status 121acpi_status
125acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type);
126
127acpi_status
128acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info); 122acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info);
129 123
130acpi_status acpi_ev_gpe_initialize(void); 124acpi_status acpi_ev_gpe_initialize(void);
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index 81e64f478679..13cb80caacde 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -426,6 +426,8 @@ struct acpi_gpe_event_info {
426 struct acpi_gpe_register_info *register_info; /* Backpointer to register info */ 426 struct acpi_gpe_register_info *register_info; /* Backpointer to register info */
427 u8 flags; /* Misc info about this GPE */ 427 u8 flags; /* Misc info about this GPE */
428 u8 gpe_number; /* This GPE */ 428 u8 gpe_number; /* This GPE */
429 u8 runtime_count;
430 u8 wakeup_count;
429}; 431};
430 432
431/* Information about a GPE register pair, one per each status/enable pair in an array */ 433/* Information about a GPE register pair, one per each status/enable pair in an array */
diff --git a/drivers/acpi/acpica/acobject.h b/drivers/acpi/acpica/acobject.h
index 64062b1be3ee..07f6e2ea2ee5 100644
--- a/drivers/acpi/acpica/acobject.h
+++ b/drivers/acpi/acpica/acobject.h
@@ -287,8 +287,10 @@ struct acpi_object_buffer_field {
287 287
288struct acpi_object_notify_handler { 288struct acpi_object_notify_handler {
289 ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node; /* Parent device */ 289 ACPI_OBJECT_COMMON_HEADER struct acpi_namespace_node *node; /* Parent device */
290 u32 handler_type;
290 acpi_notify_handler handler; 291 acpi_notify_handler handler;
291 void *context; 292 void *context;
293 struct acpi_object_notify_handler *next;
292}; 294};
293 295
294struct acpi_object_addr_handler { 296struct acpi_object_addr_handler {
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index afacf4416c73..0b453467a5a0 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -54,54 +54,9 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context);
54 54
55/******************************************************************************* 55/*******************************************************************************
56 * 56 *
57 * FUNCTION: acpi_ev_set_gpe_type
58 *
59 * PARAMETERS: gpe_event_info - GPE to set
60 * Type - New type
61 *
62 * RETURN: Status
63 *
64 * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run)
65 *
66 ******************************************************************************/
67
68acpi_status
69acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type)
70{
71 acpi_status status;
72
73 ACPI_FUNCTION_TRACE(ev_set_gpe_type);
74
75 /* Validate type and update register enable masks */
76
77 switch (type) {
78 case ACPI_GPE_TYPE_WAKE:
79 case ACPI_GPE_TYPE_RUNTIME:
80 case ACPI_GPE_TYPE_WAKE_RUN:
81 break;
82
83 default:
84 return_ACPI_STATUS(AE_BAD_PARAMETER);
85 }
86
87 /* Disable the GPE if currently enabled */
88
89 status = acpi_ev_disable_gpe(gpe_event_info);
90
91 /* Clear the type bits and insert the new Type */
92
93 gpe_event_info->flags &= ~ACPI_GPE_TYPE_MASK;
94 gpe_event_info->flags |= type;
95 return_ACPI_STATUS(status);
96}
97
98/*******************************************************************************
99 *
100 * FUNCTION: acpi_ev_update_gpe_enable_masks 57 * FUNCTION: acpi_ev_update_gpe_enable_masks
101 * 58 *
102 * PARAMETERS: gpe_event_info - GPE to update 59 * PARAMETERS: gpe_event_info - GPE to update
103 * Type - What to do: ACPI_GPE_DISABLE or
104 * ACPI_GPE_ENABLE
105 * 60 *
106 * RETURN: Status 61 * RETURN: Status
107 * 62 *
@@ -110,8 +65,7 @@ acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type)
110 ******************************************************************************/ 65 ******************************************************************************/
111 66
112acpi_status 67acpi_status
113acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info, 68acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info)
114 u8 type)
115{ 69{
116 struct acpi_gpe_register_info *gpe_register_info; 70 struct acpi_gpe_register_info *gpe_register_info;
117 u8 register_bit; 71 u8 register_bit;
@@ -127,37 +81,14 @@ acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
127 (1 << 81 (1 <<
128 (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number)); 82 (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number));
129 83
130 /* 1) Disable case. Simply clear all enable bits */ 84 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, register_bit);
131 85 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
132 if (type == ACPI_GPE_DISABLE) {
133 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
134 register_bit);
135 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
136 return_ACPI_STATUS(AE_OK);
137 }
138
139 /* 2) Enable case. Set/Clear the appropriate enable bits */
140 86
141 switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { 87 if (gpe_event_info->runtime_count)
142 case ACPI_GPE_TYPE_WAKE:
143 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
144 ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
145 break;
146
147 case ACPI_GPE_TYPE_RUNTIME:
148 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
149 register_bit);
150 ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit); 88 ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
151 break;
152 89
153 case ACPI_GPE_TYPE_WAKE_RUN: 90 if (gpe_event_info->wakeup_count)
154 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit); 91 ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
155 ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
156 break;
157
158 default:
159 return_ACPI_STATUS(AE_BAD_PARAMETER);
160 }
161 92
162 return_ACPI_STATUS(AE_OK); 93 return_ACPI_STATUS(AE_OK);
163} 94}
@@ -167,8 +98,6 @@ acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
167 * FUNCTION: acpi_ev_enable_gpe 98 * FUNCTION: acpi_ev_enable_gpe
168 * 99 *
169 * PARAMETERS: gpe_event_info - GPE to enable 100 * PARAMETERS: gpe_event_info - GPE to enable
170 * write_to_hardware - Enable now, or just mark data structs
171 * (WAKE GPEs should be deferred)
172 * 101 *
173 * RETURN: Status 102 * RETURN: Status
174 * 103 *
@@ -176,9 +105,7 @@ acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
176 * 105 *
177 ******************************************************************************/ 106 ******************************************************************************/
178 107
179acpi_status 108acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
180acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
181 u8 write_to_hardware)
182{ 109{
183 acpi_status status; 110 acpi_status status;
184 111
@@ -186,47 +113,20 @@ acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
186 113
187 /* Make sure HW enable masks are updated */ 114 /* Make sure HW enable masks are updated */
188 115
189 status = 116 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
190 acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_ENABLE); 117 if (ACPI_FAILURE(status))
191 if (ACPI_FAILURE(status)) {
192 return_ACPI_STATUS(status); 118 return_ACPI_STATUS(status);
193 }
194 119
195 /* Mark wake-enabled or HW enable, or both */ 120 /* Mark wake-enabled or HW enable, or both */
196 121
197 switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) { 122 if (gpe_event_info->runtime_count) {
198 case ACPI_GPE_TYPE_WAKE: 123 /* Clear the GPE (of stale events), then enable it */
199 124 status = acpi_hw_clear_gpe(gpe_event_info);
200 ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED); 125 if (ACPI_FAILURE(status))
201 break; 126 return_ACPI_STATUS(status);
202
203 case ACPI_GPE_TYPE_WAKE_RUN:
204
205 ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
206
207 /*lint -fallthrough */
208
209 case ACPI_GPE_TYPE_RUNTIME:
210
211 ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
212
213 if (write_to_hardware) {
214
215 /* Clear the GPE (of stale events), then enable it */
216
217 status = acpi_hw_clear_gpe(gpe_event_info);
218 if (ACPI_FAILURE(status)) {
219 return_ACPI_STATUS(status);
220 }
221
222 /* Enable the requested runtime GPE */
223
224 status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
225 }
226 break;
227 127
228 default: 128 /* Enable the requested runtime GPE */
229 return_ACPI_STATUS(AE_BAD_PARAMETER); 129 status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
230 } 130 }
231 131
232 return_ACPI_STATUS(AE_OK); 132 return_ACPI_STATUS(AE_OK);
@@ -252,34 +152,9 @@ acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
252 152
253 /* Make sure HW enable masks are updated */ 153 /* Make sure HW enable masks are updated */
254 154
255 status = 155 status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
256 acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_DISABLE); 156 if (ACPI_FAILURE(status))
257 if (ACPI_FAILURE(status)) {
258 return_ACPI_STATUS(status); 157 return_ACPI_STATUS(status);
259 }
260
261 /* Clear the appropriate enabled flags for this GPE */
262
263 switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
264 case ACPI_GPE_TYPE_WAKE:
265 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
266 break;
267
268 case ACPI_GPE_TYPE_WAKE_RUN:
269 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
270
271 /* fallthrough */
272
273 case ACPI_GPE_TYPE_RUNTIME:
274
275 /* Disable the requested runtime GPE */
276
277 ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
278 break;
279
280 default:
281 break;
282 }
283 158
284 /* 159 /*
285 * Even if we don't know the GPE type, make sure that we always 160 * Even if we don't know the GPE type, make sure that we always
@@ -521,7 +396,7 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
521 396
522 /* Set the GPE flags for return to enabled state */ 397 /* Set the GPE flags for return to enabled state */
523 398
524 (void)acpi_ev_enable_gpe(gpe_event_info, FALSE); 399 (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
525 400
526 /* 401 /*
527 * Take a snapshot of the GPE info for this level - we copy the info to 402 * Take a snapshot of the GPE info for this level - we copy the info to
diff --git a/drivers/acpi/acpica/evgpeblk.c b/drivers/acpi/acpica/evgpeblk.c
index 247920900187..3d4c4aca11cd 100644
--- a/drivers/acpi/acpica/evgpeblk.c
+++ b/drivers/acpi/acpica/evgpeblk.c
@@ -258,7 +258,6 @@ acpi_ev_save_method_info(acpi_handle obj_handle,
258 u32 gpe_number; 258 u32 gpe_number;
259 char name[ACPI_NAME_SIZE + 1]; 259 char name[ACPI_NAME_SIZE + 1];
260 u8 type; 260 u8 type;
261 acpi_status status;
262 261
263 ACPI_FUNCTION_TRACE(ev_save_method_info); 262 ACPI_FUNCTION_TRACE(ev_save_method_info);
264 263
@@ -325,26 +324,20 @@ acpi_ev_save_method_info(acpi_handle obj_handle,
325 324
326 /* 325 /*
327 * Now we can add this information to the gpe_event_info block for use 326 * Now we can add this information to the gpe_event_info block for use
328 * during dispatch of this GPE. Default type is RUNTIME, although this may 327 * during dispatch of this GPE.
329 * change when the _PRW methods are executed later.
330 */ 328 */
331 gpe_event_info = 329 gpe_event_info =
332 &gpe_block->event_info[gpe_number - gpe_block->block_base_number]; 330 &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
333 331
334 gpe_event_info->flags = (u8) 332 gpe_event_info->flags = (u8) (type | ACPI_GPE_DISPATCH_METHOD);
335 (type | ACPI_GPE_DISPATCH_METHOD | ACPI_GPE_TYPE_RUNTIME);
336 333
337 gpe_event_info->dispatch.method_node = 334 gpe_event_info->dispatch.method_node =
338 (struct acpi_namespace_node *)obj_handle; 335 (struct acpi_namespace_node *)obj_handle;
339 336
340 /* Update enable mask, but don't enable the HW GPE as of yet */
341
342 status = acpi_ev_enable_gpe(gpe_event_info, FALSE);
343
344 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, 337 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
345 "Registered GPE method %s as GPE number 0x%.2X\n", 338 "Registered GPE method %s as GPE number 0x%.2X\n",
346 name, gpe_number)); 339 name, gpe_number));
347 return_ACPI_STATUS(status); 340 return_ACPI_STATUS(AE_OK);
348} 341}
349 342
350/******************************************************************************* 343/*******************************************************************************
@@ -454,20 +447,7 @@ acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
454 gpe_block-> 447 gpe_block->
455 block_base_number]; 448 block_base_number];
456 449
457 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */ 450 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
458
459 gpe_event_info->flags &=
460 ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED);
461
462 status =
463 acpi_ev_set_gpe_type(gpe_event_info, ACPI_GPE_TYPE_WAKE);
464 if (ACPI_FAILURE(status)) {
465 goto cleanup;
466 }
467
468 status =
469 acpi_ev_update_gpe_enable_masks(gpe_event_info,
470 ACPI_GPE_DISABLE);
471 } 451 }
472 452
473 cleanup: 453 cleanup:
@@ -989,7 +969,6 @@ acpi_status
989acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device, 969acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
990 struct acpi_gpe_block_info *gpe_block) 970 struct acpi_gpe_block_info *gpe_block)
991{ 971{
992 acpi_status status;
993 struct acpi_gpe_event_info *gpe_event_info; 972 struct acpi_gpe_event_info *gpe_event_info;
994 struct acpi_gpe_walk_info gpe_info; 973 struct acpi_gpe_walk_info gpe_info;
995 u32 wake_gpe_count; 974 u32 wake_gpe_count;
@@ -1019,42 +998,50 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
1019 gpe_info.gpe_block = gpe_block; 998 gpe_info.gpe_block = gpe_block;
1020 gpe_info.gpe_device = gpe_device; 999 gpe_info.gpe_device = gpe_device;
1021 1000
1022 status = 1001 acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1023 acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1024 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, 1002 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
1025 acpi_ev_match_prw_and_gpe, NULL, 1003 acpi_ev_match_prw_and_gpe, NULL,
1026 &gpe_info, NULL); 1004 &gpe_info, NULL);
1027 } 1005 }
1028 1006
1029 /* 1007 /*
1030 * Enable all GPEs in this block that have these attributes: 1008 * Enable all GPEs that have a corresponding method and aren't
1031 * 1) are "runtime" or "run/wake" GPEs, and 1009 * capable of generating wakeups. Any other GPEs within this block
1032 * 2) have a corresponding _Lxx or _Exx method 1010 * must be enabled via the acpi_enable_gpe() interface.
1033 *
1034 * Any other GPEs within this block must be enabled via the
1035 * acpi_enable_gpe() external interface.
1036 */ 1011 */
1037 wake_gpe_count = 0; 1012 wake_gpe_count = 0;
1038 gpe_enabled_count = 0; 1013 gpe_enabled_count = 0;
1014 if (gpe_device == acpi_gbl_fadt_gpe_device)
1015 gpe_device = NULL;
1039 1016
1040 for (i = 0; i < gpe_block->register_count; i++) { 1017 for (i = 0; i < gpe_block->register_count; i++) {
1041 for (j = 0; j < 8; j++) { 1018 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
1019 acpi_status status;
1020 acpi_size gpe_index;
1021 int gpe_number;
1042 1022
1043 /* Get the info block for this particular GPE */ 1023 /* Get the info block for this particular GPE */
1024 gpe_index = (acpi_size)i * ACPI_GPE_REGISTER_WIDTH + j;
1025 gpe_event_info = &gpe_block->event_info[gpe_index];
1044 1026
1045 gpe_event_info = &gpe_block->event_info[((acpi_size) i * 1027 if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
1046 ACPI_GPE_REGISTER_WIDTH)
1047 + j];
1048
1049 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
1050 ACPI_GPE_DISPATCH_METHOD) &&
1051 (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) {
1052 gpe_enabled_count++;
1053 }
1054
1055 if (gpe_event_info->flags & ACPI_GPE_TYPE_WAKE) {
1056 wake_gpe_count++; 1028 wake_gpe_count++;
1029 if (acpi_gbl_leave_wake_gpes_disabled)
1030 continue;
1057 } 1031 }
1032
1033 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD))
1034 continue;
1035
1036 gpe_number = gpe_index + gpe_block->block_base_number;
1037 status = acpi_enable_gpe(gpe_device, gpe_number,
1038 ACPI_GPE_TYPE_RUNTIME);
1039 if (ACPI_FAILURE(status))
1040 ACPI_ERROR((AE_INFO,
1041 "Failed to enable GPE %02X\n",
1042 gpe_number));
1043 else
1044 gpe_enabled_count++;
1058 } 1045 }
1059 } 1046 }
1060 1047
@@ -1062,15 +1049,7 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
1062 "Found %u Wake, Enabled %u Runtime GPEs in this block\n", 1049 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1063 wake_gpe_count, gpe_enabled_count)); 1050 wake_gpe_count, gpe_enabled_count));
1064 1051
1065 /* Enable all valid runtime GPEs found above */ 1052 return_ACPI_STATUS(AE_OK);
1066
1067 status = acpi_hw_enable_runtime_gpe_block(NULL, gpe_block, NULL);
1068 if (ACPI_FAILURE(status)) {
1069 ACPI_ERROR((AE_INFO, "Could not enable GPEs in GpeBlock %p",
1070 gpe_block));
1071 }
1072
1073 return_ACPI_STATUS(status);
1074} 1053}
1075 1054
1076/******************************************************************************* 1055/*******************************************************************************
diff --git a/drivers/acpi/acpica/evmisc.c b/drivers/acpi/acpica/evmisc.c
index ce224e1eaa89..8f0fac6c4366 100644
--- a/drivers/acpi/acpica/evmisc.c
+++ b/drivers/acpi/acpica/evmisc.c
@@ -259,9 +259,15 @@ static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
259 259
260 handler_obj = notify_info->notify.handler_obj; 260 handler_obj = notify_info->notify.handler_obj;
261 if (handler_obj) { 261 if (handler_obj) {
262 handler_obj->notify.handler(notify_info->notify.node, 262 struct acpi_object_notify_handler *notifier;
263 notify_info->notify.value, 263
264 handler_obj->notify.context); 264 notifier = &handler_obj->notify;
265 while (notifier) {
266 notifier->handler(notify_info->notify.node,
267 notify_info->notify.value,
268 notifier->context);
269 notifier = notifier->next;
270 }
265 } 271 }
266 272
267 /* All done with the info object */ 273 /* All done with the info object */
diff --git a/drivers/acpi/acpica/evxface.c b/drivers/acpi/acpica/evxface.c
index 2fe0809d4eb2..474e2cab603d 100644
--- a/drivers/acpi/acpica/evxface.c
+++ b/drivers/acpi/acpica/evxface.c
@@ -218,6 +218,72 @@ ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
218 218
219/******************************************************************************* 219/*******************************************************************************
220 * 220 *
221 * FUNCTION: acpi_populate_handler_object
222 *
223 * PARAMETERS: handler_obj - Handler object to populate
224 * handler_type - The type of handler:
225 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
226 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
227 * ACPI_ALL_NOTIFY: both system and device
228 * handler - Address of the handler
229 * context - Value passed to the handler on each GPE
230 * next - Address of a handler object to link to
231 *
232 * RETURN: None
233 *
234 * DESCRIPTION: Populate a handler object.
235 *
236 ******************************************************************************/
237static void
238acpi_populate_handler_object(struct acpi_object_notify_handler *handler_obj,
239 u32 handler_type,
240 acpi_notify_handler handler, void *context,
241 struct acpi_object_notify_handler *next)
242{
243 handler_obj->handler_type = handler_type;
244 handler_obj->handler = handler;
245 handler_obj->context = context;
246 handler_obj->next = next;
247}
248
249/*******************************************************************************
250 *
251 * FUNCTION: acpi_add_handler_object
252 *
253 * PARAMETERS: parent_obj - Parent of the new object
254 * handler - Address of the handler
255 * context - Value passed to the handler on each GPE
256 *
257 * RETURN: Status
258 *
259 * DESCRIPTION: Create a new handler object and populate it.
260 *
261 ******************************************************************************/
262static acpi_status
263acpi_add_handler_object(struct acpi_object_notify_handler *parent_obj,
264 acpi_notify_handler handler, void *context)
265{
266 struct acpi_object_notify_handler *handler_obj;
267
268 /* The parent must not be a defice notify handler object. */
269 if (parent_obj->handler_type & ACPI_DEVICE_NOTIFY)
270 return AE_BAD_PARAMETER;
271
272 handler_obj = ACPI_ALLOCATE_ZEROED(sizeof(*handler_obj));
273 if (!handler_obj)
274 return AE_NO_MEMORY;
275
276 acpi_populate_handler_object(handler_obj,
277 ACPI_SYSTEM_NOTIFY,
278 handler, context,
279 parent_obj->next);
280 parent_obj->next = handler_obj;
281
282 return AE_OK;
283}
284
285/*******************************************************************************
286 *
221 * FUNCTION: acpi_install_notify_handler 287 * FUNCTION: acpi_install_notify_handler
222 * 288 *
223 * PARAMETERS: Device - The device for which notifies will be handled 289 * PARAMETERS: Device - The device for which notifies will be handled
@@ -316,15 +382,32 @@ acpi_install_notify_handler(acpi_handle device,
316 obj_desc = acpi_ns_get_attached_object(node); 382 obj_desc = acpi_ns_get_attached_object(node);
317 if (obj_desc) { 383 if (obj_desc) {
318 384
319 /* Object exists - make sure there's no handler */ 385 /* Object exists. */
320 386
321 if (((handler_type & ACPI_SYSTEM_NOTIFY) && 387 /* For a device notify, make sure there's no handler. */
322 obj_desc->common_notify.system_notify) || 388 if ((handler_type & ACPI_DEVICE_NOTIFY) &&
323 ((handler_type & ACPI_DEVICE_NOTIFY) && 389 obj_desc->common_notify.device_notify) {
324 obj_desc->common_notify.device_notify)) {
325 status = AE_ALREADY_EXISTS; 390 status = AE_ALREADY_EXISTS;
326 goto unlock_and_exit; 391 goto unlock_and_exit;
327 } 392 }
393
394 /* System notifies may have more handlers installed. */
395 notify_obj = obj_desc->common_notify.system_notify;
396
397 if ((handler_type & ACPI_SYSTEM_NOTIFY) && notify_obj) {
398 struct acpi_object_notify_handler *parent_obj;
399
400 if (handler_type & ACPI_DEVICE_NOTIFY) {
401 status = AE_ALREADY_EXISTS;
402 goto unlock_and_exit;
403 }
404
405 parent_obj = &notify_obj->notify;
406 status = acpi_add_handler_object(parent_obj,
407 handler,
408 context);
409 goto unlock_and_exit;
410 }
328 } else { 411 } else {
329 /* Create a new object */ 412 /* Create a new object */
330 413
@@ -356,9 +439,10 @@ acpi_install_notify_handler(acpi_handle device,
356 goto unlock_and_exit; 439 goto unlock_and_exit;
357 } 440 }
358 441
359 notify_obj->notify.node = node; 442 acpi_populate_handler_object(&notify_obj->notify,
360 notify_obj->notify.handler = handler; 443 handler_type,
361 notify_obj->notify.context = context; 444 handler, context,
445 NULL);
362 446
363 if (handler_type & ACPI_SYSTEM_NOTIFY) { 447 if (handler_type & ACPI_SYSTEM_NOTIFY) {
364 obj_desc->common_notify.system_notify = notify_obj; 448 obj_desc->common_notify.system_notify = notify_obj;
@@ -418,6 +502,10 @@ acpi_remove_notify_handler(acpi_handle device,
418 goto exit; 502 goto exit;
419 } 503 }
420 504
505
506 /* Make sure all deferred tasks are completed */
507 acpi_os_wait_events_complete(NULL);
508
421 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 509 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
422 if (ACPI_FAILURE(status)) { 510 if (ACPI_FAILURE(status)) {
423 goto exit; 511 goto exit;
@@ -445,15 +533,6 @@ acpi_remove_notify_handler(acpi_handle device,
445 goto unlock_and_exit; 533 goto unlock_and_exit;
446 } 534 }
447 535
448 /* Make sure all deferred tasks are completed */
449
450 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
451 acpi_os_wait_events_complete(NULL);
452 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
453 if (ACPI_FAILURE(status)) {
454 goto exit;
455 }
456
457 if (handler_type & ACPI_SYSTEM_NOTIFY) { 536 if (handler_type & ACPI_SYSTEM_NOTIFY) {
458 acpi_gbl_system_notify.node = NULL; 537 acpi_gbl_system_notify.node = NULL;
459 acpi_gbl_system_notify.handler = NULL; 538 acpi_gbl_system_notify.handler = NULL;
@@ -488,28 +567,60 @@ acpi_remove_notify_handler(acpi_handle device,
488 /* Object exists - make sure there's an existing handler */ 567 /* Object exists - make sure there's an existing handler */
489 568
490 if (handler_type & ACPI_SYSTEM_NOTIFY) { 569 if (handler_type & ACPI_SYSTEM_NOTIFY) {
570 struct acpi_object_notify_handler *handler_obj;
571 struct acpi_object_notify_handler *parent_obj;
572
491 notify_obj = obj_desc->common_notify.system_notify; 573 notify_obj = obj_desc->common_notify.system_notify;
492 if (!notify_obj) { 574 if (!notify_obj) {
493 status = AE_NOT_EXIST; 575 status = AE_NOT_EXIST;
494 goto unlock_and_exit; 576 goto unlock_and_exit;
495 } 577 }
496 578
497 if (notify_obj->notify.handler != handler) { 579 handler_obj = &notify_obj->notify;
580 parent_obj = NULL;
581 while (handler_obj->handler != handler) {
582 if (handler_obj->next) {
583 parent_obj = handler_obj;
584 handler_obj = handler_obj->next;
585 } else {
586 break;
587 }
588 }
589
590 if (handler_obj->handler != handler) {
498 status = AE_BAD_PARAMETER; 591 status = AE_BAD_PARAMETER;
499 goto unlock_and_exit; 592 goto unlock_and_exit;
500 } 593 }
501 /* Make sure all deferred tasks are completed */
502 594
503 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 595 /*
504 acpi_os_wait_events_complete(NULL); 596 * Remove the handler. There are three possible cases.
505 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 597 * First, we may need to remove a non-embedded object.
506 if (ACPI_FAILURE(status)) { 598 * Second, we may need to remove the embedded object's
507 goto exit; 599 * handler data, while non-embedded objects exist.
600 * Finally, we may need to remove the embedded object
601 * entirely along with its container.
602 */
603 if (parent_obj) {
604 /* Non-embedded object is being removed. */
605 parent_obj->next = handler_obj->next;
606 ACPI_FREE(handler_obj);
607 } else if (notify_obj->notify.next) {
608 /*
609 * The handler matches the embedded object, but
610 * there are more handler objects in the list.
611 * Replace the embedded object's data with the
612 * first next object's data and remove that
613 * object.
614 */
615 parent_obj = &notify_obj->notify;
616 handler_obj = notify_obj->notify.next;
617 *parent_obj = *handler_obj;
618 ACPI_FREE(handler_obj);
619 } else {
620 /* No more handler objects in the list. */
621 obj_desc->common_notify.system_notify = NULL;
622 acpi_ut_remove_reference(notify_obj);
508 } 623 }
509
510 /* Remove the handler */
511 obj_desc->common_notify.system_notify = NULL;
512 acpi_ut_remove_reference(notify_obj);
513 } 624 }
514 625
515 if (handler_type & ACPI_DEVICE_NOTIFY) { 626 if (handler_type & ACPI_DEVICE_NOTIFY) {
@@ -523,14 +634,6 @@ acpi_remove_notify_handler(acpi_handle device,
523 status = AE_BAD_PARAMETER; 634 status = AE_BAD_PARAMETER;
524 goto unlock_and_exit; 635 goto unlock_and_exit;
525 } 636 }
526 /* Make sure all deferred tasks are completed */
527
528 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
529 acpi_os_wait_events_complete(NULL);
530 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
531 if (ACPI_FAILURE(status)) {
532 goto exit;
533 }
534 637
535 /* Remove the handler */ 638 /* Remove the handler */
536 obj_desc->common_notify.device_notify = NULL; 639 obj_desc->common_notify.device_notify = NULL;
@@ -617,13 +720,6 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
617 handler->context = context; 720 handler->context = context;
618 handler->method_node = gpe_event_info->dispatch.method_node; 721 handler->method_node = gpe_event_info->dispatch.method_node;
619 722
620 /* Disable the GPE before installing the handler */
621
622 status = acpi_ev_disable_gpe(gpe_event_info);
623 if (ACPI_FAILURE(status)) {
624 goto unlock_and_exit;
625 }
626
627 /* Install the handler */ 723 /* Install the handler */
628 724
629 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); 725 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
@@ -707,13 +803,6 @@ acpi_remove_gpe_handler(acpi_handle gpe_device,
707 goto unlock_and_exit; 803 goto unlock_and_exit;
708 } 804 }
709 805
710 /* Disable the GPE before removing the handler */
711
712 status = acpi_ev_disable_gpe(gpe_event_info);
713 if (ACPI_FAILURE(status)) {
714 goto unlock_and_exit;
715 }
716
717 /* Make sure all deferred tasks are completed */ 806 /* Make sure all deferred tasks are completed */
718 807
719 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS); 808 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
diff --git a/drivers/acpi/acpica/evxfevnt.c b/drivers/acpi/acpica/evxfevnt.c
index eed7a38d25f2..124c157215bf 100644
--- a/drivers/acpi/acpica/evxfevnt.c
+++ b/drivers/acpi/acpica/evxfevnt.c
@@ -201,23 +201,27 @@ ACPI_EXPORT_SYMBOL(acpi_enable_event)
201 201
202/******************************************************************************* 202/*******************************************************************************
203 * 203 *
204 * FUNCTION: acpi_set_gpe_type 204 * FUNCTION: acpi_set_gpe
205 * 205 *
206 * PARAMETERS: gpe_device - Parent GPE Device 206 * PARAMETERS: gpe_device - Parent GPE Device
207 * gpe_number - GPE level within the GPE block 207 * gpe_number - GPE level within the GPE block
208 * Type - New GPE type 208 * action - Enable or disable
209 * Called from ISR or not
209 * 210 *
210 * RETURN: Status 211 * RETURN: Status
211 * 212 *
212 * DESCRIPTION: Set the type of an individual GPE 213 * DESCRIPTION: Enable or disable an ACPI event (general purpose)
213 * 214 *
214 ******************************************************************************/ 215 ******************************************************************************/
215acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type) 216acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
216{ 217{
217 acpi_status status = AE_OK; 218 acpi_status status = AE_OK;
219 acpi_cpu_flags flags;
218 struct acpi_gpe_event_info *gpe_event_info; 220 struct acpi_gpe_event_info *gpe_event_info;
219 221
220 ACPI_FUNCTION_TRACE(acpi_set_gpe_type); 222 ACPI_FUNCTION_TRACE(acpi_set_gpe);
223
224 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
221 225
222 /* Ensure that we have a valid GPE number */ 226 /* Ensure that we have a valid GPE number */
223 227
@@ -227,19 +231,29 @@ acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
227 goto unlock_and_exit; 231 goto unlock_and_exit;
228 } 232 }
229 233
230 if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) { 234 /* Perform the action */
231 return_ACPI_STATUS(AE_OK); 235
232 } 236 switch (action) {
237 case ACPI_GPE_ENABLE:
238 status = acpi_ev_enable_gpe(gpe_event_info);
239 break;
233 240
234 /* Set the new type (will disable GPE if currently enabled) */ 241 case ACPI_GPE_DISABLE:
242 status = acpi_ev_disable_gpe(gpe_event_info);
243 break;
235 244
236 status = acpi_ev_set_gpe_type(gpe_event_info, type); 245 default:
246 ACPI_ERROR((AE_INFO, "Invalid action\n"));
247 status = AE_BAD_PARAMETER;
248 break;
249 }
237 250
238 unlock_and_exit: 251 unlock_and_exit:
252 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
239 return_ACPI_STATUS(status); 253 return_ACPI_STATUS(status);
240} 254}
241 255
242ACPI_EXPORT_SYMBOL(acpi_set_gpe_type) 256ACPI_EXPORT_SYMBOL(acpi_set_gpe)
243 257
244/******************************************************************************* 258/*******************************************************************************
245 * 259 *
@@ -247,15 +261,14 @@ ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
247 * 261 *
248 * PARAMETERS: gpe_device - Parent GPE Device 262 * PARAMETERS: gpe_device - Parent GPE Device
249 * gpe_number - GPE level within the GPE block 263 * gpe_number - GPE level within the GPE block
250 * Flags - Just enable, or also wake enable? 264 * type - Purpose the GPE will be used for
251 * Called from ISR or not
252 * 265 *
253 * RETURN: Status 266 * RETURN: Status
254 * 267 *
255 * DESCRIPTION: Enable an ACPI event (general purpose) 268 * DESCRIPTION: Take a reference to a GPE and enable it if necessary
256 * 269 *
257 ******************************************************************************/ 270 ******************************************************************************/
258acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number) 271acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
259{ 272{
260 acpi_status status = AE_OK; 273 acpi_status status = AE_OK;
261 acpi_cpu_flags flags; 274 acpi_cpu_flags flags;
@@ -263,6 +276,9 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
263 276
264 ACPI_FUNCTION_TRACE(acpi_enable_gpe); 277 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
265 278
279 if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
280 return_ACPI_STATUS(AE_BAD_PARAMETER);
281
266 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); 282 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
267 283
268 /* Ensure that we have a valid GPE number */ 284 /* Ensure that we have a valid GPE number */
@@ -273,15 +289,32 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
273 goto unlock_and_exit; 289 goto unlock_and_exit;
274 } 290 }
275 291
276 /* Perform the enable */ 292 if (type & ACPI_GPE_TYPE_RUNTIME) {
293 if (++gpe_event_info->runtime_count == 1) {
294 status = acpi_ev_enable_gpe(gpe_event_info);
295 if (ACPI_FAILURE(status))
296 gpe_event_info->runtime_count--;
297 }
298 }
299
300 if (type & ACPI_GPE_TYPE_WAKE) {
301 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
302 status = AE_BAD_PARAMETER;
303 goto unlock_and_exit;
304 }
277 305
278 status = acpi_ev_enable_gpe(gpe_event_info, TRUE); 306 /*
307 * Wake-up GPEs are only enabled right prior to putting the
308 * system into a sleep state.
309 */
310 if (++gpe_event_info->wakeup_count == 1)
311 acpi_ev_update_gpe_enable_masks(gpe_event_info);
312 }
279 313
280 unlock_and_exit: 314unlock_and_exit:
281 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 315 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
282 return_ACPI_STATUS(status); 316 return_ACPI_STATUS(status);
283} 317}
284
285ACPI_EXPORT_SYMBOL(acpi_enable_gpe) 318ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
286 319
287/******************************************************************************* 320/*******************************************************************************
@@ -290,15 +323,14 @@ ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
290 * 323 *
291 * PARAMETERS: gpe_device - Parent GPE Device 324 * PARAMETERS: gpe_device - Parent GPE Device
292 * gpe_number - GPE level within the GPE block 325 * gpe_number - GPE level within the GPE block
293 * Flags - Just disable, or also wake disable? 326 * type - Purpose the GPE won't be used for any more
294 * Called from ISR or not
295 * 327 *
296 * RETURN: Status 328 * RETURN: Status
297 * 329 *
298 * DESCRIPTION: Disable an ACPI event (general purpose) 330 * DESCRIPTION: Release a reference to a GPE and disable it if necessary
299 * 331 *
300 ******************************************************************************/ 332 ******************************************************************************/
301acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number) 333acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
302{ 334{
303 acpi_status status = AE_OK; 335 acpi_status status = AE_OK;
304 acpi_cpu_flags flags; 336 acpi_cpu_flags flags;
@@ -306,6 +338,9 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
306 338
307 ACPI_FUNCTION_TRACE(acpi_disable_gpe); 339 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
308 340
341 if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
342 return_ACPI_STATUS(AE_BAD_PARAMETER);
343
309 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); 344 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
310 /* Ensure that we have a valid GPE number */ 345 /* Ensure that we have a valid GPE number */
311 346
@@ -315,13 +350,24 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
315 goto unlock_and_exit; 350 goto unlock_and_exit;
316 } 351 }
317 352
318 status = acpi_ev_disable_gpe(gpe_event_info); 353 if ((type & ACPI_GPE_TYPE_RUNTIME) && gpe_event_info->runtime_count) {
354 if (--gpe_event_info->runtime_count == 0)
355 status = acpi_ev_disable_gpe(gpe_event_info);
356 }
357
358 if ((type & ACPI_GPE_TYPE_WAKE) && gpe_event_info->wakeup_count) {
359 /*
360 * Wake-up GPEs are not enabled after leaving system sleep
361 * states, so we don't need to disable them here.
362 */
363 if (--gpe_event_info->wakeup_count == 0)
364 acpi_ev_update_gpe_enable_masks(gpe_event_info);
365 }
319 366
320unlock_and_exit: 367unlock_and_exit:
321 acpi_os_release_lock(acpi_gbl_gpe_lock, flags); 368 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
322 return_ACPI_STATUS(status); 369 return_ACPI_STATUS(status);
323} 370}
324
325ACPI_EXPORT_SYMBOL(acpi_disable_gpe) 371ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
326 372
327/******************************************************************************* 373/*******************************************************************************
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 8a95e8329df7..f53fbe307c9d 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -422,11 +422,10 @@ static int acpi_button_add(struct acpi_device *device)
422 422
423 if (device->wakeup.flags.valid) { 423 if (device->wakeup.flags.valid) {
424 /* Button's GPE is run-wake GPE */ 424 /* Button's GPE is run-wake GPE */
425 acpi_set_gpe_type(device->wakeup.gpe_device,
426 device->wakeup.gpe_number,
427 ACPI_GPE_TYPE_WAKE_RUN);
428 acpi_enable_gpe(device->wakeup.gpe_device, 425 acpi_enable_gpe(device->wakeup.gpe_device,
429 device->wakeup.gpe_number); 426 device->wakeup.gpe_number,
427 ACPI_GPE_TYPE_WAKE_RUN);
428 device->wakeup.run_wake_count++;
430 device->wakeup.state.enabled = 1; 429 device->wakeup.state.enabled = 1;
431 } 430 }
432 431
@@ -446,6 +445,14 @@ static int acpi_button_remove(struct acpi_device *device, int type)
446{ 445{
447 struct acpi_button *button = acpi_driver_data(device); 446 struct acpi_button *button = acpi_driver_data(device);
448 447
448 if (device->wakeup.flags.valid) {
449 acpi_disable_gpe(device->wakeup.gpe_device,
450 device->wakeup.gpe_number,
451 ACPI_GPE_TYPE_WAKE_RUN);
452 device->wakeup.run_wake_count--;
453 device->wakeup.state.enabled = 0;
454 }
455
449 acpi_button_remove_fs(device); 456 acpi_button_remove_fs(device);
450 input_unregister_device(button->input); 457 input_unregister_device(button->input);
451 kfree(button); 458 kfree(button);
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index bbc2c1315c47..b2586f57e1f5 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -935,6 +935,7 @@ static int dock_add(acpi_handle handle)
935 struct platform_device *dd; 935 struct platform_device *dd;
936 936
937 id = dock_station_count; 937 id = dock_station_count;
938 memset(&ds, 0, sizeof(ds));
938 dd = platform_device_register_data(NULL, "dock", id, &ds, sizeof(ds)); 939 dd = platform_device_register_data(NULL, "dock", id, &ds, sizeof(ds));
939 if (IS_ERR(dd)) 940 if (IS_ERR(dd))
940 return PTR_ERR(dd); 941 return PTR_ERR(dd);
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index d6471bb6852f..27e0b92b2e39 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -307,7 +307,11 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
307 pr_debug(PREFIX "transaction start\n"); 307 pr_debug(PREFIX "transaction start\n");
308 /* disable GPE during transaction if storm is detected */ 308 /* disable GPE during transaction if storm is detected */
309 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) { 309 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
310 acpi_disable_gpe(NULL, ec->gpe); 310 /*
311 * It has to be disabled at the hardware level regardless of the
312 * GPE reference counting, so that it doesn't trigger.
313 */
314 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
311 } 315 }
312 316
313 status = acpi_ec_transaction_unlocked(ec, t); 317 status = acpi_ec_transaction_unlocked(ec, t);
@@ -316,8 +320,12 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
316 ec_check_sci_sync(ec, acpi_ec_read_status(ec)); 320 ec_check_sci_sync(ec, acpi_ec_read_status(ec));
317 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) { 321 if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
318 msleep(1); 322 msleep(1);
319 /* it is safe to enable GPE outside of transaction */ 323 /*
320 acpi_enable_gpe(NULL, ec->gpe); 324 * It is safe to enable the GPE outside of the transaction. Use
325 * acpi_set_gpe() for that, since we used it to disable the GPE
326 * above.
327 */
328 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
321 } else if (t->irq_count > ACPI_EC_STORM_THRESHOLD) { 329 } else if (t->irq_count > ACPI_EC_STORM_THRESHOLD) {
322 pr_info(PREFIX "GPE storm detected, " 330 pr_info(PREFIX "GPE storm detected, "
323 "transactions will use polling mode\n"); 331 "transactions will use polling mode\n");
@@ -788,8 +796,8 @@ static int ec_install_handlers(struct acpi_ec *ec)
788 &acpi_ec_gpe_handler, ec); 796 &acpi_ec_gpe_handler, ec);
789 if (ACPI_FAILURE(status)) 797 if (ACPI_FAILURE(status))
790 return -ENODEV; 798 return -ENODEV;
791 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME); 799
792 acpi_enable_gpe(NULL, ec->gpe); 800 acpi_enable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
793 status = acpi_install_address_space_handler(ec->handle, 801 status = acpi_install_address_space_handler(ec->handle,
794 ACPI_ADR_SPACE_EC, 802 ACPI_ADR_SPACE_EC,
795 &acpi_ec_space_handler, 803 &acpi_ec_space_handler,
@@ -806,6 +814,7 @@ static int ec_install_handlers(struct acpi_ec *ec)
806 } else { 814 } else {
807 acpi_remove_gpe_handler(NULL, ec->gpe, 815 acpi_remove_gpe_handler(NULL, ec->gpe,
808 &acpi_ec_gpe_handler); 816 &acpi_ec_gpe_handler);
817 acpi_disable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
809 return -ENODEV; 818 return -ENODEV;
810 } 819 }
811 } 820 }
@@ -816,6 +825,7 @@ static int ec_install_handlers(struct acpi_ec *ec)
816 825
817static void ec_remove_handlers(struct acpi_ec *ec) 826static void ec_remove_handlers(struct acpi_ec *ec)
818{ 827{
828 acpi_disable_gpe(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
819 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle, 829 if (ACPI_FAILURE(acpi_remove_address_space_handler(ec->handle,
820 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler))) 830 ACPI_ADR_SPACE_EC, &acpi_ec_space_handler)))
821 pr_err(PREFIX "failed to remove space handler\n"); 831 pr_err(PREFIX "failed to remove space handler\n");
@@ -1057,16 +1067,16 @@ error:
1057static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state) 1067static int acpi_ec_suspend(struct acpi_device *device, pm_message_t state)
1058{ 1068{
1059 struct acpi_ec *ec = acpi_driver_data(device); 1069 struct acpi_ec *ec = acpi_driver_data(device);
1060 /* Stop using GPE */ 1070 /* Stop using the GPE, but keep it reference counted. */
1061 acpi_disable_gpe(NULL, ec->gpe); 1071 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
1062 return 0; 1072 return 0;
1063} 1073}
1064 1074
1065static int acpi_ec_resume(struct acpi_device *device) 1075static int acpi_ec_resume(struct acpi_device *device)
1066{ 1076{
1067 struct acpi_ec *ec = acpi_driver_data(device); 1077 struct acpi_ec *ec = acpi_driver_data(device);
1068 /* Enable use of GPE back */ 1078 /* Enable the GPE again, but don't reference count it once more. */
1069 acpi_enable_gpe(NULL, ec->gpe); 1079 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
1070 return 0; 1080 return 0;
1071} 1081}
1072 1082
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index cb28e0502acc..9c4c962e46e3 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -36,8 +36,6 @@ static inline int acpi_debug_init(void) { return 0; }
36int acpi_power_init(void); 36int acpi_power_init(void);
37int acpi_device_sleep_wake(struct acpi_device *dev, 37int acpi_device_sleep_wake(struct acpi_device *dev,
38 int enable, int sleep_state, int dev_state); 38 int enable, int sleep_state, int dev_state);
39int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state);
40int acpi_disable_wakeup_device_power(struct acpi_device *dev);
41int acpi_power_get_inferred_state(struct acpi_device *device); 39int acpi_power_get_inferred_state(struct acpi_device *device);
42int acpi_power_transition(struct acpi_device *device, int state); 40int acpi_power_transition(struct acpi_device *device, int state);
43extern int acpi_power_nocheck; 41extern int acpi_power_nocheck;
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index a5a77b78a723..2ef04098cc1d 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -26,7 +26,9 @@
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/pci-acpi.h>
29#include <linux/acpi.h> 30#include <linux/acpi.h>
31#include <linux/pm_runtime.h>
30#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
31#include <acpi/acpi_drivers.h> 33#include <acpi/acpi_drivers.h>
32 34
@@ -38,7 +40,13 @@ static int acpi_pci_unbind(struct acpi_device *device)
38 struct pci_dev *dev; 40 struct pci_dev *dev;
39 41
40 dev = acpi_get_pci_dev(device->handle); 42 dev = acpi_get_pci_dev(device->handle);
41 if (!dev || !dev->subordinate) 43 if (!dev)
44 goto out;
45
46 device_set_run_wake(&dev->dev, false);
47 pci_acpi_remove_pm_notifier(device);
48
49 if (!dev->subordinate)
42 goto out; 50 goto out;
43 51
44 acpi_pci_irq_del_prt(dev->subordinate); 52 acpi_pci_irq_del_prt(dev->subordinate);
@@ -62,6 +70,10 @@ static int acpi_pci_bind(struct acpi_device *device)
62 if (!dev) 70 if (!dev)
63 return 0; 71 return 0;
64 72
73 pci_acpi_add_pm_notifier(device, dev);
74 if (device->wakeup.flags.run_wake)
75 device_set_run_wake(&dev->dev, true);
76
65 /* 77 /*
66 * Install the 'bind' function to facilitate callbacks for 78 * Install the 'bind' function to facilitate callbacks for
67 * children of the P2P bridge. 79 * children of the P2P bridge.
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 64f55b6db73c..d724736d56c8 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -30,6 +30,7 @@
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/spinlock.h> 31#include <linux/spinlock.h>
32#include <linux/pm.h> 32#include <linux/pm.h>
33#include <linux/pm_runtime.h>
33#include <linux/pci.h> 34#include <linux/pci.h>
34#include <linux/pci-acpi.h> 35#include <linux/pci-acpi.h>
35#include <linux/acpi.h> 36#include <linux/acpi.h>
@@ -528,6 +529,10 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)
528 if (flags != base_flags) 529 if (flags != base_flags)
529 acpi_pci_osc_support(root, flags); 530 acpi_pci_osc_support(root, flags);
530 531
532 pci_acpi_add_bus_pm_notifier(device, root->bus);
533 if (device->wakeup.flags.run_wake)
534 device_set_run_wake(root->bus->bridge, true);
535
531 return 0; 536 return 0;
532 537
533end: 538end:
@@ -549,6 +554,9 @@ static int acpi_pci_root_remove(struct acpi_device *device, int type)
549{ 554{
550 struct acpi_pci_root *root = acpi_driver_data(device); 555 struct acpi_pci_root *root = acpi_driver_data(device);
551 556
557 device_set_run_wake(root->bus->bridge, false);
558 pci_acpi_remove_bus_pm_notifier(device);
559
552 kfree(root); 560 kfree(root);
553 return 0; 561 return 0;
554} 562}
@@ -558,6 +566,7 @@ static int __init acpi_pci_root_init(void)
558 if (acpi_pci_disabled) 566 if (acpi_pci_disabled)
559 return 0; 567 return 0;
560 568
569 pci_acpi_crs_quirks();
561 if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0) 570 if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0)
562 return -ENODEV; 571 return -ENODEV;
563 572
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 7c0441f63b39..cc978a8c00b7 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -110,6 +110,14 @@ static struct dmi_system_id __cpuinitdata processor_power_dmi_table[] = {
110 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"), 110 DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
111 DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")}, 111 DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
112 (void *)2}, 112 (void *)2},
113 { set_max_cstate, "Pavilion zv5000", {
114 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
115 DMI_MATCH(DMI_PRODUCT_NAME,"Pavilion zv5000 (DS502A#ABA)")},
116 (void *)1},
117 { set_max_cstate, "Asus L8400B", {
118 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
119 DMI_MATCH(DMI_PRODUCT_NAME,"L8400B series Notebook PC")},
120 (void *)1},
113 {}, 121 {},
114}; 122};
115 123
@@ -872,12 +880,14 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
872 return(acpi_idle_enter_c1(dev, state)); 880 return(acpi_idle_enter_c1(dev, state));
873 881
874 local_irq_disable(); 882 local_irq_disable();
875 current_thread_info()->status &= ~TS_POLLING; 883 if (cx->entry_method != ACPI_CSTATE_FFH) {
876 /* 884 current_thread_info()->status &= ~TS_POLLING;
877 * TS_POLLING-cleared state must be visible before we test 885 /*
878 * NEED_RESCHED: 886 * TS_POLLING-cleared state must be visible before we test
879 */ 887 * NEED_RESCHED:
880 smp_mb(); 888 */
889 smp_mb();
890 }
881 891
882 if (unlikely(need_resched())) { 892 if (unlikely(need_resched())) {
883 current_thread_info()->status |= TS_POLLING; 893 current_thread_info()->status |= TS_POLLING;
@@ -957,12 +967,14 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
957 } 967 }
958 968
959 local_irq_disable(); 969 local_irq_disable();
960 current_thread_info()->status &= ~TS_POLLING; 970 if (cx->entry_method != ACPI_CSTATE_FFH) {
961 /* 971 current_thread_info()->status &= ~TS_POLLING;
962 * TS_POLLING-cleared state must be visible before we test 972 /*
963 * NEED_RESCHED: 973 * TS_POLLING-cleared state must be visible before we test
964 */ 974 * NEED_RESCHED:
965 smp_mb(); 975 */
976 smp_mb();
977 }
966 978
967 if (unlikely(need_resched())) { 979 if (unlikely(need_resched())) {
968 current_thread_info()->status |= TS_POLLING; 980 current_thread_info()->status |= TS_POLLING;
diff --git a/drivers/acpi/processor_pdc.c b/drivers/acpi/processor_pdc.c
index 7247819dbd80..e306ba9aa34e 100644
--- a/drivers/acpi/processor_pdc.c
+++ b/drivers/acpi/processor_pdc.c
@@ -125,6 +125,8 @@ acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
125 return status; 125 return status;
126} 126}
127 127
128static int early_pdc_done;
129
128void acpi_processor_set_pdc(acpi_handle handle) 130void acpi_processor_set_pdc(acpi_handle handle)
129{ 131{
130 struct acpi_object_list *obj_list; 132 struct acpi_object_list *obj_list;
@@ -132,6 +134,9 @@ void acpi_processor_set_pdc(acpi_handle handle)
132 if (arch_has_acpi_pdc() == false) 134 if (arch_has_acpi_pdc() == false)
133 return; 135 return;
134 136
137 if (early_pdc_done)
138 return;
139
135 obj_list = acpi_processor_alloc_pdc(); 140 obj_list = acpi_processor_alloc_pdc();
136 if (!obj_list) 141 if (!obj_list)
137 return; 142 return;
@@ -151,6 +156,13 @@ static int set_early_pdc_optin(const struct dmi_system_id *id)
151 return 0; 156 return 0;
152} 157}
153 158
159static int param_early_pdc_optin(char *s)
160{
161 early_pdc_optin = 1;
162 return 1;
163}
164__setup("acpi_early_pdc_eval", param_early_pdc_optin);
165
154static struct dmi_system_id __cpuinitdata early_pdc_optin_table[] = { 166static struct dmi_system_id __cpuinitdata early_pdc_optin_table[] = {
155 { 167 {
156 set_early_pdc_optin, "HP Envy", { 168 set_early_pdc_optin, "HP Envy", {
@@ -192,4 +204,6 @@ void __init acpi_early_processor_set_pdc(void)
192 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, 204 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
193 ACPI_UINT32_MAX, 205 ACPI_UINT32_MAX,
194 early_init_pdc, NULL, NULL, NULL); 206 early_init_pdc, NULL, NULL, NULL);
207
208 early_pdc_done = 1;
195} 209}
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 2cabadcc4d8c..a959f6a07508 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -413,7 +413,11 @@ static int acpi_processor_get_performance_info(struct acpi_processor *pr)
413 if (result) 413 if (result)
414 goto update_bios; 414 goto update_bios;
415 415
416 return 0; 416 /* We need to call _PPC once when cpufreq starts */
417 if (ignore_ppc != 1)
418 result = acpi_processor_get_platform_limit(pr);
419
420 return result;
417 421
418 /* 422 /*
419 * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that 423 * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index ff9f6226085d..fb7fc24fe727 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -741,19 +741,40 @@ acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
741 return AE_OK; 741 return AE_OK;
742} 742}
743 743
744static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device) 744static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
745{ 745{
746 acpi_status status = 0;
747 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
748 union acpi_object *package = NULL;
749 int psw_error;
750
751 struct acpi_device_id button_device_ids[] = { 746 struct acpi_device_id button_device_ids[] = {
752 {"PNP0C0D", 0}, 747 {"PNP0C0D", 0},
753 {"PNP0C0C", 0}, 748 {"PNP0C0C", 0},
754 {"PNP0C0E", 0}, 749 {"PNP0C0E", 0},
755 {"", 0}, 750 {"", 0},
756 }; 751 };
752 acpi_status status;
753 acpi_event_status event_status;
754
755 device->wakeup.run_wake_count = 0;
756 device->wakeup.flags.notifier_present = 0;
757
758 /* Power button, Lid switch always enable wakeup */
759 if (!acpi_match_device_ids(device, button_device_ids)) {
760 device->wakeup.flags.run_wake = 1;
761 device->wakeup.flags.always_enabled = 1;
762 return;
763 }
764
765 status = acpi_get_gpe_status(NULL, device->wakeup.gpe_number,
766 ACPI_NOT_ISR, &event_status);
767 if (status == AE_OK)
768 device->wakeup.flags.run_wake =
769 !!(event_status & ACPI_EVENT_FLAG_HANDLE);
770}
771
772static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
773{
774 acpi_status status = 0;
775 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
776 union acpi_object *package = NULL;
777 int psw_error;
757 778
758 /* _PRW */ 779 /* _PRW */
759 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer); 780 status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
@@ -773,6 +794,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
773 794
774 device->wakeup.flags.valid = 1; 795 device->wakeup.flags.valid = 1;
775 device->wakeup.prepare_count = 0; 796 device->wakeup.prepare_count = 0;
797 acpi_bus_set_run_wake_flags(device);
776 /* Call _PSW/_DSW object to disable its ability to wake the sleeping 798 /* Call _PSW/_DSW object to disable its ability to wake the sleeping
777 * system for the ACPI device with the _PRW object. 799 * system for the ACPI device with the _PRW object.
778 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW. 800 * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
@@ -784,10 +806,6 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
784 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 806 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
785 "error in _DSW or _PSW evaluation\n")); 807 "error in _DSW or _PSW evaluation\n"));
786 808
787 /* Power button, Lid switch always enable wakeup */
788 if (!acpi_match_device_ids(device, button_device_ids))
789 device->wakeup.flags.run_wake = 1;
790
791end: 809end:
792 if (ACPI_FAILURE(status)) 810 if (ACPI_FAILURE(status))
793 device->flags.wake_capable = 0; 811 device->flags.wake_capable = 0;
@@ -1336,9 +1354,25 @@ static int acpi_bus_scan(acpi_handle handle, struct acpi_bus_ops *ops,
1336 1354
1337 if (child) 1355 if (child)
1338 *child = device; 1356 *child = device;
1339 return 0; 1357
1358 if (device)
1359 return 0;
1360 else
1361 return -ENODEV;
1340} 1362}
1341 1363
1364/*
1365 * acpi_bus_add and acpi_bus_start
1366 *
1367 * scan a given ACPI tree and (probably recently hot-plugged)
1368 * create and add or starts found devices.
1369 *
1370 * If no devices were found -ENODEV is returned which does not
1371 * mean that this is a real error, there just have been no suitable
1372 * ACPI objects in the table trunk from which the kernel could create
1373 * a device and add/start an appropriate driver.
1374 */
1375
1342int 1376int
1343acpi_bus_add(struct acpi_device **child, 1377acpi_bus_add(struct acpi_device **child,
1344 struct acpi_device *parent, acpi_handle handle, int type) 1378 struct acpi_device *parent, acpi_handle handle, int type)
@@ -1348,8 +1382,7 @@ acpi_bus_add(struct acpi_device **child,
1348 memset(&ops, 0, sizeof(ops)); 1382 memset(&ops, 0, sizeof(ops));
1349 ops.acpi_op_add = 1; 1383 ops.acpi_op_add = 1;
1350 1384
1351 acpi_bus_scan(handle, &ops, child); 1385 return acpi_bus_scan(handle, &ops, child);
1352 return 0;
1353} 1386}
1354EXPORT_SYMBOL(acpi_bus_add); 1387EXPORT_SYMBOL(acpi_bus_add);
1355 1388
@@ -1357,11 +1390,13 @@ int acpi_bus_start(struct acpi_device *device)
1357{ 1390{
1358 struct acpi_bus_ops ops; 1391 struct acpi_bus_ops ops;
1359 1392
1393 if (!device)
1394 return -EINVAL;
1395
1360 memset(&ops, 0, sizeof(ops)); 1396 memset(&ops, 0, sizeof(ops));
1361 ops.acpi_op_start = 1; 1397 ops.acpi_op_start = 1;
1362 1398
1363 acpi_bus_scan(device->handle, &ops, NULL); 1399 return acpi_bus_scan(device->handle, &ops, NULL);
1364 return 0;
1365} 1400}
1366EXPORT_SYMBOL(acpi_bus_start); 1401EXPORT_SYMBOL(acpi_bus_start);
1367 1402
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 79d33d908b5a..3bde594a9979 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -745,9 +745,18 @@ int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
745 return -ENODEV; 745 return -ENODEV;
746 } 746 }
747 747
748 error = enable ? 748 if (enable) {
749 acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) : 749 error = acpi_enable_wakeup_device_power(adev,
750 acpi_disable_wakeup_device_power(adev); 750 acpi_target_sleep_state);
751 if (!error)
752 acpi_enable_gpe(adev->wakeup.gpe_device,
753 adev->wakeup.gpe_number,
754 ACPI_GPE_TYPE_WAKE);
755 } else {
756 acpi_disable_gpe(adev->wakeup.gpe_device, adev->wakeup.gpe_number,
757 ACPI_GPE_TYPE_WAKE);
758 error = acpi_disable_wakeup_device_power(adev);
759 }
751 if (!error) 760 if (!error)
752 dev_info(dev, "wake-up capability %s by ACPI\n", 761 dev_info(dev, "wake-up capability %s by ACPI\n",
753 enable ? "enabled" : "disabled"); 762 enable ? "enabled" : "disabled");
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index d11282975f35..a206a12da78a 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -387,10 +387,10 @@ static ssize_t counter_set(struct kobject *kobj,
387 if (index < num_gpes) { 387 if (index < num_gpes) {
388 if (!strcmp(buf, "disable\n") && 388 if (!strcmp(buf, "disable\n") &&
389 (status & ACPI_EVENT_FLAG_ENABLED)) 389 (status & ACPI_EVENT_FLAG_ENABLED))
390 result = acpi_disable_gpe(handle, index); 390 result = acpi_set_gpe(handle, index, ACPI_GPE_DISABLE);
391 else if (!strcmp(buf, "enable\n") && 391 else if (!strcmp(buf, "enable\n") &&
392 !(status & ACPI_EVENT_FLAG_ENABLED)) 392 !(status & ACPI_EVENT_FLAG_ENABLED))
393 result = acpi_enable_gpe(handle, index); 393 result = acpi_set_gpe(handle, index, ACPI_GPE_ENABLE);
394 else if (!strcmp(buf, "clear\n") && 394 else if (!strcmp(buf, "clear\n") &&
395 (status & ACPI_EVENT_FLAG_SET)) 395 (status & ACPI_EVENT_FLAG_SET))
396 result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR); 396 result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR);
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index f336bca7c450..8a0ed2800e63 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -213,7 +213,7 @@ acpi_table_parse_entries(char *id,
213 unsigned long table_end; 213 unsigned long table_end;
214 acpi_size tbl_size; 214 acpi_size tbl_size;
215 215
216 if (acpi_disabled) 216 if (acpi_disabled && !acpi_ht)
217 return -ENODEV; 217 return -ENODEV;
218 218
219 if (!handler) 219 if (!handler)
@@ -280,7 +280,7 @@ int __init acpi_table_parse(char *id, acpi_table_handler handler)
280 struct acpi_table_header *table = NULL; 280 struct acpi_table_header *table = NULL;
281 acpi_size tbl_size; 281 acpi_size tbl_size;
282 282
283 if (acpi_disabled) 283 if (acpi_disabled && !acpi_ht)
284 return -ENODEV; 284 return -ENODEV;
285 285
286 if (!handler) 286 if (!handler)
diff --git a/drivers/acpi/wakeup.c b/drivers/acpi/wakeup.c
index e0ee0c036f5a..4b9d339a6e28 100644
--- a/drivers/acpi/wakeup.c
+++ b/drivers/acpi/wakeup.c
@@ -21,12 +21,12 @@
21ACPI_MODULE_NAME("wakeup_devices") 21ACPI_MODULE_NAME("wakeup_devices")
22 22
23/** 23/**
24 * acpi_enable_wakeup_device_prep - prepare wakeup devices 24 * acpi_enable_wakeup_device_prep - Prepare wake-up devices.
25 * @sleep_state: ACPI state 25 * @sleep_state: ACPI system sleep state.
26 * Enable all wakup devices power if the devices' wakeup level 26 *
27 * is higher than requested sleep level 27 * Enable all wake-up devices' power, unless the requested system sleep state is
28 * too deep.
28 */ 29 */
29
30void acpi_enable_wakeup_device_prep(u8 sleep_state) 30void acpi_enable_wakeup_device_prep(u8 sleep_state)
31{ 31{
32 struct list_head *node, *next; 32 struct list_head *node, *next;
@@ -36,9 +36,8 @@ void acpi_enable_wakeup_device_prep(u8 sleep_state)
36 struct acpi_device, 36 struct acpi_device,
37 wakeup_list); 37 wakeup_list);
38 38
39 if (!dev->wakeup.flags.valid || 39 if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
40 !dev->wakeup.state.enabled || 40 || (sleep_state > (u32) dev->wakeup.sleep_state))
41 (sleep_state > (u32) dev->wakeup.sleep_state))
42 continue; 41 continue;
43 42
44 acpi_enable_wakeup_device_power(dev, sleep_state); 43 acpi_enable_wakeup_device_power(dev, sleep_state);
@@ -46,9 +45,12 @@ void acpi_enable_wakeup_device_prep(u8 sleep_state)
46} 45}
47 46
48/** 47/**
49 * acpi_enable_wakeup_device - enable wakeup devices 48 * acpi_enable_wakeup_device - Enable wake-up device GPEs.
50 * @sleep_state: ACPI state 49 * @sleep_state: ACPI system sleep state.
51 * Enable all wakup devices's GPE 50 *
51 * Enable all wake-up devices' GPEs, with the assumption that
52 * acpi_disable_all_gpes() was executed before, so we don't need to disable any
53 * GPEs here.
52 */ 54 */
53void acpi_enable_wakeup_device(u8 sleep_state) 55void acpi_enable_wakeup_device(u8 sleep_state)
54{ 56{
@@ -65,29 +67,22 @@ void acpi_enable_wakeup_device(u8 sleep_state)
65 if (!dev->wakeup.flags.valid) 67 if (!dev->wakeup.flags.valid)
66 continue; 68 continue;
67 69
68 /* If users want to disable run-wake GPE,
69 * we only disable it for wake and leave it for runtime
70 */
71 if ((!dev->wakeup.state.enabled && !dev->wakeup.prepare_count) 70 if ((!dev->wakeup.state.enabled && !dev->wakeup.prepare_count)
72 || sleep_state > (u32) dev->wakeup.sleep_state) { 71 || sleep_state > (u32) dev->wakeup.sleep_state)
73 if (dev->wakeup.flags.run_wake) {
74 /* set_gpe_type will disable GPE, leave it like that */
75 acpi_set_gpe_type(dev->wakeup.gpe_device,
76 dev->wakeup.gpe_number,
77 ACPI_GPE_TYPE_RUNTIME);
78 }
79 continue; 72 continue;
80 } 73
81 if (!dev->wakeup.flags.run_wake) 74 /* The wake-up power should have been enabled already. */
82 acpi_enable_gpe(dev->wakeup.gpe_device, 75 acpi_set_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
83 dev->wakeup.gpe_number); 76 ACPI_GPE_ENABLE);
84 } 77 }
85} 78}
86 79
87/** 80/**
88 * acpi_disable_wakeup_device - disable devices' wakeup capability 81 * acpi_disable_wakeup_device - Disable devices' wakeup capability.
89 * @sleep_state: ACPI state 82 * @sleep_state: ACPI system sleep state.
90 * Disable all wakup devices's GPE and wakeup capability 83 *
84 * This function only affects devices with wakeup.state.enabled set, which means
85 * that it reverses the changes made by acpi_enable_wakeup_device_prep().
91 */ 86 */
92void acpi_disable_wakeup_device(u8 sleep_state) 87void acpi_disable_wakeup_device(u8 sleep_state)
93{ 88{
@@ -97,30 +92,11 @@ void acpi_disable_wakeup_device(u8 sleep_state)
97 struct acpi_device *dev = 92 struct acpi_device *dev =
98 container_of(node, struct acpi_device, wakeup_list); 93 container_of(node, struct acpi_device, wakeup_list);
99 94
100 if (!dev->wakeup.flags.valid) 95 if (!dev->wakeup.flags.valid || !dev->wakeup.state.enabled
101 continue; 96 || (sleep_state > (u32) dev->wakeup.sleep_state))
102
103 if ((!dev->wakeup.state.enabled && !dev->wakeup.prepare_count)
104 || sleep_state > (u32) dev->wakeup.sleep_state) {
105 if (dev->wakeup.flags.run_wake) {
106 acpi_set_gpe_type(dev->wakeup.gpe_device,
107 dev->wakeup.gpe_number,
108 ACPI_GPE_TYPE_WAKE_RUN);
109 /* Re-enable it, since set_gpe_type will disable it */
110 acpi_enable_gpe(dev->wakeup.gpe_device,
111 dev->wakeup.gpe_number);
112 }
113 continue; 97 continue;
114 }
115 98
116 acpi_disable_wakeup_device_power(dev); 99 acpi_disable_wakeup_device_power(dev);
117 /* Never disable run-wake GPE */
118 if (!dev->wakeup.flags.run_wake) {
119 acpi_disable_gpe(dev->wakeup.gpe_device,
120 dev->wakeup.gpe_number);
121 acpi_clear_gpe(dev->wakeup.gpe_device,
122 dev->wakeup.gpe_number, ACPI_NOT_ISR);
123 }
124 } 100 }
125} 101}
126 102
@@ -134,13 +110,11 @@ int __init acpi_wakeup_device_init(void)
134 struct acpi_device, 110 struct acpi_device,
135 wakeup_list); 111 wakeup_list);
136 /* In case user doesn't load button driver */ 112 /* In case user doesn't load button driver */
137 if (!dev->wakeup.flags.run_wake || dev->wakeup.state.enabled) 113 if (!dev->wakeup.flags.always_enabled ||
114 dev->wakeup.state.enabled)
138 continue; 115 continue;
139 acpi_set_gpe_type(dev->wakeup.gpe_device, 116 acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
140 dev->wakeup.gpe_number, 117 ACPI_GPE_TYPE_WAKE);
141 ACPI_GPE_TYPE_WAKE_RUN);
142 acpi_enable_gpe(dev->wakeup.gpe_device,
143 dev->wakeup.gpe_number);
144 dev->wakeup.state.enabled = 1; 118 dev->wakeup.state.enabled = 1;
145 } 119 }
146 mutex_unlock(&acpi_device_lock); 120 mutex_unlock(&acpi_device_lock);
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index b34390347c16..a6a736a7dbf2 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -3082,8 +3082,16 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
3082 ahci_save_initial_config(pdev, hpriv); 3082 ahci_save_initial_config(pdev, hpriv);
3083 3083
3084 /* prepare host */ 3084 /* prepare host */
3085 if (hpriv->cap & HOST_CAP_NCQ) 3085 if (hpriv->cap & HOST_CAP_NCQ) {
3086 pi.flags |= ATA_FLAG_NCQ | ATA_FLAG_FPDMA_AA; 3086 pi.flags |= ATA_FLAG_NCQ;
3087 /* Auto-activate optimization is supposed to be supported on
3088 all AHCI controllers indicating NCQ support, but it seems
3089 to be broken at least on some NVIDIA MCP79 chipsets.
3090 Until we get info on which NVIDIA chipsets don't have this
3091 issue, if any, disable AA on all NVIDIA AHCIs. */
3092 if (pdev->vendor != PCI_VENDOR_ID_NVIDIA)
3093 pi.flags |= ATA_FLAG_FPDMA_AA;
3094 }
3087 3095
3088 if (hpriv->cap & HOST_CAP_PMP) 3096 if (hpriv->cap & HOST_CAP_PMP)
3089 pi.flags |= ATA_FLAG_PMP; 3097 pi.flags |= ATA_FLAG_PMP;
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index a5142bddef41..0e26a6f6fd48 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -25,6 +25,7 @@
25#include <linux/resume-trace.h> 25#include <linux/resume-trace.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/async.h>
28 29
29#include "../base.h" 30#include "../base.h"
30#include "power.h" 31#include "power.h"
@@ -42,6 +43,7 @@
42LIST_HEAD(dpm_list); 43LIST_HEAD(dpm_list);
43 44
44static DEFINE_MUTEX(dpm_list_mtx); 45static DEFINE_MUTEX(dpm_list_mtx);
46static pm_message_t pm_transition;
45 47
46/* 48/*
47 * Set once the preparation of devices for a PM transition has started, reset 49 * Set once the preparation of devices for a PM transition has started, reset
@@ -56,6 +58,7 @@ static bool transition_started;
56void device_pm_init(struct device *dev) 58void device_pm_init(struct device *dev)
57{ 59{
58 dev->power.status = DPM_ON; 60 dev->power.status = DPM_ON;
61 init_completion(&dev->power.completion);
59 pm_runtime_init(dev); 62 pm_runtime_init(dev);
60} 63}
61 64
@@ -111,6 +114,7 @@ void device_pm_remove(struct device *dev)
111 pr_debug("PM: Removing info for %s:%s\n", 114 pr_debug("PM: Removing info for %s:%s\n",
112 dev->bus ? dev->bus->name : "No Bus", 115 dev->bus ? dev->bus->name : "No Bus",
113 kobject_name(&dev->kobj)); 116 kobject_name(&dev->kobj));
117 complete_all(&dev->power.completion);
114 mutex_lock(&dpm_list_mtx); 118 mutex_lock(&dpm_list_mtx);
115 list_del_init(&dev->power.entry); 119 list_del_init(&dev->power.entry);
116 mutex_unlock(&dpm_list_mtx); 120 mutex_unlock(&dpm_list_mtx);
@@ -188,6 +192,31 @@ static void initcall_debug_report(struct device *dev, ktime_t calltime,
188} 192}
189 193
190/** 194/**
195 * dpm_wait - Wait for a PM operation to complete.
196 * @dev: Device to wait for.
197 * @async: If unset, wait only if the device's power.async_suspend flag is set.
198 */
199static void dpm_wait(struct device *dev, bool async)
200{
201 if (!dev)
202 return;
203
204 if (async || (pm_async_enabled && dev->power.async_suspend))
205 wait_for_completion(&dev->power.completion);
206}
207
208static int dpm_wait_fn(struct device *dev, void *async_ptr)
209{
210 dpm_wait(dev, *((bool *)async_ptr));
211 return 0;
212}
213
214static void dpm_wait_for_children(struct device *dev, bool async)
215{
216 device_for_each_child(dev, &async, dpm_wait_fn);
217}
218
219/**
191 * pm_op - Execute the PM operation appropriate for given PM event. 220 * pm_op - Execute the PM operation appropriate for given PM event.
192 * @dev: Device to handle. 221 * @dev: Device to handle.
193 * @ops: PM operations to choose from. 222 * @ops: PM operations to choose from.
@@ -271,8 +300,9 @@ static int pm_noirq_op(struct device *dev,
271 ktime_t calltime, delta, rettime; 300 ktime_t calltime, delta, rettime;
272 301
273 if (initcall_debug) { 302 if (initcall_debug) {
274 pr_info("calling %s_i+ @ %i\n", 303 pr_info("calling %s+ @ %i, parent: %s\n",
275 dev_name(dev), task_pid_nr(current)); 304 dev_name(dev), task_pid_nr(current),
305 dev->parent ? dev_name(dev->parent) : "none");
276 calltime = ktime_get(); 306 calltime = ktime_get();
277 } 307 }
278 308
@@ -468,16 +498,20 @@ static int legacy_resume(struct device *dev, int (*cb)(struct device *dev))
468 * device_resume - Execute "resume" callbacks for given device. 498 * device_resume - Execute "resume" callbacks for given device.
469 * @dev: Device to handle. 499 * @dev: Device to handle.
470 * @state: PM transition of the system being carried out. 500 * @state: PM transition of the system being carried out.
501 * @async: If true, the device is being resumed asynchronously.
471 */ 502 */
472static int device_resume(struct device *dev, pm_message_t state) 503static int device_resume(struct device *dev, pm_message_t state, bool async)
473{ 504{
474 int error = 0; 505 int error = 0;
475 506
476 TRACE_DEVICE(dev); 507 TRACE_DEVICE(dev);
477 TRACE_RESUME(0); 508 TRACE_RESUME(0);
478 509
510 dpm_wait(dev->parent, async);
479 down(&dev->sem); 511 down(&dev->sem);
480 512
513 dev->power.status = DPM_RESUMING;
514
481 if (dev->bus) { 515 if (dev->bus) {
482 if (dev->bus->pm) { 516 if (dev->bus->pm) {
483 pm_dev_dbg(dev, state, ""); 517 pm_dev_dbg(dev, state, "");
@@ -510,11 +544,29 @@ static int device_resume(struct device *dev, pm_message_t state)
510 } 544 }
511 End: 545 End:
512 up(&dev->sem); 546 up(&dev->sem);
547 complete_all(&dev->power.completion);
513 548
514 TRACE_RESUME(error); 549 TRACE_RESUME(error);
515 return error; 550 return error;
516} 551}
517 552
553static void async_resume(void *data, async_cookie_t cookie)
554{
555 struct device *dev = (struct device *)data;
556 int error;
557
558 error = device_resume(dev, pm_transition, true);
559 if (error)
560 pm_dev_err(dev, pm_transition, " async", error);
561 put_device(dev);
562}
563
564static bool is_async(struct device *dev)
565{
566 return dev->power.async_suspend && pm_async_enabled
567 && !pm_trace_is_enabled();
568}
569
518/** 570/**
519 * dpm_resume - Execute "resume" callbacks for non-sysdev devices. 571 * dpm_resume - Execute "resume" callbacks for non-sysdev devices.
520 * @state: PM transition of the system being carried out. 572 * @state: PM transition of the system being carried out.
@@ -525,21 +577,33 @@ static int device_resume(struct device *dev, pm_message_t state)
525static void dpm_resume(pm_message_t state) 577static void dpm_resume(pm_message_t state)
526{ 578{
527 struct list_head list; 579 struct list_head list;
580 struct device *dev;
528 ktime_t starttime = ktime_get(); 581 ktime_t starttime = ktime_get();
529 582
530 INIT_LIST_HEAD(&list); 583 INIT_LIST_HEAD(&list);
531 mutex_lock(&dpm_list_mtx); 584 mutex_lock(&dpm_list_mtx);
532 while (!list_empty(&dpm_list)) { 585 pm_transition = state;
533 struct device *dev = to_device(dpm_list.next); 586
587 list_for_each_entry(dev, &dpm_list, power.entry) {
588 if (dev->power.status < DPM_OFF)
589 continue;
590
591 INIT_COMPLETION(dev->power.completion);
592 if (is_async(dev)) {
593 get_device(dev);
594 async_schedule(async_resume, dev);
595 }
596 }
534 597
598 while (!list_empty(&dpm_list)) {
599 dev = to_device(dpm_list.next);
535 get_device(dev); 600 get_device(dev);
536 if (dev->power.status >= DPM_OFF) { 601 if (dev->power.status >= DPM_OFF && !is_async(dev)) {
537 int error; 602 int error;
538 603
539 dev->power.status = DPM_RESUMING;
540 mutex_unlock(&dpm_list_mtx); 604 mutex_unlock(&dpm_list_mtx);
541 605
542 error = device_resume(dev, state); 606 error = device_resume(dev, state, false);
543 607
544 mutex_lock(&dpm_list_mtx); 608 mutex_lock(&dpm_list_mtx);
545 if (error) 609 if (error)
@@ -554,6 +618,7 @@ static void dpm_resume(pm_message_t state)
554 } 618 }
555 list_splice(&list, &dpm_list); 619 list_splice(&list, &dpm_list);
556 mutex_unlock(&dpm_list_mtx); 620 mutex_unlock(&dpm_list_mtx);
621 async_synchronize_full();
557 dpm_show_time(starttime, state, NULL); 622 dpm_show_time(starttime, state, NULL);
558} 623}
559 624
@@ -731,17 +796,24 @@ static int legacy_suspend(struct device *dev, pm_message_t state,
731 return error; 796 return error;
732} 797}
733 798
799static int async_error;
800
734/** 801/**
735 * device_suspend - Execute "suspend" callbacks for given device. 802 * device_suspend - Execute "suspend" callbacks for given device.
736 * @dev: Device to handle. 803 * @dev: Device to handle.
737 * @state: PM transition of the system being carried out. 804 * @state: PM transition of the system being carried out.
805 * @async: If true, the device is being suspended asynchronously.
738 */ 806 */
739static int device_suspend(struct device *dev, pm_message_t state) 807static int __device_suspend(struct device *dev, pm_message_t state, bool async)
740{ 808{
741 int error = 0; 809 int error = 0;
742 810
811 dpm_wait_for_children(dev, async);
743 down(&dev->sem); 812 down(&dev->sem);
744 813
814 if (async_error)
815 goto End;
816
745 if (dev->class) { 817 if (dev->class) {
746 if (dev->class->pm) { 818 if (dev->class->pm) {
747 pm_dev_dbg(dev, state, "class "); 819 pm_dev_dbg(dev, state, "class ");
@@ -772,12 +844,44 @@ static int device_suspend(struct device *dev, pm_message_t state)
772 error = legacy_suspend(dev, state, dev->bus->suspend); 844 error = legacy_suspend(dev, state, dev->bus->suspend);
773 } 845 }
774 } 846 }
847
848 if (!error)
849 dev->power.status = DPM_OFF;
850
775 End: 851 End:
776 up(&dev->sem); 852 up(&dev->sem);
853 complete_all(&dev->power.completion);
777 854
778 return error; 855 return error;
779} 856}
780 857
858static void async_suspend(void *data, async_cookie_t cookie)
859{
860 struct device *dev = (struct device *)data;
861 int error;
862
863 error = __device_suspend(dev, pm_transition, true);
864 if (error) {
865 pm_dev_err(dev, pm_transition, " async", error);
866 async_error = error;
867 }
868
869 put_device(dev);
870}
871
872static int device_suspend(struct device *dev)
873{
874 INIT_COMPLETION(dev->power.completion);
875
876 if (pm_async_enabled && dev->power.async_suspend) {
877 get_device(dev);
878 async_schedule(async_suspend, dev);
879 return 0;
880 }
881
882 return __device_suspend(dev, pm_transition, false);
883}
884
781/** 885/**
782 * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. 886 * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices.
783 * @state: PM transition of the system being carried out. 887 * @state: PM transition of the system being carried out.
@@ -790,13 +894,15 @@ static int dpm_suspend(pm_message_t state)
790 894
791 INIT_LIST_HEAD(&list); 895 INIT_LIST_HEAD(&list);
792 mutex_lock(&dpm_list_mtx); 896 mutex_lock(&dpm_list_mtx);
897 pm_transition = state;
898 async_error = 0;
793 while (!list_empty(&dpm_list)) { 899 while (!list_empty(&dpm_list)) {
794 struct device *dev = to_device(dpm_list.prev); 900 struct device *dev = to_device(dpm_list.prev);
795 901
796 get_device(dev); 902 get_device(dev);
797 mutex_unlock(&dpm_list_mtx); 903 mutex_unlock(&dpm_list_mtx);
798 904
799 error = device_suspend(dev, state); 905 error = device_suspend(dev);
800 906
801 mutex_lock(&dpm_list_mtx); 907 mutex_lock(&dpm_list_mtx);
802 if (error) { 908 if (error) {
@@ -804,13 +910,17 @@ static int dpm_suspend(pm_message_t state)
804 put_device(dev); 910 put_device(dev);
805 break; 911 break;
806 } 912 }
807 dev->power.status = DPM_OFF;
808 if (!list_empty(&dev->power.entry)) 913 if (!list_empty(&dev->power.entry))
809 list_move(&dev->power.entry, &list); 914 list_move(&dev->power.entry, &list);
810 put_device(dev); 915 put_device(dev);
916 if (async_error)
917 break;
811 } 918 }
812 list_splice(&list, dpm_list.prev); 919 list_splice(&list, dpm_list.prev);
813 mutex_unlock(&dpm_list_mtx); 920 mutex_unlock(&dpm_list_mtx);
921 async_synchronize_full();
922 if (!error)
923 error = async_error;
814 if (!error) 924 if (!error)
815 dpm_show_time(starttime, state, NULL); 925 dpm_show_time(starttime, state, NULL);
816 return error; 926 return error;
@@ -936,3 +1046,14 @@ void __suspend_report_result(const char *function, void *fn, int ret)
936 printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret); 1046 printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret);
937} 1047}
938EXPORT_SYMBOL_GPL(__suspend_report_result); 1048EXPORT_SYMBOL_GPL(__suspend_report_result);
1049
1050/**
1051 * device_pm_wait_for_dev - Wait for suspend/resume of a device to complete.
1052 * @dev: Device to wait for.
1053 * @subordinate: Device that needs to wait for @dev.
1054 */
1055void device_pm_wait_for_dev(struct device *subordinate, struct device *dev)
1056{
1057 dpm_wait(dev, subordinate->power.async_suspend);
1058}
1059EXPORT_SYMBOL_GPL(device_pm_wait_for_dev);
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index b8fa1aa5225a..c0bd03c83b9c 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -12,10 +12,10 @@ static inline void pm_runtime_remove(struct device *dev) {}
12 12
13#ifdef CONFIG_PM_SLEEP 13#ifdef CONFIG_PM_SLEEP
14 14
15/* 15/* kernel/power/main.c */
16 * main.c 16extern int pm_async_enabled;
17 */
18 17
18/* drivers/base/power/main.c */
19extern struct list_head dpm_list; /* The active device list */ 19extern struct list_head dpm_list; /* The active device list */
20 20
21static inline struct device *to_device(struct list_head *entry) 21static inline struct device *to_device(struct list_head *entry)
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index f8b044e8aef7..626dd147b75f 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1011,6 +1011,50 @@ void pm_runtime_enable(struct device *dev)
1011EXPORT_SYMBOL_GPL(pm_runtime_enable); 1011EXPORT_SYMBOL_GPL(pm_runtime_enable);
1012 1012
1013/** 1013/**
1014 * pm_runtime_forbid - Block run-time PM of a device.
1015 * @dev: Device to handle.
1016 *
1017 * Increase the device's usage count and clear its power.runtime_auto flag,
1018 * so that it cannot be suspended at run time until pm_runtime_allow() is called
1019 * for it.
1020 */
1021void pm_runtime_forbid(struct device *dev)
1022{
1023 spin_lock_irq(&dev->power.lock);
1024 if (!dev->power.runtime_auto)
1025 goto out;
1026
1027 dev->power.runtime_auto = false;
1028 atomic_inc(&dev->power.usage_count);
1029 __pm_runtime_resume(dev, false);
1030
1031 out:
1032 spin_unlock_irq(&dev->power.lock);
1033}
1034EXPORT_SYMBOL_GPL(pm_runtime_forbid);
1035
1036/**
1037 * pm_runtime_allow - Unblock run-time PM of a device.
1038 * @dev: Device to handle.
1039 *
1040 * Decrease the device's usage count and set its power.runtime_auto flag.
1041 */
1042void pm_runtime_allow(struct device *dev)
1043{
1044 spin_lock_irq(&dev->power.lock);
1045 if (dev->power.runtime_auto)
1046 goto out;
1047
1048 dev->power.runtime_auto = true;
1049 if (atomic_dec_and_test(&dev->power.usage_count))
1050 __pm_runtime_idle(dev);
1051
1052 out:
1053 spin_unlock_irq(&dev->power.lock);
1054}
1055EXPORT_SYMBOL_GPL(pm_runtime_allow);
1056
1057/**
1014 * pm_runtime_init - Initialize run-time PM fields in given device object. 1058 * pm_runtime_init - Initialize run-time PM fields in given device object.
1015 * @dev: Device object to initialize. 1059 * @dev: Device object to initialize.
1016 */ 1060 */
@@ -1028,6 +1072,7 @@ void pm_runtime_init(struct device *dev)
1028 1072
1029 atomic_set(&dev->power.child_count, 0); 1073 atomic_set(&dev->power.child_count, 0);
1030 pm_suspend_ignore_children(dev, false); 1074 pm_suspend_ignore_children(dev, false);
1075 dev->power.runtime_auto = true;
1031 1076
1032 dev->power.request_pending = false; 1077 dev->power.request_pending = false;
1033 dev->power.request = RPM_REQ_NONE; 1078 dev->power.request = RPM_REQ_NONE;
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 596aeecfdffe..86fd9373447e 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -4,9 +4,25 @@
4 4
5#include <linux/device.h> 5#include <linux/device.h>
6#include <linux/string.h> 6#include <linux/string.h>
7#include <linux/pm_runtime.h>
7#include "power.h" 8#include "power.h"
8 9
9/* 10/*
11 * control - Report/change current runtime PM setting of the device
12 *
13 * Runtime power management of a device can be blocked with the help of
14 * this attribute. All devices have one of the following two values for
15 * the power/control file:
16 *
17 * + "auto\n" to allow the device to be power managed at run time;
18 * + "on\n" to prevent the device from being power managed at run time;
19 *
20 * The default for all devices is "auto", which means that devices may be
21 * subject to automatic power management, depending on their drivers.
22 * Changing this attribute to "on" prevents the driver from power managing
23 * the device at run time. Doing that while the device is suspended causes
24 * it to be woken up.
25 *
10 * wakeup - Report/change current wakeup option for device 26 * wakeup - Report/change current wakeup option for device
11 * 27 *
12 * Some devices support "wakeup" events, which are hardware signals 28 * Some devices support "wakeup" events, which are hardware signals
@@ -38,11 +54,61 @@
38 * wakeup events internally (unless they are disabled), keeping 54 * wakeup events internally (unless they are disabled), keeping
39 * their hardware in low power modes whenever they're unused. This 55 * their hardware in low power modes whenever they're unused. This
40 * saves runtime power, without requiring system-wide sleep states. 56 * saves runtime power, without requiring system-wide sleep states.
57 *
58 * async - Report/change current async suspend setting for the device
59 *
60 * Asynchronous suspend and resume of the device during system-wide power
61 * state transitions can be enabled by writing "enabled" to this file.
62 * Analogously, if "disabled" is written to this file, the device will be
63 * suspended and resumed synchronously.
64 *
65 * All devices have one of the following two values for power/async:
66 *
67 * + "enabled\n" to permit the asynchronous suspend/resume of the device;
68 * + "disabled\n" to forbid it;
69 *
70 * NOTE: It generally is unsafe to permit the asynchronous suspend/resume
71 * of a device unless it is certain that all of the PM dependencies of the
72 * device are known to the PM core. However, for some devices this
73 * attribute is set to "enabled" by bus type code or device drivers and in
74 * that cases it should be safe to leave the default value.
41 */ 75 */
42 76
43static const char enabled[] = "enabled"; 77static const char enabled[] = "enabled";
44static const char disabled[] = "disabled"; 78static const char disabled[] = "disabled";
45 79
80#ifdef CONFIG_PM_RUNTIME
81static const char ctrl_auto[] = "auto";
82static const char ctrl_on[] = "on";
83
84static ssize_t control_show(struct device *dev, struct device_attribute *attr,
85 char *buf)
86{
87 return sprintf(buf, "%s\n",
88 dev->power.runtime_auto ? ctrl_auto : ctrl_on);
89}
90
91static ssize_t control_store(struct device * dev, struct device_attribute *attr,
92 const char * buf, size_t n)
93{
94 char *cp;
95 int len = n;
96
97 cp = memchr(buf, '\n', n);
98 if (cp)
99 len = cp - buf;
100 if (len == sizeof ctrl_auto - 1 && strncmp(buf, ctrl_auto, len) == 0)
101 pm_runtime_allow(dev);
102 else if (len == sizeof ctrl_on - 1 && strncmp(buf, ctrl_on, len) == 0)
103 pm_runtime_forbid(dev);
104 else
105 return -EINVAL;
106 return n;
107}
108
109static DEVICE_ATTR(control, 0644, control_show, control_store);
110#endif
111
46static ssize_t 112static ssize_t
47wake_show(struct device * dev, struct device_attribute *attr, char * buf) 113wake_show(struct device * dev, struct device_attribute *attr, char * buf)
48{ 114{
@@ -77,9 +143,43 @@ wake_store(struct device * dev, struct device_attribute *attr,
77 143
78static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); 144static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
79 145
146#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
147static ssize_t async_show(struct device *dev, struct device_attribute *attr,
148 char *buf)
149{
150 return sprintf(buf, "%s\n",
151 device_async_suspend_enabled(dev) ? enabled : disabled);
152}
153
154static ssize_t async_store(struct device *dev, struct device_attribute *attr,
155 const char *buf, size_t n)
156{
157 char *cp;
158 int len = n;
159
160 cp = memchr(buf, '\n', n);
161 if (cp)
162 len = cp - buf;
163 if (len == sizeof enabled - 1 && strncmp(buf, enabled, len) == 0)
164 device_enable_async_suspend(dev);
165 else if (len == sizeof disabled - 1 && strncmp(buf, disabled, len) == 0)
166 device_disable_async_suspend(dev);
167 else
168 return -EINVAL;
169 return n;
170}
171
172static DEVICE_ATTR(async, 0644, async_show, async_store);
173#endif /* CONFIG_PM_SLEEP_ADVANCED_DEBUG */
80 174
81static struct attribute * power_attrs[] = { 175static struct attribute * power_attrs[] = {
176#ifdef CONFIG_PM_RUNTIME
177 &dev_attr_control.attr,
178#endif
82 &dev_attr_wakeup.attr, 179 &dev_attr_wakeup.attr,
180#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
181 &dev_attr_async.attr,
182#endif
83 NULL, 183 NULL,
84}; 184};
85static struct attribute_group pm_attr_group = { 185static struct attribute_group pm_attr_group = {
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index a5af1d6dda8b..e35cf59cbfde 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1470,8 +1470,6 @@ repeat:
1470 1470
1471void do_fd_request(struct request_queue * q) 1471void do_fd_request(struct request_queue * q)
1472{ 1472{
1473 unsigned long flags;
1474
1475 DPRINT(("do_fd_request for pid %d\n",current->pid)); 1473 DPRINT(("do_fd_request for pid %d\n",current->pid));
1476 while( fdc_busy ) sleep_on( &fdc_wait ); 1474 while( fdc_busy ) sleep_on( &fdc_wait );
1477 fdc_busy = 1; 1475 fdc_busy = 1;
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 8f569e3df890..821c2833f9cf 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -864,7 +864,7 @@ static int __devinit swim_probe(struct platform_device *dev)
864 struct swim_priv *swd; 864 struct swim_priv *swd;
865 int ret; 865 int ret;
866 866
867 res = platform_get_resource_byname(dev, IORESOURCE_MEM, "swim-regs"); 867 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
868 if (!res) { 868 if (!res) {
869 ret = -ENODEV; 869 ret = -ENODEV;
870 goto out; 870 goto out;
@@ -942,7 +942,7 @@ static int __devexit swim_remove(struct platform_device *dev)
942 942
943 iounmap(swd->base); 943 iounmap(swd->base);
944 944
945 res = platform_get_resource_byname(dev, IORESOURCE_MEM, "swim-regs"); 945 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
946 if (res) 946 if (res)
947 release_mem_region(res->start, resource_size(res)); 947 release_mem_region(res->start, resource_size(res));
948 948
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index a8c8b56b275e..1b3def1e8591 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -28,6 +28,9 @@
28 * All disk operations are performed by sending messages back and forth to 28 * All disk operations are performed by sending messages back and forth to
29 * the OS/400 partition. 29 * the OS/400 partition.
30 */ 30 */
31
32#define pr_fmt(fmt) "viod: " fmt
33
31#include <linux/major.h> 34#include <linux/major.h>
32#include <linux/fs.h> 35#include <linux/fs.h>
33#include <linux/module.h> 36#include <linux/module.h>
@@ -63,9 +66,6 @@ MODULE_LICENSE("GPL");
63 66
64#define VIOD_VERS "1.64" 67#define VIOD_VERS "1.64"
65 68
66#define VIOD_KERN_WARNING KERN_WARNING "viod: "
67#define VIOD_KERN_INFO KERN_INFO "viod: "
68
69enum { 69enum {
70 PARTITION_SHIFT = 3, 70 PARTITION_SHIFT = 3,
71 MAX_DISKNO = HVMAXARCHITECTEDVIRTUALDISKS, 71 MAX_DISKNO = HVMAXARCHITECTEDVIRTUALDISKS,
@@ -156,7 +156,7 @@ static int viodasd_open(struct block_device *bdev, fmode_t mode)
156 ((u64)DEVICE_NO(d) << 48) | ((u64)flags << 32), 156 ((u64)DEVICE_NO(d) << 48) | ((u64)flags << 32),
157 0, 0, 0); 157 0, 0, 0);
158 if (hvrc != 0) { 158 if (hvrc != 0) {
159 printk(VIOD_KERN_WARNING "HV open failed %d\n", (int)hvrc); 159 pr_warning("HV open failed %d\n", (int)hvrc);
160 return -EIO; 160 return -EIO;
161 } 161 }
162 162
@@ -167,9 +167,8 @@ static int viodasd_open(struct block_device *bdev, fmode_t mode)
167 const struct vio_error_entry *err = 167 const struct vio_error_entry *err =
168 vio_lookup_rc(viodasd_err_table, we.sub_result); 168 vio_lookup_rc(viodasd_err_table, we.sub_result);
169 169
170 printk(VIOD_KERN_WARNING 170 pr_warning("bad rc opening disk: %d:0x%04x (%s)\n",
171 "bad rc opening disk: %d:0x%04x (%s)\n", 171 (int)we.rc, we.sub_result, err->msg);
172 (int)we.rc, we.sub_result, err->msg);
173 return -EIO; 172 return -EIO;
174 } 173 }
175 174
@@ -195,8 +194,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
195 ((u64)DEVICE_NO(d) << 48) /* | ((u64)flags << 32) */, 194 ((u64)DEVICE_NO(d) << 48) /* | ((u64)flags << 32) */,
196 0, 0, 0); 195 0, 0, 0);
197 if (hvrc != 0) 196 if (hvrc != 0)
198 printk(VIOD_KERN_WARNING "HV close call failed %d\n", 197 pr_warning("HV close call failed %d\n", (int)hvrc);
199 (int)hvrc);
200 return 0; 198 return 0;
201} 199}
202 200
@@ -288,8 +286,7 @@ static int send_request(struct request *req)
288 bevent = (struct vioblocklpevent *) 286 bevent = (struct vioblocklpevent *)
289 vio_get_event_buffer(viomajorsubtype_blockio); 287 vio_get_event_buffer(viomajorsubtype_blockio);
290 if (bevent == NULL) { 288 if (bevent == NULL) {
291 printk(VIOD_KERN_WARNING 289 pr_warning("error allocating disk event buffer\n");
292 "error allocating disk event buffer\n");
293 goto error_ret; 290 goto error_ret;
294 } 291 }
295 292
@@ -333,9 +330,8 @@ static int send_request(struct request *req)
333 } 330 }
334 331
335 if (hvrc != HvLpEvent_Rc_Good) { 332 if (hvrc != HvLpEvent_Rc_Good) {
336 printk(VIOD_KERN_WARNING 333 pr_warning("error sending disk event to OS/400 (rc %d)\n",
337 "error sending disk event to OS/400 (rc %d)\n", 334 (int)hvrc);
338 (int)hvrc);
339 goto error_ret; 335 goto error_ret;
340 } 336 }
341 spin_unlock_irqrestore(&viodasd_spinlock, flags); 337 spin_unlock_irqrestore(&viodasd_spinlock, flags);
@@ -402,7 +398,7 @@ retry:
402 ((u64)dev_no << 48) | ((u64)flags<< 32), 398 ((u64)dev_no << 48) | ((u64)flags<< 32),
403 0, 0, 0); 399 0, 0, 0);
404 if (hvrc != 0) { 400 if (hvrc != 0) {
405 printk(VIOD_KERN_WARNING "bad rc on HV open %d\n", (int)hvrc); 401 pr_warning("bad rc on HV open %d\n", (int)hvrc);
406 return 0; 402 return 0;
407 } 403 }
408 404
@@ -416,9 +412,8 @@ retry:
416 goto retry; 412 goto retry;
417 } 413 }
418 if (we.max_disk > (MAX_DISKNO - 1)) { 414 if (we.max_disk > (MAX_DISKNO - 1)) {
419 printk_once(VIOD_KERN_INFO 415 printk_once(KERN_INFO pr_fmt("Only examining the first %d of %d disks connected\n"),
420 "Only examining the first %d of %d disks connected\n", 416 MAX_DISKNO, we.max_disk + 1);
421 MAX_DISKNO, we.max_disk + 1);
422 } 417 }
423 418
424 /* Send the close event to OS/400. We DON'T expect a response */ 419 /* Send the close event to OS/400. We DON'T expect a response */
@@ -432,17 +427,15 @@ retry:
432 ((u64)dev_no << 48) | ((u64)flags << 32), 427 ((u64)dev_no << 48) | ((u64)flags << 32),
433 0, 0, 0); 428 0, 0, 0);
434 if (hvrc != 0) { 429 if (hvrc != 0) {
435 printk(VIOD_KERN_WARNING 430 pr_warning("bad rc sending event to OS/400 %d\n", (int)hvrc);
436 "bad rc sending event to OS/400 %d\n", (int)hvrc);
437 return 0; 431 return 0;
438 } 432 }
439 433
440 if (d->dev == NULL) { 434 if (d->dev == NULL) {
441 /* this is when we reprobe for new disks */ 435 /* this is when we reprobe for new disks */
442 if (vio_create_viodasd(dev_no) == NULL) { 436 if (vio_create_viodasd(dev_no) == NULL) {
443 printk(VIOD_KERN_WARNING 437 pr_warning("cannot allocate virtual device for disk %d\n",
444 "cannot allocate virtual device for disk %d\n", 438 dev_no);
445 dev_no);
446 return 0; 439 return 0;
447 } 440 }
448 /* 441 /*
@@ -457,15 +450,13 @@ retry:
457 spin_lock_init(&d->q_lock); 450 spin_lock_init(&d->q_lock);
458 q = blk_init_queue(do_viodasd_request, &d->q_lock); 451 q = blk_init_queue(do_viodasd_request, &d->q_lock);
459 if (q == NULL) { 452 if (q == NULL) {
460 printk(VIOD_KERN_WARNING "cannot allocate queue for disk %d\n", 453 pr_warning("cannot allocate queue for disk %d\n", dev_no);
461 dev_no);
462 return 0; 454 return 0;
463 } 455 }
464 g = alloc_disk(1 << PARTITION_SHIFT); 456 g = alloc_disk(1 << PARTITION_SHIFT);
465 if (g == NULL) { 457 if (g == NULL) {
466 printk(VIOD_KERN_WARNING 458 pr_warning("cannot allocate disk structure for disk %d\n",
467 "cannot allocate disk structure for disk %d\n", 459 dev_no);
468 dev_no);
469 blk_cleanup_queue(q); 460 blk_cleanup_queue(q);
470 return 0; 461 return 0;
471 } 462 }
@@ -489,13 +480,12 @@ retry:
489 g->driverfs_dev = d->dev; 480 g->driverfs_dev = d->dev;
490 set_capacity(g, d->size >> 9); 481 set_capacity(g, d->size >> 9);
491 482
492 printk(VIOD_KERN_INFO "disk %d: %lu sectors (%lu MB) " 483 pr_info("disk %d: %lu sectors (%lu MB) CHS=%d/%d/%d sector size %d%s\n",
493 "CHS=%d/%d/%d sector size %d%s\n", 484 dev_no, (unsigned long)(d->size >> 9),
494 dev_no, (unsigned long)(d->size >> 9), 485 (unsigned long)(d->size >> 20),
495 (unsigned long)(d->size >> 20), 486 (int)d->cylinders, (int)d->tracks,
496 (int)d->cylinders, (int)d->tracks, 487 (int)d->sectors, (int)d->bytes_per_sector,
497 (int)d->sectors, (int)d->bytes_per_sector, 488 d->read_only ? " (RO)" : "");
498 d->read_only ? " (RO)" : "");
499 489
500 /* register us in the global list */ 490 /* register us in the global list */
501 add_disk(g); 491 add_disk(g);
@@ -580,8 +570,8 @@ static int viodasd_handle_read_write(struct vioblocklpevent *bevent)
580 if (error) { 570 if (error) {
581 const struct vio_error_entry *err; 571 const struct vio_error_entry *err;
582 err = vio_lookup_rc(viodasd_err_table, bevent->sub_result); 572 err = vio_lookup_rc(viodasd_err_table, bevent->sub_result);
583 printk(VIOD_KERN_WARNING "read/write error %d:0x%04x (%s)\n", 573 pr_warning("read/write error %d:0x%04x (%s)\n",
584 event->xRc, bevent->sub_result, err->msg); 574 event->xRc, bevent->sub_result, err->msg);
585 num_sect = blk_rq_sectors(req); 575 num_sect = blk_rq_sectors(req);
586 } 576 }
587 qlock = req->q->queue_lock; 577 qlock = req->q->queue_lock;
@@ -606,8 +596,7 @@ static void handle_block_event(struct HvLpEvent *event)
606 return; 596 return;
607 /* First, we should NEVER get an int here...only acks */ 597 /* First, we should NEVER get an int here...only acks */
608 if (hvlpevent_is_int(event)) { 598 if (hvlpevent_is_int(event)) {
609 printk(VIOD_KERN_WARNING 599 pr_warning("Yikes! got an int in viodasd event handler!\n");
610 "Yikes! got an int in viodasd event handler!\n");
611 if (hvlpevent_need_ack(event)) { 600 if (hvlpevent_need_ack(event)) {
612 event->xRc = HvLpEvent_Rc_InvalidSubtype; 601 event->xRc = HvLpEvent_Rc_InvalidSubtype;
613 HvCallEvent_ackLpEvent(event); 602 HvCallEvent_ackLpEvent(event);
@@ -650,7 +639,7 @@ static void handle_block_event(struct HvLpEvent *event)
650 break; 639 break;
651 640
652 default: 641 default:
653 printk(VIOD_KERN_WARNING "invalid subtype!"); 642 pr_warning("invalid subtype!");
654 if (hvlpevent_need_ack(event)) { 643 if (hvlpevent_need_ack(event)) {
655 event->xRc = HvLpEvent_Rc_InvalidSubtype; 644 event->xRc = HvLpEvent_Rc_InvalidSubtype;
656 HvCallEvent_ackLpEvent(event); 645 HvCallEvent_ackLpEvent(event);
@@ -739,29 +728,26 @@ static int __init viodasd_init(void)
739 vio_set_hostlp(); 728 vio_set_hostlp();
740 729
741 if (viopath_hostLp == HvLpIndexInvalid) { 730 if (viopath_hostLp == HvLpIndexInvalid) {
742 printk(VIOD_KERN_WARNING "invalid hosting partition\n"); 731 pr_warning("invalid hosting partition\n");
743 rc = -EIO; 732 rc = -EIO;
744 goto early_fail; 733 goto early_fail;
745 } 734 }
746 735
747 printk(VIOD_KERN_INFO "vers " VIOD_VERS ", hosting partition %d\n", 736 pr_info("vers " VIOD_VERS ", hosting partition %d\n", viopath_hostLp);
748 viopath_hostLp);
749 737
750 /* register the block device */ 738 /* register the block device */
751 rc = register_blkdev(VIODASD_MAJOR, VIOD_GENHD_NAME); 739 rc = register_blkdev(VIODASD_MAJOR, VIOD_GENHD_NAME);
752 if (rc) { 740 if (rc) {
753 printk(VIOD_KERN_WARNING 741 pr_warning("Unable to get major number %d for %s\n",
754 "Unable to get major number %d for %s\n", 742 VIODASD_MAJOR, VIOD_GENHD_NAME);
755 VIODASD_MAJOR, VIOD_GENHD_NAME);
756 goto early_fail; 743 goto early_fail;
757 } 744 }
758 /* Actually open the path to the hosting partition */ 745 /* Actually open the path to the hosting partition */
759 rc = viopath_open(viopath_hostLp, viomajorsubtype_blockio, 746 rc = viopath_open(viopath_hostLp, viomajorsubtype_blockio,
760 VIOMAXREQ + 2); 747 VIOMAXREQ + 2);
761 if (rc) { 748 if (rc) {
762 printk(VIOD_KERN_WARNING 749 pr_warning("error opening path to host partition %d\n",
763 "error opening path to host partition %d\n", 750 viopath_hostLp);
764 viopath_hostLp);
765 goto unregister_blk; 751 goto unregister_blk;
766 } 752 }
767 753
@@ -770,7 +756,7 @@ static int __init viodasd_init(void)
770 756
771 rc = vio_register_driver(&viodasd_driver); 757 rc = vio_register_driver(&viodasd_driver);
772 if (rc) { 758 if (rc) {
773 printk(VIOD_KERN_WARNING "vio_register_driver failed\n"); 759 pr_warning("vio_register_driver failed\n");
774 goto unset_handler; 760 goto unset_handler;
775 } 761 }
776 762
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 51042f0ba7e1..7eff828b2117 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -243,10 +243,12 @@ static int index_to_minor(int index)
243static int __devinit virtblk_probe(struct virtio_device *vdev) 243static int __devinit virtblk_probe(struct virtio_device *vdev)
244{ 244{
245 struct virtio_blk *vblk; 245 struct virtio_blk *vblk;
246 struct request_queue *q;
246 int err; 247 int err;
247 u64 cap; 248 u64 cap;
248 u32 v; 249 u32 v, blk_size, sg_elems, opt_io_size;
249 u32 blk_size, sg_elems; 250 u16 min_io_size;
251 u8 physical_block_exp, alignment_offset;
250 252
251 if (index_to_minor(index) >= 1 << MINORBITS) 253 if (index_to_minor(index) >= 1 << MINORBITS)
252 return -ENOSPC; 254 return -ENOSPC;
@@ -293,13 +295,13 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
293 goto out_mempool; 295 goto out_mempool;
294 } 296 }
295 297
296 vblk->disk->queue = blk_init_queue(do_virtblk_request, &vblk->lock); 298 q = vblk->disk->queue = blk_init_queue(do_virtblk_request, &vblk->lock);
297 if (!vblk->disk->queue) { 299 if (!q) {
298 err = -ENOMEM; 300 err = -ENOMEM;
299 goto out_put_disk; 301 goto out_put_disk;
300 } 302 }
301 303
302 vblk->disk->queue->queuedata = vblk; 304 q->queuedata = vblk;
303 305
304 if (index < 26) { 306 if (index < 26) {
305 sprintf(vblk->disk->disk_name, "vd%c", 'a' + index % 26); 307 sprintf(vblk->disk->disk_name, "vd%c", 'a' + index % 26);
@@ -323,10 +325,10 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
323 325
324 /* If barriers are supported, tell block layer that queue is ordered */ 326 /* If barriers are supported, tell block layer that queue is ordered */
325 if (virtio_has_feature(vdev, VIRTIO_BLK_F_FLUSH)) 327 if (virtio_has_feature(vdev, VIRTIO_BLK_F_FLUSH))
326 blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_DRAIN_FLUSH, 328 blk_queue_ordered(q, QUEUE_ORDERED_DRAIN_FLUSH,
327 virtblk_prepare_flush); 329 virtblk_prepare_flush);
328 else if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER)) 330 else if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER))
329 blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL); 331 blk_queue_ordered(q, QUEUE_ORDERED_TAG, NULL);
330 332
331 /* If disk is read-only in the host, the guest should obey */ 333 /* If disk is read-only in the host, the guest should obey */
332 if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO)) 334 if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO))
@@ -345,14 +347,14 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
345 set_capacity(vblk->disk, cap); 347 set_capacity(vblk->disk, cap);
346 348
347 /* We can handle whatever the host told us to handle. */ 349 /* We can handle whatever the host told us to handle. */
348 blk_queue_max_phys_segments(vblk->disk->queue, vblk->sg_elems-2); 350 blk_queue_max_phys_segments(q, vblk->sg_elems-2);
349 blk_queue_max_hw_segments(vblk->disk->queue, vblk->sg_elems-2); 351 blk_queue_max_hw_segments(q, vblk->sg_elems-2);
350 352
351 /* No need to bounce any requests */ 353 /* No need to bounce any requests */
352 blk_queue_bounce_limit(vblk->disk->queue, BLK_BOUNCE_ANY); 354 blk_queue_bounce_limit(q, BLK_BOUNCE_ANY);
353 355
354 /* No real sector limit. */ 356 /* No real sector limit. */
355 blk_queue_max_sectors(vblk->disk->queue, -1U); 357 blk_queue_max_sectors(q, -1U);
356 358
357 /* Host can optionally specify maximum segment size and number of 359 /* Host can optionally specify maximum segment size and number of
358 * segments. */ 360 * segments. */
@@ -360,16 +362,45 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
360 offsetof(struct virtio_blk_config, size_max), 362 offsetof(struct virtio_blk_config, size_max),
361 &v); 363 &v);
362 if (!err) 364 if (!err)
363 blk_queue_max_segment_size(vblk->disk->queue, v); 365 blk_queue_max_segment_size(q, v);
364 else 366 else
365 blk_queue_max_segment_size(vblk->disk->queue, -1U); 367 blk_queue_max_segment_size(q, -1U);
366 368
367 /* Host can optionally specify the block size of the device */ 369 /* Host can optionally specify the block size of the device */
368 err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE, 370 err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE,
369 offsetof(struct virtio_blk_config, blk_size), 371 offsetof(struct virtio_blk_config, blk_size),
370 &blk_size); 372 &blk_size);
371 if (!err) 373 if (!err)
372 blk_queue_logical_block_size(vblk->disk->queue, blk_size); 374 blk_queue_logical_block_size(q, blk_size);
375 else
376 blk_size = queue_logical_block_size(q);
377
378 /* Use topology information if available */
379 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
380 offsetof(struct virtio_blk_config, physical_block_exp),
381 &physical_block_exp);
382 if (!err && physical_block_exp)
383 blk_queue_physical_block_size(q,
384 blk_size * (1 << physical_block_exp));
385
386 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
387 offsetof(struct virtio_blk_config, alignment_offset),
388 &alignment_offset);
389 if (!err && alignment_offset)
390 blk_queue_alignment_offset(q, blk_size * alignment_offset);
391
392 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
393 offsetof(struct virtio_blk_config, min_io_size),
394 &min_io_size);
395 if (!err && min_io_size)
396 blk_queue_io_min(q, blk_size * min_io_size);
397
398 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
399 offsetof(struct virtio_blk_config, opt_io_size),
400 &opt_io_size);
401 if (!err && opt_io_size)
402 blk_queue_io_opt(q, blk_size * opt_io_size);
403
373 404
374 add_disk(vblk->disk); 405 add_disk(vblk->disk);
375 return 0; 406 return 0;
@@ -412,7 +443,7 @@ static struct virtio_device_id id_table[] = {
412static unsigned int features[] = { 443static unsigned int features[] = {
413 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, 444 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX,
414 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, 445 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
415 VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_FLUSH 446 VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_TOPOLOGY
416}; 447};
417 448
418/* 449/*
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index e023682be2c4..3141dd3b6e53 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -666,6 +666,14 @@ config VIRTIO_CONSOLE
666 help 666 help
667 Virtio console for use with lguest and other hypervisors. 667 Virtio console for use with lguest and other hypervisors.
668 668
669 Also serves as a general-purpose serial device for data
670 transfer between the guest and host. Character devices at
671 /dev/vportNpn will be created when corresponding ports are
672 found, where N is the device number and n is the port number
673 within that device. If specified by the host, a sysfs
674 attribute called 'name' will be populated with a name for
675 the port which can be used by udev scripts to create a
676 symlink to the device.
669 677
670config HVCS 678config HVCS
671 tristate "IBM Hypervisor Virtual Console Server support" 679 tristate "IBM Hypervisor Virtual Console Server support"
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 3999a5f25f38..8a713f1e9653 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -8,6 +8,7 @@
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/pagemap.h> 9#include <linux/pagemap.h>
10#include <linux/agp_backend.h> 10#include <linux/agp_backend.h>
11#include <asm/smp.h>
11#include "agp.h" 12#include "agp.h"
12 13
13/* 14/*
@@ -815,12 +816,6 @@ static void intel_i830_setup_flush(void)
815 intel_i830_fini_flush(); 816 intel_i830_fini_flush();
816} 817}
817 818
818static void
819do_wbinvd(void *null)
820{
821 wbinvd();
822}
823
824/* The chipset_flush interface needs to get data that has already been 819/* The chipset_flush interface needs to get data that has already been
825 * flushed out of the CPU all the way out to main memory, because the GPU 820 * flushed out of the CPU all the way out to main memory, because the GPU
826 * doesn't snoop those buffers. 821 * doesn't snoop those buffers.
@@ -837,12 +832,10 @@ static void intel_i830_chipset_flush(struct agp_bridge_data *bridge)
837 832
838 memset(pg, 0, 1024); 833 memset(pg, 0, 1024);
839 834
840 if (cpu_has_clflush) { 835 if (cpu_has_clflush)
841 clflush_cache_range(pg, 1024); 836 clflush_cache_range(pg, 1024);
842 } else { 837 else if (wbinvd_on_all_cpus() != 0)
843 if (on_each_cpu(do_wbinvd, NULL, 1) != 0) 838 printk(KERN_ERR "Timed out waiting for cache flush.\n");
844 printk(KERN_ERR "Timed out waiting for cache flush.\n");
845 }
846} 839}
847 840
848/* The intel i830 automatically initializes the agp aperture during POST. 841/* The intel i830 automatically initializes the agp aperture during POST.
diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c
index 0afc8b82212e..5fe4631e2a61 100644
--- a/drivers/char/hvc_beat.c
+++ b/drivers/char/hvc_beat.c
@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt)
84 return cnt; 84 return cnt;
85} 85}
86 86
87static struct hv_ops hvc_beat_get_put_ops = { 87static const struct hv_ops hvc_beat_get_put_ops = {
88 .get_chars = hvc_beat_get_chars, 88 .get_chars = hvc_beat_get_chars,
89 .put_chars = hvc_beat_put_chars, 89 .put_chars = hvc_beat_put_chars,
90}; 90};
@@ -99,7 +99,7 @@ static int hvc_beat_config(char *p)
99 99
100static int __init hvc_beat_console_init(void) 100static int __init hvc_beat_console_init(void)
101{ 101{
102 if (hvc_beat_useit && machine_is_compatible("Beat")) { 102 if (hvc_beat_useit && of_machine_is_compatible("Beat")) {
103 hvc_instantiate(0, 0, &hvc_beat_get_put_ops); 103 hvc_instantiate(0, 0, &hvc_beat_get_put_ops);
104 } 104 }
105 return 0; 105 return 0;
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 416d3423150d..4c3b59be286a 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
125 * console interfaces but can still be used as a tty device. This has to be 125 * console interfaces but can still be used as a tty device. This has to be
126 * static because kmalloc will not work during early console init. 126 * static because kmalloc will not work during early console init.
127 */ 127 */
128static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES]; 128static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
129static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] = 129static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
130 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1}; 130 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
131 131
@@ -247,7 +247,7 @@ static void destroy_hvc_struct(struct kref *kref)
247 * vty adapters do NOT get an hvc_instantiate() callback since they 247 * vty adapters do NOT get an hvc_instantiate() callback since they
248 * appear after early console init. 248 * appear after early console init.
249 */ 249 */
250int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops) 250int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
251{ 251{
252 struct hvc_struct *hp; 252 struct hvc_struct *hp;
253 253
@@ -748,8 +748,9 @@ static const struct tty_operations hvc_ops = {
748 .chars_in_buffer = hvc_chars_in_buffer, 748 .chars_in_buffer = hvc_chars_in_buffer,
749}; 749};
750 750
751struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data, 751struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
752 struct hv_ops *ops, int outbuf_size) 752 const struct hv_ops *ops,
753 int outbuf_size)
753{ 754{
754 struct hvc_struct *hp; 755 struct hvc_struct *hp;
755 int i; 756 int i;
diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
index 10950ca706d8..54381eba4e4a 100644
--- a/drivers/char/hvc_console.h
+++ b/drivers/char/hvc_console.h
@@ -55,7 +55,7 @@ struct hvc_struct {
55 int outbuf_size; 55 int outbuf_size;
56 int n_outbuf; 56 int n_outbuf;
57 uint32_t vtermno; 57 uint32_t vtermno;
58 struct hv_ops *ops; 58 const struct hv_ops *ops;
59 int irq_requested; 59 int irq_requested;
60 int data; 60 int data;
61 struct winsize ws; 61 struct winsize ws;
@@ -76,11 +76,12 @@ struct hv_ops {
76}; 76};
77 77
78/* Register a vterm and a slot index for use as a console (console_init) */ 78/* Register a vterm and a slot index for use as a console (console_init) */
79extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops); 79extern int hvc_instantiate(uint32_t vtermno, int index,
80 const struct hv_ops *ops);
80 81
81/* register a vterm for hvc tty operation (module_init or hotplug add) */ 82/* register a vterm for hvc tty operation (module_init or hotplug add) */
82extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data, 83extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data,
83 struct hv_ops *ops, int outbuf_size); 84 const struct hv_ops *ops, int outbuf_size);
84/* remove a vterm from hvc tty operation (module_exit or hotplug remove) */ 85/* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
85extern int hvc_remove(struct hvc_struct *hp); 86extern int hvc_remove(struct hvc_struct *hp);
86 87
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
index 936d05bf37fa..fd0242676a2a 100644
--- a/drivers/char/hvc_iseries.c
+++ b/drivers/char/hvc_iseries.c
@@ -197,7 +197,7 @@ done:
197 return sent; 197 return sent;
198} 198}
199 199
200static struct hv_ops hvc_get_put_ops = { 200static const struct hv_ops hvc_get_put_ops = {
201 .get_chars = get_chars, 201 .get_chars = get_chars,
202 .put_chars = put_chars, 202 .put_chars = put_chars,
203 .notifier_add = notifier_add_irq, 203 .notifier_add = notifier_add_irq,
diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
index fe62bd0e17b7..21681a81cc35 100644
--- a/drivers/char/hvc_iucv.c
+++ b/drivers/char/hvc_iucv.c
@@ -922,7 +922,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev)
922 922
923 923
924/* HVC operations */ 924/* HVC operations */
925static struct hv_ops hvc_iucv_ops = { 925static const struct hv_ops hvc_iucv_ops = {
926 .get_chars = hvc_iucv_get_chars, 926 .get_chars = hvc_iucv_get_chars,
927 .put_chars = hvc_iucv_put_chars, 927 .put_chars = hvc_iucv_put_chars,
928 .notifier_add = hvc_iucv_notifier_add, 928 .notifier_add = hvc_iucv_notifier_add,
diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
index 88590d040046..61c4a61558d9 100644
--- a/drivers/char/hvc_rtas.c
+++ b/drivers/char/hvc_rtas.c
@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
71 return i; 71 return i;
72} 72}
73 73
74static struct hv_ops hvc_rtas_get_put_ops = { 74static const struct hv_ops hvc_rtas_get_put_ops = {
75 .get_chars = hvc_rtas_read_console, 75 .get_chars = hvc_rtas_read_console,
76 .put_chars = hvc_rtas_write_console, 76 .put_chars = hvc_rtas_write_console,
77}; 77};
diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c
index bd63ba878a56..b0957e61a7be 100644
--- a/drivers/char/hvc_udbg.c
+++ b/drivers/char/hvc_udbg.c
@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
58 return i; 58 return i;
59} 59}
60 60
61static struct hv_ops hvc_udbg_ops = { 61static const struct hv_ops hvc_udbg_ops = {
62 .get_chars = hvc_udbg_get, 62 .get_chars = hvc_udbg_get,
63 .put_chars = hvc_udbg_put, 63 .put_chars = hvc_udbg_put,
64}; 64};
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
index 10be343d6ae7..27370e99c66f 100644
--- a/drivers/char/hvc_vio.c
+++ b/drivers/char/hvc_vio.c
@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
77 return got; 77 return got;
78} 78}
79 79
80static struct hv_ops hvc_get_put_ops = { 80static const struct hv_ops hvc_get_put_ops = {
81 .get_chars = filtered_get_chars, 81 .get_chars = filtered_get_chars,
82 .put_chars = hvc_put_chars, 82 .put_chars = hvc_put_chars,
83 .notifier_add = notifier_add_irq, 83 .notifier_add = notifier_add_irq,
diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c
index b1a71638c772..60446f82a3fc 100644
--- a/drivers/char/hvc_xen.c
+++ b/drivers/char/hvc_xen.c
@@ -122,7 +122,7 @@ static int read_console(uint32_t vtermno, char *buf, int len)
122 return recv; 122 return recv;
123} 123}
124 124
125static struct hv_ops hvc_ops = { 125static const struct hv_ops hvc_ops = {
126 .get_chars = read_console, 126 .get_chars = read_console,
127 .put_chars = write_console, 127 .put_chars = write_console,
128 .notifier_add = notifier_add_irq, 128 .notifier_add = notifier_add_irq,
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 87060266ef91..6ea1014697d1 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -186,3 +186,15 @@ config HW_RANDOM_MXC_RNGA
186 module will be called mxc-rnga. 186 module will be called mxc-rnga.
187 187
188 If unsure, say Y. 188 If unsure, say Y.
189
190config HW_RANDOM_NOMADIK
191 tristate "ST-Ericsson Nomadik Random Number Generator support"
192 depends on HW_RANDOM && PLAT_NOMADIK
193 ---help---
194 This driver provides kernel-side support for the Random Number
195 Generator hardware found on ST-Ericsson SoCs (8815 and 8500).
196
197 To compile this driver as a module, choose M here: the
198 module will be called nomadik-rng.
199
200 If unsure, say Y.
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index 5eeb1303f0d0..4273308aa1e3 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -18,3 +18,4 @@ obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
18obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o 18obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
19obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o 19obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o
20obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o 20obj-$(CONFIG_HW_RANDOM_OCTEON) += octeon-rng.o
21obj-$(CONFIG_HW_RANDOM_NOMADIK) += nomadik-rng.o
diff --git a/drivers/char/hw_random/nomadik-rng.c b/drivers/char/hw_random/nomadik-rng.c
new file mode 100644
index 000000000000..a8b4c4010144
--- /dev/null
+++ b/drivers/char/hw_random/nomadik-rng.c
@@ -0,0 +1,103 @@
1/*
2 * Nomadik RNG support
3 * Copyright 2009 Alessandro Rubini
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/device.h>
15#include <linux/amba/bus.h>
16#include <linux/hw_random.h>
17#include <linux/io.h>
18
19static int nmk_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
20{
21 void __iomem *base = (void __iomem *)rng->priv;
22
23 /*
24 * The register is 32 bits and gives 16 random bits (low half).
25 * A subsequent read will delay the core for 400ns, so we just read
26 * once and accept the very unlikely very small delay, even if wait==0.
27 */
28 *(u16 *)data = __raw_readl(base + 8) & 0xffff;
29 return 2;
30}
31
32/* we have at most one RNG per machine, granted */
33static struct hwrng nmk_rng = {
34 .name = "nomadik",
35 .read = nmk_rng_read,
36};
37
38static int nmk_rng_probe(struct amba_device *dev, struct amba_id *id)
39{
40 void __iomem *base;
41 int ret;
42
43 ret = amba_request_regions(dev, dev->dev.init_name);
44 if (ret)
45 return ret;
46 ret = -ENOMEM;
47 base = ioremap(dev->res.start, resource_size(&dev->res));
48 if (!base)
49 goto out_release;
50 nmk_rng.priv = (unsigned long)base;
51 ret = hwrng_register(&nmk_rng);
52 if (ret)
53 goto out_unmap;
54 return 0;
55
56out_unmap:
57 iounmap(base);
58out_release:
59 amba_release_regions(dev);
60 return ret;
61}
62
63static int nmk_rng_remove(struct amba_device *dev)
64{
65 void __iomem *base = (void __iomem *)nmk_rng.priv;
66 hwrng_unregister(&nmk_rng);
67 iounmap(base);
68 amba_release_regions(dev);
69 return 0;
70}
71
72static struct amba_id nmk_rng_ids[] = {
73 {
74 .id = 0x000805e1,
75 .mask = 0x000fffff, /* top bits are rev and cfg: accept all */
76 },
77 {0, 0},
78};
79
80static struct amba_driver nmk_rng_driver = {
81 .drv = {
82 .owner = THIS_MODULE,
83 .name = "rng",
84 },
85 .probe = nmk_rng_probe,
86 .remove = nmk_rng_remove,
87 .id_table = nmk_rng_ids,
88};
89
90static int __init nmk_rng_init(void)
91{
92 return amba_driver_register(&nmk_rng_driver);
93}
94
95static void __devexit nmk_rng_exit(void)
96{
97 amba_driver_unregister(&nmk_rng_driver);
98}
99
100module_init(nmk_rng_init);
101module_exit(nmk_rng_exit);
102
103MODULE_LICENSE("GPL");
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 2db4c0a29b05..c9bc896d68af 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -1047,7 +1047,7 @@ release_io:
1047static ssize_t cmm_write(struct file *filp, const char __user *buf, 1047static ssize_t cmm_write(struct file *filp, const char __user *buf,
1048 size_t count, loff_t *ppos) 1048 size_t count, loff_t *ppos)
1049{ 1049{
1050 struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data; 1050 struct cm4000_dev *dev = filp->private_data;
1051 unsigned int iobase = dev->p_dev->io.BasePort1; 1051 unsigned int iobase = dev->p_dev->io.BasePort1;
1052 unsigned short s; 1052 unsigned short s;
1053 unsigned char tmp; 1053 unsigned char tmp;
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index a035ae39a359..213373b5f17f 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1,18 +1,6 @@
1/*D:300 1/*
2 * The Guest console driver 2 * Copyright (C) 2006, 2007, 2009 Rusty Russell, IBM Corporation
3 * 3 * Copyright (C) 2009, 2010 Red Hat, Inc.
4 * Writing console drivers is one of the few remaining Dark Arts in Linux.
5 * Fortunately for us, the path of virtual consoles has been well-trodden by
6 * the PowerPC folks, who wrote "hvc_console.c" to generically support any
7 * virtual console. We use that infrastructure which only requires us to write
8 * the basic put_chars and get_chars functions and call the right register
9 * functions.
10 :*/
11
12/*M:002 The console can be flooded: while the Guest is processing input the
13 * Host can send more. Buffering in the Host could alleviate this, but it is a
14 * difficult problem in general. :*/
15/* Copyright (C) 2006, 2007 Rusty Russell, IBM Corporation
16 * 4 *
17 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -28,142 +16,694 @@
28 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */ 18 */
19#include <linux/cdev.h>
20#include <linux/debugfs.h>
21#include <linux/device.h>
31#include <linux/err.h> 22#include <linux/err.h>
23#include <linux/fs.h>
32#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/list.h>
26#include <linux/poll.h>
27#include <linux/sched.h>
28#include <linux/spinlock.h>
33#include <linux/virtio.h> 29#include <linux/virtio.h>
34#include <linux/virtio_console.h> 30#include <linux/virtio_console.h>
31#include <linux/wait.h>
32#include <linux/workqueue.h>
35#include "hvc_console.h" 33#include "hvc_console.h"
36 34
37/*D:340 These represent our input and output console queues, and the virtio 35/*
38 * operations for them. */ 36 * This is a global struct for storing common data for all the devices
39static struct virtqueue *in_vq, *out_vq; 37 * this driver handles.
40static struct virtio_device *vdev; 38 *
39 * Mainly, it has a linked list for all the consoles in one place so
40 * that callbacks from hvc for get_chars(), put_chars() work properly
41 * across multiple devices and multiple ports per device.
42 */
43struct ports_driver_data {
44 /* Used for registering chardevs */
45 struct class *class;
46
47 /* Used for exporting per-port information to debugfs */
48 struct dentry *debugfs_dir;
49
50 /* Number of devices this driver is handling */
51 unsigned int index;
52
53 /*
54 * This is used to keep track of the number of hvc consoles
55 * spawned by this driver. This number is given as the first
56 * argument to hvc_alloc(). To correctly map an initial
57 * console spawned via hvc_instantiate to the console being
58 * hooked up via hvc_alloc, we need to pass the same vtermno.
59 *
60 * We also just assume the first console being initialised was
61 * the first one that got used as the initial console.
62 */
63 unsigned int next_vtermno;
64
65 /* All the console devices handled by this driver */
66 struct list_head consoles;
67};
68static struct ports_driver_data pdrvdata;
69
70DEFINE_SPINLOCK(pdrvdata_lock);
71
72/* This struct holds information that's relevant only for console ports */
73struct console {
74 /* We'll place all consoles in a list in the pdrvdata struct */
75 struct list_head list;
76
77 /* The hvc device associated with this console port */
78 struct hvc_struct *hvc;
79
80 /*
81 * This number identifies the number that we used to register
82 * with hvc in hvc_instantiate() and hvc_alloc(); this is the
83 * number passed on by the hvc callbacks to us to
84 * differentiate between the other console ports handled by
85 * this driver
86 */
87 u32 vtermno;
88};
89
90struct port_buffer {
91 char *buf;
92
93 /* size of the buffer in *buf above */
94 size_t size;
95
96 /* used length of the buffer */
97 size_t len;
98 /* offset in the buf from which to consume data */
99 size_t offset;
100};
101
102/*
103 * This is a per-device struct that stores data common to all the
104 * ports for that device (vdev->priv).
105 */
106struct ports_device {
107 /*
108 * Workqueue handlers where we process deferred work after
109 * notification
110 */
111 struct work_struct control_work;
112 struct work_struct config_work;
113
114 struct list_head ports;
115
116 /* To protect the list of ports */
117 spinlock_t ports_lock;
118
119 /* To protect the vq operations for the control channel */
120 spinlock_t cvq_lock;
121
122 /* The current config space is stored here */
123 struct virtio_console_config config;
124
125 /* The virtio device we're associated with */
126 struct virtio_device *vdev;
127
128 /*
129 * A couple of virtqueues for the control channel: one for
130 * guest->host transfers, one for host->guest transfers
131 */
132 struct virtqueue *c_ivq, *c_ovq;
133
134 /* Array of per-port IO virtqueues */
135 struct virtqueue **in_vqs, **out_vqs;
136
137 /* Used for numbering devices for sysfs and debugfs */
138 unsigned int drv_index;
139
140 /* Major number for this device. Ports will be created as minors. */
141 int chr_major;
142};
143
144/* This struct holds the per-port data */
145struct port {
146 /* Next port in the list, head is in the ports_device */
147 struct list_head list;
148
149 /* Pointer to the parent virtio_console device */
150 struct ports_device *portdev;
151
152 /* The current buffer from which data has to be fed to readers */
153 struct port_buffer *inbuf;
154
155 /*
156 * To protect the operations on the in_vq associated with this
157 * port. Has to be a spinlock because it can be called from
158 * interrupt context (get_char()).
159 */
160 spinlock_t inbuf_lock;
161
162 /* The IO vqs for this port */
163 struct virtqueue *in_vq, *out_vq;
164
165 /* File in the debugfs directory that exposes this port's information */
166 struct dentry *debugfs_file;
167
168 /*
169 * The entries in this struct will be valid if this port is
170 * hooked up to an hvc console
171 */
172 struct console cons;
173
174 /* Each port associates with a separate char device */
175 struct cdev cdev;
176 struct device *dev;
177
178 /* A waitqueue for poll() or blocking read operations */
179 wait_queue_head_t waitqueue;
180
181 /* The 'name' of the port that we expose via sysfs properties */
182 char *name;
183
184 /* The 'id' to identify the port with the Host */
185 u32 id;
186
187 /* Is the host device open */
188 bool host_connected;
189
190 /* We should allow only one process to open a port */
191 bool guest_connected;
192};
193
194/* This is the very early arch-specified put chars function. */
195static int (*early_put_chars)(u32, const char *, int);
196
197static struct port *find_port_by_vtermno(u32 vtermno)
198{
199 struct port *port;
200 struct console *cons;
201 unsigned long flags;
202
203 spin_lock_irqsave(&pdrvdata_lock, flags);
204 list_for_each_entry(cons, &pdrvdata.consoles, list) {
205 if (cons->vtermno == vtermno) {
206 port = container_of(cons, struct port, cons);
207 goto out;
208 }
209 }
210 port = NULL;
211out:
212 spin_unlock_irqrestore(&pdrvdata_lock, flags);
213 return port;
214}
215
216static struct port *find_port_by_id(struct ports_device *portdev, u32 id)
217{
218 struct port *port;
219 unsigned long flags;
220
221 spin_lock_irqsave(&portdev->ports_lock, flags);
222 list_for_each_entry(port, &portdev->ports, list)
223 if (port->id == id)
224 goto out;
225 port = NULL;
226out:
227 spin_unlock_irqrestore(&portdev->ports_lock, flags);
228
229 return port;
230}
231
232static struct port *find_port_by_vq(struct ports_device *portdev,
233 struct virtqueue *vq)
234{
235 struct port *port;
236 unsigned long flags;
237
238 spin_lock_irqsave(&portdev->ports_lock, flags);
239 list_for_each_entry(port, &portdev->ports, list)
240 if (port->in_vq == vq || port->out_vq == vq)
241 goto out;
242 port = NULL;
243out:
244 spin_unlock_irqrestore(&portdev->ports_lock, flags);
245 return port;
246}
247
248static bool is_console_port(struct port *port)
249{
250 if (port->cons.hvc)
251 return true;
252 return false;
253}
254
255static inline bool use_multiport(struct ports_device *portdev)
256{
257 /*
258 * This condition can be true when put_chars is called from
259 * early_init
260 */
261 if (!portdev->vdev)
262 return 0;
263 return portdev->vdev->features[0] & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
264}
41 265
42/* This is our input buffer, and how much data is left in it. */ 266static void free_buf(struct port_buffer *buf)
43static unsigned int in_len; 267{
44static char *in, *inbuf; 268 kfree(buf->buf);
269 kfree(buf);
270}
271
272static struct port_buffer *alloc_buf(size_t buf_size)
273{
274 struct port_buffer *buf;
45 275
46/* The operations for our console. */ 276 buf = kmalloc(sizeof(*buf), GFP_KERNEL);
47static struct hv_ops virtio_cons; 277 if (!buf)
278 goto fail;
279 buf->buf = kzalloc(buf_size, GFP_KERNEL);
280 if (!buf->buf)
281 goto free_buf;
282 buf->len = 0;
283 buf->offset = 0;
284 buf->size = buf_size;
285 return buf;
286
287free_buf:
288 kfree(buf);
289fail:
290 return NULL;
291}
292
293/* Callers should take appropriate locks */
294static void *get_inbuf(struct port *port)
295{
296 struct port_buffer *buf;
297 struct virtqueue *vq;
298 unsigned int len;
48 299
49/* The hvc device */ 300 vq = port->in_vq;
50static struct hvc_struct *hvc; 301 buf = vq->vq_ops->get_buf(vq, &len);
302 if (buf) {
303 buf->len = len;
304 buf->offset = 0;
305 }
306 return buf;
307}
51 308
52/*D:310 The put_chars() callback is pretty straightforward. 309/*
310 * Create a scatter-gather list representing our input buffer and put
311 * it in the queue.
53 * 312 *
54 * We turn the characters into a scatter-gather list, add it to the output 313 * Callers should take appropriate locks.
55 * queue and then kick the Host. Then we sit here waiting for it to finish: 314 */
56 * inefficient in theory, but in practice implementations will do it 315static int add_inbuf(struct virtqueue *vq, struct port_buffer *buf)
57 * immediately (lguest's Launcher does). */
58static int put_chars(u32 vtermno, const char *buf, int count)
59{ 316{
60 struct scatterlist sg[1]; 317 struct scatterlist sg[1];
318 int ret;
319
320 sg_init_one(sg, buf->buf, buf->size);
321
322 ret = vq->vq_ops->add_buf(vq, sg, 0, 1, buf);
323 vq->vq_ops->kick(vq);
324 return ret;
325}
326
327/* Discard any unread data this port has. Callers lockers. */
328static void discard_port_data(struct port *port)
329{
330 struct port_buffer *buf;
331 struct virtqueue *vq;
61 unsigned int len; 332 unsigned int len;
333 int ret;
62 334
63 /* This is a convenient routine to initialize a single-elem sg list */ 335 vq = port->in_vq;
64 sg_init_one(sg, buf, count); 336 if (port->inbuf)
337 buf = port->inbuf;
338 else
339 buf = vq->vq_ops->get_buf(vq, &len);
65 340
66 /* add_buf wants a token to identify this buffer: we hand it any 341 ret = 0;
67 * non-NULL pointer, since there's only ever one buffer. */ 342 while (buf) {
68 if (out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, (void *)1) >= 0) { 343 if (add_inbuf(vq, buf) < 0) {
69 /* Tell Host to go! */ 344 ret++;
70 out_vq->vq_ops->kick(out_vq); 345 free_buf(buf);
71 /* Chill out until it's done with the buffer. */ 346 }
72 while (!out_vq->vq_ops->get_buf(out_vq, &len)) 347 buf = vq->vq_ops->get_buf(vq, &len);
73 cpu_relax();
74 } 348 }
349 port->inbuf = NULL;
350 if (ret)
351 dev_warn(port->dev, "Errors adding %d buffers back to vq\n",
352 ret);
353}
75 354
76 /* We're expected to return the amount of data we wrote: all of it. */ 355static bool port_has_data(struct port *port)
77 return count; 356{
357 unsigned long flags;
358 bool ret;
359
360 spin_lock_irqsave(&port->inbuf_lock, flags);
361 if (port->inbuf) {
362 ret = true;
363 goto out;
364 }
365 port->inbuf = get_inbuf(port);
366 if (port->inbuf) {
367 ret = true;
368 goto out;
369 }
370 ret = false;
371out:
372 spin_unlock_irqrestore(&port->inbuf_lock, flags);
373 return ret;
78} 374}
79 375
80/* Create a scatter-gather list representing our input buffer and put it in the 376static ssize_t send_control_msg(struct port *port, unsigned int event,
81 * queue. */ 377 unsigned int value)
82static void add_inbuf(void)
83{ 378{
84 struct scatterlist sg[1]; 379 struct scatterlist sg[1];
85 sg_init_one(sg, inbuf, PAGE_SIZE); 380 struct virtio_console_control cpkt;
381 struct virtqueue *vq;
382 int len;
383
384 if (!use_multiport(port->portdev))
385 return 0;
386
387 cpkt.id = port->id;
388 cpkt.event = event;
389 cpkt.value = value;
390
391 vq = port->portdev->c_ovq;
86 392
87 /* We should always be able to add one buffer to an empty queue. */ 393 sg_init_one(sg, &cpkt, sizeof(cpkt));
88 if (in_vq->vq_ops->add_buf(in_vq, sg, 0, 1, inbuf) < 0) 394 if (vq->vq_ops->add_buf(vq, sg, 1, 0, &cpkt) >= 0) {
89 BUG(); 395 vq->vq_ops->kick(vq);
90 in_vq->vq_ops->kick(in_vq); 396 while (!vq->vq_ops->get_buf(vq, &len))
397 cpu_relax();
398 }
399 return 0;
91} 400}
92 401
93/*D:350 get_chars() is the callback from the hvc_console infrastructure when 402static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count)
94 * an interrupt is received.
95 *
96 * Most of the code deals with the fact that the hvc_console() infrastructure
97 * only asks us for 16 bytes at a time. We keep in_offset and in_used fields
98 * for partially-filled buffers. */
99static int get_chars(u32 vtermno, char *buf, int count)
100{ 403{
101 /* If we don't have an input queue yet, we can't get input. */ 404 struct scatterlist sg[1];
102 BUG_ON(!in_vq); 405 struct virtqueue *out_vq;
406 ssize_t ret;
407 unsigned int len;
408
409 out_vq = port->out_vq;
410
411 sg_init_one(sg, in_buf, in_count);
412 ret = out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, in_buf);
413
414 /* Tell Host to go! */
415 out_vq->vq_ops->kick(out_vq);
416
417 if (ret < 0) {
418 len = 0;
419 goto fail;
420 }
421
422 /*
423 * Wait till the host acknowledges it pushed out the data we
424 * sent. Also ensure we return to userspace the number of
425 * bytes that were successfully consumed by the host.
426 */
427 while (!out_vq->vq_ops->get_buf(out_vq, &len))
428 cpu_relax();
429fail:
430 /* We're expected to return the amount of data we wrote */
431 return len;
432}
433
434/*
435 * Give out the data that's requested from the buffer that we have
436 * queued up.
437 */
438static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
439 bool to_user)
440{
441 struct port_buffer *buf;
442 unsigned long flags;
443
444 if (!out_count || !port_has_data(port))
445 return 0;
446
447 buf = port->inbuf;
448 out_count = min(out_count, buf->len - buf->offset);
449
450 if (to_user) {
451 ssize_t ret;
452
453 ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
454 if (ret)
455 return -EFAULT;
456 } else {
457 memcpy(out_buf, buf->buf + buf->offset, out_count);
458 }
459
460 buf->offset += out_count;
461
462 if (buf->offset == buf->len) {
463 /*
464 * We're done using all the data in this buffer.
465 * Re-queue so that the Host can send us more data.
466 */
467 spin_lock_irqsave(&port->inbuf_lock, flags);
468 port->inbuf = NULL;
469
470 if (add_inbuf(port->in_vq, buf) < 0)
471 dev_warn(port->dev, "failed add_buf\n");
472
473 spin_unlock_irqrestore(&port->inbuf_lock, flags);
474 }
475 /* Return the number of bytes actually copied */
476 return out_count;
477}
103 478
104 /* No buffer? Try to get one. */ 479/* The condition that must be true for polling to end */
105 if (!in_len) { 480static bool wait_is_over(struct port *port)
106 in = in_vq->vq_ops->get_buf(in_vq, &in_len); 481{
107 if (!in) 482 return port_has_data(port) || !port->host_connected;
483}
484
485static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
486 size_t count, loff_t *offp)
487{
488 struct port *port;
489 ssize_t ret;
490
491 port = filp->private_data;
492
493 if (!port_has_data(port)) {
494 /*
495 * If nothing's connected on the host just return 0 in
496 * case of list_empty; this tells the userspace app
497 * that there's no connection
498 */
499 if (!port->host_connected)
108 return 0; 500 return 0;
501 if (filp->f_flags & O_NONBLOCK)
502 return -EAGAIN;
503
504 ret = wait_event_interruptible(port->waitqueue,
505 wait_is_over(port));
506 if (ret < 0)
507 return ret;
508 }
509 /*
510 * We could've received a disconnection message while we were
511 * waiting for more data.
512 *
513 * This check is not clubbed in the if() statement above as we
514 * might receive some data as well as the host could get
515 * disconnected after we got woken up from our wait. So we
516 * really want to give off whatever data we have and only then
517 * check for host_connected.
518 */
519 if (!port_has_data(port) && !port->host_connected)
520 return 0;
521
522 return fill_readbuf(port, ubuf, count, true);
523}
524
525static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
526 size_t count, loff_t *offp)
527{
528 struct port *port;
529 char *buf;
530 ssize_t ret;
531
532 port = filp->private_data;
533
534 count = min((size_t)(32 * 1024), count);
535
536 buf = kmalloc(count, GFP_KERNEL);
537 if (!buf)
538 return -ENOMEM;
539
540 ret = copy_from_user(buf, ubuf, count);
541 if (ret) {
542 ret = -EFAULT;
543 goto free_buf;
109 } 544 }
110 545
111 /* You want more than we have to give? Well, try wanting less! */ 546 ret = send_buf(port, buf, count);
112 if (in_len < count) 547free_buf:
113 count = in_len; 548 kfree(buf);
549 return ret;
550}
551
552static unsigned int port_fops_poll(struct file *filp, poll_table *wait)
553{
554 struct port *port;
555 unsigned int ret;
556
557 port = filp->private_data;
558 poll_wait(filp, &port->waitqueue, wait);
559
560 ret = 0;
561 if (port->inbuf)
562 ret |= POLLIN | POLLRDNORM;
563 if (port->host_connected)
564 ret |= POLLOUT;
565 if (!port->host_connected)
566 ret |= POLLHUP;
567
568 return ret;
569}
570
571static int port_fops_release(struct inode *inode, struct file *filp)
572{
573 struct port *port;
574
575 port = filp->private_data;
576
577 /* Notify host of port being closed */
578 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0);
579
580 spin_lock_irq(&port->inbuf_lock);
581 port->guest_connected = false;
582
583 discard_port_data(port);
584
585 spin_unlock_irq(&port->inbuf_lock);
586
587 return 0;
588}
589
590static int port_fops_open(struct inode *inode, struct file *filp)
591{
592 struct cdev *cdev = inode->i_cdev;
593 struct port *port;
594
595 port = container_of(cdev, struct port, cdev);
596 filp->private_data = port;
597
598 /*
599 * Don't allow opening of console port devices -- that's done
600 * via /dev/hvc
601 */
602 if (is_console_port(port))
603 return -ENXIO;
604
605 /* Allow only one process to open a particular port at a time */
606 spin_lock_irq(&port->inbuf_lock);
607 if (port->guest_connected) {
608 spin_unlock_irq(&port->inbuf_lock);
609 return -EMFILE;
610 }
114 611
115 /* Copy across to their buffer and increment offset. */ 612 port->guest_connected = true;
116 memcpy(buf, in, count); 613 spin_unlock_irq(&port->inbuf_lock);
117 in += count;
118 in_len -= count;
119 614
120 /* Finished? Re-register buffer so Host will use it again. */ 615 /* Notify host of port being opened */
121 if (in_len == 0) 616 send_control_msg(filp->private_data, VIRTIO_CONSOLE_PORT_OPEN, 1);
122 add_inbuf();
123 617
124 return count; 618 return 0;
125} 619}
126/*:*/
127 620
128/*D:320 Console drivers are initialized very early so boot messages can go out, 621/*
129 * so we do things slightly differently from the generic virtio initialization 622 * The file operations that we support: programs in the guest can open
130 * of the net and block drivers. 623 * a console device, read from it, write to it, poll for data and
624 * close it. The devices are at
625 * /dev/vport<device number>p<port number>
626 */
627static const struct file_operations port_fops = {
628 .owner = THIS_MODULE,
629 .open = port_fops_open,
630 .read = port_fops_read,
631 .write = port_fops_write,
632 .poll = port_fops_poll,
633 .release = port_fops_release,
634};
635
636/*
637 * The put_chars() callback is pretty straightforward.
131 * 638 *
132 * At this stage, the console is output-only. It's too early to set up a 639 * We turn the characters into a scatter-gather list, add it to the
133 * virtqueue, so we let the drivers do some boutique early-output thing. */ 640 * output queue and then kick the Host. Then we sit here waiting for
134int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)) 641 * it to finish: inefficient in theory, but in practice
642 * implementations will do it immediately (lguest's Launcher does).
643 */
644static int put_chars(u32 vtermno, const char *buf, int count)
135{ 645{
136 virtio_cons.put_chars = put_chars; 646 struct port *port;
137 return hvc_instantiate(0, 0, &virtio_cons); 647
648 port = find_port_by_vtermno(vtermno);
649 if (!port)
650 return 0;
651
652 if (unlikely(early_put_chars))
653 return early_put_chars(vtermno, buf, count);
654
655 return send_buf(port, (void *)buf, count);
138} 656}
139 657
140/* 658/*
141 * virtio console configuration. This supports: 659 * get_chars() is the callback from the hvc_console infrastructure
142 * - console resize 660 * when an interrupt is received.
661 *
662 * We call out to fill_readbuf that gets us the required data from the
663 * buffers that are queued up.
143 */ 664 */
144static void virtcons_apply_config(struct virtio_device *dev) 665static int get_chars(u32 vtermno, char *buf, int count)
145{ 666{
667 struct port *port;
668
669 port = find_port_by_vtermno(vtermno);
670 if (!port)
671 return 0;
672
673 /* If we don't have an input queue yet, we can't get input. */
674 BUG_ON(!port->in_vq);
675
676 return fill_readbuf(port, buf, count, false);
677}
678
679static void resize_console(struct port *port)
680{
681 struct virtio_device *vdev;
146 struct winsize ws; 682 struct winsize ws;
147 683
148 if (virtio_has_feature(dev, VIRTIO_CONSOLE_F_SIZE)) { 684 vdev = port->portdev->vdev;
149 dev->config->get(dev, 685 if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) {
150 offsetof(struct virtio_console_config, cols), 686 vdev->config->get(vdev,
151 &ws.ws_col, sizeof(u16)); 687 offsetof(struct virtio_console_config, cols),
152 dev->config->get(dev, 688 &ws.ws_col, sizeof(u16));
153 offsetof(struct virtio_console_config, rows), 689 vdev->config->get(vdev,
154 &ws.ws_row, sizeof(u16)); 690 offsetof(struct virtio_console_config, rows),
155 hvc_resize(hvc, ws); 691 &ws.ws_row, sizeof(u16));
692 hvc_resize(port->cons.hvc, ws);
156 } 693 }
157} 694}
158 695
159/* 696/* We set the configuration at this point, since we now have a tty */
160 * we support only one console, the hvc struct is a global var
161 * We set the configuration at this point, since we now have a tty
162 */
163static int notifier_add_vio(struct hvc_struct *hp, int data) 697static int notifier_add_vio(struct hvc_struct *hp, int data)
164{ 698{
699 struct port *port;
700
701 port = find_port_by_vtermno(hp->vtermno);
702 if (!port)
703 return -EINVAL;
704
165 hp->irq_requested = 1; 705 hp->irq_requested = 1;
166 virtcons_apply_config(vdev); 706 resize_console(port);
167 707
168 return 0; 708 return 0;
169} 709}
@@ -173,79 +713,797 @@ static void notifier_del_vio(struct hvc_struct *hp, int data)
173 hp->irq_requested = 0; 713 hp->irq_requested = 0;
174} 714}
175 715
176static void hvc_handle_input(struct virtqueue *vq) 716/* The operations for console ports. */
717static const struct hv_ops hv_ops = {
718 .get_chars = get_chars,
719 .put_chars = put_chars,
720 .notifier_add = notifier_add_vio,
721 .notifier_del = notifier_del_vio,
722 .notifier_hangup = notifier_del_vio,
723};
724
725/*
726 * Console drivers are initialized very early so boot messages can go
727 * out, so we do things slightly differently from the generic virtio
728 * initialization of the net and block drivers.
729 *
730 * At this stage, the console is output-only. It's too early to set
731 * up a virtqueue, so we let the drivers do some boutique early-output
732 * thing.
733 */
734int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
177{ 735{
178 if (hvc_poll(hvc)) 736 early_put_chars = put_chars;
737 return hvc_instantiate(0, 0, &hv_ops);
738}
739
740int init_port_console(struct port *port)
741{
742 int ret;
743
744 /*
745 * The Host's telling us this port is a console port. Hook it
746 * up with an hvc console.
747 *
748 * To set up and manage our virtual console, we call
749 * hvc_alloc().
750 *
751 * The first argument of hvc_alloc() is the virtual console
752 * number. The second argument is the parameter for the
753 * notification mechanism (like irq number). We currently
754 * leave this as zero, virtqueues have implicit notifications.
755 *
756 * The third argument is a "struct hv_ops" containing the
757 * put_chars() get_chars(), notifier_add() and notifier_del()
758 * pointers. The final argument is the output buffer size: we
759 * can do any size, so we put PAGE_SIZE here.
760 */
761 port->cons.vtermno = pdrvdata.next_vtermno;
762
763 port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE);
764 if (IS_ERR(port->cons.hvc)) {
765 ret = PTR_ERR(port->cons.hvc);
766 dev_err(port->dev,
767 "error %d allocating hvc for port\n", ret);
768 port->cons.hvc = NULL;
769 return ret;
770 }
771 spin_lock_irq(&pdrvdata_lock);
772 pdrvdata.next_vtermno++;
773 list_add_tail(&port->cons.list, &pdrvdata.consoles);
774 spin_unlock_irq(&pdrvdata_lock);
775 port->guest_connected = true;
776
777 /* Notify host of port being opened */
778 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1);
779
780 return 0;
781}
782
783static ssize_t show_port_name(struct device *dev,
784 struct device_attribute *attr, char *buffer)
785{
786 struct port *port;
787
788 port = dev_get_drvdata(dev);
789
790 return sprintf(buffer, "%s\n", port->name);
791}
792
793static DEVICE_ATTR(name, S_IRUGO, show_port_name, NULL);
794
795static struct attribute *port_sysfs_entries[] = {
796 &dev_attr_name.attr,
797 NULL
798};
799
800static struct attribute_group port_attribute_group = {
801 .name = NULL, /* put in device directory */
802 .attrs = port_sysfs_entries,
803};
804
805static int debugfs_open(struct inode *inode, struct file *filp)
806{
807 filp->private_data = inode->i_private;
808 return 0;
809}
810
811static ssize_t debugfs_read(struct file *filp, char __user *ubuf,
812 size_t count, loff_t *offp)
813{
814 struct port *port;
815 char *buf;
816 ssize_t ret, out_offset, out_count;
817
818 out_count = 1024;
819 buf = kmalloc(out_count, GFP_KERNEL);
820 if (!buf)
821 return -ENOMEM;
822
823 port = filp->private_data;
824 out_offset = 0;
825 out_offset += snprintf(buf + out_offset, out_count,
826 "name: %s\n", port->name ? port->name : "");
827 out_offset += snprintf(buf + out_offset, out_count - out_offset,
828 "guest_connected: %d\n", port->guest_connected);
829 out_offset += snprintf(buf + out_offset, out_count - out_offset,
830 "host_connected: %d\n", port->host_connected);
831 out_offset += snprintf(buf + out_offset, out_count - out_offset,
832 "is_console: %s\n",
833 is_console_port(port) ? "yes" : "no");
834 out_offset += snprintf(buf + out_offset, out_count - out_offset,
835 "console_vtermno: %u\n", port->cons.vtermno);
836
837 ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset);
838 kfree(buf);
839 return ret;
840}
841
842static const struct file_operations port_debugfs_ops = {
843 .owner = THIS_MODULE,
844 .open = debugfs_open,
845 .read = debugfs_read,
846};
847
848/* Remove all port-specific data. */
849static int remove_port(struct port *port)
850{
851 struct port_buffer *buf;
852
853 spin_lock_irq(&port->portdev->ports_lock);
854 list_del(&port->list);
855 spin_unlock_irq(&port->portdev->ports_lock);
856
857 if (is_console_port(port)) {
858 spin_lock_irq(&pdrvdata_lock);
859 list_del(&port->cons.list);
860 spin_unlock_irq(&pdrvdata_lock);
861 hvc_remove(port->cons.hvc);
862 }
863 if (port->guest_connected)
864 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0);
865
866 sysfs_remove_group(&port->dev->kobj, &port_attribute_group);
867 device_destroy(pdrvdata.class, port->dev->devt);
868 cdev_del(&port->cdev);
869
870 /* Remove unused data this port might have received. */
871 discard_port_data(port);
872
873 /* Remove buffers we queued up for the Host to send us data in. */
874 while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq)))
875 free_buf(buf);
876
877 kfree(port->name);
878
879 debugfs_remove(port->debugfs_file);
880
881 kfree(port);
882 return 0;
883}
884
885/* Any private messages that the Host and Guest want to share */
886static void handle_control_message(struct ports_device *portdev,
887 struct port_buffer *buf)
888{
889 struct virtio_console_control *cpkt;
890 struct port *port;
891 size_t name_size;
892 int err;
893
894 cpkt = (struct virtio_console_control *)(buf->buf + buf->offset);
895
896 port = find_port_by_id(portdev, cpkt->id);
897 if (!port) {
898 /* No valid header at start of buffer. Drop it. */
899 dev_dbg(&portdev->vdev->dev,
900 "Invalid index %u in control packet\n", cpkt->id);
901 return;
902 }
903
904 switch (cpkt->event) {
905 case VIRTIO_CONSOLE_CONSOLE_PORT:
906 if (!cpkt->value)
907 break;
908 if (is_console_port(port))
909 break;
910
911 init_port_console(port);
912 /*
913 * Could remove the port here in case init fails - but
914 * have to notify the host first.
915 */
916 break;
917 case VIRTIO_CONSOLE_RESIZE:
918 if (!is_console_port(port))
919 break;
920 port->cons.hvc->irq_requested = 1;
921 resize_console(port);
922 break;
923 case VIRTIO_CONSOLE_PORT_OPEN:
924 port->host_connected = cpkt->value;
925 wake_up_interruptible(&port->waitqueue);
926 break;
927 case VIRTIO_CONSOLE_PORT_NAME:
928 /*
929 * Skip the size of the header and the cpkt to get the size
930 * of the name that was sent
931 */
932 name_size = buf->len - buf->offset - sizeof(*cpkt) + 1;
933
934 port->name = kmalloc(name_size, GFP_KERNEL);
935 if (!port->name) {
936 dev_err(port->dev,
937 "Not enough space to store port name\n");
938 break;
939 }
940 strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt),
941 name_size - 1);
942 port->name[name_size - 1] = 0;
943
944 /*
945 * Since we only have one sysfs attribute, 'name',
946 * create it only if we have a name for the port.
947 */
948 err = sysfs_create_group(&port->dev->kobj,
949 &port_attribute_group);
950 if (err)
951 dev_err(port->dev,
952 "Error %d creating sysfs device attributes\n",
953 err);
954
955 break;
956 case VIRTIO_CONSOLE_PORT_REMOVE:
957 /*
958 * Hot unplug the port. We don't decrement nr_ports
959 * since we don't want to deal with extra complexities
960 * of using the lowest-available port id: We can just
961 * pick up the nr_ports number as the id and not have
962 * userspace send it to us. This helps us in two
963 * ways:
964 *
965 * - We don't need to have a 'port_id' field in the
966 * config space when a port is hot-added. This is a
967 * good thing as we might queue up multiple hotplug
968 * requests issued in our workqueue.
969 *
970 * - Another way to deal with this would have been to
971 * use a bitmap of the active ports and select the
972 * lowest non-active port from that map. That
973 * bloats the already tight config space and we
974 * would end up artificially limiting the
975 * max. number of ports to sizeof(bitmap). Right
976 * now we can support 2^32 ports (as the port id is
977 * stored in a u32 type).
978 *
979 */
980 remove_port(port);
981 break;
982 }
983}
984
985static void control_work_handler(struct work_struct *work)
986{
987 struct ports_device *portdev;
988 struct virtqueue *vq;
989 struct port_buffer *buf;
990 unsigned int len;
991
992 portdev = container_of(work, struct ports_device, control_work);
993 vq = portdev->c_ivq;
994
995 spin_lock(&portdev->cvq_lock);
996 while ((buf = vq->vq_ops->get_buf(vq, &len))) {
997 spin_unlock(&portdev->cvq_lock);
998
999 buf->len = len;
1000 buf->offset = 0;
1001
1002 handle_control_message(portdev, buf);
1003
1004 spin_lock(&portdev->cvq_lock);
1005 if (add_inbuf(portdev->c_ivq, buf) < 0) {
1006 dev_warn(&portdev->vdev->dev,
1007 "Error adding buffer to queue\n");
1008 free_buf(buf);
1009 }
1010 }
1011 spin_unlock(&portdev->cvq_lock);
1012}
1013
1014static void in_intr(struct virtqueue *vq)
1015{
1016 struct port *port;
1017 unsigned long flags;
1018
1019 port = find_port_by_vq(vq->vdev->priv, vq);
1020 if (!port)
1021 return;
1022
1023 spin_lock_irqsave(&port->inbuf_lock, flags);
1024 if (!port->inbuf)
1025 port->inbuf = get_inbuf(port);
1026
1027 /*
1028 * Don't queue up data when port is closed. This condition
1029 * can be reached when a console port is not yet connected (no
1030 * tty is spawned) and the host sends out data to console
1031 * ports. For generic serial ports, the host won't
1032 * (shouldn't) send data till the guest is connected.
1033 */
1034 if (!port->guest_connected)
1035 discard_port_data(port);
1036
1037 spin_unlock_irqrestore(&port->inbuf_lock, flags);
1038
1039 wake_up_interruptible(&port->waitqueue);
1040
1041 if (is_console_port(port) && hvc_poll(port->cons.hvc))
179 hvc_kick(); 1042 hvc_kick();
180} 1043}
181 1044
182/*D:370 Once we're further in boot, we get probed like any other virtio device. 1045static void control_intr(struct virtqueue *vq)
183 * At this stage we set up the output virtqueue. 1046{
184 * 1047 struct ports_device *portdev;
185 * To set up and manage our virtual console, we call hvc_alloc(). Since we 1048
186 * never remove the console device we never need this pointer again. 1049 portdev = vq->vdev->priv;
1050 schedule_work(&portdev->control_work);
1051}
1052
1053static void config_intr(struct virtio_device *vdev)
1054{
1055 struct ports_device *portdev;
1056
1057 portdev = vdev->priv;
1058 if (use_multiport(portdev)) {
1059 /* Handle port hot-add */
1060 schedule_work(&portdev->config_work);
1061 }
1062 /*
1063 * We'll use this way of resizing only for legacy support.
1064 * For newer userspace (VIRTIO_CONSOLE_F_MULTPORT+), use
1065 * control messages to indicate console size changes so that
1066 * it can be done per-port
1067 */
1068 resize_console(find_port_by_id(portdev, 0));
1069}
1070
1071static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock)
1072{
1073 struct port_buffer *buf;
1074 unsigned int ret;
1075 int err;
1076
1077 ret = 0;
1078 do {
1079 buf = alloc_buf(PAGE_SIZE);
1080 if (!buf)
1081 break;
1082
1083 spin_lock_irq(lock);
1084 err = add_inbuf(vq, buf);
1085 if (err < 0) {
1086 spin_unlock_irq(lock);
1087 free_buf(buf);
1088 break;
1089 }
1090 ret++;
1091 spin_unlock_irq(lock);
1092 } while (err > 0);
1093
1094 return ret;
1095}
1096
1097static int add_port(struct ports_device *portdev, u32 id)
1098{
1099 char debugfs_name[16];
1100 struct port *port;
1101 struct port_buffer *buf;
1102 dev_t devt;
1103 int err;
1104
1105 port = kmalloc(sizeof(*port), GFP_KERNEL);
1106 if (!port) {
1107 err = -ENOMEM;
1108 goto fail;
1109 }
1110
1111 port->portdev = portdev;
1112 port->id = id;
1113
1114 port->name = NULL;
1115 port->inbuf = NULL;
1116 port->cons.hvc = NULL;
1117
1118 port->host_connected = port->guest_connected = false;
1119
1120 port->in_vq = portdev->in_vqs[port->id];
1121 port->out_vq = portdev->out_vqs[port->id];
1122
1123 cdev_init(&port->cdev, &port_fops);
1124
1125 devt = MKDEV(portdev->chr_major, id);
1126 err = cdev_add(&port->cdev, devt, 1);
1127 if (err < 0) {
1128 dev_err(&port->portdev->vdev->dev,
1129 "Error %d adding cdev for port %u\n", err, id);
1130 goto free_port;
1131 }
1132 port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev,
1133 devt, port, "vport%up%u",
1134 port->portdev->drv_index, id);
1135 if (IS_ERR(port->dev)) {
1136 err = PTR_ERR(port->dev);
1137 dev_err(&port->portdev->vdev->dev,
1138 "Error %d creating device for port %u\n",
1139 err, id);
1140 goto free_cdev;
1141 }
1142
1143 spin_lock_init(&port->inbuf_lock);
1144 init_waitqueue_head(&port->waitqueue);
1145
1146 /* Fill the in_vq with buffers so the host can send us data. */
1147 err = fill_queue(port->in_vq, &port->inbuf_lock);
1148 if (!err) {
1149 dev_err(port->dev, "Error allocating inbufs\n");
1150 err = -ENOMEM;
1151 goto free_device;
1152 }
1153
1154 /*
1155 * If we're not using multiport support, this has to be a console port
1156 */
1157 if (!use_multiport(port->portdev)) {
1158 err = init_port_console(port);
1159 if (err)
1160 goto free_inbufs;
1161 }
1162
1163 spin_lock_irq(&portdev->ports_lock);
1164 list_add_tail(&port->list, &port->portdev->ports);
1165 spin_unlock_irq(&portdev->ports_lock);
1166
1167 /*
1168 * Tell the Host we're set so that it can send us various
1169 * configuration parameters for this port (eg, port name,
1170 * caching, whether this is a console port, etc.)
1171 */
1172 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1);
1173
1174 if (pdrvdata.debugfs_dir) {
1175 /*
1176 * Finally, create the debugfs file that we can use to
1177 * inspect a port's state at any time
1178 */
1179 sprintf(debugfs_name, "vport%up%u",
1180 port->portdev->drv_index, id);
1181 port->debugfs_file = debugfs_create_file(debugfs_name, 0444,
1182 pdrvdata.debugfs_dir,
1183 port,
1184 &port_debugfs_ops);
1185 }
1186 return 0;
1187
1188free_inbufs:
1189 while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq)))
1190 free_buf(buf);
1191free_device:
1192 device_destroy(pdrvdata.class, port->dev->devt);
1193free_cdev:
1194 cdev_del(&port->cdev);
1195free_port:
1196 kfree(port);
1197fail:
1198 return err;
1199}
1200
1201/*
1202 * The workhandler for config-space updates.
187 * 1203 *
188 * Finally we put our input buffer in the input queue, ready to receive. */ 1204 * This is called when ports are hot-added.
189static int __devinit virtcons_probe(struct virtio_device *dev) 1205 */
1206static void config_work_handler(struct work_struct *work)
1207{
1208 struct virtio_console_config virtconconf;
1209 struct ports_device *portdev;
1210 struct virtio_device *vdev;
1211 int err;
1212
1213 portdev = container_of(work, struct ports_device, config_work);
1214
1215 vdev = portdev->vdev;
1216 vdev->config->get(vdev,
1217 offsetof(struct virtio_console_config, nr_ports),
1218 &virtconconf.nr_ports,
1219 sizeof(virtconconf.nr_ports));
1220
1221 if (portdev->config.nr_ports == virtconconf.nr_ports) {
1222 /*
1223 * Port 0 got hot-added. Since we already did all the
1224 * other initialisation for it, just tell the Host
1225 * that the port is ready if we find the port. In
1226 * case the port was hot-removed earlier, we call
1227 * add_port to add the port.
1228 */
1229 struct port *port;
1230
1231 port = find_port_by_id(portdev, 0);
1232 if (!port)
1233 add_port(portdev, 0);
1234 else
1235 send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1);
1236 return;
1237 }
1238 if (virtconconf.nr_ports > portdev->config.max_nr_ports) {
1239 dev_warn(&vdev->dev,
1240 "More ports specified (%u) than allowed (%u)",
1241 portdev->config.nr_ports + 1,
1242 portdev->config.max_nr_ports);
1243 return;
1244 }
1245 if (virtconconf.nr_ports < portdev->config.nr_ports)
1246 return;
1247
1248 /* Hot-add ports */
1249 while (virtconconf.nr_ports - portdev->config.nr_ports) {
1250 err = add_port(portdev, portdev->config.nr_ports);
1251 if (err)
1252 break;
1253 portdev->config.nr_ports++;
1254 }
1255}
1256
1257static int init_vqs(struct ports_device *portdev)
190{ 1258{
191 vq_callback_t *callbacks[] = { hvc_handle_input, NULL}; 1259 vq_callback_t **io_callbacks;
192 const char *names[] = { "input", "output" }; 1260 char **io_names;
193 struct virtqueue *vqs[2]; 1261 struct virtqueue **vqs;
1262 u32 i, j, nr_ports, nr_queues;
194 int err; 1263 int err;
195 1264
196 vdev = dev; 1265 nr_ports = portdev->config.max_nr_ports;
1266 nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2;
197 1267
198 /* This is the scratch page we use to receive console input */ 1268 vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL);
199 inbuf = kmalloc(PAGE_SIZE, GFP_KERNEL); 1269 if (!vqs) {
200 if (!inbuf) {
201 err = -ENOMEM; 1270 err = -ENOMEM;
202 goto fail; 1271 goto fail;
203 } 1272 }
1273 io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL);
1274 if (!io_callbacks) {
1275 err = -ENOMEM;
1276 goto free_vqs;
1277 }
1278 io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL);
1279 if (!io_names) {
1280 err = -ENOMEM;
1281 goto free_callbacks;
1282 }
1283 portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
1284 GFP_KERNEL);
1285 if (!portdev->in_vqs) {
1286 err = -ENOMEM;
1287 goto free_names;
1288 }
1289 portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
1290 GFP_KERNEL);
1291 if (!portdev->out_vqs) {
1292 err = -ENOMEM;
1293 goto free_invqs;
1294 }
1295
1296 /*
1297 * For backward compat (newer host but older guest), the host
1298 * spawns a console port first and also inits the vqs for port
1299 * 0 before others.
1300 */
1301 j = 0;
1302 io_callbacks[j] = in_intr;
1303 io_callbacks[j + 1] = NULL;
1304 io_names[j] = "input";
1305 io_names[j + 1] = "output";
1306 j += 2;
204 1307
1308 if (use_multiport(portdev)) {
1309 io_callbacks[j] = control_intr;
1310 io_callbacks[j + 1] = NULL;
1311 io_names[j] = "control-i";
1312 io_names[j + 1] = "control-o";
1313
1314 for (i = 1; i < nr_ports; i++) {
1315 j += 2;
1316 io_callbacks[j] = in_intr;
1317 io_callbacks[j + 1] = NULL;
1318 io_names[j] = "input";
1319 io_names[j + 1] = "output";
1320 }
1321 }
205 /* Find the queues. */ 1322 /* Find the queues. */
206 /* FIXME: This is why we want to wean off hvc: we do nothing 1323 err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs,
207 * when input comes in. */ 1324 io_callbacks,
208 err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names); 1325 (const char **)io_names);
209 if (err) 1326 if (err)
1327 goto free_outvqs;
1328
1329 j = 0;
1330 portdev->in_vqs[0] = vqs[0];
1331 portdev->out_vqs[0] = vqs[1];
1332 j += 2;
1333 if (use_multiport(portdev)) {
1334 portdev->c_ivq = vqs[j];
1335 portdev->c_ovq = vqs[j + 1];
1336
1337 for (i = 1; i < nr_ports; i++) {
1338 j += 2;
1339 portdev->in_vqs[i] = vqs[j];
1340 portdev->out_vqs[i] = vqs[j + 1];
1341 }
1342 }
1343 kfree(io_callbacks);
1344 kfree(io_names);
1345 kfree(vqs);
1346
1347 return 0;
1348
1349free_names:
1350 kfree(io_names);
1351free_callbacks:
1352 kfree(io_callbacks);
1353free_outvqs:
1354 kfree(portdev->out_vqs);
1355free_invqs:
1356 kfree(portdev->in_vqs);
1357free_vqs:
1358 kfree(vqs);
1359fail:
1360 return err;
1361}
1362
1363static const struct file_operations portdev_fops = {
1364 .owner = THIS_MODULE,
1365};
1366
1367/*
1368 * Once we're further in boot, we get probed like any other virtio
1369 * device.
1370 *
1371 * If the host also supports multiple console ports, we check the
1372 * config space to see how many ports the host has spawned. We
1373 * initialize each port found.
1374 */
1375static int __devinit virtcons_probe(struct virtio_device *vdev)
1376{
1377 struct ports_device *portdev;
1378 u32 i;
1379 int err;
1380 bool multiport;
1381
1382 portdev = kmalloc(sizeof(*portdev), GFP_KERNEL);
1383 if (!portdev) {
1384 err = -ENOMEM;
1385 goto fail;
1386 }
1387
1388 /* Attach this portdev to this virtio_device, and vice-versa. */
1389 portdev->vdev = vdev;
1390 vdev->priv = portdev;
1391
1392 spin_lock_irq(&pdrvdata_lock);
1393 portdev->drv_index = pdrvdata.index++;
1394 spin_unlock_irq(&pdrvdata_lock);
1395
1396 portdev->chr_major = register_chrdev(0, "virtio-portsdev",
1397 &portdev_fops);
1398 if (portdev->chr_major < 0) {
1399 dev_err(&vdev->dev,
1400 "Error %d registering chrdev for device %u\n",
1401 portdev->chr_major, portdev->drv_index);
1402 err = portdev->chr_major;
210 goto free; 1403 goto free;
1404 }
211 1405
212 in_vq = vqs[0]; 1406 multiport = false;
213 out_vq = vqs[1]; 1407 portdev->config.nr_ports = 1;
1408 portdev->config.max_nr_ports = 1;
1409 if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) {
1410 multiport = true;
1411 vdev->features[0] |= 1 << VIRTIO_CONSOLE_F_MULTIPORT;
214 1412
215 /* Start using the new console output. */ 1413 vdev->config->get(vdev, offsetof(struct virtio_console_config,
216 virtio_cons.get_chars = get_chars; 1414 nr_ports),
217 virtio_cons.put_chars = put_chars; 1415 &portdev->config.nr_ports,
218 virtio_cons.notifier_add = notifier_add_vio; 1416 sizeof(portdev->config.nr_ports));
219 virtio_cons.notifier_del = notifier_del_vio; 1417 vdev->config->get(vdev, offsetof(struct virtio_console_config,
220 virtio_cons.notifier_hangup = notifier_del_vio; 1418 max_nr_ports),
221 1419 &portdev->config.max_nr_ports,
222 /* The first argument of hvc_alloc() is the virtual console number, so 1420 sizeof(portdev->config.max_nr_ports));
223 * we use zero. The second argument is the parameter for the 1421 if (portdev->config.nr_ports > portdev->config.max_nr_ports) {
224 * notification mechanism (like irq number). We currently leave this 1422 dev_warn(&vdev->dev,
225 * as zero, virtqueues have implicit notifications. 1423 "More ports (%u) specified than allowed (%u). Will init %u ports.",
226 * 1424 portdev->config.nr_ports,
227 * The third argument is a "struct hv_ops" containing the put_chars() 1425 portdev->config.max_nr_ports,
228 * get_chars(), notifier_add() and notifier_del() pointers. 1426 portdev->config.max_nr_ports);
229 * The final argument is the output buffer size: we can do any size, 1427
230 * so we put PAGE_SIZE here. */ 1428 portdev->config.nr_ports = portdev->config.max_nr_ports;
231 hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE); 1429 }
232 if (IS_ERR(hvc)) { 1430 }
233 err = PTR_ERR(hvc); 1431
234 goto free_vqs; 1432 /* Let the Host know we support multiple ports.*/
1433 vdev->config->finalize_features(vdev);
1434
1435 err = init_vqs(portdev);
1436 if (err < 0) {
1437 dev_err(&vdev->dev, "Error %d initializing vqs\n", err);
1438 goto free_chrdev;
1439 }
1440
1441 spin_lock_init(&portdev->ports_lock);
1442 INIT_LIST_HEAD(&portdev->ports);
1443
1444 if (multiport) {
1445 spin_lock_init(&portdev->cvq_lock);
1446 INIT_WORK(&portdev->control_work, &control_work_handler);
1447 INIT_WORK(&portdev->config_work, &config_work_handler);
1448
1449 err = fill_queue(portdev->c_ivq, &portdev->cvq_lock);
1450 if (!err) {
1451 dev_err(&vdev->dev,
1452 "Error allocating buffers for control queue\n");
1453 err = -ENOMEM;
1454 goto free_vqs;
1455 }
235 } 1456 }
236 1457
237 /* Register the input buffer the first time. */ 1458 for (i = 0; i < portdev->config.nr_ports; i++)
238 add_inbuf(); 1459 add_port(portdev, i);
1460
1461 /* Start using the new console output. */
1462 early_put_chars = NULL;
239 return 0; 1463 return 0;
240 1464
241free_vqs: 1465free_vqs:
242 vdev->config->del_vqs(vdev); 1466 vdev->config->del_vqs(vdev);
1467 kfree(portdev->in_vqs);
1468 kfree(portdev->out_vqs);
1469free_chrdev:
1470 unregister_chrdev(portdev->chr_major, "virtio-portsdev");
243free: 1471free:
244 kfree(inbuf); 1472 kfree(portdev);
245fail: 1473fail:
246 return err; 1474 return err;
247} 1475}
248 1476
1477static void virtcons_remove(struct virtio_device *vdev)
1478{
1479 struct ports_device *portdev;
1480 struct port *port, *port2;
1481 struct port_buffer *buf;
1482 unsigned int len;
1483
1484 portdev = vdev->priv;
1485
1486 cancel_work_sync(&portdev->control_work);
1487 cancel_work_sync(&portdev->config_work);
1488
1489 list_for_each_entry_safe(port, port2, &portdev->ports, list)
1490 remove_port(port);
1491
1492 unregister_chrdev(portdev->chr_major, "virtio-portsdev");
1493
1494 while ((buf = portdev->c_ivq->vq_ops->get_buf(portdev->c_ivq, &len)))
1495 free_buf(buf);
1496
1497 while ((buf = portdev->c_ivq->vq_ops->detach_unused_buf(portdev->c_ivq)))
1498 free_buf(buf);
1499
1500 vdev->config->del_vqs(vdev);
1501 kfree(portdev->in_vqs);
1502 kfree(portdev->out_vqs);
1503
1504 kfree(portdev);
1505}
1506
249static struct virtio_device_id id_table[] = { 1507static struct virtio_device_id id_table[] = {
250 { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID }, 1508 { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID },
251 { 0 }, 1509 { 0 },
@@ -253,6 +1511,7 @@ static struct virtio_device_id id_table[] = {
253 1511
254static unsigned int features[] = { 1512static unsigned int features[] = {
255 VIRTIO_CONSOLE_F_SIZE, 1513 VIRTIO_CONSOLE_F_SIZE,
1514 VIRTIO_CONSOLE_F_MULTIPORT,
256}; 1515};
257 1516
258static struct virtio_driver virtio_console = { 1517static struct virtio_driver virtio_console = {
@@ -262,14 +1521,41 @@ static struct virtio_driver virtio_console = {
262 .driver.owner = THIS_MODULE, 1521 .driver.owner = THIS_MODULE,
263 .id_table = id_table, 1522 .id_table = id_table,
264 .probe = virtcons_probe, 1523 .probe = virtcons_probe,
265 .config_changed = virtcons_apply_config, 1524 .remove = virtcons_remove,
1525 .config_changed = config_intr,
266}; 1526};
267 1527
268static int __init init(void) 1528static int __init init(void)
269{ 1529{
1530 int err;
1531
1532 pdrvdata.class = class_create(THIS_MODULE, "virtio-ports");
1533 if (IS_ERR(pdrvdata.class)) {
1534 err = PTR_ERR(pdrvdata.class);
1535 pr_err("Error %d creating virtio-ports class\n", err);
1536 return err;
1537 }
1538
1539 pdrvdata.debugfs_dir = debugfs_create_dir("virtio-ports", NULL);
1540 if (!pdrvdata.debugfs_dir) {
1541 pr_warning("Error %ld creating debugfs dir for virtio-ports\n",
1542 PTR_ERR(pdrvdata.debugfs_dir));
1543 }
1544 INIT_LIST_HEAD(&pdrvdata.consoles);
1545
270 return register_virtio_driver(&virtio_console); 1546 return register_virtio_driver(&virtio_console);
271} 1547}
1548
1549static void __exit fini(void)
1550{
1551 unregister_virtio_driver(&virtio_console);
1552
1553 class_destroy(pdrvdata.class);
1554 if (pdrvdata.debugfs_dir)
1555 debugfs_remove_recursive(pdrvdata.debugfs_dir);
1556}
272module_init(init); 1557module_init(init);
1558module_exit(fini);
273 1559
274MODULE_DEVICE_TABLE(virtio, id_table); 1560MODULE_DEVICE_TABLE(virtio, id_table);
275MODULE_DESCRIPTION("Virtio console driver"); 1561MODULE_DESCRIPTION("Virtio console driver");
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index 994e1a58b987..8b24729fec89 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -136,7 +136,7 @@ static const struct tty_port_operations scc_port_ops = {
136 * vme_scc_init() and support functions 136 * vme_scc_init() and support functions
137 *---------------------------------------------------------------------------*/ 137 *---------------------------------------------------------------------------*/
138 138
139static int scc_init_drivers(void) 139static int __init scc_init_drivers(void)
140{ 140{
141 int error; 141 int error;
142 142
@@ -172,7 +172,7 @@ static int scc_init_drivers(void)
172/* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1). 172/* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
173 */ 173 */
174 174
175static void scc_init_portstructs(void) 175static void __init scc_init_portstructs(void)
176{ 176{
177 struct scc_port *port; 177 struct scc_port *port;
178 int i; 178 int i;
@@ -195,7 +195,7 @@ static void scc_init_portstructs(void)
195 195
196 196
197#ifdef CONFIG_MVME147_SCC 197#ifdef CONFIG_MVME147_SCC
198static int mvme147_scc_init(void) 198static int __init mvme147_scc_init(void)
199{ 199{
200 struct scc_port *port; 200 struct scc_port *port;
201 int error; 201 int error;
@@ -298,7 +298,7 @@ fail:
298 298
299 299
300#ifdef CONFIG_MVME162_SCC 300#ifdef CONFIG_MVME162_SCC
301static int mvme162_scc_init(void) 301static int __init mvme162_scc_init(void)
302{ 302{
303 struct scc_port *port; 303 struct scc_port *port;
304 int error; 304 int error;
@@ -404,7 +404,7 @@ fail:
404 404
405 405
406#ifdef CONFIG_BVME6000_SCC 406#ifdef CONFIG_BVME6000_SCC
407static int bvme6000_scc_init(void) 407static int __init bvme6000_scc_init(void)
408{ 408{
409 struct scc_port *port; 409 struct scc_port *port;
410 int error; 410 int error;
@@ -503,7 +503,7 @@ fail_free_b_rx:
503#endif 503#endif
504 504
505 505
506static int vme_scc_init(void) 506static int __init vme_scc_init(void)
507{ 507{
508 int res = -ENODEV; 508 int res = -ENODEV;
509 509
diff --git a/drivers/clocksource/cs5535-clockevt.c b/drivers/clocksource/cs5535-clockevt.c
index 27d20fac19d1..b314a999aabe 100644
--- a/drivers/clocksource/cs5535-clockevt.c
+++ b/drivers/clocksource/cs5535-clockevt.c
@@ -21,7 +21,7 @@
21 21
22#define DRV_NAME "cs5535-clockevt" 22#define DRV_NAME "cs5535-clockevt"
23 23
24static int timer_irq = CONFIG_CS5535_MFGPT_DEFAULT_IRQ; 24static int timer_irq;
25module_param_named(irq, timer_irq, int, 0644); 25module_param_named(irq, timer_irq, int, 0644);
26MODULE_PARM_DESC(irq, "Which IRQ to use for the clock source MFGPT ticks."); 26MODULE_PARM_DESC(irq, "Which IRQ to use for the clock source MFGPT ticks.");
27 27
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
index 6b3e0c2f33e2..6fe4f7701188 100644
--- a/drivers/clocksource/sh_cmt.c
+++ b/drivers/clocksource/sh_cmt.c
@@ -603,18 +603,13 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
603 p->irqaction.handler = sh_cmt_interrupt; 603 p->irqaction.handler = sh_cmt_interrupt;
604 p->irqaction.dev_id = p; 604 p->irqaction.dev_id = p;
605 p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL; 605 p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
606 ret = setup_irq(irq, &p->irqaction);
607 if (ret) {
608 pr_err("sh_cmt: failed to request irq %d\n", irq);
609 goto err1;
610 }
611 606
612 /* get hold of clock */ 607 /* get hold of clock */
613 p->clk = clk_get(&p->pdev->dev, cfg->clk); 608 p->clk = clk_get(&p->pdev->dev, cfg->clk);
614 if (IS_ERR(p->clk)) { 609 if (IS_ERR(p->clk)) {
615 pr_err("sh_cmt: cannot get clock \"%s\"\n", cfg->clk); 610 pr_err("sh_cmt: cannot get clock \"%s\"\n", cfg->clk);
616 ret = PTR_ERR(p->clk); 611 ret = PTR_ERR(p->clk);
617 goto err2; 612 goto err1;
618 } 613 }
619 614
620 if (resource_size(res) == 6) { 615 if (resource_size(res) == 6) {
@@ -627,14 +622,25 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
627 p->clear_bits = ~0xc000; 622 p->clear_bits = ~0xc000;
628 } 623 }
629 624
630 return sh_cmt_register(p, cfg->name, 625 ret = sh_cmt_register(p, cfg->name,
631 cfg->clockevent_rating, 626 cfg->clockevent_rating,
632 cfg->clocksource_rating); 627 cfg->clocksource_rating);
633 err2: 628 if (ret) {
634 remove_irq(irq, &p->irqaction); 629 pr_err("sh_cmt: registration failed\n");
635 err1: 630 goto err1;
631 }
632
633 ret = setup_irq(irq, &p->irqaction);
634 if (ret) {
635 pr_err("sh_cmt: failed to request irq %d\n", irq);
636 goto err1;
637 }
638
639 return 0;
640
641err1:
636 iounmap(p->mapbase); 642 iounmap(p->mapbase);
637 err0: 643err0:
638 return ret; 644 return ret;
639} 645}
640 646
diff --git a/drivers/clocksource/sh_mtu2.c b/drivers/clocksource/sh_mtu2.c
index 973e714d6051..4c8a759e60cd 100644
--- a/drivers/clocksource/sh_mtu2.c
+++ b/drivers/clocksource/sh_mtu2.c
@@ -221,15 +221,15 @@ static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p,
221 ced->cpumask = cpumask_of(0); 221 ced->cpumask = cpumask_of(0);
222 ced->set_mode = sh_mtu2_clock_event_mode; 222 ced->set_mode = sh_mtu2_clock_event_mode;
223 223
224 pr_info("sh_mtu2: %s used for clock events\n", ced->name);
225 clockevents_register_device(ced);
226
224 ret = setup_irq(p->irqaction.irq, &p->irqaction); 227 ret = setup_irq(p->irqaction.irq, &p->irqaction);
225 if (ret) { 228 if (ret) {
226 pr_err("sh_mtu2: failed to request irq %d\n", 229 pr_err("sh_mtu2: failed to request irq %d\n",
227 p->irqaction.irq); 230 p->irqaction.irq);
228 return; 231 return;
229 } 232 }
230
231 pr_info("sh_mtu2: %s used for clock events\n", ced->name);
232 clockevents_register_device(ced);
233} 233}
234 234
235static int sh_mtu2_register(struct sh_mtu2_priv *p, char *name, 235static int sh_mtu2_register(struct sh_mtu2_priv *p, char *name,
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
index 93c2322feab7..961f5b5ef6a3 100644
--- a/drivers/clocksource/sh_tmu.c
+++ b/drivers/clocksource/sh_tmu.c
@@ -323,15 +323,15 @@ static void sh_tmu_register_clockevent(struct sh_tmu_priv *p,
323 ced->set_next_event = sh_tmu_clock_event_next; 323 ced->set_next_event = sh_tmu_clock_event_next;
324 ced->set_mode = sh_tmu_clock_event_mode; 324 ced->set_mode = sh_tmu_clock_event_mode;
325 325
326 pr_info("sh_tmu: %s used for clock events\n", ced->name);
327 clockevents_register_device(ced);
328
326 ret = setup_irq(p->irqaction.irq, &p->irqaction); 329 ret = setup_irq(p->irqaction.irq, &p->irqaction);
327 if (ret) { 330 if (ret) {
328 pr_err("sh_tmu: failed to request irq %d\n", 331 pr_err("sh_tmu: failed to request irq %d\n",
329 p->irqaction.irq); 332 p->irqaction.irq);
330 return; 333 return;
331 } 334 }
332
333 pr_info("sh_tmu: %s used for clock events\n", ced->name);
334 clockevents_register_device(ced);
335} 335}
336 336
337static int sh_tmu_register(struct sh_tmu_priv *p, char *name, 337static int sh_tmu_register(struct sh_tmu_priv *p, char *name,
diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index 46e899ac924e..1c3849f6b7a2 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -1274,7 +1274,7 @@ static int __exit crypto4xx_remove(struct of_device *ofdev)
1274 return 0; 1274 return 0;
1275} 1275}
1276 1276
1277static struct of_device_id crypto4xx_match[] = { 1277static const struct of_device_id crypto4xx_match[] = {
1278 { .compatible = "amcc,ppc4xx-crypto",}, 1278 { .compatible = "amcc,ppc4xx-crypto",},
1279 { }, 1279 { },
1280}; 1280};
diff --git a/drivers/crypto/geode-aes.c b/drivers/crypto/geode-aes.c
index 4801162919d9..c7a5a43ba691 100644
--- a/drivers/crypto/geode-aes.c
+++ b/drivers/crypto/geode-aes.c
@@ -135,13 +135,13 @@ static int geode_setkey_cip(struct crypto_tfm *tfm, const u8 *key,
135 /* 135 /*
136 * The requested key size is not supported by HW, do a fallback 136 * The requested key size is not supported by HW, do a fallback
137 */ 137 */
138 op->fallback.blk->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; 138 op->fallback.cip->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK;
139 op->fallback.blk->base.crt_flags |= (tfm->crt_flags & CRYPTO_TFM_REQ_MASK); 139 op->fallback.cip->base.crt_flags |= (tfm->crt_flags & CRYPTO_TFM_REQ_MASK);
140 140
141 ret = crypto_cipher_setkey(op->fallback.cip, key, len); 141 ret = crypto_cipher_setkey(op->fallback.cip, key, len);
142 if (ret) { 142 if (ret) {
143 tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK; 143 tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
144 tfm->crt_flags |= (op->fallback.blk->base.crt_flags & CRYPTO_TFM_RES_MASK); 144 tfm->crt_flags |= (op->fallback.cip->base.crt_flags & CRYPTO_TFM_RES_MASK);
145 } 145 }
146 return ret; 146 return ret;
147} 147}
@@ -263,7 +263,7 @@ static int fallback_init_cip(struct crypto_tfm *tfm)
263 263
264 if (IS_ERR(op->fallback.cip)) { 264 if (IS_ERR(op->fallback.cip)) {
265 printk(KERN_ERR "Error allocating fallback algo %s\n", name); 265 printk(KERN_ERR "Error allocating fallback algo %s\n", name);
266 return PTR_ERR(op->fallback.blk); 266 return PTR_ERR(op->fallback.cip);
267 } 267 }
268 268
269 return 0; 269 return 0;
diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
index c47ffe8a73ef..fd529d68c5ba 100644
--- a/drivers/crypto/talitos.c
+++ b/drivers/crypto/talitos.c
@@ -1958,7 +1958,7 @@ err_out:
1958 return err; 1958 return err;
1959} 1959}
1960 1960
1961static struct of_device_id talitos_match[] = { 1961static const struct of_device_id talitos_match[] = {
1962 { 1962 {
1963 .compatible = "fsl,sec2.0", 1963 .compatible = "fsl,sec2.0",
1964 }, 1964 },
diff --git a/drivers/dma/shdma.c b/drivers/dma/shdma.c
index d10cc899c460..b75ce8b84c46 100644
--- a/drivers/dma/shdma.c
+++ b/drivers/dma/shdma.c
@@ -48,23 +48,20 @@ enum sh_dmae_desc_status {
48 */ 48 */
49#define RS_DEFAULT (RS_DUAL) 49#define RS_DEFAULT (RS_DUAL)
50 50
51/* A bitmask with bits enough for enum sh_dmae_slave_chan_id */
52static unsigned long sh_dmae_slave_used[BITS_TO_LONGS(SHDMA_SLAVE_NUMBER)];
53
51static void sh_dmae_chan_ld_cleanup(struct sh_dmae_chan *sh_chan, bool all); 54static void sh_dmae_chan_ld_cleanup(struct sh_dmae_chan *sh_chan, bool all);
52 55
53#define SH_DMAC_CHAN_BASE(id) (dma_base_addr[id]) 56#define SH_DMAC_CHAN_BASE(id) (dma_base_addr[id])
54static void sh_dmae_writel(struct sh_dmae_chan *sh_dc, u32 data, u32 reg) 57static void sh_dmae_writel(struct sh_dmae_chan *sh_dc, u32 data, u32 reg)
55{ 58{
56 ctrl_outl(data, (SH_DMAC_CHAN_BASE(sh_dc->id) + reg)); 59 ctrl_outl(data, SH_DMAC_CHAN_BASE(sh_dc->id) + reg);
57} 60}
58 61
59static u32 sh_dmae_readl(struct sh_dmae_chan *sh_dc, u32 reg) 62static u32 sh_dmae_readl(struct sh_dmae_chan *sh_dc, u32 reg)
60{ 63{
61 return ctrl_inl((SH_DMAC_CHAN_BASE(sh_dc->id) + reg)); 64 return ctrl_inl(SH_DMAC_CHAN_BASE(sh_dc->id) + reg);
62}
63
64static void dmae_init(struct sh_dmae_chan *sh_chan)
65{
66 u32 chcr = RS_DEFAULT; /* default is DUAL mode */
67 sh_dmae_writel(sh_chan, chcr, CHCR);
68} 65}
69 66
70/* 67/*
@@ -95,27 +92,30 @@ static int sh_dmae_rst(int id)
95 return 0; 92 return 0;
96} 93}
97 94
98static int dmae_is_busy(struct sh_dmae_chan *sh_chan) 95static bool dmae_is_busy(struct sh_dmae_chan *sh_chan)
99{ 96{
100 u32 chcr = sh_dmae_readl(sh_chan, CHCR); 97 u32 chcr = sh_dmae_readl(sh_chan, CHCR);
101 if (chcr & CHCR_DE) { 98
102 if (!(chcr & CHCR_TE)) 99 if ((chcr & (CHCR_DE | CHCR_TE)) == CHCR_DE)
103 return -EBUSY; /* working */ 100 return true; /* working */
104 } 101
105 return 0; /* waiting */ 102 return false; /* waiting */
106} 103}
107 104
108static inline unsigned int calc_xmit_shift(struct sh_dmae_chan *sh_chan) 105static unsigned int ts_shift[] = TS_SHIFT;
106static inline unsigned int calc_xmit_shift(u32 chcr)
109{ 107{
110 u32 chcr = sh_dmae_readl(sh_chan, CHCR); 108 int cnt = ((chcr & CHCR_TS_LOW_MASK) >> CHCR_TS_LOW_SHIFT) |
111 return ts_shift[(chcr & CHCR_TS_MASK) >> CHCR_TS_SHIFT]; 109 ((chcr & CHCR_TS_HIGH_MASK) >> CHCR_TS_HIGH_SHIFT);
110
111 return ts_shift[cnt];
112} 112}
113 113
114static void dmae_set_reg(struct sh_dmae_chan *sh_chan, struct sh_dmae_regs *hw) 114static void dmae_set_reg(struct sh_dmae_chan *sh_chan, struct sh_dmae_regs *hw)
115{ 115{
116 sh_dmae_writel(sh_chan, hw->sar, SAR); 116 sh_dmae_writel(sh_chan, hw->sar, SAR);
117 sh_dmae_writel(sh_chan, hw->dar, DAR); 117 sh_dmae_writel(sh_chan, hw->dar, DAR);
118 sh_dmae_writel(sh_chan, hw->tcr >> calc_xmit_shift(sh_chan), TCR); 118 sh_dmae_writel(sh_chan, hw->tcr >> sh_chan->xmit_shift, TCR);
119} 119}
120 120
121static void dmae_start(struct sh_dmae_chan *sh_chan) 121static void dmae_start(struct sh_dmae_chan *sh_chan)
@@ -123,7 +123,7 @@ static void dmae_start(struct sh_dmae_chan *sh_chan)
123 u32 chcr = sh_dmae_readl(sh_chan, CHCR); 123 u32 chcr = sh_dmae_readl(sh_chan, CHCR);
124 124
125 chcr |= CHCR_DE | CHCR_IE; 125 chcr |= CHCR_DE | CHCR_IE;
126 sh_dmae_writel(sh_chan, chcr, CHCR); 126 sh_dmae_writel(sh_chan, chcr & ~CHCR_TE, CHCR);
127} 127}
128 128
129static void dmae_halt(struct sh_dmae_chan *sh_chan) 129static void dmae_halt(struct sh_dmae_chan *sh_chan)
@@ -134,55 +134,50 @@ static void dmae_halt(struct sh_dmae_chan *sh_chan)
134 sh_dmae_writel(sh_chan, chcr, CHCR); 134 sh_dmae_writel(sh_chan, chcr, CHCR);
135} 135}
136 136
137static void dmae_init(struct sh_dmae_chan *sh_chan)
138{
139 u32 chcr = RS_DEFAULT; /* default is DUAL mode */
140 sh_chan->xmit_shift = calc_xmit_shift(chcr);
141 sh_dmae_writel(sh_chan, chcr, CHCR);
142}
143
137static int dmae_set_chcr(struct sh_dmae_chan *sh_chan, u32 val) 144static int dmae_set_chcr(struct sh_dmae_chan *sh_chan, u32 val)
138{ 145{
139 int ret = dmae_is_busy(sh_chan);
140 /* When DMA was working, can not set data to CHCR */ 146 /* When DMA was working, can not set data to CHCR */
141 if (ret) 147 if (dmae_is_busy(sh_chan))
142 return ret; 148 return -EBUSY;
143 149
150 sh_chan->xmit_shift = calc_xmit_shift(val);
144 sh_dmae_writel(sh_chan, val, CHCR); 151 sh_dmae_writel(sh_chan, val, CHCR);
152
145 return 0; 153 return 0;
146} 154}
147 155
148#define DMARS1_ADDR 0x04 156#define DMARS_SHIFT 8
149#define DMARS2_ADDR 0x08 157#define DMARS_CHAN_MSK 0x01
150#define DMARS_SHIFT 8
151#define DMARS_CHAN_MSK 0x01
152static int dmae_set_dmars(struct sh_dmae_chan *sh_chan, u16 val) 158static int dmae_set_dmars(struct sh_dmae_chan *sh_chan, u16 val)
153{ 159{
154 u32 addr; 160 u32 addr;
155 int shift = 0; 161 int shift = 0;
156 int ret = dmae_is_busy(sh_chan); 162
157 if (ret) 163 if (dmae_is_busy(sh_chan))
158 return ret; 164 return -EBUSY;
159 165
160 if (sh_chan->id & DMARS_CHAN_MSK) 166 if (sh_chan->id & DMARS_CHAN_MSK)
161 shift = DMARS_SHIFT; 167 shift = DMARS_SHIFT;
162 168
163 switch (sh_chan->id) { 169 if (sh_chan->id < 6)
164 /* DMARS0 */ 170 /* DMA0RS0 - DMA0RS2 */
165 case 0: 171 addr = SH_DMARS_BASE0 + (sh_chan->id / 2) * 4;
166 case 1: 172#ifdef SH_DMARS_BASE1
167 addr = SH_DMARS_BASE; 173 else if (sh_chan->id < 12)
168 break; 174 /* DMA1RS0 - DMA1RS2 */
169 /* DMARS1 */ 175 addr = SH_DMARS_BASE1 + ((sh_chan->id - 6) / 2) * 4;
170 case 2: 176#endif
171 case 3: 177 else
172 addr = (SH_DMARS_BASE + DMARS1_ADDR);
173 break;
174 /* DMARS2 */
175 case 4:
176 case 5:
177 addr = (SH_DMARS_BASE + DMARS2_ADDR);
178 break;
179 default:
180 return -EINVAL; 178 return -EINVAL;
181 }
182 179
183 ctrl_outw((val << shift) | 180 ctrl_outw((val << shift) | (ctrl_inw(addr) & (0xFF00 >> shift)), addr);
184 (ctrl_inw(addr) & (shift ? 0xFF00 : 0x00FF)),
185 addr);
186 181
187 return 0; 182 return 0;
188} 183}
@@ -250,10 +245,53 @@ static struct sh_desc *sh_dmae_get_desc(struct sh_dmae_chan *sh_chan)
250 return NULL; 245 return NULL;
251} 246}
252 247
248static struct sh_dmae_slave_config *sh_dmae_find_slave(
249 struct sh_dmae_chan *sh_chan, enum sh_dmae_slave_chan_id slave_id)
250{
251 struct dma_device *dma_dev = sh_chan->common.device;
252 struct sh_dmae_device *shdev = container_of(dma_dev,
253 struct sh_dmae_device, common);
254 struct sh_dmae_pdata *pdata = &shdev->pdata;
255 int i;
256
257 if ((unsigned)slave_id >= SHDMA_SLAVE_NUMBER)
258 return NULL;
259
260 for (i = 0; i < pdata->config_num; i++)
261 if (pdata->config[i].slave_id == slave_id)
262 return pdata->config + i;
263
264 return NULL;
265}
266
253static int sh_dmae_alloc_chan_resources(struct dma_chan *chan) 267static int sh_dmae_alloc_chan_resources(struct dma_chan *chan)
254{ 268{
255 struct sh_dmae_chan *sh_chan = to_sh_chan(chan); 269 struct sh_dmae_chan *sh_chan = to_sh_chan(chan);
256 struct sh_desc *desc; 270 struct sh_desc *desc;
271 struct sh_dmae_slave *param = chan->private;
272
273 /*
274 * This relies on the guarantee from dmaengine that alloc_chan_resources
275 * never runs concurrently with itself or free_chan_resources.
276 */
277 if (param) {
278 struct sh_dmae_slave_config *cfg;
279
280 cfg = sh_dmae_find_slave(sh_chan, param->slave_id);
281 if (!cfg)
282 return -EINVAL;
283
284 if (test_and_set_bit(param->slave_id, sh_dmae_slave_used))
285 return -EBUSY;
286
287 param->config = cfg;
288
289 dmae_set_dmars(sh_chan, cfg->mid_rid);
290 dmae_set_chcr(sh_chan, cfg->chcr);
291 } else {
292 if ((sh_dmae_readl(sh_chan, CHCR) & 0x700) != 0x400)
293 dmae_set_chcr(sh_chan, RS_DEFAULT);
294 }
257 295
258 spin_lock_bh(&sh_chan->desc_lock); 296 spin_lock_bh(&sh_chan->desc_lock);
259 while (sh_chan->descs_allocated < NR_DESCS_PER_CHANNEL) { 297 while (sh_chan->descs_allocated < NR_DESCS_PER_CHANNEL) {
@@ -286,10 +324,18 @@ static void sh_dmae_free_chan_resources(struct dma_chan *chan)
286 struct sh_desc *desc, *_desc; 324 struct sh_desc *desc, *_desc;
287 LIST_HEAD(list); 325 LIST_HEAD(list);
288 326
327 dmae_halt(sh_chan);
328
289 /* Prepared and not submitted descriptors can still be on the queue */ 329 /* Prepared and not submitted descriptors can still be on the queue */
290 if (!list_empty(&sh_chan->ld_queue)) 330 if (!list_empty(&sh_chan->ld_queue))
291 sh_dmae_chan_ld_cleanup(sh_chan, true); 331 sh_dmae_chan_ld_cleanup(sh_chan, true);
292 332
333 if (chan->private) {
334 /* The caller is holding dma_list_mutex */
335 struct sh_dmae_slave *param = chan->private;
336 clear_bit(param->slave_id, sh_dmae_slave_used);
337 }
338
293 spin_lock_bh(&sh_chan->desc_lock); 339 spin_lock_bh(&sh_chan->desc_lock);
294 340
295 list_splice_init(&sh_chan->ld_free, &list); 341 list_splice_init(&sh_chan->ld_free, &list);
@@ -301,23 +347,97 @@ static void sh_dmae_free_chan_resources(struct dma_chan *chan)
301 kfree(desc); 347 kfree(desc);
302} 348}
303 349
304static struct dma_async_tx_descriptor *sh_dmae_prep_memcpy( 350/**
305 struct dma_chan *chan, dma_addr_t dma_dest, dma_addr_t dma_src, 351 * sh_dmae_add_desc - get, set up and return one transfer descriptor
306 size_t len, unsigned long flags) 352 * @sh_chan: DMA channel
353 * @flags: DMA transfer flags
354 * @dest: destination DMA address, incremented when direction equals
355 * DMA_FROM_DEVICE or DMA_BIDIRECTIONAL
356 * @src: source DMA address, incremented when direction equals
357 * DMA_TO_DEVICE or DMA_BIDIRECTIONAL
358 * @len: DMA transfer length
359 * @first: if NULL, set to the current descriptor and cookie set to -EBUSY
360 * @direction: needed for slave DMA to decide which address to keep constant,
361 * equals DMA_BIDIRECTIONAL for MEMCPY
362 * Returns 0 or an error
363 * Locks: called with desc_lock held
364 */
365static struct sh_desc *sh_dmae_add_desc(struct sh_dmae_chan *sh_chan,
366 unsigned long flags, dma_addr_t *dest, dma_addr_t *src, size_t *len,
367 struct sh_desc **first, enum dma_data_direction direction)
307{ 368{
308 struct sh_dmae_chan *sh_chan; 369 struct sh_desc *new;
309 struct sh_desc *first = NULL, *prev = NULL, *new;
310 size_t copy_size; 370 size_t copy_size;
311 LIST_HEAD(tx_list);
312 int chunks = (len + SH_DMA_TCR_MAX) / (SH_DMA_TCR_MAX + 1);
313 371
314 if (!chan) 372 if (!*len)
315 return NULL; 373 return NULL;
316 374
317 if (!len) 375 /* Allocate the link descriptor from the free list */
376 new = sh_dmae_get_desc(sh_chan);
377 if (!new) {
378 dev_err(sh_chan->dev, "No free link descriptor available\n");
318 return NULL; 379 return NULL;
380 }
319 381
320 sh_chan = to_sh_chan(chan); 382 copy_size = min(*len, (size_t)SH_DMA_TCR_MAX + 1);
383
384 new->hw.sar = *src;
385 new->hw.dar = *dest;
386 new->hw.tcr = copy_size;
387
388 if (!*first) {
389 /* First desc */
390 new->async_tx.cookie = -EBUSY;
391 *first = new;
392 } else {
393 /* Other desc - invisible to the user */
394 new->async_tx.cookie = -EINVAL;
395 }
396
397 dev_dbg(sh_chan->dev,
398 "chaining (%u/%u)@%x -> %x with %p, cookie %d, shift %d\n",
399 copy_size, *len, *src, *dest, &new->async_tx,
400 new->async_tx.cookie, sh_chan->xmit_shift);
401
402 new->mark = DESC_PREPARED;
403 new->async_tx.flags = flags;
404 new->direction = direction;
405
406 *len -= copy_size;
407 if (direction == DMA_BIDIRECTIONAL || direction == DMA_TO_DEVICE)
408 *src += copy_size;
409 if (direction == DMA_BIDIRECTIONAL || direction == DMA_FROM_DEVICE)
410 *dest += copy_size;
411
412 return new;
413}
414
415/*
416 * sh_dmae_prep_sg - prepare transfer descriptors from an SG list
417 *
418 * Common routine for public (MEMCPY) and slave DMA. The MEMCPY case is also
419 * converted to scatter-gather to guarantee consistent locking and a correct
420 * list manipulation. For slave DMA direction carries the usual meaning, and,
421 * logically, the SG list is RAM and the addr variable contains slave address,
422 * e.g., the FIFO I/O register. For MEMCPY direction equals DMA_BIDIRECTIONAL
423 * and the SG list contains only one element and points at the source buffer.
424 */
425static struct dma_async_tx_descriptor *sh_dmae_prep_sg(struct sh_dmae_chan *sh_chan,
426 struct scatterlist *sgl, unsigned int sg_len, dma_addr_t *addr,
427 enum dma_data_direction direction, unsigned long flags)
428{
429 struct scatterlist *sg;
430 struct sh_desc *first = NULL, *new = NULL /* compiler... */;
431 LIST_HEAD(tx_list);
432 int chunks = 0;
433 int i;
434
435 if (!sg_len)
436 return NULL;
437
438 for_each_sg(sgl, sg, sg_len, i)
439 chunks += (sg_dma_len(sg) + SH_DMA_TCR_MAX) /
440 (SH_DMA_TCR_MAX + 1);
321 441
322 /* Have to lock the whole loop to protect against concurrent release */ 442 /* Have to lock the whole loop to protect against concurrent release */
323 spin_lock_bh(&sh_chan->desc_lock); 443 spin_lock_bh(&sh_chan->desc_lock);
@@ -333,49 +453,32 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_memcpy(
333 * only during this function, then they are immediately spliced 453 * only during this function, then they are immediately spliced
334 * back onto the free list in form of a chain 454 * back onto the free list in form of a chain
335 */ 455 */
336 do { 456 for_each_sg(sgl, sg, sg_len, i) {
337 /* Allocate the link descriptor from the free list */ 457 dma_addr_t sg_addr = sg_dma_address(sg);
338 new = sh_dmae_get_desc(sh_chan); 458 size_t len = sg_dma_len(sg);
339 if (!new) { 459
340 dev_err(sh_chan->dev, 460 if (!len)
341 "No free memory for link descriptor\n"); 461 goto err_get_desc;
342 list_for_each_entry(new, &tx_list, node) 462
343 new->mark = DESC_IDLE; 463 do {
344 list_splice(&tx_list, &sh_chan->ld_free); 464 dev_dbg(sh_chan->dev, "Add SG #%d@%p[%d], dma %llx\n",
345 spin_unlock_bh(&sh_chan->desc_lock); 465 i, sg, len, (unsigned long long)sg_addr);
346 return NULL; 466
347 } 467 if (direction == DMA_FROM_DEVICE)
348 468 new = sh_dmae_add_desc(sh_chan, flags,
349 copy_size = min(len, (size_t)SH_DMA_TCR_MAX + 1); 469 &sg_addr, addr, &len, &first,
350 470 direction);
351 new->hw.sar = dma_src; 471 else
352 new->hw.dar = dma_dest; 472 new = sh_dmae_add_desc(sh_chan, flags,
353 new->hw.tcr = copy_size; 473 addr, &sg_addr, &len, &first,
354 if (!first) { 474 direction);
355 /* First desc */ 475 if (!new)
356 new->async_tx.cookie = -EBUSY; 476 goto err_get_desc;
357 first = new; 477
358 } else { 478 new->chunks = chunks--;
359 /* Other desc - invisible to the user */ 479 list_add_tail(&new->node, &tx_list);
360 new->async_tx.cookie = -EINVAL; 480 } while (len);
361 } 481 }
362
363 dev_dbg(sh_chan->dev,
364 "chaining %u of %u with %p, dst %x, cookie %d\n",
365 copy_size, len, &new->async_tx, dma_dest,
366 new->async_tx.cookie);
367
368 new->mark = DESC_PREPARED;
369 new->async_tx.flags = flags;
370 new->chunks = chunks--;
371
372 prev = new;
373 len -= copy_size;
374 dma_src += copy_size;
375 dma_dest += copy_size;
376 /* Insert the link descriptor to the LD ring */
377 list_add_tail(&new->node, &tx_list);
378 } while (len);
379 482
380 if (new != first) 483 if (new != first)
381 new->async_tx.cookie = -ENOSPC; 484 new->async_tx.cookie = -ENOSPC;
@@ -386,6 +489,77 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_memcpy(
386 spin_unlock_bh(&sh_chan->desc_lock); 489 spin_unlock_bh(&sh_chan->desc_lock);
387 490
388 return &first->async_tx; 491 return &first->async_tx;
492
493err_get_desc:
494 list_for_each_entry(new, &tx_list, node)
495 new->mark = DESC_IDLE;
496 list_splice(&tx_list, &sh_chan->ld_free);
497
498 spin_unlock_bh(&sh_chan->desc_lock);
499
500 return NULL;
501}
502
503static struct dma_async_tx_descriptor *sh_dmae_prep_memcpy(
504 struct dma_chan *chan, dma_addr_t dma_dest, dma_addr_t dma_src,
505 size_t len, unsigned long flags)
506{
507 struct sh_dmae_chan *sh_chan;
508 struct scatterlist sg;
509
510 if (!chan || !len)
511 return NULL;
512
513 chan->private = NULL;
514
515 sh_chan = to_sh_chan(chan);
516
517 sg_init_table(&sg, 1);
518 sg_set_page(&sg, pfn_to_page(PFN_DOWN(dma_src)), len,
519 offset_in_page(dma_src));
520 sg_dma_address(&sg) = dma_src;
521 sg_dma_len(&sg) = len;
522
523 return sh_dmae_prep_sg(sh_chan, &sg, 1, &dma_dest, DMA_BIDIRECTIONAL,
524 flags);
525}
526
527static struct dma_async_tx_descriptor *sh_dmae_prep_slave_sg(
528 struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
529 enum dma_data_direction direction, unsigned long flags)
530{
531 struct sh_dmae_slave *param;
532 struct sh_dmae_chan *sh_chan;
533
534 if (!chan)
535 return NULL;
536
537 sh_chan = to_sh_chan(chan);
538 param = chan->private;
539
540 /* Someone calling slave DMA on a public channel? */
541 if (!param || !sg_len) {
542 dev_warn(sh_chan->dev, "%s: bad parameter: %p, %d, %d\n",
543 __func__, param, sg_len, param ? param->slave_id : -1);
544 return NULL;
545 }
546
547 /*
548 * if (param != NULL), this is a successfully requested slave channel,
549 * therefore param->config != NULL too.
550 */
551 return sh_dmae_prep_sg(sh_chan, sgl, sg_len, &param->config->addr,
552 direction, flags);
553}
554
555static void sh_dmae_terminate_all(struct dma_chan *chan)
556{
557 struct sh_dmae_chan *sh_chan = to_sh_chan(chan);
558
559 if (!chan)
560 return;
561
562 sh_dmae_chan_ld_cleanup(sh_chan, true);
389} 563}
390 564
391static dma_async_tx_callback __ld_cleanup(struct sh_dmae_chan *sh_chan, bool all) 565static dma_async_tx_callback __ld_cleanup(struct sh_dmae_chan *sh_chan, bool all)
@@ -419,7 +593,11 @@ static dma_async_tx_callback __ld_cleanup(struct sh_dmae_chan *sh_chan, bool all
419 cookie = tx->cookie; 593 cookie = tx->cookie;
420 594
421 if (desc->mark == DESC_COMPLETED && desc->chunks == 1) { 595 if (desc->mark == DESC_COMPLETED && desc->chunks == 1) {
422 BUG_ON(sh_chan->completed_cookie != desc->cookie - 1); 596 if (sh_chan->completed_cookie != desc->cookie - 1)
597 dev_dbg(sh_chan->dev,
598 "Completing cookie %d, expected %d\n",
599 desc->cookie,
600 sh_chan->completed_cookie + 1);
423 sh_chan->completed_cookie = desc->cookie; 601 sh_chan->completed_cookie = desc->cookie;
424 } 602 }
425 603
@@ -492,7 +670,7 @@ static void sh_chan_xfer_ld_queue(struct sh_dmae_chan *sh_chan)
492 return; 670 return;
493 } 671 }
494 672
495 /* Find the first un-transfer desciptor */ 673 /* Find the first not transferred desciptor */
496 list_for_each_entry(sd, &sh_chan->ld_queue, node) 674 list_for_each_entry(sd, &sh_chan->ld_queue, node)
497 if (sd->mark == DESC_SUBMITTED) { 675 if (sd->mark == DESC_SUBMITTED) {
498 /* Get the ld start address from ld_queue */ 676 /* Get the ld start address from ld_queue */
@@ -559,7 +737,7 @@ static irqreturn_t sh_dmae_err(int irq, void *data)
559 737
560 /* IRQ Multi */ 738 /* IRQ Multi */
561 if (shdev->pdata.mode & SHDMA_MIX_IRQ) { 739 if (shdev->pdata.mode & SHDMA_MIX_IRQ) {
562 int cnt = 0; 740 int __maybe_unused cnt = 0;
563 switch (irq) { 741 switch (irq) {
564#if defined(DMTE6_IRQ) && defined(DMAE1_IRQ) 742#if defined(DMTE6_IRQ) && defined(DMAE1_IRQ)
565 case DMTE6_IRQ: 743 case DMTE6_IRQ:
@@ -596,11 +774,14 @@ static void dmae_do_tasklet(unsigned long data)
596 struct sh_dmae_chan *sh_chan = (struct sh_dmae_chan *)data; 774 struct sh_dmae_chan *sh_chan = (struct sh_dmae_chan *)data;
597 struct sh_desc *desc; 775 struct sh_desc *desc;
598 u32 sar_buf = sh_dmae_readl(sh_chan, SAR); 776 u32 sar_buf = sh_dmae_readl(sh_chan, SAR);
777 u32 dar_buf = sh_dmae_readl(sh_chan, DAR);
599 778
600 spin_lock(&sh_chan->desc_lock); 779 spin_lock(&sh_chan->desc_lock);
601 list_for_each_entry(desc, &sh_chan->ld_queue, node) { 780 list_for_each_entry(desc, &sh_chan->ld_queue, node) {
602 if ((desc->hw.sar + desc->hw.tcr) == sar_buf && 781 if (desc->mark == DESC_SUBMITTED &&
603 desc->mark == DESC_SUBMITTED) { 782 ((desc->direction == DMA_FROM_DEVICE &&
783 (desc->hw.dar + desc->hw.tcr) == dar_buf) ||
784 (desc->hw.sar + desc->hw.tcr) == sar_buf)) {
604 dev_dbg(sh_chan->dev, "done #%d@%p dst %u\n", 785 dev_dbg(sh_chan->dev, "done #%d@%p dst %u\n",
605 desc->async_tx.cookie, &desc->async_tx, 786 desc->async_tx.cookie, &desc->async_tx,
606 desc->hw.dar); 787 desc->hw.dar);
@@ -673,7 +854,7 @@ static int __devinit sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id)
673 } 854 }
674 855
675 snprintf(new_sh_chan->dev_id, sizeof(new_sh_chan->dev_id), 856 snprintf(new_sh_chan->dev_id, sizeof(new_sh_chan->dev_id),
676 "sh-dmae%d", new_sh_chan->id); 857 "sh-dmae%d", new_sh_chan->id);
677 858
678 /* set up channel irq */ 859 /* set up channel irq */
679 err = request_irq(irq, &sh_dmae_interrupt, irqflags, 860 err = request_irq(irq, &sh_dmae_interrupt, irqflags,
@@ -684,11 +865,6 @@ static int __devinit sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id)
684 goto err_no_irq; 865 goto err_no_irq;
685 } 866 }
686 867
687 /* CHCR register control function */
688 new_sh_chan->set_chcr = dmae_set_chcr;
689 /* DMARS register control function */
690 new_sh_chan->set_dmars = dmae_set_dmars;
691
692 shdev->chan[id] = new_sh_chan; 868 shdev->chan[id] = new_sh_chan;
693 return 0; 869 return 0;
694 870
@@ -759,12 +935,19 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
759 INIT_LIST_HEAD(&shdev->common.channels); 935 INIT_LIST_HEAD(&shdev->common.channels);
760 936
761 dma_cap_set(DMA_MEMCPY, shdev->common.cap_mask); 937 dma_cap_set(DMA_MEMCPY, shdev->common.cap_mask);
938 dma_cap_set(DMA_SLAVE, shdev->common.cap_mask);
939
762 shdev->common.device_alloc_chan_resources 940 shdev->common.device_alloc_chan_resources
763 = sh_dmae_alloc_chan_resources; 941 = sh_dmae_alloc_chan_resources;
764 shdev->common.device_free_chan_resources = sh_dmae_free_chan_resources; 942 shdev->common.device_free_chan_resources = sh_dmae_free_chan_resources;
765 shdev->common.device_prep_dma_memcpy = sh_dmae_prep_memcpy; 943 shdev->common.device_prep_dma_memcpy = sh_dmae_prep_memcpy;
766 shdev->common.device_is_tx_complete = sh_dmae_is_complete; 944 shdev->common.device_is_tx_complete = sh_dmae_is_complete;
767 shdev->common.device_issue_pending = sh_dmae_memcpy_issue_pending; 945 shdev->common.device_issue_pending = sh_dmae_memcpy_issue_pending;
946
947 /* Compulsory for DMA_SLAVE fields */
948 shdev->common.device_prep_slave_sg = sh_dmae_prep_slave_sg;
949 shdev->common.device_terminate_all = sh_dmae_terminate_all;
950
768 shdev->common.dev = &pdev->dev; 951 shdev->common.dev = &pdev->dev;
769 /* Default transfer size of 32 bytes requires 32-byte alignment */ 952 /* Default transfer size of 32 bytes requires 32-byte alignment */
770 shdev->common.copy_align = 5; 953 shdev->common.copy_align = 5;
diff --git a/drivers/dma/shdma.h b/drivers/dma/shdma.h
index 108f1cffb6f5..7e227f3c87c4 100644
--- a/drivers/dma/shdma.h
+++ b/drivers/dma/shdma.h
@@ -29,6 +29,7 @@ struct sh_desc {
29 struct sh_dmae_regs hw; 29 struct sh_dmae_regs hw;
30 struct list_head node; 30 struct list_head node;
31 struct dma_async_tx_descriptor async_tx; 31 struct dma_async_tx_descriptor async_tx;
32 enum dma_data_direction direction;
32 dma_cookie_t cookie; 33 dma_cookie_t cookie;
33 int chunks; 34 int chunks;
34 int mark; 35 int mark;
@@ -45,13 +46,9 @@ struct sh_dmae_chan {
45 struct device *dev; /* Channel device */ 46 struct device *dev; /* Channel device */
46 struct tasklet_struct tasklet; /* Tasklet */ 47 struct tasklet_struct tasklet; /* Tasklet */
47 int descs_allocated; /* desc count */ 48 int descs_allocated; /* desc count */
49 int xmit_shift; /* log_2(bytes_per_xfer) */
48 int id; /* Raw id of this channel */ 50 int id; /* Raw id of this channel */
49 char dev_id[16]; /* unique name per DMAC of channel */ 51 char dev_id[16]; /* unique name per DMAC of channel */
50
51 /* Set chcr */
52 int (*set_chcr)(struct sh_dmae_chan *sh_chan, u32 regs);
53 /* Set DMA resource */
54 int (*set_dmars)(struct sh_dmae_chan *sh_chan, u16 res);
55}; 52};
56 53
57struct sh_dmae_device { 54struct sh_dmae_device {
diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
index 5aeb3b541c80..a3600e3ed0fa 100644
--- a/drivers/firmware/iscsi_ibft.c
+++ b/drivers/firmware/iscsi_ibft.c
@@ -380,7 +380,7 @@ static ssize_t ibft_attr_show_nic(struct ibft_kobject *entry,
380 struct ibft_nic *nic = entry->nic; 380 struct ibft_nic *nic = entry->nic;
381 void *ibft_loc = entry->header; 381 void *ibft_loc = entry->header;
382 char *str = buf; 382 char *str = buf;
383 int val; 383 __be32 val;
384 384
385 if (!nic) 385 if (!nic)
386 return 0; 386 return 0;
@@ -396,10 +396,8 @@ static ssize_t ibft_attr_show_nic(struct ibft_kobject *entry,
396 str += sprintf_ipaddr(str, nic->ip_addr); 396 str += sprintf_ipaddr(str, nic->ip_addr);
397 break; 397 break;
398 case ibft_eth_subnet_mask: 398 case ibft_eth_subnet_mask:
399 val = ~((1 << (32-nic->subnet_mask_prefix))-1); 399 val = cpu_to_be32(~((1 << (32-nic->subnet_mask_prefix))-1));
400 str += sprintf(str, NIPQUAD_FMT, 400 str += sprintf(str, "%pI4", &val);
401 (u8)(val >> 24), (u8)(val >> 16),
402 (u8)(val >> 8), (u8)(val));
403 break; 401 break;
404 case ibft_eth_origin: 402 case ibft_eth_origin:
405 str += sprintf(str, "%d\n", nic->origin); 403 str += sprintf(str, "%d\n", nic->origin);
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index f665b05592f3..ab6c97330412 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -598,6 +598,50 @@ struct drm_display_mode *drm_mode_std(struct drm_device *dev,
598 return mode; 598 return mode;
599} 599}
600 600
601/*
602 * EDID is delightfully ambiguous about how interlaced modes are to be
603 * encoded. Our internal representation is of frame height, but some
604 * HDTV detailed timings are encoded as field height.
605 *
606 * The format list here is from CEA, in frame size. Technically we
607 * should be checking refresh rate too. Whatever.
608 */
609static void
610drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
611 struct detailed_pixel_timing *pt)
612{
613 int i;
614 static const struct {
615 int w, h;
616 } cea_interlaced[] = {
617 { 1920, 1080 },
618 { 720, 480 },
619 { 1440, 480 },
620 { 2880, 480 },
621 { 720, 576 },
622 { 1440, 576 },
623 { 2880, 576 },
624 };
625 static const int n_sizes =
626 sizeof(cea_interlaced)/sizeof(cea_interlaced[0]);
627
628 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
629 return;
630
631 for (i = 0; i < n_sizes; i++) {
632 if ((mode->hdisplay == cea_interlaced[i].w) &&
633 (mode->vdisplay == cea_interlaced[i].h / 2)) {
634 mode->vdisplay *= 2;
635 mode->vsync_start *= 2;
636 mode->vsync_end *= 2;
637 mode->vtotal *= 2;
638 mode->vtotal |= 1;
639 }
640 }
641
642 mode->flags |= DRM_MODE_FLAG_INTERLACE;
643}
644
601/** 645/**
602 * drm_mode_detailed - create a new mode from an EDID detailed timing section 646 * drm_mode_detailed - create a new mode from an EDID detailed timing section
603 * @dev: DRM device (needed to create new mode) 647 * @dev: DRM device (needed to create new mode)
@@ -680,8 +724,7 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
680 724
681 drm_mode_set_name(mode); 725 drm_mode_set_name(mode);
682 726
683 if (pt->misc & DRM_EDID_PT_INTERLACED) 727 drm_mode_do_interlace_quirk(mode, pt);
684 mode->flags |= DRM_MODE_FLAG_INTERLACE;
685 728
686 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) { 729 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
687 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE; 730 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 79beffcf5936..cf4cb3e9a0c2 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -176,6 +176,8 @@ MODULE_DEVICE_TABLE(pci, pciidlist);
176 176
177static int i915_drm_freeze(struct drm_device *dev) 177static int i915_drm_freeze(struct drm_device *dev)
178{ 178{
179 struct drm_i915_private *dev_priv = dev->dev_private;
180
179 pci_save_state(dev->pdev); 181 pci_save_state(dev->pdev);
180 182
181 /* If KMS is active, we do the leavevt stuff here */ 183 /* If KMS is active, we do the leavevt stuff here */
@@ -191,17 +193,12 @@ static int i915_drm_freeze(struct drm_device *dev)
191 193
192 i915_save_state(dev); 194 i915_save_state(dev);
193 195
194 return 0;
195}
196
197static void i915_drm_suspend(struct drm_device *dev)
198{
199 struct drm_i915_private *dev_priv = dev->dev_private;
200
201 intel_opregion_free(dev, 1); 196 intel_opregion_free(dev, 1);
202 197
203 /* Modeset on resume, not lid events */ 198 /* Modeset on resume, not lid events */
204 dev_priv->modeset_on_lid = 0; 199 dev_priv->modeset_on_lid = 0;
200
201 return 0;
205} 202}
206 203
207static int i915_suspend(struct drm_device *dev, pm_message_t state) 204static int i915_suspend(struct drm_device *dev, pm_message_t state)
@@ -221,8 +218,6 @@ static int i915_suspend(struct drm_device *dev, pm_message_t state)
221 if (error) 218 if (error)
222 return error; 219 return error;
223 220
224 i915_drm_suspend(dev);
225
226 if (state.event == PM_EVENT_SUSPEND) { 221 if (state.event == PM_EVENT_SUSPEND) {
227 /* Shut down the device */ 222 /* Shut down the device */
228 pci_disable_device(dev->pdev); 223 pci_disable_device(dev->pdev);
@@ -237,6 +232,10 @@ static int i915_drm_thaw(struct drm_device *dev)
237 struct drm_i915_private *dev_priv = dev->dev_private; 232 struct drm_i915_private *dev_priv = dev->dev_private;
238 int error = 0; 233 int error = 0;
239 234
235 i915_restore_state(dev);
236
237 intel_opregion_init(dev, 1);
238
240 /* KMS EnterVT equivalent */ 239 /* KMS EnterVT equivalent */
241 if (drm_core_check_feature(dev, DRIVER_MODESET)) { 240 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
242 mutex_lock(&dev->struct_mutex); 241 mutex_lock(&dev->struct_mutex);
@@ -263,10 +262,6 @@ static int i915_resume(struct drm_device *dev)
263 262
264 pci_set_master(dev->pdev); 263 pci_set_master(dev->pdev);
265 264
266 i915_restore_state(dev);
267
268 intel_opregion_init(dev, 1);
269
270 return i915_drm_thaw(dev); 265 return i915_drm_thaw(dev);
271} 266}
272 267
@@ -423,8 +418,6 @@ static int i915_pm_suspend(struct device *dev)
423 if (error) 418 if (error)
424 return error; 419 return error;
425 420
426 i915_drm_suspend(drm_dev);
427
428 pci_disable_device(pdev); 421 pci_disable_device(pdev);
429 pci_set_power_state(pdev, PCI_D3hot); 422 pci_set_power_state(pdev, PCI_D3hot);
430 423
@@ -464,13 +457,8 @@ static int i915_pm_poweroff(struct device *dev)
464{ 457{
465 struct pci_dev *pdev = to_pci_dev(dev); 458 struct pci_dev *pdev = to_pci_dev(dev);
466 struct drm_device *drm_dev = pci_get_drvdata(pdev); 459 struct drm_device *drm_dev = pci_get_drvdata(pdev);
467 int error;
468
469 error = i915_drm_freeze(drm_dev);
470 if (!error)
471 i915_drm_suspend(drm_dev);
472 460
473 return error; 461 return i915_drm_freeze(drm_dev);
474} 462}
475 463
476const struct dev_pm_ops i915_pm_ops = { 464const struct dev_pm_ops i915_pm_ops = {
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index b1d0acbae4e4..c2e8a45780d5 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -636,6 +636,13 @@ static const struct dmi_system_id bad_lid_status[] = {
636 DMI_MATCH(DMI_PRODUCT_NAME, "PC-81005"), 636 DMI_MATCH(DMI_PRODUCT_NAME, "PC-81005"),
637 }, 637 },
638 }, 638 },
639 {
640 .ident = "Clevo M5x0N",
641 .matches = {
642 DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."),
643 DMI_MATCH(DMI_BOARD_NAME, "M5x0N"),
644 },
645 },
639 { } 646 { }
640}; 647};
641 648
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
index 2cd0fad17dac..0e9cd1d49130 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
@@ -5861,13 +5861,12 @@ nouveau_bios_run_init_table(struct drm_device *dev, uint16_t table,
5861 struct drm_nouveau_private *dev_priv = dev->dev_private; 5861 struct drm_nouveau_private *dev_priv = dev->dev_private;
5862 struct nvbios *bios = &dev_priv->VBIOS; 5862 struct nvbios *bios = &dev_priv->VBIOS;
5863 struct init_exec iexec = { true, false }; 5863 struct init_exec iexec = { true, false };
5864 unsigned long flags;
5865 5864
5866 spin_lock_irqsave(&bios->lock, flags); 5865 mutex_lock(&bios->lock);
5867 bios->display.output = dcbent; 5866 bios->display.output = dcbent;
5868 parse_init_table(bios, table, &iexec); 5867 parse_init_table(bios, table, &iexec);
5869 bios->display.output = NULL; 5868 bios->display.output = NULL;
5870 spin_unlock_irqrestore(&bios->lock, flags); 5869 mutex_unlock(&bios->lock);
5871} 5870}
5872 5871
5873static bool NVInitVBIOS(struct drm_device *dev) 5872static bool NVInitVBIOS(struct drm_device *dev)
@@ -5876,7 +5875,7 @@ static bool NVInitVBIOS(struct drm_device *dev)
5876 struct nvbios *bios = &dev_priv->VBIOS; 5875 struct nvbios *bios = &dev_priv->VBIOS;
5877 5876
5878 memset(bios, 0, sizeof(struct nvbios)); 5877 memset(bios, 0, sizeof(struct nvbios));
5879 spin_lock_init(&bios->lock); 5878 mutex_init(&bios->lock);
5880 bios->dev = dev; 5879 bios->dev = dev;
5881 5880
5882 if (!NVShadowVBIOS(dev, bios->data)) 5881 if (!NVShadowVBIOS(dev, bios->data))
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.h b/drivers/gpu/drm/nouveau/nouveau_bios.h
index 68446fd4146b..fd94bd6dc264 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bios.h
+++ b/drivers/gpu/drm/nouveau/nouveau_bios.h
@@ -205,7 +205,7 @@ struct nvbios {
205 struct drm_device *dev; 205 struct drm_device *dev;
206 struct nouveau_bios_info pub; 206 struct nouveau_bios_info pub;
207 207
208 spinlock_t lock; 208 struct mutex lock;
209 209
210 uint8_t data[NV_PROM_SIZE]; 210 uint8_t data[NV_PROM_SIZE];
211 unsigned int length; 211 unsigned int length;
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
index 5445cefdd03e..1c15ef37b71c 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
@@ -583,6 +583,7 @@ struct drm_nouveau_private {
583 uint64_t vm_end; 583 uint64_t vm_end;
584 struct nouveau_gpuobj *vm_vram_pt[NV50_VM_VRAM_NR]; 584 struct nouveau_gpuobj *vm_vram_pt[NV50_VM_VRAM_NR];
585 int vm_vram_pt_nr; 585 int vm_vram_pt_nr;
586 uint64_t vram_sys_base;
586 587
587 /* the mtrr covering the FB */ 588 /* the mtrr covering the FB */
588 int fb_mtrr; 589 int fb_mtrr;
diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.c b/drivers/gpu/drm/nouveau/nouveau_mem.c
index 8f3a12f614ed..2dc09dbd817d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_mem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_mem.c
@@ -285,53 +285,50 @@ nv50_mem_vm_bind_linear(struct drm_device *dev, uint64_t virt, uint32_t size,
285 uint32_t flags, uint64_t phys) 285 uint32_t flags, uint64_t phys)
286{ 286{
287 struct drm_nouveau_private *dev_priv = dev->dev_private; 287 struct drm_nouveau_private *dev_priv = dev->dev_private;
288 struct nouveau_gpuobj **pgt; 288 struct nouveau_gpuobj *pgt;
289 unsigned psz, pfl, pages; 289 unsigned block;
290 290 int i;
291 if (virt >= dev_priv->vm_gart_base &&
292 (virt + size) < (dev_priv->vm_gart_base + dev_priv->vm_gart_size)) {
293 psz = 12;
294 pgt = &dev_priv->gart_info.sg_ctxdma;
295 pfl = 0x21;
296 virt -= dev_priv->vm_gart_base;
297 } else
298 if (virt >= dev_priv->vm_vram_base &&
299 (virt + size) < (dev_priv->vm_vram_base + dev_priv->vm_vram_size)) {
300 psz = 16;
301 pgt = dev_priv->vm_vram_pt;
302 pfl = 0x01;
303 virt -= dev_priv->vm_vram_base;
304 } else {
305 NV_ERROR(dev, "Invalid address: 0x%16llx-0x%16llx\n",
306 virt, virt + size - 1);
307 return -EINVAL;
308 }
309 291
310 pages = size >> psz; 292 virt = ((virt - dev_priv->vm_vram_base) >> 16) << 1;
293 size = (size >> 16) << 1;
294
295 phys |= ((uint64_t)flags << 32);
296 phys |= 1;
297 if (dev_priv->vram_sys_base) {
298 phys += dev_priv->vram_sys_base;
299 phys |= 0x30;
300 }
311 301
312 dev_priv->engine.instmem.prepare_access(dev, true); 302 dev_priv->engine.instmem.prepare_access(dev, true);
313 if (flags & 0x80000000) { 303 while (size) {
314 while (pages--) { 304 unsigned offset_h = upper_32_bits(phys);
315 struct nouveau_gpuobj *pt = pgt[virt >> 29]; 305 unsigned offset_l = lower_32_bits(phys);
316 unsigned pte = ((virt & 0x1fffffffULL) >> psz) << 1; 306 unsigned pte, end;
307
308 for (i = 7; i >= 0; i--) {
309 block = 1 << (i + 1);
310 if (size >= block && !(virt & (block - 1)))
311 break;
312 }
313 offset_l |= (i << 7);
317 314
318 nv_wo32(dev, pt, pte++, 0x00000000); 315 phys += block << 15;
319 nv_wo32(dev, pt, pte++, 0x00000000); 316 size -= block;
320 317
321 virt += (1 << psz); 318 while (block) {
322 } 319 pgt = dev_priv->vm_vram_pt[virt >> 14];
323 } else { 320 pte = virt & 0x3ffe;
324 while (pages--) {
325 struct nouveau_gpuobj *pt = pgt[virt >> 29];
326 unsigned pte = ((virt & 0x1fffffffULL) >> psz) << 1;
327 unsigned offset_h = upper_32_bits(phys) & 0xff;
328 unsigned offset_l = lower_32_bits(phys);
329 321
330 nv_wo32(dev, pt, pte++, offset_l | pfl); 322 end = pte + block;
331 nv_wo32(dev, pt, pte++, offset_h | flags); 323 if (end > 16384)
324 end = 16384;
325 block -= (end - pte);
326 virt += (end - pte);
332 327
333 phys += (1 << psz); 328 while (pte < end) {
334 virt += (1 << psz); 329 nv_wo32(dev, pgt, pte++, offset_l);
330 nv_wo32(dev, pgt, pte++, offset_h);
331 }
335 } 332 }
336 } 333 }
337 dev_priv->engine.instmem.finish_access(dev); 334 dev_priv->engine.instmem.finish_access(dev);
@@ -356,7 +353,41 @@ nv50_mem_vm_bind_linear(struct drm_device *dev, uint64_t virt, uint32_t size,
356void 353void
357nv50_mem_vm_unbind(struct drm_device *dev, uint64_t virt, uint32_t size) 354nv50_mem_vm_unbind(struct drm_device *dev, uint64_t virt, uint32_t size)
358{ 355{
359 nv50_mem_vm_bind_linear(dev, virt, size, 0x80000000, 0); 356 struct drm_nouveau_private *dev_priv = dev->dev_private;
357 struct nouveau_gpuobj *pgt;
358 unsigned pages, pte, end;
359
360 virt -= dev_priv->vm_vram_base;
361 pages = (size >> 16) << 1;
362
363 dev_priv->engine.instmem.prepare_access(dev, true);
364 while (pages) {
365 pgt = dev_priv->vm_vram_pt[virt >> 29];
366 pte = (virt & 0x1ffe0000ULL) >> 15;
367
368 end = pte + pages;
369 if (end > 16384)
370 end = 16384;
371 pages -= (end - pte);
372 virt += (end - pte) << 15;
373
374 while (pte < end)
375 nv_wo32(dev, pgt, pte++, 0);
376 }
377 dev_priv->engine.instmem.finish_access(dev);
378
379 nv_wr32(dev, 0x100c80, 0x00050001);
380 if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) {
381 NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n");
382 NV_ERROR(dev, "0x100c80 = 0x%08x\n", nv_rd32(dev, 0x100c80));
383 return;
384 }
385
386 nv_wr32(dev, 0x100c80, 0x00000001);
387 if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) {
388 NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n");
389 NV_ERROR(dev, "0x100c80 = 0x%08x\n", nv_rd32(dev, 0x100c80));
390 }
360} 391}
361 392
362/* 393/*
diff --git a/drivers/gpu/drm/nouveau/nv04_dac.c b/drivers/gpu/drm/nouveau/nv04_dac.c
index d0e038d28948..1d73b15d70da 100644
--- a/drivers/gpu/drm/nouveau/nv04_dac.c
+++ b/drivers/gpu/drm/nouveau/nv04_dac.c
@@ -119,7 +119,7 @@ static enum drm_connector_status nv04_dac_detect(struct drm_encoder *encoder,
119 struct drm_connector *connector) 119 struct drm_connector *connector)
120{ 120{
121 struct drm_device *dev = encoder->dev; 121 struct drm_device *dev = encoder->dev;
122 uint8_t saved_seq1, saved_pi, saved_rpc1; 122 uint8_t saved_seq1, saved_pi, saved_rpc1, saved_cr_mode;
123 uint8_t saved_palette0[3], saved_palette_mask; 123 uint8_t saved_palette0[3], saved_palette_mask;
124 uint32_t saved_rtest_ctrl, saved_rgen_ctrl; 124 uint32_t saved_rtest_ctrl, saved_rgen_ctrl;
125 int i; 125 int i;
@@ -135,6 +135,9 @@ static enum drm_connector_status nv04_dac_detect(struct drm_encoder *encoder,
135 /* only implemented for head A for now */ 135 /* only implemented for head A for now */
136 NVSetOwner(dev, 0); 136 NVSetOwner(dev, 0);
137 137
138 saved_cr_mode = NVReadVgaCrtc(dev, 0, NV_CIO_CR_MODE_INDEX);
139 NVWriteVgaCrtc(dev, 0, NV_CIO_CR_MODE_INDEX, saved_cr_mode | 0x80);
140
138 saved_seq1 = NVReadVgaSeq(dev, 0, NV_VIO_SR_CLOCK_INDEX); 141 saved_seq1 = NVReadVgaSeq(dev, 0, NV_VIO_SR_CLOCK_INDEX);
139 NVWriteVgaSeq(dev, 0, NV_VIO_SR_CLOCK_INDEX, saved_seq1 & ~0x20); 142 NVWriteVgaSeq(dev, 0, NV_VIO_SR_CLOCK_INDEX, saved_seq1 & ~0x20);
140 143
@@ -203,6 +206,7 @@ out:
203 NVWriteVgaCrtc(dev, 0, NV_CIO_CRE_PIXEL_INDEX, saved_pi); 206 NVWriteVgaCrtc(dev, 0, NV_CIO_CRE_PIXEL_INDEX, saved_pi);
204 NVWriteVgaCrtc(dev, 0, NV_CIO_CRE_RPC1_INDEX, saved_rpc1); 207 NVWriteVgaCrtc(dev, 0, NV_CIO_CRE_RPC1_INDEX, saved_rpc1);
205 NVWriteVgaSeq(dev, 0, NV_VIO_SR_CLOCK_INDEX, saved_seq1); 208 NVWriteVgaSeq(dev, 0, NV_VIO_SR_CLOCK_INDEX, saved_seq1);
209 NVWriteVgaCrtc(dev, 0, NV_CIO_CR_MODE_INDEX, saved_cr_mode);
206 210
207 if (blue == 0x18) { 211 if (blue == 0x18) {
208 NV_INFO(dev, "Load detected on head A\n"); 212 NV_INFO(dev, "Load detected on head A\n");
diff --git a/drivers/gpu/drm/nouveau/nv17_tv.c b/drivers/gpu/drm/nouveau/nv17_tv.c
index 58b917c3341b..21ac6e49b6ee 100644
--- a/drivers/gpu/drm/nouveau/nv17_tv.c
+++ b/drivers/gpu/drm/nouveau/nv17_tv.c
@@ -579,6 +579,8 @@ static void nv17_tv_restore(struct drm_encoder *encoder)
579 nouveau_encoder(encoder)->restore.output); 579 nouveau_encoder(encoder)->restore.output);
580 580
581 nv17_tv_state_load(dev, &to_tv_enc(encoder)->saved_state); 581 nv17_tv_state_load(dev, &to_tv_enc(encoder)->saved_state);
582
583 nouveau_encoder(encoder)->last_dpms = NV_DPMS_CLEARED;
582} 584}
583 585
584static int nv17_tv_create_resources(struct drm_encoder *encoder, 586static int nv17_tv_create_resources(struct drm_encoder *encoder,
diff --git a/drivers/gpu/drm/nouveau/nv50_instmem.c b/drivers/gpu/drm/nouveau/nv50_instmem.c
index 94400f777e7f..f0dc4e36ef05 100644
--- a/drivers/gpu/drm/nouveau/nv50_instmem.c
+++ b/drivers/gpu/drm/nouveau/nv50_instmem.c
@@ -76,6 +76,11 @@ nv50_instmem_init(struct drm_device *dev)
76 for (i = 0x1700; i <= 0x1710; i += 4) 76 for (i = 0x1700; i <= 0x1710; i += 4)
77 priv->save1700[(i-0x1700)/4] = nv_rd32(dev, i); 77 priv->save1700[(i-0x1700)/4] = nv_rd32(dev, i);
78 78
79 if (dev_priv->chipset == 0xaa || dev_priv->chipset == 0xac)
80 dev_priv->vram_sys_base = nv_rd32(dev, 0x100e10) << 12;
81 else
82 dev_priv->vram_sys_base = 0;
83
79 /* Reserve the last MiB of VRAM, we should probably try to avoid 84 /* Reserve the last MiB of VRAM, we should probably try to avoid
80 * setting up the below tables over the top of the VBIOS image at 85 * setting up the below tables over the top of the VBIOS image at
81 * some point. 86 * some point.
@@ -172,16 +177,28 @@ nv50_instmem_init(struct drm_device *dev)
172 * We map the entire fake channel into the start of the PRAMIN BAR 177 * We map the entire fake channel into the start of the PRAMIN BAR
173 */ 178 */
174 ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, pt_size, 0x1000, 179 ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, pt_size, 0x1000,
175 0, &priv->pramin_pt); 180 0, &priv->pramin_pt);
176 if (ret) 181 if (ret)
177 return ret; 182 return ret;
178 183
179 for (i = 0, v = c_offset; i < pt_size; i += 8, v += 0x1000) { 184 v = c_offset | 1;
180 if (v < (c_offset + c_size)) 185 if (dev_priv->vram_sys_base) {
181 BAR0_WI32(priv->pramin_pt->gpuobj, i + 0, v | 1); 186 v += dev_priv->vram_sys_base;
182 else 187 v |= 0x30;
183 BAR0_WI32(priv->pramin_pt->gpuobj, i + 0, 0x00000009); 188 }
189
190 i = 0;
191 while (v < dev_priv->vram_sys_base + c_offset + c_size) {
192 BAR0_WI32(priv->pramin_pt->gpuobj, i + 0, v);
193 BAR0_WI32(priv->pramin_pt->gpuobj, i + 4, 0x00000000);
194 v += 0x1000;
195 i += 8;
196 }
197
198 while (i < pt_size) {
199 BAR0_WI32(priv->pramin_pt->gpuobj, i + 0, 0x00000000);
184 BAR0_WI32(priv->pramin_pt->gpuobj, i + 4, 0x00000000); 200 BAR0_WI32(priv->pramin_pt->gpuobj, i + 4, 0x00000000);
201 i += 8;
185 } 202 }
186 203
187 BAR0_WI32(chan->vm_pd, 0x00, priv->pramin_pt->instance | 0x63); 204 BAR0_WI32(chan->vm_pd, 0x00, priv->pramin_pt->instance | 0x63);
@@ -416,7 +433,9 @@ nv50_instmem_bind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
416{ 433{
417 struct drm_nouveau_private *dev_priv = dev->dev_private; 434 struct drm_nouveau_private *dev_priv = dev->dev_private;
418 struct nv50_instmem_priv *priv = dev_priv->engine.instmem.priv; 435 struct nv50_instmem_priv *priv = dev_priv->engine.instmem.priv;
419 uint32_t pte, pte_end, vram; 436 struct nouveau_gpuobj *pramin_pt = priv->pramin_pt->gpuobj;
437 uint32_t pte, pte_end;
438 uint64_t vram;
420 439
421 if (!gpuobj->im_backing || !gpuobj->im_pramin || gpuobj->im_bound) 440 if (!gpuobj->im_backing || !gpuobj->im_pramin || gpuobj->im_bound)
422 return -EINVAL; 441 return -EINVAL;
@@ -424,20 +443,24 @@ nv50_instmem_bind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
424 NV_DEBUG(dev, "st=0x%0llx sz=0x%0llx\n", 443 NV_DEBUG(dev, "st=0x%0llx sz=0x%0llx\n",
425 gpuobj->im_pramin->start, gpuobj->im_pramin->size); 444 gpuobj->im_pramin->start, gpuobj->im_pramin->size);
426 445
427 pte = (gpuobj->im_pramin->start >> 12) << 3; 446 pte = (gpuobj->im_pramin->start >> 12) << 1;
428 pte_end = ((gpuobj->im_pramin->size >> 12) << 3) + pte; 447 pte_end = ((gpuobj->im_pramin->size >> 12) << 1) + pte;
429 vram = gpuobj->im_backing_start; 448 vram = gpuobj->im_backing_start;
430 449
431 NV_DEBUG(dev, "pramin=0x%llx, pte=%d, pte_end=%d\n", 450 NV_DEBUG(dev, "pramin=0x%llx, pte=%d, pte_end=%d\n",
432 gpuobj->im_pramin->start, pte, pte_end); 451 gpuobj->im_pramin->start, pte, pte_end);
433 NV_DEBUG(dev, "first vram page: 0x%08x\n", gpuobj->im_backing_start); 452 NV_DEBUG(dev, "first vram page: 0x%08x\n", gpuobj->im_backing_start);
434 453
454 vram |= 1;
455 if (dev_priv->vram_sys_base) {
456 vram += dev_priv->vram_sys_base;
457 vram |= 0x30;
458 }
459
435 dev_priv->engine.instmem.prepare_access(dev, true); 460 dev_priv->engine.instmem.prepare_access(dev, true);
436 while (pte < pte_end) { 461 while (pte < pte_end) {
437 nv_wo32(dev, priv->pramin_pt->gpuobj, (pte + 0)/4, vram | 1); 462 nv_wo32(dev, pramin_pt, pte++, lower_32_bits(vram));
438 nv_wo32(dev, priv->pramin_pt->gpuobj, (pte + 4)/4, 0x00000000); 463 nv_wo32(dev, pramin_pt, pte++, upper_32_bits(vram));
439
440 pte += 8;
441 vram += NV50_INSTMEM_PAGE_SIZE; 464 vram += NV50_INSTMEM_PAGE_SIZE;
442 } 465 }
443 dev_priv->engine.instmem.finish_access(dev); 466 dev_priv->engine.instmem.finish_access(dev);
@@ -470,14 +493,13 @@ nv50_instmem_unbind(struct drm_device *dev, struct nouveau_gpuobj *gpuobj)
470 if (gpuobj->im_bound == 0) 493 if (gpuobj->im_bound == 0)
471 return -EINVAL; 494 return -EINVAL;
472 495
473 pte = (gpuobj->im_pramin->start >> 12) << 3; 496 pte = (gpuobj->im_pramin->start >> 12) << 1;
474 pte_end = ((gpuobj->im_pramin->size >> 12) << 3) + pte; 497 pte_end = ((gpuobj->im_pramin->size >> 12) << 1) + pte;
475 498
476 dev_priv->engine.instmem.prepare_access(dev, true); 499 dev_priv->engine.instmem.prepare_access(dev, true);
477 while (pte < pte_end) { 500 while (pte < pte_end) {
478 nv_wo32(dev, priv->pramin_pt->gpuobj, (pte + 0)/4, 0x00000009); 501 nv_wo32(dev, priv->pramin_pt->gpuobj, pte++, 0x00000000);
479 nv_wo32(dev, priv->pramin_pt->gpuobj, (pte + 4)/4, 0x00000000); 502 nv_wo32(dev, priv->pramin_pt->gpuobj, pte++, 0x00000000);
480 pte += 8;
481 } 503 }
482 dev_priv->engine.instmem.finish_access(dev); 504 dev_priv->engine.instmem.finish_access(dev);
483 505
diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
index 2a3df5599ab4..7f152f66f196 100644
--- a/drivers/gpu/drm/radeon/atom.c
+++ b/drivers/gpu/drm/radeon/atom.c
@@ -643,7 +643,7 @@ static void atom_op_delay(atom_exec_context *ctx, int *ptr, int arg)
643 uint8_t count = U8((*ptr)++); 643 uint8_t count = U8((*ptr)++);
644 SDEBUG(" count: %d\n", count); 644 SDEBUG(" count: %d\n", count);
645 if (arg == ATOM_UNIT_MICROSEC) 645 if (arg == ATOM_UNIT_MICROSEC)
646 schedule_timeout_uninterruptible(usecs_to_jiffies(count)); 646 udelay(count);
647 else 647 else
648 schedule_timeout_uninterruptible(msecs_to_jiffies(count)); 648 schedule_timeout_uninterruptible(msecs_to_jiffies(count));
649} 649}
diff --git a/drivers/gpu/drm/radeon/r600_blit_kms.c b/drivers/gpu/drm/radeon/r600_blit_kms.c
index af1c3ca8a4cb..446b765ac72a 100644
--- a/drivers/gpu/drm/radeon/r600_blit_kms.c
+++ b/drivers/gpu/drm/radeon/r600_blit_kms.c
@@ -543,9 +543,6 @@ int r600_vb_ib_get(struct radeon_device *rdev)
543void r600_vb_ib_put(struct radeon_device *rdev) 543void r600_vb_ib_put(struct radeon_device *rdev)
544{ 544{
545 radeon_fence_emit(rdev, rdev->r600_blit.vb_ib->fence); 545 radeon_fence_emit(rdev, rdev->r600_blit.vb_ib->fence);
546 mutex_lock(&rdev->ib_pool.mutex);
547 list_add_tail(&rdev->r600_blit.vb_ib->list, &rdev->ib_pool.scheduled_ibs);
548 mutex_unlock(&rdev->ib_pool.mutex);
549 radeon_ib_free(rdev, &rdev->r600_blit.vb_ib); 546 radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
550} 547}
551 548
diff --git a/drivers/gpu/drm/radeon/r600_cp.c b/drivers/gpu/drm/radeon/r600_cp.c
index 6d5a711c2e91..75bcf35a0931 100644
--- a/drivers/gpu/drm/radeon/r600_cp.c
+++ b/drivers/gpu/drm/radeon/r600_cp.c
@@ -1428,9 +1428,12 @@ static void r700_gfx_init(struct drm_device *dev,
1428 1428
1429 gb_tiling_config |= R600_BANK_SWAPS(1); 1429 gb_tiling_config |= R600_BANK_SWAPS(1);
1430 1430
1431 backend_map = r700_get_tile_pipe_to_backend_map(dev_priv->r600_max_tile_pipes, 1431 if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV740)
1432 dev_priv->r600_max_backends, 1432 backend_map = 0x28;
1433 (0xff << dev_priv->r600_max_backends) & 0xff); 1433 else
1434 backend_map = r700_get_tile_pipe_to_backend_map(dev_priv->r600_max_tile_pipes,
1435 dev_priv->r600_max_backends,
1436 (0xff << dev_priv->r600_max_backends) & 0xff);
1434 gb_tiling_config |= R600_BACKEND_MAP(backend_map); 1437 gb_tiling_config |= R600_BACKEND_MAP(backend_map);
1435 1438
1436 cc_gc_shader_pipe_config = 1439 cc_gc_shader_pipe_config =
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index f57480ba1355..c0356bb193e5 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -96,6 +96,7 @@ extern int radeon_audio;
96 * symbol; 96 * symbol;
97 */ 97 */
98#define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */ 98#define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
99/* RADEON_IB_POOL_SIZE must be a power of 2 */
99#define RADEON_IB_POOL_SIZE 16 100#define RADEON_IB_POOL_SIZE 16
100#define RADEON_DEBUGFS_MAX_NUM_FILES 32 101#define RADEON_DEBUGFS_MAX_NUM_FILES 32
101#define RADEONFB_CONN_LIMIT 4 102#define RADEONFB_CONN_LIMIT 4
@@ -363,11 +364,12 @@ void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
363 */ 364 */
364struct radeon_ib { 365struct radeon_ib {
365 struct list_head list; 366 struct list_head list;
366 unsigned long idx; 367 unsigned idx;
367 uint64_t gpu_addr; 368 uint64_t gpu_addr;
368 struct radeon_fence *fence; 369 struct radeon_fence *fence;
369 uint32_t *ptr; 370 uint32_t *ptr;
370 uint32_t length_dw; 371 uint32_t length_dw;
372 bool free;
371}; 373};
372 374
373/* 375/*
@@ -377,10 +379,9 @@ struct radeon_ib {
377struct radeon_ib_pool { 379struct radeon_ib_pool {
378 struct mutex mutex; 380 struct mutex mutex;
379 struct radeon_bo *robj; 381 struct radeon_bo *robj;
380 struct list_head scheduled_ibs;
381 struct radeon_ib ibs[RADEON_IB_POOL_SIZE]; 382 struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
382 bool ready; 383 bool ready;
383 DECLARE_BITMAP(alloc_bm, RADEON_IB_POOL_SIZE); 384 unsigned head_id;
384}; 385};
385 386
386struct radeon_cp { 387struct radeon_cp {
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index 2dcda6115874..4d8831548a5f 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -206,6 +206,15 @@ static bool radeon_atom_apply_quirks(struct drm_device *dev,
206 *connector_type = DRM_MODE_CONNECTOR_DVID; 206 *connector_type = DRM_MODE_CONNECTOR_DVID;
207 } 207 }
208 208
209 /* Asrock RS600 board lists the DVI port as HDMI */
210 if ((dev->pdev->device == 0x7941) &&
211 (dev->pdev->subsystem_vendor == 0x1849) &&
212 (dev->pdev->subsystem_device == 0x7941)) {
213 if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
214 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
215 *connector_type = DRM_MODE_CONNECTOR_DVID;
216 }
217
209 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */ 218 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
210 if ((dev->pdev->device == 0x7941) && 219 if ((dev->pdev->device == 0x7941) &&
211 (dev->pdev->subsystem_vendor == 0x147b) && 220 (dev->pdev->subsystem_vendor == 0x147b) &&
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index e7b19440102e..22d476160d52 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -1279,47 +1279,47 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1279 rdev->mode_info.connector_table = radeon_connector_table; 1279 rdev->mode_info.connector_table = radeon_connector_table;
1280 if (rdev->mode_info.connector_table == CT_NONE) { 1280 if (rdev->mode_info.connector_table == CT_NONE) {
1281#ifdef CONFIG_PPC_PMAC 1281#ifdef CONFIG_PPC_PMAC
1282 if (machine_is_compatible("PowerBook3,3")) { 1282 if (of_machine_is_compatible("PowerBook3,3")) {
1283 /* powerbook with VGA */ 1283 /* powerbook with VGA */
1284 rdev->mode_info.connector_table = CT_POWERBOOK_VGA; 1284 rdev->mode_info.connector_table = CT_POWERBOOK_VGA;
1285 } else if (machine_is_compatible("PowerBook3,4") || 1285 } else if (of_machine_is_compatible("PowerBook3,4") ||
1286 machine_is_compatible("PowerBook3,5")) { 1286 of_machine_is_compatible("PowerBook3,5")) {
1287 /* powerbook with internal tmds */ 1287 /* powerbook with internal tmds */
1288 rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL; 1288 rdev->mode_info.connector_table = CT_POWERBOOK_INTERNAL;
1289 } else if (machine_is_compatible("PowerBook5,1") || 1289 } else if (of_machine_is_compatible("PowerBook5,1") ||
1290 machine_is_compatible("PowerBook5,2") || 1290 of_machine_is_compatible("PowerBook5,2") ||
1291 machine_is_compatible("PowerBook5,3") || 1291 of_machine_is_compatible("PowerBook5,3") ||
1292 machine_is_compatible("PowerBook5,4") || 1292 of_machine_is_compatible("PowerBook5,4") ||
1293 machine_is_compatible("PowerBook5,5")) { 1293 of_machine_is_compatible("PowerBook5,5")) {
1294 /* powerbook with external single link tmds (sil164) */ 1294 /* powerbook with external single link tmds (sil164) */
1295 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL; 1295 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
1296 } else if (machine_is_compatible("PowerBook5,6")) { 1296 } else if (of_machine_is_compatible("PowerBook5,6")) {
1297 /* powerbook with external dual or single link tmds */ 1297 /* powerbook with external dual or single link tmds */
1298 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL; 1298 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
1299 } else if (machine_is_compatible("PowerBook5,7") || 1299 } else if (of_machine_is_compatible("PowerBook5,7") ||
1300 machine_is_compatible("PowerBook5,8") || 1300 of_machine_is_compatible("PowerBook5,8") ||
1301 machine_is_compatible("PowerBook5,9")) { 1301 of_machine_is_compatible("PowerBook5,9")) {
1302 /* PowerBook6,2 ? */ 1302 /* PowerBook6,2 ? */
1303 /* powerbook with external dual link tmds (sil1178?) */ 1303 /* powerbook with external dual link tmds (sil1178?) */
1304 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL; 1304 rdev->mode_info.connector_table = CT_POWERBOOK_EXTERNAL;
1305 } else if (machine_is_compatible("PowerBook4,1") || 1305 } else if (of_machine_is_compatible("PowerBook4,1") ||
1306 machine_is_compatible("PowerBook4,2") || 1306 of_machine_is_compatible("PowerBook4,2") ||
1307 machine_is_compatible("PowerBook4,3") || 1307 of_machine_is_compatible("PowerBook4,3") ||
1308 machine_is_compatible("PowerBook6,3") || 1308 of_machine_is_compatible("PowerBook6,3") ||
1309 machine_is_compatible("PowerBook6,5") || 1309 of_machine_is_compatible("PowerBook6,5") ||
1310 machine_is_compatible("PowerBook6,7")) { 1310 of_machine_is_compatible("PowerBook6,7")) {
1311 /* ibook */ 1311 /* ibook */
1312 rdev->mode_info.connector_table = CT_IBOOK; 1312 rdev->mode_info.connector_table = CT_IBOOK;
1313 } else if (machine_is_compatible("PowerMac4,4")) { 1313 } else if (of_machine_is_compatible("PowerMac4,4")) {
1314 /* emac */ 1314 /* emac */
1315 rdev->mode_info.connector_table = CT_EMAC; 1315 rdev->mode_info.connector_table = CT_EMAC;
1316 } else if (machine_is_compatible("PowerMac10,1")) { 1316 } else if (of_machine_is_compatible("PowerMac10,1")) {
1317 /* mini with internal tmds */ 1317 /* mini with internal tmds */
1318 rdev->mode_info.connector_table = CT_MINI_INTERNAL; 1318 rdev->mode_info.connector_table = CT_MINI_INTERNAL;
1319 } else if (machine_is_compatible("PowerMac10,2")) { 1319 } else if (of_machine_is_compatible("PowerMac10,2")) {
1320 /* mini with external tmds */ 1320 /* mini with external tmds */
1321 rdev->mode_info.connector_table = CT_MINI_EXTERNAL; 1321 rdev->mode_info.connector_table = CT_MINI_EXTERNAL;
1322 } else if (machine_is_compatible("PowerMac12,1")) { 1322 } else if (of_machine_is_compatible("PowerMac12,1")) {
1323 /* PowerMac8,1 ? */ 1323 /* PowerMac8,1 ? */
1324 /* imac g5 isight */ 1324 /* imac g5 isight */
1325 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT; 1325 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 238188540017..65f81942f399 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -780,7 +780,7 @@ static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connect
780 * connected and the DVI port disconnected. If the edid doesn't 780 * connected and the DVI port disconnected. If the edid doesn't
781 * say HDMI, vice versa. 781 * say HDMI, vice versa.
782 */ 782 */
783 if (radeon_connector->shared_ddc && connector_status_connected) { 783 if (radeon_connector->shared_ddc && (ret == connector_status_connected)) {
784 struct drm_device *dev = connector->dev; 784 struct drm_device *dev = connector->dev;
785 struct drm_connector *list_connector; 785 struct drm_connector *list_connector;
786 struct radeon_connector *list_radeon_connector; 786 struct radeon_connector *list_radeon_connector;
@@ -1060,8 +1060,7 @@ radeon_add_atom_connector(struct drm_device *dev,
1060 return; 1060 return;
1061 } 1061 }
1062 if (radeon_connector->ddc_bus && i2c_bus->valid) { 1062 if (radeon_connector->ddc_bus && i2c_bus->valid) {
1063 if (memcmp(&radeon_connector->ddc_bus->rec, i2c_bus, 1063 if (radeon_connector->ddc_bus->rec.i2c_id == i2c_bus->i2c_id) {
1064 sizeof(struct radeon_i2c_bus_rec)) == 0) {
1065 radeon_connector->shared_ddc = true; 1064 radeon_connector->shared_ddc = true;
1066 shared_ddc = true; 1065 shared_ddc = true;
1067 } 1066 }
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index 1190148cf5e6..e9d085021c1f 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -86,7 +86,7 @@ int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
86 &p->validated); 86 &p->validated);
87 } 87 }
88 } 88 }
89 return radeon_bo_list_validate(&p->validated, p->ib->fence); 89 return radeon_bo_list_validate(&p->validated);
90} 90}
91 91
92int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data) 92int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data)
@@ -189,12 +189,10 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error)
189{ 189{
190 unsigned i; 190 unsigned i;
191 191
192 if (error && parser->ib) { 192 if (!error && parser->ib) {
193 radeon_bo_list_unvalidate(&parser->validated, 193 radeon_bo_list_fence(&parser->validated, parser->ib->fence);
194 parser->ib->fence);
195 } else {
196 radeon_bo_list_unreserve(&parser->validated);
197 } 194 }
195 radeon_bo_list_unreserve(&parser->validated);
198 for (i = 0; i < parser->nrelocs; i++) { 196 for (i = 0; i < parser->nrelocs; i++) {
199 if (parser->relocs[i].gobj) { 197 if (parser->relocs[i].gobj) {
200 mutex_lock(&parser->rdev->ddev->struct_mutex); 198 mutex_lock(&parser->rdev->ddev->struct_mutex);
diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
index e13785282a82..c57ad606504d 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.h
+++ b/drivers/gpu/drm/radeon/radeon_drv.h
@@ -106,9 +106,10 @@
106 * 1.29- R500 3D cmd buffer support 106 * 1.29- R500 3D cmd buffer support
107 * 1.30- Add support for occlusion queries 107 * 1.30- Add support for occlusion queries
108 * 1.31- Add support for num Z pipes from GET_PARAM 108 * 1.31- Add support for num Z pipes from GET_PARAM
109 * 1.32- fixes for rv740 setup
109 */ 110 */
110#define DRIVER_MAJOR 1 111#define DRIVER_MAJOR 1
111#define DRIVER_MINOR 31 112#define DRIVER_MINOR 32
112#define DRIVER_PATCHLEVEL 0 113#define DRIVER_PATCHLEVEL 0
113 114
114enum radeon_cp_microcode_version { 115enum radeon_cp_microcode_version {
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index d72a71bff218..f1da370928eb 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -306,11 +306,10 @@ void radeon_bo_list_unreserve(struct list_head *head)
306 } 306 }
307} 307}
308 308
309int radeon_bo_list_validate(struct list_head *head, void *fence) 309int radeon_bo_list_validate(struct list_head *head)
310{ 310{
311 struct radeon_bo_list *lobj; 311 struct radeon_bo_list *lobj;
312 struct radeon_bo *bo; 312 struct radeon_bo *bo;
313 struct radeon_fence *old_fence = NULL;
314 int r; 313 int r;
315 314
316 r = radeon_bo_list_reserve(head); 315 r = radeon_bo_list_reserve(head);
@@ -334,32 +333,27 @@ int radeon_bo_list_validate(struct list_head *head, void *fence)
334 } 333 }
335 lobj->gpu_offset = radeon_bo_gpu_offset(bo); 334 lobj->gpu_offset = radeon_bo_gpu_offset(bo);
336 lobj->tiling_flags = bo->tiling_flags; 335 lobj->tiling_flags = bo->tiling_flags;
337 if (fence) {
338 old_fence = (struct radeon_fence *)bo->tbo.sync_obj;
339 bo->tbo.sync_obj = radeon_fence_ref(fence);
340 bo->tbo.sync_obj_arg = NULL;
341 }
342 if (old_fence) {
343 radeon_fence_unref(&old_fence);
344 }
345 } 336 }
346 return 0; 337 return 0;
347} 338}
348 339
349void radeon_bo_list_unvalidate(struct list_head *head, void *fence) 340void radeon_bo_list_fence(struct list_head *head, void *fence)
350{ 341{
351 struct radeon_bo_list *lobj; 342 struct radeon_bo_list *lobj;
352 struct radeon_fence *old_fence; 343 struct radeon_bo *bo;
353 344 struct radeon_fence *old_fence = NULL;
354 if (fence) 345
355 list_for_each_entry(lobj, head, list) { 346 list_for_each_entry(lobj, head, list) {
356 old_fence = to_radeon_fence(lobj->bo->tbo.sync_obj); 347 bo = lobj->bo;
357 if (old_fence == fence) { 348 spin_lock(&bo->tbo.lock);
358 lobj->bo->tbo.sync_obj = NULL; 349 old_fence = (struct radeon_fence *)bo->tbo.sync_obj;
359 radeon_fence_unref(&old_fence); 350 bo->tbo.sync_obj = radeon_fence_ref(fence);
360 } 351 bo->tbo.sync_obj_arg = NULL;
352 spin_unlock(&bo->tbo.lock);
353 if (old_fence) {
354 radeon_fence_unref(&old_fence);
361 } 355 }
362 radeon_bo_list_unreserve(head); 356 }
363} 357}
364 358
365int radeon_bo_fbdev_mmap(struct radeon_bo *bo, 359int radeon_bo_fbdev_mmap(struct radeon_bo *bo,
diff --git a/drivers/gpu/drm/radeon/radeon_object.h b/drivers/gpu/drm/radeon/radeon_object.h
index a02f18011ad1..7ab43de1e244 100644
--- a/drivers/gpu/drm/radeon/radeon_object.h
+++ b/drivers/gpu/drm/radeon/radeon_object.h
@@ -156,8 +156,8 @@ extern void radeon_bo_list_add_object(struct radeon_bo_list *lobj,
156 struct list_head *head); 156 struct list_head *head);
157extern int radeon_bo_list_reserve(struct list_head *head); 157extern int radeon_bo_list_reserve(struct list_head *head);
158extern void radeon_bo_list_unreserve(struct list_head *head); 158extern void radeon_bo_list_unreserve(struct list_head *head);
159extern int radeon_bo_list_validate(struct list_head *head, void *fence); 159extern int radeon_bo_list_validate(struct list_head *head);
160extern void radeon_bo_list_unvalidate(struct list_head *head, void *fence); 160extern void radeon_bo_list_fence(struct list_head *head, void *fence);
161extern int radeon_bo_fbdev_mmap(struct radeon_bo *bo, 161extern int radeon_bo_fbdev_mmap(struct radeon_bo *bo,
162 struct vm_area_struct *vma); 162 struct vm_area_struct *vma);
163extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo, 163extern int radeon_bo_set_tiling_flags(struct radeon_bo *bo,
diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c
index 4d12b2d17b4d..6579eb4c1f28 100644
--- a/drivers/gpu/drm/radeon/radeon_ring.c
+++ b/drivers/gpu/drm/radeon/radeon_ring.c
@@ -41,68 +41,55 @@ int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib)
41{ 41{
42 struct radeon_fence *fence; 42 struct radeon_fence *fence;
43 struct radeon_ib *nib; 43 struct radeon_ib *nib;
44 unsigned long i; 44 int r = 0, i, c;
45 int r = 0;
46 45
47 *ib = NULL; 46 *ib = NULL;
48 r = radeon_fence_create(rdev, &fence); 47 r = radeon_fence_create(rdev, &fence);
49 if (r) { 48 if (r) {
50 DRM_ERROR("failed to create fence for new IB\n"); 49 dev_err(rdev->dev, "failed to create fence for new IB\n");
51 return r; 50 return r;
52 } 51 }
53 mutex_lock(&rdev->ib_pool.mutex); 52 mutex_lock(&rdev->ib_pool.mutex);
54 i = find_first_zero_bit(rdev->ib_pool.alloc_bm, RADEON_IB_POOL_SIZE); 53 for (i = rdev->ib_pool.head_id, c = 0, nib = NULL; c < RADEON_IB_POOL_SIZE; c++, i++) {
55 if (i < RADEON_IB_POOL_SIZE) { 54 i &= (RADEON_IB_POOL_SIZE - 1);
56 set_bit(i, rdev->ib_pool.alloc_bm); 55 if (rdev->ib_pool.ibs[i].free) {
57 rdev->ib_pool.ibs[i].length_dw = 0; 56 nib = &rdev->ib_pool.ibs[i];
58 *ib = &rdev->ib_pool.ibs[i]; 57 break;
59 mutex_unlock(&rdev->ib_pool.mutex); 58 }
60 goto out;
61 } 59 }
62 if (list_empty(&rdev->ib_pool.scheduled_ibs)) { 60 if (nib == NULL) {
63 /* we go do nothings here */ 61 /* This should never happen, it means we allocated all
62 * IB and haven't scheduled one yet, return EBUSY to
63 * userspace hoping that on ioctl recall we get better
64 * luck
65 */
66 dev_err(rdev->dev, "no free indirect buffer !\n");
64 mutex_unlock(&rdev->ib_pool.mutex); 67 mutex_unlock(&rdev->ib_pool.mutex);
65 DRM_ERROR("all IB allocated none scheduled.\n"); 68 radeon_fence_unref(&fence);
66 r = -EINVAL; 69 return -EBUSY;
67 goto out;
68 } 70 }
69 /* get the first ib on the scheduled list */ 71 rdev->ib_pool.head_id = (nib->idx + 1) & (RADEON_IB_POOL_SIZE - 1);
70 nib = list_entry(rdev->ib_pool.scheduled_ibs.next, 72 nib->free = false;
71 struct radeon_ib, list); 73 if (nib->fence) {
72 if (nib->fence == NULL) {
73 /* we go do nothings here */
74 mutex_unlock(&rdev->ib_pool.mutex); 74 mutex_unlock(&rdev->ib_pool.mutex);
75 DRM_ERROR("IB %lu scheduled without a fence.\n", nib->idx); 75 r = radeon_fence_wait(nib->fence, false);
76 r = -EINVAL; 76 if (r) {
77 goto out; 77 dev_err(rdev->dev, "error waiting fence of IB(%u:0x%016lX:%u)\n",
78 } 78 nib->idx, (unsigned long)nib->gpu_addr, nib->length_dw);
79 mutex_unlock(&rdev->ib_pool.mutex); 79 mutex_lock(&rdev->ib_pool.mutex);
80 80 nib->free = true;
81 r = radeon_fence_wait(nib->fence, false); 81 mutex_unlock(&rdev->ib_pool.mutex);
82 if (r) { 82 radeon_fence_unref(&fence);
83 DRM_ERROR("radeon: IB(%lu:0x%016lX:%u)\n", nib->idx, 83 return r;
84 (unsigned long)nib->gpu_addr, nib->length_dw); 84 }
85 DRM_ERROR("radeon: GPU lockup detected, fail to get a IB\n"); 85 mutex_lock(&rdev->ib_pool.mutex);
86 goto out;
87 } 86 }
88 radeon_fence_unref(&nib->fence); 87 radeon_fence_unref(&nib->fence);
89 88 nib->fence = fence;
90 nib->length_dw = 0; 89 nib->length_dw = 0;
91
92 /* scheduled list is accessed here */
93 mutex_lock(&rdev->ib_pool.mutex);
94 list_del(&nib->list);
95 INIT_LIST_HEAD(&nib->list);
96 mutex_unlock(&rdev->ib_pool.mutex); 90 mutex_unlock(&rdev->ib_pool.mutex);
97
98 *ib = nib; 91 *ib = nib;
99out: 92 return 0;
100 if (r) {
101 radeon_fence_unref(&fence);
102 } else {
103 (*ib)->fence = fence;
104 }
105 return r;
106} 93}
107 94
108void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib) 95void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
@@ -113,19 +100,10 @@ void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib)
113 if (tmp == NULL) { 100 if (tmp == NULL) {
114 return; 101 return;
115 } 102 }
116 mutex_lock(&rdev->ib_pool.mutex); 103 if (!tmp->fence->emited)
117 if (!list_empty(&tmp->list) && !radeon_fence_signaled(tmp->fence)) {
118 /* IB is scheduled & not signaled don't do anythings */
119 mutex_unlock(&rdev->ib_pool.mutex);
120 return;
121 }
122 list_del(&tmp->list);
123 INIT_LIST_HEAD(&tmp->list);
124 if (tmp->fence)
125 radeon_fence_unref(&tmp->fence); 104 radeon_fence_unref(&tmp->fence);
126 105 mutex_lock(&rdev->ib_pool.mutex);
127 tmp->length_dw = 0; 106 tmp->free = true;
128 clear_bit(tmp->idx, rdev->ib_pool.alloc_bm);
129 mutex_unlock(&rdev->ib_pool.mutex); 107 mutex_unlock(&rdev->ib_pool.mutex);
130} 108}
131 109
@@ -135,7 +113,7 @@ int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib)
135 113
136 if (!ib->length_dw || !rdev->cp.ready) { 114 if (!ib->length_dw || !rdev->cp.ready) {
137 /* TODO: Nothings in the ib we should report. */ 115 /* TODO: Nothings in the ib we should report. */
138 DRM_ERROR("radeon: couldn't schedule IB(%lu).\n", ib->idx); 116 DRM_ERROR("radeon: couldn't schedule IB(%u).\n", ib->idx);
139 return -EINVAL; 117 return -EINVAL;
140 } 118 }
141 119
@@ -148,7 +126,8 @@ int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib)
148 radeon_ring_ib_execute(rdev, ib); 126 radeon_ring_ib_execute(rdev, ib);
149 radeon_fence_emit(rdev, ib->fence); 127 radeon_fence_emit(rdev, ib->fence);
150 mutex_lock(&rdev->ib_pool.mutex); 128 mutex_lock(&rdev->ib_pool.mutex);
151 list_add_tail(&ib->list, &rdev->ib_pool.scheduled_ibs); 129 /* once scheduled IB is considered free and protected by the fence */
130 ib->free = true;
152 mutex_unlock(&rdev->ib_pool.mutex); 131 mutex_unlock(&rdev->ib_pool.mutex);
153 radeon_ring_unlock_commit(rdev); 132 radeon_ring_unlock_commit(rdev);
154 return 0; 133 return 0;
@@ -164,7 +143,6 @@ int radeon_ib_pool_init(struct radeon_device *rdev)
164 if (rdev->ib_pool.robj) 143 if (rdev->ib_pool.robj)
165 return 0; 144 return 0;
166 /* Allocate 1M object buffer */ 145 /* Allocate 1M object buffer */
167 INIT_LIST_HEAD(&rdev->ib_pool.scheduled_ibs);
168 r = radeon_bo_create(rdev, NULL, RADEON_IB_POOL_SIZE*64*1024, 146 r = radeon_bo_create(rdev, NULL, RADEON_IB_POOL_SIZE*64*1024,
169 true, RADEON_GEM_DOMAIN_GTT, 147 true, RADEON_GEM_DOMAIN_GTT,
170 &rdev->ib_pool.robj); 148 &rdev->ib_pool.robj);
@@ -195,9 +173,9 @@ int radeon_ib_pool_init(struct radeon_device *rdev)
195 rdev->ib_pool.ibs[i].ptr = ptr + offset; 173 rdev->ib_pool.ibs[i].ptr = ptr + offset;
196 rdev->ib_pool.ibs[i].idx = i; 174 rdev->ib_pool.ibs[i].idx = i;
197 rdev->ib_pool.ibs[i].length_dw = 0; 175 rdev->ib_pool.ibs[i].length_dw = 0;
198 INIT_LIST_HEAD(&rdev->ib_pool.ibs[i].list); 176 rdev->ib_pool.ibs[i].free = true;
199 } 177 }
200 bitmap_zero(rdev->ib_pool.alloc_bm, RADEON_IB_POOL_SIZE); 178 rdev->ib_pool.head_id = 0;
201 rdev->ib_pool.ready = true; 179 rdev->ib_pool.ready = true;
202 DRM_INFO("radeon: ib pool ready.\n"); 180 DRM_INFO("radeon: ib pool ready.\n");
203 if (radeon_debugfs_ib_init(rdev)) { 181 if (radeon_debugfs_ib_init(rdev)) {
@@ -214,7 +192,6 @@ void radeon_ib_pool_fini(struct radeon_device *rdev)
214 return; 192 return;
215 } 193 }
216 mutex_lock(&rdev->ib_pool.mutex); 194 mutex_lock(&rdev->ib_pool.mutex);
217 bitmap_zero(rdev->ib_pool.alloc_bm, RADEON_IB_POOL_SIZE);
218 if (rdev->ib_pool.robj) { 195 if (rdev->ib_pool.robj) {
219 r = radeon_bo_reserve(rdev->ib_pool.robj, false); 196 r = radeon_bo_reserve(rdev->ib_pool.robj, false);
220 if (likely(r == 0)) { 197 if (likely(r == 0)) {
@@ -363,7 +340,7 @@ static int radeon_debugfs_ib_info(struct seq_file *m, void *data)
363 if (ib == NULL) { 340 if (ib == NULL) {
364 return 0; 341 return 0;
365 } 342 }
366 seq_printf(m, "IB %04lu\n", ib->idx); 343 seq_printf(m, "IB %04u\n", ib->idx);
367 seq_printf(m, "IB fence %p\n", ib->fence); 344 seq_printf(m, "IB fence %p\n", ib->fence);
368 seq_printf(m, "IB size %05u dwords\n", ib->length_dw); 345 seq_printf(m, "IB size %05u dwords\n", ib->length_dw);
369 for (i = 0; i < ib->length_dw; i++) { 346 for (i = 0; i < ib->length_dw; i++) {
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index 5943d561fd1e..03021674d097 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -549,9 +549,12 @@ static void rv770_gpu_init(struct radeon_device *rdev)
549 549
550 gb_tiling_config |= BANK_SWAPS(1); 550 gb_tiling_config |= BANK_SWAPS(1);
551 551
552 backend_map = r700_get_tile_pipe_to_backend_map(rdev->config.rv770.max_tile_pipes, 552 if (rdev->family == CHIP_RV740)
553 rdev->config.rv770.max_backends, 553 backend_map = 0x28;
554 (0xff << rdev->config.rv770.max_backends) & 0xff); 554 else
555 backend_map = r700_get_tile_pipe_to_backend_map(rdev->config.rv770.max_tile_pipes,
556 rdev->config.rv770.max_backends,
557 (0xff << rdev->config.rv770.max_backends) & 0xff);
555 gb_tiling_config |= BACKEND_MAP(backend_map); 558 gb_tiling_config |= BACKEND_MAP(backend_map);
556 559
557 cc_gc_shader_pipe_config = 560 cc_gc_shader_pipe_config =
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index e2123af7775a..3d47a2c12322 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -196,14 +196,15 @@ EXPORT_SYMBOL(ttm_tt_populate);
196 196
197#ifdef CONFIG_X86 197#ifdef CONFIG_X86
198static inline int ttm_tt_set_page_caching(struct page *p, 198static inline int ttm_tt_set_page_caching(struct page *p,
199 enum ttm_caching_state c_state) 199 enum ttm_caching_state c_old,
200 enum ttm_caching_state c_new)
200{ 201{
201 int ret = 0; 202 int ret = 0;
202 203
203 if (PageHighMem(p)) 204 if (PageHighMem(p))
204 return 0; 205 return 0;
205 206
206 if (get_page_memtype(p) != -1) { 207 if (c_old != tt_cached) {
207 /* p isn't in the default caching state, set it to 208 /* p isn't in the default caching state, set it to
208 * writeback first to free its current memtype. */ 209 * writeback first to free its current memtype. */
209 210
@@ -212,16 +213,17 @@ static inline int ttm_tt_set_page_caching(struct page *p,
212 return ret; 213 return ret;
213 } 214 }
214 215
215 if (c_state == tt_wc) 216 if (c_new == tt_wc)
216 ret = set_memory_wc((unsigned long) page_address(p), 1); 217 ret = set_memory_wc((unsigned long) page_address(p), 1);
217 else if (c_state == tt_uncached) 218 else if (c_new == tt_uncached)
218 ret = set_pages_uc(p, 1); 219 ret = set_pages_uc(p, 1);
219 220
220 return ret; 221 return ret;
221} 222}
222#else /* CONFIG_X86 */ 223#else /* CONFIG_X86 */
223static inline int ttm_tt_set_page_caching(struct page *p, 224static inline int ttm_tt_set_page_caching(struct page *p,
224 enum ttm_caching_state c_state) 225 enum ttm_caching_state c_old,
226 enum ttm_caching_state c_new)
225{ 227{
226 return 0; 228 return 0;
227} 229}
@@ -254,7 +256,9 @@ static int ttm_tt_set_caching(struct ttm_tt *ttm,
254 for (i = 0; i < ttm->num_pages; ++i) { 256 for (i = 0; i < ttm->num_pages; ++i) {
255 cur_page = ttm->pages[i]; 257 cur_page = ttm->pages[i];
256 if (likely(cur_page != NULL)) { 258 if (likely(cur_page != NULL)) {
257 ret = ttm_tt_set_page_caching(cur_page, c_state); 259 ret = ttm_tt_set_page_caching(cur_page,
260 ttm->caching_state,
261 c_state);
258 if (unlikely(ret != 0)) 262 if (unlikely(ret != 0))
259 goto out_err; 263 goto out_err;
260 } 264 }
@@ -268,7 +272,7 @@ out_err:
268 for (j = 0; j < i; ++j) { 272 for (j = 0; j < i; ++j) {
269 cur_page = ttm->pages[j]; 273 cur_page = ttm->pages[j];
270 if (likely(cur_page != NULL)) { 274 if (likely(cur_page != NULL)) {
271 (void)ttm_tt_set_page_caching(cur_page, 275 (void)ttm_tt_set_page_caching(cur_page, c_state,
272 ttm->caching_state); 276 ttm->caching_state);
273 } 277 }
274 } 278 }
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index a6e8f687fa64..0c9c0811f42d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -348,22 +348,19 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
348 */ 348 */
349 349
350 DRM_INFO("It appears like vesafb is loaded. " 350 DRM_INFO("It appears like vesafb is loaded. "
351 "Ignore above error if any. Entering stealth mode.\n"); 351 "Ignore above error if any.\n");
352 ret = pci_request_region(dev->pdev, 2, "vmwgfx stealth probe"); 352 ret = pci_request_region(dev->pdev, 2, "vmwgfx stealth probe");
353 if (unlikely(ret != 0)) { 353 if (unlikely(ret != 0)) {
354 DRM_ERROR("Failed reserving the SVGA MMIO resource.\n"); 354 DRM_ERROR("Failed reserving the SVGA MMIO resource.\n");
355 goto out_no_device; 355 goto out_no_device;
356 } 356 }
357 vmw_kms_init(dev_priv);
358 vmw_overlay_init(dev_priv);
359 } else {
360 ret = vmw_request_device(dev_priv);
361 if (unlikely(ret != 0))
362 goto out_no_device;
363 vmw_kms_init(dev_priv);
364 vmw_overlay_init(dev_priv);
365 vmw_fb_init(dev_priv);
366 } 357 }
358 ret = vmw_request_device(dev_priv);
359 if (unlikely(ret != 0))
360 goto out_no_device;
361 vmw_kms_init(dev_priv);
362 vmw_overlay_init(dev_priv);
363 vmw_fb_init(dev_priv);
367 364
368 dev_priv->pm_nb.notifier_call = vmwgfx_pm_notifier; 365 dev_priv->pm_nb.notifier_call = vmwgfx_pm_notifier;
369 register_pm_notifier(&dev_priv->pm_nb); 366 register_pm_notifier(&dev_priv->pm_nb);
@@ -406,17 +403,15 @@ static int vmw_driver_unload(struct drm_device *dev)
406 403
407 unregister_pm_notifier(&dev_priv->pm_nb); 404 unregister_pm_notifier(&dev_priv->pm_nb);
408 405
409 if (!dev_priv->stealth) { 406 vmw_fb_close(dev_priv);
410 vmw_fb_close(dev_priv); 407 vmw_kms_close(dev_priv);
411 vmw_kms_close(dev_priv); 408 vmw_overlay_close(dev_priv);
412 vmw_overlay_close(dev_priv); 409 vmw_release_device(dev_priv);
413 vmw_release_device(dev_priv); 410 if (dev_priv->stealth)
414 pci_release_regions(dev->pdev);
415 } else {
416 vmw_kms_close(dev_priv);
417 vmw_overlay_close(dev_priv);
418 pci_release_region(dev->pdev, 2); 411 pci_release_region(dev->pdev, 2);
419 } 412 else
413 pci_release_regions(dev->pdev);
414
420 if (dev_priv->capabilities & SVGA_CAP_IRQMASK) 415 if (dev_priv->capabilities & SVGA_CAP_IRQMASK)
421 drm_irq_uninstall(dev_priv->dev); 416 drm_irq_uninstall(dev_priv->dev);
422 if (dev->devname == vmw_devname) 417 if (dev->devname == vmw_devname)
@@ -585,11 +580,6 @@ static int vmw_master_set(struct drm_device *dev,
585 int ret = 0; 580 int ret = 0;
586 581
587 DRM_INFO("Master set.\n"); 582 DRM_INFO("Master set.\n");
588 if (dev_priv->stealth) {
589 ret = vmw_request_device(dev_priv);
590 if (unlikely(ret != 0))
591 return ret;
592 }
593 583
594 if (active) { 584 if (active) {
595 BUG_ON(active != &dev_priv->fbdev_master); 585 BUG_ON(active != &dev_priv->fbdev_master);
@@ -649,18 +639,11 @@ static void vmw_master_drop(struct drm_device *dev,
649 639
650 ttm_lock_set_kill(&vmaster->lock, true, SIGTERM); 640 ttm_lock_set_kill(&vmaster->lock, true, SIGTERM);
651 641
652 if (dev_priv->stealth) {
653 ret = ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM);
654 if (unlikely(ret != 0))
655 DRM_ERROR("Unable to clean VRAM on master drop.\n");
656 vmw_release_device(dev_priv);
657 }
658 dev_priv->active_master = &dev_priv->fbdev_master; 642 dev_priv->active_master = &dev_priv->fbdev_master;
659 ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM); 643 ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM);
660 ttm_vt_unlock(&dev_priv->fbdev_master.lock); 644 ttm_vt_unlock(&dev_priv->fbdev_master.lock);
661 645
662 if (!dev_priv->stealth) 646 vmw_fb_on(dev_priv);
663 vmw_fb_on(dev_priv);
664} 647}
665 648
666 649
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
index d69caf92ffe7..0897359b3e4e 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
@@ -182,25 +182,19 @@ static int vmw_cmd_present_check(struct vmw_private *dev_priv,
182 return vmw_cmd_sid_check(dev_priv, sw_context, &cmd->body.sid); 182 return vmw_cmd_sid_check(dev_priv, sw_context, &cmd->body.sid);
183} 183}
184 184
185static int vmw_cmd_dma(struct vmw_private *dev_priv, 185static int vmw_translate_guest_ptr(struct vmw_private *dev_priv,
186 struct vmw_sw_context *sw_context, 186 struct vmw_sw_context *sw_context,
187 SVGA3dCmdHeader *header) 187 SVGAGuestPtr *ptr,
188 struct vmw_dma_buffer **vmw_bo_p)
188{ 189{
189 uint32_t handle;
190 struct vmw_dma_buffer *vmw_bo = NULL; 190 struct vmw_dma_buffer *vmw_bo = NULL;
191 struct ttm_buffer_object *bo; 191 struct ttm_buffer_object *bo;
192 struct vmw_surface *srf = NULL; 192 uint32_t handle = ptr->gmrId;
193 struct vmw_dma_cmd {
194 SVGA3dCmdHeader header;
195 SVGA3dCmdSurfaceDMA dma;
196 } *cmd;
197 struct vmw_relocation *reloc; 193 struct vmw_relocation *reloc;
198 int ret;
199 uint32_t cur_validate_node; 194 uint32_t cur_validate_node;
200 struct ttm_validate_buffer *val_buf; 195 struct ttm_validate_buffer *val_buf;
196 int ret;
201 197
202 cmd = container_of(header, struct vmw_dma_cmd, header);
203 handle = cmd->dma.guest.ptr.gmrId;
204 ret = vmw_user_dmabuf_lookup(sw_context->tfile, handle, &vmw_bo); 198 ret = vmw_user_dmabuf_lookup(sw_context->tfile, handle, &vmw_bo);
205 if (unlikely(ret != 0)) { 199 if (unlikely(ret != 0)) {
206 DRM_ERROR("Could not find or use GMR region.\n"); 200 DRM_ERROR("Could not find or use GMR region.\n");
@@ -209,14 +203,14 @@ static int vmw_cmd_dma(struct vmw_private *dev_priv,
209 bo = &vmw_bo->base; 203 bo = &vmw_bo->base;
210 204
211 if (unlikely(sw_context->cur_reloc >= VMWGFX_MAX_RELOCATIONS)) { 205 if (unlikely(sw_context->cur_reloc >= VMWGFX_MAX_RELOCATIONS)) {
212 DRM_ERROR("Max number of DMA commands per submission" 206 DRM_ERROR("Max number relocations per submission"
213 " exceeded\n"); 207 " exceeded\n");
214 ret = -EINVAL; 208 ret = -EINVAL;
215 goto out_no_reloc; 209 goto out_no_reloc;
216 } 210 }
217 211
218 reloc = &sw_context->relocs[sw_context->cur_reloc++]; 212 reloc = &sw_context->relocs[sw_context->cur_reloc++];
219 reloc->location = &cmd->dma.guest.ptr; 213 reloc->location = ptr;
220 214
221 cur_validate_node = vmw_dmabuf_validate_node(bo, sw_context->cur_val_buf); 215 cur_validate_node = vmw_dmabuf_validate_node(bo, sw_context->cur_val_buf);
222 if (unlikely(cur_validate_node >= VMWGFX_MAX_GMRS)) { 216 if (unlikely(cur_validate_node >= VMWGFX_MAX_GMRS)) {
@@ -234,7 +228,89 @@ static int vmw_cmd_dma(struct vmw_private *dev_priv,
234 list_add_tail(&val_buf->head, &sw_context->validate_nodes); 228 list_add_tail(&val_buf->head, &sw_context->validate_nodes);
235 ++sw_context->cur_val_buf; 229 ++sw_context->cur_val_buf;
236 } 230 }
231 *vmw_bo_p = vmw_bo;
232 return 0;
233
234out_no_reloc:
235 vmw_dmabuf_unreference(&vmw_bo);
236 vmw_bo_p = NULL;
237 return ret;
238}
239
240static int vmw_cmd_end_query(struct vmw_private *dev_priv,
241 struct vmw_sw_context *sw_context,
242 SVGA3dCmdHeader *header)
243{
244 struct vmw_dma_buffer *vmw_bo;
245 struct vmw_query_cmd {
246 SVGA3dCmdHeader header;
247 SVGA3dCmdEndQuery q;
248 } *cmd;
249 int ret;
250
251 cmd = container_of(header, struct vmw_query_cmd, header);
252 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
253 if (unlikely(ret != 0))
254 return ret;
255
256 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
257 &cmd->q.guestResult,
258 &vmw_bo);
259 if (unlikely(ret != 0))
260 return ret;
261
262 vmw_dmabuf_unreference(&vmw_bo);
263 return 0;
264}
237 265
266static int vmw_cmd_wait_query(struct vmw_private *dev_priv,
267 struct vmw_sw_context *sw_context,
268 SVGA3dCmdHeader *header)
269{
270 struct vmw_dma_buffer *vmw_bo;
271 struct vmw_query_cmd {
272 SVGA3dCmdHeader header;
273 SVGA3dCmdWaitForQuery q;
274 } *cmd;
275 int ret;
276
277 cmd = container_of(header, struct vmw_query_cmd, header);
278 ret = vmw_cmd_cid_check(dev_priv, sw_context, header);
279 if (unlikely(ret != 0))
280 return ret;
281
282 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
283 &cmd->q.guestResult,
284 &vmw_bo);
285 if (unlikely(ret != 0))
286 return ret;
287
288 vmw_dmabuf_unreference(&vmw_bo);
289 return 0;
290}
291
292
293static int vmw_cmd_dma(struct vmw_private *dev_priv,
294 struct vmw_sw_context *sw_context,
295 SVGA3dCmdHeader *header)
296{
297 struct vmw_dma_buffer *vmw_bo = NULL;
298 struct ttm_buffer_object *bo;
299 struct vmw_surface *srf = NULL;
300 struct vmw_dma_cmd {
301 SVGA3dCmdHeader header;
302 SVGA3dCmdSurfaceDMA dma;
303 } *cmd;
304 int ret;
305
306 cmd = container_of(header, struct vmw_dma_cmd, header);
307 ret = vmw_translate_guest_ptr(dev_priv, sw_context,
308 &cmd->dma.guest.ptr,
309 &vmw_bo);
310 if (unlikely(ret != 0))
311 return ret;
312
313 bo = &vmw_bo->base;
238 ret = vmw_user_surface_lookup_handle(dev_priv, sw_context->tfile, 314 ret = vmw_user_surface_lookup_handle(dev_priv, sw_context->tfile,
239 cmd->dma.host.sid, &srf); 315 cmd->dma.host.sid, &srf);
240 if (ret) { 316 if (ret) {
@@ -379,8 +455,8 @@ static vmw_cmd_func vmw_cmd_funcs[SVGA_3D_CMD_MAX] = {
379 VMW_CMD_DEF(SVGA_3D_CMD_DRAW_PRIMITIVES, &vmw_cmd_draw), 455 VMW_CMD_DEF(SVGA_3D_CMD_DRAW_PRIMITIVES, &vmw_cmd_draw),
380 VMW_CMD_DEF(SVGA_3D_CMD_SETSCISSORRECT, &vmw_cmd_cid_check), 456 VMW_CMD_DEF(SVGA_3D_CMD_SETSCISSORRECT, &vmw_cmd_cid_check),
381 VMW_CMD_DEF(SVGA_3D_CMD_BEGIN_QUERY, &vmw_cmd_cid_check), 457 VMW_CMD_DEF(SVGA_3D_CMD_BEGIN_QUERY, &vmw_cmd_cid_check),
382 VMW_CMD_DEF(SVGA_3D_CMD_END_QUERY, &vmw_cmd_cid_check), 458 VMW_CMD_DEF(SVGA_3D_CMD_END_QUERY, &vmw_cmd_end_query),
383 VMW_CMD_DEF(SVGA_3D_CMD_WAIT_FOR_QUERY, &vmw_cmd_cid_check), 459 VMW_CMD_DEF(SVGA_3D_CMD_WAIT_FOR_QUERY, &vmw_cmd_wait_query),
384 VMW_CMD_DEF(SVGA_3D_CMD_PRESENT_READBACK, &vmw_cmd_ok), 460 VMW_CMD_DEF(SVGA_3D_CMD_PRESENT_READBACK, &vmw_cmd_ok),
385 VMW_CMD_DEF(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN, 461 VMW_CMD_DEF(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN,
386 &vmw_cmd_blt_surf_screen_check) 462 &vmw_cmd_blt_surf_screen_check)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
index 4f4f6432be8b..a93367041cdc 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
@@ -559,6 +559,9 @@ int vmw_fb_init(struct vmw_private *vmw_priv)
559 info->pixmap.scan_align = 1; 559 info->pixmap.scan_align = 1;
560#endif 560#endif
561 561
562 info->aperture_base = vmw_priv->vram_start;
563 info->aperture_size = vmw_priv->vram_size;
564
562 /* 565 /*
563 * Dirty & Deferred IO 566 * Dirty & Deferred IO
564 */ 567 */
diff --git a/drivers/gpu/vga/Kconfig b/drivers/gpu/vga/Kconfig
index 790e675b13eb..0920492cea0a 100644
--- a/drivers/gpu/vga/Kconfig
+++ b/drivers/gpu/vga/Kconfig
@@ -8,3 +8,11 @@ config VGA_ARB
8 are accessed at same time they need some kind of coordination. Please 8 are accessed at same time they need some kind of coordination. Please
9 see Documentation/vgaarbiter.txt for more details. Select this to 9 see Documentation/vgaarbiter.txt for more details. Select this to
10 enable VGA arbiter. 10 enable VGA arbiter.
11
12config VGA_ARB_MAX_GPUS
13 int "Maximum number of GPUs"
14 default 16
15 depends on VGA_ARB
16 help
17 Reserves space in the kernel to maintain resource locking for
18 multiple GPUS. The overhead for each GPU is very small.
diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index 24b56dc54597..8827814d0735 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -688,7 +688,7 @@ EXPORT_SYMBOL(vga_client_register);
688 * the arbiter. 688 * the arbiter.
689 */ 689 */
690 690
691#define MAX_USER_CARDS 16 691#define MAX_USER_CARDS CONFIG_VGA_ARB_MAX_GPUS
692#define PCI_INVALID_CARD ((struct pci_dev *)-1UL) 692#define PCI_INVALID_CARD ((struct pci_dev *)-1UL)
693 693
694/* 694/*
@@ -954,6 +954,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
954 } 954 }
955 955
956 } else if (strncmp(curr_pos, "target ", 7) == 0) { 956 } else if (strncmp(curr_pos, "target ", 7) == 0) {
957 struct pci_bus *pbus;
957 unsigned int domain, bus, devfn; 958 unsigned int domain, bus, devfn;
958 struct vga_device *vgadev; 959 struct vga_device *vgadev;
959 960
@@ -961,7 +962,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
961 remaining -= 7; 962 remaining -= 7;
962 pr_devel("client 0x%p called 'target'\n", priv); 963 pr_devel("client 0x%p called 'target'\n", priv);
963 /* if target is default */ 964 /* if target is default */
964 if (!strncmp(kbuf, "default", 7)) 965 if (!strncmp(curr_pos, "default", 7))
965 pdev = pci_dev_get(vga_default_device()); 966 pdev = pci_dev_get(vga_default_device());
966 else { 967 else {
967 if (!vga_pci_str_to_vars(curr_pos, remaining, 968 if (!vga_pci_str_to_vars(curr_pos, remaining,
@@ -969,18 +970,31 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
969 ret_val = -EPROTO; 970 ret_val = -EPROTO;
970 goto done; 971 goto done;
971 } 972 }
972 973 pr_devel("vgaarb: %s ==> %x:%x:%x.%x\n", curr_pos,
973 pdev = pci_get_bus_and_slot(bus, devfn); 974 domain, bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
975
976 pbus = pci_find_bus(domain, bus);
977 pr_devel("vgaarb: pbus %p\n", pbus);
978 if (pbus == NULL) {
979 pr_err("vgaarb: invalid PCI domain and/or bus address %x:%x\n",
980 domain, bus);
981 ret_val = -ENODEV;
982 goto done;
983 }
984 pdev = pci_get_slot(pbus, devfn);
985 pr_devel("vgaarb: pdev %p\n", pdev);
974 if (!pdev) { 986 if (!pdev) {
975 pr_info("vgaarb: invalid PCI address!\n"); 987 pr_err("vgaarb: invalid PCI address %x:%x\n",
988 bus, devfn);
976 ret_val = -ENODEV; 989 ret_val = -ENODEV;
977 goto done; 990 goto done;
978 } 991 }
979 } 992 }
980 993
981 vgadev = vgadev_find(pdev); 994 vgadev = vgadev_find(pdev);
995 pr_devel("vgaarb: vgadev %p\n", vgadev);
982 if (vgadev == NULL) { 996 if (vgadev == NULL) {
983 pr_info("vgaarb: this pci device is not a vga device\n"); 997 pr_err("vgaarb: this pci device is not a vga device\n");
984 pci_dev_put(pdev); 998 pci_dev_put(pdev);
985 ret_val = -ENODEV; 999 ret_val = -ENODEV;
986 goto done; 1000 goto done;
@@ -998,7 +1012,8 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
998 } 1012 }
999 } 1013 }
1000 if (i == MAX_USER_CARDS) { 1014 if (i == MAX_USER_CARDS) {
1001 pr_err("vgaarb: maximum user cards number reached!\n"); 1015 pr_err("vgaarb: maximum user cards (%d) number reached!\n",
1016 MAX_USER_CARDS);
1002 pci_dev_put(pdev); 1017 pci_dev_put(pdev);
1003 /* XXX: which value to return? */ 1018 /* XXX: which value to return? */
1004 ret_val = -ENOMEM; 1019 ret_val = -ENOMEM;
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 24d90ea246ce..71d4c0703629 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -55,6 +55,12 @@ source "drivers/hid/usbhid/Kconfig"
55menu "Special HID drivers" 55menu "Special HID drivers"
56 depends on HID 56 depends on HID
57 57
58config HID_3M_PCT
59 tristate "3M PCT"
60 depends on USB_HID
61 ---help---
62 Support for 3M PCT touch screens.
63
58config HID_A4TECH 64config HID_A4TECH
59 tristate "A4 tech" if EMBEDDED 65 tristate "A4 tech" if EMBEDDED
60 depends on USB_HID 66 depends on USB_HID
@@ -183,6 +189,23 @@ config LOGIRUMBLEPAD2_FF
183 Say Y here if you want to enable force feedback support for Logitech 189 Say Y here if you want to enable force feedback support for Logitech
184 Rumblepad 2 devices. 190 Rumblepad 2 devices.
185 191
192config LOGIG940_FF
193 bool "Logitech Flight System G940 force feedback support"
194 depends on HID_LOGITECH
195 select INPUT_FF_MEMLESS
196 help
197 Say Y here if you want to enable force feedback support for Logitech
198 Flight System G940 devices.
199
200config HID_MAGICMOUSE
201 tristate "Apple MagicMouse multi-touch support"
202 depends on BT_HIDP
203 ---help---
204 Support for the Apple Magic Mouse multi-touch.
205
206 Say Y here if you want support for the multi-touch features of the
207 Apple Wireless "Magic" Mouse.
208
186config HID_MICROSOFT 209config HID_MICROSOFT
187 tristate "Microsoft" if EMBEDDED 210 tristate "Microsoft" if EMBEDDED
188 depends on USB_HID 211 depends on USB_HID
@@ -190,6 +213,12 @@ config HID_MICROSOFT
190 ---help--- 213 ---help---
191 Support for Microsoft devices that are not fully compliant with HID standard. 214 Support for Microsoft devices that are not fully compliant with HID standard.
192 215
216config HID_MOSART
217 tristate "MosArt"
218 depends on USB_HID
219 ---help---
220 Support for MosArt dual-touch panels.
221
193config HID_MONTEREY 222config HID_MONTEREY
194 tristate "Monterey" if EMBEDDED 223 tristate "Monterey" if EMBEDDED
195 depends on USB_HID 224 depends on USB_HID
@@ -198,12 +227,18 @@ config HID_MONTEREY
198 Support for Monterey Genius KB29E. 227 Support for Monterey Genius KB29E.
199 228
200config HID_NTRIG 229config HID_NTRIG
201 tristate "NTrig" if EMBEDDED 230 tristate "NTrig"
202 depends on USB_HID 231 depends on USB_HID
203 default !EMBEDDED
204 ---help--- 232 ---help---
205 Support for N-Trig touch screen. 233 Support for N-Trig touch screen.
206 234
235config HID_ORTEK
236 tristate "Ortek" if EMBEDDED
237 depends on USB_HID
238 default !EMBEDDED
239 ---help---
240 Support for Ortek WKB-2000 wireless keyboard + mouse trackpad.
241
207config HID_PANTHERLORD 242config HID_PANTHERLORD
208 tristate "Pantherlord support" if EMBEDDED 243 tristate "Pantherlord support" if EMBEDDED
209 depends on USB_HID 244 depends on USB_HID
@@ -227,6 +262,12 @@ config HID_PETALYNX
227 ---help--- 262 ---help---
228 Support for Petalynx Maxter remote control. 263 Support for Petalynx Maxter remote control.
229 264
265config HID_QUANTA
266 tristate "Quanta Optical Touch"
267 depends on USB_HID
268 ---help---
269 Support for Quanta Optical Touch dual-touch panels.
270
230config HID_SAMSUNG 271config HID_SAMSUNG
231 tristate "Samsung" if EMBEDDED 272 tristate "Samsung" if EMBEDDED
232 depends on USB_HID 273 depends on USB_HID
@@ -241,6 +282,12 @@ config HID_SONY
241 ---help--- 282 ---help---
242 Support for Sony PS3 controller. 283 Support for Sony PS3 controller.
243 284
285config HID_STANTUM
286 tristate "Stantum"
287 depends on USB_HID
288 ---help---
289 Support for Stantum multitouch panel.
290
244config HID_SUNPLUS 291config HID_SUNPLUS
245 tristate "Sunplus" if EMBEDDED 292 tristate "Sunplus" if EMBEDDED
246 depends on USB_HID 293 depends on USB_HID
@@ -305,9 +352,8 @@ config THRUSTMASTER_FF
305 Rumble Force or Force Feedback Wheel. 352 Rumble Force or Force Feedback Wheel.
306 353
307config HID_WACOM 354config HID_WACOM
308 tristate "Wacom Bluetooth devices support" if EMBEDDED 355 tristate "Wacom Bluetooth devices support"
309 depends on BT_HIDP 356 depends on BT_HIDP
310 default !EMBEDDED
311 ---help--- 357 ---help---
312 Support for Wacom Graphire Bluetooth tablet. 358 Support for Wacom Graphire Bluetooth tablet.
313 359
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 0de2dff5542c..0b2618f092ca 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -18,7 +18,11 @@ endif
18ifdef CONFIG_LOGIRUMBLEPAD2_FF 18ifdef CONFIG_LOGIRUMBLEPAD2_FF
19 hid-logitech-objs += hid-lg2ff.o 19 hid-logitech-objs += hid-lg2ff.o
20endif 20endif
21ifdef CONFIG_LOGIG940_FF
22 hid-logitech-objs += hid-lg3ff.o
23endif
21 24
25obj-$(CONFIG_HID_3M_PCT) += hid-3m-pct.o
22obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o 26obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o
23obj-$(CONFIG_HID_APPLE) += hid-apple.o 27obj-$(CONFIG_HID_APPLE) += hid-apple.o
24obj-$(CONFIG_HID_BELKIN) += hid-belkin.o 28obj-$(CONFIG_HID_BELKIN) += hid-belkin.o
@@ -31,14 +35,19 @@ obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
31obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o 35obj-$(CONFIG_HID_KENSINGTON) += hid-kensington.o
32obj-$(CONFIG_HID_KYE) += hid-kye.o 36obj-$(CONFIG_HID_KYE) += hid-kye.o
33obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o 37obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o
38obj-$(CONFIG_HID_MAGICMOUSE) += hid-magicmouse.o
34obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o 39obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o
35obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o 40obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o
41obj-$(CONFIG_HID_MOSART) += hid-mosart.o
36obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o 42obj-$(CONFIG_HID_NTRIG) += hid-ntrig.o
43obj-$(CONFIG_HID_ORTEK) += hid-ortek.o
44obj-$(CONFIG_HID_QUANTA) += hid-quanta.o
37obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o 45obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o
38obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o 46obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o
39obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o 47obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o
40obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o 48obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o
41obj-$(CONFIG_HID_SONY) += hid-sony.o 49obj-$(CONFIG_HID_SONY) += hid-sony.o
50obj-$(CONFIG_HID_STANTUM) += hid-stantum.o
42obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o 51obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o
43obj-$(CONFIG_HID_GREENASIA) += hid-gaff.o 52obj-$(CONFIG_HID_GREENASIA) += hid-gaff.o
44obj-$(CONFIG_HID_THRUSTMASTER) += hid-tmff.o 53obj-$(CONFIG_HID_THRUSTMASTER) += hid-tmff.o
diff --git a/drivers/hid/hid-3m-pct.c b/drivers/hid/hid-3m-pct.c
new file mode 100644
index 000000000000..2370aefc86b2
--- /dev/null
+++ b/drivers/hid/hid-3m-pct.c
@@ -0,0 +1,290 @@
1/*
2 * HID driver for 3M PCT multitouch panels
3 *
4 * Copyright (c) 2009 Stephane Chatty <chatty@enac.fr>
5 *
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
18#include <linux/usb.h>
19
20MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
21MODULE_DESCRIPTION("3M PCT multitouch panels");
22MODULE_LICENSE("GPL");
23
24#include "hid-ids.h"
25
26struct mmm_finger {
27 __s32 x, y;
28 __u8 rank;
29 bool touch, valid;
30};
31
32struct mmm_data {
33 struct mmm_finger f[10];
34 __u8 curid, num;
35 bool touch, valid;
36};
37
38static int mmm_input_mapping(struct hid_device *hdev, struct hid_input *hi,
39 struct hid_field *field, struct hid_usage *usage,
40 unsigned long **bit, int *max)
41{
42 switch (usage->hid & HID_USAGE_PAGE) {
43
44 case HID_UP_BUTTON:
45 return -1;
46
47 case HID_UP_GENDESK:
48 switch (usage->hid) {
49 case HID_GD_X:
50 hid_map_usage(hi, usage, bit, max,
51 EV_ABS, ABS_MT_POSITION_X);
52 /* touchscreen emulation */
53 input_set_abs_params(hi->input, ABS_X,
54 field->logical_minimum,
55 field->logical_maximum, 0, 0);
56 return 1;
57 case HID_GD_Y:
58 hid_map_usage(hi, usage, bit, max,
59 EV_ABS, ABS_MT_POSITION_Y);
60 /* touchscreen emulation */
61 input_set_abs_params(hi->input, ABS_Y,
62 field->logical_minimum,
63 field->logical_maximum, 0, 0);
64 return 1;
65 }
66 return 0;
67
68 case HID_UP_DIGITIZER:
69 switch (usage->hid) {
70 /* we do not want to map these: no input-oriented meaning */
71 case 0x14:
72 case 0x23:
73 case HID_DG_INPUTMODE:
74 case HID_DG_DEVICEINDEX:
75 case HID_DG_CONTACTCOUNT:
76 case HID_DG_CONTACTMAX:
77 case HID_DG_INRANGE:
78 case HID_DG_CONFIDENCE:
79 return -1;
80 case HID_DG_TIPSWITCH:
81 /* touchscreen emulation */
82 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
83 return 1;
84 case HID_DG_CONTACTID:
85 hid_map_usage(hi, usage, bit, max,
86 EV_ABS, ABS_MT_TRACKING_ID);
87 return 1;
88 }
89 /* let hid-input decide for the others */
90 return 0;
91
92 case 0xff000000:
93 /* we do not want to map these: no input-oriented meaning */
94 return -1;
95 }
96
97 return 0;
98}
99
100static int mmm_input_mapped(struct hid_device *hdev, struct hid_input *hi,
101 struct hid_field *field, struct hid_usage *usage,
102 unsigned long **bit, int *max)
103{
104 if (usage->type == EV_KEY || usage->type == EV_ABS)
105 clear_bit(usage->code, *bit);
106
107 return 0;
108}
109
110/*
111 * this function is called when a whole packet has been received and processed,
112 * so that it can decide what to send to the input layer.
113 */
114static void mmm_filter_event(struct mmm_data *md, struct input_dev *input)
115{
116 struct mmm_finger *oldest = 0;
117 bool pressed = false, released = false;
118 int i;
119
120 /*
121 * we need to iterate on all fingers to decide if we have a press
122 * or a release event in our touchscreen emulation.
123 */
124 for (i = 0; i < 10; ++i) {
125 struct mmm_finger *f = &md->f[i];
126 if (!f->valid) {
127 /* this finger is just placeholder data, ignore */
128 } else if (f->touch) {
129 /* this finger is on the screen */
130 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, i);
131 input_event(input, EV_ABS, ABS_MT_POSITION_X, f->x);
132 input_event(input, EV_ABS, ABS_MT_POSITION_Y, f->y);
133 input_mt_sync(input);
134 /*
135 * touchscreen emulation: maintain the age rank
136 * of this finger, decide if we have a press
137 */
138 if (f->rank == 0) {
139 f->rank = ++(md->num);
140 if (f->rank == 1)
141 pressed = true;
142 }
143 if (f->rank == 1)
144 oldest = f;
145 } else {
146 /* this finger took off the screen */
147 /* touchscreen emulation: maintain age rank of others */
148 int j;
149
150 for (j = 0; j < 10; ++j) {
151 struct mmm_finger *g = &md->f[j];
152 if (g->rank > f->rank) {
153 g->rank--;
154 if (g->rank == 1)
155 oldest = g;
156 }
157 }
158 f->rank = 0;
159 --(md->num);
160 if (md->num == 0)
161 released = true;
162 }
163 f->valid = 0;
164 }
165
166 /* touchscreen emulation */
167 if (oldest) {
168 if (pressed)
169 input_event(input, EV_KEY, BTN_TOUCH, 1);
170 input_event(input, EV_ABS, ABS_X, oldest->x);
171 input_event(input, EV_ABS, ABS_Y, oldest->y);
172 } else if (released) {
173 input_event(input, EV_KEY, BTN_TOUCH, 0);
174 }
175}
176
177/*
178 * this function is called upon all reports
179 * so that we can accumulate contact point information,
180 * and call input_mt_sync after each point.
181 */
182static int mmm_event(struct hid_device *hid, struct hid_field *field,
183 struct hid_usage *usage, __s32 value)
184{
185 struct mmm_data *md = hid_get_drvdata(hid);
186 /*
187 * strangely, this function can be called before
188 * field->hidinput is initialized!
189 */
190 if (hid->claimed & HID_CLAIMED_INPUT) {
191 struct input_dev *input = field->hidinput->input;
192 switch (usage->hid) {
193 case HID_DG_TIPSWITCH:
194 md->touch = value;
195 break;
196 case HID_DG_CONFIDENCE:
197 md->valid = value;
198 break;
199 case HID_DG_CONTACTID:
200 if (md->valid) {
201 md->curid = value;
202 md->f[value].touch = md->touch;
203 md->f[value].valid = 1;
204 }
205 break;
206 case HID_GD_X:
207 if (md->valid)
208 md->f[md->curid].x = value;
209 break;
210 case HID_GD_Y:
211 if (md->valid)
212 md->f[md->curid].y = value;
213 break;
214 case HID_DG_CONTACTCOUNT:
215 mmm_filter_event(md, input);
216 break;
217 }
218 }
219
220 /* we have handled the hidinput part, now remains hiddev */
221 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
222 hid->hiddev_hid_event(hid, field, usage, value);
223
224 return 1;
225}
226
227static int mmm_probe(struct hid_device *hdev, const struct hid_device_id *id)
228{
229 int ret;
230 struct mmm_data *md;
231
232 md = kzalloc(sizeof(struct mmm_data), GFP_KERNEL);
233 if (!md) {
234 dev_err(&hdev->dev, "cannot allocate 3M data\n");
235 return -ENOMEM;
236 }
237 hid_set_drvdata(hdev, md);
238
239 ret = hid_parse(hdev);
240 if (!ret)
241 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
242
243 if (ret)
244 kfree(md);
245 return ret;
246}
247
248static void mmm_remove(struct hid_device *hdev)
249{
250 hid_hw_stop(hdev);
251 kfree(hid_get_drvdata(hdev));
252 hid_set_drvdata(hdev, NULL);
253}
254
255static const struct hid_device_id mmm_devices[] = {
256 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
257 { }
258};
259MODULE_DEVICE_TABLE(hid, mmm_devices);
260
261static const struct hid_usage_id mmm_grabbed_usages[] = {
262 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
263 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
264};
265
266static struct hid_driver mmm_driver = {
267 .name = "3m-pct",
268 .id_table = mmm_devices,
269 .probe = mmm_probe,
270 .remove = mmm_remove,
271 .input_mapping = mmm_input_mapping,
272 .input_mapped = mmm_input_mapped,
273 .usage_table = mmm_grabbed_usages,
274 .event = mmm_event,
275};
276
277static int __init mmm_init(void)
278{
279 return hid_register_driver(&mmm_driver);
280}
281
282static void __exit mmm_exit(void)
283{
284 hid_unregister_driver(&mmm_driver);
285}
286
287module_init(mmm_init);
288module_exit(mmm_exit);
289MODULE_LICENSE("GPL");
290
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 5b4d66dc1a05..78286b184ace 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -40,6 +40,11 @@ module_param(fnmode, uint, 0644);
40MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, " 40MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
41 "[1] = fkeyslast, 2 = fkeysfirst)"); 41 "[1] = fkeyslast, 2 = fkeysfirst)");
42 42
43static unsigned int iso_layout = 1;
44module_param(iso_layout, uint, 0644);
45MODULE_PARM_DESC(iso_layout, "Enable/Disable hardcoded ISO-layout of the keyboard. "
46 "(0 = disabled, [1] = enabled)");
47
43struct apple_sc { 48struct apple_sc {
44 unsigned long quirks; 49 unsigned long quirks;
45 unsigned int fn_on; 50 unsigned int fn_on;
@@ -199,11 +204,13 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
199 } 204 }
200 } 205 }
201 206
202 if (asc->quirks & APPLE_ISO_KEYBOARD) { 207 if (iso_layout) {
203 trans = apple_find_translation(apple_iso_keyboard, usage->code); 208 if (asc->quirks & APPLE_ISO_KEYBOARD) {
204 if (trans) { 209 trans = apple_find_translation(apple_iso_keyboard, usage->code);
205 input_event(input, usage->type, trans->to, value); 210 if (trans) {
206 return 1; 211 input_event(input, usage->type, trans->to, value);
212 return 1;
213 }
207 } 214 }
208 } 215 }
209 216
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index eabe5f87c6c1..368fbb0c4ca6 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/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-2007 Jiri Kosina 7 * Copyright (c) 2006-2010 Jiri Kosina
8 */ 8 */
9 9
10/* 10/*
@@ -51,7 +51,7 @@ EXPORT_SYMBOL_GPL(hid_debug);
51 * Register a new report for a device. 51 * Register a new report for a device.
52 */ 52 */
53 53
54static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id) 54struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
55{ 55{
56 struct hid_report_enum *report_enum = device->report_enum + type; 56 struct hid_report_enum *report_enum = device->report_enum + type;
57 struct hid_report *report; 57 struct hid_report *report;
@@ -75,6 +75,7 @@ static struct hid_report *hid_register_report(struct hid_device *device, unsigne
75 75
76 return report; 76 return report;
77} 77}
78EXPORT_SYMBOL_GPL(hid_register_report);
78 79
79/* 80/*
80 * Register a new field for this report. 81 * Register a new field for this report.
@@ -387,7 +388,8 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
387 __u32 data; 388 __u32 data;
388 unsigned n; 389 unsigned n;
389 390
390 if (item->size == 0) { 391 /* Local delimiter could have value 0, which allows size to be 0 */
392 if (item->size == 0 && item->tag != HID_LOCAL_ITEM_TAG_DELIMITER) {
391 dbg_hid("item data expected for local item\n"); 393 dbg_hid("item data expected for local item\n");
392 return -1; 394 return -1;
393 } 395 }
@@ -1248,11 +1250,13 @@ EXPORT_SYMBOL_GPL(hid_disconnect);
1248 1250
1249/* a list of devices for which there is a specialized driver on HID bus */ 1251/* a list of devices for which there is a specialized driver on HID bus */
1250static const struct hid_device_id hid_blacklist[] = { 1252static const struct hid_device_id hid_blacklist[] = {
1253 { HID_USB_DEVICE(USB_VENDOR_ID_3M, USB_DEVICE_ID_3M1968) },
1251 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, 1254 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1252 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, 1255 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1253 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, 1256 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
1254 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, 1257 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1255 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, 1258 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1259 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE) },
1256 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, 1260 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1257 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, 1261 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1258 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) }, 1262 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
@@ -1324,6 +1328,7 @@ static const struct hid_device_id hid_blacklist[] = {
1324 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) }, 1328 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1325 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) }, 1329 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) },
1326 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) }, 1330 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
1331 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940) },
1327 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) }, 1332 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1328 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) }, 1333 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
1329 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) }, 1334 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G25_WHEEL) },
@@ -1337,10 +1342,15 @@ static const struct hid_device_id hid_blacklist[] = {
1337 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) }, 1342 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
1338 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) }, 1343 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
1339 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) }, 1344 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, USB_DEVICE_ID_NTRIG_TOUCH_SCREEN) },
1345 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
1340 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, 1346 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1347 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
1348 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
1341 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, 1349 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1342 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 1350 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1351 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1343 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, 1352 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) },
1353 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
1344 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, 1354 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1345 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, 1355 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1346 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) }, 1356 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
@@ -1543,8 +1553,9 @@ static const struct hid_device_id hid_ignore_list[] = {
1543 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) }, 1553 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1544 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) }, 1554 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1545 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, 1555 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
1546 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM)}, 1556 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT)},
1547 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM2)}, 1557 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
1558 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
1548 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, 1559 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1549 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, 1560 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1550 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, 1561 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
@@ -1661,8 +1672,6 @@ static const struct hid_device_id hid_ignore_list[] = {
1661 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) }, 1672 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
1662 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) }, 1673 { HID_USB_DEVICE(USB_VENDOR_ID_PHILIPS, USB_DEVICE_ID_PHILIPS_IEEE802154_DONGLE) },
1663 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) }, 1674 { HID_USB_DEVICE(USB_VENDOR_ID_POWERCOM, USB_DEVICE_ID_POWERCOM_UPS) },
1664 { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY1) },
1665 { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY2) },
1666 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) }, 1675 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1667 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) }, 1676 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1668 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) }, 1677 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 6abd0369aedb..cd4ece6fdfb9 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -864,13 +864,13 @@ static const char **names[EV_MAX + 1] = {
864 [EV_SND] = sounds, [EV_REP] = repeats, 864 [EV_SND] = sounds, [EV_REP] = repeats,
865}; 865};
866 866
867void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f) { 867static void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f)
868 868{
869 seq_printf(f, "%s.%s", events[type] ? events[type] : "?", 869 seq_printf(f, "%s.%s", events[type] ? events[type] : "?",
870 names[type] ? (names[type][code] ? names[type][code] : "?") : "?"); 870 names[type] ? (names[type][code] ? names[type][code] : "?") : "?");
871} 871}
872 872
873void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f) 873static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
874{ 874{
875 int i, j, k; 875 int i, j, k;
876 struct hid_report *report; 876 struct hid_report *report;
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 010368e649ed..72c05f90553c 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -18,6 +18,9 @@
18#ifndef HID_IDS_H_FILE 18#ifndef HID_IDS_H_FILE
19#define HID_IDS_H_FILE 19#define HID_IDS_H_FILE
20 20
21#define USB_VENDOR_ID_3M 0x0596
22#define USB_DEVICE_ID_3M1968 0x0500
23
21#define USB_VENDOR_ID_A4TECH 0x09da 24#define USB_VENDOR_ID_A4TECH 0x09da
22#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 25#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
23#define USB_DEVICE_ID_A4TECH_X5_005D 0x000a 26#define USB_DEVICE_ID_A4TECH_X5_005D 0x000a
@@ -56,6 +59,7 @@
56 59
57#define USB_VENDOR_ID_APPLE 0x05ac 60#define USB_VENDOR_ID_APPLE 0x05ac
58#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 61#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
62#define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
59#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e 63#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e
60#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f 64#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f
61#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214 65#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
@@ -96,9 +100,12 @@
96#define USB_DEVICE_ID_APPLE_ATV_IRCONTROL 0x8241 100#define USB_DEVICE_ID_APPLE_ATV_IRCONTROL 0x8241
97#define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242 101#define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242
98 102
99#define USB_VENDOR_ID_ASUS 0x0b05 103#define USB_VENDOR_ID_ASUS 0x0486
100#define USB_DEVICE_ID_ASUS_LCM 0x1726 104#define USB_DEVICE_ID_ASUS_T91MT 0x0185
101#define USB_DEVICE_ID_ASUS_LCM2 0x175b 105
106#define USB_VENDOR_ID_ASUSTEK 0x0b05
107#define USB_DEVICE_ID_ASUSTEK_LCM 0x1726
108#define USB_DEVICE_ID_ASUSTEK_LCM2 0x175b
102 109
103#define USB_VENDOR_ID_ATEN 0x0557 110#define USB_VENDOR_ID_ATEN 0x0557
104#define USB_DEVICE_ID_ATEN_UC100KM 0x2004 111#define USB_DEVICE_ID_ATEN_UC100KM 0x2004
@@ -169,6 +176,9 @@
169#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f 176#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f
170#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100 177#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100
171 178
179#define USB_VENDOR_ID_ETURBOTOUCH 0x22b9
180#define USB_DEVICE_ID_ETURBOTOUCH 0x0006
181
172#define USB_VENDOR_ID_ETT 0x0664 182#define USB_VENDOR_ID_ETT 0x0664
173#define USB_DEVICE_ID_TC5UH 0x0309 183#define USB_DEVICE_ID_TC5UH 0x0309
174 184
@@ -303,6 +313,7 @@
303#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2 0xc219 313#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2 0xc219
304#define USB_DEVICE_ID_LOGITECH_WINGMAN_F3D 0xc283 314#define USB_DEVICE_ID_LOGITECH_WINGMAN_F3D 0xc283
305#define USB_DEVICE_ID_LOGITECH_FORCE3D_PRO 0xc286 315#define USB_DEVICE_ID_LOGITECH_FORCE3D_PRO 0xc286
316#define USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940 0xc287
306#define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294 317#define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294
307#define USB_DEVICE_ID_LOGITECH_WINGMAN_FFG 0xc293 318#define USB_DEVICE_ID_LOGITECH_WINGMAN_FFG 0xc293
308#define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL 0xc295 319#define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL 0xc295
@@ -365,6 +376,9 @@
365#define USB_VENDOR_ID_ONTRAK 0x0a07 376#define USB_VENDOR_ID_ONTRAK 0x0a07
366#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064 377#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
367 378
379#define USB_VENDOR_ID_ORTEK 0x05a4
380#define USB_DEVICE_ID_ORTEK_WKB2000 0x2000
381
368#define USB_VENDOR_ID_PANJIT 0x134c 382#define USB_VENDOR_ID_PANJIT 0x134c
369 383
370#define USB_VENDOR_ID_PANTHERLORD 0x0810 384#define USB_VENDOR_ID_PANTHERLORD 0x0810
@@ -382,9 +396,16 @@
382#define USB_VENDOR_ID_POWERCOM 0x0d9f 396#define USB_VENDOR_ID_POWERCOM 0x0d9f
383#define USB_DEVICE_ID_POWERCOM_UPS 0x0002 397#define USB_DEVICE_ID_POWERCOM_UPS 0x0002
384 398
399#define USB_VENDOR_ID_PRODIGE 0x05af
400#define USB_DEVICE_ID_PRODIGE_CORDLESS 0x3062
401
385#define USB_VENDOR_ID_SAITEK 0x06a3 402#define USB_VENDOR_ID_SAITEK 0x06a3
386#define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17 403#define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17
387 404
405#define USB_VENDOR_ID_QUANTA 0x0408
406#define USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH 0x3000
407#define USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN 0x3001
408
388#define USB_VENDOR_ID_SAMSUNG 0x0419 409#define USB_VENDOR_ID_SAMSUNG 0x0419
389#define USB_DEVICE_ID_SAMSUNG_IR_REMOTE 0x0001 410#define USB_DEVICE_ID_SAMSUNG_IR_REMOTE 0x0001
390 411
@@ -396,18 +417,20 @@
396#define USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST 0x0034 417#define USB_DEVICE_ID_SOUNDGRAPH_IMON_FIRST 0x0034
397#define USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST 0x0046 418#define USB_DEVICE_ID_SOUNDGRAPH_IMON_LAST 0x0046
398 419
420#define USB_VENDOR_ID_STANTUM 0x1f87
421#define USB_DEVICE_ID_MTP 0x0002
422
399#define USB_VENDOR_ID_SUN 0x0430 423#define USB_VENDOR_ID_SUN 0x0430
400#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab 424#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
401 425
402#define USB_VENDOR_ID_SUNPLUS 0x04fc 426#define USB_VENDOR_ID_SUNPLUS 0x04fc
403#define USB_DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8 427#define USB_DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8
404 428
405#define USB_VENDOR_ID_TENX 0x1130
406#define USB_DEVICE_ID_TENX_IBUDDY1 0x0001
407#define USB_DEVICE_ID_TENX_IBUDDY2 0x0002
408
409#define USB_VENDOR_ID_THRUSTMASTER 0x044f 429#define USB_VENDOR_ID_THRUSTMASTER 0x044f
410 430
431#define USB_VENDOR_ID_TOUCHPACK 0x1bfd
432#define USB_DEVICE_ID_TOUCHPACK_RTS 0x1688
433
411#define USB_VENDOR_ID_TOPMAX 0x0663 434#define USB_VENDOR_ID_TOPMAX 0x0663
412#define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103 435#define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103
413 436
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 5862b0f3b55d..79d9edd0bdfa 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2000-2001 Vojtech Pavlik 2 * Copyright (c) 2000-2001 Vojtech Pavlik
3 * Copyright (c) 2006-2007 Jiri Kosina 3 * Copyright (c) 2006-2010 Jiri Kosina
4 * 4 *
5 * HID to Linux Input mapping 5 * HID to Linux Input mapping
6 */ 6 */
@@ -193,12 +193,17 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
193 break; 193 break;
194 194
195 case HID_UP_BUTTON: 195 case HID_UP_BUTTON:
196 code = ((usage->hid - 1) & 0xf); 196 code = ((usage->hid - 1) & HID_USAGE);
197 197
198 switch (field->application) { 198 switch (field->application) {
199 case HID_GD_MOUSE: 199 case HID_GD_MOUSE:
200 case HID_GD_POINTER: code += 0x110; break; 200 case HID_GD_POINTER: code += 0x110; break;
201 case HID_GD_JOYSTICK: code += 0x120; break; 201 case HID_GD_JOYSTICK:
202 if (code <= 0xf)
203 code += BTN_JOYSTICK;
204 else
205 code += BTN_TRIGGER_HAPPY;
206 break;
202 case HID_GD_GAMEPAD: code += 0x130; break; 207 case HID_GD_GAMEPAD: code += 0x130; break;
203 default: 208 default:
204 switch (field->physical) { 209 switch (field->physical) {
@@ -400,6 +405,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
400 case 0x192: map_key_clear(KEY_CALC); break; 405 case 0x192: map_key_clear(KEY_CALC); break;
401 case 0x194: map_key_clear(KEY_FILE); break; 406 case 0x194: map_key_clear(KEY_FILE); break;
402 case 0x196: map_key_clear(KEY_WWW); break; 407 case 0x196: map_key_clear(KEY_WWW); break;
408 case 0x199: map_key_clear(KEY_CHAT); break;
403 case 0x19c: map_key_clear(KEY_LOGOFF); break; 409 case 0x19c: map_key_clear(KEY_LOGOFF); break;
404 case 0x19e: map_key_clear(KEY_COFFEE); break; 410 case 0x19e: map_key_clear(KEY_COFFEE); break;
405 case 0x1a6: map_key_clear(KEY_HELP); break; 411 case 0x1a6: map_key_clear(KEY_HELP); break;
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
index 9fcd3d017ab3..3677c9037a11 100644
--- a/drivers/hid/hid-lg.c
+++ b/drivers/hid/hid-lg.c
@@ -34,6 +34,7 @@
34#define LG_FF 0x200 34#define LG_FF 0x200
35#define LG_FF2 0x400 35#define LG_FF2 0x400
36#define LG_RDESC_REL_ABS 0x800 36#define LG_RDESC_REL_ABS 0x800
37#define LG_FF3 0x1000
37 38
38/* 39/*
39 * Certain Logitech keyboards send in report #3 keys which are far 40 * Certain Logitech keyboards send in report #3 keys which are far
@@ -266,7 +267,7 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
266 goto err_free; 267 goto err_free;
267 } 268 }
268 269
269 if (quirks & (LG_FF | LG_FF2)) 270 if (quirks & (LG_FF | LG_FF2 | LG_FF3))
270 connect_mask &= ~HID_CONNECT_FF; 271 connect_mask &= ~HID_CONNECT_FF;
271 272
272 ret = hid_hw_start(hdev, connect_mask); 273 ret = hid_hw_start(hdev, connect_mask);
@@ -279,6 +280,8 @@ static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
279 lgff_init(hdev); 280 lgff_init(hdev);
280 if (quirks & LG_FF2) 281 if (quirks & LG_FF2)
281 lg2ff_init(hdev); 282 lg2ff_init(hdev);
283 if (quirks & LG_FF3)
284 lg3ff_init(hdev);
282 285
283 return 0; 286 return 0;
284err_free: 287err_free:
@@ -331,6 +334,8 @@ static const struct hid_device_id lg_devices[] = {
331 .driver_data = LG_FF }, 334 .driver_data = LG_FF },
332 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2), 335 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2),
333 .driver_data = LG_FF2 }, 336 .driver_data = LG_FF2 },
337 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940),
338 .driver_data = LG_FF3 },
334 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR), 339 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACENAVIGATOR),
335 .driver_data = LG_RDESC_REL_ABS }, 340 .driver_data = LG_RDESC_REL_ABS },
336 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER), 341 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_SPACETRAVELLER),
diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h
index bf31592eaf79..ce2ac8672624 100644
--- a/drivers/hid/hid-lg.h
+++ b/drivers/hid/hid-lg.h
@@ -13,4 +13,10 @@ int lg2ff_init(struct hid_device *hdev);
13static inline int lg2ff_init(struct hid_device *hdev) { return -1; } 13static inline int lg2ff_init(struct hid_device *hdev) { return -1; }
14#endif 14#endif
15 15
16#ifdef CONFIG_LOGIG940_FF
17int lg3ff_init(struct hid_device *hdev);
18#else
19static inline int lg3ff_init(struct hid_device *hdev) { return -1; }
20#endif
21
16#endif 22#endif
diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
new file mode 100644
index 000000000000..4002832ee4af
--- /dev/null
+++ b/drivers/hid/hid-lg3ff.c
@@ -0,0 +1,176 @@
1/*
2 * Force feedback support for Logitech Flight System G940
3 *
4 * Copyright (c) 2009 Gary Stein <LordCnidarian@gmail.com>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23
24#include <linux/input.h>
25#include <linux/usb.h>
26#include <linux/hid.h>
27
28#include "usbhid/usbhid.h"
29#include "hid-lg.h"
30
31/*
32 * G940 Theory of Operation (from experimentation)
33 *
34 * There are 63 fields (only 3 of them currently used)
35 * 0 - seems to be command field
36 * 1 - 30 deal with the x axis
37 * 31 -60 deal with the y axis
38 *
39 * Field 1 is x axis constant force
40 * Field 31 is y axis constant force
41 *
42 * other interesting fields 1,2,3,4 on x axis
43 * (same for 31,32,33,34 on y axis)
44 *
45 * 0 0 127 127 makes the joystick autocenter hard
46 *
47 * 127 0 127 127 makes the joystick loose on the right,
48 * but stops all movemnt left
49 *
50 * -127 0 -127 -127 makes the joystick loose on the left,
51 * but stops all movement right
52 *
53 * 0 0 -127 -127 makes the joystick rattle very hard
54 *
55 * I'm sure these are effects that I don't know enough about them
56 */
57
58struct lg3ff_device {
59 struct hid_report *report;
60};
61
62static int hid_lg3ff_play(struct input_dev *dev, void *data,
63 struct ff_effect *effect)
64{
65 struct hid_device *hid = input_get_drvdata(dev);
66 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
67 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
68 int x, y;
69
70/*
71 * Maxusage should always be 63 (maximum fields)
72 * likely a better way to ensure this data is clean
73 */
74 memset(report->field[0]->value, 0, sizeof(__s32)*report->field[0]->maxusage);
75
76 switch (effect->type) {
77 case FF_CONSTANT:
78/*
79 * Already clamped in ff_memless
80 * 0 is center (different then other logitech)
81 */
82 x = effect->u.ramp.start_level;
83 y = effect->u.ramp.end_level;
84
85 /* send command byte */
86 report->field[0]->value[0] = 0x51;
87
88/*
89 * Sign backwards from other Force3d pro
90 * which get recast here in two's complement 8 bits
91 */
92 report->field[0]->value[1] = (unsigned char)(-x);
93 report->field[0]->value[31] = (unsigned char)(-y);
94
95 usbhid_submit_report(hid, report, USB_DIR_OUT);
96 break;
97 }
98 return 0;
99}
100static void hid_lg3ff_set_autocenter(struct input_dev *dev, u16 magnitude)
101{
102 struct hid_device *hid = input_get_drvdata(dev);
103 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
104 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
105
106/*
107 * Auto Centering probed from device
108 * NOTE: deadman's switch on G940 must be covered
109 * for effects to work
110 */
111 report->field[0]->value[0] = 0x51;
112 report->field[0]->value[1] = 0x00;
113 report->field[0]->value[2] = 0x00;
114 report->field[0]->value[3] = 0x7F;
115 report->field[0]->value[4] = 0x7F;
116 report->field[0]->value[31] = 0x00;
117 report->field[0]->value[32] = 0x00;
118 report->field[0]->value[33] = 0x7F;
119 report->field[0]->value[34] = 0x7F;
120
121 usbhid_submit_report(hid, report, USB_DIR_OUT);
122}
123
124
125static const signed short ff3_joystick_ac[] = {
126 FF_CONSTANT,
127 FF_AUTOCENTER,
128 -1
129};
130
131int lg3ff_init(struct hid_device *hid)
132{
133 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
134 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
135 struct input_dev *dev = hidinput->input;
136 struct hid_report *report;
137 struct hid_field *field;
138 const signed short *ff_bits = ff3_joystick_ac;
139 int error;
140 int i;
141
142 /* Find the report to use */
143 if (list_empty(report_list)) {
144 err_hid("No output report found");
145 return -1;
146 }
147
148 /* Check that the report looks ok */
149 report = list_entry(report_list->next, struct hid_report, list);
150 if (!report) {
151 err_hid("NULL output report");
152 return -1;
153 }
154
155 field = report->field[0];
156 if (!field) {
157 err_hid("NULL field");
158 return -1;
159 }
160
161 /* Assume single fixed device G940 */
162 for (i = 0; ff_bits[i] >= 0; i++)
163 set_bit(ff_bits[i], dev->ffbit);
164
165 error = input_ff_create_memless(dev, NULL, hid_lg3ff_play);
166 if (error)
167 return error;
168
169 if (test_bit(FF_AUTOCENTER, dev->ffbit))
170 dev->ff->set_autocenter = hid_lg3ff_set_autocenter;
171
172 dev_info(&hid->dev, "Force feedback for Logitech Flight System G940 by "
173 "Gary Stein <LordCnidarian@gmail.com>\n");
174 return 0;
175}
176
diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
index 987abebe0829..61142b76a9b1 100644
--- a/drivers/hid/hid-lgff.c
+++ b/drivers/hid/hid-lgff.c
@@ -67,6 +67,7 @@ static const struct dev_type devices[] = {
67 { 0x046d, 0xc219, ff_rumble }, 67 { 0x046d, 0xc219, ff_rumble },
68 { 0x046d, 0xc283, ff_joystick }, 68 { 0x046d, 0xc283, ff_joystick },
69 { 0x046d, 0xc286, ff_joystick_ac }, 69 { 0x046d, 0xc286, ff_joystick_ac },
70 { 0x046d, 0xc287, ff_joystick_ac },
70 { 0x046d, 0xc293, ff_joystick }, 71 { 0x046d, 0xc293, ff_joystick },
71 { 0x046d, 0xc294, ff_wheel }, 72 { 0x046d, 0xc294, ff_wheel },
72 { 0x046d, 0xc295, ff_joystick }, 73 { 0x046d, 0xc295, ff_joystick },
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
new file mode 100644
index 000000000000..4a3a94f2b10c
--- /dev/null
+++ b/drivers/hid/hid-magicmouse.c
@@ -0,0 +1,449 @@
1/*
2 * Apple "Magic" Wireless Mouse driver
3 *
4 * Copyright (c) 2010 Michael Poole <mdpoole@troilus.org>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 */
13
14#include <linux/device.h>
15#include <linux/hid.h>
16#include <linux/module.h>
17#include <linux/usb.h>
18
19#include "hid-ids.h"
20
21static bool emulate_3button = true;
22module_param(emulate_3button, bool, 0644);
23MODULE_PARM_DESC(emulate_3button, "Emulate a middle button");
24
25static int middle_button_start = -350;
26static int middle_button_stop = +350;
27
28static bool emulate_scroll_wheel = true;
29module_param(emulate_scroll_wheel, bool, 0644);
30MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
31
32static bool report_touches = true;
33module_param(report_touches, bool, 0644);
34MODULE_PARM_DESC(report_touches, "Emit touch records (otherwise, only use them for emulation)");
35
36static bool report_undeciphered;
37module_param(report_undeciphered, bool, 0644);
38MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
39
40#define TOUCH_REPORT_ID 0x29
41/* These definitions are not precise, but they're close enough. (Bits
42 * 0x03 seem to indicate the aspect ratio of the touch, bits 0x70 seem
43 * to be some kind of bit mask -- 0x20 may be a near-field reading,
44 * and 0x40 is actual contact, and 0x10 may be a start/stop or change
45 * indication.)
46 */
47#define TOUCH_STATE_MASK 0xf0
48#define TOUCH_STATE_NONE 0x00
49#define TOUCH_STATE_START 0x30
50#define TOUCH_STATE_DRAG 0x40
51
52/**
53 * struct magicmouse_sc - Tracks Magic Mouse-specific data.
54 * @input: Input device through which we report events.
55 * @quirks: Currently unused.
56 * @last_timestamp: Timestamp from most recent (18-bit) touch report
57 * (units of milliseconds over short windows, but seems to
58 * increase faster when there are no touches).
59 * @delta_time: 18-bit difference between the two most recent touch
60 * reports from the mouse.
61 * @ntouches: Number of touches in most recent touch report.
62 * @scroll_accel: Number of consecutive scroll motions.
63 * @scroll_jiffies: Time of last scroll motion.
64 * @touches: Most recent data for a touch, indexed by tracking ID.
65 * @tracking_ids: Mapping of current touch input data to @touches.
66 */
67struct magicmouse_sc {
68 struct input_dev *input;
69 unsigned long quirks;
70
71 int last_timestamp;
72 int delta_time;
73 int ntouches;
74 int scroll_accel;
75 unsigned long scroll_jiffies;
76
77 struct {
78 short x;
79 short y;
80 short scroll_y;
81 u8 size;
82 } touches[16];
83 int tracking_ids[16];
84};
85
86static int magicmouse_firm_touch(struct magicmouse_sc *msc)
87{
88 int touch = -1;
89 int ii;
90
91 /* If there is only one "firm" touch, set touch to its
92 * tracking ID.
93 */
94 for (ii = 0; ii < msc->ntouches; ii++) {
95 int idx = msc->tracking_ids[ii];
96 if (msc->touches[idx].size < 8) {
97 /* Ignore this touch. */
98 } else if (touch >= 0) {
99 touch = -1;
100 break;
101 } else {
102 touch = idx;
103 }
104 }
105
106 return touch;
107}
108
109static void magicmouse_emit_buttons(struct magicmouse_sc *msc, int state)
110{
111 int last_state = test_bit(BTN_LEFT, msc->input->key) << 0 |
112 test_bit(BTN_RIGHT, msc->input->key) << 1 |
113 test_bit(BTN_MIDDLE, msc->input->key) << 2;
114
115 if (emulate_3button) {
116 int id;
117
118 /* If some button was pressed before, keep it held
119 * down. Otherwise, if there's exactly one firm
120 * touch, use that to override the mouse's guess.
121 */
122 if (state == 0) {
123 /* The button was released. */
124 } else if (last_state != 0) {
125 state = last_state;
126 } else if ((id = magicmouse_firm_touch(msc)) >= 0) {
127 int x = msc->touches[id].x;
128 if (x < middle_button_start)
129 state = 1;
130 else if (x > middle_button_stop)
131 state = 2;
132 else
133 state = 4;
134 } /* else: we keep the mouse's guess */
135
136 input_report_key(msc->input, BTN_MIDDLE, state & 4);
137 }
138
139 input_report_key(msc->input, BTN_LEFT, state & 1);
140 input_report_key(msc->input, BTN_RIGHT, state & 2);
141
142 if (state != last_state)
143 msc->scroll_accel = 0;
144}
145
146static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tdata)
147{
148 struct input_dev *input = msc->input;
149 __s32 x_y = tdata[0] << 8 | tdata[1] << 16 | tdata[2] << 24;
150 int misc = tdata[5] | tdata[6] << 8;
151 int id = (misc >> 6) & 15;
152 int x = x_y << 12 >> 20;
153 int y = -(x_y >> 20);
154
155 /* Store tracking ID and other fields. */
156 msc->tracking_ids[raw_id] = id;
157 msc->touches[id].x = x;
158 msc->touches[id].y = y;
159 msc->touches[id].size = misc & 63;
160
161 /* If requested, emulate a scroll wheel by detecting small
162 * vertical touch motions along the middle of the mouse.
163 */
164 if (emulate_scroll_wheel &&
165 middle_button_start < x && x < middle_button_stop) {
166 static const int accel_profile[] = {
167 256, 228, 192, 160, 128, 96, 64, 32,
168 };
169 unsigned long now = jiffies;
170 int step = msc->touches[id].scroll_y - y;
171
172 /* Reset acceleration after half a second. */
173 if (time_after(now, msc->scroll_jiffies + HZ / 2))
174 msc->scroll_accel = 0;
175
176 /* Calculate and apply the scroll motion. */
177 switch (tdata[7] & TOUCH_STATE_MASK) {
178 case TOUCH_STATE_START:
179 msc->touches[id].scroll_y = y;
180 msc->scroll_accel = min_t(int, msc->scroll_accel + 1,
181 ARRAY_SIZE(accel_profile) - 1);
182 break;
183 case TOUCH_STATE_DRAG:
184 step = step / accel_profile[msc->scroll_accel];
185 if (step != 0) {
186 msc->touches[id].scroll_y = y;
187 msc->scroll_jiffies = now;
188 input_report_rel(input, REL_WHEEL, step);
189 }
190 break;
191 }
192 }
193
194 /* Generate the input events for this touch. */
195 if (report_touches) {
196 int orientation = (misc >> 10) - 32;
197
198 input_report_abs(input, ABS_MT_TRACKING_ID, id);
199 input_report_abs(input, ABS_MT_TOUCH_MAJOR, tdata[3]);
200 input_report_abs(input, ABS_MT_TOUCH_MINOR, tdata[4]);
201 input_report_abs(input, ABS_MT_ORIENTATION, orientation);
202 input_report_abs(input, ABS_MT_POSITION_X, x);
203 input_report_abs(input, ABS_MT_POSITION_Y, y);
204
205 if (report_undeciphered)
206 input_event(input, EV_MSC, MSC_RAW, tdata[7]);
207
208 input_mt_sync(input);
209 }
210}
211
212static int magicmouse_raw_event(struct hid_device *hdev,
213 struct hid_report *report, u8 *data, int size)
214{
215 struct magicmouse_sc *msc = hid_get_drvdata(hdev);
216 struct input_dev *input = msc->input;
217 int x, y, ts, ii, clicks;
218
219 switch (data[0]) {
220 case 0x10:
221 if (size != 6)
222 return 0;
223 x = (__s16)(data[2] | data[3] << 8);
224 y = (__s16)(data[4] | data[5] << 8);
225 clicks = data[1];
226 break;
227 case TOUCH_REPORT_ID:
228 /* Expect six bytes of prefix, and N*8 bytes of touch data. */
229 if (size < 6 || ((size - 6) % 8) != 0)
230 return 0;
231 ts = data[3] >> 6 | data[4] << 2 | data[5] << 10;
232 msc->delta_time = (ts - msc->last_timestamp) & 0x3ffff;
233 msc->last_timestamp = ts;
234 msc->ntouches = (size - 6) / 8;
235 for (ii = 0; ii < msc->ntouches; ii++)
236 magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
237 /* When emulating three-button mode, it is important
238 * to have the current touch information before
239 * generating a click event.
240 */
241 x = (signed char)data[1];
242 y = (signed char)data[2];
243 clicks = data[3];
244 break;
245 case 0x20: /* Theoretically battery status (0-100), but I have
246 * never seen it -- maybe it is only upon request.
247 */
248 case 0x60: /* Unknown, maybe laser on/off. */
249 case 0x61: /* Laser reflection status change.
250 * data[1]: 0 = spotted, 1 = lost
251 */
252 default:
253 return 0;
254 }
255
256 magicmouse_emit_buttons(msc, clicks & 3);
257 input_report_rel(input, REL_X, x);
258 input_report_rel(input, REL_Y, y);
259 input_sync(input);
260 return 1;
261}
262
263static int magicmouse_input_open(struct input_dev *dev)
264{
265 struct hid_device *hid = input_get_drvdata(dev);
266
267 return hid->ll_driver->open(hid);
268}
269
270static void magicmouse_input_close(struct input_dev *dev)
271{
272 struct hid_device *hid = input_get_drvdata(dev);
273
274 hid->ll_driver->close(hid);
275}
276
277static void magicmouse_setup_input(struct input_dev *input, struct hid_device *hdev)
278{
279 input_set_drvdata(input, hdev);
280 input->event = hdev->ll_driver->hidinput_input_event;
281 input->open = magicmouse_input_open;
282 input->close = magicmouse_input_close;
283
284 input->name = hdev->name;
285 input->phys = hdev->phys;
286 input->uniq = hdev->uniq;
287 input->id.bustype = hdev->bus;
288 input->id.vendor = hdev->vendor;
289 input->id.product = hdev->product;
290 input->id.version = hdev->version;
291 input->dev.parent = hdev->dev.parent;
292
293 __set_bit(EV_KEY, input->evbit);
294 __set_bit(BTN_LEFT, input->keybit);
295 __set_bit(BTN_RIGHT, input->keybit);
296 if (emulate_3button)
297 __set_bit(BTN_MIDDLE, input->keybit);
298 __set_bit(BTN_TOOL_FINGER, input->keybit);
299
300 __set_bit(EV_REL, input->evbit);
301 __set_bit(REL_X, input->relbit);
302 __set_bit(REL_Y, input->relbit);
303 if (emulate_scroll_wheel)
304 __set_bit(REL_WHEEL, input->relbit);
305
306 if (report_touches) {
307 __set_bit(EV_ABS, input->evbit);
308
309 input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15, 0, 0);
310 input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 4, 0);
311 input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 4, 0);
312 input_set_abs_params(input, ABS_MT_ORIENTATION, -32, 31, 1, 0);
313 input_set_abs_params(input, ABS_MT_POSITION_X, -1100, 1358,
314 4, 0);
315 /* Note: Touch Y position from the device is inverted relative
316 * to how pointer motion is reported (and relative to how USB
317 * HID recommends the coordinates work). This driver keeps
318 * the origin at the same position, and just uses the additive
319 * inverse of the reported Y.
320 */
321 input_set_abs_params(input, ABS_MT_POSITION_Y, -1589, 2047,
322 4, 0);
323 }
324
325 if (report_undeciphered) {
326 __set_bit(EV_MSC, input->evbit);
327 __set_bit(MSC_RAW, input->mscbit);
328 }
329}
330
331static int magicmouse_probe(struct hid_device *hdev,
332 const struct hid_device_id *id)
333{
334 __u8 feature_1[] = { 0xd7, 0x01 };
335 __u8 feature_2[] = { 0xf8, 0x01, 0x32 };
336 struct input_dev *input;
337 struct magicmouse_sc *msc;
338 struct hid_report *report;
339 int ret;
340
341 msc = kzalloc(sizeof(*msc), GFP_KERNEL);
342 if (msc == NULL) {
343 dev_err(&hdev->dev, "can't alloc magicmouse descriptor\n");
344 return -ENOMEM;
345 }
346
347 msc->quirks = id->driver_data;
348 hid_set_drvdata(hdev, msc);
349
350 ret = hid_parse(hdev);
351 if (ret) {
352 dev_err(&hdev->dev, "magicmouse hid parse failed\n");
353 goto err_free;
354 }
355
356 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
357 if (ret) {
358 dev_err(&hdev->dev, "magicmouse hw start failed\n");
359 goto err_free;
360 }
361
362 report = hid_register_report(hdev, HID_INPUT_REPORT, TOUCH_REPORT_ID);
363 if (!report) {
364 dev_err(&hdev->dev, "unable to register touch report\n");
365 ret = -ENOMEM;
366 goto err_stop_hw;
367 }
368 report->size = 6;
369
370 ret = hdev->hid_output_raw_report(hdev, feature_1, sizeof(feature_1),
371 HID_FEATURE_REPORT);
372 if (ret != sizeof(feature_1)) {
373 dev_err(&hdev->dev, "unable to request touch data (1:%d)\n",
374 ret);
375 goto err_stop_hw;
376 }
377 ret = hdev->hid_output_raw_report(hdev, feature_2,
378 sizeof(feature_2), HID_FEATURE_REPORT);
379 if (ret != sizeof(feature_2)) {
380 dev_err(&hdev->dev, "unable to request touch data (2:%d)\n",
381 ret);
382 goto err_stop_hw;
383 }
384
385 input = input_allocate_device();
386 if (!input) {
387 dev_err(&hdev->dev, "can't alloc input device\n");
388 ret = -ENOMEM;
389 goto err_stop_hw;
390 }
391 magicmouse_setup_input(input, hdev);
392
393 ret = input_register_device(input);
394 if (ret) {
395 dev_err(&hdev->dev, "input device registration failed\n");
396 goto err_input;
397 }
398 msc->input = input;
399
400 return 0;
401err_input:
402 input_free_device(input);
403err_stop_hw:
404 hid_hw_stop(hdev);
405err_free:
406 kfree(msc);
407 return ret;
408}
409
410static void magicmouse_remove(struct hid_device *hdev)
411{
412 hid_hw_stop(hdev);
413 kfree(hid_get_drvdata(hdev));
414}
415
416static const struct hid_device_id magic_mice[] = {
417 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGICMOUSE),
418 .driver_data = 0 },
419 { }
420};
421MODULE_DEVICE_TABLE(hid, magic_mice);
422
423static struct hid_driver magicmouse_driver = {
424 .name = "magicmouse",
425 .id_table = magic_mice,
426 .probe = magicmouse_probe,
427 .remove = magicmouse_remove,
428 .raw_event = magicmouse_raw_event,
429};
430
431static int __init magicmouse_init(void)
432{
433 int ret;
434
435 ret = hid_register_driver(&magicmouse_driver);
436 if (ret)
437 printk(KERN_ERR "can't register magicmouse driver\n");
438
439 return ret;
440}
441
442static void __exit magicmouse_exit(void)
443{
444 hid_unregister_driver(&magicmouse_driver);
445}
446
447module_init(magicmouse_init);
448module_exit(magicmouse_exit);
449MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-mosart.c b/drivers/hid/hid-mosart.c
new file mode 100644
index 000000000000..c8718168fe42
--- /dev/null
+++ b/drivers/hid/hid-mosart.c
@@ -0,0 +1,273 @@
1/*
2 * HID driver for the multitouch panel on the ASUS EeePC T91MT
3 *
4 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
5 * Copyright (c) 2010 Teemu Tuominen <teemu.tuominen@cybercom.com>
6 *
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 */
15
16#include <linux/device.h>
17#include <linux/hid.h>
18#include <linux/module.h>
19#include <linux/usb.h>
20#include "usbhid/usbhid.h"
21
22MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
23MODULE_DESCRIPTION("MosArt dual-touch panel");
24MODULE_LICENSE("GPL");
25
26#include "hid-ids.h"
27
28struct mosart_data {
29 __u16 x, y;
30 __u8 id;
31 bool valid; /* valid finger data, or just placeholder? */
32 bool first; /* is this the first finger in this frame? */
33 bool activity_now; /* at least one active finger in this frame? */
34 bool activity; /* at least one active finger previously? */
35};
36
37static int mosart_input_mapping(struct hid_device *hdev, struct hid_input *hi,
38 struct hid_field *field, struct hid_usage *usage,
39 unsigned long **bit, int *max)
40{
41 switch (usage->hid & HID_USAGE_PAGE) {
42
43 case HID_UP_GENDESK:
44 switch (usage->hid) {
45 case HID_GD_X:
46 hid_map_usage(hi, usage, bit, max,
47 EV_ABS, ABS_MT_POSITION_X);
48 /* touchscreen emulation */
49 input_set_abs_params(hi->input, ABS_X,
50 field->logical_minimum,
51 field->logical_maximum, 0, 0);
52 return 1;
53 case HID_GD_Y:
54 hid_map_usage(hi, usage, bit, max,
55 EV_ABS, ABS_MT_POSITION_Y);
56 /* touchscreen emulation */
57 input_set_abs_params(hi->input, ABS_Y,
58 field->logical_minimum,
59 field->logical_maximum, 0, 0);
60 return 1;
61 }
62 return 0;
63
64 case HID_UP_DIGITIZER:
65 switch (usage->hid) {
66 case HID_DG_CONFIDENCE:
67 case HID_DG_TIPSWITCH:
68 case HID_DG_INPUTMODE:
69 case HID_DG_DEVICEINDEX:
70 case HID_DG_CONTACTCOUNT:
71 case HID_DG_CONTACTMAX:
72 case HID_DG_TIPPRESSURE:
73 case HID_DG_WIDTH:
74 case HID_DG_HEIGHT:
75 return -1;
76 case HID_DG_INRANGE:
77 /* touchscreen emulation */
78 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
79 return 1;
80
81 case HID_DG_CONTACTID:
82 hid_map_usage(hi, usage, bit, max,
83 EV_ABS, ABS_MT_TRACKING_ID);
84 return 1;
85
86 }
87 return 0;
88
89 case 0xff000000:
90 /* ignore HID features */
91 return -1;
92 }
93
94 return 0;
95}
96
97static int mosart_input_mapped(struct hid_device *hdev, struct hid_input *hi,
98 struct hid_field *field, struct hid_usage *usage,
99 unsigned long **bit, int *max)
100{
101 if (usage->type == EV_KEY || usage->type == EV_ABS)
102 clear_bit(usage->code, *bit);
103
104 return 0;
105}
106
107/*
108 * this function is called when a whole finger has been parsed,
109 * so that it can decide what to send to the input layer.
110 */
111static void mosart_filter_event(struct mosart_data *td, struct input_dev *input)
112{
113 td->first = !td->first; /* touchscreen emulation */
114
115 if (!td->valid) {
116 /*
117 * touchscreen emulation: if no finger in this frame is valid
118 * and there previously was finger activity, this is a release
119 */
120 if (!td->first && !td->activity_now && td->activity) {
121 input_event(input, EV_KEY, BTN_TOUCH, 0);
122 td->activity = false;
123 }
124 return;
125 }
126
127 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, td->id);
128 input_event(input, EV_ABS, ABS_MT_POSITION_X, td->x);
129 input_event(input, EV_ABS, ABS_MT_POSITION_Y, td->y);
130
131 input_mt_sync(input);
132 td->valid = false;
133
134 /* touchscreen emulation: if first active finger in this frame... */
135 if (!td->activity_now) {
136 /* if there was no previous activity, emit touch event */
137 if (!td->activity) {
138 input_event(input, EV_KEY, BTN_TOUCH, 1);
139 td->activity = true;
140 }
141 td->activity_now = true;
142 /* and in any case this is our preferred finger */
143 input_event(input, EV_ABS, ABS_X, td->x);
144 input_event(input, EV_ABS, ABS_Y, td->y);
145 }
146}
147
148
149static int mosart_event(struct hid_device *hid, struct hid_field *field,
150 struct hid_usage *usage, __s32 value)
151{
152 struct mosart_data *td = hid_get_drvdata(hid);
153
154 if (hid->claimed & HID_CLAIMED_INPUT) {
155 struct input_dev *input = field->hidinput->input;
156 switch (usage->hid) {
157 case HID_DG_INRANGE:
158 td->valid = !!value;
159 break;
160 case HID_GD_X:
161 td->x = value;
162 break;
163 case HID_GD_Y:
164 td->y = value;
165 mosart_filter_event(td, input);
166 break;
167 case HID_DG_CONTACTID:
168 td->id = value;
169 break;
170 case HID_DG_CONTACTCOUNT:
171 /* touch emulation: this is the last field in a frame */
172 td->first = false;
173 td->activity_now = false;
174 break;
175 case HID_DG_CONFIDENCE:
176 case HID_DG_TIPSWITCH:
177 /* avoid interference from generic hidinput handling */
178 break;
179
180 default:
181 /* fallback to the generic hidinput handling */
182 return 0;
183 }
184 }
185
186 /* we have handled the hidinput part, now remains hiddev */
187 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
188 hid->hiddev_hid_event(hid, field, usage, value);
189
190 return 1;
191}
192
193static int mosart_probe(struct hid_device *hdev, const struct hid_device_id *id)
194{
195 int ret;
196 struct mosart_data *td;
197
198
199 td = kmalloc(sizeof(struct mosart_data), GFP_KERNEL);
200 if (!td) {
201 dev_err(&hdev->dev, "cannot allocate MosArt data\n");
202 return -ENOMEM;
203 }
204 td->valid = false;
205 td->activity = false;
206 td->activity_now = false;
207 td->first = false;
208 hid_set_drvdata(hdev, td);
209
210 /* currently, it's better to have one evdev device only */
211#if 0
212 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
213#endif
214
215 ret = hid_parse(hdev);
216 if (ret == 0)
217 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
218
219 if (ret == 0) {
220 struct hid_report_enum *re = hdev->report_enum
221 + HID_FEATURE_REPORT;
222 struct hid_report *r = re->report_id_hash[7];
223
224 r->field[0]->value[0] = 0x02;
225 usbhid_submit_report(hdev, r, USB_DIR_OUT);
226 } else
227 kfree(td);
228
229 return ret;
230}
231
232static void mosart_remove(struct hid_device *hdev)
233{
234 hid_hw_stop(hdev);
235 kfree(hid_get_drvdata(hdev));
236 hid_set_drvdata(hdev, NULL);
237}
238
239static const struct hid_device_id mosart_devices[] = {
240 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
241 { }
242};
243MODULE_DEVICE_TABLE(hid, mosart_devices);
244
245static const struct hid_usage_id mosart_grabbed_usages[] = {
246 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
247 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
248};
249
250static struct hid_driver mosart_driver = {
251 .name = "mosart",
252 .id_table = mosart_devices,
253 .probe = mosart_probe,
254 .remove = mosart_remove,
255 .input_mapping = mosart_input_mapping,
256 .input_mapped = mosart_input_mapped,
257 .usage_table = mosart_grabbed_usages,
258 .event = mosart_event,
259};
260
261static int __init mosart_init(void)
262{
263 return hid_register_driver(&mosart_driver);
264}
265
266static void __exit mosart_exit(void)
267{
268 hid_unregister_driver(&mosart_driver);
269}
270
271module_init(mosart_init);
272module_exit(mosart_exit);
273
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index 49ce69d7bba7..3234c729a895 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -25,11 +25,16 @@
25 EV_KEY, (c)) 25 EV_KEY, (c))
26 26
27struct ntrig_data { 27struct ntrig_data {
28 __s32 x, y, id, w, h; 28 /* Incoming raw values for a single contact */
29 char reading_a_point, found_contact_id; 29 __u16 x, y, w, h;
30 char pen_active; 30 __u16 id;
31 char finger_active; 31 __u8 confidence;
32 char inverted; 32
33 bool reading_mt;
34 __u8 first_contact_confidence;
35
36 __u8 mt_footer[4];
37 __u8 mt_foot_count;
33}; 38};
34 39
35/* 40/*
@@ -42,8 +47,11 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi,
42 struct hid_field *field, struct hid_usage *usage, 47 struct hid_field *field, struct hid_usage *usage,
43 unsigned long **bit, int *max) 48 unsigned long **bit, int *max)
44{ 49{
45 switch (usage->hid & HID_USAGE_PAGE) { 50 /* No special mappings needed for the pen and single touch */
51 if (field->physical)
52 return 0;
46 53
54 switch (usage->hid & HID_USAGE_PAGE) {
47 case HID_UP_GENDESK: 55 case HID_UP_GENDESK:
48 switch (usage->hid) { 56 switch (usage->hid) {
49 case HID_GD_X: 57 case HID_GD_X:
@@ -66,18 +74,12 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi,
66 case HID_UP_DIGITIZER: 74 case HID_UP_DIGITIZER:
67 switch (usage->hid) { 75 switch (usage->hid) {
68 /* we do not want to map these for now */ 76 /* we do not want to map these for now */
69 case HID_DG_CONTACTID: /* value is useless */ 77 case HID_DG_CONTACTID: /* Not trustworthy, squelch for now */
70 case HID_DG_INPUTMODE: 78 case HID_DG_INPUTMODE:
71 case HID_DG_DEVICEINDEX: 79 case HID_DG_DEVICEINDEX:
72 case HID_DG_CONTACTCOUNT:
73 case HID_DG_CONTACTMAX: 80 case HID_DG_CONTACTMAX:
74 return -1; 81 return -1;
75 82
76 /* original mapping by Rafi Rubin */
77 case HID_DG_CONFIDENCE:
78 nt_map_key_clear(BTN_TOOL_DOUBLETAP);
79 return 1;
80
81 /* width/height mapped on TouchMajor/TouchMinor/Orientation */ 83 /* width/height mapped on TouchMajor/TouchMinor/Orientation */
82 case HID_DG_WIDTH: 84 case HID_DG_WIDTH:
83 hid_map_usage(hi, usage, bit, max, 85 hid_map_usage(hi, usage, bit, max,
@@ -104,6 +106,10 @@ static int ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi,
104 struct hid_field *field, struct hid_usage *usage, 106 struct hid_field *field, struct hid_usage *usage,
105 unsigned long **bit, int *max) 107 unsigned long **bit, int *max)
106{ 108{
109 /* No special mappings needed for the pen and single touch */
110 if (field->physical)
111 return 0;
112
107 if (usage->type == EV_KEY || usage->type == EV_REL 113 if (usage->type == EV_KEY || usage->type == EV_REL
108 || usage->type == EV_ABS) 114 || usage->type == EV_ABS)
109 clear_bit(usage->code, *bit); 115 clear_bit(usage->code, *bit);
@@ -123,31 +129,30 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
123 struct input_dev *input = field->hidinput->input; 129 struct input_dev *input = field->hidinput->input;
124 struct ntrig_data *nd = hid_get_drvdata(hid); 130 struct ntrig_data *nd = hid_get_drvdata(hid);
125 131
132 /* No special handling needed for the pen */
133 if (field->application == HID_DG_PEN)
134 return 0;
135
126 if (hid->claimed & HID_CLAIMED_INPUT) { 136 if (hid->claimed & HID_CLAIMED_INPUT) {
127 switch (usage->hid) { 137 switch (usage->hid) {
128 138 case 0xff000001:
129 case HID_DG_INRANGE: 139 /* Tag indicating the start of a multitouch group */
130 if (field->application & 0x3) 140 nd->reading_mt = 1;
131 nd->pen_active = (value != 0); 141 nd->first_contact_confidence = 0;
132 else 142 break;
133 nd->finger_active = (value != 0); 143 case HID_DG_CONFIDENCE:
134 return 0; 144 nd->confidence = value;
135 145 break;
136 case HID_DG_INVERT:
137 nd->inverted = value;
138 return 0;
139
140 case HID_GD_X: 146 case HID_GD_X:
141 nd->x = value; 147 nd->x = value;
142 nd->reading_a_point = 1; 148 /* Clear the contact footer */
149 nd->mt_foot_count = 0;
143 break; 150 break;
144 case HID_GD_Y: 151 case HID_GD_Y:
145 nd->y = value; 152 nd->y = value;
146 break; 153 break;
147 case HID_DG_CONTACTID: 154 case HID_DG_CONTACTID:
148 nd->id = value; 155 nd->id = value;
149 /* we receive this only when in multitouch mode */
150 nd->found_contact_id = 1;
151 break; 156 break;
152 case HID_DG_WIDTH: 157 case HID_DG_WIDTH:
153 nd->w = value; 158 nd->w = value;
@@ -159,35 +164,13 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
159 * report received in a finger event. We want 164 * report received in a finger event. We want
160 * to emit a normal (X, Y) position 165 * to emit a normal (X, Y) position
161 */ 166 */
162 if (!nd->found_contact_id) { 167 if (!nd->reading_mt) {
163 if (nd->pen_active && nd->finger_active) { 168 input_report_key(input, BTN_TOOL_DOUBLETAP,
164 input_report_key(input, BTN_TOOL_DOUBLETAP, 0); 169 (nd->confidence != 0));
165 input_report_key(input, BTN_TOOL_DOUBLETAP, 1);
166 }
167 input_event(input, EV_ABS, ABS_X, nd->x); 170 input_event(input, EV_ABS, ABS_X, nd->x);
168 input_event(input, EV_ABS, ABS_Y, nd->y); 171 input_event(input, EV_ABS, ABS_Y, nd->y);
169 } 172 }
170 break; 173 break;
171 case HID_DG_TIPPRESSURE:
172 /*
173 * when in single touch mode, this is the last
174 * report received in a pen event. We want
175 * to emit a normal (X, Y) position
176 */
177 if (! nd->found_contact_id) {
178 if (nd->pen_active && nd->finger_active) {
179 input_report_key(input,
180 nd->inverted ? BTN_TOOL_RUBBER : BTN_TOOL_PEN
181 , 0);
182 input_report_key(input,
183 nd->inverted ? BTN_TOOL_RUBBER : BTN_TOOL_PEN
184 , 1);
185 }
186 input_event(input, EV_ABS, ABS_X, nd->x);
187 input_event(input, EV_ABS, ABS_Y, nd->y);
188 input_event(input, EV_ABS, ABS_PRESSURE, value);
189 }
190 break;
191 case 0xff000002: 174 case 0xff000002:
192 /* 175 /*
193 * we receive this when the device is in multitouch 176 * we receive this when the device is in multitouch
@@ -195,10 +178,34 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
195 * this usage tells if the contact point is real 178 * this usage tells if the contact point is real
196 * or a placeholder 179 * or a placeholder
197 */ 180 */
198 if (!nd->reading_a_point || value != 1) 181
182 /* Shouldn't get more than 4 footer packets, so skip */
183 if (nd->mt_foot_count >= 4)
199 break; 184 break;
185
186 nd->mt_footer[nd->mt_foot_count++] = value;
187
188 /* if the footer isn't complete break */
189 if (nd->mt_foot_count != 4)
190 break;
191
192 /* Pen activity signal, trigger end of touch. */
193 if (nd->mt_footer[2]) {
194 nd->confidence = 0;
195 break;
196 }
197
198 /* If the contact was invalid */
199 if (!(nd->confidence && nd->mt_footer[0])
200 || nd->w <= 250
201 || nd->h <= 190) {
202 nd->confidence = 0;
203 break;
204 }
205
200 /* emit a normal (X, Y) for the first point only */ 206 /* emit a normal (X, Y) for the first point only */
201 if (nd->id == 0) { 207 if (nd->id == 0) {
208 nd->first_contact_confidence = nd->confidence;
202 input_event(input, EV_ABS, ABS_X, nd->x); 209 input_event(input, EV_ABS, ABS_X, nd->x);
203 input_event(input, EV_ABS, ABS_Y, nd->y); 210 input_event(input, EV_ABS, ABS_Y, nd->y);
204 } 211 }
@@ -220,8 +227,39 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
220 ABS_MT_TOUCH_MINOR, nd->w); 227 ABS_MT_TOUCH_MINOR, nd->w);
221 } 228 }
222 input_mt_sync(field->hidinput->input); 229 input_mt_sync(field->hidinput->input);
223 nd->reading_a_point = 0; 230 break;
224 nd->found_contact_id = 0; 231
232 case HID_DG_CONTACTCOUNT: /* End of a multitouch group */
233 if (!nd->reading_mt)
234 break;
235
236 nd->reading_mt = 0;
237
238 if (nd->first_contact_confidence) {
239 switch (value) {
240 case 0: /* for single touch devices */
241 case 1:
242 input_report_key(input,
243 BTN_TOOL_DOUBLETAP, 1);
244 break;
245 case 2:
246 input_report_key(input,
247 BTN_TOOL_TRIPLETAP, 1);
248 break;
249 case 3:
250 default:
251 input_report_key(input,
252 BTN_TOOL_QUADTAP, 1);
253 }
254 input_report_key(input, BTN_TOUCH, 1);
255 } else {
256 input_report_key(input,
257 BTN_TOOL_DOUBLETAP, 0);
258 input_report_key(input,
259 BTN_TOOL_TRIPLETAP, 0);
260 input_report_key(input,
261 BTN_TOOL_QUADTAP, 0);
262 }
225 break; 263 break;
226 264
227 default: 265 default:
@@ -231,8 +269,8 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
231 } 269 }
232 270
233 /* we have handled the hidinput part, now remains hiddev */ 271 /* we have handled the hidinput part, now remains hiddev */
234 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) 272 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_hid_event)
235 hid->hiddev_hid_event(hid, field, usage, value); 273 hid->hiddev_hid_event(hid, field, usage, value);
236 274
237 return 1; 275 return 1;
238} 276}
@@ -241,23 +279,67 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id)
241{ 279{
242 int ret; 280 int ret;
243 struct ntrig_data *nd; 281 struct ntrig_data *nd;
282 struct hid_input *hidinput;
283 struct input_dev *input;
284
285 if (id->driver_data)
286 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
244 287
245 nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL); 288 nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL);
246 if (!nd) { 289 if (!nd) {
247 dev_err(&hdev->dev, "cannot allocate N-Trig data\n"); 290 dev_err(&hdev->dev, "cannot allocate N-Trig data\n");
248 return -ENOMEM; 291 return -ENOMEM;
249 } 292 }
250 nd->reading_a_point = 0; 293
251 nd->found_contact_id = 0; 294 nd->reading_mt = 0;
252 hid_set_drvdata(hdev, nd); 295 hid_set_drvdata(hdev, nd);
253 296
254 ret = hid_parse(hdev); 297 ret = hid_parse(hdev);
255 if (!ret) 298 if (ret) {
256 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 299 dev_err(&hdev->dev, "parse failed\n");
300 goto err_free;
301 }
302
303 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
304 if (ret) {
305 dev_err(&hdev->dev, "hw start failed\n");
306 goto err_free;
307 }
257 308
258 if (ret)
259 kfree (nd);
260 309
310 list_for_each_entry(hidinput, &hdev->inputs, list) {
311 input = hidinput->input;
312 switch (hidinput->report->field[0]->application) {
313 case HID_DG_PEN:
314 input->name = "N-Trig Pen";
315 break;
316 case HID_DG_TOUCHSCREEN:
317 __clear_bit(BTN_TOOL_PEN, input->keybit);
318 /*
319 * A little something special to enable
320 * two and three finger taps.
321 */
322 __set_bit(BTN_TOOL_DOUBLETAP, input->keybit);
323 __set_bit(BTN_TOOL_TRIPLETAP, input->keybit);
324 __set_bit(BTN_TOOL_QUADTAP, input->keybit);
325 /*
326 * The physical touchscreen (single touch)
327 * input has a value for physical, whereas
328 * the multitouch only has logical input
329 * fields.
330 */
331 input->name =
332 (hidinput->report->field[0]
333 ->physical) ?
334 "N-Trig Touchscreen" :
335 "N-Trig MultiTouch";
336 break;
337 }
338 }
339
340 return 0;
341err_free:
342 kfree(nd);
261 return ret; 343 return ret;
262} 344}
263 345
@@ -276,7 +358,7 @@ MODULE_DEVICE_TABLE(hid, ntrig_devices);
276 358
277static const struct hid_usage_id ntrig_grabbed_usages[] = { 359static const struct hid_usage_id ntrig_grabbed_usages[] = {
278 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, 360 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
279 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} 361 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 }
280}; 362};
281 363
282static struct hid_driver ntrig_driver = { 364static struct hid_driver ntrig_driver = {
diff --git a/drivers/hid/hid-ortek.c b/drivers/hid/hid-ortek.c
new file mode 100644
index 000000000000..aa9a960f73a4
--- /dev/null
+++ b/drivers/hid/hid-ortek.c
@@ -0,0 +1,56 @@
1/*
2 * HID driver for Ortek WKB-2000 (wireless keyboard + mouse trackpad).
3 * Fixes LogicalMaximum error in USB report description, see
4 * http://bugzilla.kernel.org/show_bug.cgi?id=14787
5 *
6 * Copyright (c) 2010 Johnathon Harris <jmharris@gmail.com>
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 */
15
16#include <linux/device.h>
17#include <linux/hid.h>
18#include <linux/module.h>
19
20#include "hid-ids.h"
21
22static void ortek_report_fixup(struct hid_device *hdev, __u8 *rdesc,
23 unsigned int rsize)
24{
25 if (rsize >= 56 && rdesc[54] == 0x25 && rdesc[55] == 0x01) {
26 dev_info(&hdev->dev, "Fixing up Ortek WKB-2000 "
27 "report descriptor.\n");
28 rdesc[55] = 0x92;
29 }
30}
31
32static const struct hid_device_id ortek_devices[] = {
33 { HID_USB_DEVICE(USB_VENDOR_ID_ORTEK, USB_DEVICE_ID_ORTEK_WKB2000) },
34 { }
35};
36MODULE_DEVICE_TABLE(hid, ortek_devices);
37
38static struct hid_driver ortek_driver = {
39 .name = "ortek",
40 .id_table = ortek_devices,
41 .report_fixup = ortek_report_fixup
42};
43
44static int __init ortek_init(void)
45{
46 return hid_register_driver(&ortek_driver);
47}
48
49static void __exit ortek_exit(void)
50{
51 hid_unregister_driver(&ortek_driver);
52}
53
54module_init(ortek_init);
55module_exit(ortek_exit);
56MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-quanta.c b/drivers/hid/hid-quanta.c
new file mode 100644
index 000000000000..01dd51c4986c
--- /dev/null
+++ b/drivers/hid/hid-quanta.c
@@ -0,0 +1,260 @@
1/*
2 * HID driver for Quanta Optical Touch dual-touch panels
3 *
4 * Copyright (c) 2009-2010 Stephane Chatty <chatty@enac.fr>
5 *
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
18
19MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
20MODULE_DESCRIPTION("Quanta dual-touch panel");
21MODULE_LICENSE("GPL");
22
23#include "hid-ids.h"
24
25struct quanta_data {
26 __u16 x, y;
27 __u8 id;
28 bool valid; /* valid finger data, or just placeholder? */
29 bool first; /* is this the first finger in this frame? */
30 bool activity_now; /* at least one active finger in this frame? */
31 bool activity; /* at least one active finger previously? */
32};
33
34static int quanta_input_mapping(struct hid_device *hdev, struct hid_input *hi,
35 struct hid_field *field, struct hid_usage *usage,
36 unsigned long **bit, int *max)
37{
38 switch (usage->hid & HID_USAGE_PAGE) {
39
40 case HID_UP_GENDESK:
41 switch (usage->hid) {
42 case HID_GD_X:
43 hid_map_usage(hi, usage, bit, max,
44 EV_ABS, ABS_MT_POSITION_X);
45 /* touchscreen emulation */
46 input_set_abs_params(hi->input, ABS_X,
47 field->logical_minimum,
48 field->logical_maximum, 0, 0);
49 return 1;
50 case HID_GD_Y:
51 hid_map_usage(hi, usage, bit, max,
52 EV_ABS, ABS_MT_POSITION_Y);
53 /* touchscreen emulation */
54 input_set_abs_params(hi->input, ABS_Y,
55 field->logical_minimum,
56 field->logical_maximum, 0, 0);
57 return 1;
58 }
59 return 0;
60
61 case HID_UP_DIGITIZER:
62 switch (usage->hid) {
63 case HID_DG_CONFIDENCE:
64 case HID_DG_TIPSWITCH:
65 case HID_DG_INPUTMODE:
66 case HID_DG_DEVICEINDEX:
67 case HID_DG_CONTACTCOUNT:
68 case HID_DG_CONTACTMAX:
69 case HID_DG_TIPPRESSURE:
70 case HID_DG_WIDTH:
71 case HID_DG_HEIGHT:
72 return -1;
73 case HID_DG_INRANGE:
74 /* touchscreen emulation */
75 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
76 return 1;
77 case HID_DG_CONTACTID:
78 hid_map_usage(hi, usage, bit, max,
79 EV_ABS, ABS_MT_TRACKING_ID);
80 return 1;
81 }
82 return 0;
83
84 case 0xff000000:
85 /* ignore vendor-specific features */
86 return -1;
87 }
88
89 return 0;
90}
91
92static int quanta_input_mapped(struct hid_device *hdev, struct hid_input *hi,
93 struct hid_field *field, struct hid_usage *usage,
94 unsigned long **bit, int *max)
95{
96 if (usage->type == EV_KEY || usage->type == EV_ABS)
97 clear_bit(usage->code, *bit);
98
99 return 0;
100}
101
102/*
103 * this function is called when a whole finger has been parsed,
104 * so that it can decide what to send to the input layer.
105 */
106static void quanta_filter_event(struct quanta_data *td, struct input_dev *input)
107{
108
109 td->first = !td->first; /* touchscreen emulation */
110
111 if (!td->valid) {
112 /*
113 * touchscreen emulation: if no finger in this frame is valid
114 * and there previously was finger activity, this is a release
115 */
116 if (!td->first && !td->activity_now && td->activity) {
117 input_event(input, EV_KEY, BTN_TOUCH, 0);
118 td->activity = false;
119 }
120 return;
121 }
122
123 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, td->id);
124 input_event(input, EV_ABS, ABS_MT_POSITION_X, td->x);
125 input_event(input, EV_ABS, ABS_MT_POSITION_Y, td->y);
126
127 input_mt_sync(input);
128 td->valid = false;
129
130 /* touchscreen emulation: if first active finger in this frame... */
131 if (!td->activity_now) {
132 /* if there was no previous activity, emit touch event */
133 if (!td->activity) {
134 input_event(input, EV_KEY, BTN_TOUCH, 1);
135 td->activity = true;
136 }
137 td->activity_now = true;
138 /* and in any case this is our preferred finger */
139 input_event(input, EV_ABS, ABS_X, td->x);
140 input_event(input, EV_ABS, ABS_Y, td->y);
141 }
142}
143
144
145static int quanta_event(struct hid_device *hid, struct hid_field *field,
146 struct hid_usage *usage, __s32 value)
147{
148 struct quanta_data *td = hid_get_drvdata(hid);
149
150 if (hid->claimed & HID_CLAIMED_INPUT) {
151 struct input_dev *input = field->hidinput->input;
152
153 switch (usage->hid) {
154 case HID_DG_INRANGE:
155 td->valid = !!value;
156 break;
157 case HID_GD_X:
158 td->x = value;
159 break;
160 case HID_GD_Y:
161 td->y = value;
162 quanta_filter_event(td, input);
163 break;
164 case HID_DG_CONTACTID:
165 td->id = value;
166 break;
167 case HID_DG_CONTACTCOUNT:
168 /* touch emulation: this is the last field in a frame */
169 td->first = false;
170 td->activity_now = false;
171 break;
172 case HID_DG_CONFIDENCE:
173 case HID_DG_TIPSWITCH:
174 /* avoid interference from generic hidinput handling */
175 break;
176
177 default:
178 /* fallback to the generic hidinput handling */
179 return 0;
180 }
181 }
182
183 /* we have handled the hidinput part, now remains hiddev */
184 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
185 hid->hiddev_hid_event(hid, field, usage, value);
186
187 return 1;
188}
189
190static int quanta_probe(struct hid_device *hdev, const struct hid_device_id *id)
191{
192 int ret;
193 struct quanta_data *td;
194
195 td = kmalloc(sizeof(struct quanta_data), GFP_KERNEL);
196 if (!td) {
197 dev_err(&hdev->dev, "cannot allocate Quanta Touch data\n");
198 return -ENOMEM;
199 }
200 td->valid = false;
201 td->activity = false;
202 td->activity_now = false;
203 td->first = false;
204 hid_set_drvdata(hdev, td);
205
206 ret = hid_parse(hdev);
207 if (!ret)
208 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
209
210 if (ret)
211 kfree(td);
212
213 return ret;
214}
215
216static void quanta_remove(struct hid_device *hdev)
217{
218 hid_hw_stop(hdev);
219 kfree(hid_get_drvdata(hdev));
220 hid_set_drvdata(hdev, NULL);
221}
222
223static const struct hid_device_id quanta_devices[] = {
224 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
225 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
226 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
227 USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
228 { }
229};
230MODULE_DEVICE_TABLE(hid, quanta_devices);
231
232static const struct hid_usage_id quanta_grabbed_usages[] = {
233 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
234 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
235};
236
237static struct hid_driver quanta_driver = {
238 .name = "quanta-touch",
239 .id_table = quanta_devices,
240 .probe = quanta_probe,
241 .remove = quanta_remove,
242 .input_mapping = quanta_input_mapping,
243 .input_mapped = quanta_input_mapped,
244 .usage_table = quanta_grabbed_usages,
245 .event = quanta_event,
246};
247
248static int __init quanta_init(void)
249{
250 return hid_register_driver(&quanta_driver);
251}
252
253static void __exit quanta_exit(void)
254{
255 hid_unregister_driver(&quanta_driver);
256}
257
258module_init(quanta_init);
259module_exit(quanta_exit);
260
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 4e8450228a24..9bf00d77d92b 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -48,7 +48,7 @@ static void sony_report_fixup(struct hid_device *hdev, __u8 *rdesc,
48 * to "operational". Without this, the ps3 controller will not report any 48 * to "operational". Without this, the ps3 controller will not report any
49 * events. 49 * events.
50 */ 50 */
51static int sony_set_operational(struct hid_device *hdev) 51static int sony_set_operational_usb(struct hid_device *hdev)
52{ 52{
53 struct usb_interface *intf = to_usb_interface(hdev->dev.parent); 53 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
54 struct usb_device *dev = interface_to_usbdev(intf); 54 struct usb_device *dev = interface_to_usbdev(intf);
@@ -73,6 +73,12 @@ static int sony_set_operational(struct hid_device *hdev)
73 return ret; 73 return ret;
74} 74}
75 75
76static int sony_set_operational_bt(struct hid_device *hdev)
77{
78 unsigned char buf[] = { 0x53, 0xf4, 0x42, 0x03, 0x00, 0x00 };
79 return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT);
80}
81
76static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) 82static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
77{ 83{
78 int ret; 84 int ret;
@@ -81,7 +87,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
81 87
82 sc = kzalloc(sizeof(*sc), GFP_KERNEL); 88 sc = kzalloc(sizeof(*sc), GFP_KERNEL);
83 if (sc == NULL) { 89 if (sc == NULL) {
84 dev_err(&hdev->dev, "can't alloc apple descriptor\n"); 90 dev_err(&hdev->dev, "can't alloc sony descriptor\n");
85 return -ENOMEM; 91 return -ENOMEM;
86 } 92 }
87 93
@@ -101,7 +107,17 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
101 goto err_free; 107 goto err_free;
102 } 108 }
103 109
104 ret = sony_set_operational(hdev); 110 switch (hdev->bus) {
111 case BUS_USB:
112 ret = sony_set_operational_usb(hdev);
113 break;
114 case BUS_BLUETOOTH:
115 ret = sony_set_operational_bt(hdev);
116 break;
117 default:
118 ret = 0;
119 }
120
105 if (ret < 0) 121 if (ret < 0)
106 goto err_stop; 122 goto err_stop;
107 123
@@ -121,6 +137,7 @@ static void sony_remove(struct hid_device *hdev)
121 137
122static const struct hid_device_id sony_devices[] = { 138static const struct hid_device_id sony_devices[] = {
123 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, 139 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
140 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
124 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE), 141 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE),
125 .driver_data = VAIO_RDESC_CONSTANT }, 142 .driver_data = VAIO_RDESC_CONSTANT },
126 { } 143 { }
diff --git a/drivers/hid/hid-stantum.c b/drivers/hid/hid-stantum.c
new file mode 100644
index 000000000000..2e592a06654e
--- /dev/null
+++ b/drivers/hid/hid-stantum.c
@@ -0,0 +1,283 @@
1/*
2 * HID driver for Stantum multitouch panels
3 *
4 * Copyright (c) 2009 Stephane Chatty <chatty@enac.fr>
5 *
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 */
14
15#include <linux/device.h>
16#include <linux/hid.h>
17#include <linux/module.h>
18
19MODULE_AUTHOR("Stephane Chatty <chatty@enac.fr>");
20MODULE_DESCRIPTION("Stantum HID multitouch panels");
21MODULE_LICENSE("GPL");
22
23#include "hid-ids.h"
24
25struct stantum_data {
26 __s32 x, y, z, w, h; /* x, y, pressure, width, height */
27 __u16 id; /* touch id */
28 bool valid; /* valid finger data, or just placeholder? */
29 bool first; /* first finger in the HID packet? */
30 bool activity; /* at least one active finger so far? */
31};
32
33static int stantum_input_mapping(struct hid_device *hdev, struct hid_input *hi,
34 struct hid_field *field, struct hid_usage *usage,
35 unsigned long **bit, int *max)
36{
37 switch (usage->hid & HID_USAGE_PAGE) {
38
39 case HID_UP_GENDESK:
40 switch (usage->hid) {
41 case HID_GD_X:
42 hid_map_usage(hi, usage, bit, max,
43 EV_ABS, ABS_MT_POSITION_X);
44 /* touchscreen emulation */
45 input_set_abs_params(hi->input, ABS_X,
46 field->logical_minimum,
47 field->logical_maximum, 0, 0);
48 return 1;
49 case HID_GD_Y:
50 hid_map_usage(hi, usage, bit, max,
51 EV_ABS, ABS_MT_POSITION_Y);
52 /* touchscreen emulation */
53 input_set_abs_params(hi->input, ABS_Y,
54 field->logical_minimum,
55 field->logical_maximum, 0, 0);
56 return 1;
57 }
58 return 0;
59
60 case HID_UP_DIGITIZER:
61 switch (usage->hid) {
62 case HID_DG_INRANGE:
63 case HID_DG_CONFIDENCE:
64 case HID_DG_INPUTMODE:
65 case HID_DG_DEVICEINDEX:
66 case HID_DG_CONTACTCOUNT:
67 case HID_DG_CONTACTMAX:
68 return -1;
69
70 case HID_DG_TIPSWITCH:
71 /* touchscreen emulation */
72 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_TOUCH);
73 return 1;
74
75 case HID_DG_WIDTH:
76 hid_map_usage(hi, usage, bit, max,
77 EV_ABS, ABS_MT_TOUCH_MAJOR);
78 return 1;
79 case HID_DG_HEIGHT:
80 hid_map_usage(hi, usage, bit, max,
81 EV_ABS, ABS_MT_TOUCH_MINOR);
82 input_set_abs_params(hi->input, ABS_MT_ORIENTATION,
83 1, 1, 0, 0);
84 return 1;
85 case HID_DG_TIPPRESSURE:
86 hid_map_usage(hi, usage, bit, max,
87 EV_ABS, ABS_MT_PRESSURE);
88 return 1;
89
90 case HID_DG_CONTACTID:
91 hid_map_usage(hi, usage, bit, max,
92 EV_ABS, ABS_MT_TRACKING_ID);
93 return 1;
94
95 }
96 return 0;
97
98 case 0xff000000:
99 /* no input-oriented meaning */
100 return -1;
101 }
102
103 return 0;
104}
105
106static int stantum_input_mapped(struct hid_device *hdev, struct hid_input *hi,
107 struct hid_field *field, struct hid_usage *usage,
108 unsigned long **bit, int *max)
109{
110 if (usage->type == EV_KEY || usage->type == EV_ABS)
111 clear_bit(usage->code, *bit);
112
113 return 0;
114}
115
116/*
117 * this function is called when a whole finger has been parsed,
118 * so that it can decide what to send to the input layer.
119 */
120static void stantum_filter_event(struct stantum_data *sd,
121 struct input_dev *input)
122{
123 bool wide;
124
125 if (!sd->valid) {
126 /*
127 * touchscreen emulation: if the first finger is not valid and
128 * there previously was finger activity, this is a release
129 */
130 if (sd->first && sd->activity) {
131 input_event(input, EV_KEY, BTN_TOUCH, 0);
132 sd->activity = false;
133 }
134 return;
135 }
136
137 input_event(input, EV_ABS, ABS_MT_TRACKING_ID, sd->id);
138 input_event(input, EV_ABS, ABS_MT_POSITION_X, sd->x);
139 input_event(input, EV_ABS, ABS_MT_POSITION_Y, sd->y);
140
141 wide = (sd->w > sd->h);
142 input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
143 input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, wide ? sd->w : sd->h);
144 input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR, wide ? sd->h : sd->w);
145
146 input_event(input, EV_ABS, ABS_MT_PRESSURE, sd->z);
147
148 input_mt_sync(input);
149 sd->valid = false;
150
151 /* touchscreen emulation */
152 if (sd->first) {
153 if (!sd->activity) {
154 input_event(input, EV_KEY, BTN_TOUCH, 1);
155 sd->activity = true;
156 }
157 input_event(input, EV_ABS, ABS_X, sd->x);
158 input_event(input, EV_ABS, ABS_Y, sd->y);
159 }
160 sd->first = false;
161}
162
163
164static int stantum_event(struct hid_device *hid, struct hid_field *field,
165 struct hid_usage *usage, __s32 value)
166{
167 struct stantum_data *sd = hid_get_drvdata(hid);
168
169 if (hid->claimed & HID_CLAIMED_INPUT) {
170 struct input_dev *input = field->hidinput->input;
171
172 switch (usage->hid) {
173 case HID_DG_INRANGE:
174 /* this is the last field in a finger */
175 stantum_filter_event(sd, input);
176 break;
177 case HID_DG_WIDTH:
178 sd->w = value;
179 break;
180 case HID_DG_HEIGHT:
181 sd->h = value;
182 break;
183 case HID_GD_X:
184 sd->x = value;
185 break;
186 case HID_GD_Y:
187 sd->y = value;
188 break;
189 case HID_DG_TIPPRESSURE:
190 sd->z = value;
191 break;
192 case HID_DG_CONTACTID:
193 sd->id = value;
194 break;
195 case HID_DG_CONFIDENCE:
196 sd->valid = !!value;
197 break;
198 case 0xff000002:
199 /* this comes only before the first finger */
200 sd->first = true;
201 break;
202
203 default:
204 /* ignore the others */
205 return 1;
206 }
207 }
208
209 /* we have handled the hidinput part, now remains hiddev */
210 if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event)
211 hid->hiddev_hid_event(hid, field, usage, value);
212
213 return 1;
214}
215
216static int stantum_probe(struct hid_device *hdev,
217 const struct hid_device_id *id)
218{
219 int ret;
220 struct stantum_data *sd;
221
222 sd = kmalloc(sizeof(struct stantum_data), GFP_KERNEL);
223 if (!sd) {
224 dev_err(&hdev->dev, "cannot allocate Stantum data\n");
225 return -ENOMEM;
226 }
227 sd->valid = false;
228 sd->first = false;
229 sd->activity = false;
230 hid_set_drvdata(hdev, sd);
231
232 ret = hid_parse(hdev);
233 if (!ret)
234 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
235
236 if (ret)
237 kfree(sd);
238
239 return ret;
240}
241
242static void stantum_remove(struct hid_device *hdev)
243{
244 hid_hw_stop(hdev);
245 kfree(hid_get_drvdata(hdev));
246 hid_set_drvdata(hdev, NULL);
247}
248
249static const struct hid_device_id stantum_devices[] = {
250 { HID_USB_DEVICE(USB_VENDOR_ID_STANTUM, USB_DEVICE_ID_MTP) },
251 { }
252};
253MODULE_DEVICE_TABLE(hid, stantum_devices);
254
255static const struct hid_usage_id stantum_grabbed_usages[] = {
256 { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
257 { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1}
258};
259
260static struct hid_driver stantum_driver = {
261 .name = "stantum",
262 .id_table = stantum_devices,
263 .probe = stantum_probe,
264 .remove = stantum_remove,
265 .input_mapping = stantum_input_mapping,
266 .input_mapped = stantum_input_mapped,
267 .usage_table = stantum_grabbed_usages,
268 .event = stantum_event,
269};
270
271static int __init stantum_init(void)
272{
273 return hid_register_driver(&stantum_driver);
274}
275
276static void __exit stantum_exit(void)
277{
278 hid_unregister_driver(&stantum_driver);
279}
280
281module_init(stantum_init);
282module_exit(stantum_exit);
283
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c
index 12dcda529201..8d3b46f5d149 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -156,7 +156,9 @@ static int wacom_probe(struct hid_device *hdev,
156 struct hid_input *hidinput; 156 struct hid_input *hidinput;
157 struct input_dev *input; 157 struct input_dev *input;
158 struct wacom_data *wdata; 158 struct wacom_data *wdata;
159 char rep_data[2];
159 int ret; 160 int ret;
161 int limit;
160 162
161 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); 163 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
162 if (wdata == NULL) { 164 if (wdata == NULL) {
@@ -166,6 +168,7 @@ static int wacom_probe(struct hid_device *hdev,
166 168
167 hid_set_drvdata(hdev, wdata); 169 hid_set_drvdata(hdev, wdata);
168 170
171 /* Parse the HID report now */
169 ret = hid_parse(hdev); 172 ret = hid_parse(hdev);
170 if (ret) { 173 if (ret) {
171 dev_err(&hdev->dev, "parse failed\n"); 174 dev_err(&hdev->dev, "parse failed\n");
@@ -178,6 +181,31 @@ static int wacom_probe(struct hid_device *hdev,
178 goto err_free; 181 goto err_free;
179 } 182 }
180 183
184 /*
185 * Note that if the raw queries fail, it's not a hard failure and it
186 * is safe to continue
187 */
188
189 /* Set Wacom mode2 */
190 rep_data[0] = 0x03; rep_data[1] = 0x00;
191 limit = 3;
192 do {
193 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
194 HID_FEATURE_REPORT);
195 } while (ret < 0 && limit-- > 0);
196 if (ret < 0)
197 dev_warn(&hdev->dev, "failed to poke device #1, %d\n", ret);
198
199 /* 0x06 - high reporting speed, 0x05 - low speed */
200 rep_data[0] = 0x06; rep_data[1] = 0x00;
201 limit = 3;
202 do {
203 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
204 HID_FEATURE_REPORT);
205 } while (ret < 0 && limit-- > 0);
206 if (ret < 0)
207 dev_warn(&hdev->dev, "failed to poke device #2, %d\n", ret);
208
181 hidinput = list_entry(hdev->inputs.next, struct hid_input, list); 209 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
182 input = hidinput->input; 210 input = hidinput->input;
183 211
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index cdd136942bca..d04476700b7b 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -134,7 +134,7 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t
134 goto out; 134 goto out;
135 } 135 }
136 136
137 ret = dev->hid_output_raw_report(dev, buf, count); 137 ret = dev->hid_output_raw_report(dev, buf, count, HID_OUTPUT_REPORT);
138out: 138out:
139 kfree(buf); 139 kfree(buf);
140 return ret; 140 return ret;
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index e2997a8d5e1b..56d06cd8075b 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -5,7 +5,7 @@
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) 2007-2008 Oliver Neukum 7 * Copyright (c) 2007-2008 Oliver Neukum
8 * Copyright (c) 2006-2009 Jiri Kosina 8 * Copyright (c) 2006-2010 Jiri Kosina
9 */ 9 */
10 10
11/* 11/*
@@ -316,6 +316,7 @@ static int hid_submit_out(struct hid_device *hid)
316 err_hid("usb_submit_urb(out) failed"); 316 err_hid("usb_submit_urb(out) failed");
317 return -1; 317 return -1;
318 } 318 }
319 usbhid->last_out = jiffies;
319 } else { 320 } else {
320 /* 321 /*
321 * queue work to wake up the device. 322 * queue work to wake up the device.
@@ -377,6 +378,7 @@ static int hid_submit_ctrl(struct hid_device *hid)
377 err_hid("usb_submit_urb(ctrl) failed"); 378 err_hid("usb_submit_urb(ctrl) failed");
378 return -1; 379 return -1;
379 } 380 }
381 usbhid->last_ctrl = jiffies;
380 } else { 382 } else {
381 /* 383 /*
382 * queue work to wake up the device. 384 * queue work to wake up the device.
@@ -512,9 +514,20 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
512 usbhid->out[usbhid->outhead].report = report; 514 usbhid->out[usbhid->outhead].report = report;
513 usbhid->outhead = head; 515 usbhid->outhead = head;
514 516
515 if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl)) 517 if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl)) {
516 if (hid_submit_out(hid)) 518 if (hid_submit_out(hid))
517 clear_bit(HID_OUT_RUNNING, &usbhid->iofl); 519 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
520 } else {
521 /*
522 * the queue is known to run
523 * but an earlier request may be stuck
524 * we may need to time out
525 * no race because this is called under
526 * spinlock
527 */
528 if (time_after(jiffies, usbhid->last_out + HZ * 5))
529 usb_unlink_urb(usbhid->urbout);
530 }
518 return; 531 return;
519 } 532 }
520 533
@@ -535,9 +548,20 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
535 usbhid->ctrl[usbhid->ctrlhead].dir = dir; 548 usbhid->ctrl[usbhid->ctrlhead].dir = dir;
536 usbhid->ctrlhead = head; 549 usbhid->ctrlhead = head;
537 550
538 if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl)) 551 if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl)) {
539 if (hid_submit_ctrl(hid)) 552 if (hid_submit_ctrl(hid))
540 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl); 553 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
554 } else {
555 /*
556 * the queue is known to run
557 * but an earlier request may be stuck
558 * we may need to time out
559 * no race because this is called under
560 * spinlock
561 */
562 if (time_after(jiffies, usbhid->last_ctrl + HZ * 5))
563 usb_unlink_urb(usbhid->urbctrl);
564 }
541} 565}
542 566
543void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir) 567void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir)
@@ -774,7 +798,8 @@ static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
774 return 0; 798 return 0;
775} 799}
776 800
777static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count) 801static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count,
802 unsigned char report_type)
778{ 803{
779 struct usbhid_device *usbhid = hid->driver_data; 804 struct usbhid_device *usbhid = hid->driver_data;
780 struct usb_device *dev = hid_to_usb_dev(hid); 805 struct usb_device *dev = hid_to_usb_dev(hid);
@@ -785,7 +810,7 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co
785 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 810 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
786 HID_REQ_SET_REPORT, 811 HID_REQ_SET_REPORT,
787 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 812 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
788 ((HID_OUTPUT_REPORT + 1) << 8) | *buf, 813 ((report_type + 1) << 8) | *buf,
789 interface->desc.bInterfaceNumber, buf + 1, count - 1, 814 interface->desc.bInterfaceNumber, buf + 1, count - 1,
790 USB_CTRL_SET_TIMEOUT); 815 USB_CTRL_SET_TIMEOUT);
791 816
@@ -981,9 +1006,6 @@ static int usbhid_start(struct hid_device *hid)
981 1006
982 spin_lock_init(&usbhid->lock); 1007 spin_lock_init(&usbhid->lock);
983 1008
984 usbhid->intf = intf;
985 usbhid->ifnum = interface->desc.bInterfaceNumber;
986
987 usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); 1009 usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
988 if (!usbhid->urbctrl) { 1010 if (!usbhid->urbctrl) {
989 ret = -ENOMEM; 1011 ret = -ENOMEM;
@@ -1154,6 +1176,8 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *
1154 1176
1155 hid->driver_data = usbhid; 1177 hid->driver_data = usbhid;
1156 usbhid->hid = hid; 1178 usbhid->hid = hid;
1179 usbhid->intf = intf;
1180 usbhid->ifnum = interface->desc.bInterfaceNumber;
1157 1181
1158 ret = hid_add_device(hid); 1182 ret = hid_add_device(hid);
1159 if (ret) { 1183 if (ret) {
@@ -1342,7 +1366,7 @@ static int hid_reset_resume(struct usb_interface *intf)
1342 1366
1343#endif /* CONFIG_PM */ 1367#endif /* CONFIG_PM */
1344 1368
1345static struct usb_device_id hid_usb_ids [] = { 1369static const struct usb_device_id hid_usb_ids[] = {
1346 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, 1370 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
1347 .bInterfaceClass = USB_INTERFACE_CLASS_HID }, 1371 .bInterfaceClass = USB_INTERFACE_CLASS_HID },
1348 { } /* Terminating entry */ 1372 { } /* Terminating entry */
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 38773dc2821b..7844280897d1 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -43,8 +43,10 @@ static const struct hid_blacklist {
43 43
44 { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL }, 44 { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL },
45 45
46 { USB_VENDOR_ID_ETURBOTOUCH, USB_DEVICE_ID_ETURBOTOUCH, HID_QUIRK_MULTI_INPUT },
46 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, 47 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS },
47 { USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII, HID_QUIRK_MULTI_INPUT }, 48 { USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII, HID_QUIRK_MULTI_INPUT },
49 { USB_VENDOR_ID_TOUCHPACK, USB_DEVICE_ID_TOUCHPACK_RTS, HID_QUIRK_MULTI_INPUT },
48 50
49 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, 51 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET },
50 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, 52 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET },
@@ -57,6 +59,7 @@ static const struct hid_blacklist {
57 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_3AXIS_5BUTTON_STICK, HID_QUIRK_NOGET }, 59 { USB_VENDOR_ID_CH, USB_DEVICE_ID_CH_3AXIS_5BUTTON_STICK, HID_QUIRK_NOGET },
58 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, 60 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET },
59 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, 61 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
62 { USB_VENDOR_ID_PRODIGE, USB_DEVICE_ID_PRODIGE_CORDLESS, HID_QUIRK_NOGET },
60 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, 63 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
61 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 64 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
62 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209, HID_QUIRK_MULTI_INPUT }, 65 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209, HID_QUIRK_MULTI_INPUT },
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index 08f505ca2e3d..ec20400c7f29 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -80,12 +80,14 @@ struct usbhid_device {
80 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */ 80 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
81 char *ctrlbuf; /* Control buffer */ 81 char *ctrlbuf; /* Control buffer */
82 dma_addr_t ctrlbuf_dma; /* Control buffer dma */ 82 dma_addr_t ctrlbuf_dma; /* Control buffer dma */
83 unsigned long last_ctrl; /* record of last output for timeouts */
83 84
84 struct urb *urbout; /* Output URB */ 85 struct urb *urbout; /* Output URB */
85 struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */ 86 struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
86 unsigned char outhead, outtail; /* Output pipe fifo head & tail */ 87 unsigned char outhead, outtail; /* Output pipe fifo head & tail */
87 char *outbuf; /* Output buffer */ 88 char *outbuf; /* Output buffer */
88 dma_addr_t outbuf_dma; /* Output buffer dma */ 89 dma_addr_t outbuf_dma; /* Output buffer dma */
90 unsigned long last_out; /* record of last output for timeouts */
89 91
90 spinlock_t lock; /* fifo spinlock */ 92 spinlock_t lock; /* fifo spinlock */
91 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ 93 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
diff --git a/drivers/hwmon/ams/ams-core.c b/drivers/hwmon/ams/ams-core.c
index 6c9ace1b76f6..2ad62c339cd2 100644
--- a/drivers/hwmon/ams/ams-core.c
+++ b/drivers/hwmon/ams/ams-core.c
@@ -213,7 +213,7 @@ int __init ams_init(void)
213 return -ENODEV; 213 return -ENODEV;
214} 214}
215 215
216void ams_exit(void) 216void ams_sensor_detach(void)
217{ 217{
218 /* Remove input device */ 218 /* Remove input device */
219 ams_input_exit(); 219 ams_input_exit();
@@ -221,9 +221,6 @@ void ams_exit(void)
221 /* Remove attributes */ 221 /* Remove attributes */
222 device_remove_file(&ams_info.of_dev->dev, &dev_attr_current); 222 device_remove_file(&ams_info.of_dev->dev, &dev_attr_current);
223 223
224 /* Shut down implementation */
225 ams_info.exit();
226
227 /* Flush interrupt worker 224 /* Flush interrupt worker
228 * 225 *
229 * We do this after ams_info.exit(), because an interrupt might 226 * We do this after ams_info.exit(), because an interrupt might
@@ -239,6 +236,12 @@ void ams_exit(void)
239 pmf_unregister_irq_client(&ams_freefall_client); 236 pmf_unregister_irq_client(&ams_freefall_client);
240} 237}
241 238
239static void __exit ams_exit(void)
240{
241 /* Shut down implementation */
242 ams_info.exit();
243}
244
242MODULE_AUTHOR("Stelian Pop, Michael Hanselmann"); 245MODULE_AUTHOR("Stelian Pop, Michael Hanselmann");
243MODULE_DESCRIPTION("Apple Motion Sensor driver"); 246MODULE_DESCRIPTION("Apple Motion Sensor driver");
244MODULE_LICENSE("GPL"); 247MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/ams/ams-i2c.c b/drivers/hwmon/ams/ams-i2c.c
index 2cbf8a6506c7..abeecd27b484 100644
--- a/drivers/hwmon/ams/ams-i2c.c
+++ b/drivers/hwmon/ams/ams-i2c.c
@@ -238,6 +238,8 @@ static int ams_i2c_probe(struct i2c_client *client,
238static int ams_i2c_remove(struct i2c_client *client) 238static int ams_i2c_remove(struct i2c_client *client)
239{ 239{
240 if (ams_info.has_device) { 240 if (ams_info.has_device) {
241 ams_sensor_detach();
242
241 /* Disable interrupts */ 243 /* Disable interrupts */
242 ams_i2c_set_irq(AMS_IRQ_ALL, 0); 244 ams_i2c_set_irq(AMS_IRQ_ALL, 0);
243 245
diff --git a/drivers/hwmon/ams/ams-pmu.c b/drivers/hwmon/ams/ams-pmu.c
index fb18b3d3162b..4f61b3ee1b08 100644
--- a/drivers/hwmon/ams/ams-pmu.c
+++ b/drivers/hwmon/ams/ams-pmu.c
@@ -133,6 +133,8 @@ static void ams_pmu_get_xyz(s8 *x, s8 *y, s8 *z)
133 133
134static void ams_pmu_exit(void) 134static void ams_pmu_exit(void)
135{ 135{
136 ams_sensor_detach();
137
136 /* Disable interrupts */ 138 /* Disable interrupts */
137 ams_pmu_set_irq(AMS_IRQ_ALL, 0); 139 ams_pmu_set_irq(AMS_IRQ_ALL, 0);
138 140
diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h
index 5ed387b0bd9a..b28d7e27a031 100644
--- a/drivers/hwmon/ams/ams.h
+++ b/drivers/hwmon/ams/ams.h
@@ -61,6 +61,7 @@ extern struct ams ams_info;
61 61
62extern void ams_sensors(s8 *x, s8 *y, s8 *z); 62extern void ams_sensors(s8 *x, s8 *y, s8 *z);
63extern int ams_sensor_attach(void); 63extern int ams_sensor_attach(void);
64extern void ams_sensor_detach(void);
64 65
65extern int ams_pmu_init(struct device_node *np); 66extern int ams_pmu_init(struct device_node *np);
66extern int ams_i2c_init(struct device_node *np); 67extern int ams_i2c_init(struct device_node *np);
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 5f318ce29770..737f05200b1d 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -564,6 +564,16 @@ config I2C_VERSATILE
564 This driver can also be built as a module. If so, the module 564 This driver can also be built as a module. If so, the module
565 will be called i2c-versatile. 565 will be called i2c-versatile.
566 566
567config I2C_OCTEON
568 tristate "Cavium OCTEON I2C bus support"
569 depends on CPU_CAVIUM_OCTEON
570 help
571 Say yes if you want to support the I2C serial bus on Cavium
572 OCTEON SOC.
573
574 This driver can also be built as a module. If so, the module
575 will be called i2c-octeon.
576
567comment "External I2C/SMBus adapter drivers" 577comment "External I2C/SMBus adapter drivers"
568 578
569config I2C_PARPORT 579config I2C_PARPORT
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 302c551977bb..c2c4ea1908d8 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -54,6 +54,7 @@ obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o
54obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o 54obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o
55obj-$(CONFIG_I2C_STU300) += i2c-stu300.o 55obj-$(CONFIG_I2C_STU300) += i2c-stu300.o
56obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 56obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
57obj-$(CONFIG_I2C_OCTEON) += i2c-octeon.o
57 58
58# External I2C/SMBus adapter drivers 59# External I2C/SMBus adapter drivers
59obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 60obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
new file mode 100644
index 000000000000..60375504fa49
--- /dev/null
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -0,0 +1,651 @@
1/*
2 * (C) Copyright 2009-2010
3 * Nokia Siemens Networks, michael.lawnick.ext@nsn.com
4 *
5 * Portions Copyright (C) 2010 Cavium Networks, Inc.
6 *
7 * This is a driver for the i2c adapter in Cavium Networks' OCTEON processors.
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/sched.h>
17#include <linux/init.h>
18
19#include <linux/io.h>
20#include <linux/i2c.h>
21#include <linux/interrupt.h>
22#include <linux/delay.h>
23#include <linux/platform_device.h>
24
25#include <asm/octeon/octeon.h>
26
27#define DRV_NAME "i2c-octeon"
28
29/* The previous out-of-tree version was implicitly version 1.0. */
30#define DRV_VERSION "2.0"
31
32/* register offsets */
33#define SW_TWSI 0x00
34#define TWSI_INT 0x10
35
36/* Controller command patterns */
37#define SW_TWSI_V 0x8000000000000000ull
38#define SW_TWSI_EOP_TWSI_DATA 0x0C00000100000000ull
39#define SW_TWSI_EOP_TWSI_CTL 0x0C00000200000000ull
40#define SW_TWSI_EOP_TWSI_CLKCTL 0x0C00000300000000ull
41#define SW_TWSI_EOP_TWSI_STAT 0x0C00000300000000ull
42#define SW_TWSI_EOP_TWSI_RST 0x0C00000700000000ull
43#define SW_TWSI_OP_TWSI_CLK 0x0800000000000000ull
44#define SW_TWSI_R 0x0100000000000000ull
45
46/* Controller command and status bits */
47#define TWSI_CTL_CE 0x80
48#define TWSI_CTL_ENAB 0x40
49#define TWSI_CTL_STA 0x20
50#define TWSI_CTL_STP 0x10
51#define TWSI_CTL_IFLG 0x08
52#define TWSI_CTL_AAK 0x04
53
54/* Some status values */
55#define STAT_START 0x08
56#define STAT_RSTART 0x10
57#define STAT_TXADDR_ACK 0x18
58#define STAT_TXDATA_ACK 0x28
59#define STAT_RXADDR_ACK 0x40
60#define STAT_RXDATA_ACK 0x50
61#define STAT_IDLE 0xF8
62
63struct octeon_i2c {
64 wait_queue_head_t queue;
65 struct i2c_adapter adap;
66 int irq;
67 int twsi_freq;
68 int sys_freq;
69 resource_size_t twsi_phys;
70 void __iomem *twsi_base;
71 resource_size_t regsize;
72 struct device *dev;
73};
74
75/**
76 * octeon_i2c_write_sw - write an I2C core register.
77 * @i2c: The struct octeon_i2c.
78 * @eop_reg: Register selector.
79 * @data: Value to be written.
80 *
81 * The I2C core registers are accessed indirectly via the SW_TWSI CSR.
82 */
83static void octeon_i2c_write_sw(struct octeon_i2c *i2c,
84 u64 eop_reg,
85 u8 data)
86{
87 u64 tmp;
88
89 __raw_writeq(SW_TWSI_V | eop_reg | data, i2c->twsi_base + SW_TWSI);
90 do {
91 tmp = __raw_readq(i2c->twsi_base + SW_TWSI);
92 } while ((tmp & SW_TWSI_V) != 0);
93}
94
95/**
96 * octeon_i2c_read_sw - write an I2C core register.
97 * @i2c: The struct octeon_i2c.
98 * @eop_reg: Register selector.
99 *
100 * Returns the data.
101 *
102 * The I2C core registers are accessed indirectly via the SW_TWSI CSR.
103 */
104static u8 octeon_i2c_read_sw(struct octeon_i2c *i2c, u64 eop_reg)
105{
106 u64 tmp;
107
108 __raw_writeq(SW_TWSI_V | eop_reg | SW_TWSI_R, i2c->twsi_base + SW_TWSI);
109 do {
110 tmp = __raw_readq(i2c->twsi_base + SW_TWSI);
111 } while ((tmp & SW_TWSI_V) != 0);
112
113 return tmp & 0xFF;
114}
115
116/**
117 * octeon_i2c_write_int - write the TWSI_INT register
118 * @i2c: The struct octeon_i2c.
119 * @data: Value to be written.
120 */
121static void octeon_i2c_write_int(struct octeon_i2c *i2c, u64 data)
122{
123 u64 tmp;
124
125 __raw_writeq(data, i2c->twsi_base + TWSI_INT);
126 tmp = __raw_readq(i2c->twsi_base + TWSI_INT);
127}
128
129/**
130 * octeon_i2c_int_enable - enable the TS interrupt.
131 * @i2c: The struct octeon_i2c.
132 *
133 * The interrupt will be asserted when there is non-STAT_IDLE state in
134 * the SW_TWSI_EOP_TWSI_STAT register.
135 */
136static void octeon_i2c_int_enable(struct octeon_i2c *i2c)
137{
138 octeon_i2c_write_int(i2c, 0x40);
139}
140
141/**
142 * octeon_i2c_int_disable - disable the TS interrupt.
143 * @i2c: The struct octeon_i2c.
144 */
145static void octeon_i2c_int_disable(struct octeon_i2c *i2c)
146{
147 octeon_i2c_write_int(i2c, 0);
148}
149
150/**
151 * octeon_i2c_unblock - unblock the bus.
152 * @i2c: The struct octeon_i2c.
153 *
154 * If there was a reset while a device was driving 0 to bus,
155 * bus is blocked. We toggle it free manually by some clock
156 * cycles and send a stop.
157 */
158static void octeon_i2c_unblock(struct octeon_i2c *i2c)
159{
160 int i;
161
162 dev_dbg(i2c->dev, "%s\n", __func__);
163 for (i = 0; i < 9; i++) {
164 octeon_i2c_write_int(i2c, 0x0);
165 udelay(5);
166 octeon_i2c_write_int(i2c, 0x200);
167 udelay(5);
168 }
169 octeon_i2c_write_int(i2c, 0x300);
170 udelay(5);
171 octeon_i2c_write_int(i2c, 0x100);
172 udelay(5);
173 octeon_i2c_write_int(i2c, 0x0);
174}
175
176/**
177 * octeon_i2c_isr - the interrupt service routine.
178 * @int: The irq, unused.
179 * @dev_id: Our struct octeon_i2c.
180 */
181static irqreturn_t octeon_i2c_isr(int irq, void *dev_id)
182{
183 struct octeon_i2c *i2c = dev_id;
184
185 octeon_i2c_int_disable(i2c);
186 wake_up_interruptible(&i2c->queue);
187
188 return IRQ_HANDLED;
189}
190
191
192static int octeon_i2c_test_iflg(struct octeon_i2c *i2c)
193{
194 return (octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_CTL) & TWSI_CTL_IFLG) != 0;
195}
196
197/**
198 * octeon_i2c_wait - wait for the IFLG to be set.
199 * @i2c: The struct octeon_i2c.
200 *
201 * Returns 0 on success, otherwise a negative errno.
202 */
203static int octeon_i2c_wait(struct octeon_i2c *i2c)
204{
205 int result;
206
207 octeon_i2c_int_enable(i2c);
208
209 result = wait_event_interruptible_timeout(i2c->queue,
210 octeon_i2c_test_iflg(i2c),
211 i2c->adap.timeout);
212
213 octeon_i2c_int_disable(i2c);
214
215 if (result < 0) {
216 dev_dbg(i2c->dev, "%s: wait interrupted\n", __func__);
217 return result;
218 } else if (result == 0) {
219 dev_dbg(i2c->dev, "%s: timeout\n", __func__);
220 result = -ETIMEDOUT;
221 }
222
223 return 0;
224}
225
226/**
227 * octeon_i2c_start - send START to the bus.
228 * @i2c: The struct octeon_i2c.
229 *
230 * Returns 0 on success, otherwise a negative errno.
231 */
232static int octeon_i2c_start(struct octeon_i2c *i2c)
233{
234 u8 data;
235 int result;
236
237 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
238 TWSI_CTL_ENAB | TWSI_CTL_STA);
239
240 result = octeon_i2c_wait(i2c);
241 if (result) {
242 if (octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT) == STAT_IDLE) {
243 /*
244 * Controller refused to send start flag May
245 * be a client is holding SDA low - let's try
246 * to free it.
247 */
248 octeon_i2c_unblock(i2c);
249 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
250 TWSI_CTL_ENAB | TWSI_CTL_STA);
251
252 result = octeon_i2c_wait(i2c);
253 }
254 if (result)
255 return result;
256 }
257
258 data = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
259 if ((data != STAT_START) && (data != STAT_RSTART)) {
260 dev_err(i2c->dev, "%s: bad status (0x%x)\n", __func__, data);
261 return -EIO;
262 }
263
264 return 0;
265}
266
267/**
268 * octeon_i2c_stop - send STOP to the bus.
269 * @i2c: The struct octeon_i2c.
270 *
271 * Returns 0 on success, otherwise a negative errno.
272 */
273static int octeon_i2c_stop(struct octeon_i2c *i2c)
274{
275 u8 data;
276
277 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
278 TWSI_CTL_ENAB | TWSI_CTL_STP);
279
280 data = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
281
282 if (data != STAT_IDLE) {
283 dev_err(i2c->dev, "%s: bad status(0x%x)\n", __func__, data);
284 return -EIO;
285 }
286 return 0;
287}
288
289/**
290 * octeon_i2c_write - send data to the bus.
291 * @i2c: The struct octeon_i2c.
292 * @target: Target address.
293 * @data: Pointer to the data to be sent.
294 * @length: Length of the data.
295 *
296 * The address is sent over the bus, then the data.
297 *
298 * Returns 0 on success, otherwise a negative errno.
299 */
300static int octeon_i2c_write(struct octeon_i2c *i2c, int target,
301 const u8 *data, int length)
302{
303 int i, result;
304 u8 tmp;
305
306 result = octeon_i2c_start(i2c);
307 if (result)
308 return result;
309
310 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, target << 1);
311 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
312
313 result = octeon_i2c_wait(i2c);
314 if (result)
315 return result;
316
317 for (i = 0; i < length; i++) {
318 tmp = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
319 if ((tmp != STAT_TXADDR_ACK) && (tmp != STAT_TXDATA_ACK)) {
320 dev_err(i2c->dev,
321 "%s: bad status before write (0x%x)\n",
322 __func__, tmp);
323 return -EIO;
324 }
325
326 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, data[i]);
327 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
328
329 result = octeon_i2c_wait(i2c);
330 if (result)
331 return result;
332 }
333
334 return 0;
335}
336
337/**
338 * octeon_i2c_read - receive data from the bus.
339 * @i2c: The struct octeon_i2c.
340 * @target: Target address.
341 * @data: Pointer to the location to store the datae .
342 * @length: Length of the data.
343 *
344 * The address is sent over the bus, then the data is read.
345 *
346 * Returns 0 on success, otherwise a negative errno.
347 */
348static int octeon_i2c_read(struct octeon_i2c *i2c, int target,
349 u8 *data, int length)
350{
351 int i, result;
352 u8 tmp;
353
354 if (length < 1)
355 return -EINVAL;
356
357 result = octeon_i2c_start(i2c);
358 if (result)
359 return result;
360
361 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_DATA, (target<<1) | 1);
362 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
363
364 result = octeon_i2c_wait(i2c);
365 if (result)
366 return result;
367
368 for (i = 0; i < length; i++) {
369 tmp = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
370 if ((tmp != STAT_RXDATA_ACK) && (tmp != STAT_RXADDR_ACK)) {
371 dev_err(i2c->dev,
372 "%s: bad status before read (0x%x)\n",
373 __func__, tmp);
374 return -EIO;
375 }
376
377 if (i+1 < length)
378 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
379 TWSI_CTL_ENAB | TWSI_CTL_AAK);
380 else
381 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL,
382 TWSI_CTL_ENAB);
383
384 result = octeon_i2c_wait(i2c);
385 if (result)
386 return result;
387
388 data[i] = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_DATA);
389 }
390 return 0;
391}
392
393/**
394 * octeon_i2c_xfer - The driver's master_xfer function.
395 * @adap: Pointer to the i2c_adapter structure.
396 * @msgs: Pointer to the messages to be processed.
397 * @num: Length of the MSGS array.
398 *
399 * Returns the number of messages processed, or a negative errno on
400 * failure.
401 */
402static int octeon_i2c_xfer(struct i2c_adapter *adap,
403 struct i2c_msg *msgs,
404 int num)
405{
406 struct i2c_msg *pmsg;
407 int i;
408 int ret = 0;
409 struct octeon_i2c *i2c = i2c_get_adapdata(adap);
410
411 for (i = 0; ret == 0 && i < num; i++) {
412 pmsg = &msgs[i];
413 dev_dbg(i2c->dev,
414 "Doing %s %d byte(s) to/from 0x%02x - %d of %d messages\n",
415 pmsg->flags & I2C_M_RD ? "read" : "write",
416 pmsg->len, pmsg->addr, i + 1, num);
417 if (pmsg->flags & I2C_M_RD)
418 ret = octeon_i2c_read(i2c, pmsg->addr, pmsg->buf,
419 pmsg->len);
420 else
421 ret = octeon_i2c_write(i2c, pmsg->addr, pmsg->buf,
422 pmsg->len);
423 }
424 octeon_i2c_stop(i2c);
425
426 return (ret != 0) ? ret : num;
427}
428
429static u32 octeon_i2c_functionality(struct i2c_adapter *adap)
430{
431 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
432}
433
434static const struct i2c_algorithm octeon_i2c_algo = {
435 .master_xfer = octeon_i2c_xfer,
436 .functionality = octeon_i2c_functionality,
437};
438
439static struct i2c_adapter octeon_i2c_ops = {
440 .owner = THIS_MODULE,
441 .name = "OCTEON adapter",
442 .algo = &octeon_i2c_algo,
443 .timeout = 2,
444};
445
446/**
447 * octeon_i2c_setclock - Calculate and set clock divisors.
448 */
449static int __init octeon_i2c_setclock(struct octeon_i2c *i2c)
450{
451 int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff;
452 int thp = 0x18, mdiv = 2, ndiv = 0, delta_hz = 1000000;
453
454 for (ndiv_idx = 0; ndiv_idx < 8 && delta_hz != 0; ndiv_idx++) {
455 /*
456 * An mdiv value of less than 2 seems to not work well
457 * with ds1337 RTCs, so we constrain it to larger
458 * values.
459 */
460 for (mdiv_idx = 15; mdiv_idx >= 2 && delta_hz != 0; mdiv_idx--) {
461 /*
462 * For given ndiv and mdiv values check the
463 * two closest thp values.
464 */
465 tclk = i2c->twsi_freq * (mdiv_idx + 1) * 10;
466 tclk *= (1 << ndiv_idx);
467 thp_base = (i2c->sys_freq / (tclk * 2)) - 1;
468 for (inc = 0; inc <= 1; inc++) {
469 thp_idx = thp_base + inc;
470 if (thp_idx < 5 || thp_idx > 0xff)
471 continue;
472
473 foscl = i2c->sys_freq / (2 * (thp_idx + 1));
474 foscl = foscl / (1 << ndiv_idx);
475 foscl = foscl / (mdiv_idx + 1) / 10;
476 diff = abs(foscl - i2c->twsi_freq);
477 if (diff < delta_hz) {
478 delta_hz = diff;
479 thp = thp_idx;
480 mdiv = mdiv_idx;
481 ndiv = ndiv_idx;
482 }
483 }
484 }
485 }
486 octeon_i2c_write_sw(i2c, SW_TWSI_OP_TWSI_CLK, thp);
487 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CLKCTL, (mdiv << 3) | ndiv);
488
489 return 0;
490}
491
492static int __init octeon_i2c_initlowlevel(struct octeon_i2c *i2c)
493{
494 u8 status;
495 int tries;
496
497 /* disable high level controller, enable bus access */
498 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_CTL, TWSI_CTL_ENAB);
499
500 /* reset controller */
501 octeon_i2c_write_sw(i2c, SW_TWSI_EOP_TWSI_RST, 0);
502
503 for (tries = 10; tries; tries--) {
504 udelay(1);
505 status = octeon_i2c_read_sw(i2c, SW_TWSI_EOP_TWSI_STAT);
506 if (status == STAT_IDLE)
507 return 0;
508 }
509 dev_err(i2c->dev, "%s: TWSI_RST failed! (0x%x)\n", __func__, status);
510 return -EIO;
511}
512
513static int __devinit octeon_i2c_probe(struct platform_device *pdev)
514{
515 int irq, result = 0;
516 struct octeon_i2c *i2c;
517 struct octeon_i2c_data *i2c_data;
518 struct resource *res_mem;
519
520 /* All adaptors have an irq. */
521 irq = platform_get_irq(pdev, 0);
522 if (irq < 0)
523 return irq;
524
525 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
526 if (!i2c) {
527 dev_err(&pdev->dev, "kzalloc failed\n");
528 result = -ENOMEM;
529 goto out;
530 }
531 i2c->dev = &pdev->dev;
532 i2c_data = pdev->dev.platform_data;
533
534 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
535
536 if (res_mem == NULL) {
537 dev_err(i2c->dev, "found no memory resource\n");
538 result = -ENXIO;
539 goto fail_region;
540 }
541
542 if (i2c_data == NULL) {
543 dev_err(i2c->dev, "no I2C frequency data\n");
544 result = -ENXIO;
545 goto fail_region;
546 }
547
548 i2c->twsi_phys = res_mem->start;
549 i2c->regsize = resource_size(res_mem);
550 i2c->twsi_freq = i2c_data->i2c_freq;
551 i2c->sys_freq = i2c_data->sys_freq;
552
553 if (!request_mem_region(i2c->twsi_phys, i2c->regsize, res_mem->name)) {
554 dev_err(i2c->dev, "request_mem_region failed\n");
555 goto fail_region;
556 }
557 i2c->twsi_base = ioremap(i2c->twsi_phys, i2c->regsize);
558
559 init_waitqueue_head(&i2c->queue);
560
561 i2c->irq = irq;
562
563 result = request_irq(i2c->irq, octeon_i2c_isr, 0, DRV_NAME, i2c);
564 if (result < 0) {
565 dev_err(i2c->dev, "failed to attach interrupt\n");
566 goto fail_irq;
567 }
568
569 result = octeon_i2c_initlowlevel(i2c);
570 if (result) {
571 dev_err(i2c->dev, "init low level failed\n");
572 goto fail_add;
573 }
574
575 result = octeon_i2c_setclock(i2c);
576 if (result) {
577 dev_err(i2c->dev, "clock init failed\n");
578 goto fail_add;
579 }
580
581 i2c->adap = octeon_i2c_ops;
582 i2c->adap.dev.parent = &pdev->dev;
583 i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0;
584 i2c_set_adapdata(&i2c->adap, i2c);
585 platform_set_drvdata(pdev, i2c);
586
587 result = i2c_add_numbered_adapter(&i2c->adap);
588 if (result < 0) {
589 dev_err(i2c->dev, "failed to add adapter\n");
590 goto fail_add;
591 }
592
593 dev_info(i2c->dev, "version %s\n", DRV_VERSION);
594
595 return result;
596
597fail_add:
598 platform_set_drvdata(pdev, NULL);
599 free_irq(i2c->irq, i2c);
600fail_irq:
601 iounmap(i2c->twsi_base);
602 release_mem_region(i2c->twsi_phys, i2c->regsize);
603fail_region:
604 kfree(i2c);
605out:
606 return result;
607};
608
609static int __devexit octeon_i2c_remove(struct platform_device *pdev)
610{
611 struct octeon_i2c *i2c = platform_get_drvdata(pdev);
612
613 i2c_del_adapter(&i2c->adap);
614 platform_set_drvdata(pdev, NULL);
615 free_irq(i2c->irq, i2c);
616 iounmap(i2c->twsi_base);
617 release_mem_region(i2c->twsi_phys, i2c->regsize);
618 kfree(i2c);
619 return 0;
620};
621
622static struct platform_driver octeon_i2c_driver = {
623 .probe = octeon_i2c_probe,
624 .remove = __devexit_p(octeon_i2c_remove),
625 .driver = {
626 .owner = THIS_MODULE,
627 .name = DRV_NAME,
628 },
629};
630
631static int __init octeon_i2c_init(void)
632{
633 int rv;
634
635 rv = platform_driver_register(&octeon_i2c_driver);
636 return rv;
637}
638
639static void __exit octeon_i2c_exit(void)
640{
641 platform_driver_unregister(&octeon_i2c_driver);
642}
643
644MODULE_AUTHOR("Michael Lawnick <michael.lawnick.ext@nsn.com>");
645MODULE_DESCRIPTION("I2C-Bus adapter for Cavium OCTEON processors");
646MODULE_LICENSE("GPL");
647MODULE_VERSION(DRV_VERSION);
648MODULE_ALIAS("platform:" DRV_NAME);
649
650module_init(octeon_i2c_init);
651module_exit(octeon_i2c_exit);
diff --git a/drivers/ide/au1xxx-ide.c b/drivers/ide/au1xxx-ide.c
index 87cef0c440ad..349a67bf1a36 100644
--- a/drivers/ide/au1xxx-ide.c
+++ b/drivers/ide/au1xxx-ide.c
@@ -56,8 +56,8 @@ static inline void auide_insw(unsigned long port, void *addr, u32 count)
56 chan_tab_t *ctp; 56 chan_tab_t *ctp;
57 au1x_ddma_desc_t *dp; 57 au1x_ddma_desc_t *dp;
58 58
59 if(!put_dest_flags(ahwif->rx_chan, (void*)addr, count << 1, 59 if (!au1xxx_dbdma_put_dest(ahwif->rx_chan, virt_to_phys(addr),
60 DDMA_FLAGS_NOIE)) { 60 count << 1, DDMA_FLAGS_NOIE)) {
61 printk(KERN_ERR "%s failed %d\n", __func__, __LINE__); 61 printk(KERN_ERR "%s failed %d\n", __func__, __LINE__);
62 return; 62 return;
63 } 63 }
@@ -74,8 +74,8 @@ static inline void auide_outsw(unsigned long port, void *addr, u32 count)
74 chan_tab_t *ctp; 74 chan_tab_t *ctp;
75 au1x_ddma_desc_t *dp; 75 au1x_ddma_desc_t *dp;
76 76
77 if(!put_source_flags(ahwif->tx_chan, (void*)addr, 77 if (!au1xxx_dbdma_put_source(ahwif->tx_chan, virt_to_phys(addr),
78 count << 1, DDMA_FLAGS_NOIE)) { 78 count << 1, DDMA_FLAGS_NOIE)) {
79 printk(KERN_ERR "%s failed %d\n", __func__, __LINE__); 79 printk(KERN_ERR "%s failed %d\n", __func__, __LINE__);
80 return; 80 return;
81 } 81 }
@@ -246,17 +246,14 @@ static int auide_build_dmatable(ide_drive_t *drive, struct ide_cmd *cmd)
246 flags = DDMA_FLAGS_NOIE; 246 flags = DDMA_FLAGS_NOIE;
247 247
248 if (iswrite) { 248 if (iswrite) {
249 if(!put_source_flags(ahwif->tx_chan, 249 if (!au1xxx_dbdma_put_source(ahwif->tx_chan,
250 (void*) sg_virt(sg), 250 sg_phys(sg), tc, flags)) {
251 tc, flags)) {
252 printk(KERN_ERR "%s failed %d\n", 251 printk(KERN_ERR "%s failed %d\n",
253 __func__, __LINE__); 252 __func__, __LINE__);
254 } 253 }
255 } else 254 } else {
256 { 255 if (!au1xxx_dbdma_put_dest(ahwif->rx_chan,
257 if(!put_dest_flags(ahwif->rx_chan, 256 sg_phys(sg), tc, flags)) {
258 (void*) sg_virt(sg),
259 tc, flags)) {
260 printk(KERN_ERR "%s failed %d\n", 257 printk(KERN_ERR "%s failed %d\n",
261 __func__, __LINE__); 258 __func__, __LINE__);
262 } 259 }
diff --git a/drivers/input/input-polldev.c b/drivers/input/input-polldev.c
index aa6713b4a988..291d9393d359 100644
--- a/drivers/input/input-polldev.c
+++ b/drivers/input/input-polldev.c
@@ -100,6 +100,12 @@ static void input_close_polled_device(struct input_dev *input)
100 struct input_polled_dev *dev = input_get_drvdata(input); 100 struct input_polled_dev *dev = input_get_drvdata(input);
101 101
102 cancel_delayed_work_sync(&dev->work); 102 cancel_delayed_work_sync(&dev->work);
103 /*
104 * Clean up work struct to remove references to the workqueue.
105 * It may be destroyed by the next call. This causes problems
106 * at next device open-close in case of poll_interval == 0.
107 */
108 INIT_DELAYED_WORK(&dev->work, dev->work.work.func);
103 input_polldev_stop_workqueue(); 109 input_polldev_stop_workqueue();
104 110
105 if (dev->close) 111 if (dev->close)
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index d84a36e545f6..b54aee7cd9e3 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -1161,9 +1161,17 @@ static int i8042_pm_restore(struct device *dev)
1161 return 0; 1161 return 0;
1162} 1162}
1163 1163
1164static int i8042_pm_thaw(struct device *dev)
1165{
1166 i8042_interrupt(0, NULL);
1167
1168 return 0;
1169}
1170
1164static const struct dev_pm_ops i8042_pm_ops = { 1171static const struct dev_pm_ops i8042_pm_ops = {
1165 .suspend = i8042_pm_reset, 1172 .suspend = i8042_pm_reset,
1166 .resume = i8042_pm_restore, 1173 .resume = i8042_pm_restore,
1174 .thaw = i8042_pm_thaw,
1167 .poweroff = i8042_pm_reset, 1175 .poweroff = i8042_pm_reset,
1168 .restore = i8042_pm_restore, 1176 .restore = i8042_pm_restore,
1169}; 1177};
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 09a5e7341bd5..5256123a5228 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -618,8 +618,8 @@ static int idealtek_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
618#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH 618#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
619static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt) 619static int general_touch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
620{ 620{
621 dev->x = ((pkt[2] & 0x0F) << 8) | pkt[1] ; 621 dev->x = (pkt[2] << 8) | pkt[1];
622 dev->y = ((pkt[4] & 0x0F) << 8) | pkt[3] ; 622 dev->y = (pkt[4] << 8) | pkt[3];
623 dev->press = pkt[5] & 0xff; 623 dev->press = pkt[5] & 0xff;
624 dev->touch = pkt[0] & 0x01; 624 dev->touch = pkt[0] & 0x01;
625 625
@@ -809,9 +809,9 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
809#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH 809#ifdef CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH
810 [DEVTYPE_GENERAL_TOUCH] = { 810 [DEVTYPE_GENERAL_TOUCH] = {
811 .min_xc = 0x0, 811 .min_xc = 0x0,
812 .max_xc = 0x0500, 812 .max_xc = 0x7fff,
813 .min_yc = 0x0, 813 .min_yc = 0x0,
814 .max_yc = 0x0500, 814 .max_yc = 0x7fff,
815 .rept_size = 7, 815 .rept_size = 7,
816 .read_data = general_touch_read_data, 816 .read_data = general_touch_read_data,
817 }, 817 },
diff --git a/drivers/isdn/hisax/Kconfig b/drivers/isdn/hisax/Kconfig
index 3464ebc4cdbc..452fde9edf86 100644
--- a/drivers/isdn/hisax/Kconfig
+++ b/drivers/isdn/hisax/Kconfig
@@ -109,7 +109,7 @@ config HISAX_16_3
109 109
110config HISAX_TELESPCI 110config HISAX_TELESPCI
111 bool "Teles PCI" 111 bool "Teles PCI"
112 depends on PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) 112 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
113 help 113 help
114 This enables HiSax support for the Teles PCI. 114 This enables HiSax support for the Teles PCI.
115 See <file:Documentation/isdn/README.HiSax> on how to configure it. 115 See <file:Documentation/isdn/README.HiSax> on how to configure it.
@@ -237,7 +237,7 @@ config HISAX_MIC
237 237
238config HISAX_NETJET 238config HISAX_NETJET
239 bool "NETjet card" 239 bool "NETjet card"
240 depends on PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) 240 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
241 help 241 help
242 This enables HiSax support for the NetJet from Traverse 242 This enables HiSax support for the NetJet from Traverse
243 Technologies. 243 Technologies.
@@ -248,7 +248,7 @@ config HISAX_NETJET
248 248
249config HISAX_NETJET_U 249config HISAX_NETJET_U
250 bool "NETspider U card" 250 bool "NETspider U card"
251 depends on PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) 251 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
252 help 252 help
253 This enables HiSax support for the Netspider U interface ISDN card 253 This enables HiSax support for the Netspider U interface ISDN card
254 from Traverse Technologies. 254 from Traverse Technologies.
@@ -287,7 +287,7 @@ config HISAX_HSTSAPHIR
287 287
288config HISAX_BKM_A4T 288config HISAX_BKM_A4T
289 bool "Telekom A4T card" 289 bool "Telekom A4T card"
290 depends on PCI && PCI_LEGACY 290 depends on PCI
291 help 291 help
292 This enables HiSax support for the Telekom A4T card. 292 This enables HiSax support for the Telekom A4T card.
293 293
@@ -297,7 +297,7 @@ config HISAX_BKM_A4T
297 297
298config HISAX_SCT_QUADRO 298config HISAX_SCT_QUADRO
299 bool "Scitel Quadro card" 299 bool "Scitel Quadro card"
300 depends on PCI && PCI_LEGACY 300 depends on PCI
301 help 301 help
302 This enables HiSax support for the Scitel Quadro card. 302 This enables HiSax support for the Scitel Quadro card.
303 303
@@ -316,7 +316,7 @@ config HISAX_GAZEL
316 316
317config HISAX_HFC_PCI 317config HISAX_HFC_PCI
318 bool "HFC PCI-Bus cards" 318 bool "HFC PCI-Bus cards"
319 depends on PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) 319 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
320 help 320 help
321 This enables HiSax support for the HFC-S PCI 2BDS0 based cards. 321 This enables HiSax support for the HFC-S PCI 2BDS0 based cards.
322 322
@@ -325,7 +325,7 @@ config HISAX_HFC_PCI
325 325
326config HISAX_W6692 326config HISAX_W6692
327 bool "Winbond W6692 based cards" 327 bool "Winbond W6692 based cards"
328 depends on PCI && PCI_LEGACY 328 depends on PCI
329 help 329 help
330 This enables HiSax support for Winbond W6692 based PCI ISDN cards. 330 This enables HiSax support for Winbond W6692 based PCI ISDN cards.
331 331
@@ -341,7 +341,7 @@ config HISAX_HFC_SX
341 341
342config HISAX_ENTERNOW_PCI 342config HISAX_ENTERNOW_PCI
343 bool "Formula-n enter:now PCI card" 343 bool "Formula-n enter:now PCI card"
344 depends on HISAX_NETJET && PCI && PCI_LEGACY && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) 344 depends on HISAX_NETJET && PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
345 help 345 help
346 This enables HiSax support for the Formula-n enter:now PCI 346 This enables HiSax support for the Formula-n enter:now PCI
347 ISDN card. 347 ISDN card.
@@ -412,7 +412,7 @@ config HISAX_HFC4S8S
412 412
413config HISAX_FRITZ_PCIPNP 413config HISAX_FRITZ_PCIPNP
414 tristate "AVM Fritz!Card PCI/PCIv2/PnP support (EXPERIMENTAL)" 414 tristate "AVM Fritz!Card PCI/PCIv2/PnP support (EXPERIMENTAL)"
415 depends on PCI && PCI_LEGACY && EXPERIMENTAL 415 depends on PCI && EXPERIMENTAL
416 help 416 help
417 This enables the driver for the AVM Fritz!Card PCI, 417 This enables the driver for the AVM Fritz!Card PCI,
418 Fritz!Card PCI v2 and Fritz!Card PnP. 418 Fritz!Card PCI v2 and Fritz!Card PnP.
diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
index 7cabc5a19492..14295a155e71 100644
--- a/drivers/isdn/hisax/avm_pci.c
+++ b/drivers/isdn/hisax/avm_pci.c
@@ -822,7 +822,7 @@ static int __devinit avm_pnp_setup(struct IsdnCardState *cs)
822 822
823#endif /* __ISAPNP__ */ 823#endif /* __ISAPNP__ */
824 824
825#ifndef CONFIG_PCI_LEGACY 825#ifndef CONFIG_PCI
826 826
827static int __devinit avm_pci_setup(struct IsdnCardState *cs) 827static int __devinit avm_pci_setup(struct IsdnCardState *cs)
828{ 828{
@@ -835,7 +835,7 @@ static struct pci_dev *dev_avm __devinitdata = NULL;
835 835
836static int __devinit avm_pci_setup(struct IsdnCardState *cs) 836static int __devinit avm_pci_setup(struct IsdnCardState *cs)
837{ 837{
838 if ((dev_avm = pci_find_device(PCI_VENDOR_ID_AVM, 838 if ((dev_avm = hisax_find_pci_device(PCI_VENDOR_ID_AVM,
839 PCI_DEVICE_ID_AVM_A1, dev_avm))) { 839 PCI_DEVICE_ID_AVM_A1, dev_avm))) {
840 840
841 if (pci_enable_device(dev_avm)) 841 if (pci_enable_device(dev_avm))
@@ -864,7 +864,7 @@ static int __devinit avm_pci_setup(struct IsdnCardState *cs)
864 return (1); 864 return (1);
865} 865}
866 866
867#endif /* CONFIG_PCI_LEGACY */ 867#endif /* CONFIG_PCI */
868 868
869int __devinit 869int __devinit
870setup_avm_pcipnp(struct IsdnCard *card) 870setup_avm_pcipnp(struct IsdnCard *card)
diff --git a/drivers/isdn/hisax/bkm_a4t.c b/drivers/isdn/hisax/bkm_a4t.c
index 9ca2ee54cc94..9f2009c0b69c 100644
--- a/drivers/isdn/hisax/bkm_a4t.c
+++ b/drivers/isdn/hisax/bkm_a4t.c
@@ -340,7 +340,7 @@ setup_bkm_a4t(struct IsdnCard *card)
340 } else 340 } else
341 return (0); 341 return (0);
342 342
343 while ((dev_a4t = pci_find_device(PCI_VENDOR_ID_ZORAN, 343 while ((dev_a4t = hisax_find_pci_device(PCI_VENDOR_ID_ZORAN,
344 PCI_DEVICE_ID_ZORAN_36120, dev_a4t))) { 344 PCI_DEVICE_ID_ZORAN_36120, dev_a4t))) {
345 ret = a4t_pci_probe(dev_a4t, cs, &found, &pci_memaddr); 345 ret = a4t_pci_probe(dev_a4t, cs, &found, &pci_memaddr);
346 if (!ret) 346 if (!ret)
diff --git a/drivers/isdn/hisax/bkm_a8.c b/drivers/isdn/hisax/bkm_a8.c
index e1ff4717a8a6..e775706c60e3 100644
--- a/drivers/isdn/hisax/bkm_a8.c
+++ b/drivers/isdn/hisax/bkm_a8.c
@@ -301,7 +301,7 @@ setup_sct_quadro(struct IsdnCard *card)
301 (sub_vendor_id != PCI_VENDOR_ID_BERKOM))) 301 (sub_vendor_id != PCI_VENDOR_ID_BERKOM)))
302 return (0); 302 return (0);
303 if (cs->subtyp == SCT_1) { 303 if (cs->subtyp == SCT_1) {
304 while ((dev_a8 = pci_find_device(PCI_VENDOR_ID_PLX, 304 while ((dev_a8 = hisax_find_pci_device(PCI_VENDOR_ID_PLX,
305 PCI_DEVICE_ID_PLX_9050, dev_a8))) { 305 PCI_DEVICE_ID_PLX_9050, dev_a8))) {
306 306
307 sub_vendor_id = dev_a8->subsystem_vendor; 307 sub_vendor_id = dev_a8->subsystem_vendor;
diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
index 0b0c2e5d806b..780da9bda915 100644
--- a/drivers/isdn/hisax/diva.c
+++ b/drivers/isdn/hisax/diva.c
@@ -1148,7 +1148,7 @@ static int __devinit setup_diva_isapnp(struct IsdnCard *card)
1148 1148
1149#endif /* ISAPNP */ 1149#endif /* ISAPNP */
1150 1150
1151#ifdef CONFIG_PCI_LEGACY 1151#ifdef CONFIG_PCI
1152static struct pci_dev *dev_diva __devinitdata = NULL; 1152static struct pci_dev *dev_diva __devinitdata = NULL;
1153static struct pci_dev *dev_diva_u __devinitdata = NULL; 1153static struct pci_dev *dev_diva_u __devinitdata = NULL;
1154static struct pci_dev *dev_diva201 __devinitdata = NULL; 1154static struct pci_dev *dev_diva201 __devinitdata = NULL;
@@ -1159,21 +1159,21 @@ static int __devinit setup_diva_pci(struct IsdnCard *card)
1159 struct IsdnCardState *cs = card->cs; 1159 struct IsdnCardState *cs = card->cs;
1160 1160
1161 cs->subtyp = 0; 1161 cs->subtyp = 0;
1162 if ((dev_diva = pci_find_device(PCI_VENDOR_ID_EICON, 1162 if ((dev_diva = hisax_find_pci_device(PCI_VENDOR_ID_EICON,
1163 PCI_DEVICE_ID_EICON_DIVA20, dev_diva))) { 1163 PCI_DEVICE_ID_EICON_DIVA20, dev_diva))) {
1164 if (pci_enable_device(dev_diva)) 1164 if (pci_enable_device(dev_diva))
1165 return(0); 1165 return(0);
1166 cs->subtyp = DIVA_PCI; 1166 cs->subtyp = DIVA_PCI;
1167 cs->irq = dev_diva->irq; 1167 cs->irq = dev_diva->irq;
1168 cs->hw.diva.cfg_reg = pci_resource_start(dev_diva, 2); 1168 cs->hw.diva.cfg_reg = pci_resource_start(dev_diva, 2);
1169 } else if ((dev_diva_u = pci_find_device(PCI_VENDOR_ID_EICON, 1169 } else if ((dev_diva_u = hisax_find_pci_device(PCI_VENDOR_ID_EICON,
1170 PCI_DEVICE_ID_EICON_DIVA20_U, dev_diva_u))) { 1170 PCI_DEVICE_ID_EICON_DIVA20_U, dev_diva_u))) {
1171 if (pci_enable_device(dev_diva_u)) 1171 if (pci_enable_device(dev_diva_u))
1172 return(0); 1172 return(0);
1173 cs->subtyp = DIVA_PCI; 1173 cs->subtyp = DIVA_PCI;
1174 cs->irq = dev_diva_u->irq; 1174 cs->irq = dev_diva_u->irq;
1175 cs->hw.diva.cfg_reg = pci_resource_start(dev_diva_u, 2); 1175 cs->hw.diva.cfg_reg = pci_resource_start(dev_diva_u, 2);
1176 } else if ((dev_diva201 = pci_find_device(PCI_VENDOR_ID_EICON, 1176 } else if ((dev_diva201 = hisax_find_pci_device(PCI_VENDOR_ID_EICON,
1177 PCI_DEVICE_ID_EICON_DIVA201, dev_diva201))) { 1177 PCI_DEVICE_ID_EICON_DIVA201, dev_diva201))) {
1178 if (pci_enable_device(dev_diva201)) 1178 if (pci_enable_device(dev_diva201))
1179 return(0); 1179 return(0);
@@ -1183,7 +1183,7 @@ static int __devinit setup_diva_pci(struct IsdnCard *card)
1183 (ulong) ioremap(pci_resource_start(dev_diva201, 0), 4096); 1183 (ulong) ioremap(pci_resource_start(dev_diva201, 0), 4096);
1184 cs->hw.diva.cfg_reg = 1184 cs->hw.diva.cfg_reg =
1185 (ulong) ioremap(pci_resource_start(dev_diva201, 1), 4096); 1185 (ulong) ioremap(pci_resource_start(dev_diva201, 1), 4096);
1186 } else if ((dev_diva202 = pci_find_device(PCI_VENDOR_ID_EICON, 1186 } else if ((dev_diva202 = hisax_find_pci_device(PCI_VENDOR_ID_EICON,
1187 PCI_DEVICE_ID_EICON_DIVA202, dev_diva202))) { 1187 PCI_DEVICE_ID_EICON_DIVA202, dev_diva202))) {
1188 if (pci_enable_device(dev_diva202)) 1188 if (pci_enable_device(dev_diva202))
1189 return(0); 1189 return(0);
@@ -1229,14 +1229,14 @@ static int __devinit setup_diva_pci(struct IsdnCard *card)
1229 return (1); /* card found */ 1229 return (1); /* card found */
1230} 1230}
1231 1231
1232#else /* if !CONFIG_PCI_LEGACY */ 1232#else /* if !CONFIG_PCI */
1233 1233
1234static int __devinit setup_diva_pci(struct IsdnCard *card) 1234static int __devinit setup_diva_pci(struct IsdnCard *card)
1235{ 1235{
1236 return (-1); /* card not found; continue search */ 1236 return (-1); /* card not found; continue search */
1237} 1237}
1238 1238
1239#endif /* CONFIG_PCI_LEGACY */ 1239#endif /* CONFIG_PCI */
1240 1240
1241int __devinit 1241int __devinit
1242setup_diva(struct IsdnCard *card) 1242setup_diva(struct IsdnCard *card)
diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
index aa29d1cf16af..23c41fcd864e 100644
--- a/drivers/isdn/hisax/elsa.c
+++ b/drivers/isdn/hisax/elsa.c
@@ -1025,7 +1025,7 @@ setup_elsa_pcmcia(struct IsdnCard *card)
1025 cs->irq); 1025 cs->irq);
1026} 1026}
1027 1027
1028#ifdef CONFIG_PCI_LEGACY 1028#ifdef CONFIG_PCI
1029static struct pci_dev *dev_qs1000 __devinitdata = NULL; 1029static struct pci_dev *dev_qs1000 __devinitdata = NULL;
1030static struct pci_dev *dev_qs3000 __devinitdata = NULL; 1030static struct pci_dev *dev_qs3000 __devinitdata = NULL;
1031 1031
@@ -1035,7 +1035,7 @@ setup_elsa_pci(struct IsdnCard *card)
1035 struct IsdnCardState *cs = card->cs; 1035 struct IsdnCardState *cs = card->cs;
1036 1036
1037 cs->subtyp = 0; 1037 cs->subtyp = 0;
1038 if ((dev_qs1000 = pci_find_device(PCI_VENDOR_ID_ELSA, 1038 if ((dev_qs1000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA,
1039 PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) { 1039 PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
1040 if (pci_enable_device(dev_qs1000)) 1040 if (pci_enable_device(dev_qs1000))
1041 return(0); 1041 return(0);
@@ -1043,7 +1043,7 @@ setup_elsa_pci(struct IsdnCard *card)
1043 cs->irq = dev_qs1000->irq; 1043 cs->irq = dev_qs1000->irq;
1044 cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1); 1044 cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1);
1045 cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3); 1045 cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3);
1046 } else if ((dev_qs3000 = pci_find_device(PCI_VENDOR_ID_ELSA, 1046 } else if ((dev_qs3000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA,
1047 PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) { 1047 PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
1048 if (pci_enable_device(dev_qs3000)) 1048 if (pci_enable_device(dev_qs3000))
1049 return(0); 1049 return(0);
@@ -1093,7 +1093,7 @@ setup_elsa_pci(struct IsdnCard *card)
1093{ 1093{
1094 return (1); 1094 return (1);
1095} 1095}
1096#endif /* CONFIG_PCI_LEGACY */ 1096#endif /* CONFIG_PCI */
1097 1097
1098static int __devinit 1098static int __devinit
1099setup_elsa_common(struct IsdnCard *card) 1099setup_elsa_common(struct IsdnCard *card)
diff --git a/drivers/isdn/hisax/enternow_pci.c b/drivers/isdn/hisax/enternow_pci.c
index 39f421ed8de8..26264abf1f58 100644
--- a/drivers/isdn/hisax/enternow_pci.c
+++ b/drivers/isdn/hisax/enternow_pci.c
@@ -406,7 +406,7 @@ setup_enternow_pci(struct IsdnCard *card)
406 406
407 for ( ;; ) 407 for ( ;; )
408 { 408 {
409 if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET, 409 if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET,
410 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) { 410 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
411 ret = en_pci_probe(dev_netjet, cs); 411 ret = en_pci_probe(dev_netjet, cs);
412 if (!ret) 412 if (!ret)
diff --git a/drivers/isdn/hisax/gazel.c b/drivers/isdn/hisax/gazel.c
index 0ea3b4607680..353982fc1436 100644
--- a/drivers/isdn/hisax/gazel.c
+++ b/drivers/isdn/hisax/gazel.c
@@ -531,7 +531,7 @@ setup_gazelisa(struct IsdnCard *card, struct IsdnCardState *cs)
531 return (0); 531 return (0);
532} 532}
533 533
534#ifdef CONFIG_PCI_LEGACY 534#ifdef CONFIG_PCI
535static struct pci_dev *dev_tel __devinitdata = NULL; 535static struct pci_dev *dev_tel __devinitdata = NULL;
536 536
537static int __devinit 537static int __devinit
@@ -546,7 +546,7 @@ setup_gazelpci(struct IsdnCardState *cs)
546 found = 0; 546 found = 0;
547 seekcard = PCI_DEVICE_ID_PLX_R685; 547 seekcard = PCI_DEVICE_ID_PLX_R685;
548 for (nbseek = 0; nbseek < 4; nbseek++) { 548 for (nbseek = 0; nbseek < 4; nbseek++) {
549 if ((dev_tel = pci_find_device(PCI_VENDOR_ID_PLX, 549 if ((dev_tel = hisax_find_pci_device(PCI_VENDOR_ID_PLX,
550 seekcard, dev_tel))) { 550 seekcard, dev_tel))) {
551 if (pci_enable_device(dev_tel)) 551 if (pci_enable_device(dev_tel))
552 return 1; 552 return 1;
@@ -620,7 +620,7 @@ setup_gazelpci(struct IsdnCardState *cs)
620 620
621 return (0); 621 return (0);
622} 622}
623#endif /* CONFIG_PCI_LEGACY */ 623#endif /* CONFIG_PCI */
624 624
625int __devinit 625int __devinit
626setup_gazel(struct IsdnCard *card) 626setup_gazel(struct IsdnCard *card)
@@ -640,7 +640,7 @@ setup_gazel(struct IsdnCard *card)
640 return (0); 640 return (0);
641 } else { 641 } else {
642 642
643#ifdef CONFIG_PCI_LEGACY 643#ifdef CONFIG_PCI
644 if (setup_gazelpci(cs)) 644 if (setup_gazelpci(cs))
645 return (0); 645 return (0);
646#else 646#else
diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
index 10914731b304..917cc84065bd 100644
--- a/drivers/isdn/hisax/hfc_pci.c
+++ b/drivers/isdn/hisax/hfc_pci.c
@@ -1658,7 +1658,7 @@ setup_hfcpci(struct IsdnCard *card)
1658 1658
1659 i = 0; 1659 i = 0;
1660 while (id_list[i].vendor_id) { 1660 while (id_list[i].vendor_id) {
1661 tmp_hfcpci = pci_find_device(id_list[i].vendor_id, 1661 tmp_hfcpci = hisax_find_pci_device(id_list[i].vendor_id,
1662 id_list[i].device_id, 1662 id_list[i].device_id,
1663 dev_hfcpci); 1663 dev_hfcpci);
1664 i++; 1664 i++;
diff --git a/drivers/isdn/hisax/hisax.h b/drivers/isdn/hisax/hisax.h
index 0685c1946969..832a87855ffb 100644
--- a/drivers/isdn/hisax/hisax.h
+++ b/drivers/isdn/hisax/hisax.h
@@ -1323,3 +1323,26 @@ void release_tei(struct IsdnCardState *cs);
1323char *HiSax_getrev(const char *revision); 1323char *HiSax_getrev(const char *revision);
1324int TeiNew(void); 1324int TeiNew(void);
1325void TeiFree(void); 1325void TeiFree(void);
1326
1327#ifdef CONFIG_PCI
1328
1329#include <linux/pci.h>
1330
1331/* adaptation wrapper for old usage
1332 * WARNING! This is unfit for use in a PCI hotplug environment,
1333 * as the returned PCI device can disappear at any moment in time.
1334 * Callers should be converted to use pci_get_device() instead.
1335 */
1336static inline struct pci_dev *hisax_find_pci_device(unsigned int vendor,
1337 unsigned int device,
1338 struct pci_dev *from)
1339{
1340 struct pci_dev *pdev;
1341
1342 pci_dev_get(from);
1343 pdev = pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
1344 pci_dev_put(pdev);
1345 return pdev;
1346}
1347
1348#endif
diff --git a/drivers/isdn/hisax/niccy.c b/drivers/isdn/hisax/niccy.c
index ef00633e1d2a..ccaa6e13310f 100644
--- a/drivers/isdn/hisax/niccy.c
+++ b/drivers/isdn/hisax/niccy.c
@@ -297,12 +297,12 @@ int __devinit setup_niccy(struct IsdnCard *card)
297 return 0; 297 return 0;
298 } 298 }
299 } else { 299 } else {
300#ifdef CONFIG_PCI_LEGACY 300#ifdef CONFIG_PCI
301 static struct pci_dev *niccy_dev __devinitdata; 301 static struct pci_dev *niccy_dev __devinitdata;
302 302
303 u_int pci_ioaddr; 303 u_int pci_ioaddr;
304 cs->subtyp = 0; 304 cs->subtyp = 0;
305 if ((niccy_dev = pci_find_device(PCI_VENDOR_ID_SATSAGEM, 305 if ((niccy_dev = hisax_find_pci_device(PCI_VENDOR_ID_SATSAGEM,
306 PCI_DEVICE_ID_SATSAGEM_NICCY, 306 PCI_DEVICE_ID_SATSAGEM_NICCY,
307 niccy_dev))) { 307 niccy_dev))) {
308 if (pci_enable_device(niccy_dev)) 308 if (pci_enable_device(niccy_dev))
@@ -354,7 +354,7 @@ int __devinit setup_niccy(struct IsdnCard *card)
354 printk(KERN_WARNING "Niccy: io0 0 and NO_PCI_BIOS\n"); 354 printk(KERN_WARNING "Niccy: io0 0 and NO_PCI_BIOS\n");
355 printk(KERN_WARNING "Niccy: unable to config NICCY PCI\n"); 355 printk(KERN_WARNING "Niccy: unable to config NICCY PCI\n");
356 return 0; 356 return 0;
357#endif /* CONFIG_PCI_LEGACY */ 357#endif /* CONFIG_PCI */
358 } 358 }
359 printk(KERN_INFO "HiSax: NICCY %s config irq:%d data:0x%X ale:0x%X\n", 359 printk(KERN_INFO "HiSax: NICCY %s config irq:%d data:0x%X ale:0x%X\n",
360 (cs->subtyp == 1) ? "PnP" : "PCI", 360 (cs->subtyp == 1) ? "PnP" : "PCI",
diff --git a/drivers/isdn/hisax/nj_s.c b/drivers/isdn/hisax/nj_s.c
index 8d36ccc87d81..2344e7b33448 100644
--- a/drivers/isdn/hisax/nj_s.c
+++ b/drivers/isdn/hisax/nj_s.c
@@ -276,7 +276,7 @@ setup_netjet_s(struct IsdnCard *card)
276 276
277 for ( ;; ) 277 for ( ;; )
278 { 278 {
279 if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET, 279 if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET,
280 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) { 280 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
281 ret = njs_pci_probe(dev_netjet, cs); 281 ret = njs_pci_probe(dev_netjet, cs);
282 if (!ret) 282 if (!ret)
diff --git a/drivers/isdn/hisax/nj_u.c b/drivers/isdn/hisax/nj_u.c
index d306c946ffba..095e974aed80 100644
--- a/drivers/isdn/hisax/nj_u.c
+++ b/drivers/isdn/hisax/nj_u.c
@@ -240,7 +240,7 @@ setup_netjet_u(struct IsdnCard *card)
240 240
241 for ( ;; ) 241 for ( ;; )
242 { 242 {
243 if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET, 243 if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET,
244 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) { 244 PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
245 ret = nju_pci_probe(dev_netjet, cs); 245 ret = nju_pci_probe(dev_netjet, cs);
246 if (!ret) 246 if (!ret)
diff --git a/drivers/isdn/hisax/sedlbauer.c b/drivers/isdn/hisax/sedlbauer.c
index 5569a522e2a1..69dfc8d29017 100644
--- a/drivers/isdn/hisax/sedlbauer.c
+++ b/drivers/isdn/hisax/sedlbauer.c
@@ -598,7 +598,7 @@ setup_sedlbauer_isapnp(struct IsdnCard *card, int *bytecnt)
598} 598}
599#endif /* __ISAPNP__ */ 599#endif /* __ISAPNP__ */
600 600
601#ifdef CONFIG_PCI_LEGACY 601#ifdef CONFIG_PCI
602static struct pci_dev *dev_sedl __devinitdata = NULL; 602static struct pci_dev *dev_sedl __devinitdata = NULL;
603 603
604static int __devinit 604static int __devinit
@@ -607,7 +607,7 @@ setup_sedlbauer_pci(struct IsdnCard *card)
607 struct IsdnCardState *cs = card->cs; 607 struct IsdnCardState *cs = card->cs;
608 u16 sub_vendor_id, sub_id; 608 u16 sub_vendor_id, sub_id;
609 609
610 if ((dev_sedl = pci_find_device(PCI_VENDOR_ID_TIGERJET, 610 if ((dev_sedl = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET,
611 PCI_DEVICE_ID_TIGERJET_100, dev_sedl))) { 611 PCI_DEVICE_ID_TIGERJET_100, dev_sedl))) {
612 if (pci_enable_device(dev_sedl)) 612 if (pci_enable_device(dev_sedl))
613 return(0); 613 return(0);
@@ -673,7 +673,7 @@ setup_sedlbauer_pci(struct IsdnCard *card)
673 return (1); 673 return (1);
674} 674}
675 675
676#endif /* CONFIG_PCI_LEGACY */ 676#endif /* CONFIG_PCI */
677 677
678int __devinit 678int __devinit
679setup_sedlbauer(struct IsdnCard *card) 679setup_sedlbauer(struct IsdnCard *card)
diff --git a/drivers/isdn/hisax/telespci.c b/drivers/isdn/hisax/telespci.c
index 28b08de4673d..b85ceb3746ce 100644
--- a/drivers/isdn/hisax/telespci.c
+++ b/drivers/isdn/hisax/telespci.c
@@ -300,7 +300,7 @@ setup_telespci(struct IsdnCard *card)
300 if (cs->typ != ISDN_CTYPE_TELESPCI) 300 if (cs->typ != ISDN_CTYPE_TELESPCI)
301 return (0); 301 return (0);
302 302
303 if ((dev_tel = pci_find_device (PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36120, dev_tel))) { 303 if ((dev_tel = hisax_find_pci_device (PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36120, dev_tel))) {
304 if (pci_enable_device(dev_tel)) 304 if (pci_enable_device(dev_tel))
305 return(0); 305 return(0);
306 cs->irq = dev_tel->irq; 306 cs->irq = dev_tel->irq;
diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
index c4d862c11a60..9d6e864023fe 100644
--- a/drivers/isdn/hisax/w6692.c
+++ b/drivers/isdn/hisax/w6692.c
@@ -1007,7 +1007,7 @@ setup_w6692(struct IsdnCard *card)
1007 return (0); 1007 return (0);
1008 1008
1009 while (id_list[id_idx].vendor_id) { 1009 while (id_list[id_idx].vendor_id) {
1010 dev_w6692 = pci_find_device(id_list[id_idx].vendor_id, 1010 dev_w6692 = hisax_find_pci_device(id_list[id_idx].vendor_id,
1011 id_list[id_idx].device_id, 1011 id_list[id_idx].device_id,
1012 dev_w6692); 1012 dev_w6692);
1013 if (dev_w6692) { 1013 if (dev_w6692) {
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 23741cec45e3..1c4ee6e77937 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -317,13 +317,15 @@ static int __init adb_init(void)
317 break; 317 break;
318 } 318 }
319 } 319 }
320 if ((adb_controller == NULL) || adb_controller->init()) { 320 if (adb_controller != NULL && adb_controller->init &&
321 printk(KERN_WARNING "Warning: no ADB interface detected\n"); 321 adb_controller->init())
322 adb_controller = NULL; 322 adb_controller = NULL;
323 if (adb_controller == NULL) {
324 printk(KERN_WARNING "Warning: no ADB interface detected\n");
323 } else { 325 } else {
324#ifdef CONFIG_PPC 326#ifdef CONFIG_PPC
325 if (machine_is_compatible("AAPL,PowerBook1998") || 327 if (of_machine_is_compatible("AAPL,PowerBook1998") ||
326 machine_is_compatible("PowerBook1,1")) 328 of_machine_is_compatible("PowerBook1,1"))
327 sleepy_trackpad = 1; 329 sleepy_trackpad = 1;
328#endif /* CONFIG_PPC */ 330#endif /* CONFIG_PPC */
329 331
diff --git a/drivers/macintosh/therm_adt746x.c b/drivers/macintosh/therm_adt746x.c
index 5ff47ba7f2d0..c42eeb43042d 100644
--- a/drivers/macintosh/therm_adt746x.c
+++ b/drivers/macintosh/therm_adt746x.c
@@ -90,6 +90,8 @@ static struct task_struct *thread_therm = NULL;
90 90
91static void write_both_fan_speed(struct thermostat *th, int speed); 91static void write_both_fan_speed(struct thermostat *th, int speed);
92static void write_fan_speed(struct thermostat *th, int speed, int fan); 92static void write_fan_speed(struct thermostat *th, int speed, int fan);
93static void thermostat_create_files(void);
94static void thermostat_remove_files(void);
93 95
94static int 96static int
95write_reg(struct thermostat* th, int reg, u8 data) 97write_reg(struct thermostat* th, int reg, u8 data)
@@ -161,6 +163,8 @@ remove_thermostat(struct i2c_client *client)
161 struct thermostat *th = i2c_get_clientdata(client); 163 struct thermostat *th = i2c_get_clientdata(client);
162 int i; 164 int i;
163 165
166 thermostat_remove_files();
167
164 if (thread_therm != NULL) { 168 if (thread_therm != NULL) {
165 kthread_stop(thread_therm); 169 kthread_stop(thread_therm);
166 } 170 }
@@ -312,7 +316,7 @@ static void update_fans_speed (struct thermostat *th)
312 316
313 if (verbose) 317 if (verbose)
314 printk(KERN_DEBUG "adt746x: Setting fans speed to %d " 318 printk(KERN_DEBUG "adt746x: Setting fans speed to %d "
315 "(limit exceeded by %d on %s) \n", 319 "(limit exceeded by %d on %s)\n",
316 new_speed, var, 320 new_speed, var,
317 sensor_location[fan_number+1]); 321 sensor_location[fan_number+1]);
318 write_both_fan_speed(th, new_speed); 322 write_both_fan_speed(th, new_speed);
@@ -449,6 +453,8 @@ static int probe_thermostat(struct i2c_client *client,
449 return -ENOMEM; 453 return -ENOMEM;
450 } 454 }
451 455
456 thermostat_create_files();
457
452 return 0; 458 return 0;
453} 459}
454 460
@@ -566,7 +572,6 @@ thermostat_init(void)
566 struct device_node* np; 572 struct device_node* np;
567 const u32 *prop; 573 const u32 *prop;
568 int i = 0, offset = 0; 574 int i = 0, offset = 0;
569 int err;
570 575
571 np = of_find_node_by_name(NULL, "fan"); 576 np = of_find_node_by_name(NULL, "fan");
572 if (!np) 577 if (!np)
@@ -633,6 +638,17 @@ thermostat_init(void)
633 return -ENODEV; 638 return -ENODEV;
634 } 639 }
635 640
641#ifndef CONFIG_I2C_POWERMAC
642 request_module("i2c-powermac");
643#endif
644
645 return i2c_add_driver(&thermostat_driver);
646}
647
648static void thermostat_create_files(void)
649{
650 int err;
651
636 err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature); 652 err = device_create_file(&of_dev->dev, &dev_attr_sensor1_temperature);
637 err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature); 653 err |= device_create_file(&of_dev->dev, &dev_attr_sensor2_temperature);
638 err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit); 654 err |= device_create_file(&of_dev->dev, &dev_attr_sensor1_limit);
@@ -647,16 +663,9 @@ thermostat_init(void)
647 if (err) 663 if (err)
648 printk(KERN_WARNING 664 printk(KERN_WARNING
649 "Failed to create tempertaure attribute file(s).\n"); 665 "Failed to create tempertaure attribute file(s).\n");
650
651#ifndef CONFIG_I2C_POWERMAC
652 request_module("i2c-powermac");
653#endif
654
655 return i2c_add_driver(&thermostat_driver);
656} 666}
657 667
658static void __exit 668static void thermostat_remove_files(void)
659thermostat_exit(void)
660{ 669{
661 if (of_dev) { 670 if (of_dev) {
662 device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature); 671 device_remove_file(&of_dev->dev, &dev_attr_sensor1_temperature);
@@ -673,9 +682,14 @@ thermostat_exit(void)
673 device_remove_file(&of_dev->dev, 682 device_remove_file(&of_dev->dev,
674 &dev_attr_sensor2_fan_speed); 683 &dev_attr_sensor2_fan_speed);
675 684
676 of_device_unregister(of_dev);
677 } 685 }
686}
687
688static void __exit
689thermostat_exit(void)
690{
678 i2c_del_driver(&thermostat_driver); 691 i2c_del_driver(&thermostat_driver);
692 of_device_unregister(of_dev);
679} 693}
680 694
681module_init(thermostat_init); 695module_init(thermostat_init);
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index 454bc501df3c..5738d8bf2d97 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -1899,7 +1899,7 @@ static int create_control_loops(void)
1899 */ 1899 */
1900 if (rackmac) 1900 if (rackmac)
1901 cpu_pid_type = CPU_PID_TYPE_RACKMAC; 1901 cpu_pid_type = CPU_PID_TYPE_RACKMAC;
1902 else if (machine_is_compatible("PowerMac7,3") 1902 else if (of_machine_is_compatible("PowerMac7,3")
1903 && (cpu_count > 1) 1903 && (cpu_count > 1)
1904 && fcu_fans[CPUA_PUMP_RPM_INDEX].id != FCU_FAN_ABSENT_ID 1904 && fcu_fans[CPUA_PUMP_RPM_INDEX].id != FCU_FAN_ABSENT_ID
1905 && fcu_fans[CPUB_PUMP_RPM_INDEX].id != FCU_FAN_ABSENT_ID) { 1905 && fcu_fans[CPUB_PUMP_RPM_INDEX].id != FCU_FAN_ABSENT_ID) {
@@ -2234,10 +2234,10 @@ static int __init therm_pm72_init(void)
2234{ 2234{
2235 struct device_node *np; 2235 struct device_node *np;
2236 2236
2237 rackmac = machine_is_compatible("RackMac3,1"); 2237 rackmac = of_machine_is_compatible("RackMac3,1");
2238 2238
2239 if (!machine_is_compatible("PowerMac7,2") && 2239 if (!of_machine_is_compatible("PowerMac7,2") &&
2240 !machine_is_compatible("PowerMac7,3") && 2240 !of_machine_is_compatible("PowerMac7,3") &&
2241 !rackmac) 2241 !rackmac)
2242 return -ENODEV; 2242 return -ENODEV;
2243 2243
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index ba48fd76396e..7fb8b4da35a7 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -490,7 +490,7 @@ g4fan_init( void )
490 info = of_get_property(np, "thermal-info", NULL); 490 info = of_get_property(np, "thermal-info", NULL);
491 of_node_put(np); 491 of_node_put(np);
492 492
493 if( !info || !machine_is_compatible("PowerMac3,6") ) 493 if( !info || !of_machine_is_compatible("PowerMac3,6") )
494 return -ENODEV; 494 return -ENODEV;
495 495
496 if( info->id != 3 ) { 496 if( info->id != 3 ) {
diff --git a/drivers/macintosh/via-cuda.c b/drivers/macintosh/via-cuda.c
index 62dd1fdafecf..971bc9582a5f 100644
--- a/drivers/macintosh/via-cuda.c
+++ b/drivers/macintosh/via-cuda.c
@@ -89,7 +89,6 @@ static int cuda_fully_inited;
89 89
90#ifdef CONFIG_ADB 90#ifdef CONFIG_ADB
91static int cuda_probe(void); 91static int cuda_probe(void);
92static int cuda_init(void);
93static int cuda_send_request(struct adb_request *req, int sync); 92static int cuda_send_request(struct adb_request *req, int sync);
94static int cuda_adb_autopoll(int devs); 93static int cuda_adb_autopoll(int devs);
95static int cuda_reset_adb_bus(void); 94static int cuda_reset_adb_bus(void);
@@ -107,17 +106,42 @@ int cuda_request(struct adb_request *req,
107 106
108#ifdef CONFIG_ADB 107#ifdef CONFIG_ADB
109struct adb_driver via_cuda_driver = { 108struct adb_driver via_cuda_driver = {
110 "CUDA", 109 .name = "CUDA",
111 cuda_probe, 110 .probe = cuda_probe,
112 cuda_init, 111 .send_request = cuda_send_request,
113 cuda_send_request, 112 .autopoll = cuda_adb_autopoll,
114 cuda_adb_autopoll, 113 .poll = cuda_poll,
115 cuda_poll, 114 .reset_bus = cuda_reset_adb_bus,
116 cuda_reset_adb_bus
117}; 115};
118#endif /* CONFIG_ADB */ 116#endif /* CONFIG_ADB */
119 117
120#ifdef CONFIG_PPC 118#ifdef CONFIG_MAC
119int __init find_via_cuda(void)
120{
121 struct adb_request req;
122 int err;
123
124 if (macintosh_config->adb_type != MAC_ADB_CUDA)
125 return 0;
126
127 via = via1;
128 cuda_state = idle;
129
130 err = cuda_init_via();
131 if (err) {
132 printk(KERN_ERR "cuda_init_via() failed\n");
133 via = NULL;
134 return 0;
135 }
136
137 /* enable autopoll */
138 cuda_request(&req, NULL, 3, CUDA_PACKET, CUDA_AUTOPOLL, 1);
139 while (!req.complete)
140 cuda_poll();
141
142 return 1;
143}
144#else
121int __init find_via_cuda(void) 145int __init find_via_cuda(void)
122{ 146{
123 struct adb_request req; 147 struct adb_request req;
@@ -175,7 +199,7 @@ int __init find_via_cuda(void)
175 vias = NULL; 199 vias = NULL;
176 return 0; 200 return 0;
177} 201}
178#endif /* CONFIG_PPC */ 202#endif /* !defined CONFIG_MAC */
179 203
180static int __init via_cuda_start(void) 204static int __init via_cuda_start(void)
181{ 205{
@@ -184,14 +208,14 @@ static int __init via_cuda_start(void)
184 208
185#ifdef CONFIG_MAC 209#ifdef CONFIG_MAC
186 cuda_irq = IRQ_MAC_ADB; 210 cuda_irq = IRQ_MAC_ADB;
187#else /* CONFIG_MAC */ 211#else
188 cuda_irq = irq_of_parse_and_map(vias, 0); 212 cuda_irq = irq_of_parse_and_map(vias, 0);
189 if (cuda_irq == NO_IRQ) { 213 if (cuda_irq == NO_IRQ) {
190 printk(KERN_ERR "via-cuda: can't map interrupts for %s\n", 214 printk(KERN_ERR "via-cuda: can't map interrupts for %s\n",
191 vias->full_name); 215 vias->full_name);
192 return -ENODEV; 216 return -ENODEV;
193 } 217 }
194#endif /* CONFIG_MAC */ 218#endif
195 219
196 if (request_irq(cuda_irq, cuda_interrupt, 0, "ADB", cuda_interrupt)) { 220 if (request_irq(cuda_irq, cuda_interrupt, 0, "ADB", cuda_interrupt)) {
197 printk(KERN_ERR "via-cuda: can't request irq %d\n", cuda_irq); 221 printk(KERN_ERR "via-cuda: can't request irq %d\n", cuda_irq);
@@ -216,28 +240,10 @@ cuda_probe(void)
216#else 240#else
217 if (macintosh_config->adb_type != MAC_ADB_CUDA) 241 if (macintosh_config->adb_type != MAC_ADB_CUDA)
218 return -ENODEV; 242 return -ENODEV;
219 via = via1;
220#endif 243#endif
221 return 0;
222}
223
224static int __init
225cuda_init(void)
226{
227#ifdef CONFIG_PPC
228 if (via == NULL) 244 if (via == NULL)
229 return -ENODEV; 245 return -ENODEV;
230 return 0; 246 return 0;
231#else
232 int err = cuda_init_via();
233 if (err) {
234 printk(KERN_ERR "cuda_init_via() failed\n");
235 return -ENODEV;
236 }
237 out_8(&via[IER], IER_SET|SR_INT); /* enable interrupt from SR */
238
239 return via_cuda_start();
240#endif
241} 247}
242#endif /* CONFIG_ADB */ 248#endif /* CONFIG_ADB */
243 249
@@ -430,9 +436,11 @@ cuda_poll(void)
430 /* cuda_interrupt only takes a normal lock, we disable 436 /* cuda_interrupt only takes a normal lock, we disable
431 * interrupts here to avoid re-entering and thus deadlocking. 437 * interrupts here to avoid re-entering and thus deadlocking.
432 */ 438 */
433 disable_irq(cuda_irq); 439 if (cuda_irq)
440 disable_irq(cuda_irq);
434 cuda_interrupt(0, NULL); 441 cuda_interrupt(0, NULL);
435 enable_irq(cuda_irq); 442 if (cuda_irq)
443 enable_irq(cuda_irq);
436} 444}
437 445
438static irqreturn_t 446static irqreturn_t
@@ -446,7 +454,7 @@ cuda_interrupt(int irq, void *arg)
446 454
447 spin_lock(&cuda_lock); 455 spin_lock(&cuda_lock);
448 456
449 /* On powermacs, this handler is registered for the VIA IRQ. But it uses 457 /* On powermacs, this handler is registered for the VIA IRQ. But they use
450 * just the shift register IRQ -- other VIA interrupt sources are disabled. 458 * just the shift register IRQ -- other VIA interrupt sources are disabled.
451 * On m68k macs, the VIA IRQ sources are dispatched individually. Unless 459 * On m68k macs, the VIA IRQ sources are dispatched individually. Unless
452 * we are polling, the shift register IRQ flag has already been cleared. 460 * we are polling, the shift register IRQ flag has already been cleared.
diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
index a348bb0791d3..4f3c4479c16a 100644
--- a/drivers/macintosh/via-pmu-backlight.c
+++ b/drivers/macintosh/via-pmu-backlight.c
@@ -150,13 +150,13 @@ void __init pmu_backlight_init()
150 150
151 /* Special case for the old PowerBook since I can't test on it */ 151 /* Special case for the old PowerBook since I can't test on it */
152 autosave = 152 autosave =
153 machine_is_compatible("AAPL,3400/2400") || 153 of_machine_is_compatible("AAPL,3400/2400") ||
154 machine_is_compatible("AAPL,3500"); 154 of_machine_is_compatible("AAPL,3500");
155 155
156 if (!autosave && 156 if (!autosave &&
157 !pmac_has_backlight_type("pmu") && 157 !pmac_has_backlight_type("pmu") &&
158 !machine_is_compatible("AAPL,PowerBook1998") && 158 !of_machine_is_compatible("AAPL,PowerBook1998") &&
159 !machine_is_compatible("PowerBook1,1")) 159 !of_machine_is_compatible("PowerBook1,1"))
160 return; 160 return;
161 161
162 snprintf(name, sizeof(name), "pmubl"); 162 snprintf(name, sizeof(name), "pmubl");
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index db379c381432..42764849eb78 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -463,8 +463,8 @@ static int __init via_pmu_dev_init(void)
463#endif 463#endif
464 464
465#ifdef CONFIG_PPC32 465#ifdef CONFIG_PPC32
466 if (machine_is_compatible("AAPL,3400/2400") || 466 if (of_machine_is_compatible("AAPL,3400/2400") ||
467 machine_is_compatible("AAPL,3500")) { 467 of_machine_is_compatible("AAPL,3500")) {
468 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO, 468 int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
469 NULL, PMAC_MB_INFO_MODEL, 0); 469 NULL, PMAC_MB_INFO_MODEL, 0);
470 pmu_battery_count = 1; 470 pmu_battery_count = 1;
@@ -472,8 +472,8 @@ static int __init via_pmu_dev_init(void)
472 pmu_batteries[0].flags |= PMU_BATT_TYPE_COMET; 472 pmu_batteries[0].flags |= PMU_BATT_TYPE_COMET;
473 else 473 else
474 pmu_batteries[0].flags |= PMU_BATT_TYPE_HOOPER; 474 pmu_batteries[0].flags |= PMU_BATT_TYPE_HOOPER;
475 } else if (machine_is_compatible("AAPL,PowerBook1998") || 475 } else if (of_machine_is_compatible("AAPL,PowerBook1998") ||
476 machine_is_compatible("PowerBook1,1")) { 476 of_machine_is_compatible("PowerBook1,1")) {
477 pmu_battery_count = 2; 477 pmu_battery_count = 2;
478 pmu_batteries[0].flags |= PMU_BATT_TYPE_SMART; 478 pmu_batteries[0].flags |= PMU_BATT_TYPE_SMART;
479 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART; 479 pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
diff --git a/drivers/macintosh/windfarm_core.c b/drivers/macintosh/windfarm_core.c
index 075b4d99e354..437f55c5d18d 100644
--- a/drivers/macintosh/windfarm_core.c
+++ b/drivers/macintosh/windfarm_core.c
@@ -468,9 +468,9 @@ static int __init windfarm_core_init(void)
468 DBG("wf: core loaded\n"); 468 DBG("wf: core loaded\n");
469 469
470 /* Don't register on old machines that use therm_pm72 for now */ 470 /* Don't register on old machines that use therm_pm72 for now */
471 if (machine_is_compatible("PowerMac7,2") || 471 if (of_machine_is_compatible("PowerMac7,2") ||
472 machine_is_compatible("PowerMac7,3") || 472 of_machine_is_compatible("PowerMac7,3") ||
473 machine_is_compatible("RackMac3,1")) 473 of_machine_is_compatible("RackMac3,1"))
474 return -ENODEV; 474 return -ENODEV;
475 platform_device_register(&wf_platform_device); 475 platform_device_register(&wf_platform_device);
476 return 0; 476 return 0;
diff --git a/drivers/macintosh/windfarm_cpufreq_clamp.c b/drivers/macintosh/windfarm_cpufreq_clamp.c
index 900aade06198..1a77a7c97d0e 100644
--- a/drivers/macintosh/windfarm_cpufreq_clamp.c
+++ b/drivers/macintosh/windfarm_cpufreq_clamp.c
@@ -76,9 +76,9 @@ static int __init wf_cpufreq_clamp_init(void)
76 struct wf_control *clamp; 76 struct wf_control *clamp;
77 77
78 /* Don't register on old machines that use therm_pm72 for now */ 78 /* Don't register on old machines that use therm_pm72 for now */
79 if (machine_is_compatible("PowerMac7,2") || 79 if (of_machine_is_compatible("PowerMac7,2") ||
80 machine_is_compatible("PowerMac7,3") || 80 of_machine_is_compatible("PowerMac7,3") ||
81 machine_is_compatible("RackMac3,1")) 81 of_machine_is_compatible("RackMac3,1"))
82 return -ENODEV; 82 return -ENODEV;
83 83
84 clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL); 84 clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL);
diff --git a/drivers/macintosh/windfarm_lm75_sensor.c b/drivers/macintosh/windfarm_lm75_sensor.c
index ed6426a10773..d8257d35afde 100644
--- a/drivers/macintosh/windfarm_lm75_sensor.c
+++ b/drivers/macintosh/windfarm_lm75_sensor.c
@@ -239,9 +239,9 @@ static struct i2c_driver wf_lm75_driver = {
239static int __init wf_lm75_sensor_init(void) 239static int __init wf_lm75_sensor_init(void)
240{ 240{
241 /* Don't register on old machines that use therm_pm72 for now */ 241 /* Don't register on old machines that use therm_pm72 for now */
242 if (machine_is_compatible("PowerMac7,2") || 242 if (of_machine_is_compatible("PowerMac7,2") ||
243 machine_is_compatible("PowerMac7,3") || 243 of_machine_is_compatible("PowerMac7,3") ||
244 machine_is_compatible("RackMac3,1")) 244 of_machine_is_compatible("RackMac3,1"))
245 return -ENODEV; 245 return -ENODEV;
246 return i2c_add_driver(&wf_lm75_driver); 246 return i2c_add_driver(&wf_lm75_driver);
247} 247}
diff --git a/drivers/macintosh/windfarm_max6690_sensor.c b/drivers/macintosh/windfarm_max6690_sensor.c
index a67b349319e9..b486eb929fde 100644
--- a/drivers/macintosh/windfarm_max6690_sensor.c
+++ b/drivers/macintosh/windfarm_max6690_sensor.c
@@ -188,9 +188,9 @@ static struct i2c_driver wf_max6690_driver = {
188static int __init wf_max6690_sensor_init(void) 188static int __init wf_max6690_sensor_init(void)
189{ 189{
190 /* Don't register on old machines that use therm_pm72 for now */ 190 /* Don't register on old machines that use therm_pm72 for now */
191 if (machine_is_compatible("PowerMac7,2") || 191 if (of_machine_is_compatible("PowerMac7,2") ||
192 machine_is_compatible("PowerMac7,3") || 192 of_machine_is_compatible("PowerMac7,3") ||
193 machine_is_compatible("RackMac3,1")) 193 of_machine_is_compatible("RackMac3,1"))
194 return -ENODEV; 194 return -ENODEV;
195 return i2c_add_driver(&wf_max6690_driver); 195 return i2c_add_driver(&wf_max6690_driver);
196} 196}
diff --git a/drivers/macintosh/windfarm_pm112.c b/drivers/macintosh/windfarm_pm112.c
index 73d695dc9e50..e0ee80700cde 100644
--- a/drivers/macintosh/windfarm_pm112.c
+++ b/drivers/macintosh/windfarm_pm112.c
@@ -676,7 +676,7 @@ static int __init wf_pm112_init(void)
676{ 676{
677 struct device_node *cpu; 677 struct device_node *cpu;
678 678
679 if (!machine_is_compatible("PowerMac11,2")) 679 if (!of_machine_is_compatible("PowerMac11,2"))
680 return -ENODEV; 680 return -ENODEV;
681 681
682 /* Count the number of CPU cores */ 682 /* Count the number of CPU cores */
diff --git a/drivers/macintosh/windfarm_pm121.c b/drivers/macintosh/windfarm_pm121.c
index 66ec4fb115bb..947d4afa25ca 100644
--- a/drivers/macintosh/windfarm_pm121.c
+++ b/drivers/macintosh/windfarm_pm121.c
@@ -1008,7 +1008,7 @@ static int __init pm121_init(void)
1008{ 1008{
1009 int rc = -ENODEV; 1009 int rc = -ENODEV;
1010 1010
1011 if (machine_is_compatible("PowerMac12,1")) 1011 if (of_machine_is_compatible("PowerMac12,1"))
1012 rc = pm121_init_pm(); 1012 rc = pm121_init_pm();
1013 1013
1014 if (rc == 0) { 1014 if (rc == 0) {
diff --git a/drivers/macintosh/windfarm_pm81.c b/drivers/macintosh/windfarm_pm81.c
index abbe206474f5..565d5b2adc95 100644
--- a/drivers/macintosh/windfarm_pm81.c
+++ b/drivers/macintosh/windfarm_pm81.c
@@ -779,8 +779,8 @@ static int __init wf_smu_init(void)
779{ 779{
780 int rc = -ENODEV; 780 int rc = -ENODEV;
781 781
782 if (machine_is_compatible("PowerMac8,1") || 782 if (of_machine_is_compatible("PowerMac8,1") ||
783 machine_is_compatible("PowerMac8,2")) 783 of_machine_is_compatible("PowerMac8,2"))
784 rc = wf_init_pm(); 784 rc = wf_init_pm();
785 785
786 if (rc == 0) { 786 if (rc == 0) {
diff --git a/drivers/macintosh/windfarm_pm91.c b/drivers/macintosh/windfarm_pm91.c
index 764c525b2117..bea99168ff35 100644
--- a/drivers/macintosh/windfarm_pm91.c
+++ b/drivers/macintosh/windfarm_pm91.c
@@ -711,7 +711,7 @@ static int __init wf_smu_init(void)
711{ 711{
712 int rc = -ENODEV; 712 int rc = -ENODEV;
713 713
714 if (machine_is_compatible("PowerMac9,1")) 714 if (of_machine_is_compatible("PowerMac9,1"))
715 rc = wf_init_pm(); 715 rc = wf_init_pm();
716 716
717 if (rc == 0) { 717 if (rc == 0) {
diff --git a/drivers/macintosh/windfarm_smu_sensors.c b/drivers/macintosh/windfarm_smu_sensors.c
index 9c567b93f417..3c193504bb80 100644
--- a/drivers/macintosh/windfarm_smu_sensors.c
+++ b/drivers/macintosh/windfarm_smu_sensors.c
@@ -363,9 +363,9 @@ smu_cpu_power_create(struct wf_sensor *volts, struct wf_sensor *amps)
363 * I yet have to figure out what's up with 8,2 and will have to 363 * I yet have to figure out what's up with 8,2 and will have to
364 * adjust for later, unless we can 100% trust the SDB partition... 364 * adjust for later, unless we can 100% trust the SDB partition...
365 */ 365 */
366 if ((machine_is_compatible("PowerMac8,1") || 366 if ((of_machine_is_compatible("PowerMac8,1") ||
367 machine_is_compatible("PowerMac8,2") || 367 of_machine_is_compatible("PowerMac8,2") ||
368 machine_is_compatible("PowerMac9,1")) && 368 of_machine_is_compatible("PowerMac9,1")) &&
369 cpuvcp_version >= 2) { 369 cpuvcp_version >= 2) {
370 pow->quadratic = 1; 370 pow->quadratic = 1;
371 DBG("windfarm: CPU Power using quadratic transform\n"); 371 DBG("windfarm: CPU Power using quadratic transform\n");
diff --git a/drivers/media/IR/Makefile b/drivers/media/IR/Makefile
index df5ddb4bbbf7..171890e7a41d 100644
--- a/drivers/media/IR/Makefile
+++ b/drivers/media/IR/Makefile
@@ -1,5 +1,5 @@
1ir-common-objs := ir-functions.o ir-keymaps.o 1ir-common-objs := ir-functions.o ir-keymaps.o
2ir-core-objs := ir-keytable.o 2ir-core-objs := ir-keytable.o ir-sysfs.o
3 3
4obj-$(CONFIG_IR_CORE) += ir-core.o 4obj-$(CONFIG_IR_CORE) += ir-core.o
5obj-$(CONFIG_VIDEO_IR) += ir-common.o 5obj-$(CONFIG_VIDEO_IR) += ir-common.o
diff --git a/drivers/media/IR/ir-functions.c b/drivers/media/IR/ir-functions.c
index 776a136616d6..ab06919ad5fc 100644
--- a/drivers/media/IR/ir-functions.c
+++ b/drivers/media/IR/ir-functions.c
@@ -52,7 +52,7 @@ static void ir_input_key_event(struct input_dev *dev, struct ir_input_state *ir)
52/* -------------------------------------------------------------------------- */ 52/* -------------------------------------------------------------------------- */
53 53
54int ir_input_init(struct input_dev *dev, struct ir_input_state *ir, 54int ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
55 int ir_type) 55 const u64 ir_type)
56{ 56{
57 ir->ir_type = ir_type; 57 ir->ir_type = ir_type;
58 58
diff --git a/drivers/media/IR/ir-keymaps.c b/drivers/media/IR/ir-keymaps.c
index 9bbe6b1e9871..0efdefe75f32 100644
--- a/drivers/media/IR/ir-keymaps.c
+++ b/drivers/media/IR/ir-keymaps.c
@@ -3393,3 +3393,102 @@ struct ir_scancode_table ir_codes_nec_terratec_cinergy_xs_table = {
3393}; 3393};
3394EXPORT_SYMBOL_GPL(ir_codes_nec_terratec_cinergy_xs_table); 3394EXPORT_SYMBOL_GPL(ir_codes_nec_terratec_cinergy_xs_table);
3395 3395
3396
3397/* Leadtek Winfast TV USB II Deluxe remote
3398 Magnus Alm <magnus.alm@gmail.com>
3399 */
3400static struct ir_scancode ir_codes_winfast_usbii_deluxe[] = {
3401 { 0x62, KEY_0},
3402 { 0x75, KEY_1},
3403 { 0x76, KEY_2},
3404 { 0x77, KEY_3},
3405 { 0x79, KEY_4},
3406 { 0x7a, KEY_5},
3407 { 0x7b, KEY_6},
3408 { 0x7d, KEY_7},
3409 { 0x7e, KEY_8},
3410 { 0x7f, KEY_9},
3411
3412 { 0x38, KEY_CAMERA}, /* SNAPSHOT */
3413 { 0x37, KEY_RECORD}, /* RECORD */
3414 { 0x35, KEY_TIME}, /* TIMESHIFT */
3415
3416 { 0x74, KEY_VOLUMEUP}, /* VOLUMEUP */
3417 { 0x78, KEY_VOLUMEDOWN}, /* VOLUMEDOWN */
3418 { 0x64, KEY_MUTE}, /* MUTE */
3419
3420 { 0x21, KEY_CHANNEL}, /* SURF */
3421 { 0x7c, KEY_CHANNELUP}, /* CHANNELUP */
3422 { 0x60, KEY_CHANNELDOWN}, /* CHANNELDOWN */
3423 { 0x61, KEY_LAST}, /* LAST CHANNEL (RECALL) */
3424
3425 { 0x72, KEY_VIDEO}, /* INPUT MODES (TV/FM) */
3426
3427 { 0x70, KEY_POWER2}, /* TV ON/OFF */
3428
3429 { 0x39, KEY_CYCLEWINDOWS}, /* MINIMIZE (BOSS) */
3430 { 0x3a, KEY_NEW}, /* PIP */
3431 { 0x73, KEY_ZOOM}, /* FULLSECREEN */
3432
3433 { 0x66, KEY_INFO}, /* OSD (DISPLAY) */
3434
3435 { 0x31, KEY_DOT}, /* '.' */
3436 { 0x63, KEY_ENTER}, /* ENTER */
3437
3438};
3439struct ir_scancode_table ir_codes_winfast_usbii_deluxe_table = {
3440 .scan = ir_codes_winfast_usbii_deluxe,
3441 .size = ARRAY_SIZE(ir_codes_winfast_usbii_deluxe),
3442};
3443EXPORT_SYMBOL_GPL(ir_codes_winfast_usbii_deluxe_table);
3444
3445/* Kworld 315U
3446 */
3447static struct ir_scancode ir_codes_kworld_315u[] = {
3448 { 0x6143, KEY_POWER },
3449 { 0x6101, KEY_TUNER }, /* source */
3450 { 0x610b, KEY_ZOOM },
3451 { 0x6103, KEY_POWER2 }, /* shutdown */
3452
3453 { 0x6104, KEY_1 },
3454 { 0x6108, KEY_2 },
3455 { 0x6102, KEY_3 },
3456 { 0x6109, KEY_CHANNELUP },
3457
3458 { 0x610f, KEY_4 },
3459 { 0x6105, KEY_5 },
3460 { 0x6106, KEY_6 },
3461 { 0x6107, KEY_CHANNELDOWN },
3462
3463 { 0x610c, KEY_7 },
3464 { 0x610d, KEY_8 },
3465 { 0x610a, KEY_9 },
3466 { 0x610e, KEY_VOLUMEUP },
3467
3468 { 0x6110, KEY_LAST },
3469 { 0x6111, KEY_0 },
3470 { 0x6112, KEY_ENTER },
3471 { 0x6113, KEY_VOLUMEDOWN },
3472
3473 { 0x6114, KEY_RECORD },
3474 { 0x6115, KEY_STOP },
3475 { 0x6116, KEY_PLAY },
3476 { 0x6117, KEY_MUTE },
3477
3478 { 0x6118, KEY_UP },
3479 { 0x6119, KEY_DOWN },
3480 { 0x611a, KEY_LEFT },
3481 { 0x611b, KEY_RIGHT },
3482
3483 { 0x611c, KEY_RED },
3484 { 0x611d, KEY_GREEN },
3485 { 0x611e, KEY_YELLOW },
3486 { 0x611f, KEY_BLUE },
3487};
3488
3489struct ir_scancode_table ir_codes_kworld_315u_table = {
3490 .scan = ir_codes_kworld_315u,
3491 .size = ARRAY_SIZE(ir_codes_kworld_315u),
3492 .ir_type = IR_TYPE_NEC,
3493};
3494EXPORT_SYMBOL_GPL(ir_codes_kworld_315u_table);
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index b521ed9d6e2e..0903f539bf68 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -65,7 +65,7 @@ exit:
65 * In order to reduce the quantity of table resizes, it has a minimum 65 * In order to reduce the quantity of table resizes, it has a minimum
66 * table size of IR_TAB_MIN_SIZE. 66 * table size of IR_TAB_MIN_SIZE.
67 */ 67 */
68int ir_roundup_tablesize(int n_elems) 68static int ir_roundup_tablesize(int n_elems)
69{ 69{
70 size_t size; 70 size_t size;
71 71
@@ -81,7 +81,6 @@ int ir_roundup_tablesize(int n_elems)
81 81
82 return n_elems; 82 return n_elems;
83} 83}
84EXPORT_SYMBOL_GPL(ir_roundup_tablesize);
85 84
86/** 85/**
87 * ir_copy_table() - copies a keytable, discarding the unused entries 86 * ir_copy_table() - copies a keytable, discarding the unused entries
@@ -89,9 +88,11 @@ EXPORT_SYMBOL_GPL(ir_roundup_tablesize);
89 * @origin: origin table 88 * @origin: origin table
90 * 89 *
91 * Copies all entries where the keycode is not KEY_UNKNOWN/KEY_RESERVED 90 * Copies all entries where the keycode is not KEY_UNKNOWN/KEY_RESERVED
91 * Also copies table size and table protocol.
92 * NOTE: It shouldn't copy the lock field
92 */ 93 */
93 94
94int ir_copy_table(struct ir_scancode_table *destin, 95static int ir_copy_table(struct ir_scancode_table *destin,
95 const struct ir_scancode_table *origin) 96 const struct ir_scancode_table *origin)
96{ 97{
97 int i, j = 0; 98 int i, j = 0;
@@ -105,12 +106,12 @@ int ir_copy_table(struct ir_scancode_table *destin,
105 j++; 106 j++;
106 } 107 }
107 destin->size = j; 108 destin->size = j;
109 destin->ir_type = origin->ir_type;
108 110
109 IR_dprintk(1, "Copied %d scancodes to the new keycode table\n", destin->size); 111 IR_dprintk(1, "Copied %d scancodes to the new keycode table\n", destin->size);
110 112
111 return 0; 113 return 0;
112} 114}
113EXPORT_SYMBOL_GPL(ir_copy_table);
114 115
115/** 116/**
116 * ir_getkeycode() - get a keycode at the evdev scancode ->keycode table 117 * ir_getkeycode() - get a keycode at the evdev scancode ->keycode table
@@ -184,18 +185,14 @@ static void ir_delete_key(struct ir_scancode_table *rc_tab, int elem)
184 int newsize = rc_tab->size - 1; 185 int newsize = rc_tab->size - 1;
185 int resize = ir_is_resize_needed(rc_tab, newsize); 186 int resize = ir_is_resize_needed(rc_tab, newsize);
186 struct ir_scancode *oldkeymap = rc_tab->scan; 187 struct ir_scancode *oldkeymap = rc_tab->scan;
187 struct ir_scancode *newkeymap; 188 struct ir_scancode *newkeymap = NULL;
188 189
189 if (resize) { 190 if (resize)
190 newkeymap = kzalloc(ir_roundup_tablesize(newsize) * 191 newkeymap = kzalloc(ir_roundup_tablesize(newsize) *
191 sizeof(*newkeymap), GFP_ATOMIC); 192 sizeof(*newkeymap), GFP_ATOMIC);
192 193
193 /* There's no memory for resize. Keep the old table */ 194 /* There's no memory for resize. Keep the old table */
194 if (!newkeymap) 195 if (!resize || !newkeymap) {
195 resize = 0;
196 }
197
198 if (!resize) {
199 newkeymap = oldkeymap; 196 newkeymap = oldkeymap;
200 197
201 /* We'll modify the live table. Lock it */ 198 /* We'll modify the live table. Lock it */
@@ -399,12 +396,14 @@ EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
399 * @input_dev: the struct input_dev descriptor of the device 396 * @input_dev: the struct input_dev descriptor of the device
400 * @rc_tab: the struct ir_scancode_table table of scancode/keymap 397 * @rc_tab: the struct ir_scancode_table table of scancode/keymap
401 * 398 *
402 * This routine is used to initialize the input infrastructure to work with 399 * This routine is used to initialize the input infrastructure
403 * an IR. 400 * to work with an IR.
404 * It should be called before registering the IR device. 401 * It will register the input/evdev interface for the device and
402 * register the syfs code for IR class
405 */ 403 */
406int ir_input_register(struct input_dev *input_dev, 404int ir_input_register(struct input_dev *input_dev,
407 struct ir_scancode_table *rc_tab) 405 const struct ir_scancode_table *rc_tab,
406 const struct ir_dev_props *props)
408{ 407{
409 struct ir_input_dev *ir_dev; 408 struct ir_input_dev *ir_dev;
410 struct ir_scancode *keymap = rc_tab->scan; 409 struct ir_scancode *keymap = rc_tab->scan;
@@ -417,19 +416,22 @@ int ir_input_register(struct input_dev *input_dev,
417 if (!ir_dev) 416 if (!ir_dev)
418 return -ENOMEM; 417 return -ENOMEM;
419 418
420 spin_lock_init(&rc_tab->lock); 419 spin_lock_init(&ir_dev->rc_tab.lock);
421 420
422 ir_dev->rc_tab.size = ir_roundup_tablesize(rc_tab->size); 421 ir_dev->rc_tab.size = ir_roundup_tablesize(rc_tab->size);
423 ir_dev->rc_tab.scan = kzalloc(ir_dev->rc_tab.size * 422 ir_dev->rc_tab.scan = kzalloc(ir_dev->rc_tab.size *
424 sizeof(struct ir_scancode), GFP_KERNEL); 423 sizeof(struct ir_scancode), GFP_KERNEL);
425 if (!ir_dev->rc_tab.scan) 424 if (!ir_dev->rc_tab.scan) {
425 kfree(ir_dev);
426 return -ENOMEM; 426 return -ENOMEM;
427 }
427 428
428 IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n", 429 IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n",
429 ir_dev->rc_tab.size, 430 ir_dev->rc_tab.size,
430 ir_dev->rc_tab.size * sizeof(ir_dev->rc_tab.scan)); 431 ir_dev->rc_tab.size * sizeof(ir_dev->rc_tab.scan));
431 432
432 ir_copy_table(&ir_dev->rc_tab, rc_tab); 433 ir_copy_table(&ir_dev->rc_tab, rc_tab);
434 ir_dev->props = props;
433 435
434 /* set the bits for the keys */ 436 /* set the bits for the keys */
435 IR_dprintk(1, "key map size: %d\n", rc_tab->size); 437 IR_dprintk(1, "key map size: %d\n", rc_tab->size);
@@ -447,16 +449,31 @@ int ir_input_register(struct input_dev *input_dev,
447 input_set_drvdata(input_dev, ir_dev); 449 input_set_drvdata(input_dev, ir_dev);
448 450
449 rc = input_register_device(input_dev); 451 rc = input_register_device(input_dev);
452 if (rc < 0)
453 goto err;
454
455 rc = ir_register_class(input_dev);
450 if (rc < 0) { 456 if (rc < 0) {
451 kfree(rc_tab->scan); 457 input_unregister_device(input_dev);
452 kfree(ir_dev); 458 goto err;
453 input_set_drvdata(input_dev, NULL);
454 } 459 }
455 460
461 return 0;
462
463err:
464 kfree(rc_tab->scan);
465 kfree(ir_dev);
466 input_set_drvdata(input_dev, NULL);
456 return rc; 467 return rc;
457} 468}
458EXPORT_SYMBOL_GPL(ir_input_register); 469EXPORT_SYMBOL_GPL(ir_input_register);
459 470
471/**
472 * ir_input_unregister() - unregisters IR and frees resources
473 * @input_dev: the struct input_dev descriptor of the device
474
475 * This routine is used to free memory and de-register interfaces.
476 */
460void ir_input_unregister(struct input_dev *dev) 477void ir_input_unregister(struct input_dev *dev)
461{ 478{
462 struct ir_input_dev *ir_dev = input_get_drvdata(dev); 479 struct ir_input_dev *ir_dev = input_get_drvdata(dev);
@@ -472,6 +489,8 @@ void ir_input_unregister(struct input_dev *dev)
472 kfree(rc_tab->scan); 489 kfree(rc_tab->scan);
473 rc_tab->scan = NULL; 490 rc_tab->scan = NULL;
474 491
492 ir_unregister_class(dev);
493
475 kfree(ir_dev); 494 kfree(ir_dev);
476 input_unregister_device(dev); 495 input_unregister_device(dev);
477} 496}
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
new file mode 100644
index 000000000000..bf5fbcd84238
--- /dev/null
+++ b/drivers/media/IR/ir-sysfs.c
@@ -0,0 +1,211 @@
1/* ir-register.c - handle IR scancode->keycode tables
2 *
3 * Copyright (C) 2009 by Mauro Carvalho Chehab <mchehab@redhat.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/input.h>
16#include <linux/device.h>
17#include <media/ir-core.h>
18
19#define IRRCV_NUM_DEVICES 256
20
21/* bit array to represent IR sysfs device number */
22static unsigned long ir_core_dev_number;
23
24/* class for /sys/class/irrcv */
25static struct class *ir_input_class;
26
27/**
28 * show_protocol() - shows the current IR protocol
29 * @d: the device descriptor
30 * @mattr: the device attribute struct (unused)
31 * @buf: a pointer to the output buffer
32 *
33 * This routine is a callback routine for input read the IR protocol type.
34 * it is trigged by reading /sys/class/irrcv/irrcv?/current_protocol.
35 * It returns the protocol name, as understood by the driver.
36 */
37static ssize_t show_protocol(struct device *d,
38 struct device_attribute *mattr, char *buf)
39{
40 char *s;
41 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
42 u64 ir_type = ir_dev->rc_tab.ir_type;
43
44 IR_dprintk(1, "Current protocol is %lld\n", (long long)ir_type);
45
46 /* FIXME: doesn't support multiple protocols at the same time */
47 if (ir_type == IR_TYPE_UNKNOWN)
48 s = "Unknown";
49 else if (ir_type == IR_TYPE_RC5)
50 s = "RC-5";
51 else if (ir_type == IR_TYPE_PD)
52 s = "Pulse/distance";
53 else if (ir_type == IR_TYPE_NEC)
54 s = "NEC";
55 else
56 s = "Other";
57
58 return sprintf(buf, "%s\n", s);
59}
60
61/**
62 * store_protocol() - shows the current IR protocol
63 * @d: the device descriptor
64 * @mattr: the device attribute struct (unused)
65 * @buf: a pointer to the input buffer
66 * @len: length of the input buffer
67 *
68 * This routine is a callback routine for changing the IR protocol type.
69 * it is trigged by reading /sys/class/irrcv/irrcv?/current_protocol.
70 * It changes the IR the protocol name, if the IR type is recognized
71 * by the driver.
72 * If an unknown protocol name is used, returns -EINVAL.
73 */
74static ssize_t store_protocol(struct device *d,
75 struct device_attribute *mattr,
76 const char *data,
77 size_t len)
78{
79 struct ir_input_dev *ir_dev = dev_get_drvdata(d);
80 u64 ir_type = IR_TYPE_UNKNOWN;
81 int rc = -EINVAL;
82 unsigned long flags;
83 char *buf;
84
85 buf = strsep((char **) &data, "\n");
86
87 if (!strcasecmp(buf, "rc-5"))
88 ir_type = IR_TYPE_RC5;
89 else if (!strcasecmp(buf, "pd"))
90 ir_type = IR_TYPE_PD;
91 else if (!strcasecmp(buf, "nec"))
92 ir_type = IR_TYPE_NEC;
93
94 if (ir_type == IR_TYPE_UNKNOWN) {
95 IR_dprintk(1, "Error setting protocol to %lld\n",
96 (long long)ir_type);
97 return -EINVAL;
98 }
99
100 if (ir_dev->props && ir_dev->props->change_protocol)
101 rc = ir_dev->props->change_protocol(ir_dev->props->priv,
102 ir_type);
103
104 if (rc < 0) {
105 IR_dprintk(1, "Error setting protocol to %lld\n",
106 (long long)ir_type);
107 return -EINVAL;
108 }
109
110 spin_lock_irqsave(&ir_dev->rc_tab.lock, flags);
111 ir_dev->rc_tab.ir_type = ir_type;
112 spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags);
113
114 IR_dprintk(1, "Current protocol is %lld\n",
115 (long long)ir_type);
116
117 return len;
118}
119
120/*
121 * Static device attribute struct with the sysfs attributes for IR's
122 */
123static DEVICE_ATTR(current_protocol, S_IRUGO | S_IWUSR,
124 show_protocol, store_protocol);
125
126static struct attribute *ir_dev_attrs[] = {
127 &dev_attr_current_protocol.attr,
128 NULL,
129};
130
131/**
132 * ir_register_class() - creates the sysfs for /sys/class/irrcv/irrcv?
133 * @input_dev: the struct input_dev descriptor of the device
134 *
135 * This routine is used to register the syfs code for IR class
136 */
137int ir_register_class(struct input_dev *input_dev)
138{
139 int rc;
140 struct kobject *kobj;
141
142 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
143 int devno = find_first_zero_bit(&ir_core_dev_number,
144 IRRCV_NUM_DEVICES);
145
146 if (unlikely(devno < 0))
147 return devno;
148
149 ir_dev->attr.attrs = ir_dev_attrs;
150 ir_dev->class_dev = device_create(ir_input_class, NULL,
151 input_dev->dev.devt, ir_dev,
152 "irrcv%d", devno);
153 kobj = &ir_dev->class_dev->kobj;
154
155 printk(KERN_WARNING "Creating IR device %s\n", kobject_name(kobj));
156 rc = sysfs_create_group(kobj, &ir_dev->attr);
157 if (unlikely(rc < 0)) {
158 device_destroy(ir_input_class, input_dev->dev.devt);
159 return -ENOMEM;
160 }
161
162 ir_dev->devno = devno;
163 set_bit(devno, &ir_core_dev_number);
164
165 return 0;
166};
167
168/**
169 * ir_unregister_class() - removes the sysfs for sysfs for
170 * /sys/class/irrcv/irrcv?
171 * @input_dev: the struct input_dev descriptor of the device
172 *
173 * This routine is used to unregister the syfs code for IR class
174 */
175void ir_unregister_class(struct input_dev *input_dev)
176{
177 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
178 struct kobject *kobj;
179
180 clear_bit(ir_dev->devno, &ir_core_dev_number);
181
182 kobj = &ir_dev->class_dev->kobj;
183
184 sysfs_remove_group(kobj, &ir_dev->attr);
185 device_destroy(ir_input_class, input_dev->dev.devt);
186
187 kfree(ir_dev->attr.name);
188}
189
190/*
191 * Init/exit code for the module. Basically, creates/removes /sys/class/irrcv
192 */
193
194static int __init ir_core_init(void)
195{
196 ir_input_class = class_create(THIS_MODULE, "irrcv");
197 if (IS_ERR(ir_input_class)) {
198 printk(KERN_ERR "ir_core: unable to register irrcv class\n");
199 return PTR_ERR(ir_input_class);
200 }
201
202 return 0;
203}
204
205static void __exit ir_core_exit(void)
206{
207 class_destroy(ir_input_class);
208}
209
210module_init(ir_core_init);
211module_exit(ir_core_exit);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index 7364b9642d00..fd8e1f45be36 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -423,14 +423,15 @@ static void vv_callback(struct saa7146_dev *dev, unsigned long status)
423 } 423 }
424} 424}
425 425
426int saa7146_vv_devinit(struct saa7146_dev *dev)
427{
428 return v4l2_device_register(&dev->pci->dev, &dev->v4l2_dev);
429}
430EXPORT_SYMBOL_GPL(saa7146_vv_devinit);
431
426int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv) 432int saa7146_vv_init(struct saa7146_dev* dev, struct saa7146_ext_vv *ext_vv)
427{ 433{
428 struct saa7146_vv *vv; 434 struct saa7146_vv *vv;
429 int err;
430
431 err = v4l2_device_register(&dev->pci->dev, &dev->v4l2_dev);
432 if (err)
433 return err;
434 435
435 vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL); 436 vv = kzalloc(sizeof(struct saa7146_vv), GFP_KERNEL);
436 if (vv == NULL) { 437 if (vv == NULL) {
diff --git a/drivers/media/common/tuners/tuner-types.c b/drivers/media/common/tuners/tuner-types.c
index 2b876f3988c1..d9aaaca620c9 100644
--- a/drivers/media/common/tuners/tuner-types.c
+++ b/drivers/media/common/tuners/tuner-types.c
@@ -1337,6 +1337,22 @@ static struct tuner_params tuner_philips_cu1216l_params[] = {
1337 }, 1337 },
1338}; 1338};
1339 1339
1340/* ---------------------- TUNER_SONY_BTF_PXN01Z ------------------------ */
1341
1342static struct tuner_range tuner_sony_btf_pxn01z_ranges[] = {
1343 { 16 * 137.25 /*MHz*/, 0x8e, 0x01, },
1344 { 16 * 367.25 /*MHz*/, 0x8e, 0x02, },
1345 { 16 * 999.99 , 0x8e, 0x04, },
1346};
1347
1348static struct tuner_params tuner_sony_btf_pxn01z_params[] = {
1349 {
1350 .type = TUNER_PARAM_TYPE_NTSC,
1351 .ranges = tuner_sony_btf_pxn01z_ranges,
1352 .count = ARRAY_SIZE(tuner_sony_btf_pxn01z_ranges),
1353 },
1354};
1355
1340/* --------------------------------------------------------------------- */ 1356/* --------------------------------------------------------------------- */
1341 1357
1342struct tunertype tuners[] = { 1358struct tunertype tuners[] = {
@@ -1805,6 +1821,11 @@ struct tunertype tuners[] = {
1805 .name = "NXP TDA18271", 1821 .name = "NXP TDA18271",
1806 /* see tda18271-fe.c for details */ 1822 /* see tda18271-fe.c for details */
1807 }, 1823 },
1824 [TUNER_SONY_BTF_PXN01Z] = {
1825 .name = "Sony BTF-Pxn01Z",
1826 .params = tuner_sony_btf_pxn01z_params,
1827 .count = ARRAY_SIZE(tuner_sony_btf_pxn01z_params),
1828 },
1808}; 1829};
1809EXPORT_SYMBOL(tuners); 1830EXPORT_SYMBOL(tuners);
1810 1831
diff --git a/drivers/media/common/tuners/tuner-xc2028.c b/drivers/media/common/tuners/tuner-xc2028.c
index f270e605da83..be51c294b375 100644
--- a/drivers/media/common/tuners/tuner-xc2028.c
+++ b/drivers/media/common/tuners/tuner-xc2028.c
@@ -917,30 +917,68 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
917 * that xc2028 will be in a safe state. 917 * that xc2028 will be in a safe state.
918 * Maybe this might also be needed for DTV. 918 * Maybe this might also be needed for DTV.
919 */ 919 */
920 if (new_mode == T_ANALOG_TV) 920 if (new_mode == T_ANALOG_TV) {
921 rc = send_seq(priv, {0x00, 0x00}); 921 rc = send_seq(priv, {0x00, 0x00});
922 922
923 /* 923 /* Analog modes require offset = 0 */
924 * Digital modes require an offset to adjust to the 924 } else {
925 * proper frequency. 925 /*
926 * Analog modes require offset = 0 926 * Digital modes require an offset to adjust to the
927 */ 927 * proper frequency. The offset depends on what
928 if (new_mode == T_DIGITAL_TV) { 928 * firmware version is used.
929 /* Sets the offset according with firmware */ 929 */
930
931 /*
932 * Adjust to the center frequency. This is calculated by the
933 * formula: offset = 1.25MHz - BW/2
934 * For DTV 7/8, the firmware uses BW = 8000, so it needs a
935 * further adjustment to get the frequency center on VHF
936 */
930 if (priv->cur_fw.type & DTV6) 937 if (priv->cur_fw.type & DTV6)
931 offset = 1750000; 938 offset = 1750000;
932 else if (priv->cur_fw.type & DTV7) 939 else if (priv->cur_fw.type & DTV7)
933 offset = 2250000; 940 offset = 2250000;
934 else /* DTV8 or DTV78 */ 941 else /* DTV8 or DTV78 */
935 offset = 2750000; 942 offset = 2750000;
943 if ((priv->cur_fw.type & DTV78) && freq < 470000000)
944 offset -= 500000;
936 945
937 /* 946 /*
938 * We must adjust the offset by 500kHz when 947 * xc3028 additional "magic"
939 * tuning a 7MHz VHF channel with DTV78 firmware 948 * Depending on the firmware version, it needs some adjustments
940 * (used in Australia, Italy and Germany) 949 * to properly centralize the frequency. This seems to be
950 * needed to compensate the SCODE table adjustments made by
951 * newer firmwares
941 */ 952 */
942 if ((priv->cur_fw.type & DTV78) && freq < 470000000) 953
943 offset -= 500000; 954#if 1
955 /*
956 * The proper adjustment would be to do it at s-code table.
957 * However, this didn't work, as reported by
958 * Robert Lowery <rglowery@exemail.com.au>
959 */
960
961 if (priv->cur_fw.type & DTV7)
962 offset += 500000;
963
964#else
965 /*
966 * Still need tests for XC3028L (firmware 3.2 or upper)
967 * So, for now, let's just comment the per-firmware
968 * version of this change. Reports with xc3028l working
969 * with and without the lines bellow are welcome
970 */
971
972 if (priv->firm_version < 0x0302) {
973 if (priv->cur_fw.type & DTV7)
974 offset += 500000;
975 } else {
976 if (priv->cur_fw.type & DTV7)
977 offset -= 300000;
978 else if (type != ATSC) /* DVB @6MHz, DTV 8 and DTV 7/8 */
979 offset += 200000;
980 }
981#endif
944 } 982 }
945 983
946 div = (freq - offset + DIV / 2) / DIV; 984 div = (freq - offset + DIV / 2) / DIV;
@@ -1097,17 +1135,24 @@ static int xc2028_set_params(struct dvb_frontend *fe,
1097 1135
1098 /* All S-code tables need a 200kHz shift */ 1136 /* All S-code tables need a 200kHz shift */
1099 if (priv->ctrl.demod) { 1137 if (priv->ctrl.demod) {
1100 demod = priv->ctrl.demod + 200; 1138 demod = priv->ctrl.demod;
1139
1140 /*
1141 * Newer firmwares require a 200 kHz offset only for ATSC
1142 */
1143 if (type == ATSC || priv->firm_version < 0x0302)
1144 demod += 200;
1101 /* 1145 /*
1102 * The DTV7 S-code table needs a 700 kHz shift. 1146 * The DTV7 S-code table needs a 700 kHz shift.
1103 * Thanks to Terry Wu <terrywu2009@gmail.com> for reporting this
1104 * 1147 *
1105 * DTV7 is only used in Australia. Germany or Italy may also 1148 * DTV7 is only used in Australia. Germany or Italy may also
1106 * use this firmware after initialization, but a tune to a UHF 1149 * use this firmware after initialization, but a tune to a UHF
1107 * channel should then cause DTV78 to be used. 1150 * channel should then cause DTV78 to be used.
1151 *
1152 * Unfortunately, on real-field tests, the s-code offset
1153 * didn't work as expected, as reported by
1154 * Robert Lowery <rglowery@exemail.com.au>
1108 */ 1155 */
1109 if (type & DTV7)
1110 demod += 500;
1111 } 1156 }
1112 1157
1113 return generic_set_freq(fe, p->frequency, 1158 return generic_set_freq(fe, p->frequency,
diff --git a/drivers/media/dvb/Kconfig b/drivers/media/dvb/Kconfig
index cf8f65f309da..161ccfd471cb 100644
--- a/drivers/media/dvb/Kconfig
+++ b/drivers/media/dvb/Kconfig
@@ -76,6 +76,10 @@ comment "Supported Mantis Adapters"
76 depends on DVB_CORE && PCI && I2C 76 depends on DVB_CORE && PCI && I2C
77 source "drivers/media/dvb/mantis/Kconfig" 77 source "drivers/media/dvb/mantis/Kconfig"
78 78
79comment "Supported nGene Adapters"
80 depends on DVB_CORE && PCI && I2C
81 source "drivers/media/dvb/ngene/Kconfig"
82
79comment "Supported DVB Frontends" 83comment "Supported DVB Frontends"
80 depends on DVB_CORE 84 depends on DVB_CORE
81source "drivers/media/dvb/frontends/Kconfig" 85source "drivers/media/dvb/frontends/Kconfig"
diff --git a/drivers/media/dvb/Makefile b/drivers/media/dvb/Makefile
index c12922c3659b..a1a08758a6f2 100644
--- a/drivers/media/dvb/Makefile
+++ b/drivers/media/dvb/Makefile
@@ -14,6 +14,7 @@ obj-y := dvb-core/ \
14 siano/ \ 14 siano/ \
15 dm1105/ \ 15 dm1105/ \
16 pt1/ \ 16 pt1/ \
17 mantis/ 17 mantis/ \
18 ngene/
18 19
19obj-$(CONFIG_DVB_FIREDTV) += firewire/ 20obj-$(CONFIG_DVB_FIREDTV) += firewire/
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c
index a24c125331f0..99d62094f908 100644
--- a/drivers/media/dvb/bt8xx/bt878.c
+++ b/drivers/media/dvb/bt8xx/bt878.c
@@ -576,43 +576,30 @@ static struct pci_driver bt878_pci_driver = {
576 .remove = __devexit_p(bt878_remove), 576 .remove = __devexit_p(bt878_remove),
577}; 577};
578 578
579static int bt878_pci_driver_registered;
580
581/*******************************/ 579/*******************************/
582/* Module management functions */ 580/* Module management functions */
583/*******************************/ 581/*******************************/
584 582
585static int bt878_init_module(void) 583static int __init bt878_init_module(void)
586{ 584{
587 bt878_num = 0; 585 bt878_num = 0;
588 bt878_pci_driver_registered = 0;
589 586
590 printk(KERN_INFO "bt878: AUDIO driver version %d.%d.%d loaded\n", 587 printk(KERN_INFO "bt878: AUDIO driver version %d.%d.%d loaded\n",
591 (BT878_VERSION_CODE >> 16) & 0xff, 588 (BT878_VERSION_CODE >> 16) & 0xff,
592 (BT878_VERSION_CODE >> 8) & 0xff, 589 (BT878_VERSION_CODE >> 8) & 0xff,
593 BT878_VERSION_CODE & 0xff); 590 BT878_VERSION_CODE & 0xff);
594/* 591
595 bt878_check_chipset();
596*/
597 /* later we register inside of bt878_find_audio_dma()
598 * because we may want to ignore certain cards */
599 bt878_pci_driver_registered = 1;
600 return pci_register_driver(&bt878_pci_driver); 592 return pci_register_driver(&bt878_pci_driver);
601} 593}
602 594
603static void bt878_cleanup_module(void) 595static void __exit bt878_cleanup_module(void)
604{ 596{
605 if (bt878_pci_driver_registered) { 597 pci_unregister_driver(&bt878_pci_driver);
606 bt878_pci_driver_registered = 0;
607 pci_unregister_driver(&bt878_pci_driver);
608 }
609 return;
610} 598}
611 599
612module_init(bt878_init_module); 600module_init(bt878_init_module);
613module_exit(bt878_cleanup_module); 601module_exit(bt878_cleanup_module);
614 602
615//MODULE_AUTHOR("XXX");
616MODULE_LICENSE("GPL"); 603MODULE_LICENSE("GPL");
617 604
618/* 605/*
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 91353a6faf1d..8b0cde38984d 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1352,8 +1352,7 @@ static int dst_get_tuna(struct dst_state *state)
1352 return retval; 1352 return retval;
1353 } 1353 }
1354 if ((state->type_flags & DST_TYPE_HAS_VLF) && 1354 if ((state->type_flags & DST_TYPE_HAS_VLF) &&
1355 !(state->dst_type == DST_TYPE_IS_CABLE) && 1355 !(state->dst_type == DST_TYPE_IS_ATSC)) {
1356 !(state->dst_type == DST_TYPE_IS_ATSC)) {
1357 1356
1358 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) { 1357 if (state->rx_tuna[9] != dst_check_sum(&state->rx_tuna[0], 9)) {
1359 dprintk(verbose, DST_INFO, 1, "checksum failure ? "); 1358 dprintk(verbose, DST_INFO, 1, "checksum failure ? ");
@@ -1820,8 +1819,13 @@ static struct dvb_frontend_ops dst_dvbc_ops = {
1820 .frequency_max = 858000000, 1819 .frequency_max = 858000000,
1821 .symbol_rate_min = 1000000, 1820 .symbol_rate_min = 1000000,
1822 .symbol_rate_max = 45000000, 1821 .symbol_rate_max = 45000000,
1823 /* . symbol_rate_tolerance = ???,*/ 1822 .caps = FE_CAN_FEC_AUTO |
1824 .caps = FE_CAN_FEC_AUTO | FE_CAN_QAM_AUTO 1823 FE_CAN_QAM_AUTO |
1824 FE_CAN_QAM_16 |
1825 FE_CAN_QAM_32 |
1826 FE_CAN_QAM_64 |
1827 FE_CAN_QAM_128 |
1828 FE_CAN_QAM_256
1825 }, 1829 },
1826 1830
1827 .release = dst_release, 1831 .release = dst_release,
diff --git a/drivers/media/dvb/dm1105/Kconfig b/drivers/media/dvb/dm1105/Kconfig
index de3eeb0a8d6e..695239227cb7 100644
--- a/drivers/media/dvb/dm1105/Kconfig
+++ b/drivers/media/dvb/dm1105/Kconfig
@@ -8,6 +8,7 @@ config DVB_DM1105
8 select DVB_STB6000 if !DVB_FE_CUSTOMISE 8 select DVB_STB6000 if !DVB_FE_CUSTOMISE
9 select DVB_CX24116 if !DVB_FE_CUSTOMISE 9 select DVB_CX24116 if !DVB_FE_CUSTOMISE
10 select DVB_SI21XX if !DVB_FE_CUSTOMISE 10 select DVB_SI21XX if !DVB_FE_CUSTOMISE
11 select DVB_DS3000 if !DVB_FE_CUSTOMISE
11 select VIDEO_IR 12 select VIDEO_IR
12 help 13 help
13 Support for cards based on the SDMC DM1105 PCI chip like 14 Support for cards based on the SDMC DM1105 PCI chip like
diff --git a/drivers/media/dvb/dm1105/dm1105.c b/drivers/media/dvb/dm1105/dm1105.c
index f0f483ac8b89..383cca378b8c 100644
--- a/drivers/media/dvb/dm1105/dm1105.c
+++ b/drivers/media/dvb/dm1105/dm1105.c
@@ -43,6 +43,7 @@
43#include "si21xx.h" 43#include "si21xx.h"
44#include "cx24116.h" 44#include "cx24116.h"
45#include "z0194a.h" 45#include "z0194a.h"
46#include "ds3000.h"
46 47
47#define UNSET (-1U) 48#define UNSET (-1U)
48 49
@@ -269,7 +270,7 @@ struct infrared {
269 u32 ir_command; 270 u32 ir_command;
270}; 271};
271 272
272struct dm1105dvb { 273struct dm1105_dev {
273 /* pci */ 274 /* pci */
274 struct pci_dev *pdev; 275 struct pci_dev *pdev;
275 u8 __iomem *io_mem; 276 u8 __iomem *io_mem;
@@ -308,31 +309,47 @@ struct dm1105dvb {
308 spinlock_t lock; 309 spinlock_t lock;
309}; 310};
310 311
311#define dm_io_mem(reg) ((unsigned long)(&dm1105dvb->io_mem[reg])) 312#define dm_io_mem(reg) ((unsigned long)(&dev->io_mem[reg]))
313
314#define dm_readb(reg) inb(dm_io_mem(reg))
315#define dm_writeb(reg, value) outb((value), (dm_io_mem(reg)))
316
317#define dm_readw(reg) inw(dm_io_mem(reg))
318#define dm_writew(reg, value) outw((value), (dm_io_mem(reg)))
319
320#define dm_readl(reg) inl(dm_io_mem(reg))
321#define dm_writel(reg, value) outl((value), (dm_io_mem(reg)))
322
323#define dm_andorl(reg, mask, value) \
324 outl((inl(dm_io_mem(reg)) & ~(mask)) |\
325 ((value) & (mask)), (dm_io_mem(reg)))
326
327#define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit))
328#define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0)
312 329
313static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap, 330static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap,
314 struct i2c_msg *msgs, int num) 331 struct i2c_msg *msgs, int num)
315{ 332{
316 struct dm1105dvb *dm1105dvb ; 333 struct dm1105_dev *dev ;
317 334
318 int addr, rc, i, j, k, len, byte, data; 335 int addr, rc, i, j, k, len, byte, data;
319 u8 status; 336 u8 status;
320 337
321 dm1105dvb = i2c_adap->algo_data; 338 dev = i2c_adap->algo_data;
322 for (i = 0; i < num; i++) { 339 for (i = 0; i < num; i++) {
323 outb(0x00, dm_io_mem(DM1105_I2CCTR)); 340 dm_writeb(DM1105_I2CCTR, 0x00);
324 if (msgs[i].flags & I2C_M_RD) { 341 if (msgs[i].flags & I2C_M_RD) {
325 /* read bytes */ 342 /* read bytes */
326 addr = msgs[i].addr << 1; 343 addr = msgs[i].addr << 1;
327 addr |= 1; 344 addr |= 1;
328 outb(addr, dm_io_mem(DM1105_I2CDAT)); 345 dm_writeb(DM1105_I2CDAT, addr);
329 for (byte = 0; byte < msgs[i].len; byte++) 346 for (byte = 0; byte < msgs[i].len; byte++)
330 outb(0, dm_io_mem(DM1105_I2CDAT + byte + 1)); 347 dm_writeb(DM1105_I2CDAT + byte + 1, 0);
331 348
332 outb(0x81 + msgs[i].len, dm_io_mem(DM1105_I2CCTR)); 349 dm_writeb(DM1105_I2CCTR, 0x81 + msgs[i].len);
333 for (j = 0; j < 55; j++) { 350 for (j = 0; j < 55; j++) {
334 mdelay(10); 351 mdelay(10);
335 status = inb(dm_io_mem(DM1105_I2CSTS)); 352 status = dm_readb(DM1105_I2CSTS);
336 if ((status & 0xc0) == 0x40) 353 if ((status & 0xc0) == 0x40)
337 break; 354 break;
338 } 355 }
@@ -340,56 +357,54 @@ static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap,
340 return -1; 357 return -1;
341 358
342 for (byte = 0; byte < msgs[i].len; byte++) { 359 for (byte = 0; byte < msgs[i].len; byte++) {
343 rc = inb(dm_io_mem(DM1105_I2CDAT + byte + 1)); 360 rc = dm_readb(DM1105_I2CDAT + byte + 1);
344 if (rc < 0) 361 if (rc < 0)
345 goto err; 362 goto err;
346 msgs[i].buf[byte] = rc; 363 msgs[i].buf[byte] = rc;
347 } 364 }
348 } else { 365 } else if ((msgs[i].buf[0] == 0xf7) && (msgs[i].addr == 0x55)) {
349 if ((msgs[i].buf[0] == 0xf7) && (msgs[i].addr == 0x55)) { 366 /* prepaired for cx24116 firmware */
350 /* prepaired for cx24116 firmware */ 367 /* Write in small blocks */
351 /* Write in small blocks */ 368 len = msgs[i].len - 1;
352 len = msgs[i].len - 1; 369 k = 1;
353 k = 1; 370 do {
354 do { 371 dm_writeb(DM1105_I2CDAT, msgs[i].addr << 1);
355 outb(msgs[i].addr << 1, dm_io_mem(DM1105_I2CDAT)); 372 dm_writeb(DM1105_I2CDAT + 1, 0xf7);
356 outb(0xf7, dm_io_mem(DM1105_I2CDAT + 1)); 373 for (byte = 0; byte < (len > 48 ? 48 : len); byte++) {
357 for (byte = 0; byte < (len > 48 ? 48 : len); byte++) { 374 data = msgs[i].buf[k + byte];
358 data = msgs[i].buf[k+byte]; 375 dm_writeb(DM1105_I2CDAT + byte + 2, data);
359 outb(data, dm_io_mem(DM1105_I2CDAT + byte + 2));
360 }
361 outb(0x82 + (len > 48 ? 48 : len), dm_io_mem(DM1105_I2CCTR));
362 for (j = 0; j < 25; j++) {
363 mdelay(10);
364 status = inb(dm_io_mem(DM1105_I2CSTS));
365 if ((status & 0xc0) == 0x40)
366 break;
367 }
368
369 if (j >= 25)
370 return -1;
371
372 k += 48;
373 len -= 48;
374 } while (len > 0);
375 } else {
376 /* write bytes */
377 outb(msgs[i].addr<<1, dm_io_mem(DM1105_I2CDAT));
378 for (byte = 0; byte < msgs[i].len; byte++) {
379 data = msgs[i].buf[byte];
380 outb(data, dm_io_mem(DM1105_I2CDAT + byte + 1));
381 } 376 }
382 outb(0x81 + msgs[i].len, dm_io_mem(DM1105_I2CCTR)); 377 dm_writeb(DM1105_I2CCTR, 0x82 + (len > 48 ? 48 : len));
383 for (j = 0; j < 25; j++) { 378 for (j = 0; j < 25; j++) {
384 mdelay(10); 379 mdelay(10);
385 status = inb(dm_io_mem(DM1105_I2CSTS)); 380 status = dm_readb(DM1105_I2CSTS);
386 if ((status & 0xc0) == 0x40) 381 if ((status & 0xc0) == 0x40)
387 break; 382 break;
388 } 383 }
389 384
390 if (j >= 25) 385 if (j >= 25)
391 return -1; 386 return -1;
387
388 k += 48;
389 len -= 48;
390 } while (len > 0);
391 } else {
392 /* write bytes */
393 dm_writeb(DM1105_I2CDAT, msgs[i].addr << 1);
394 for (byte = 0; byte < msgs[i].len; byte++) {
395 data = msgs[i].buf[byte];
396 dm_writeb(DM1105_I2CDAT + byte + 1, data);
392 } 397 }
398 dm_writeb(DM1105_I2CCTR, 0x81 + msgs[i].len);
399 for (j = 0; j < 25; j++) {
400 mdelay(10);
401 status = dm_readb(DM1105_I2CSTS);
402 if ((status & 0xc0) == 0x40)
403 break;
404 }
405
406 if (j >= 25)
407 return -1;
393 } 408 }
394 } 409 }
395 return num; 410 return num;
@@ -407,22 +422,22 @@ static struct i2c_algorithm dm1105_algo = {
407 .functionality = functionality, 422 .functionality = functionality,
408}; 423};
409 424
410static inline struct dm1105dvb *feed_to_dm1105dvb(struct dvb_demux_feed *feed) 425static inline struct dm1105_dev *feed_to_dm1105_dev(struct dvb_demux_feed *feed)
411{ 426{
412 return container_of(feed->demux, struct dm1105dvb, demux); 427 return container_of(feed->demux, struct dm1105_dev, demux);
413} 428}
414 429
415static inline struct dm1105dvb *frontend_to_dm1105dvb(struct dvb_frontend *fe) 430static inline struct dm1105_dev *frontend_to_dm1105_dev(struct dvb_frontend *fe)
416{ 431{
417 return container_of(fe->dvb, struct dm1105dvb, dvb_adapter); 432 return container_of(fe->dvb, struct dm1105_dev, dvb_adapter);
418} 433}
419 434
420static int dm1105dvb_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 435static int dm1105_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
421{ 436{
422 struct dm1105dvb *dm1105dvb = frontend_to_dm1105dvb(fe); 437 struct dm1105_dev *dev = frontend_to_dm1105_dev(fe);
423 u32 lnb_mask, lnb_13v, lnb_18v, lnb_off; 438 u32 lnb_mask, lnb_13v, lnb_18v, lnb_off;
424 439
425 switch (dm1105dvb->boardnr) { 440 switch (dev->boardnr) {
426 case DM1105_BOARD_AXESS_DM05: 441 case DM1105_BOARD_AXESS_DM05:
427 lnb_mask = DM05_LNB_MASK; 442 lnb_mask = DM05_LNB_MASK;
428 lnb_off = DM05_LNB_OFF; 443 lnb_off = DM05_LNB_OFF;
@@ -438,62 +453,67 @@ static int dm1105dvb_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volta
438 lnb_18v = DM1105_LNB_18V; 453 lnb_18v = DM1105_LNB_18V;
439 } 454 }
440 455
441 outl(lnb_mask, dm_io_mem(DM1105_GPIOCTR)); 456 dm_writel(DM1105_GPIOCTR, lnb_mask);
442 if (voltage == SEC_VOLTAGE_18) 457 if (voltage == SEC_VOLTAGE_18)
443 outl(lnb_18v , dm_io_mem(DM1105_GPIOVAL)); 458 dm_writel(DM1105_GPIOVAL, lnb_18v);
444 else if (voltage == SEC_VOLTAGE_13) 459 else if (voltage == SEC_VOLTAGE_13)
445 outl(lnb_13v, dm_io_mem(DM1105_GPIOVAL)); 460 dm_writel(DM1105_GPIOVAL, lnb_13v);
446 else 461 else
447 outl(lnb_off, dm_io_mem(DM1105_GPIOVAL)); 462 dm_writel(DM1105_GPIOVAL, lnb_off);
448 463
449 return 0; 464 return 0;
450} 465}
451 466
452static void dm1105dvb_set_dma_addr(struct dm1105dvb *dm1105dvb) 467static void dm1105_set_dma_addr(struct dm1105_dev *dev)
453{ 468{
454 outl(cpu_to_le32(dm1105dvb->dma_addr), dm_io_mem(DM1105_STADR)); 469 dm_writel(DM1105_STADR, cpu_to_le32(dev->dma_addr));
455} 470}
456 471
457static int __devinit dm1105dvb_dma_map(struct dm1105dvb *dm1105dvb) 472static int __devinit dm1105_dma_map(struct dm1105_dev *dev)
458{ 473{
459 dm1105dvb->ts_buf = pci_alloc_consistent(dm1105dvb->pdev, 6*DM1105_DMA_BYTES, &dm1105dvb->dma_addr); 474 dev->ts_buf = pci_alloc_consistent(dev->pdev,
475 6 * DM1105_DMA_BYTES,
476 &dev->dma_addr);
460 477
461 return !dm1105dvb->ts_buf; 478 return !dev->ts_buf;
462} 479}
463 480
464static void dm1105dvb_dma_unmap(struct dm1105dvb *dm1105dvb) 481static void dm1105_dma_unmap(struct dm1105_dev *dev)
465{ 482{
466 pci_free_consistent(dm1105dvb->pdev, 6*DM1105_DMA_BYTES, dm1105dvb->ts_buf, dm1105dvb->dma_addr); 483 pci_free_consistent(dev->pdev,
484 6 * DM1105_DMA_BYTES,
485 dev->ts_buf,
486 dev->dma_addr);
467} 487}
468 488
469static void dm1105dvb_enable_irqs(struct dm1105dvb *dm1105dvb) 489static void dm1105_enable_irqs(struct dm1105_dev *dev)
470{ 490{
471 outb(INTMAK_ALLMASK, dm_io_mem(DM1105_INTMAK)); 491 dm_writeb(DM1105_INTMAK, INTMAK_ALLMASK);
472 outb(1, dm_io_mem(DM1105_CR)); 492 dm_writeb(DM1105_CR, 1);
473} 493}
474 494
475static void dm1105dvb_disable_irqs(struct dm1105dvb *dm1105dvb) 495static void dm1105_disable_irqs(struct dm1105_dev *dev)
476{ 496{
477 outb(INTMAK_IRM, dm_io_mem(DM1105_INTMAK)); 497 dm_writeb(DM1105_INTMAK, INTMAK_IRM);
478 outb(0, dm_io_mem(DM1105_CR)); 498 dm_writeb(DM1105_CR, 0);
479} 499}
480 500
481static int dm1105dvb_start_feed(struct dvb_demux_feed *f) 501static int dm1105_start_feed(struct dvb_demux_feed *f)
482{ 502{
483 struct dm1105dvb *dm1105dvb = feed_to_dm1105dvb(f); 503 struct dm1105_dev *dev = feed_to_dm1105_dev(f);
484 504
485 if (dm1105dvb->full_ts_users++ == 0) 505 if (dev->full_ts_users++ == 0)
486 dm1105dvb_enable_irqs(dm1105dvb); 506 dm1105_enable_irqs(dev);
487 507
488 return 0; 508 return 0;
489} 509}
490 510
491static int dm1105dvb_stop_feed(struct dvb_demux_feed *f) 511static int dm1105_stop_feed(struct dvb_demux_feed *f)
492{ 512{
493 struct dm1105dvb *dm1105dvb = feed_to_dm1105dvb(f); 513 struct dm1105_dev *dev = feed_to_dm1105_dev(f);
494 514
495 if (--dm1105dvb->full_ts_users == 0) 515 if (--dev->full_ts_users == 0)
496 dm1105dvb_disable_irqs(dm1105dvb); 516 dm1105_disable_irqs(dev);
497 517
498 return 0; 518 return 0;
499} 519}
@@ -517,68 +537,64 @@ static void dm1105_emit_key(struct work_struct *work)
517/* work handler */ 537/* work handler */
518static void dm1105_dmx_buffer(struct work_struct *work) 538static void dm1105_dmx_buffer(struct work_struct *work)
519{ 539{
520 struct dm1105dvb *dm1105dvb = 540 struct dm1105_dev *dev = container_of(work, struct dm1105_dev, work);
521 container_of(work, struct dm1105dvb, work);
522 unsigned int nbpackets; 541 unsigned int nbpackets;
523 u32 oldwrp = dm1105dvb->wrp; 542 u32 oldwrp = dev->wrp;
524 u32 nextwrp = dm1105dvb->nextwrp; 543 u32 nextwrp = dev->nextwrp;
525 544
526 if (!((dm1105dvb->ts_buf[oldwrp] == 0x47) && 545 if (!((dev->ts_buf[oldwrp] == 0x47) &&
527 (dm1105dvb->ts_buf[oldwrp + 188] == 0x47) && 546 (dev->ts_buf[oldwrp + 188] == 0x47) &&
528 (dm1105dvb->ts_buf[oldwrp + 188 * 2] == 0x47))) { 547 (dev->ts_buf[oldwrp + 188 * 2] == 0x47))) {
529 dm1105dvb->PacketErrorCount++; 548 dev->PacketErrorCount++;
530 /* bad packet found */ 549 /* bad packet found */
531 if ((dm1105dvb->PacketErrorCount >= 2) && 550 if ((dev->PacketErrorCount >= 2) &&
532 (dm1105dvb->dmarst == 0)) { 551 (dev->dmarst == 0)) {
533 outb(1, dm_io_mem(DM1105_RST)); 552 dm_writeb(DM1105_RST, 1);
534 dm1105dvb->wrp = 0; 553 dev->wrp = 0;
535 dm1105dvb->PacketErrorCount = 0; 554 dev->PacketErrorCount = 0;
536 dm1105dvb->dmarst = 0; 555 dev->dmarst = 0;
537 return; 556 return;
538 } 557 }
539 } 558 }
540 559
541 if (nextwrp < oldwrp) { 560 if (nextwrp < oldwrp) {
542 memcpy(dm1105dvb->ts_buf + dm1105dvb->buffer_size, 561 memcpy(dev->ts_buf + dev->buffer_size, dev->ts_buf, nextwrp);
543 dm1105dvb->ts_buf, nextwrp); 562 nbpackets = ((dev->buffer_size - oldwrp) + nextwrp) / 188;
544 nbpackets = ((dm1105dvb->buffer_size - oldwrp) + nextwrp) / 188;
545 } else 563 } else
546 nbpackets = (nextwrp - oldwrp) / 188; 564 nbpackets = (nextwrp - oldwrp) / 188;
547 565
548 dm1105dvb->wrp = nextwrp; 566 dev->wrp = nextwrp;
549 dvb_dmx_swfilter_packets(&dm1105dvb->demux, 567 dvb_dmx_swfilter_packets(&dev->demux, &dev->ts_buf[oldwrp], nbpackets);
550 &dm1105dvb->ts_buf[oldwrp], nbpackets);
551} 568}
552 569
553static irqreturn_t dm1105dvb_irq(int irq, void *dev_id) 570static irqreturn_t dm1105_irq(int irq, void *dev_id)
554{ 571{
555 struct dm1105dvb *dm1105dvb = dev_id; 572 struct dm1105_dev *dev = dev_id;
556 573
557 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */ 574 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
558 unsigned int intsts = inb(dm_io_mem(DM1105_INTSTS)); 575 unsigned int intsts = dm_readb(DM1105_INTSTS);
559 outb(intsts, dm_io_mem(DM1105_INTSTS)); 576 dm_writeb(DM1105_INTSTS, intsts);
560 577
561 switch (intsts) { 578 switch (intsts) {
562 case INTSTS_TSIRQ: 579 case INTSTS_TSIRQ:
563 case (INTSTS_TSIRQ | INTSTS_IR): 580 case (INTSTS_TSIRQ | INTSTS_IR):
564 dm1105dvb->nextwrp = inl(dm_io_mem(DM1105_WRP)) - 581 dev->nextwrp = dm_readl(DM1105_WRP) - dm_readl(DM1105_STADR);
565 inl(dm_io_mem(DM1105_STADR)); 582 queue_work(dev->wq, &dev->work);
566 queue_work(dm1105dvb->wq, &dm1105dvb->work);
567 break; 583 break;
568 case INTSTS_IR: 584 case INTSTS_IR:
569 dm1105dvb->ir.ir_command = inl(dm_io_mem(DM1105_IRCODE)); 585 dev->ir.ir_command = dm_readl(DM1105_IRCODE);
570 schedule_work(&dm1105dvb->ir.work); 586 schedule_work(&dev->ir.work);
571 break; 587 break;
572 } 588 }
573 589
574 return IRQ_HANDLED; 590 return IRQ_HANDLED;
575} 591}
576 592
577int __devinit dm1105_ir_init(struct dm1105dvb *dm1105) 593int __devinit dm1105_ir_init(struct dm1105_dev *dm1105)
578{ 594{
579 struct input_dev *input_dev; 595 struct input_dev *input_dev;
580 struct ir_scancode_table *ir_codes = &ir_codes_dm1105_nec_table; 596 struct ir_scancode_table *ir_codes = &ir_codes_dm1105_nec_table;
581 int ir_type = IR_TYPE_OTHER; 597 u64 ir_type = IR_TYPE_OTHER;
582 int err = -ENOMEM; 598 int err = -ENOMEM;
583 599
584 input_dev = input_allocate_device(); 600 input_dev = input_allocate_device();
@@ -611,51 +627,51 @@ int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)
611 627
612 INIT_WORK(&dm1105->ir.work, dm1105_emit_key); 628 INIT_WORK(&dm1105->ir.work, dm1105_emit_key);
613 629
614 err = ir_input_register(input_dev, ir_codes); 630 err = ir_input_register(input_dev, ir_codes, NULL);
615 631
616 return err; 632 return err;
617} 633}
618 634
619void __devexit dm1105_ir_exit(struct dm1105dvb *dm1105) 635void __devexit dm1105_ir_exit(struct dm1105_dev *dm1105)
620{ 636{
621 ir_input_unregister(dm1105->ir.input_dev); 637 ir_input_unregister(dm1105->ir.input_dev);
622} 638}
623 639
624static int __devinit dm1105dvb_hw_init(struct dm1105dvb *dm1105dvb) 640static int __devinit dm1105_hw_init(struct dm1105_dev *dev)
625{ 641{
626 dm1105dvb_disable_irqs(dm1105dvb); 642 dm1105_disable_irqs(dev);
627 643
628 outb(0, dm_io_mem(DM1105_HOST_CTR)); 644 dm_writeb(DM1105_HOST_CTR, 0);
629 645
630 /*DATALEN 188,*/ 646 /*DATALEN 188,*/
631 outb(188, dm_io_mem(DM1105_DTALENTH)); 647 dm_writeb(DM1105_DTALENTH, 188);
632 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/ 648 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
633 outw(0xc10a, dm_io_mem(DM1105_TSCTR)); 649 dm_writew(DM1105_TSCTR, 0xc10a);
634 650
635 /* map DMA and set address */ 651 /* map DMA and set address */
636 dm1105dvb_dma_map(dm1105dvb); 652 dm1105_dma_map(dev);
637 dm1105dvb_set_dma_addr(dm1105dvb); 653 dm1105_set_dma_addr(dev);
638 /* big buffer */ 654 /* big buffer */
639 outl(5*DM1105_DMA_BYTES, dm_io_mem(DM1105_RLEN)); 655 dm_writel(DM1105_RLEN, 5 * DM1105_DMA_BYTES);
640 outb(47, dm_io_mem(DM1105_INTCNT)); 656 dm_writeb(DM1105_INTCNT, 47);
641 657
642 /* IR NEC mode enable */ 658 /* IR NEC mode enable */
643 outb((DM1105_IR_EN | DM1105_SYS_CHK), dm_io_mem(DM1105_IRCTR)); 659 dm_writeb(DM1105_IRCTR, (DM1105_IR_EN | DM1105_SYS_CHK));
644 outb(0, dm_io_mem(DM1105_IRMODE)); 660 dm_writeb(DM1105_IRMODE, 0);
645 outw(0, dm_io_mem(DM1105_SYSTEMCODE)); 661 dm_writew(DM1105_SYSTEMCODE, 0);
646 662
647 return 0; 663 return 0;
648} 664}
649 665
650static void dm1105dvb_hw_exit(struct dm1105dvb *dm1105dvb) 666static void dm1105_hw_exit(struct dm1105_dev *dev)
651{ 667{
652 dm1105dvb_disable_irqs(dm1105dvb); 668 dm1105_disable_irqs(dev);
653 669
654 /* IR disable */ 670 /* IR disable */
655 outb(0, dm_io_mem(DM1105_IRCTR)); 671 dm_writeb(DM1105_IRCTR, 0);
656 outb(INTMAK_NONEMASK, dm_io_mem(DM1105_INTMAK)); 672 dm_writeb(DM1105_INTMAK, INTMAK_NONEMASK);
657 673
658 dm1105dvb_dma_unmap(dm1105dvb); 674 dm1105_dma_unmap(dev);
659} 675}
660 676
661static struct stv0299_config sharp_z0194a_config = { 677static struct stv0299_config sharp_z0194a_config = {
@@ -685,70 +701,79 @@ static struct cx24116_config serit_sp2633_config = {
685 .demod_address = 0x55, 701 .demod_address = 0x55,
686}; 702};
687 703
688static int __devinit frontend_init(struct dm1105dvb *dm1105dvb) 704static struct ds3000_config dvbworld_ds3000_config = {
705 .demod_address = 0x68,
706};
707
708static int __devinit frontend_init(struct dm1105_dev *dev)
689{ 709{
690 int ret; 710 int ret;
691 711
692 switch (dm1105dvb->boardnr) { 712 switch (dev->boardnr) {
693 case DM1105_BOARD_DVBWORLD_2004: 713 case DM1105_BOARD_DVBWORLD_2004:
694 dm1105dvb->fe = dvb_attach( 714 dev->fe = dvb_attach(
695 cx24116_attach, &serit_sp2633_config, 715 cx24116_attach, &serit_sp2633_config,
696 &dm1105dvb->i2c_adap); 716 &dev->i2c_adap);
697 if (dm1105dvb->fe) 717 if (dev->fe) {
698 dm1105dvb->fe->ops.set_voltage = dm1105dvb_set_voltage; 718 dev->fe->ops.set_voltage = dm1105_set_voltage;
719 break;
720 }
721
722 dev->fe = dvb_attach(
723 ds3000_attach, &dvbworld_ds3000_config,
724 &dev->i2c_adap);
725 if (dev->fe)
726 dev->fe->ops.set_voltage = dm1105_set_voltage;
699 727
700 break; 728 break;
701 case DM1105_BOARD_DVBWORLD_2002: 729 case DM1105_BOARD_DVBWORLD_2002:
702 case DM1105_BOARD_AXESS_DM05: 730 case DM1105_BOARD_AXESS_DM05:
703 default: 731 default:
704 dm1105dvb->fe = dvb_attach( 732 dev->fe = dvb_attach(
705 stv0299_attach, &sharp_z0194a_config, 733 stv0299_attach, &sharp_z0194a_config,
706 &dm1105dvb->i2c_adap); 734 &dev->i2c_adap);
707 if (dm1105dvb->fe) { 735 if (dev->fe) {
708 dm1105dvb->fe->ops.set_voltage = 736 dev->fe->ops.set_voltage = dm1105_set_voltage;
709 dm1105dvb_set_voltage; 737 dvb_attach(dvb_pll_attach, dev->fe, 0x60,
710 dvb_attach(dvb_pll_attach, dm1105dvb->fe, 0x60, 738 &dev->i2c_adap, DVB_PLL_OPERA1);
711 &dm1105dvb->i2c_adap, DVB_PLL_OPERA1);
712 break; 739 break;
713 } 740 }
714 741
715 dm1105dvb->fe = dvb_attach( 742 dev->fe = dvb_attach(
716 stv0288_attach, &earda_config, 743 stv0288_attach, &earda_config,
717 &dm1105dvb->i2c_adap); 744 &dev->i2c_adap);
718 if (dm1105dvb->fe) { 745 if (dev->fe) {
719 dm1105dvb->fe->ops.set_voltage = 746 dev->fe->ops.set_voltage = dm1105_set_voltage;
720 dm1105dvb_set_voltage; 747 dvb_attach(stb6000_attach, dev->fe, 0x61,
721 dvb_attach(stb6000_attach, dm1105dvb->fe, 0x61, 748 &dev->i2c_adap);
722 &dm1105dvb->i2c_adap);
723 break; 749 break;
724 } 750 }
725 751
726 dm1105dvb->fe = dvb_attach( 752 dev->fe = dvb_attach(
727 si21xx_attach, &serit_config, 753 si21xx_attach, &serit_config,
728 &dm1105dvb->i2c_adap); 754 &dev->i2c_adap);
729 if (dm1105dvb->fe) 755 if (dev->fe)
730 dm1105dvb->fe->ops.set_voltage = 756 dev->fe->ops.set_voltage = dm1105_set_voltage;
731 dm1105dvb_set_voltage;
732 757
733 } 758 }
734 759
735 if (!dm1105dvb->fe) { 760 if (!dev->fe) {
736 dev_err(&dm1105dvb->pdev->dev, "could not attach frontend\n"); 761 dev_err(&dev->pdev->dev, "could not attach frontend\n");
737 return -ENODEV; 762 return -ENODEV;
738 } 763 }
739 764
740 ret = dvb_register_frontend(&dm1105dvb->dvb_adapter, dm1105dvb->fe); 765 ret = dvb_register_frontend(&dev->dvb_adapter, dev->fe);
741 if (ret < 0) { 766 if (ret < 0) {
742 if (dm1105dvb->fe->ops.release) 767 if (dev->fe->ops.release)
743 dm1105dvb->fe->ops.release(dm1105dvb->fe); 768 dev->fe->ops.release(dev->fe);
744 dm1105dvb->fe = NULL; 769 dev->fe = NULL;
745 return ret; 770 return ret;
746 } 771 }
747 772
748 return 0; 773 return 0;
749} 774}
750 775
751static void __devinit dm1105dvb_read_mac(struct dm1105dvb *dm1105dvb, u8 *mac) 776static void __devinit dm1105_read_mac(struct dm1105_dev *dev, u8 *mac)
752{ 777{
753 static u8 command[1] = { 0x28 }; 778 static u8 command[1] = { 0x28 };
754 779
@@ -766,47 +791,47 @@ static void __devinit dm1105dvb_read_mac(struct dm1105dvb *dm1105dvb, u8 *mac)
766 }, 791 },
767 }; 792 };
768 793
769 dm1105_i2c_xfer(&dm1105dvb->i2c_adap, msg , 2); 794 dm1105_i2c_xfer(&dev->i2c_adap, msg , 2);
770 dev_info(&dm1105dvb->pdev->dev, "MAC %pM\n", mac); 795 dev_info(&dev->pdev->dev, "MAC %pM\n", mac);
771} 796}
772 797
773static int __devinit dm1105_probe(struct pci_dev *pdev, 798static int __devinit dm1105_probe(struct pci_dev *pdev,
774 const struct pci_device_id *ent) 799 const struct pci_device_id *ent)
775{ 800{
776 struct dm1105dvb *dm1105dvb; 801 struct dm1105_dev *dev;
777 struct dvb_adapter *dvb_adapter; 802 struct dvb_adapter *dvb_adapter;
778 struct dvb_demux *dvbdemux; 803 struct dvb_demux *dvbdemux;
779 struct dmx_demux *dmx; 804 struct dmx_demux *dmx;
780 int ret = -ENOMEM; 805 int ret = -ENOMEM;
781 int i; 806 int i;
782 807
783 dm1105dvb = kzalloc(sizeof(struct dm1105dvb), GFP_KERNEL); 808 dev = kzalloc(sizeof(struct dm1105_dev), GFP_KERNEL);
784 if (!dm1105dvb) 809 if (!dev)
785 return -ENOMEM; 810 return -ENOMEM;
786 811
787 /* board config */ 812 /* board config */
788 dm1105dvb->nr = dm1105_devcount; 813 dev->nr = dm1105_devcount;
789 dm1105dvb->boardnr = UNSET; 814 dev->boardnr = UNSET;
790 if (card[dm1105dvb->nr] < ARRAY_SIZE(dm1105_boards)) 815 if (card[dev->nr] < ARRAY_SIZE(dm1105_boards))
791 dm1105dvb->boardnr = card[dm1105dvb->nr]; 816 dev->boardnr = card[dev->nr];
792 for (i = 0; UNSET == dm1105dvb->boardnr && 817 for (i = 0; UNSET == dev->boardnr &&
793 i < ARRAY_SIZE(dm1105_subids); i++) 818 i < ARRAY_SIZE(dm1105_subids); i++)
794 if (pdev->subsystem_vendor == 819 if (pdev->subsystem_vendor ==
795 dm1105_subids[i].subvendor && 820 dm1105_subids[i].subvendor &&
796 pdev->subsystem_device == 821 pdev->subsystem_device ==
797 dm1105_subids[i].subdevice) 822 dm1105_subids[i].subdevice)
798 dm1105dvb->boardnr = dm1105_subids[i].card; 823 dev->boardnr = dm1105_subids[i].card;
799 824
800 if (UNSET == dm1105dvb->boardnr) { 825 if (UNSET == dev->boardnr) {
801 dm1105dvb->boardnr = DM1105_BOARD_UNKNOWN; 826 dev->boardnr = DM1105_BOARD_UNKNOWN;
802 dm1105_card_list(pdev); 827 dm1105_card_list(pdev);
803 } 828 }
804 829
805 dm1105_devcount++; 830 dm1105_devcount++;
806 dm1105dvb->pdev = pdev; 831 dev->pdev = pdev;
807 dm1105dvb->buffer_size = 5 * DM1105_DMA_BYTES; 832 dev->buffer_size = 5 * DM1105_DMA_BYTES;
808 dm1105dvb->PacketErrorCount = 0; 833 dev->PacketErrorCount = 0;
809 dm1105dvb->dmarst = 0; 834 dev->dmarst = 0;
810 835
811 ret = pci_enable_device(pdev); 836 ret = pci_enable_device(pdev);
812 if (ret < 0) 837 if (ret < 0)
@@ -822,47 +847,47 @@ static int __devinit dm1105_probe(struct pci_dev *pdev,
822 if (ret < 0) 847 if (ret < 0)
823 goto err_pci_disable_device; 848 goto err_pci_disable_device;
824 849
825 dm1105dvb->io_mem = pci_iomap(pdev, 0, pci_resource_len(pdev, 0)); 850 dev->io_mem = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
826 if (!dm1105dvb->io_mem) { 851 if (!dev->io_mem) {
827 ret = -EIO; 852 ret = -EIO;
828 goto err_pci_release_regions; 853 goto err_pci_release_regions;
829 } 854 }
830 855
831 spin_lock_init(&dm1105dvb->lock); 856 spin_lock_init(&dev->lock);
832 pci_set_drvdata(pdev, dm1105dvb); 857 pci_set_drvdata(pdev, dev);
833 858
834 ret = dm1105dvb_hw_init(dm1105dvb); 859 ret = dm1105_hw_init(dev);
835 if (ret < 0) 860 if (ret < 0)
836 goto err_pci_iounmap; 861 goto err_pci_iounmap;
837 862
838 /* i2c */ 863 /* i2c */
839 i2c_set_adapdata(&dm1105dvb->i2c_adap, dm1105dvb); 864 i2c_set_adapdata(&dev->i2c_adap, dev);
840 strcpy(dm1105dvb->i2c_adap.name, DRIVER_NAME); 865 strcpy(dev->i2c_adap.name, DRIVER_NAME);
841 dm1105dvb->i2c_adap.owner = THIS_MODULE; 866 dev->i2c_adap.owner = THIS_MODULE;
842 dm1105dvb->i2c_adap.class = I2C_CLASS_TV_DIGITAL; 867 dev->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
843 dm1105dvb->i2c_adap.dev.parent = &pdev->dev; 868 dev->i2c_adap.dev.parent = &pdev->dev;
844 dm1105dvb->i2c_adap.algo = &dm1105_algo; 869 dev->i2c_adap.algo = &dm1105_algo;
845 dm1105dvb->i2c_adap.algo_data = dm1105dvb; 870 dev->i2c_adap.algo_data = dev;
846 ret = i2c_add_adapter(&dm1105dvb->i2c_adap); 871 ret = i2c_add_adapter(&dev->i2c_adap);
847 872
848 if (ret < 0) 873 if (ret < 0)
849 goto err_dm1105dvb_hw_exit; 874 goto err_dm1105_hw_exit;
850 875
851 /* dvb */ 876 /* dvb */
852 ret = dvb_register_adapter(&dm1105dvb->dvb_adapter, DRIVER_NAME, 877 ret = dvb_register_adapter(&dev->dvb_adapter, DRIVER_NAME,
853 THIS_MODULE, &pdev->dev, adapter_nr); 878 THIS_MODULE, &pdev->dev, adapter_nr);
854 if (ret < 0) 879 if (ret < 0)
855 goto err_i2c_del_adapter; 880 goto err_i2c_del_adapter;
856 881
857 dvb_adapter = &dm1105dvb->dvb_adapter; 882 dvb_adapter = &dev->dvb_adapter;
858 883
859 dm1105dvb_read_mac(dm1105dvb, dvb_adapter->proposed_mac); 884 dm1105_read_mac(dev, dvb_adapter->proposed_mac);
860 885
861 dvbdemux = &dm1105dvb->demux; 886 dvbdemux = &dev->demux;
862 dvbdemux->filternum = 256; 887 dvbdemux->filternum = 256;
863 dvbdemux->feednum = 256; 888 dvbdemux->feednum = 256;
864 dvbdemux->start_feed = dm1105dvb_start_feed; 889 dvbdemux->start_feed = dm1105_start_feed;
865 dvbdemux->stop_feed = dm1105dvb_stop_feed; 890 dvbdemux->stop_feed = dm1105_stop_feed;
866 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING | 891 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
867 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING); 892 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
868 ret = dvb_dmx_init(dvbdemux); 893 ret = dvb_dmx_init(dvbdemux);
@@ -870,113 +895,113 @@ static int __devinit dm1105_probe(struct pci_dev *pdev,
870 goto err_dvb_unregister_adapter; 895 goto err_dvb_unregister_adapter;
871 896
872 dmx = &dvbdemux->dmx; 897 dmx = &dvbdemux->dmx;
873 dm1105dvb->dmxdev.filternum = 256; 898 dev->dmxdev.filternum = 256;
874 dm1105dvb->dmxdev.demux = dmx; 899 dev->dmxdev.demux = dmx;
875 dm1105dvb->dmxdev.capabilities = 0; 900 dev->dmxdev.capabilities = 0;
876 901
877 ret = dvb_dmxdev_init(&dm1105dvb->dmxdev, dvb_adapter); 902 ret = dvb_dmxdev_init(&dev->dmxdev, dvb_adapter);
878 if (ret < 0) 903 if (ret < 0)
879 goto err_dvb_dmx_release; 904 goto err_dvb_dmx_release;
880 905
881 dm1105dvb->hw_frontend.source = DMX_FRONTEND_0; 906 dev->hw_frontend.source = DMX_FRONTEND_0;
882 907
883 ret = dmx->add_frontend(dmx, &dm1105dvb->hw_frontend); 908 ret = dmx->add_frontend(dmx, &dev->hw_frontend);
884 if (ret < 0) 909 if (ret < 0)
885 goto err_dvb_dmxdev_release; 910 goto err_dvb_dmxdev_release;
886 911
887 dm1105dvb->mem_frontend.source = DMX_MEMORY_FE; 912 dev->mem_frontend.source = DMX_MEMORY_FE;
888 913
889 ret = dmx->add_frontend(dmx, &dm1105dvb->mem_frontend); 914 ret = dmx->add_frontend(dmx, &dev->mem_frontend);
890 if (ret < 0) 915 if (ret < 0)
891 goto err_remove_hw_frontend; 916 goto err_remove_hw_frontend;
892 917
893 ret = dmx->connect_frontend(dmx, &dm1105dvb->hw_frontend); 918 ret = dmx->connect_frontend(dmx, &dev->hw_frontend);
894 if (ret < 0) 919 if (ret < 0)
895 goto err_remove_mem_frontend; 920 goto err_remove_mem_frontend;
896 921
897 ret = frontend_init(dm1105dvb); 922 ret = frontend_init(dev);
898 if (ret < 0) 923 if (ret < 0)
899 goto err_disconnect_frontend; 924 goto err_disconnect_frontend;
900 925
901 dvb_net_init(dvb_adapter, &dm1105dvb->dvbnet, dmx); 926 dvb_net_init(dvb_adapter, &dev->dvbnet, dmx);
902 dm1105_ir_init(dm1105dvb); 927 dm1105_ir_init(dev);
903 928
904 INIT_WORK(&dm1105dvb->work, dm1105_dmx_buffer); 929 INIT_WORK(&dev->work, dm1105_dmx_buffer);
905 sprintf(dm1105dvb->wqn, "%s/%d", dvb_adapter->name, dvb_adapter->num); 930 sprintf(dev->wqn, "%s/%d", dvb_adapter->name, dvb_adapter->num);
906 dm1105dvb->wq = create_singlethread_workqueue(dm1105dvb->wqn); 931 dev->wq = create_singlethread_workqueue(dev->wqn);
907 if (!dm1105dvb->wq) 932 if (!dev->wq)
908 goto err_dvb_net; 933 goto err_dvb_net;
909 934
910 ret = request_irq(pdev->irq, dm1105dvb_irq, IRQF_SHARED, 935 ret = request_irq(pdev->irq, dm1105_irq, IRQF_SHARED,
911 DRIVER_NAME, dm1105dvb); 936 DRIVER_NAME, dev);
912 if (ret < 0) 937 if (ret < 0)
913 goto err_workqueue; 938 goto err_workqueue;
914 939
915 return 0; 940 return 0;
916 941
917err_workqueue: 942err_workqueue:
918 destroy_workqueue(dm1105dvb->wq); 943 destroy_workqueue(dev->wq);
919err_dvb_net: 944err_dvb_net:
920 dvb_net_release(&dm1105dvb->dvbnet); 945 dvb_net_release(&dev->dvbnet);
921err_disconnect_frontend: 946err_disconnect_frontend:
922 dmx->disconnect_frontend(dmx); 947 dmx->disconnect_frontend(dmx);
923err_remove_mem_frontend: 948err_remove_mem_frontend:
924 dmx->remove_frontend(dmx, &dm1105dvb->mem_frontend); 949 dmx->remove_frontend(dmx, &dev->mem_frontend);
925err_remove_hw_frontend: 950err_remove_hw_frontend:
926 dmx->remove_frontend(dmx, &dm1105dvb->hw_frontend); 951 dmx->remove_frontend(dmx, &dev->hw_frontend);
927err_dvb_dmxdev_release: 952err_dvb_dmxdev_release:
928 dvb_dmxdev_release(&dm1105dvb->dmxdev); 953 dvb_dmxdev_release(&dev->dmxdev);
929err_dvb_dmx_release: 954err_dvb_dmx_release:
930 dvb_dmx_release(dvbdemux); 955 dvb_dmx_release(dvbdemux);
931err_dvb_unregister_adapter: 956err_dvb_unregister_adapter:
932 dvb_unregister_adapter(dvb_adapter); 957 dvb_unregister_adapter(dvb_adapter);
933err_i2c_del_adapter: 958err_i2c_del_adapter:
934 i2c_del_adapter(&dm1105dvb->i2c_adap); 959 i2c_del_adapter(&dev->i2c_adap);
935err_dm1105dvb_hw_exit: 960err_dm1105_hw_exit:
936 dm1105dvb_hw_exit(dm1105dvb); 961 dm1105_hw_exit(dev);
937err_pci_iounmap: 962err_pci_iounmap:
938 pci_iounmap(pdev, dm1105dvb->io_mem); 963 pci_iounmap(pdev, dev->io_mem);
939err_pci_release_regions: 964err_pci_release_regions:
940 pci_release_regions(pdev); 965 pci_release_regions(pdev);
941err_pci_disable_device: 966err_pci_disable_device:
942 pci_disable_device(pdev); 967 pci_disable_device(pdev);
943err_kfree: 968err_kfree:
944 pci_set_drvdata(pdev, NULL); 969 pci_set_drvdata(pdev, NULL);
945 kfree(dm1105dvb); 970 kfree(dev);
946 return ret; 971 return ret;
947} 972}
948 973
949static void __devexit dm1105_remove(struct pci_dev *pdev) 974static void __devexit dm1105_remove(struct pci_dev *pdev)
950{ 975{
951 struct dm1105dvb *dm1105dvb = pci_get_drvdata(pdev); 976 struct dm1105_dev *dev = pci_get_drvdata(pdev);
952 struct dvb_adapter *dvb_adapter = &dm1105dvb->dvb_adapter; 977 struct dvb_adapter *dvb_adapter = &dev->dvb_adapter;
953 struct dvb_demux *dvbdemux = &dm1105dvb->demux; 978 struct dvb_demux *dvbdemux = &dev->demux;
954 struct dmx_demux *dmx = &dvbdemux->dmx; 979 struct dmx_demux *dmx = &dvbdemux->dmx;
955 980
956 dm1105_ir_exit(dm1105dvb); 981 dm1105_ir_exit(dev);
957 dmx->close(dmx); 982 dmx->close(dmx);
958 dvb_net_release(&dm1105dvb->dvbnet); 983 dvb_net_release(&dev->dvbnet);
959 if (dm1105dvb->fe) 984 if (dev->fe)
960 dvb_unregister_frontend(dm1105dvb->fe); 985 dvb_unregister_frontend(dev->fe);
961 986
962 dmx->disconnect_frontend(dmx); 987 dmx->disconnect_frontend(dmx);
963 dmx->remove_frontend(dmx, &dm1105dvb->mem_frontend); 988 dmx->remove_frontend(dmx, &dev->mem_frontend);
964 dmx->remove_frontend(dmx, &dm1105dvb->hw_frontend); 989 dmx->remove_frontend(dmx, &dev->hw_frontend);
965 dvb_dmxdev_release(&dm1105dvb->dmxdev); 990 dvb_dmxdev_release(&dev->dmxdev);
966 dvb_dmx_release(dvbdemux); 991 dvb_dmx_release(dvbdemux);
967 dvb_unregister_adapter(dvb_adapter); 992 dvb_unregister_adapter(dvb_adapter);
968 if (&dm1105dvb->i2c_adap) 993 if (&dev->i2c_adap)
969 i2c_del_adapter(&dm1105dvb->i2c_adap); 994 i2c_del_adapter(&dev->i2c_adap);
970 995
971 dm1105dvb_hw_exit(dm1105dvb); 996 dm1105_hw_exit(dev);
972 synchronize_irq(pdev->irq); 997 synchronize_irq(pdev->irq);
973 free_irq(pdev->irq, dm1105dvb); 998 free_irq(pdev->irq, dev);
974 pci_iounmap(pdev, dm1105dvb->io_mem); 999 pci_iounmap(pdev, dev->io_mem);
975 pci_release_regions(pdev); 1000 pci_release_regions(pdev);
976 pci_disable_device(pdev); 1001 pci_disable_device(pdev);
977 pci_set_drvdata(pdev, NULL); 1002 pci_set_drvdata(pdev, NULL);
978 dm1105_devcount--; 1003 dm1105_devcount--;
979 kfree(dm1105dvb); 1004 kfree(dev);
980} 1005}
981 1006
982static struct pci_device_id dm1105_id_table[] __devinitdata = { 1007static struct pci_device_id dm1105_id_table[] __devinitdata = {
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 07461222a7f5..55ea260572bf 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -1199,8 +1199,6 @@ static int dtv_property_process_get(struct dvb_frontend *fe,
1199{ 1199{
1200 int r = 0; 1200 int r = 0;
1201 1201
1202 dtv_property_dump(tvp);
1203
1204 /* Allow the frontend to validate incoming properties */ 1202 /* Allow the frontend to validate incoming properties */
1205 if (fe->ops.get_property) 1203 if (fe->ops.get_property)
1206 r = fe->ops.get_property(fe, tvp); 1204 r = fe->ops.get_property(fe, tvp);
@@ -1323,6 +1321,8 @@ static int dtv_property_process_get(struct dvb_frontend *fe,
1323 r = -1; 1321 r = -1;
1324 } 1322 }
1325 1323
1324 dtv_property_dump(tvp);
1325
1326 return r; 1326 return r;
1327} 1327}
1328 1328
@@ -1488,7 +1488,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
1488 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1488 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1489 int err = -EOPNOTSUPP; 1489 int err = -EOPNOTSUPP;
1490 1490
1491 dprintk ("%s\n", __func__); 1491 dprintk("%s (%d)\n", __func__, _IOC_NR(cmd));
1492 1492
1493 if (fepriv->exit) 1493 if (fepriv->exit)
1494 return -ENODEV; 1494 return -ENODEV;
@@ -1536,8 +1536,7 @@ static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
1536 if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) 1536 if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
1537 return -EINVAL; 1537 return -EINVAL;
1538 1538
1539 tvp = (struct dtv_property *) kmalloc(tvps->num * 1539 tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL);
1540 sizeof(struct dtv_property), GFP_KERNEL);
1541 if (!tvp) { 1540 if (!tvp) {
1542 err = -ENOMEM; 1541 err = -ENOMEM;
1543 goto out; 1542 goto out;
@@ -1569,8 +1568,7 @@ static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
1569 if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) 1568 if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
1570 return -EINVAL; 1569 return -EINVAL;
1571 1570
1572 tvp = (struct dtv_property *) kmalloc(tvps->num * 1571 tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL);
1573 sizeof(struct dtv_property), GFP_KERNEL);
1574 if (!tvp) { 1572 if (!tvp) {
1575 err = -ENOMEM; 1573 err = -ENOMEM;
1576 goto out; 1574 goto out;
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index 37d8579fc7a9..441c0642b30a 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -504,6 +504,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
504 "bytes left in TS. Resyncing.\n", ts_remain); 504 "bytes left in TS. Resyncing.\n", ts_remain);
505 priv->ule_sndu_len = 0; 505 priv->ule_sndu_len = 0;
506 priv->need_pusi = 1; 506 priv->need_pusi = 1;
507 ts += TS_SZ;
507 continue; 508 continue;
508 } 509 }
509 510
diff --git a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
index 584bbd194dc8..a5712cd7c65f 100644
--- a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
+++ b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
@@ -89,6 +89,7 @@ void dvb_ringbuffer_flush(struct dvb_ringbuffer *rbuf)
89 rbuf->pread = rbuf->pwrite; 89 rbuf->pread = rbuf->pwrite;
90 rbuf->error = 0; 90 rbuf->error = 0;
91} 91}
92EXPORT_SYMBOL(dvb_ringbuffer_flush);
92 93
93void dvb_ringbuffer_reset(struct dvb_ringbuffer *rbuf) 94void dvb_ringbuffer_reset(struct dvb_ringbuffer *rbuf)
94{ 95{
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 1b249897c9fb..e5f91f16ffa4 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -112,11 +112,13 @@ config DVB_USB_CXUSB
112 select DVB_MT352 if !DVB_FE_CUSTOMISE 112 select DVB_MT352 if !DVB_FE_CUSTOMISE
113 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 113 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
114 select DVB_DIB7000P if !DVB_FE_CUSTOMISE 114 select DVB_DIB7000P if !DVB_FE_CUSTOMISE
115 select DVB_LGS8GL5 if !DVB_FE_CUSTOMISE
116 select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE 115 select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE
116 select DVB_ATBM8830 if !DVB_FE_CUSTOMISE
117 select DVB_LGS8GXX if !DVB_FE_CUSTOMISE
117 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE 118 select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE
118 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE 119 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE
119 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE 120 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE
121 select MEDIA_TUNER_MAX2165 if !MEDIA_TUNER_CUSTOMISE
120 help 122 help
121 Say Y here to support the Conexant USB2.0 hybrid reference design. 123 Say Y here to support the Conexant USB2.0 hybrid reference design.
122 Currently, only DVB and ATSC modes are supported, analog mode 124 Currently, only DVB and ATSC modes are supported, analog mode
@@ -334,3 +336,11 @@ config DVB_USB_EC168
334 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE 336 select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE
335 help 337 help
336 Say Y here to support the E3C EC168 DVB-T USB2.0 receiver. 338 Say Y here to support the E3C EC168 DVB-T USB2.0 receiver.
339
340config DVB_USB_AZ6027
341 tristate "Azurewave DVB-S/S2 USB2.0 AZ6027 support"
342 depends on DVB_USB
343 select DVB_STB0899 if !DVB_FE_CUSTOMISE
344 select DVB_STB6100 if !DVB_FE_CUSTOMISE
345 help
346 Say Y here to support the AZ6027 device
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 72c92cb69a22..1a192453b0e7 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -85,6 +85,9 @@ obj-$(CONFIG_DVB_USB_FRIIO) += dvb-usb-friio.o
85dvb-usb-ec168-objs = ec168.o 85dvb-usb-ec168-objs = ec168.o
86obj-$(CONFIG_DVB_USB_EC168) += dvb-usb-ec168.o 86obj-$(CONFIG_DVB_USB_EC168) += dvb-usb-ec168.o
87 87
88dvb-usb-az6027-objs = az6027.o
89obj-$(CONFIG_DVB_USB_AZ6027) += dvb-usb-az6027.o
90
88EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 91EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
89# due to tuner-xc3028 92# due to tuner-xc3028
90EXTRA_CFLAGS += -Idrivers/media/common/tuners 93EXTRA_CFLAGS += -Idrivers/media/common/tuners
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c
index 8b60a601fb82..d7975383d31b 100644
--- a/drivers/media/dvb/dvb-usb/af9015.c
+++ b/drivers/media/dvb/dvb-usb/af9015.c
@@ -21,6 +21,8 @@
21 * 21 *
22 */ 22 */
23 23
24#include <linux/hash.h>
25
24#include "af9015.h" 26#include "af9015.h"
25#include "af9013.h" 27#include "af9013.h"
26#include "mt2060.h" 28#include "mt2060.h"
@@ -553,26 +555,45 @@ exit:
553 return ret; 555 return ret;
554} 556}
555 557
556/* dump eeprom */ 558/* hash (and dump) eeprom */
557static int af9015_eeprom_dump(struct dvb_usb_device *d) 559static int af9015_eeprom_hash(struct usb_device *udev)
558{ 560{
559 u8 reg, val; 561 static const unsigned int eeprom_size = 256;
562 unsigned int reg;
563 int ret;
564 u8 val, *eeprom;
565 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
560 566
561 for (reg = 0; ; reg++) { 567 eeprom = kmalloc(eeprom_size, GFP_KERNEL);
562 if (reg % 16 == 0) { 568 if (eeprom == NULL)
563 if (reg) 569 return -ENOMEM;
564 deb_info(KERN_CONT "\n"); 570
565 deb_info(KERN_DEBUG "%02x:", reg); 571 for (reg = 0; reg < eeprom_size; reg++) {
566 } 572 req.addr = reg;
567 if (af9015_read_reg_i2c(d, AF9015_I2C_EEPROM, reg, &val) == 0) 573 ret = af9015_rw_udev(udev, &req);
568 deb_info(KERN_CONT " %02x", val); 574 if (ret)
569 else 575 goto free;
570 deb_info(KERN_CONT " --"); 576 eeprom[reg] = val;
571 if (reg == 0xff)
572 break;
573 } 577 }
574 deb_info(KERN_CONT "\n"); 578
575 return 0; 579 if (dvb_usb_af9015_debug & 0x01)
580 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, eeprom,
581 eeprom_size);
582
583 BUG_ON(eeprom_size % 4);
584
585 af9015_config.eeprom_sum = 0;
586 for (reg = 0; reg < eeprom_size / sizeof(u32); reg++) {
587 af9015_config.eeprom_sum *= GOLDEN_RATIO_PRIME_32;
588 af9015_config.eeprom_sum += le32_to_cpu(((u32 *)eeprom)[reg]);
589 }
590
591 deb_info("%s: eeprom sum=%.8x\n", __func__, af9015_config.eeprom_sum);
592
593 ret = 0;
594free:
595 kfree(eeprom);
596 return ret;
576} 597}
577 598
578static int af9015_download_ir_table(struct dvb_usb_device *d) 599static int af9015_download_ir_table(struct dvb_usb_device *d)
@@ -711,12 +732,132 @@ error:
711 return ret; 732 return ret;
712} 733}
713 734
735struct af9015_setup {
736 unsigned int id;
737 struct dvb_usb_rc_key *rc_key_map;
738 unsigned int rc_key_map_size;
739 u8 *ir_table;
740 unsigned int ir_table_size;
741};
742
743static const struct af9015_setup *af9015_setup_match(unsigned int id,
744 const struct af9015_setup *table)
745{
746 for (; table->rc_key_map; table++)
747 if (table->id == id)
748 return table;
749 return NULL;
750}
751
752static const struct af9015_setup af9015_setup_modparam[] = {
753 { AF9015_REMOTE_A_LINK_DTU_M,
754 af9015_rc_keys_a_link, ARRAY_SIZE(af9015_rc_keys_a_link),
755 af9015_ir_table_a_link, ARRAY_SIZE(af9015_ir_table_a_link) },
756 { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
757 af9015_rc_keys_msi, ARRAY_SIZE(af9015_rc_keys_msi),
758 af9015_ir_table_msi, ARRAY_SIZE(af9015_ir_table_msi) },
759 { AF9015_REMOTE_MYGICTV_U718,
760 af9015_rc_keys_mygictv, ARRAY_SIZE(af9015_rc_keys_mygictv),
761 af9015_ir_table_mygictv, ARRAY_SIZE(af9015_ir_table_mygictv) },
762 { AF9015_REMOTE_DIGITTRADE_DVB_T,
763 af9015_rc_keys_digittrade, ARRAY_SIZE(af9015_rc_keys_digittrade),
764 af9015_ir_table_digittrade, ARRAY_SIZE(af9015_ir_table_digittrade) },
765 { AF9015_REMOTE_AVERMEDIA_KS,
766 af9015_rc_keys_avermedia, ARRAY_SIZE(af9015_rc_keys_avermedia),
767 af9015_ir_table_avermedia_ks, ARRAY_SIZE(af9015_ir_table_avermedia_ks) },
768 { }
769};
770
771/* don't add new entries here anymore, use hashes instead */
772static const struct af9015_setup af9015_setup_usbids[] = {
773 { USB_VID_LEADTEK,
774 af9015_rc_keys_leadtek, ARRAY_SIZE(af9015_rc_keys_leadtek),
775 af9015_ir_table_leadtek, ARRAY_SIZE(af9015_ir_table_leadtek) },
776 { USB_VID_VISIONPLUS,
777 af9015_rc_keys_twinhan, ARRAY_SIZE(af9015_rc_keys_twinhan),
778 af9015_ir_table_twinhan, ARRAY_SIZE(af9015_ir_table_twinhan) },
779 { USB_VID_KWORLD_2, /* TODO: use correct rc keys */
780 af9015_rc_keys_twinhan, ARRAY_SIZE(af9015_rc_keys_twinhan),
781 af9015_ir_table_kworld, ARRAY_SIZE(af9015_ir_table_kworld) },
782 { USB_VID_AVERMEDIA,
783 af9015_rc_keys_avermedia, ARRAY_SIZE(af9015_rc_keys_avermedia),
784 af9015_ir_table_avermedia, ARRAY_SIZE(af9015_ir_table_avermedia) },
785 { USB_VID_MSI_2,
786 af9015_rc_keys_msi_digivox_iii, ARRAY_SIZE(af9015_rc_keys_msi_digivox_iii),
787 af9015_ir_table_msi_digivox_iii, ARRAY_SIZE(af9015_ir_table_msi_digivox_iii) },
788 { }
789};
790
791static const struct af9015_setup af9015_setup_hashes[] = {
792 { 0xb8feb708,
793 af9015_rc_keys_msi, ARRAY_SIZE(af9015_rc_keys_msi),
794 af9015_ir_table_msi, ARRAY_SIZE(af9015_ir_table_msi) },
795 { 0xa3703d00,
796 af9015_rc_keys_a_link, ARRAY_SIZE(af9015_rc_keys_a_link),
797 af9015_ir_table_a_link, ARRAY_SIZE(af9015_ir_table_a_link) },
798 { 0x9b7dc64e,
799 af9015_rc_keys_mygictv, ARRAY_SIZE(af9015_rc_keys_mygictv),
800 af9015_ir_table_mygictv, ARRAY_SIZE(af9015_ir_table_mygictv) },
801 { }
802};
803
804static void af9015_set_remote_config(struct usb_device *udev,
805 struct dvb_usb_device_properties *props)
806{
807 const struct af9015_setup *table = NULL;
808
809 if (dvb_usb_af9015_remote) {
810 /* load remote defined as module param */
811 table = af9015_setup_match(dvb_usb_af9015_remote,
812 af9015_setup_modparam);
813 } else {
814 u16 vendor = le16_to_cpu(udev->descriptor.idVendor);
815
816 table = af9015_setup_match(af9015_config.eeprom_sum,
817 af9015_setup_hashes);
818
819 if (!table && vendor == USB_VID_AFATECH) {
820 /* Check USB manufacturer and product strings and try
821 to determine correct remote in case of chip vendor
822 reference IDs are used.
823 DO NOT ADD ANYTHING NEW HERE. Use hashes instead.
824 */
825 char manufacturer[10];
826 memset(manufacturer, 0, sizeof(manufacturer));
827 usb_string(udev, udev->descriptor.iManufacturer,
828 manufacturer, sizeof(manufacturer));
829 if (!strcmp("MSI", manufacturer)) {
830 /* iManufacturer 1 MSI
831 iProduct 2 MSI K-VOX */
832 table = af9015_setup_match(
833 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
834 af9015_setup_modparam);
835 } else if (udev->descriptor.idProduct ==
836 cpu_to_le16(USB_PID_TREKSTOR_DVBT)) {
837 table = &(const struct af9015_setup){ 0,
838 af9015_rc_keys_trekstor,
839 ARRAY_SIZE(af9015_rc_keys_trekstor),
840 af9015_ir_table_trekstor,
841 ARRAY_SIZE(af9015_ir_table_trekstor)
842 };
843 }
844 } else if (!table)
845 table = af9015_setup_match(vendor, af9015_setup_usbids);
846 }
847
848 if (table) {
849 props->rc_key_map = table->rc_key_map;
850 props->rc_key_map_size = table->rc_key_map_size;
851 af9015_config.ir_table = table->ir_table;
852 af9015_config.ir_table_size = table->ir_table_size;
853 }
854}
855
714static int af9015_read_config(struct usb_device *udev) 856static int af9015_read_config(struct usb_device *udev)
715{ 857{
716 int ret; 858 int ret;
717 u8 val, i, offset = 0; 859 u8 val, i, offset = 0;
718 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val}; 860 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
719 char manufacturer[10];
720 861
721 /* IR remote controller */ 862 /* IR remote controller */
722 req.addr = AF9015_EEPROM_IR_MODE; 863 req.addr = AF9015_EEPROM_IR_MODE;
@@ -728,158 +869,18 @@ static int af9015_read_config(struct usb_device *udev)
728 } 869 }
729 if (ret) 870 if (ret)
730 goto error; 871 goto error;
872
873 ret = af9015_eeprom_hash(udev);
874 if (ret)
875 goto error;
876
731 deb_info("%s: IR mode:%d\n", __func__, val); 877 deb_info("%s: IR mode:%d\n", __func__, val);
732 for (i = 0; i < af9015_properties_count; i++) { 878 for (i = 0; i < af9015_properties_count; i++) {
733 if (val == AF9015_IR_MODE_DISABLED) { 879 if (val == AF9015_IR_MODE_DISABLED) {
734 af9015_properties[i].rc_key_map = NULL; 880 af9015_properties[i].rc_key_map = NULL;
735 af9015_properties[i].rc_key_map_size = 0; 881 af9015_properties[i].rc_key_map_size = 0;
736 } else if (dvb_usb_af9015_remote) { 882 } else
737 /* load remote defined as module param */ 883 af9015_set_remote_config(udev, &af9015_properties[i]);
738 switch (dvb_usb_af9015_remote) {
739 case AF9015_REMOTE_A_LINK_DTU_M:
740 af9015_properties[i].rc_key_map =
741 af9015_rc_keys_a_link;
742 af9015_properties[i].rc_key_map_size =
743 ARRAY_SIZE(af9015_rc_keys_a_link);
744 af9015_config.ir_table = af9015_ir_table_a_link;
745 af9015_config.ir_table_size =
746 ARRAY_SIZE(af9015_ir_table_a_link);
747 break;
748 case AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3:
749 af9015_properties[i].rc_key_map =
750 af9015_rc_keys_msi;
751 af9015_properties[i].rc_key_map_size =
752 ARRAY_SIZE(af9015_rc_keys_msi);
753 af9015_config.ir_table = af9015_ir_table_msi;
754 af9015_config.ir_table_size =
755 ARRAY_SIZE(af9015_ir_table_msi);
756 break;
757 case AF9015_REMOTE_MYGICTV_U718:
758 af9015_properties[i].rc_key_map =
759 af9015_rc_keys_mygictv;
760 af9015_properties[i].rc_key_map_size =
761 ARRAY_SIZE(af9015_rc_keys_mygictv);
762 af9015_config.ir_table =
763 af9015_ir_table_mygictv;
764 af9015_config.ir_table_size =
765 ARRAY_SIZE(af9015_ir_table_mygictv);
766 break;
767 case AF9015_REMOTE_DIGITTRADE_DVB_T:
768 af9015_properties[i].rc_key_map =
769 af9015_rc_keys_digittrade;
770 af9015_properties[i].rc_key_map_size =
771 ARRAY_SIZE(af9015_rc_keys_digittrade);
772 af9015_config.ir_table =
773 af9015_ir_table_digittrade;
774 af9015_config.ir_table_size =
775 ARRAY_SIZE(af9015_ir_table_digittrade);
776 break;
777 case AF9015_REMOTE_AVERMEDIA_KS:
778 af9015_properties[i].rc_key_map =
779 af9015_rc_keys_avermedia;
780 af9015_properties[i].rc_key_map_size =
781 ARRAY_SIZE(af9015_rc_keys_avermedia);
782 af9015_config.ir_table =
783 af9015_ir_table_avermedia_ks;
784 af9015_config.ir_table_size =
785 ARRAY_SIZE(af9015_ir_table_avermedia_ks);
786 break;
787 }
788 } else {
789 switch (le16_to_cpu(udev->descriptor.idVendor)) {
790 case USB_VID_LEADTEK:
791 af9015_properties[i].rc_key_map =
792 af9015_rc_keys_leadtek;
793 af9015_properties[i].rc_key_map_size =
794 ARRAY_SIZE(af9015_rc_keys_leadtek);
795 af9015_config.ir_table =
796 af9015_ir_table_leadtek;
797 af9015_config.ir_table_size =
798 ARRAY_SIZE(af9015_ir_table_leadtek);
799 break;
800 case USB_VID_VISIONPLUS:
801 af9015_properties[i].rc_key_map =
802 af9015_rc_keys_twinhan;
803 af9015_properties[i].rc_key_map_size =
804 ARRAY_SIZE(af9015_rc_keys_twinhan);
805 af9015_config.ir_table =
806 af9015_ir_table_twinhan;
807 af9015_config.ir_table_size =
808 ARRAY_SIZE(af9015_ir_table_twinhan);
809 break;
810 case USB_VID_KWORLD_2:
811 /* TODO: use correct rc keys */
812 af9015_properties[i].rc_key_map =
813 af9015_rc_keys_twinhan;
814 af9015_properties[i].rc_key_map_size =
815 ARRAY_SIZE(af9015_rc_keys_twinhan);
816 af9015_config.ir_table = af9015_ir_table_kworld;
817 af9015_config.ir_table_size =
818 ARRAY_SIZE(af9015_ir_table_kworld);
819 break;
820 /* Check USB manufacturer and product strings and try
821 to determine correct remote in case of chip vendor
822 reference IDs are used. */
823 case USB_VID_AFATECH:
824 memset(manufacturer, 0, sizeof(manufacturer));
825 usb_string(udev, udev->descriptor.iManufacturer,
826 manufacturer, sizeof(manufacturer));
827 if (!strcmp("Geniatech", manufacturer)) {
828 /* iManufacturer 1 Geniatech
829 iProduct 2 AF9015 */
830 af9015_properties[i].rc_key_map =
831 af9015_rc_keys_mygictv;
832 af9015_properties[i].rc_key_map_size =
833 ARRAY_SIZE(af9015_rc_keys_mygictv);
834 af9015_config.ir_table =
835 af9015_ir_table_mygictv;
836 af9015_config.ir_table_size =
837 ARRAY_SIZE(af9015_ir_table_mygictv);
838 } else if (!strcmp("MSI", manufacturer)) {
839 /* iManufacturer 1 MSI
840 iProduct 2 MSI K-VOX */
841 af9015_properties[i].rc_key_map =
842 af9015_rc_keys_msi;
843 af9015_properties[i].rc_key_map_size =
844 ARRAY_SIZE(af9015_rc_keys_msi);
845 af9015_config.ir_table =
846 af9015_ir_table_msi;
847 af9015_config.ir_table_size =
848 ARRAY_SIZE(af9015_ir_table_msi);
849 } else if (udev->descriptor.idProduct ==
850 cpu_to_le16(USB_PID_TREKSTOR_DVBT)) {
851 af9015_properties[i].rc_key_map =
852 af9015_rc_keys_trekstor;
853 af9015_properties[i].rc_key_map_size =
854 ARRAY_SIZE(af9015_rc_keys_trekstor);
855 af9015_config.ir_table =
856 af9015_ir_table_trekstor;
857 af9015_config.ir_table_size =
858 ARRAY_SIZE(af9015_ir_table_trekstor);
859 }
860 break;
861 case USB_VID_AVERMEDIA:
862 af9015_properties[i].rc_key_map =
863 af9015_rc_keys_avermedia;
864 af9015_properties[i].rc_key_map_size =
865 ARRAY_SIZE(af9015_rc_keys_avermedia);
866 af9015_config.ir_table =
867 af9015_ir_table_avermedia;
868 af9015_config.ir_table_size =
869 ARRAY_SIZE(af9015_ir_table_avermedia);
870 break;
871 case USB_VID_MSI_2:
872 af9015_properties[i].rc_key_map =
873 af9015_rc_keys_msi_digivox_iii;
874 af9015_properties[i].rc_key_map_size =
875 ARRAY_SIZE(af9015_rc_keys_msi_digivox_iii);
876 af9015_config.ir_table =
877 af9015_ir_table_msi_digivox_iii;
878 af9015_config.ir_table_size =
879 ARRAY_SIZE(af9015_ir_table_msi_digivox_iii);
880 break;
881 }
882 }
883 } 884 }
884 885
885 /* TS mode - one or two receivers */ 886 /* TS mode - one or two receivers */
@@ -1001,6 +1002,9 @@ static int af9015_read_config(struct usb_device *udev)
1001 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO; 1002 af9015_af9013_config[i].gpio[1] = AF9013_GPIO_LO;
1002 af9015_af9013_config[i].rf_spec_inv = 1; 1003 af9015_af9013_config[i].rf_spec_inv = 1;
1003 break; 1004 break;
1005 case AF9013_TUNER_TDA18218:
1006 warn("tuner NXP TDA18218 not supported yet");
1007 return -ENODEV;
1004 default: 1008 default:
1005 warn("tuner id:%d not supported, please report!", val); 1009 warn("tuner id:%d not supported, please report!", val);
1006 return -ENODEV; 1010 return -ENODEV;
@@ -1125,11 +1129,6 @@ static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
1125 1129
1126 deb_info("%s: init I2C\n", __func__); 1130 deb_info("%s: init I2C\n", __func__);
1127 ret = af9015_i2c_init(adap->dev); 1131 ret = af9015_i2c_init(adap->dev);
1128
1129 /* dump eeprom (debug) */
1130 ret = af9015_eeprom_dump(adap->dev);
1131 if (ret)
1132 return ret;
1133 } else { 1132 } else {
1134 /* select I2C adapter */ 1133 /* select I2C adapter */
1135 i2c_adap = &state->i2c_adap; 1134 i2c_adap = &state->i2c_adap;
@@ -1295,6 +1294,8 @@ static struct usb_device_id af9015_usb_table[] = {
1295/* 25 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2)}, 1294/* 25 */{USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U_2)},
1296 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T)}, 1295 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_T)},
1297 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20)}, 1296 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20)},
1297 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_TINYTWIN_2)},
1298 {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV2000DS)},
1298 {0}, 1299 {0},
1299}; 1300};
1300MODULE_DEVICE_TABLE(usb, af9015_usb_table); 1301MODULE_DEVICE_TABLE(usb, af9015_usb_table);
@@ -1381,7 +1382,8 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1381 }, 1382 },
1382 { 1383 {
1383 .name = "DigitalNow TinyTwin DVB-T Receiver", 1384 .name = "DigitalNow TinyTwin DVB-T Receiver",
1384 .cold_ids = {&af9015_usb_table[5], NULL}, 1385 .cold_ids = {&af9015_usb_table[5],
1386 &af9015_usb_table[28], NULL},
1385 .warm_ids = {NULL}, 1387 .warm_ids = {NULL},
1386 }, 1388 },
1387 { 1389 {
@@ -1566,7 +1568,7 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1566 1568
1567 .i2c_algo = &af9015_i2c_algo, 1569 .i2c_algo = &af9015_i2c_algo,
1568 1570
1569 .num_device_descs = 6, /* max 9 */ 1571 .num_device_descs = 7, /* max 9 */
1570 .devices = { 1572 .devices = {
1571 { 1573 {
1572 .name = "AverMedia AVerTV Volar GPS 805 (A805)", 1574 .name = "AverMedia AVerTV Volar GPS 805 (A805)",
@@ -1600,6 +1602,11 @@ static struct dvb_usb_device_properties af9015_properties[] = {
1600 .cold_ids = {&af9015_usb_table[27], NULL}, 1602 .cold_ids = {&af9015_usb_table[27], NULL},
1601 .warm_ids = {NULL}, 1603 .warm_ids = {NULL},
1602 }, 1604 },
1605 {
1606 .name = "Leadtek WinFast DTV2000DS",
1607 .cold_ids = {&af9015_usb_table[29], NULL},
1608 .warm_ids = {NULL},
1609 },
1603 } 1610 }
1604 }, 1611 },
1605}; 1612};
diff --git a/drivers/media/dvb/dvb-usb/af9015.h b/drivers/media/dvb/dvb-usb/af9015.h
index 931c8515830d..ef36b1831490 100644
--- a/drivers/media/dvb/dvb-usb/af9015.h
+++ b/drivers/media/dvb/dvb-usb/af9015.h
@@ -107,6 +107,7 @@ struct af9015_config {
107 u16 mt2060_if1[2]; 107 u16 mt2060_if1[2];
108 u16 firmware_size; 108 u16 firmware_size;
109 u16 firmware_checksum; 109 u16 firmware_checksum;
110 u32 eeprom_sum;
110 u8 *ir_table; 111 u8 *ir_table;
111 u16 ir_table_size; 112 u16 ir_table_size;
112}; 113};
diff --git a/drivers/media/dvb/dvb-usb/az6027.c b/drivers/media/dvb/dvb-usb/az6027.c
new file mode 100644
index 000000000000..d7290b2c0913
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/az6027.c
@@ -0,0 +1,1151 @@
1/* DVB USB compliant Linux driver for the AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)
2 * receiver.
3 *
4 * Copyright (C) 2009 Adams.Xu <adams.xu@azwave.com.cn>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, version 2.
9 *
10 * see Documentation/dvb/README.dvb-usb for more information
11 */
12#include "az6027.h"
13
14#include "stb0899_drv.h"
15#include "stb0899_reg.h"
16#include "stb0899_cfg.h"
17
18#include "stb6100.h"
19#include "stb6100_cfg.h"
20#include "dvb_ca_en50221.h"
21
22int dvb_usb_az6027_debug;
23module_param_named(debug, dvb_usb_az6027_debug, int, 0644);
24MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
25
26DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
27
28struct az6027_device_state {
29 struct dvb_ca_en50221 ca;
30 struct mutex ca_mutex;
31 u8 power_state;
32};
33
34static const struct stb0899_s1_reg az6027_stb0899_s1_init_1[] = {
35
36 /* 0x0000000b, SYSREG */
37 { STB0899_DEV_ID , 0x30 },
38 { STB0899_DISCNTRL1 , 0x32 },
39 { STB0899_DISCNTRL2 , 0x80 },
40 { STB0899_DISRX_ST0 , 0x04 },
41 { STB0899_DISRX_ST1 , 0x00 },
42 { STB0899_DISPARITY , 0x00 },
43 { STB0899_DISFIFO , 0x00 },
44 { STB0899_DISSTATUS , 0x20 },
45 { STB0899_DISF22 , 0x99 },
46 { STB0899_DISF22RX , 0xa8 },
47 /* SYSREG ? */
48 { STB0899_ACRPRESC , 0x11 },
49 { STB0899_ACRDIV1 , 0x0a },
50 { STB0899_ACRDIV2 , 0x05 },
51 { STB0899_DACR1 , 0x00 },
52 { STB0899_DACR2 , 0x00 },
53 { STB0899_OUTCFG , 0x00 },
54 { STB0899_MODECFG , 0x00 },
55 { STB0899_IRQSTATUS_3 , 0xfe },
56 { STB0899_IRQSTATUS_2 , 0x03 },
57 { STB0899_IRQSTATUS_1 , 0x7c },
58 { STB0899_IRQSTATUS_0 , 0xf4 },
59 { STB0899_IRQMSK_3 , 0xf3 },
60 { STB0899_IRQMSK_2 , 0xfc },
61 { STB0899_IRQMSK_1 , 0xff },
62 { STB0899_IRQMSK_0 , 0xff },
63 { STB0899_IRQCFG , 0x00 },
64 { STB0899_I2CCFG , 0x88 },
65 { STB0899_I2CRPT , 0x58 },
66 { STB0899_IOPVALUE5 , 0x00 },
67 { STB0899_IOPVALUE4 , 0x33 },
68 { STB0899_IOPVALUE3 , 0x6d },
69 { STB0899_IOPVALUE2 , 0x90 },
70 { STB0899_IOPVALUE1 , 0x60 },
71 { STB0899_IOPVALUE0 , 0x00 },
72 { STB0899_GPIO00CFG , 0x82 },
73 { STB0899_GPIO01CFG , 0x82 },
74 { STB0899_GPIO02CFG , 0x82 },
75 { STB0899_GPIO03CFG , 0x82 },
76 { STB0899_GPIO04CFG , 0x82 },
77 { STB0899_GPIO05CFG , 0x82 },
78 { STB0899_GPIO06CFG , 0x82 },
79 { STB0899_GPIO07CFG , 0x82 },
80 { STB0899_GPIO08CFG , 0x82 },
81 { STB0899_GPIO09CFG , 0x82 },
82 { STB0899_GPIO10CFG , 0x82 },
83 { STB0899_GPIO11CFG , 0x82 },
84 { STB0899_GPIO12CFG , 0x82 },
85 { STB0899_GPIO13CFG , 0x82 },
86 { STB0899_GPIO14CFG , 0x82 },
87 { STB0899_GPIO15CFG , 0x82 },
88 { STB0899_GPIO16CFG , 0x82 },
89 { STB0899_GPIO17CFG , 0x82 },
90 { STB0899_GPIO18CFG , 0x82 },
91 { STB0899_GPIO19CFG , 0x82 },
92 { STB0899_GPIO20CFG , 0x82 },
93 { STB0899_SDATCFG , 0xb8 },
94 { STB0899_SCLTCFG , 0xba },
95 { STB0899_AGCRFCFG , 0x1c }, /* 0x11 */
96 { STB0899_GPIO22 , 0x82 }, /* AGCBB2CFG */
97 { STB0899_GPIO21 , 0x91 }, /* AGCBB1CFG */
98 { STB0899_DIRCLKCFG , 0x82 },
99 { STB0899_CLKOUT27CFG , 0x7e },
100 { STB0899_STDBYCFG , 0x82 },
101 { STB0899_CS0CFG , 0x82 },
102 { STB0899_CS1CFG , 0x82 },
103 { STB0899_DISEQCOCFG , 0x20 },
104 { STB0899_GPIO32CFG , 0x82 },
105 { STB0899_GPIO33CFG , 0x82 },
106 { STB0899_GPIO34CFG , 0x82 },
107 { STB0899_GPIO35CFG , 0x82 },
108 { STB0899_GPIO36CFG , 0x82 },
109 { STB0899_GPIO37CFG , 0x82 },
110 { STB0899_GPIO38CFG , 0x82 },
111 { STB0899_GPIO39CFG , 0x82 },
112 { STB0899_NCOARSE , 0x17 }, /* 0x15 = 27 Mhz Clock, F/3 = 198MHz, F/6 = 99MHz */
113 { STB0899_SYNTCTRL , 0x02 }, /* 0x00 = CLK from CLKI, 0x02 = CLK from XTALI */
114 { STB0899_FILTCTRL , 0x00 },
115 { STB0899_SYSCTRL , 0x01 },
116 { STB0899_STOPCLK1 , 0x20 },
117 { STB0899_STOPCLK2 , 0x00 },
118 { STB0899_INTBUFSTATUS , 0x00 },
119 { STB0899_INTBUFCTRL , 0x0a },
120 { 0xffff , 0xff },
121};
122
123static const struct stb0899_s1_reg az6027_stb0899_s1_init_3[] = {
124 { STB0899_DEMOD , 0x00 },
125 { STB0899_RCOMPC , 0xc9 },
126 { STB0899_AGC1CN , 0x01 },
127 { STB0899_AGC1REF , 0x10 },
128 { STB0899_RTC , 0x23 },
129 { STB0899_TMGCFG , 0x4e },
130 { STB0899_AGC2REF , 0x34 },
131 { STB0899_TLSR , 0x84 },
132 { STB0899_CFD , 0xf7 },
133 { STB0899_ACLC , 0x87 },
134 { STB0899_BCLC , 0x94 },
135 { STB0899_EQON , 0x41 },
136 { STB0899_LDT , 0xf1 },
137 { STB0899_LDT2 , 0xe3 },
138 { STB0899_EQUALREF , 0xb4 },
139 { STB0899_TMGRAMP , 0x10 },
140 { STB0899_TMGTHD , 0x30 },
141 { STB0899_IDCCOMP , 0xfd },
142 { STB0899_QDCCOMP , 0xff },
143 { STB0899_POWERI , 0x0c },
144 { STB0899_POWERQ , 0x0f },
145 { STB0899_RCOMP , 0x6c },
146 { STB0899_AGCIQIN , 0x80 },
147 { STB0899_AGC2I1 , 0x06 },
148 { STB0899_AGC2I2 , 0x00 },
149 { STB0899_TLIR , 0x30 },
150 { STB0899_RTF , 0x7f },
151 { STB0899_DSTATUS , 0x00 },
152 { STB0899_LDI , 0xbc },
153 { STB0899_CFRM , 0xea },
154 { STB0899_CFRL , 0x31 },
155 { STB0899_NIRM , 0x2b },
156 { STB0899_NIRL , 0x80 },
157 { STB0899_ISYMB , 0x1d },
158 { STB0899_QSYMB , 0xa6 },
159 { STB0899_SFRH , 0x2f },
160 { STB0899_SFRM , 0x68 },
161 { STB0899_SFRL , 0x40 },
162 { STB0899_SFRUPH , 0x2f },
163 { STB0899_SFRUPM , 0x68 },
164 { STB0899_SFRUPL , 0x40 },
165 { STB0899_EQUAI1 , 0x02 },
166 { STB0899_EQUAQ1 , 0xff },
167 { STB0899_EQUAI2 , 0x04 },
168 { STB0899_EQUAQ2 , 0x05 },
169 { STB0899_EQUAI3 , 0x02 },
170 { STB0899_EQUAQ3 , 0xfd },
171 { STB0899_EQUAI4 , 0x03 },
172 { STB0899_EQUAQ4 , 0x07 },
173 { STB0899_EQUAI5 , 0x08 },
174 { STB0899_EQUAQ5 , 0xf5 },
175 { STB0899_DSTATUS2 , 0x00 },
176 { STB0899_VSTATUS , 0x00 },
177 { STB0899_VERROR , 0x86 },
178 { STB0899_IQSWAP , 0x2a },
179 { STB0899_ECNT1M , 0x00 },
180 { STB0899_ECNT1L , 0x00 },
181 { STB0899_ECNT2M , 0x00 },
182 { STB0899_ECNT2L , 0x00 },
183 { STB0899_ECNT3M , 0x0a },
184 { STB0899_ECNT3L , 0xad },
185 { STB0899_FECAUTO1 , 0x06 },
186 { STB0899_FECM , 0x01 },
187 { STB0899_VTH12 , 0xb0 },
188 { STB0899_VTH23 , 0x7a },
189 { STB0899_VTH34 , 0x58 },
190 { STB0899_VTH56 , 0x38 },
191 { STB0899_VTH67 , 0x34 },
192 { STB0899_VTH78 , 0x24 },
193 { STB0899_PRVIT , 0xff },
194 { STB0899_VITSYNC , 0x19 },
195 { STB0899_RSULC , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
196 { STB0899_TSULC , 0x42 },
197 { STB0899_RSLLC , 0x41 },
198 { STB0899_TSLPL , 0x12 },
199 { STB0899_TSCFGH , 0x0c },
200 { STB0899_TSCFGM , 0x00 },
201 { STB0899_TSCFGL , 0x00 },
202 { STB0899_TSOUT , 0x69 }, /* 0x0d for CAM */
203 { STB0899_RSSYNCDEL , 0x00 },
204 { STB0899_TSINHDELH , 0x02 },
205 { STB0899_TSINHDELM , 0x00 },
206 { STB0899_TSINHDELL , 0x00 },
207 { STB0899_TSLLSTKM , 0x1b },
208 { STB0899_TSLLSTKL , 0xb3 },
209 { STB0899_TSULSTKM , 0x00 },
210 { STB0899_TSULSTKL , 0x00 },
211 { STB0899_PCKLENUL , 0xbc },
212 { STB0899_PCKLENLL , 0xcc },
213 { STB0899_RSPCKLEN , 0xbd },
214 { STB0899_TSSTATUS , 0x90 },
215 { STB0899_ERRCTRL1 , 0xb6 },
216 { STB0899_ERRCTRL2 , 0x95 },
217 { STB0899_ERRCTRL3 , 0x8d },
218 { STB0899_DMONMSK1 , 0x27 },
219 { STB0899_DMONMSK0 , 0x03 },
220 { STB0899_DEMAPVIT , 0x5c },
221 { STB0899_PLPARM , 0x19 },
222 { STB0899_PDELCTRL , 0x48 },
223 { STB0899_PDELCTRL2 , 0x00 },
224 { STB0899_BBHCTRL1 , 0x00 },
225 { STB0899_BBHCTRL2 , 0x00 },
226 { STB0899_HYSTTHRESH , 0x77 },
227 { STB0899_MATCSTM , 0x00 },
228 { STB0899_MATCSTL , 0x00 },
229 { STB0899_UPLCSTM , 0x00 },
230 { STB0899_UPLCSTL , 0x00 },
231 { STB0899_DFLCSTM , 0x00 },
232 { STB0899_DFLCSTL , 0x00 },
233 { STB0899_SYNCCST , 0x00 },
234 { STB0899_SYNCDCSTM , 0x00 },
235 { STB0899_SYNCDCSTL , 0x00 },
236 { STB0899_ISI_ENTRY , 0x00 },
237 { STB0899_ISI_BIT_EN , 0x00 },
238 { STB0899_MATSTRM , 0xf0 },
239 { STB0899_MATSTRL , 0x02 },
240 { STB0899_UPLSTRM , 0x45 },
241 { STB0899_UPLSTRL , 0x60 },
242 { STB0899_DFLSTRM , 0xe3 },
243 { STB0899_DFLSTRL , 0x00 },
244 { STB0899_SYNCSTR , 0x47 },
245 { STB0899_SYNCDSTRM , 0x05 },
246 { STB0899_SYNCDSTRL , 0x18 },
247 { STB0899_CFGPDELSTATUS1 , 0x19 },
248 { STB0899_CFGPDELSTATUS2 , 0x2b },
249 { STB0899_BBFERRORM , 0x00 },
250 { STB0899_BBFERRORL , 0x01 },
251 { STB0899_UPKTERRORM , 0x00 },
252 { STB0899_UPKTERRORL , 0x00 },
253 { 0xffff , 0xff },
254};
255
256
257
258struct stb0899_config az6027_stb0899_config = {
259 .init_dev = az6027_stb0899_s1_init_1,
260 .init_s2_demod = stb0899_s2_init_2,
261 .init_s1_demod = az6027_stb0899_s1_init_3,
262 .init_s2_fec = stb0899_s2_init_4,
263 .init_tst = stb0899_s1_init_5,
264
265 .demod_address = 0xd0, /* 0x68, 0xd0 >> 1 */
266
267 .xtal_freq = 27000000,
268 .inversion = IQ_SWAP_ON, /* 1 */
269
270 .lo_clk = 76500000,
271 .hi_clk = 99000000,
272
273 .esno_ave = STB0899_DVBS2_ESNO_AVE,
274 .esno_quant = STB0899_DVBS2_ESNO_QUANT,
275 .avframes_coarse = STB0899_DVBS2_AVFRAMES_COARSE,
276 .avframes_fine = STB0899_DVBS2_AVFRAMES_FINE,
277 .miss_threshold = STB0899_DVBS2_MISS_THRESHOLD,
278 .uwp_threshold_acq = STB0899_DVBS2_UWP_THRESHOLD_ACQ,
279 .uwp_threshold_track = STB0899_DVBS2_UWP_THRESHOLD_TRACK,
280 .uwp_threshold_sof = STB0899_DVBS2_UWP_THRESHOLD_SOF,
281 .sof_search_timeout = STB0899_DVBS2_SOF_SEARCH_TIMEOUT,
282
283 .btr_nco_bits = STB0899_DVBS2_BTR_NCO_BITS,
284 .btr_gain_shift_offset = STB0899_DVBS2_BTR_GAIN_SHIFT_OFFSET,
285 .crl_nco_bits = STB0899_DVBS2_CRL_NCO_BITS,
286 .ldpc_max_iter = STB0899_DVBS2_LDPC_MAX_ITER,
287
288 .tuner_get_frequency = stb6100_get_frequency,
289 .tuner_set_frequency = stb6100_set_frequency,
290 .tuner_set_bandwidth = stb6100_set_bandwidth,
291 .tuner_get_bandwidth = stb6100_get_bandwidth,
292 .tuner_set_rfsiggain = NULL,
293};
294
295struct stb6100_config az6027_stb6100_config = {
296 .tuner_address = 0xc0,
297 .refclock = 27000000,
298};
299
300
301/* check for mutex FIXME */
302int az6027_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
303{
304 int ret = -1;
305 if (mutex_lock_interruptible(&d->usb_mutex))
306 return -EAGAIN;
307
308 ret = usb_control_msg(d->udev,
309 usb_rcvctrlpipe(d->udev, 0),
310 req,
311 USB_TYPE_VENDOR | USB_DIR_IN,
312 value,
313 index,
314 b,
315 blen,
316 2000);
317
318 if (ret < 0) {
319 warn("usb in operation failed. (%d)", ret);
320 ret = -EIO;
321 } else
322 ret = 0;
323
324 deb_xfer("in: req. %02x, val: %04x, ind: %04x, buffer: ", req, value, index);
325 debug_dump(b, blen, deb_xfer);
326
327 mutex_unlock(&d->usb_mutex);
328 return ret;
329}
330
331static int az6027_usb_out_op(struct dvb_usb_device *d,
332 u8 req,
333 u16 value,
334 u16 index,
335 u8 *b,
336 int blen)
337{
338 int ret;
339
340 deb_xfer("out: req. %02x, val: %04x, ind: %04x, buffer: ", req, value, index);
341 debug_dump(b, blen, deb_xfer);
342
343 if (mutex_lock_interruptible(&d->usb_mutex))
344 return -EAGAIN;
345
346 ret = usb_control_msg(d->udev,
347 usb_sndctrlpipe(d->udev, 0),
348 req,
349 USB_TYPE_VENDOR | USB_DIR_OUT,
350 value,
351 index,
352 b,
353 blen,
354 2000);
355
356 if (ret != blen) {
357 warn("usb out operation failed. (%d)", ret);
358 mutex_unlock(&d->usb_mutex);
359 return -EIO;
360 } else{
361 mutex_unlock(&d->usb_mutex);
362 return 0;
363 }
364}
365
366static int az6027_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
367{
368 int ret;
369 u8 req;
370 u16 value;
371 u16 index;
372 int blen;
373
374 deb_info("%s %d", __func__, onoff);
375
376 req = 0xBC;
377 value = onoff;
378 index = 0;
379 blen = 0;
380
381 ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen);
382 if (ret != 0)
383 warn("usb out operation failed. (%d)", ret);
384
385 return ret;
386}
387
388/* keys for the enclosed remote control */
389static struct dvb_usb_rc_key az6027_rc_keys[] = {
390 { 0x01, KEY_1 },
391 { 0x02, KEY_2 },
392};
393
394/* remote control stuff (does not work with my box) */
395static int az6027_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
396{
397 return 0;
398}
399
400/*
401int az6027_power_ctrl(struct dvb_usb_device *d, int onoff)
402{
403 u8 v = onoff;
404 return az6027_usb_out_op(d,0xBC,v,3,NULL,1);
405}
406*/
407
408static int az6027_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
409 int slot,
410 int address)
411{
412 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
413 struct az6027_device_state *state = (struct az6027_device_state *)d->priv;
414
415 int ret;
416 u8 req;
417 u16 value;
418 u16 index;
419 int blen;
420 u8 b[12];
421
422 if (slot != 0)
423 return -EINVAL;
424
425 mutex_lock(&state->ca_mutex);
426
427 req = 0xC1;
428 value = address;
429 index = 0;
430 blen = 1;
431
432 ret = az6027_usb_in_op(d, req, value, index, b, blen);
433 if (ret < 0) {
434 warn("usb in operation failed. (%d)", ret);
435 ret = -EINVAL;
436 } else {
437 ret = b[0];
438 }
439
440 mutex_unlock(&state->ca_mutex);
441 return ret;
442}
443
444static int az6027_ci_write_attribute_mem(struct dvb_ca_en50221 *ca,
445 int slot,
446 int address,
447 u8 value)
448{
449 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
450 struct az6027_device_state *state = (struct az6027_device_state *)d->priv;
451
452 int ret;
453 u8 req;
454 u16 value1;
455 u16 index;
456 int blen;
457
458 deb_info("%s %d", __func__, slot);
459 if (slot != 0)
460 return -EINVAL;
461
462 mutex_lock(&state->ca_mutex);
463 req = 0xC2;
464 value1 = address;
465 index = value;
466 blen = 0;
467
468 ret = az6027_usb_out_op(d, req, value1, index, NULL, blen);
469 if (ret != 0)
470 warn("usb out operation failed. (%d)", ret);
471
472 mutex_unlock(&state->ca_mutex);
473 return ret;
474}
475
476static int az6027_ci_read_cam_control(struct dvb_ca_en50221 *ca,
477 int slot,
478 u8 address)
479{
480 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
481 struct az6027_device_state *state = (struct az6027_device_state *)d->priv;
482
483 int ret;
484 u8 req;
485 u16 value;
486 u16 index;
487 int blen;
488 u8 b[12];
489
490 if (slot != 0)
491 return -EINVAL;
492
493 mutex_lock(&state->ca_mutex);
494
495 req = 0xC3;
496 value = address;
497 index = 0;
498 blen = 2;
499
500 ret = az6027_usb_in_op(d, req, value, index, b, blen);
501 if (ret < 0) {
502 warn("usb in operation failed. (%d)", ret);
503 ret = -EINVAL;
504 } else {
505 if (b[0] == 0)
506 warn("Read CI IO error");
507
508 ret = b[1];
509 deb_info("read cam data = %x from 0x%x", b[1], value);
510 }
511
512 mutex_unlock(&state->ca_mutex);
513 return ret;
514}
515
516static int az6027_ci_write_cam_control(struct dvb_ca_en50221 *ca,
517 int slot,
518 u8 address,
519 u8 value)
520{
521 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
522 struct az6027_device_state *state = (struct az6027_device_state *)d->priv;
523
524 int ret;
525 u8 req;
526 u16 value1;
527 u16 index;
528 int blen;
529
530 if (slot != 0)
531 return -EINVAL;
532
533 mutex_lock(&state->ca_mutex);
534 req = 0xC4;
535 value1 = address;
536 index = value;
537 blen = 0;
538
539 ret = az6027_usb_out_op(d, req, value1, index, NULL, blen);
540 if (ret != 0) {
541 warn("usb out operation failed. (%d)", ret);
542 goto failed;
543 }
544
545failed:
546 mutex_unlock(&state->ca_mutex);
547 return ret;
548}
549
550static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot)
551{
552 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
553
554 int ret;
555 u8 req;
556 u16 value;
557 u16 index;
558 int blen;
559 u8 b[12];
560
561 req = 0xC8;
562 value = 0;
563 index = 0;
564 blen = 1;
565
566 ret = az6027_usb_in_op(d, req, value, index, b, blen);
567 if (ret < 0) {
568 warn("usb in operation failed. (%d)", ret);
569 ret = -EIO;
570 } else{
571 ret = b[0];
572 }
573 return ret;
574}
575
576static int az6027_ci_slot_reset(struct dvb_ca_en50221 *ca, int slot)
577{
578 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
579 struct az6027_device_state *state = (struct az6027_device_state *)d->priv;
580
581 int ret, i;
582 u8 req;
583 u16 value;
584 u16 index;
585 int blen;
586
587 mutex_lock(&state->ca_mutex);
588
589 req = 0xC6;
590 value = 1;
591 index = 0;
592 blen = 0;
593
594 ret = az6027_usb_out_op(d, req, value, index, NULL, blen);
595 if (ret != 0) {
596 warn("usb out operation failed. (%d)", ret);
597 goto failed;
598 }
599
600 msleep(500);
601 req = 0xC6;
602 value = 0;
603 index = 0;
604 blen = 0;
605
606 ret = az6027_usb_out_op(d, req, value, index, NULL, blen);
607 if (ret != 0) {
608 warn("usb out operation failed. (%d)", ret);
609 goto failed;
610 }
611
612 for (i = 0; i < 15; i++) {
613 msleep(100);
614
615 if (CI_CamReady(ca, slot)) {
616 deb_info("CAM Ready");
617 break;
618 }
619 }
620 msleep(5000);
621
622failed:
623 mutex_unlock(&state->ca_mutex);
624 return ret;
625}
626
627static int az6027_ci_slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
628{
629 return 0;
630}
631
632static int az6027_ci_slot_ts_enable(struct dvb_ca_en50221 *ca, int slot)
633{
634 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
635 struct az6027_device_state *state = (struct az6027_device_state *)d->priv;
636
637 int ret;
638 u8 req;
639 u16 value;
640 u16 index;
641 int blen;
642
643 deb_info("%s", __func__);
644 mutex_lock(&state->ca_mutex);
645 req = 0xC7;
646 value = 1;
647 index = 0;
648 blen = 0;
649
650 ret = az6027_usb_out_op(d, req, value, index, NULL, blen);
651 if (ret != 0) {
652 warn("usb out operation failed. (%d)", ret);
653 goto failed;
654 }
655
656failed:
657 mutex_unlock(&state->ca_mutex);
658 return ret;
659}
660
661static int az6027_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int open)
662{
663 struct dvb_usb_device *d = (struct dvb_usb_device *)ca->data;
664 struct az6027_device_state *state = (struct az6027_device_state *)d->priv;
665 int ret;
666 u8 req;
667 u16 value;
668 u16 index;
669 int blen;
670 u8 b[12];
671
672 mutex_lock(&state->ca_mutex);
673
674 req = 0xC5;
675 value = 0;
676 index = 0;
677 blen = 1;
678
679 ret = az6027_usb_in_op(d, req, value, index, b, blen);
680 if (ret < 0) {
681 warn("usb in operation failed. (%d)", ret);
682 ret = -EIO;
683 } else
684 ret = 0;
685
686 if (b[0] == 0) {
687 ret = 0;
688
689 } else if (b[0] == 1) {
690 ret = DVB_CA_EN50221_POLL_CAM_PRESENT |
691 DVB_CA_EN50221_POLL_CAM_READY;
692 }
693
694 mutex_unlock(&state->ca_mutex);
695 return ret;
696}
697
698
699static void az6027_ci_uninit(struct dvb_usb_device *d)
700{
701 struct az6027_device_state *state;
702
703 deb_info("%s", __func__);
704
705 if (NULL == d)
706 return;
707
708 state = (struct az6027_device_state *)d->priv;
709 if (NULL == state)
710 return;
711
712 if (NULL == state->ca.data)
713 return;
714
715 dvb_ca_en50221_release(&state->ca);
716
717 memset(&state->ca, 0, sizeof(state->ca));
718}
719
720
721static int az6027_ci_init(struct dvb_usb_adapter *a)
722{
723 struct dvb_usb_device *d = a->dev;
724 struct az6027_device_state *state = (struct az6027_device_state *)d->priv;
725 int ret;
726
727 deb_info("%s", __func__);
728
729 mutex_init(&state->ca_mutex);
730
731 state->ca.owner = THIS_MODULE;
732 state->ca.read_attribute_mem = az6027_ci_read_attribute_mem;
733 state->ca.write_attribute_mem = az6027_ci_write_attribute_mem;
734 state->ca.read_cam_control = az6027_ci_read_cam_control;
735 state->ca.write_cam_control = az6027_ci_write_cam_control;
736 state->ca.slot_reset = az6027_ci_slot_reset;
737 state->ca.slot_shutdown = az6027_ci_slot_shutdown;
738 state->ca.slot_ts_enable = az6027_ci_slot_ts_enable;
739 state->ca.poll_slot_status = az6027_ci_poll_slot_status;
740 state->ca.data = d;
741
742 ret = dvb_ca_en50221_init(&a->dvb_adap,
743 &state->ca,
744 0, /* flags */
745 1);/* n_slots */
746 if (ret != 0) {
747 err("Cannot initialize CI: Error %d.", ret);
748 memset(&state->ca, 0, sizeof(state->ca));
749 return ret;
750 }
751
752 deb_info("CI initialized.");
753
754 return 0;
755}
756
757/*
758static int az6027_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
759{
760 az6027_usb_in_op(d, 0xb7, 6, 0, &mac[0], 6);
761 return 0;
762}
763*/
764
765static int az6027_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
766{
767
768 u8 buf;
769 int ret;
770 struct dvb_usb_adapter *adap = fe->dvb->priv;
771
772 struct i2c_msg i2c_msg = {
773 .addr = 0x99,
774 .flags = 0,
775 .buf = &buf,
776 .len = 1
777 };
778
779 /*
780 * 2 --18v
781 * 1 --13v
782 * 0 --off
783 */
784 switch (voltage) {
785 case SEC_VOLTAGE_13:
786 buf = 1;
787 ret = i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
788 break;
789
790 case SEC_VOLTAGE_18:
791 buf = 2;
792 ret = i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
793 break;
794
795 case SEC_VOLTAGE_OFF:
796 buf = 0;
797 ret = i2c_transfer(&adap->dev->i2c_adap, &i2c_msg, 1);
798 break;
799
800 default:
801 return -EINVAL;
802 }
803 return 0;
804}
805
806
807static int az6027_frontend_poweron(struct dvb_usb_adapter *adap)
808{
809 int ret;
810 u8 req;
811 u16 value;
812 u16 index;
813 int blen;
814
815 req = 0xBC;
816 value = 1; /* power on */
817 index = 3;
818 blen = 0;
819
820 ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen);
821 if (ret != 0)
822 return -EIO;
823
824 return 0;
825}
826static int az6027_frontend_reset(struct dvb_usb_adapter *adap)
827{
828 int ret;
829 u8 req;
830 u16 value;
831 u16 index;
832 int blen;
833
834 /* reset demodulator */
835 req = 0xC0;
836 value = 1; /* high */
837 index = 3;
838 blen = 0;
839
840 ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen);
841 if (ret != 0)
842 return -EIO;
843
844 req = 0xC0;
845 value = 0; /* low */
846 index = 3;
847 blen = 0;
848 msleep_interruptible(200);
849
850 ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen);
851 if (ret != 0)
852 return -EIO;
853
854 msleep_interruptible(200);
855
856 req = 0xC0;
857 value = 1; /*high */
858 index = 3;
859 blen = 0;
860
861 ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen);
862 if (ret != 0)
863 return -EIO;
864
865 msleep_interruptible(200);
866 return 0;
867}
868
869static int az6027_frontend_tsbypass(struct dvb_usb_adapter *adap, int onoff)
870{
871 int ret;
872 u8 req;
873 u16 value;
874 u16 index;
875 int blen;
876
877 /* TS passthrough */
878 req = 0xC7;
879 value = onoff;
880 index = 0;
881 blen = 0;
882
883 ret = az6027_usb_out_op(adap->dev, req, value, index, NULL, blen);
884 if (ret != 0)
885 return -EIO;
886
887 return 0;
888}
889
890static int az6027_frontend_attach(struct dvb_usb_adapter *adap)
891{
892
893 az6027_frontend_poweron(adap);
894 az6027_frontend_reset(adap);
895
896 deb_info("adap = %p, dev = %p\n", adap, adap->dev);
897 adap->fe = stb0899_attach(&az6027_stb0899_config, &adap->dev->i2c_adap);
898
899 if (adap->fe) {
900 deb_info("found STB0899 DVB-S/DVB-S2 frontend @0x%02x", az6027_stb0899_config.demod_address);
901 if (stb6100_attach(adap->fe, &az6027_stb6100_config, &adap->dev->i2c_adap)) {
902 deb_info("found STB6100 DVB-S/DVB-S2 frontend @0x%02x", az6027_stb6100_config.tuner_address);
903 adap->fe->ops.set_voltage = az6027_set_voltage;
904 az6027_ci_init(adap);
905 } else {
906 adap->fe = NULL;
907 }
908 } else
909 warn("no front-end attached\n");
910
911 az6027_frontend_tsbypass(adap, 0);
912
913 return 0;
914}
915
916static struct dvb_usb_device_properties az6027_properties;
917
918static void az6027_usb_disconnect(struct usb_interface *intf)
919{
920 struct dvb_usb_device *d = usb_get_intfdata(intf);
921 az6027_ci_uninit(d);
922 dvb_usb_device_exit(intf);
923}
924
925
926static int az6027_usb_probe(struct usb_interface *intf,
927 const struct usb_device_id *id)
928{
929 return dvb_usb_device_init(intf,
930 &az6027_properties,
931 THIS_MODULE,
932 NULL,
933 adapter_nr);
934}
935
936/* I2C */
937static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
938{
939 struct dvb_usb_device *d = i2c_get_adapdata(adap);
940 int i = 0, j = 0, len = 0;
941 int ret;
942 u16 index;
943 u16 value;
944 int length;
945 u8 req;
946 u8 data[256];
947
948 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
949 return -EAGAIN;
950
951 if (num > 2)
952 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
953
954 for (i = 0; i < num; i++) {
955
956 if (msg[i].addr == 0x99) {
957 req = 0xBE;
958 index = 0;
959 value = msg[i].buf[0] & 0x00ff;
960 length = 1;
961 az6027_usb_out_op(d, req, value, index, data, length);
962 }
963
964 if (msg[i].addr == 0xd0) {
965 /* write/read request */
966 if (i + 1 < num && (msg[i + 1].flags & I2C_M_RD)) {
967 req = 0xB9;
968 index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff));
969 value = msg[i].addr + (msg[i].len << 8);
970 length = msg[i + 1].len + 6;
971 ret = az6027_usb_in_op(d, req, value, index, data, length);
972 len = msg[i + 1].len;
973 for (j = 0; j < len; j++)
974 msg[i + 1].buf[j] = data[j + 5];
975
976 i++;
977 } else {
978
979 if (msg[i].addr == 0xd0) {
980 /* demod 16bit addr */
981 req = 0xBD;
982 index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff));
983 value = msg[i].addr + (2 << 8);
984 length = msg[i].len - 2;
985 len = msg[i].len - 2;
986 for (j = 0; j < len; j++)
987 data[j] = msg[i].buf[j + 2];
988
989 }
990 az6027_usb_out_op(d, req, value, index, data, length);
991 }
992 }
993
994 if (msg[i].addr == 0xc0) {
995 if (msg[i].flags & I2C_M_RD) {
996
997 req = 0xB9;
998 index = 0x0;
999 value = msg[i].addr;
1000 length = msg[i].len + 6;
1001 ret = az6027_usb_in_op(d, req, value, index, data, length);
1002 len = msg[i].len;
1003 for (j = 0; j < len; j++)
1004 msg[i].buf[j] = data[j + 5];
1005
1006 } else {
1007
1008 req = 0xBD;
1009 index = msg[i].buf[0] & 0x00FF;
1010 value = msg[i].addr + (1 << 8);
1011 length = msg[i].len - 1;
1012 len = msg[i].len - 1;
1013
1014 for (j = 0; j < len; j++)
1015 data[j] = msg[i].buf[j + 1];
1016
1017 az6027_usb_out_op(d, req, value, index, data, length);
1018 }
1019 }
1020 }
1021 mutex_unlock(&d->i2c_mutex);
1022
1023 return i;
1024}
1025
1026
1027static u32 az6027_i2c_func(struct i2c_adapter *adapter)
1028{
1029 return I2C_FUNC_I2C;
1030}
1031
1032static struct i2c_algorithm az6027_i2c_algo = {
1033 .master_xfer = az6027_i2c_xfer,
1034 .functionality = az6027_i2c_func,
1035};
1036
1037int az6027_identify_state(struct usb_device *udev,
1038 struct dvb_usb_device_properties *props,
1039 struct dvb_usb_device_description **desc,
1040 int *cold)
1041{
1042 u8 b[16];
1043 s16 ret = usb_control_msg(udev,
1044 usb_rcvctrlpipe(udev, 0),
1045 0xb7,
1046 USB_TYPE_VENDOR | USB_DIR_IN,
1047 6,
1048 0,
1049 b,
1050 6,
1051 USB_CTRL_GET_TIMEOUT);
1052
1053 *cold = ret <= 0;
1054
1055 deb_info("cold: %d\n", *cold);
1056 return 0;
1057}
1058
1059
1060static struct usb_device_id az6027_usb_table[] = {
1061 { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_AZ6027) },
1062 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_DVBS2CI) },
1063 { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI) },
1064 { },
1065};
1066
1067MODULE_DEVICE_TABLE(usb, az6027_usb_table);
1068
1069static struct dvb_usb_device_properties az6027_properties = {
1070 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1071 .usb_ctrl = CYPRESS_FX2,
1072 .firmware = "dvb-usb-az6027-03.fw",
1073 .no_reconnect = 1,
1074
1075 .size_of_priv = sizeof(struct az6027_device_state),
1076 .identify_state = az6027_identify_state,
1077 .num_adapters = 1,
1078 .adapter = {
1079 {
1080 .streaming_ctrl = az6027_streaming_ctrl,
1081 .frontend_attach = az6027_frontend_attach,
1082
1083 /* parameter for the MPEG2-data transfer */
1084 .stream = {
1085 .type = USB_BULK,
1086 .count = 10,
1087 .endpoint = 0x02,
1088 .u = {
1089 .bulk = {
1090 .buffersize = 4096,
1091 }
1092 }
1093 },
1094 }
1095 },
1096/*
1097 .power_ctrl = az6027_power_ctrl,
1098 .read_mac_address = az6027_read_mac_addr,
1099 */
1100 .rc_key_map = az6027_rc_keys,
1101 .rc_key_map_size = ARRAY_SIZE(az6027_rc_keys),
1102 .rc_interval = 400,
1103 .rc_query = az6027_rc_query,
1104 .i2c_algo = &az6027_i2c_algo,
1105
1106 .num_device_descs = 1,
1107 .devices = {
1108 {
1109 .name = "AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)",
1110 .cold_ids = { &az6027_usb_table[0], NULL },
1111 .warm_ids = { NULL },
1112 },
1113 { NULL },
1114 }
1115};
1116
1117/* usb specific object needed to register this driver with the usb subsystem */
1118static struct usb_driver az6027_usb_driver = {
1119 .name = "dvb_usb_az6027",
1120 .probe = az6027_usb_probe,
1121 .disconnect = az6027_usb_disconnect,
1122 .id_table = az6027_usb_table,
1123};
1124
1125/* module stuff */
1126static int __init az6027_usb_module_init(void)
1127{
1128 int result;
1129
1130 result = usb_register(&az6027_usb_driver);
1131 if (result) {
1132 err("usb_register failed. (%d)", result);
1133 return result;
1134 }
1135
1136 return 0;
1137}
1138
1139static void __exit az6027_usb_module_exit(void)
1140{
1141 /* deregister this driver from the USB subsystem */
1142 usb_deregister(&az6027_usb_driver);
1143}
1144
1145module_init(az6027_usb_module_init);
1146module_exit(az6027_usb_module_exit);
1147
1148MODULE_AUTHOR("Adams Xu <Adams.xu@azwave.com.cn>");
1149MODULE_DESCRIPTION("Driver for AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)");
1150MODULE_VERSION("1.0");
1151MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/az6027.h b/drivers/media/dvb/dvb-usb/az6027.h
new file mode 100644
index 000000000000..f3afe17f3f3d
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/az6027.h
@@ -0,0 +1,14 @@
1#ifndef _DVB_USB_VP6027_H_
2#define _DVB_USB_VP6027_H_
3
4#define DVB_USB_LOG_PREFIX "az6027"
5#include "dvb-usb.h"
6
7
8extern int dvb_usb_az6027_debug;
9#define deb_info(args...) dprintk(dvb_usb_az6027_debug, 0x01, args)
10#define deb_xfer(args...) dprintk(dvb_usb_az6027_debug, 0x02, args)
11#define deb_rc(args...) dprintk(dvb_usb_az6027_debug, 0x04, args)
12#define deb_fe(args...) dprintk(dvb_usb_az6027_debug, 0x08, args)
13
14#endif
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 05fb28e9c69e..a7b8405c291e 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -1184,6 +1184,9 @@ static struct atbm8830_config mygica_d689_atbm8830_cfg = {
1184 .osc_clk_freq = 30400, /* in kHz */ 1184 .osc_clk_freq = 30400, /* in kHz */
1185 .if_freq = 0, /* zero IF */ 1185 .if_freq = 0, /* zero IF */
1186 .zif_swap_iq = 1, 1186 .zif_swap_iq = 1,
1187 .agc_min = 0x2E,
1188 .agc_max = 0x90,
1189 .agc_hold_loop = 0,
1187}; 1190};
1188 1191
1189static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap) 1192static int cxusb_mygica_d689_frontend_attach(struct dvb_usb_adapter *adap)
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index 495a90577c5f..83fc24a6c31a 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -42,7 +42,6 @@ struct dib0700_state {
42 u16 mt2060_if1[2]; 42 u16 mt2060_if1[2];
43 u8 rc_toggle; 43 u8 rc_toggle;
44 u8 rc_counter; 44 u8 rc_counter;
45 u8 rc_func_version;
46 u8 is_dib7000pc; 45 u8 is_dib7000pc;
47 u8 fw_use_new_i2c_api; 46 u8 fw_use_new_i2c_api;
48 u8 disable_streaming_master_mode; 47 u8 disable_streaming_master_mode;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index 0d3c9a9a33be..4f961d2d1817 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -471,14 +471,209 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
471 return dib0700_ctrl_wr(adap->dev, b, 4); 471 return dib0700_ctrl_wr(adap->dev, b, 4);
472} 472}
473 473
474/* Number of keypresses to ignore before start repeating */
475#define RC_REPEAT_DELAY_V1_20 10
476
477/* This is the structure of the RC response packet starting in firmware 1.20 */
478struct dib0700_rc_response {
479 u8 report_id;
480 u8 data_state;
481 u16 system;
482 u8 data;
483 u8 not_data;
484};
485#define RC_MSG_SIZE_V1_20 6
486
487static void dib0700_rc_urb_completion(struct urb *purb)
488{
489 struct dvb_usb_device *d = purb->context;
490 struct dvb_usb_rc_key *keymap;
491 struct dib0700_state *st;
492 struct dib0700_rc_response poll_reply;
493 u8 *buf;
494 int found = 0;
495 u32 event;
496 int state;
497 int i;
498
499 deb_info("%s()\n", __func__);
500 if (d == NULL)
501 return;
502
503 if (d->rc_input_dev == NULL) {
504 /* This will occur if disable_rc_polling=1 */
505 usb_free_urb(purb);
506 return;
507 }
508
509 keymap = d->props.rc_key_map;
510 st = d->priv;
511 buf = (u8 *)purb->transfer_buffer;
512
513 if (purb->status < 0) {
514 deb_info("discontinuing polling\n");
515 usb_free_urb(purb);
516 return;
517 }
518
519 if (purb->actual_length != RC_MSG_SIZE_V1_20) {
520 deb_info("malformed rc msg size=%d\n", purb->actual_length);
521 goto resubmit;
522 }
523
524 /* Set initial results in case we exit the function early */
525 event = 0;
526 state = REMOTE_NO_KEY_PRESSED;
527
528 deb_data("IR raw %02X %02X %02X %02X %02X %02X (len %d)\n", buf[0],
529 buf[1], buf[2], buf[3], buf[4], buf[5], purb->actual_length);
530
531 switch (dvb_usb_dib0700_ir_proto) {
532 case 0:
533 /* NEC Protocol */
534 poll_reply.report_id = 0;
535 poll_reply.data_state = 1;
536 poll_reply.system = buf[2];
537 poll_reply.data = buf[4];
538 poll_reply.not_data = buf[5];
539
540 /* NEC protocol sends repeat code as 0 0 0 FF */
541 if ((poll_reply.system == 0x00) && (poll_reply.data == 0x00)
542 && (poll_reply.not_data == 0xff)) {
543 poll_reply.data_state = 2;
544 break;
545 }
546 break;
547 default:
548 /* RC5 Protocol */
549 poll_reply.report_id = buf[0];
550 poll_reply.data_state = buf[1];
551 poll_reply.system = (buf[2] << 8) | buf[3];
552 poll_reply.data = buf[4];
553 poll_reply.not_data = buf[5];
554 break;
555 }
556
557 if ((poll_reply.data + poll_reply.not_data) != 0xff) {
558 /* Key failed integrity check */
559 err("key failed integrity check: %04x %02x %02x",
560 poll_reply.system,
561 poll_reply.data, poll_reply.not_data);
562 goto resubmit;
563 }
564
565 deb_data("rid=%02x ds=%02x sm=%04x d=%02x nd=%02x\n",
566 poll_reply.report_id, poll_reply.data_state,
567 poll_reply.system, poll_reply.data, poll_reply.not_data);
568
569 /* Find the key in the map */
570 for (i = 0; i < d->props.rc_key_map_size; i++) {
571 if (rc5_custom(&keymap[i]) == (poll_reply.system & 0xff) &&
572 rc5_data(&keymap[i]) == poll_reply.data) {
573 event = keymap[i].event;
574 found = 1;
575 break;
576 }
577 }
578
579 if (found == 0) {
580 err("Unknown remote controller key: %04x %02x %02x",
581 poll_reply.system, poll_reply.data, poll_reply.not_data);
582 d->last_event = 0;
583 goto resubmit;
584 }
585
586 if (poll_reply.data_state == 1) {
587 /* New key hit */
588 st->rc_counter = 0;
589 event = keymap[i].event;
590 state = REMOTE_KEY_PRESSED;
591 d->last_event = keymap[i].event;
592 } else if (poll_reply.data_state == 2) {
593 /* Key repeated */
594 st->rc_counter++;
595
596 /* prevents unwanted double hits */
597 if (st->rc_counter > RC_REPEAT_DELAY_V1_20) {
598 event = d->last_event;
599 state = REMOTE_KEY_PRESSED;
600 st->rc_counter = RC_REPEAT_DELAY_V1_20;
601 }
602 } else {
603 err("Unknown data state [%d]", poll_reply.data_state);
604 }
605
606 switch (state) {
607 case REMOTE_NO_KEY_PRESSED:
608 break;
609 case REMOTE_KEY_PRESSED:
610 deb_info("key pressed\n");
611 d->last_event = event;
612 case REMOTE_KEY_REPEAT:
613 deb_info("key repeated\n");
614 input_event(d->rc_input_dev, EV_KEY, event, 1);
615 input_sync(d->rc_input_dev);
616 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0);
617 input_sync(d->rc_input_dev);
618 break;
619 default:
620 break;
621 }
622
623resubmit:
624 /* Clean the buffer before we requeue */
625 memset(purb->transfer_buffer, 0, RC_MSG_SIZE_V1_20);
626
627 /* Requeue URB */
628 usb_submit_urb(purb, GFP_ATOMIC);
629}
630
474int dib0700_rc_setup(struct dvb_usb_device *d) 631int dib0700_rc_setup(struct dvb_usb_device *d)
475{ 632{
633 struct dib0700_state *st = d->priv;
476 u8 rc_setup[3] = {REQUEST_SET_RC, dvb_usb_dib0700_ir_proto, 0}; 634 u8 rc_setup[3] = {REQUEST_SET_RC, dvb_usb_dib0700_ir_proto, 0};
477 int i = dib0700_ctrl_wr(d, rc_setup, 3); 635 struct urb *purb;
636 int ret;
637 int i;
638
639 if (d->props.rc_key_map == NULL)
640 return 0;
641
642 /* Set the IR mode */
643 i = dib0700_ctrl_wr(d, rc_setup, 3);
478 if (i<0) { 644 if (i<0) {
479 err("ir protocol setup failed"); 645 err("ir protocol setup failed");
480 return -1; 646 return -1;
481 } 647 }
648
649 if (st->fw_version < 0x10200)
650 return 0;
651
652 /* Starting in firmware 1.20, the RC info is provided on a bulk pipe */
653 purb = usb_alloc_urb(0, GFP_KERNEL);
654 if (purb == NULL) {
655 err("rc usb alloc urb failed\n");
656 return -1;
657 }
658
659 purb->transfer_buffer = kzalloc(RC_MSG_SIZE_V1_20, GFP_KERNEL);
660 if (purb->transfer_buffer == NULL) {
661 err("rc kzalloc failed\n");
662 usb_free_urb(purb);
663 return -1;
664 }
665
666 purb->status = -EINPROGRESS;
667 usb_fill_bulk_urb(purb, d->udev, usb_rcvbulkpipe(d->udev, 1),
668 purb->transfer_buffer, RC_MSG_SIZE_V1_20,
669 dib0700_rc_urb_completion, d);
670
671 ret = usb_submit_urb(purb, GFP_ATOMIC);
672 if (ret != 0) {
673 err("rc submit urb failed\n");
674 return -1;
675 }
676
482 return 0; 677 return 0;
483} 678}
484 679
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index 44972d01bbd0..34eab05afc6c 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -472,20 +472,25 @@ static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
472 472
473/* Number of keypresses to ignore before start repeating */ 473/* Number of keypresses to ignore before start repeating */
474#define RC_REPEAT_DELAY 6 474#define RC_REPEAT_DELAY 6
475#define RC_REPEAT_DELAY_V1_20 10
476 475
477 476static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
478
479/* Used by firmware versions < 1.20 (deprecated) */
480static int dib0700_rc_query_legacy(struct dvb_usb_device *d, u32 *event,
481 int *state)
482{ 477{
483 u8 key[4]; 478 u8 key[4];
484 int i; 479 int i;
485 struct dvb_usb_rc_key *keymap = d->props.rc_key_map; 480 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
486 struct dib0700_state *st = d->priv; 481 struct dib0700_state *st = d->priv;
482
487 *event = 0; 483 *event = 0;
488 *state = REMOTE_NO_KEY_PRESSED; 484 *state = REMOTE_NO_KEY_PRESSED;
485
486 if (st->fw_version >= 0x10200) {
487 /* For 1.20 firmware , We need to keep the RC polling
488 callback so we can reuse the input device setup in
489 dvb-usb-remote.c. However, the actual work is being done
490 in the bulk URB completion handler. */
491 return 0;
492 }
493
489 i=dib0700_ctrl_rd(d,rc_request,2,key,4); 494 i=dib0700_ctrl_rd(d,rc_request,2,key,4);
490 if (i<=0) { 495 if (i<=0) {
491 err("RC Query Failed"); 496 err("RC Query Failed");
@@ -557,149 +562,6 @@ static int dib0700_rc_query_legacy(struct dvb_usb_device *d, u32 *event,
557 return 0; 562 return 0;
558} 563}
559 564
560/* This is the structure of the RC response packet starting in firmware 1.20 */
561struct dib0700_rc_response {
562 u8 report_id;
563 u8 data_state;
564 u16 system;
565 u8 data;
566 u8 not_data;
567};
568
569/* This supports the new IR response format for firmware v1.20 */
570static int dib0700_rc_query_v1_20(struct dvb_usb_device *d, u32 *event,
571 int *state)
572{
573 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
574 struct dib0700_state *st = d->priv;
575 struct dib0700_rc_response poll_reply;
576 u8 buf[6];
577 int i;
578 int status;
579 int actlen;
580 int found = 0;
581
582 /* Set initial results in case we exit the function early */
583 *event = 0;
584 *state = REMOTE_NO_KEY_PRESSED;
585
586 /* Firmware v1.20 provides RC data via bulk endpoint 1 */
587 status = usb_bulk_msg(d->udev, usb_rcvbulkpipe(d->udev, 1), buf,
588 sizeof(buf), &actlen, 50);
589 if (status < 0) {
590 /* No data available (meaning no key press) */
591 return 0;
592 }
593
594
595 switch (dvb_usb_dib0700_ir_proto) {
596 case 0:
597 poll_reply.report_id = 0;
598 poll_reply.data_state = 1;
599 poll_reply.system = buf[2];
600 poll_reply.data = buf[4];
601 poll_reply.not_data = buf[5];
602
603 /* NEC protocol sends repeat code as 0 0 0 FF */
604 if ((poll_reply.system == 0x00) && (poll_reply.data == 0x00)
605 && (poll_reply.not_data == 0xff)) {
606 poll_reply.data_state = 2;
607 break;
608 }
609 break;
610 default:
611 if (actlen != sizeof(buf)) {
612 /* We didn't get back the 6 byte message we expected */
613 err("Unexpected RC response size [%d]", actlen);
614 return -1;
615 }
616
617 poll_reply.report_id = buf[0];
618 poll_reply.data_state = buf[1];
619 poll_reply.system = (buf[2] << 8) | buf[3];
620 poll_reply.data = buf[4];
621 poll_reply.not_data = buf[5];
622
623 break;
624 }
625
626 if ((poll_reply.data + poll_reply.not_data) != 0xff) {
627 /* Key failed integrity check */
628 err("key failed integrity check: %04x %02x %02x",
629 poll_reply.system,
630 poll_reply.data, poll_reply.not_data);
631 return -1;
632 }
633
634
635 /* Find the key in the map */
636 for (i = 0; i < d->props.rc_key_map_size; i++) {
637 if (rc5_custom(&keymap[i]) == (poll_reply.system & 0xff) &&
638 rc5_data(&keymap[i]) == poll_reply.data) {
639 *event = keymap[i].event;
640 found = 1;
641 break;
642 }
643 }
644
645 if (found == 0) {
646 err("Unknown remote controller key: %04x %02x %02x",
647 poll_reply.system,
648 poll_reply.data, poll_reply.not_data);
649 d->last_event = 0;
650 return 0;
651 }
652
653 if (poll_reply.data_state == 1) {
654 /* New key hit */
655 st->rc_counter = 0;
656 *event = keymap[i].event;
657 *state = REMOTE_KEY_PRESSED;
658 d->last_event = keymap[i].event;
659 } else if (poll_reply.data_state == 2) {
660 /* Key repeated */
661 st->rc_counter++;
662
663 /* prevents unwanted double hits */
664 if (st->rc_counter > RC_REPEAT_DELAY_V1_20) {
665 *event = d->last_event;
666 *state = REMOTE_KEY_PRESSED;
667 st->rc_counter = RC_REPEAT_DELAY_V1_20;
668 }
669 } else {
670 err("Unknown data state [%d]", poll_reply.data_state);
671 }
672
673 return 0;
674}
675
676static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
677{
678 struct dib0700_state *st = d->priv;
679
680 /* Because some people may have improperly named firmware files,
681 let's figure out whether to use the new firmware call or the legacy
682 call based on the firmware version embedded in the file */
683 if (st->rc_func_version == 0) {
684 u32 hwver, romver, ramver, fwtype;
685 int ret = dib0700_get_version(d, &hwver, &romver, &ramver,
686 &fwtype);
687 if (ret < 0) {
688 err("Could not determine version info");
689 return -1;
690 }
691 if (ramver < 0x10200)
692 st->rc_func_version = 1;
693 else
694 st->rc_func_version = 2;
695 }
696
697 if (st->rc_func_version == 2)
698 return dib0700_rc_query_v1_20(d, event, state);
699 else
700 return dib0700_rc_query_legacy(d, event, state);
701}
702
703static struct dvb_usb_rc_key dib0700_rc_keys[] = { 565static struct dvb_usb_rc_key dib0700_rc_keys[] = {
704 /* Key codes for the tiny Pinnacle remote*/ 566 /* Key codes for the tiny Pinnacle remote*/
705 { 0x0700, KEY_MUTE }, 567 { 0x0700, KEY_MUTE },
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index bc3581d58ced..ae8b57acfe05 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -64,6 +64,8 @@
64#define USB_VID_HUMAX_COEX 0x10b9 64#define USB_VID_HUMAX_COEX 0x10b9
65#define USB_VID_774 0x7a69 65#define USB_VID_774 0x7a69
66#define USB_VID_EVOLUTEPC 0x1e59 66#define USB_VID_EVOLUTEPC 0x1e59
67#define USB_VID_AZUREWAVE 0x13d3
68#define USB_VID_TECHNISAT 0x14f7
67 69
68/* Product IDs */ 70/* Product IDs */
69#define USB_PID_ADSTECH_USB2_COLD 0xa333 71#define USB_PID_ADSTECH_USB2_COLD 0xa333
@@ -138,6 +140,7 @@
138#define USB_PID_TWINHAN_VP7021_COLD 0x3207 140#define USB_PID_TWINHAN_VP7021_COLD 0x3207
139#define USB_PID_TWINHAN_VP7021_WARM 0x3208 141#define USB_PID_TWINHAN_VP7021_WARM 0x3208
140#define USB_PID_TINYTWIN 0x3226 142#define USB_PID_TINYTWIN 0x3226
143#define USB_PID_TINYTWIN_2 0xe402
141#define USB_PID_DNTV_TINYUSB2_COLD 0x3223 144#define USB_PID_DNTV_TINYUSB2_COLD 0x3223
142#define USB_PID_DNTV_TINYUSB2_WARM 0x3224 145#define USB_PID_DNTV_TINYUSB2_WARM 0x3224
143#define USB_PID_ULTIMA_TVBOX_COLD 0x8105 146#define USB_PID_ULTIMA_TVBOX_COLD 0x8105
@@ -209,6 +212,7 @@
209#define USB_PID_PINNACLE_PCTV71E 0x022b 212#define USB_PID_PINNACLE_PCTV71E 0x022b
210#define USB_PID_PINNACLE_PCTV72E 0x0236 213#define USB_PID_PINNACLE_PCTV72E 0x0236
211#define USB_PID_PINNACLE_PCTV73E 0x0237 214#define USB_PID_PINNACLE_PCTV73E 0x0237
215#define USB_PID_PINNACLE_PCTV310E 0x3211
212#define USB_PID_PINNACLE_PCTV801E 0x023a 216#define USB_PID_PINNACLE_PCTV801E 0x023a
213#define USB_PID_PINNACLE_PCTV801E_SE 0x023b 217#define USB_PID_PINNACLE_PCTV801E_SE 0x023b
214#define USB_PID_PINNACLE_PCTV73A 0x0243 218#define USB_PID_PINNACLE_PCTV73A 0x0243
@@ -248,6 +252,7 @@
248#define USB_PID_DIGIVOX_MINI_SL_WARM 0xe361 252#define USB_PID_DIGIVOX_MINI_SL_WARM 0xe361
249#define USB_PID_GRANDTEC_DVBT_USB2_COLD 0x0bc6 253#define USB_PID_GRANDTEC_DVBT_USB2_COLD 0x0bc6
250#define USB_PID_GRANDTEC_DVBT_USB2_WARM 0x0bc7 254#define USB_PID_GRANDTEC_DVBT_USB2_WARM 0x0bc7
255#define USB_PID_WINFAST_DTV2000DS 0x6a04
251#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025 256#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025
252#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026 257#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026
253#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00 258#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00
@@ -290,5 +295,7 @@
290#define USB_PID_FRIIO_WHITE 0x0001 295#define USB_PID_FRIIO_WHITE 0x0001
291#define USB_PID_TVWAY_PLUS 0x0002 296#define USB_PID_TVWAY_PLUS 0x0002
292#define USB_PID_SVEON_STV20 0xe39d 297#define USB_PID_SVEON_STV20 0xe39d
293 298#define USB_PID_AZUREWAVE_AZ6027 0x3275
299#define USB_PID_TERRATEC_DVBS2CI 0x3275
300#define USB_PID_TECHNISAT_USB2_HDCI 0x0002
294#endif 301#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index e331db8c77b2..5d91f70d2d2d 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -243,7 +243,7 @@ int dvb_usb_device_init(struct usb_interface *intf,
243 d = kzalloc(sizeof(struct dvb_usb_device),GFP_KERNEL); 243 d = kzalloc(sizeof(struct dvb_usb_device),GFP_KERNEL);
244 if (d == NULL) { 244 if (d == NULL) {
245 err("no memory for 'struct dvb_usb_device'"); 245 err("no memory for 'struct dvb_usb_device'");
246 return ret; 246 return -ENOMEM;
247 } 247 }
248 248
249 d->udev = udev; 249 d->udev = udev;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index 6b5ded9e7d5d..a03ef7efec9a 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -107,6 +107,7 @@ static void dvb_usb_read_remote_control(struct work_struct *work)
107 case REMOTE_KEY_REPEAT: 107 case REMOTE_KEY_REPEAT:
108 deb_rc("key repeated\n"); 108 deb_rc("key repeated\n");
109 input_event(d->rc_input_dev, EV_KEY, event, 1); 109 input_event(d->rc_input_dev, EV_KEY, event, 1);
110 input_sync(d->rc_input_dev);
110 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0); 111 input_event(d->rc_input_dev, EV_KEY, d->last_event, 0);
111 input_sync(d->rc_input_dev); 112 input_sync(d->rc_input_dev);
112 break; 113 break;
diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
index 64132c0cf80d..accc65509b07 100644
--- a/drivers/media/dvb/dvb-usb/dw2102.c
+++ b/drivers/media/dvb/dvb-usb/dw2102.c
@@ -1,6 +1,7 @@
1/* DVB USB framework compliant Linux driver for the 1/* DVB USB framework compliant Linux driver for the
2* DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101, 2* DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
3* TeVii S600, S630, S650 Cards 3* TeVii S600, S630, S650,
4* Prof 1100, 7500 Cards
4* Copyright (C) 2008,2009 Igor M. Liplianin (liplianin@me.by) 5* Copyright (C) 2008,2009 Igor M. Liplianin (liplianin@me.by)
5* 6*
6* This program is free software; you can redistribute it and/or modify it 7* This program is free software; you can redistribute it and/or modify it
@@ -469,11 +470,13 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
469 int num) 470 int num)
470{ 471{
471 struct dvb_usb_device *d = i2c_get_adapdata(adap); 472 struct dvb_usb_device *d = i2c_get_adapdata(adap);
473 struct usb_device *udev;
472 int ret = 0; 474 int ret = 0;
473 int len, i, j; 475 int len, i, j;
474 476
475 if (!d) 477 if (!d)
476 return -ENODEV; 478 return -ENODEV;
479 udev = d->udev;
477 if (mutex_lock_interruptible(&d->i2c_mutex) < 0) 480 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
478 return -EAGAIN; 481 return -EAGAIN;
479 482
@@ -488,8 +491,13 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
488 } 491 }
489 case (DW2102_VOLTAGE_CTRL): { 492 case (DW2102_VOLTAGE_CTRL): {
490 u8 obuf[2]; 493 u8 obuf[2];
494
495 obuf[0] = 1;
496 obuf[1] = msg[j].buf[1];/* off-on */
497 ret = dw210x_op_rw(d->udev, 0x8a, 0, 0,
498 obuf, 2, DW210X_WRITE_MSG);
491 obuf[0] = 3; 499 obuf[0] = 3;
492 obuf[1] = msg[j].buf[0]; 500 obuf[1] = msg[j].buf[0];/* 13v-18v */
493 ret = dw210x_op_rw(d->udev, 0x8a, 0, 0, 501 ret = dw210x_op_rw(d->udev, 0x8a, 0, 0,
494 obuf, 2, DW210X_WRITE_MSG); 502 obuf, 2, DW210X_WRITE_MSG);
495 break; 503 break;
@@ -527,6 +535,17 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
527 i += 16; 535 i += 16;
528 len -= 16; 536 len -= 16;
529 } while (len > 0); 537 } while (len > 0);
538 } else if ((udev->descriptor.idProduct == 0x7500)
539 && (j < (num - 1))) {
540 /* write register addr before read */
541 u8 obuf[msg[j].len + 2];
542 obuf[0] = msg[j + 1].len;
543 obuf[1] = (msg[j].addr << 1);
544 memcpy(obuf + 2, msg[j].buf, msg[j].len);
545 ret = dw210x_op_rw(d->udev, 0x92, 0, 0,
546 obuf, msg[j].len + 2,
547 DW210X_WRITE_MSG);
548 break;
530 } else { 549 } else {
531 /* write registers */ 550 /* write registers */
532 u8 obuf[msg[j].len + 2]; 551 u8 obuf[msg[j].len + 2];
@@ -651,18 +670,25 @@ static int s6x0_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
651 670
652static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 671static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
653{ 672{
654 static u8 command_13v[1] = {0x00}; 673 static u8 command_13v[] = {0x00, 0x01};
655 static u8 command_18v[1] = {0x01}; 674 static u8 command_18v[] = {0x01, 0x01};
656 struct i2c_msg msg[] = { 675 static u8 command_off[] = {0x00, 0x00};
657 {.addr = DW2102_VOLTAGE_CTRL, .flags = 0, 676 struct i2c_msg msg = {
658 .buf = command_13v, .len = 1}, 677 .addr = DW2102_VOLTAGE_CTRL,
678 .flags = 0,
679 .buf = command_off,
680 .len = 2,
659 }; 681 };
660 682
661 struct dvb_usb_adapter *udev_adap = 683 struct dvb_usb_adapter *udev_adap =
662 (struct dvb_usb_adapter *)(fe->dvb->priv); 684 (struct dvb_usb_adapter *)(fe->dvb->priv);
663 if (voltage == SEC_VOLTAGE_18) 685 if (voltage == SEC_VOLTAGE_18)
664 msg[0].buf = command_18v; 686 msg.buf = command_18v;
665 i2c_transfer(&udev_adap->dev->i2c_adap, msg, 1); 687 else if (voltage == SEC_VOLTAGE_13)
688 msg.buf = command_13v;
689
690 i2c_transfer(&udev_adap->dev->i2c_adap, &msg, 1);
691
666 return 0; 692 return 0;
667} 693}
668 694
@@ -735,6 +761,18 @@ static struct stv6110_config dw2104_stv6110_config = {
735 .clk_div = 1, 761 .clk_div = 1,
736}; 762};
737 763
764static struct stv0900_config prof_7500_stv0900_config = {
765 .demod_address = 0x6a,
766 .demod_mode = 0,
767 .xtal = 27000000,
768 .clkmode = 3,/* 0-CLKI, 2-XTALI, else AUTO */
769 .diseqc_mode = 2,/* 2/3 PWM */
770 .tun1_maddress = 0,/* 0x60 */
771 .tun1_adc = 0,/* 2 Vpp */
772 .path1_mode = 3,
773 .tun1_type = 3,
774};
775
738static int dw2104_frontend_attach(struct dvb_usb_adapter *d) 776static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
739{ 777{
740 struct dvb_tuner_ops *tuner_ops = NULL; 778 struct dvb_tuner_ops *tuner_ops = NULL;
@@ -882,6 +920,19 @@ static int s6x0_frontend_attach(struct dvb_usb_adapter *d)
882 return -EIO; 920 return -EIO;
883} 921}
884 922
923static int prof_7500_frontend_attach(struct dvb_usb_adapter *d)
924{
925 d->fe = dvb_attach(stv0900_attach, &prof_7500_stv0900_config,
926 &d->dev->i2c_adap, 0);
927 if (d->fe == NULL)
928 return -EIO;
929 d->fe->ops.set_voltage = dw210x_set_voltage;
930
931 info("Attached STV0900+STB6100A!\n");
932
933 return 0;
934}
935
885static int dw2102_tuner_attach(struct dvb_usb_adapter *adap) 936static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
886{ 937{
887 dvb_attach(dvb_pll_attach, adap->fe, 0x60, 938 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
@@ -1073,6 +1124,7 @@ static struct usb_device_id dw2102_table[] = {
1073 {USB_DEVICE(0x9022, USB_PID_TEVII_S630)}, 1124 {USB_DEVICE(0x9022, USB_PID_TEVII_S630)},
1074 {USB_DEVICE(0x3011, USB_PID_PROF_1100)}, 1125 {USB_DEVICE(0x3011, USB_PID_PROF_1100)},
1075 {USB_DEVICE(0x9022, USB_PID_TEVII_S660)}, 1126 {USB_DEVICE(0x9022, USB_PID_TEVII_S660)},
1127 {USB_DEVICE(0x3034, 0x7500)},
1076 { } 1128 { }
1077}; 1129};
1078 1130
@@ -1387,9 +1439,30 @@ static struct dvb_usb_device_properties s6x0_properties = {
1387 } 1439 }
1388}; 1440};
1389 1441
1442struct dvb_usb_device_properties *p7500;
1443static struct dvb_usb_device_description d7500 = {
1444 "Prof 7500 USB DVB-S2",
1445 {&dw2102_table[9], NULL},
1446 {NULL},
1447};
1448
1390static int dw2102_probe(struct usb_interface *intf, 1449static int dw2102_probe(struct usb_interface *intf,
1391 const struct usb_device_id *id) 1450 const struct usb_device_id *id)
1392{ 1451{
1452
1453 p7500 = kzalloc(sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
1454 if (!p7500)
1455 return -ENOMEM;
1456 /* copy default structure */
1457 memcpy(p7500, &s6x0_properties,
1458 sizeof(struct dvb_usb_device_properties));
1459 /* fill only different fields */
1460 p7500->firmware = "dvb-usb-p7500.fw";
1461 p7500->devices[0] = d7500;
1462 p7500->rc_key_map = tbs_rc_keys;
1463 p7500->rc_key_map_size = ARRAY_SIZE(tbs_rc_keys);
1464 p7500->adapter->frontend_attach = prof_7500_frontend_attach;
1465
1393 if (0 == dvb_usb_device_init(intf, &dw2102_properties, 1466 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
1394 THIS_MODULE, NULL, adapter_nr) || 1467 THIS_MODULE, NULL, adapter_nr) ||
1395 0 == dvb_usb_device_init(intf, &dw2104_properties, 1468 0 == dvb_usb_device_init(intf, &dw2104_properties,
@@ -1397,6 +1470,8 @@ static int dw2102_probe(struct usb_interface *intf,
1397 0 == dvb_usb_device_init(intf, &dw3101_properties, 1470 0 == dvb_usb_device_init(intf, &dw3101_properties,
1398 THIS_MODULE, NULL, adapter_nr) || 1471 THIS_MODULE, NULL, adapter_nr) ||
1399 0 == dvb_usb_device_init(intf, &s6x0_properties, 1472 0 == dvb_usb_device_init(intf, &s6x0_properties,
1473 THIS_MODULE, NULL, adapter_nr) ||
1474 0 == dvb_usb_device_init(intf, p7500,
1400 THIS_MODULE, NULL, adapter_nr)) 1475 THIS_MODULE, NULL, adapter_nr))
1401 return 0; 1476 return 0;
1402 1477
@@ -1431,6 +1506,6 @@ MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
1431MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104," 1506MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
1432 " DVB-C 3101 USB2.0," 1507 " DVB-C 3101 USB2.0,"
1433 " TeVii S600, S630, S650, S660 USB2.0," 1508 " TeVii S600, S630, S650, S660 USB2.0,"
1434 " Prof 1100 USB2.0 devices"); 1509 " Prof 1100, 7500 USB2.0 devices");
1435MODULE_VERSION("0.1"); 1510MODULE_VERSION("0.1");
1436MODULE_LICENSE("GPL"); 1511MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/friio-fe.c b/drivers/media/dvb/dvb-usb/friio-fe.c
index ebb7b9fd115b..d14bd227b502 100644
--- a/drivers/media/dvb/dvb-usb/friio-fe.c
+++ b/drivers/media/dvb/dvb-usb/friio-fe.c
@@ -366,7 +366,7 @@ static u8 init_code[][2] = {
366 {0x76, 0x0C}, 366 {0x76, 0x0C},
367}; 367};
368 368
369const static int init_code_len = sizeof(init_code) / sizeof(u8[2]); 369static const int init_code_len = sizeof(init_code) / sizeof(u8[2]);
370 370
371static int jdvbt90502_init(struct dvb_frontend *fe) 371static int jdvbt90502_init(struct dvb_frontend *fe)
372{ 372{
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c
index ef9b7bed13ff..737ffa36ac9c 100644
--- a/drivers/media/dvb/dvb-usb/m920x.c
+++ b/drivers/media/dvb/dvb-usb/m920x.c
@@ -16,6 +16,9 @@
16#include "qt1010.h" 16#include "qt1010.h"
17#include "tda1004x.h" 17#include "tda1004x.h"
18#include "tda827x.h" 18#include "tda827x.h"
19
20#include <media/tuner.h>
21#include "tuner-simple.h"
19#include <asm/unaligned.h> 22#include <asm/unaligned.h>
20 23
21/* debug */ 24/* debug */
@@ -158,11 +161,14 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
158 161
159 case 0x93: 162 case 0x93:
160 case 0x92: 163 case 0x92:
164 case 0x83: /* pinnacle PCTV310e */
165 case 0x82:
161 m->rep_count = 0; 166 m->rep_count = 0;
162 *state = REMOTE_KEY_PRESSED; 167 *state = REMOTE_KEY_PRESSED;
163 goto unlock; 168 goto unlock;
164 169
165 case 0x91: 170 case 0x91:
171 case 0x81: /* pinnacle PCTV310e */
166 /* prevent immediate auto-repeat */ 172 /* prevent immediate auto-repeat */
167 if (++m->rep_count > 2) 173 if (++m->rep_count > 2)
168 *state = REMOTE_KEY_REPEAT; 174 *state = REMOTE_KEY_REPEAT;
@@ -546,6 +552,14 @@ static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
546 return 0; 552 return 0;
547} 553}
548 554
555static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
556{
557 dvb_attach(simple_tuner_attach, adap->fe,
558 &adap->dev->i2c_adap, 0x61,
559 TUNER_PHILIPS_FMD1216ME_MK3);
560 return 0;
561}
562
549/* device-specific initialization */ 563/* device-specific initialization */
550static struct m920x_inits megasky_rc_init [] = { 564static struct m920x_inits megasky_rc_init [] = {
551 { M9206_RC_INIT2, 0xa8 }, 565 { M9206_RC_INIT2, 0xa8 },
@@ -562,6 +576,18 @@ static struct m920x_inits tvwalkertwin_rc_init [] = {
562 { } /* terminating entry */ 576 { } /* terminating entry */
563}; 577};
564 578
579static struct m920x_inits pinnacle310e_init[] = {
580 /* without these the tuner don't work */
581 { 0xff20, 0x9b },
582 { 0xff22, 0x70 },
583
584 /* rc settings */
585 { 0xff50, 0x80 },
586 { M9206_RC_INIT1, 0x00 },
587 { M9206_RC_INIT2, 0xff },
588 { } /* terminating entry */
589};
590
565/* ir keymaps */ 591/* ir keymaps */
566static struct dvb_usb_rc_key megasky_rc_keys [] = { 592static struct dvb_usb_rc_key megasky_rc_keys [] = {
567 { 0x0012, KEY_POWER }, 593 { 0x0012, KEY_POWER },
@@ -602,11 +628,68 @@ static struct dvb_usb_rc_key tvwalkertwin_rc_keys [] = {
602 { 0x001e, KEY_VOLUMEUP }, 628 { 0x001e, KEY_VOLUMEUP },
603}; 629};
604 630
631static struct dvb_usb_rc_key pinnacle310e_rc_keys[] = {
632 { 0x16, KEY_POWER },
633 { 0x17, KEY_FAVORITES },
634 { 0x0f, KEY_TEXT },
635 { 0x48, KEY_MEDIA }, /* preview */
636 { 0x1c, KEY_EPG },
637 { 0x04, KEY_LIST }, /* record list */
638 { 0x03, KEY_1 },
639 { 0x01, KEY_2 },
640 { 0x06, KEY_3 },
641 { 0x09, KEY_4 },
642 { 0x1d, KEY_5 },
643 { 0x1f, KEY_6 },
644 { 0x0d, KEY_7 },
645 { 0x19, KEY_8 },
646 { 0x1b, KEY_9 },
647 { 0x15, KEY_0 },
648 { 0x0c, KEY_CANCEL },
649 { 0x4a, KEY_CLEAR },
650 { 0x13, KEY_BACK },
651 { 0x00, KEY_TAB },
652 { 0x4b, KEY_UP },
653 { 0x4e, KEY_LEFT },
654 { 0x52, KEY_RIGHT },
655 { 0x51, KEY_DOWN },
656 { 0x4f, KEY_ENTER }, /* could also be KEY_OK */
657 { 0x1e, KEY_VOLUMEUP },
658 { 0x0a, KEY_VOLUMEDOWN },
659 { 0x05, KEY_CHANNELUP },
660 { 0x02, KEY_CHANNELDOWN },
661 { 0x11, KEY_RECORD },
662 { 0x14, KEY_PLAY },
663 { 0x4c, KEY_PAUSE },
664 { 0x1a, KEY_STOP },
665 { 0x40, KEY_REWIND },
666 { 0x12, KEY_FASTFORWARD },
667 { 0x41, KEY_PREVIOUSSONG }, /* Replay */
668 { 0x42, KEY_NEXTSONG }, /* Skip */
669 { 0x54, KEY_CAMERA }, /* Capture */
670/* { 0x50, KEY_SAP }, */ /* Sap */
671 { 0x47, KEY_CYCLEWINDOWS }, /* Pip */
672 { 0x4d, KEY_SCREEN }, /* FullScreen */
673 { 0x08, KEY_SUBTITLE },
674 { 0x0e, KEY_MUTE },
675/* { 0x49, KEY_LR }, */ /* L/R */
676 { 0x07, KEY_SLEEP }, /* Hibernate */
677 { 0x08, KEY_MEDIA }, /* A/V */
678 { 0x0e, KEY_MENU }, /* Recall */
679 { 0x45, KEY_ZOOMIN },
680 { 0x46, KEY_ZOOMOUT },
681 { 0x18, KEY_TV }, /* Red */
682 { 0x53, KEY_VCR }, /* Green */
683 { 0x5e, KEY_SAT }, /* Yellow */
684 { 0x5f, KEY_PLAYER }, /* Blue */
685};
686
605/* DVB USB Driver stuff */ 687/* DVB USB Driver stuff */
606static struct dvb_usb_device_properties megasky_properties; 688static struct dvb_usb_device_properties megasky_properties;
607static struct dvb_usb_device_properties digivox_mini_ii_properties; 689static struct dvb_usb_device_properties digivox_mini_ii_properties;
608static struct dvb_usb_device_properties tvwalkertwin_properties; 690static struct dvb_usb_device_properties tvwalkertwin_properties;
609static struct dvb_usb_device_properties dposh_properties; 691static struct dvb_usb_device_properties dposh_properties;
692static struct dvb_usb_device_properties pinnacle_pctv310e_properties;
610 693
611static int m920x_probe(struct usb_interface *intf, 694static int m920x_probe(struct usb_interface *intf,
612 const struct usb_device_id *id) 695 const struct usb_device_id *id)
@@ -652,6 +735,13 @@ static int m920x_probe(struct usb_interface *intf,
652 goto found; 735 goto found;
653 } 736 }
654 737
738 ret = dvb_usb_device_init(intf, &pinnacle_pctv310e_properties,
739 THIS_MODULE, &d, adapter_nr);
740 if (ret == 0) {
741 rc_init_seq = pinnacle310e_init;
742 goto found;
743 }
744
655 return ret; 745 return ret;
656 } else { 746 } else {
657 /* Another interface on a multi-tuner device */ 747 /* Another interface on a multi-tuner device */
@@ -682,6 +772,7 @@ static struct usb_device_id m920x_table [] = {
682 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) }, 772 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
683 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) }, 773 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
684 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) }, 774 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
775 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_PINNACLE_PCTV310E) },
685 { } /* Terminating entry */ 776 { } /* Terminating entry */
686}; 777};
687MODULE_DEVICE_TABLE (usb, m920x_table); 778MODULE_DEVICE_TABLE (usb, m920x_table);
@@ -895,6 +986,56 @@ static struct dvb_usb_device_properties dposh_properties = {
895 } 986 }
896}; 987};
897 988
989static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
990 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
991
992 .usb_ctrl = DEVICE_SPECIFIC,
993 .download_firmware = NULL,
994
995 .rc_interval = 100,
996 .rc_key_map = pinnacle310e_rc_keys,
997 .rc_key_map_size = ARRAY_SIZE(pinnacle310e_rc_keys),
998 .rc_query = m920x_rc_query,
999
1000 .size_of_priv = sizeof(struct m920x_state),
1001
1002 .identify_state = m920x_identify_state,
1003 .num_adapters = 1,
1004 .adapter = {{
1005 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1006 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1007
1008 .pid_filter_count = 8,
1009 .pid_filter = m920x_pid_filter,
1010 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1011
1012 .frontend_attach = m920x_mt352_frontend_attach,
1013 .tuner_attach = m920x_fmd1216me_tuner_attach,
1014
1015 .stream = {
1016 .type = USB_ISOC,
1017 .count = 5,
1018 .endpoint = 0x84,
1019 .u = {
1020 .isoc = {
1021 .framesperurb = 128,
1022 .framesize = 564,
1023 .interval = 1,
1024 }
1025 }
1026 },
1027 } },
1028 .i2c_algo = &m920x_i2c_algo,
1029
1030 .num_device_descs = 1,
1031 .devices = {
1032 { "Pinnacle PCTV 310e",
1033 { &m920x_table[6], NULL },
1034 { NULL },
1035 }
1036 }
1037};
1038
898static struct usb_driver m920x_driver = { 1039static struct usb_driver m920x_driver = {
899 .name = "dvb_usb_m920x", 1040 .name = "dvb_usb_m920x",
900 .probe = m920x_probe, 1041 .probe = m920x_probe,
diff --git a/drivers/media/dvb/dvb-usb/m920x.h b/drivers/media/dvb/dvb-usb/m920x.h
index 37532890accd..3c061518ffc1 100644
--- a/drivers/media/dvb/dvb-usb/m920x.h
+++ b/drivers/media/dvb/dvb-usb/m920x.h
@@ -18,7 +18,7 @@
18#define M9206_FW 0x30 18#define M9206_FW 0x30
19 19
20#define M9206_MAX_FILTERS 8 20#define M9206_MAX_FILTERS 8
21#define M9206_MAX_ADAPTERS 2 21#define M9206_MAX_ADAPTERS 4
22 22
23/* 23/*
24sequences found in logs: 24sequences found in logs:
diff --git a/drivers/media/dvb/dvb-usb/opera1.c b/drivers/media/dvb/dvb-usb/opera1.c
index d4e230941679..830557696ae6 100644
--- a/drivers/media/dvb/dvb-usb/opera1.c
+++ b/drivers/media/dvb/dvb-usb/opera1.c
@@ -138,7 +138,7 @@ static int opera1_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
138 (msg[i].addr<<1)|(msg[i].flags&I2C_M_RD?0x01:0), 138 (msg[i].addr<<1)|(msg[i].flags&I2C_M_RD?0x01:0),
139 msg[i].buf, 139 msg[i].buf,
140 msg[i].len 140 msg[i].len
141 )!= msg[i].len)) { 141 )) != msg[i].len) {
142 break; 142 break;
143 } 143 }
144 if (dvb_usb_opera1_debug & 0x10) 144 if (dvb_usb_opera1_debug & 0x10)
diff --git a/drivers/media/dvb/firewire/firedtv-1394.c b/drivers/media/dvb/firewire/firedtv-1394.c
index 7c5459c27b75..c3e0ec2dcfca 100644
--- a/drivers/media/dvb/firewire/firedtv-1394.c
+++ b/drivers/media/dvb/firewire/firedtv-1394.c
@@ -90,13 +90,14 @@ static inline struct node_entry *node_of(struct firedtv *fdtv)
90 return container_of(fdtv->device, struct unit_directory, device)->ne; 90 return container_of(fdtv->device, struct unit_directory, device)->ne;
91} 91}
92 92
93static int node_lock(struct firedtv *fdtv, u64 addr, __be32 data[]) 93static int node_lock(struct firedtv *fdtv, u64 addr, void *data)
94{ 94{
95 quadlet_t *d = data;
95 int ret; 96 int ret;
96 97
97 ret = hpsb_node_lock(node_of(fdtv), addr, EXTCODE_COMPARE_SWAP, 98 ret = hpsb_node_lock(node_of(fdtv), addr,
98 (__force quadlet_t *)&data[1], (__force quadlet_t)data[0]); 99 EXTCODE_COMPARE_SWAP, &d[1], d[0]);
99 data[0] = data[1]; 100 d[0] = d[1];
100 101
101 return ret; 102 return ret;
102} 103}
@@ -192,9 +193,13 @@ static int node_probe(struct device *dev)
192 int kv_len, err; 193 int kv_len, err;
193 void *kv_str; 194 void *kv_str;
194 195
195 kv_len = (ud->model_name_kv->value.leaf.len - 2) * sizeof(quadlet_t); 196 if (ud->model_name_kv) {
196 kv_str = CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(ud->model_name_kv); 197 kv_len = (ud->model_name_kv->value.leaf.len - 2) * 4;
197 198 kv_str = CSR1212_TEXTUAL_DESCRIPTOR_LEAF_DATA(ud->model_name_kv);
199 } else {
200 kv_len = 0;
201 kv_str = NULL;
202 }
198 fdtv = fdtv_alloc(dev, &fdtv_1394_backend, kv_str, kv_len); 203 fdtv = fdtv_alloc(dev, &fdtv_1394_backend, kv_str, kv_len);
199 if (!fdtv) 204 if (!fdtv)
200 return -ENOMEM; 205 return -ENOMEM;
diff --git a/drivers/media/dvb/firewire/firedtv-avc.c b/drivers/media/dvb/firewire/firedtv-avc.c
index 50c42a4b972b..1b31bebc27d6 100644
--- a/drivers/media/dvb/firewire/firedtv-avc.c
+++ b/drivers/media/dvb/firewire/firedtv-avc.c
@@ -74,7 +74,6 @@
74#define EN50221_TAG_CA_INFO 0x9f8031 74#define EN50221_TAG_CA_INFO 0x9f8031
75 75
76struct avc_command_frame { 76struct avc_command_frame {
77 int length;
78 u8 ctype; 77 u8 ctype;
79 u8 subunit; 78 u8 subunit;
80 u8 opcode; 79 u8 opcode;
@@ -82,13 +81,27 @@ struct avc_command_frame {
82}; 81};
83 82
84struct avc_response_frame { 83struct avc_response_frame {
85 int length;
86 u8 response; 84 u8 response;
87 u8 subunit; 85 u8 subunit;
88 u8 opcode; 86 u8 opcode;
89 u8 operand[509]; 87 u8 operand[509];
90}; 88};
91 89
90#define LAST_OPERAND (509 - 1)
91
92static inline void clear_operands(struct avc_command_frame *c, int from, int to)
93{
94 memset(&c->operand[from], 0, to - from + 1);
95}
96
97static void pad_operands(struct avc_command_frame *c, int from)
98{
99 int to = ALIGN(from, 4);
100
101 if (from <= to && to <= LAST_OPERAND)
102 clear_operands(c, from, to);
103}
104
92#define AVC_DEBUG_READ_DESCRIPTOR 0x0001 105#define AVC_DEBUG_READ_DESCRIPTOR 0x0001
93#define AVC_DEBUG_DSIT 0x0002 106#define AVC_DEBUG_DSIT 0x0002
94#define AVC_DEBUG_DSD 0x0004 107#define AVC_DEBUG_DSD 0x0004
@@ -202,78 +215,65 @@ static void debug_pmt(char *msg, int length)
202 16, 1, msg, length, false); 215 16, 1, msg, length, false);
203} 216}
204 217
205static int __avc_write(struct firedtv *fdtv, 218static int avc_write(struct firedtv *fdtv)
206 const struct avc_command_frame *c, struct avc_response_frame *r)
207{ 219{
208 int err, retry; 220 int err, retry;
209 221
210 if (r) 222 fdtv->avc_reply_received = false;
211 fdtv->avc_reply_received = false;
212 223
213 for (retry = 0; retry < 6; retry++) { 224 for (retry = 0; retry < 6; retry++) {
214 if (unlikely(avc_debug)) 225 if (unlikely(avc_debug))
215 debug_fcp(&c->ctype, c->length); 226 debug_fcp(fdtv->avc_data, fdtv->avc_data_length);
216 227
217 err = fdtv->backend->write(fdtv, FCP_COMMAND_REGISTER, 228 err = fdtv->backend->write(fdtv, FCP_COMMAND_REGISTER,
218 (void *)&c->ctype, c->length); 229 fdtv->avc_data, fdtv->avc_data_length);
219 if (err) { 230 if (err) {
220 fdtv->avc_reply_received = true;
221 dev_err(fdtv->device, "FCP command write failed\n"); 231 dev_err(fdtv->device, "FCP command write failed\n");
232
222 return err; 233 return err;
223 } 234 }
224 235
225 if (!r)
226 return 0;
227
228 /* 236 /*
229 * AV/C specs say that answers should be sent within 150 ms. 237 * AV/C specs say that answers should be sent within 150 ms.
230 * Time out after 200 ms. 238 * Time out after 200 ms.
231 */ 239 */
232 if (wait_event_timeout(fdtv->avc_wait, 240 if (wait_event_timeout(fdtv->avc_wait,
233 fdtv->avc_reply_received, 241 fdtv->avc_reply_received,
234 msecs_to_jiffies(200)) != 0) { 242 msecs_to_jiffies(200)) != 0)
235 r->length = fdtv->response_length;
236 memcpy(&r->response, fdtv->response, r->length);
237
238 return 0; 243 return 0;
239 }
240 } 244 }
241 dev_err(fdtv->device, "FCP response timed out\n"); 245 dev_err(fdtv->device, "FCP response timed out\n");
246
242 return -ETIMEDOUT; 247 return -ETIMEDOUT;
243} 248}
244 249
245static int avc_write(struct firedtv *fdtv, 250static bool is_register_rc(struct avc_response_frame *r)
246 const struct avc_command_frame *c, struct avc_response_frame *r)
247{ 251{
248 int ret; 252 return r->opcode == AVC_OPCODE_VENDOR &&
249 253 r->operand[0] == SFE_VENDOR_DE_COMPANYID_0 &&
250 if (mutex_lock_interruptible(&fdtv->avc_mutex)) 254 r->operand[1] == SFE_VENDOR_DE_COMPANYID_1 &&
251 return -EINTR; 255 r->operand[2] == SFE_VENDOR_DE_COMPANYID_2 &&
252 256 r->operand[3] == SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL;
253 ret = __avc_write(fdtv, c, r);
254
255 mutex_unlock(&fdtv->avc_mutex);
256 return ret;
257} 257}
258 258
259int avc_recv(struct firedtv *fdtv, void *data, size_t length) 259int avc_recv(struct firedtv *fdtv, void *data, size_t length)
260{ 260{
261 struct avc_response_frame *r = 261 struct avc_response_frame *r = data;
262 data - offsetof(struct avc_response_frame, response);
263 262
264 if (unlikely(avc_debug)) 263 if (unlikely(avc_debug))
265 debug_fcp(data, length); 264 debug_fcp(data, length);
266 265
267 if (length >= 8 && 266 if (length >= 8 && is_register_rc(r)) {
268 r->operand[0] == SFE_VENDOR_DE_COMPANYID_0 && 267 switch (r->response) {
269 r->operand[1] == SFE_VENDOR_DE_COMPANYID_1 && 268 case AVC_RESPONSE_CHANGED:
270 r->operand[2] == SFE_VENDOR_DE_COMPANYID_2 && 269 fdtv_handle_rc(fdtv, r->operand[4] << 8 | r->operand[5]);
271 r->operand[3] == SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL) {
272 if (r->response == AVC_RESPONSE_CHANGED) {
273 fdtv_handle_rc(fdtv,
274 r->operand[4] << 8 | r->operand[5]);
275 schedule_work(&fdtv->remote_ctrl_work); 270 schedule_work(&fdtv->remote_ctrl_work);
276 } else if (r->response != AVC_RESPONSE_INTERIM) { 271 break;
272 case AVC_RESPONSE_INTERIM:
273 if (is_register_rc((void *)fdtv->avc_data))
274 goto wake;
275 break;
276 default:
277 dev_info(fdtv->device, 277 dev_info(fdtv->device,
278 "remote control result = %d\n", r->response); 278 "remote control result = %d\n", r->response);
279 } 279 }
@@ -285,9 +285,9 @@ int avc_recv(struct firedtv *fdtv, void *data, size_t length)
285 return -EIO; 285 return -EIO;
286 } 286 }
287 287
288 memcpy(fdtv->response, data, length); 288 memcpy(fdtv->avc_data, data, length);
289 fdtv->response_length = length; 289 fdtv->avc_data_length = length;
290 290wake:
291 fdtv->avc_reply_received = true; 291 fdtv->avc_reply_received = true;
292 wake_up(&fdtv->avc_wait); 292 wake_up(&fdtv->avc_wait);
293 293
@@ -318,10 +318,11 @@ static int add_pid_filter(struct firedtv *fdtv, u8 *operand)
318 * tuning command for setting the relative LNB frequency 318 * tuning command for setting the relative LNB frequency
319 * (not supported by the AVC standard) 319 * (not supported by the AVC standard)
320 */ 320 */
321static void avc_tuner_tuneqpsk(struct firedtv *fdtv, 321static int avc_tuner_tuneqpsk(struct firedtv *fdtv,
322 struct dvb_frontend_parameters *params, 322 struct dvb_frontend_parameters *params)
323 struct avc_command_frame *c)
324{ 323{
324 struct avc_command_frame *c = (void *)fdtv->avc_data;
325
325 c->opcode = AVC_OPCODE_VENDOR; 326 c->opcode = AVC_OPCODE_VENDOR;
326 327
327 c->operand[0] = SFE_VENDOR_DE_COMPANYID_0; 328 c->operand[0] = SFE_VENDOR_DE_COMPANYID_0;
@@ -370,16 +371,18 @@ static void avc_tuner_tuneqpsk(struct firedtv *fdtv,
370 c->operand[13] = 0x1; 371 c->operand[13] = 0x1;
371 c->operand[14] = 0xff; 372 c->operand[14] = 0xff;
372 c->operand[15] = 0xff; 373 c->operand[15] = 0xff;
373 c->length = 20; 374
375 return 16;
374 } else { 376 } else {
375 c->length = 16; 377 return 13;
376 } 378 }
377} 379}
378 380
379static void avc_tuner_dsd_dvb_c(struct firedtv *fdtv, 381static int avc_tuner_dsd_dvb_c(struct firedtv *fdtv,
380 struct dvb_frontend_parameters *params, 382 struct dvb_frontend_parameters *params)
381 struct avc_command_frame *c)
382{ 383{
384 struct avc_command_frame *c = (void *)fdtv->avc_data;
385
383 c->opcode = AVC_OPCODE_DSD; 386 c->opcode = AVC_OPCODE_DSD;
384 387
385 c->operand[0] = 0; /* source plug */ 388 c->operand[0] = 0; /* source plug */
@@ -440,15 +443,14 @@ static void avc_tuner_dsd_dvb_c(struct firedtv *fdtv,
440 c->operand[20] = 0x00; 443 c->operand[20] = 0x00;
441 c->operand[21] = 0x00; 444 c->operand[21] = 0x00;
442 445
443 /* Add PIDs to filter */ 446 return 22 + add_pid_filter(fdtv, &c->operand[22]);
444 c->length = ALIGN(22 + add_pid_filter(fdtv, &c->operand[22]) + 3, 4);
445} 447}
446 448
447static void avc_tuner_dsd_dvb_t(struct firedtv *fdtv, 449static int avc_tuner_dsd_dvb_t(struct firedtv *fdtv,
448 struct dvb_frontend_parameters *params, 450 struct dvb_frontend_parameters *params)
449 struct avc_command_frame *c)
450{ 451{
451 struct dvb_ofdm_parameters *ofdm = &params->u.ofdm; 452 struct dvb_ofdm_parameters *ofdm = &params->u.ofdm;
453 struct avc_command_frame *c = (void *)fdtv->avc_data;
452 454
453 c->opcode = AVC_OPCODE_DSD; 455 c->opcode = AVC_OPCODE_DSD;
454 456
@@ -543,55 +545,58 @@ static void avc_tuner_dsd_dvb_t(struct firedtv *fdtv,
543 c->operand[15] = 0x00; /* network_ID[0] */ 545 c->operand[15] = 0x00; /* network_ID[0] */
544 c->operand[16] = 0x00; /* network_ID[1] */ 546 c->operand[16] = 0x00; /* network_ID[1] */
545 547
546 /* Add PIDs to filter */ 548 return 17 + add_pid_filter(fdtv, &c->operand[17]);
547 c->length = ALIGN(17 + add_pid_filter(fdtv, &c->operand[17]) + 3, 4);
548} 549}
549 550
550int avc_tuner_dsd(struct firedtv *fdtv, 551int avc_tuner_dsd(struct firedtv *fdtv,
551 struct dvb_frontend_parameters *params) 552 struct dvb_frontend_parameters *params)
552{ 553{
553 char buffer[sizeof(struct avc_command_frame)]; 554 struct avc_command_frame *c = (void *)fdtv->avc_data;
554 struct avc_command_frame *c = (void *)buffer; 555 int pos, ret;
555 struct avc_response_frame *r = (void *)buffer; /* FIXME: unused */
556 556
557 memset(c, 0, sizeof(*c)); 557 mutex_lock(&fdtv->avc_mutex);
558 558
559 c->ctype = AVC_CTYPE_CONTROL; 559 c->ctype = AVC_CTYPE_CONTROL;
560 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 560 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
561 561
562 switch (fdtv->type) { 562 switch (fdtv->type) {
563 case FIREDTV_DVB_S: 563 case FIREDTV_DVB_S:
564 case FIREDTV_DVB_S2: avc_tuner_tuneqpsk(fdtv, params, c); break; 564 case FIREDTV_DVB_S2: pos = avc_tuner_tuneqpsk(fdtv, params); break;
565 case FIREDTV_DVB_C: avc_tuner_dsd_dvb_c(fdtv, params, c); break; 565 case FIREDTV_DVB_C: pos = avc_tuner_dsd_dvb_c(fdtv, params); break;
566 case FIREDTV_DVB_T: avc_tuner_dsd_dvb_t(fdtv, params, c); break; 566 case FIREDTV_DVB_T: pos = avc_tuner_dsd_dvb_t(fdtv, params); break;
567 default: 567 default:
568 BUG(); 568 BUG();
569 } 569 }
570 pad_operands(c, pos);
570 571
571 if (avc_write(fdtv, c, r) < 0) 572 fdtv->avc_data_length = ALIGN(3 + pos, 4);
572 return -EIO; 573 ret = avc_write(fdtv);
573
574 msleep(500);
575#if 0 574#if 0
576 /* FIXME: */ 575 /*
577 /* u8 *status was an out-parameter of avc_tuner_dsd, unused by caller */ 576 * FIXME:
577 * u8 *status was an out-parameter of avc_tuner_dsd, unused by caller.
578 * Check for AVC_RESPONSE_ACCEPTED here instead?
579 */
578 if (status) 580 if (status)
579 *status = r->operand[2]; 581 *status = r->operand[2];
580#endif 582#endif
581 return 0; 583 mutex_unlock(&fdtv->avc_mutex);
584
585 if (ret == 0)
586 msleep(500);
587
588 return ret;
582} 589}
583 590
584int avc_tuner_set_pids(struct firedtv *fdtv, unsigned char pidc, u16 pid[]) 591int avc_tuner_set_pids(struct firedtv *fdtv, unsigned char pidc, u16 pid[])
585{ 592{
586 char buffer[sizeof(struct avc_command_frame)]; 593 struct avc_command_frame *c = (void *)fdtv->avc_data;
587 struct avc_command_frame *c = (void *)buffer; 594 int ret, pos, k;
588 struct avc_response_frame *r = (void *)buffer; /* FIXME: unused */
589 int pos, k;
590 595
591 if (pidc > 16 && pidc != 0xff) 596 if (pidc > 16 && pidc != 0xff)
592 return -EINVAL; 597 return -EINVAL;
593 598
594 memset(c, 0, sizeof(*c)); 599 mutex_lock(&fdtv->avc_mutex);
595 600
596 c->ctype = AVC_CTYPE_CONTROL; 601 c->ctype = AVC_CTYPE_CONTROL;
597 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 602 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -614,24 +619,27 @@ int avc_tuner_set_pids(struct firedtv *fdtv, unsigned char pidc, u16 pid[])
614 c->operand[pos++] = 0x00; /* tableID */ 619 c->operand[pos++] = 0x00; /* tableID */
615 c->operand[pos++] = 0x00; /* filter_length */ 620 c->operand[pos++] = 0x00; /* filter_length */
616 } 621 }
622 pad_operands(c, pos);
617 623
618 c->length = ALIGN(3 + pos, 4); 624 fdtv->avc_data_length = ALIGN(3 + pos, 4);
625 ret = avc_write(fdtv);
619 626
620 if (avc_write(fdtv, c, r) < 0) 627 /* FIXME: check response code? */
621 return -EIO;
622 628
623 msleep(50); 629 mutex_unlock(&fdtv->avc_mutex);
624 return 0; 630
631 if (ret == 0)
632 msleep(50);
633
634 return ret;
625} 635}
626 636
627int avc_tuner_get_ts(struct firedtv *fdtv) 637int avc_tuner_get_ts(struct firedtv *fdtv)
628{ 638{
629 char buffer[sizeof(struct avc_command_frame)]; 639 struct avc_command_frame *c = (void *)fdtv->avc_data;
630 struct avc_command_frame *c = (void *)buffer; 640 int ret, sl;
631 struct avc_response_frame *r = (void *)buffer; /* FIXME: unused */
632 int sl;
633 641
634 memset(c, 0, sizeof(*c)); 642 mutex_lock(&fdtv->avc_mutex);
635 643
636 c->ctype = AVC_CTYPE_CONTROL; 644 c->ctype = AVC_CTYPE_CONTROL;
637 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 645 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -646,26 +654,33 @@ int avc_tuner_get_ts(struct firedtv *fdtv)
646 c->operand[4] = 0x00; /* antenna number */ 654 c->operand[4] = 0x00; /* antenna number */
647 c->operand[5] = 0x0; /* system_specific_search_flags */ 655 c->operand[5] = 0x0; /* system_specific_search_flags */
648 c->operand[6] = sl; /* system_specific_multiplex selection_length */ 656 c->operand[6] = sl; /* system_specific_multiplex selection_length */
649 c->operand[7] = 0x00; /* valid_flags [0] */ 657 /*
650 c->operand[8] = 0x00; /* valid_flags [1] */ 658 * operand[7]: valid_flags[0]
651 c->operand[7 + sl] = 0x00; /* nr_of_dsit_sel_specs (always 0) */ 659 * operand[8]: valid_flags[1]
660 * operand[7 + sl]: nr_of_dsit_sel_specs (always 0)
661 */
662 clear_operands(c, 7, 24);
652 663
653 c->length = fdtv->type == FIREDTV_DVB_T ? 24 : 28; 664 fdtv->avc_data_length = fdtv->type == FIREDTV_DVB_T ? 24 : 28;
665 ret = avc_write(fdtv);
654 666
655 if (avc_write(fdtv, c, r) < 0) 667 /* FIXME: check response code? */
656 return -EIO;
657 668
658 msleep(250); 669 mutex_unlock(&fdtv->avc_mutex);
659 return 0; 670
671 if (ret == 0)
672 msleep(250);
673
674 return ret;
660} 675}
661 676
662int avc_identify_subunit(struct firedtv *fdtv) 677int avc_identify_subunit(struct firedtv *fdtv)
663{ 678{
664 char buffer[sizeof(struct avc_command_frame)]; 679 struct avc_command_frame *c = (void *)fdtv->avc_data;
665 struct avc_command_frame *c = (void *)buffer; 680 struct avc_response_frame *r = (void *)fdtv->avc_data;
666 struct avc_response_frame *r = (void *)buffer; 681 int ret;
667 682
668 memset(c, 0, sizeof(*c)); 683 mutex_lock(&fdtv->avc_mutex);
669 684
670 c->ctype = AVC_CTYPE_CONTROL; 685 c->ctype = AVC_CTYPE_CONTROL;
671 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 686 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -678,31 +693,34 @@ int avc_identify_subunit(struct firedtv *fdtv)
678 c->operand[4] = 0x08; /* length lowbyte */ 693 c->operand[4] = 0x08; /* length lowbyte */
679 c->operand[5] = 0x00; /* offset highbyte */ 694 c->operand[5] = 0x00; /* offset highbyte */
680 c->operand[6] = 0x0d; /* offset lowbyte */ 695 c->operand[6] = 0x0d; /* offset lowbyte */
696 clear_operands(c, 7, 8); /* padding */
681 697
682 c->length = 12; 698 fdtv->avc_data_length = 12;
683 699 ret = avc_write(fdtv);
684 if (avc_write(fdtv, c, r) < 0) 700 if (ret < 0)
685 return -EIO; 701 goto out;
686 702
687 if ((r->response != AVC_RESPONSE_STABLE && 703 if ((r->response != AVC_RESPONSE_STABLE &&
688 r->response != AVC_RESPONSE_ACCEPTED) || 704 r->response != AVC_RESPONSE_ACCEPTED) ||
689 (r->operand[3] << 8) + r->operand[4] != 8) { 705 (r->operand[3] << 8) + r->operand[4] != 8) {
690 dev_err(fdtv->device, "cannot read subunit identifier\n"); 706 dev_err(fdtv->device, "cannot read subunit identifier\n");
691 return -EINVAL; 707 ret = -EINVAL;
692 } 708 }
693 return 0; 709out:
710 mutex_unlock(&fdtv->avc_mutex);
711
712 return ret;
694} 713}
695 714
696#define SIZEOF_ANTENNA_INPUT_INFO 22 715#define SIZEOF_ANTENNA_INPUT_INFO 22
697 716
698int avc_tuner_status(struct firedtv *fdtv, struct firedtv_tuner_status *stat) 717int avc_tuner_status(struct firedtv *fdtv, struct firedtv_tuner_status *stat)
699{ 718{
700 char buffer[sizeof(struct avc_command_frame)]; 719 struct avc_command_frame *c = (void *)fdtv->avc_data;
701 struct avc_command_frame *c = (void *)buffer; 720 struct avc_response_frame *r = (void *)fdtv->avc_data;
702 struct avc_response_frame *r = (void *)buffer; 721 int length, ret;
703 int length;
704 722
705 memset(c, 0, sizeof(*c)); 723 mutex_lock(&fdtv->avc_mutex);
706 724
707 c->ctype = AVC_CTYPE_CONTROL; 725 c->ctype = AVC_CTYPE_CONTROL;
708 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 726 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -710,27 +728,30 @@ int avc_tuner_status(struct firedtv *fdtv, struct firedtv_tuner_status *stat)
710 728
711 c->operand[0] = DESCRIPTOR_TUNER_STATUS; 729 c->operand[0] = DESCRIPTOR_TUNER_STATUS;
712 c->operand[1] = 0xff; /* read_result_status */ 730 c->operand[1] = 0xff; /* read_result_status */
713 c->operand[2] = 0x00; /* reserved */ 731 /*
714 c->operand[3] = 0; /* SIZEOF_ANTENNA_INPUT_INFO >> 8; */ 732 * operand[2]: reserved
715 c->operand[4] = 0; /* SIZEOF_ANTENNA_INPUT_INFO & 0xff; */ 733 * operand[3]: SIZEOF_ANTENNA_INPUT_INFO >> 8
716 c->operand[5] = 0x00; 734 * operand[4]: SIZEOF_ANTENNA_INPUT_INFO & 0xff
717 c->operand[6] = 0x00; 735 */
718 736 clear_operands(c, 2, 31);
719 c->length = 12; 737
720 738 fdtv->avc_data_length = 12;
721 if (avc_write(fdtv, c, r) < 0) 739 ret = avc_write(fdtv);
722 return -EIO; 740 if (ret < 0)
741 goto out;
723 742
724 if (r->response != AVC_RESPONSE_STABLE && 743 if (r->response != AVC_RESPONSE_STABLE &&
725 r->response != AVC_RESPONSE_ACCEPTED) { 744 r->response != AVC_RESPONSE_ACCEPTED) {
726 dev_err(fdtv->device, "cannot read tuner status\n"); 745 dev_err(fdtv->device, "cannot read tuner status\n");
727 return -EINVAL; 746 ret = -EINVAL;
747 goto out;
728 } 748 }
729 749
730 length = r->operand[9]; 750 length = r->operand[9];
731 if (r->operand[1] != 0x10 || length != SIZEOF_ANTENNA_INPUT_INFO) { 751 if (r->operand[1] != 0x10 || length != SIZEOF_ANTENNA_INPUT_INFO) {
732 dev_err(fdtv->device, "got invalid tuner status\n"); 752 dev_err(fdtv->device, "got invalid tuner status\n");
733 return -EINVAL; 753 ret = -EINVAL;
754 goto out;
734 } 755 }
735 756
736 stat->active_system = r->operand[10]; 757 stat->active_system = r->operand[10];
@@ -766,20 +787,21 @@ int avc_tuner_status(struct firedtv *fdtv, struct firedtv_tuner_status *stat)
766 stat->ca_dvb_flag = r->operand[31] >> 3 & 1; 787 stat->ca_dvb_flag = r->operand[31] >> 3 & 1;
767 stat->ca_error_flag = r->operand[31] >> 2 & 1; 788 stat->ca_error_flag = r->operand[31] >> 2 & 1;
768 stat->ca_initialization_status = r->operand[31] >> 1 & 1; 789 stat->ca_initialization_status = r->operand[31] >> 1 & 1;
790out:
791 mutex_unlock(&fdtv->avc_mutex);
769 792
770 return 0; 793 return ret;
771} 794}
772 795
773int avc_lnb_control(struct firedtv *fdtv, char voltage, char burst, 796int avc_lnb_control(struct firedtv *fdtv, char voltage, char burst,
774 char conttone, char nrdiseq, 797 char conttone, char nrdiseq,
775 struct dvb_diseqc_master_cmd *diseqcmd) 798 struct dvb_diseqc_master_cmd *diseqcmd)
776{ 799{
777 char buffer[sizeof(struct avc_command_frame)]; 800 struct avc_command_frame *c = (void *)fdtv->avc_data;
778 struct avc_command_frame *c = (void *)buffer; 801 struct avc_response_frame *r = (void *)fdtv->avc_data;
779 struct avc_response_frame *r = (void *)buffer; 802 int pos, j, k, ret;
780 int i, j, k;
781 803
782 memset(c, 0, sizeof(*c)); 804 mutex_lock(&fdtv->avc_mutex);
783 805
784 c->ctype = AVC_CTYPE_CONTROL; 806 c->ctype = AVC_CTYPE_CONTROL;
785 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 807 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -789,41 +811,41 @@ int avc_lnb_control(struct firedtv *fdtv, char voltage, char burst,
789 c->operand[1] = SFE_VENDOR_DE_COMPANYID_1; 811 c->operand[1] = SFE_VENDOR_DE_COMPANYID_1;
790 c->operand[2] = SFE_VENDOR_DE_COMPANYID_2; 812 c->operand[2] = SFE_VENDOR_DE_COMPANYID_2;
791 c->operand[3] = SFE_VENDOR_OPCODE_LNB_CONTROL; 813 c->operand[3] = SFE_VENDOR_OPCODE_LNB_CONTROL;
792
793 c->operand[4] = voltage; 814 c->operand[4] = voltage;
794 c->operand[5] = nrdiseq; 815 c->operand[5] = nrdiseq;
795 816
796 i = 6; 817 pos = 6;
797
798 for (j = 0; j < nrdiseq; j++) { 818 for (j = 0; j < nrdiseq; j++) {
799 c->operand[i++] = diseqcmd[j].msg_len; 819 c->operand[pos++] = diseqcmd[j].msg_len;
800 820
801 for (k = 0; k < diseqcmd[j].msg_len; k++) 821 for (k = 0; k < diseqcmd[j].msg_len; k++)
802 c->operand[i++] = diseqcmd[j].msg[k]; 822 c->operand[pos++] = diseqcmd[j].msg[k];
803 } 823 }
824 c->operand[pos++] = burst;
825 c->operand[pos++] = conttone;
826 pad_operands(c, pos);
804 827
805 c->operand[i++] = burst; 828 fdtv->avc_data_length = ALIGN(3 + pos, 4);
806 c->operand[i++] = conttone; 829 ret = avc_write(fdtv);
807 830 if (ret < 0)
808 c->length = ALIGN(3 + i, 4); 831 goto out;
809
810 if (avc_write(fdtv, c, r) < 0)
811 return -EIO;
812 832
813 if (r->response != AVC_RESPONSE_ACCEPTED) { 833 if (r->response != AVC_RESPONSE_ACCEPTED) {
814 dev_err(fdtv->device, "LNB control failed\n"); 834 dev_err(fdtv->device, "LNB control failed\n");
815 return -EINVAL; 835 ret = -EINVAL;
816 } 836 }
837out:
838 mutex_unlock(&fdtv->avc_mutex);
817 839
818 return 0; 840 return ret;
819} 841}
820 842
821int avc_register_remote_control(struct firedtv *fdtv) 843int avc_register_remote_control(struct firedtv *fdtv)
822{ 844{
823 char buffer[sizeof(struct avc_command_frame)]; 845 struct avc_command_frame *c = (void *)fdtv->avc_data;
824 struct avc_command_frame *c = (void *)buffer; 846 int ret;
825 847
826 memset(c, 0, sizeof(*c)); 848 mutex_lock(&fdtv->avc_mutex);
827 849
828 c->ctype = AVC_CTYPE_NOTIFY; 850 c->ctype = AVC_CTYPE_NOTIFY;
829 c->subunit = AVC_SUBUNIT_TYPE_UNIT | 7; 851 c->subunit = AVC_SUBUNIT_TYPE_UNIT | 7;
@@ -833,10 +855,16 @@ int avc_register_remote_control(struct firedtv *fdtv)
833 c->operand[1] = SFE_VENDOR_DE_COMPANYID_1; 855 c->operand[1] = SFE_VENDOR_DE_COMPANYID_1;
834 c->operand[2] = SFE_VENDOR_DE_COMPANYID_2; 856 c->operand[2] = SFE_VENDOR_DE_COMPANYID_2;
835 c->operand[3] = SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL; 857 c->operand[3] = SFE_VENDOR_OPCODE_REGISTER_REMOTE_CONTROL;
858 c->operand[4] = 0; /* padding */
859
860 fdtv->avc_data_length = 8;
861 ret = avc_write(fdtv);
836 862
837 c->length = 8; 863 /* FIXME: check response code? */
838 864
839 return avc_write(fdtv, c, NULL); 865 mutex_unlock(&fdtv->avc_mutex);
866
867 return ret;
840} 868}
841 869
842void avc_remote_ctrl_work(struct work_struct *work) 870void avc_remote_ctrl_work(struct work_struct *work)
@@ -851,11 +879,10 @@ void avc_remote_ctrl_work(struct work_struct *work)
851#if 0 /* FIXME: unused */ 879#if 0 /* FIXME: unused */
852int avc_tuner_host2ca(struct firedtv *fdtv) 880int avc_tuner_host2ca(struct firedtv *fdtv)
853{ 881{
854 char buffer[sizeof(struct avc_command_frame)]; 882 struct avc_command_frame *c = (void *)fdtv->avc_data;
855 struct avc_command_frame *c = (void *)buffer; 883 int ret;
856 struct avc_response_frame *r = (void *)buffer; /* FIXME: unused */
857 884
858 memset(c, 0, sizeof(*c)); 885 mutex_lock(&fdtv->avc_mutex);
859 886
860 c->ctype = AVC_CTYPE_CONTROL; 887 c->ctype = AVC_CTYPE_CONTROL;
861 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 888 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -867,15 +894,16 @@ int avc_tuner_host2ca(struct firedtv *fdtv)
867 c->operand[3] = SFE_VENDOR_OPCODE_HOST2CA; 894 c->operand[3] = SFE_VENDOR_OPCODE_HOST2CA;
868 c->operand[4] = 0; /* slot */ 895 c->operand[4] = 0; /* slot */
869 c->operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; /* ca tag */ 896 c->operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; /* ca tag */
870 c->operand[6] = 0; /* more/last */ 897 clear_operands(c, 6, 8);
871 c->operand[7] = 0; /* length */
872 898
873 c->length = 12; 899 fdtv->avc_data_length = 12;
900 ret = avc_write(fdtv);
874 901
875 if (avc_write(fdtv, c, r) < 0) 902 /* FIXME: check response code? */
876 return -EIO;
877 903
878 return 0; 904 mutex_unlock(&fdtv->avc_mutex);
905
906 return ret;
879} 907}
880#endif 908#endif
881 909
@@ -906,12 +934,11 @@ static int get_ca_object_length(struct avc_response_frame *r)
906 934
907int avc_ca_app_info(struct firedtv *fdtv, char *app_info, unsigned int *len) 935int avc_ca_app_info(struct firedtv *fdtv, char *app_info, unsigned int *len)
908{ 936{
909 char buffer[sizeof(struct avc_command_frame)]; 937 struct avc_command_frame *c = (void *)fdtv->avc_data;
910 struct avc_command_frame *c = (void *)buffer; 938 struct avc_response_frame *r = (void *)fdtv->avc_data;
911 struct avc_response_frame *r = (void *)buffer; 939 int pos, ret;
912 int pos;
913 940
914 memset(c, 0, sizeof(*c)); 941 mutex_lock(&fdtv->avc_mutex);
915 942
916 c->ctype = AVC_CTYPE_STATUS; 943 c->ctype = AVC_CTYPE_STATUS;
917 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 944 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -923,11 +950,12 @@ int avc_ca_app_info(struct firedtv *fdtv, char *app_info, unsigned int *len)
923 c->operand[3] = SFE_VENDOR_OPCODE_CA2HOST; 950 c->operand[3] = SFE_VENDOR_OPCODE_CA2HOST;
924 c->operand[4] = 0; /* slot */ 951 c->operand[4] = 0; /* slot */
925 c->operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; /* ca tag */ 952 c->operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; /* ca tag */
953 clear_operands(c, 6, LAST_OPERAND);
926 954
927 c->length = 12; 955 fdtv->avc_data_length = 12;
928 956 ret = avc_write(fdtv);
929 if (avc_write(fdtv, c, r) < 0) 957 if (ret < 0)
930 return -EIO; 958 goto out;
931 959
932 /* FIXME: check response code and validate response data */ 960 /* FIXME: check response code and validate response data */
933 961
@@ -939,18 +967,19 @@ int avc_ca_app_info(struct firedtv *fdtv, char *app_info, unsigned int *len)
939 app_info[4] = 0x01; 967 app_info[4] = 0x01;
940 memcpy(&app_info[5], &r->operand[pos], 5 + r->operand[pos + 4]); 968 memcpy(&app_info[5], &r->operand[pos], 5 + r->operand[pos + 4]);
941 *len = app_info[3] + 4; 969 *len = app_info[3] + 4;
970out:
971 mutex_unlock(&fdtv->avc_mutex);
942 972
943 return 0; 973 return ret;
944} 974}
945 975
946int avc_ca_info(struct firedtv *fdtv, char *app_info, unsigned int *len) 976int avc_ca_info(struct firedtv *fdtv, char *app_info, unsigned int *len)
947{ 977{
948 char buffer[sizeof(struct avc_command_frame)]; 978 struct avc_command_frame *c = (void *)fdtv->avc_data;
949 struct avc_command_frame *c = (void *)buffer; 979 struct avc_response_frame *r = (void *)fdtv->avc_data;
950 struct avc_response_frame *r = (void *)buffer; 980 int pos, ret;
951 int pos;
952 981
953 memset(c, 0, sizeof(*c)); 982 mutex_lock(&fdtv->avc_mutex);
954 983
955 c->ctype = AVC_CTYPE_STATUS; 984 c->ctype = AVC_CTYPE_STATUS;
956 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 985 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -962,11 +991,14 @@ int avc_ca_info(struct firedtv *fdtv, char *app_info, unsigned int *len)
962 c->operand[3] = SFE_VENDOR_OPCODE_CA2HOST; 991 c->operand[3] = SFE_VENDOR_OPCODE_CA2HOST;
963 c->operand[4] = 0; /* slot */ 992 c->operand[4] = 0; /* slot */
964 c->operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; /* ca tag */ 993 c->operand[5] = SFE_VENDOR_TAG_CA_APPLICATION_INFO; /* ca tag */
994 clear_operands(c, 6, LAST_OPERAND);
965 995
966 c->length = 12; 996 fdtv->avc_data_length = 12;
997 ret = avc_write(fdtv);
998 if (ret < 0)
999 goto out;
967 1000
968 if (avc_write(fdtv, c, r) < 0) 1001 /* FIXME: check response code and validate response data */
969 return -EIO;
970 1002
971 pos = get_ca_object_pos(r); 1003 pos = get_ca_object_pos(r);
972 app_info[0] = (EN50221_TAG_CA_INFO >> 16) & 0xff; 1004 app_info[0] = (EN50221_TAG_CA_INFO >> 16) & 0xff;
@@ -976,17 +1008,18 @@ int avc_ca_info(struct firedtv *fdtv, char *app_info, unsigned int *len)
976 app_info[4] = r->operand[pos + 0]; 1008 app_info[4] = r->operand[pos + 0];
977 app_info[5] = r->operand[pos + 1]; 1009 app_info[5] = r->operand[pos + 1];
978 *len = app_info[3] + 4; 1010 *len = app_info[3] + 4;
1011out:
1012 mutex_unlock(&fdtv->avc_mutex);
979 1013
980 return 0; 1014 return ret;
981} 1015}
982 1016
983int avc_ca_reset(struct firedtv *fdtv) 1017int avc_ca_reset(struct firedtv *fdtv)
984{ 1018{
985 char buffer[sizeof(struct avc_command_frame)]; 1019 struct avc_command_frame *c = (void *)fdtv->avc_data;
986 struct avc_command_frame *c = (void *)buffer; 1020 int ret;
987 struct avc_response_frame *r = (void *)buffer; /* FIXME: unused */
988 1021
989 memset(c, 0, sizeof(*c)); 1022 mutex_lock(&fdtv->avc_mutex);
990 1023
991 c->ctype = AVC_CTYPE_CONTROL; 1024 c->ctype = AVC_CTYPE_CONTROL;
992 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 1025 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -1002,19 +1035,20 @@ int avc_ca_reset(struct firedtv *fdtv)
1002 c->operand[7] = 1; /* length */ 1035 c->operand[7] = 1; /* length */
1003 c->operand[8] = 0; /* force hardware reset */ 1036 c->operand[8] = 0; /* force hardware reset */
1004 1037
1005 c->length = 12; 1038 fdtv->avc_data_length = 12;
1039 ret = avc_write(fdtv);
1006 1040
1007 if (avc_write(fdtv, c, r) < 0) 1041 /* FIXME: check response code? */
1008 return -EIO;
1009 1042
1010 return 0; 1043 mutex_unlock(&fdtv->avc_mutex);
1044
1045 return ret;
1011} 1046}
1012 1047
1013int avc_ca_pmt(struct firedtv *fdtv, char *msg, int length) 1048int avc_ca_pmt(struct firedtv *fdtv, char *msg, int length)
1014{ 1049{
1015 char buffer[sizeof(struct avc_command_frame)]; 1050 struct avc_command_frame *c = (void *)fdtv->avc_data;
1016 struct avc_command_frame *c = (void *)buffer; 1051 struct avc_response_frame *r = (void *)fdtv->avc_data;
1017 struct avc_response_frame *r = (void *)buffer;
1018 int list_management; 1052 int list_management;
1019 int program_info_length; 1053 int program_info_length;
1020 int pmt_cmd_id; 1054 int pmt_cmd_id;
@@ -1022,11 +1056,12 @@ int avc_ca_pmt(struct firedtv *fdtv, char *msg, int length)
1022 int write_pos; 1056 int write_pos;
1023 int es_info_length; 1057 int es_info_length;
1024 int crc32_csum; 1058 int crc32_csum;
1059 int ret;
1025 1060
1026 if (unlikely(avc_debug & AVC_DEBUG_APPLICATION_PMT)) 1061 if (unlikely(avc_debug & AVC_DEBUG_APPLICATION_PMT))
1027 debug_pmt(msg, length); 1062 debug_pmt(msg, length);
1028 1063
1029 memset(c, 0, sizeof(*c)); 1064 mutex_lock(&fdtv->avc_mutex);
1030 1065
1031 c->ctype = AVC_CTYPE_CONTROL; 1066 c->ctype = AVC_CTYPE_CONTROL;
1032 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 1067 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -1058,7 +1093,7 @@ int avc_ca_pmt(struct firedtv *fdtv, char *msg, int length)
1058 1093
1059 c->operand[12] = 0x02; /* Table id=2 */ 1094 c->operand[12] = 0x02; /* Table id=2 */
1060 c->operand[13] = 0x80; /* Section syntax + length */ 1095 c->operand[13] = 0x80; /* Section syntax + length */
1061 /* c->operand[14] = XXXprogram_info_length + 12; */ 1096
1062 c->operand[15] = msg[1]; /* Program number */ 1097 c->operand[15] = msg[1]; /* Program number */
1063 c->operand[16] = msg[2]; 1098 c->operand[16] = msg[2];
1064 c->operand[17] = 0x01; /* Version number=0 + current/next=1 */ 1099 c->operand[17] = 0x01; /* Version number=0 + current/next=1 */
@@ -1106,12 +1141,7 @@ int avc_ca_pmt(struct firedtv *fdtv, char *msg, int length)
1106 write_pos += es_info_length; 1141 write_pos += es_info_length;
1107 } 1142 }
1108 } 1143 }
1109 1144 write_pos += 4; /* CRC */
1110 /* CRC */
1111 c->operand[write_pos++] = 0x00;
1112 c->operand[write_pos++] = 0x00;
1113 c->operand[write_pos++] = 0x00;
1114 c->operand[write_pos++] = 0x00;
1115 1145
1116 c->operand[7] = 0x82; 1146 c->operand[7] = 0x82;
1117 c->operand[8] = (write_pos - 10) >> 8; 1147 c->operand[8] = (write_pos - 10) >> 8;
@@ -1123,28 +1153,31 @@ int avc_ca_pmt(struct firedtv *fdtv, char *msg, int length)
1123 c->operand[write_pos - 3] = (crc32_csum >> 16) & 0xff; 1153 c->operand[write_pos - 3] = (crc32_csum >> 16) & 0xff;
1124 c->operand[write_pos - 2] = (crc32_csum >> 8) & 0xff; 1154 c->operand[write_pos - 2] = (crc32_csum >> 8) & 0xff;
1125 c->operand[write_pos - 1] = (crc32_csum >> 0) & 0xff; 1155 c->operand[write_pos - 1] = (crc32_csum >> 0) & 0xff;
1156 pad_operands(c, write_pos);
1126 1157
1127 c->length = ALIGN(3 + write_pos, 4); 1158 fdtv->avc_data_length = ALIGN(3 + write_pos, 4);
1128 1159 ret = avc_write(fdtv);
1129 if (avc_write(fdtv, c, r) < 0) 1160 if (ret < 0)
1130 return -EIO; 1161 goto out;
1131 1162
1132 if (r->response != AVC_RESPONSE_ACCEPTED) { 1163 if (r->response != AVC_RESPONSE_ACCEPTED) {
1133 dev_err(fdtv->device, 1164 dev_err(fdtv->device,
1134 "CA PMT failed with response 0x%x\n", r->response); 1165 "CA PMT failed with response 0x%x\n", r->response);
1135 return -EFAULT; 1166 ret = -EFAULT;
1136 } 1167 }
1168out:
1169 mutex_unlock(&fdtv->avc_mutex);
1137 1170
1138 return 0; 1171 return ret;
1139} 1172}
1140 1173
1141int avc_ca_get_time_date(struct firedtv *fdtv, int *interval) 1174int avc_ca_get_time_date(struct firedtv *fdtv, int *interval)
1142{ 1175{
1143 char buffer[sizeof(struct avc_command_frame)]; 1176 struct avc_command_frame *c = (void *)fdtv->avc_data;
1144 struct avc_command_frame *c = (void *)buffer; 1177 struct avc_response_frame *r = (void *)fdtv->avc_data;
1145 struct avc_response_frame *r = (void *)buffer; 1178 int ret;
1146 1179
1147 memset(c, 0, sizeof(*c)); 1180 mutex_lock(&fdtv->avc_mutex);
1148 1181
1149 c->ctype = AVC_CTYPE_STATUS; 1182 c->ctype = AVC_CTYPE_STATUS;
1150 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 1183 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -1156,28 +1189,28 @@ int avc_ca_get_time_date(struct firedtv *fdtv, int *interval)
1156 c->operand[3] = SFE_VENDOR_OPCODE_CA2HOST; 1189 c->operand[3] = SFE_VENDOR_OPCODE_CA2HOST;
1157 c->operand[4] = 0; /* slot */ 1190 c->operand[4] = 0; /* slot */
1158 c->operand[5] = SFE_VENDOR_TAG_CA_DATE_TIME; /* ca tag */ 1191 c->operand[5] = SFE_VENDOR_TAG_CA_DATE_TIME; /* ca tag */
1159 c->operand[6] = 0; /* more/last */ 1192 clear_operands(c, 6, LAST_OPERAND);
1160 c->operand[7] = 0; /* length */
1161 1193
1162 c->length = 12; 1194 fdtv->avc_data_length = 12;
1163 1195 ret = avc_write(fdtv);
1164 if (avc_write(fdtv, c, r) < 0) 1196 if (ret < 0)
1165 return -EIO; 1197 goto out;
1166 1198
1167 /* FIXME: check response code and validate response data */ 1199 /* FIXME: check response code and validate response data */
1168 1200
1169 *interval = r->operand[get_ca_object_pos(r)]; 1201 *interval = r->operand[get_ca_object_pos(r)];
1202out:
1203 mutex_unlock(&fdtv->avc_mutex);
1170 1204
1171 return 0; 1205 return ret;
1172} 1206}
1173 1207
1174int avc_ca_enter_menu(struct firedtv *fdtv) 1208int avc_ca_enter_menu(struct firedtv *fdtv)
1175{ 1209{
1176 char buffer[sizeof(struct avc_command_frame)]; 1210 struct avc_command_frame *c = (void *)fdtv->avc_data;
1177 struct avc_command_frame *c = (void *)buffer; 1211 int ret;
1178 struct avc_response_frame *r = (void *)buffer; /* FIXME: unused */
1179 1212
1180 memset(c, 0, sizeof(*c)); 1213 mutex_lock(&fdtv->avc_mutex);
1181 1214
1182 c->ctype = AVC_CTYPE_STATUS; 1215 c->ctype = AVC_CTYPE_STATUS;
1183 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 1216 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -1189,24 +1222,25 @@ int avc_ca_enter_menu(struct firedtv *fdtv)
1189 c->operand[3] = SFE_VENDOR_OPCODE_HOST2CA; 1222 c->operand[3] = SFE_VENDOR_OPCODE_HOST2CA;
1190 c->operand[4] = 0; /* slot */ 1223 c->operand[4] = 0; /* slot */
1191 c->operand[5] = SFE_VENDOR_TAG_CA_ENTER_MENU; 1224 c->operand[5] = SFE_VENDOR_TAG_CA_ENTER_MENU;
1192 c->operand[6] = 0; /* more/last */ 1225 clear_operands(c, 6, 8);
1193 c->operand[7] = 0; /* length */
1194 1226
1195 c->length = 12; 1227 fdtv->avc_data_length = 12;
1228 ret = avc_write(fdtv);
1196 1229
1197 if (avc_write(fdtv, c, r) < 0) 1230 /* FIXME: check response code? */
1198 return -EIO;
1199 1231
1200 return 0; 1232 mutex_unlock(&fdtv->avc_mutex);
1233
1234 return ret;
1201} 1235}
1202 1236
1203int avc_ca_get_mmi(struct firedtv *fdtv, char *mmi_object, unsigned int *len) 1237int avc_ca_get_mmi(struct firedtv *fdtv, char *mmi_object, unsigned int *len)
1204{ 1238{
1205 char buffer[sizeof(struct avc_command_frame)]; 1239 struct avc_command_frame *c = (void *)fdtv->avc_data;
1206 struct avc_command_frame *c = (void *)buffer; 1240 struct avc_response_frame *r = (void *)fdtv->avc_data;
1207 struct avc_response_frame *r = (void *)buffer; 1241 int ret;
1208 1242
1209 memset(c, 0, sizeof(*c)); 1243 mutex_lock(&fdtv->avc_mutex);
1210 1244
1211 c->ctype = AVC_CTYPE_STATUS; 1245 c->ctype = AVC_CTYPE_STATUS;
1212 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit; 1246 c->subunit = AVC_SUBUNIT_TYPE_TUNER | fdtv->subunit;
@@ -1218,20 +1252,21 @@ int avc_ca_get_mmi(struct firedtv *fdtv, char *mmi_object, unsigned int *len)
1218 c->operand[3] = SFE_VENDOR_OPCODE_CA2HOST; 1252 c->operand[3] = SFE_VENDOR_OPCODE_CA2HOST;
1219 c->operand[4] = 0; /* slot */ 1253 c->operand[4] = 0; /* slot */
1220 c->operand[5] = SFE_VENDOR_TAG_CA_MMI; 1254 c->operand[5] = SFE_VENDOR_TAG_CA_MMI;
1221 c->operand[6] = 0; /* more/last */ 1255 clear_operands(c, 6, LAST_OPERAND);
1222 c->operand[7] = 0; /* length */
1223 1256
1224 c->length = 12; 1257 fdtv->avc_data_length = 12;
1225 1258 ret = avc_write(fdtv);
1226 if (avc_write(fdtv, c, r) < 0) 1259 if (ret < 0)
1227 return -EIO; 1260 goto out;
1228 1261
1229 /* FIXME: check response code and validate response data */ 1262 /* FIXME: check response code and validate response data */
1230 1263
1231 *len = get_ca_object_length(r); 1264 *len = get_ca_object_length(r);
1232 memcpy(mmi_object, &r->operand[get_ca_object_pos(r)], *len); 1265 memcpy(mmi_object, &r->operand[get_ca_object_pos(r)], *len);
1266out:
1267 mutex_unlock(&fdtv->avc_mutex);
1233 1268
1234 return 0; 1269 return ret;
1235} 1270}
1236 1271
1237#define CMP_OUTPUT_PLUG_CONTROL_REG_0 0xfffff0000904ULL 1272#define CMP_OUTPUT_PLUG_CONTROL_REG_0 0xfffff0000904ULL
@@ -1240,14 +1275,14 @@ static int cmp_read(struct firedtv *fdtv, u64 addr, __be32 *data)
1240{ 1275{
1241 int ret; 1276 int ret;
1242 1277
1243 if (mutex_lock_interruptible(&fdtv->avc_mutex)) 1278 mutex_lock(&fdtv->avc_mutex);
1244 return -EINTR;
1245 1279
1246 ret = fdtv->backend->read(fdtv, addr, data); 1280 ret = fdtv->backend->read(fdtv, addr, data);
1247 if (ret < 0) 1281 if (ret < 0)
1248 dev_err(fdtv->device, "CMP: read I/O error\n"); 1282 dev_err(fdtv->device, "CMP: read I/O error\n");
1249 1283
1250 mutex_unlock(&fdtv->avc_mutex); 1284 mutex_unlock(&fdtv->avc_mutex);
1285
1251 return ret; 1286 return ret;
1252} 1287}
1253 1288
@@ -1255,14 +1290,19 @@ static int cmp_lock(struct firedtv *fdtv, u64 addr, __be32 data[])
1255{ 1290{
1256 int ret; 1291 int ret;
1257 1292
1258 if (mutex_lock_interruptible(&fdtv->avc_mutex)) 1293 mutex_lock(&fdtv->avc_mutex);
1259 return -EINTR; 1294
1295 /* data[] is stack-allocated and should not be DMA-mapped. */
1296 memcpy(fdtv->avc_data, data, 8);
1260 1297
1261 ret = fdtv->backend->lock(fdtv, addr, data); 1298 ret = fdtv->backend->lock(fdtv, addr, fdtv->avc_data);
1262 if (ret < 0) 1299 if (ret < 0)
1263 dev_err(fdtv->device, "CMP: lock I/O error\n"); 1300 dev_err(fdtv->device, "CMP: lock I/O error\n");
1301 else
1302 memcpy(data, fdtv->avc_data, 8);
1264 1303
1265 mutex_unlock(&fdtv->avc_mutex); 1304 mutex_unlock(&fdtv->avc_mutex);
1305
1266 return ret; 1306 return ret;
1267} 1307}
1268 1308
diff --git a/drivers/media/dvb/firewire/firedtv-dvb.c b/drivers/media/dvb/firewire/firedtv-dvb.c
index fc9996c13e13..079e8c5b0475 100644
--- a/drivers/media/dvb/firewire/firedtv-dvb.c
+++ b/drivers/media/dvb/firewire/firedtv-dvb.c
@@ -277,7 +277,6 @@ struct firedtv *fdtv_alloc(struct device *dev,
277 277
278 mutex_init(&fdtv->avc_mutex); 278 mutex_init(&fdtv->avc_mutex);
279 init_waitqueue_head(&fdtv->avc_wait); 279 init_waitqueue_head(&fdtv->avc_wait);
280 fdtv->avc_reply_received = true;
281 mutex_init(&fdtv->demux_mutex); 280 mutex_init(&fdtv->demux_mutex);
282 INIT_WORK(&fdtv->remote_ctrl_work, avc_remote_ctrl_work); 281 INIT_WORK(&fdtv->remote_ctrl_work, avc_remote_ctrl_work);
283 282
diff --git a/drivers/media/dvb/firewire/firedtv-fw.c b/drivers/media/dvb/firewire/firedtv-fw.c
index 6223bf01efe9..7a3de16fba06 100644
--- a/drivers/media/dvb/firewire/firedtv-fw.c
+++ b/drivers/media/dvb/firewire/firedtv-fw.c
@@ -41,7 +41,7 @@ static int node_req(struct firedtv *fdtv, u64 addr, void *data, size_t len,
41 return rcode != RCODE_COMPLETE ? -EIO : 0; 41 return rcode != RCODE_COMPLETE ? -EIO : 0;
42} 42}
43 43
44static int node_lock(struct firedtv *fdtv, u64 addr, __be32 data[]) 44static int node_lock(struct firedtv *fdtv, u64 addr, void *data)
45{ 45{
46 return node_req(fdtv, addr, data, 8, TCODE_LOCK_COMPARE_SWAP); 46 return node_req(fdtv, addr, data, 8, TCODE_LOCK_COMPARE_SWAP);
47} 47}
diff --git a/drivers/media/dvb/firewire/firedtv.h b/drivers/media/dvb/firewire/firedtv.h
index 35080dbb3c66..78cc28f36914 100644
--- a/drivers/media/dvb/firewire/firedtv.h
+++ b/drivers/media/dvb/firewire/firedtv.h
@@ -73,7 +73,7 @@ struct input_dev;
73struct firedtv; 73struct firedtv;
74 74
75struct firedtv_backend { 75struct firedtv_backend {
76 int (*lock)(struct firedtv *fdtv, u64 addr, __be32 data[]); 76 int (*lock)(struct firedtv *fdtv, u64 addr, void *data);
77 int (*read)(struct firedtv *fdtv, u64 addr, void *data); 77 int (*read)(struct firedtv *fdtv, u64 addr, void *data);
78 int (*write)(struct firedtv *fdtv, u64 addr, void *data, size_t len); 78 int (*write)(struct firedtv *fdtv, u64 addr, void *data, size_t len);
79 int (*start_iso)(struct firedtv *fdtv); 79 int (*start_iso)(struct firedtv *fdtv);
@@ -114,8 +114,8 @@ struct firedtv {
114 unsigned long channel_active; 114 unsigned long channel_active;
115 u16 channel_pid[16]; 115 u16 channel_pid[16];
116 116
117 size_t response_length; 117 int avc_data_length;
118 u8 response[512]; 118 u8 avc_data[512];
119}; 119};
120 120
121/* firedtv-1394.c */ 121/* firedtv-1394.c */
diff --git a/drivers/media/dvb/frontends/af9013.h b/drivers/media/dvb/frontends/af9013.h
index 28b90c91c766..e90fa92b1c1d 100644
--- a/drivers/media/dvb/frontends/af9013.h
+++ b/drivers/media/dvb/frontends/af9013.h
@@ -44,6 +44,7 @@ enum af9013_tuner {
44 AF9013_TUNER_MT2060_2 = 147, /* Microtune */ 44 AF9013_TUNER_MT2060_2 = 147, /* Microtune */
45 AF9013_TUNER_TDA18271 = 156, /* NXP */ 45 AF9013_TUNER_TDA18271 = 156, /* NXP */
46 AF9013_TUNER_QT1010A = 162, /* Quantek */ 46 AF9013_TUNER_QT1010A = 162, /* Quantek */
47 AF9013_TUNER_TDA18218 = 179, /* NXP */
47}; 48};
48 49
49/* AF9013/5 GPIOs (mostly guessed) 50/* AF9013/5 GPIOs (mostly guessed)
diff --git a/drivers/media/dvb/frontends/atbm8830.c b/drivers/media/dvb/frontends/atbm8830.c
index 59881a5944eb..43aac2f85c2e 100644
--- a/drivers/media/dvb/frontends/atbm8830.c
+++ b/drivers/media/dvb/frontends/atbm8830.c
@@ -170,6 +170,19 @@ static int is_locked(struct atbm_state *priv, u8 *locked)
170 return 0; 170 return 0;
171} 171}
172 172
173static int set_agc_config(struct atbm_state *priv,
174 u8 min, u8 max, u8 hold_loop)
175{
176 /* no effect if both min and max are zero */
177 if (!min && !max)
178 return 0;
179
180 atbm8830_write_reg(priv, REG_AGC_MIN, min);
181 atbm8830_write_reg(priv, REG_AGC_MAX, max);
182 atbm8830_write_reg(priv, REG_AGC_HOLD_LOOP, hold_loop);
183
184 return 0;
185}
173 186
174static int set_static_channel_mode(struct atbm_state *priv) 187static int set_static_channel_mode(struct atbm_state *priv)
175{ 188{
@@ -227,6 +240,9 @@ static int atbm8830_init(struct dvb_frontend *fe)
227 /*Set IF frequency*/ 240 /*Set IF frequency*/
228 set_if_freq(priv, cfg->if_freq); 241 set_if_freq(priv, cfg->if_freq);
229 242
243 /*Set AGC Config*/
244 set_agc_config(priv, cfg->agc_min, cfg->agc_max,
245 cfg->agc_hold_loop);
230 246
231 /*Set static channel mode*/ 247 /*Set static channel mode*/
232 set_static_channel_mode(priv); 248 set_static_channel_mode(priv);
diff --git a/drivers/media/dvb/frontends/dib0090.c b/drivers/media/dvb/frontends/dib0090.c
index 614552709a6f..7eac178f57b2 100644
--- a/drivers/media/dvb/frontends/dib0090.c
+++ b/drivers/media/dvb/frontends/dib0090.c
@@ -283,7 +283,7 @@ static int dib0090_sleep(struct dvb_frontend *fe)
283 return 0; 283 return 0;
284} 284}
285 285
286extern void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast) 286void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast)
287{ 287{
288 struct dib0090_state *state = fe->tuner_priv; 288 struct dib0090_state *state = fe->tuner_priv;
289 if (fast) 289 if (fast)
diff --git a/drivers/media/dvb/frontends/dib8000.c b/drivers/media/dvb/frontends/dib8000.c
index 6f6fa29d9ea4..2aa97dd6a8af 100644
--- a/drivers/media/dvb/frontends/dib8000.c
+++ b/drivers/media/dvb/frontends/dib8000.c
@@ -1999,6 +1999,8 @@ static int dib8000_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_par
1999 struct dib8000_state *state = fe->demodulator_priv; 1999 struct dib8000_state *state = fe->demodulator_priv;
2000 int time, ret; 2000 int time, ret;
2001 2001
2002 fe->dtv_property_cache.delivery_system = SYS_ISDBT;
2003
2002 dib8000_set_output_mode(state, OUTMODE_HIGH_Z); 2004 dib8000_set_output_mode(state, OUTMODE_HIGH_Z);
2003 2005
2004 if (fe->ops.tuner_ops.set_params) 2006 if (fe->ops.tuner_ops.set_params)
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c
index e6f3d73db9d3..980e02f1575e 100644
--- a/drivers/media/dvb/frontends/dibx000_common.c
+++ b/drivers/media/dvb/frontends/dibx000_common.c
@@ -174,7 +174,7 @@ void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst)
174EXPORT_SYMBOL(dibx000_exit_i2c_master); 174EXPORT_SYMBOL(dibx000_exit_i2c_master);
175 175
176 176
177u32 systime() 177u32 systime(void)
178{ 178{
179 struct timespec t; 179 struct timespec t;
180 180
diff --git a/drivers/media/dvb/frontends/l64781.c b/drivers/media/dvb/frontends/l64781.c
index 3051b64aa17c..445fa1068064 100644
--- a/drivers/media/dvb/frontends/l64781.c
+++ b/drivers/media/dvb/frontends/l64781.c
@@ -192,8 +192,8 @@ static int apply_frontend_param (struct dvb_frontend* fe, struct dvb_frontend_pa
192 spi_bias *= qam_tab[p->constellation]; 192 spi_bias *= qam_tab[p->constellation];
193 spi_bias /= p->code_rate_HP + 1; 193 spi_bias /= p->code_rate_HP + 1;
194 spi_bias /= (guard_tab[p->guard_interval] + 32); 194 spi_bias /= (guard_tab[p->guard_interval] + 32);
195 spi_bias *= 1000ULL; 195 spi_bias *= 1000;
196 spi_bias /= 1000ULL + ppm/1000; 196 spi_bias /= 1000 + ppm/1000;
197 spi_bias *= p->code_rate_HP; 197 spi_bias *= p->code_rate_HP;
198 198
199 val0x04 = (p->transmission_mode << 2) | p->guard_interval; 199 val0x04 = (p->transmission_mode << 2) | p->guard_interval;
diff --git a/drivers/media/dvb/frontends/lnbp21.c b/drivers/media/dvb/frontends/lnbp21.c
index b181bf023ada..13437259eeac 100644
--- a/drivers/media/dvb/frontends/lnbp21.c
+++ b/drivers/media/dvb/frontends/lnbp21.c
@@ -158,7 +158,8 @@ static struct dvb_frontend *lnbx2x_attach(struct dvb_frontend *fe,
158 /* override frontend ops */ 158 /* override frontend ops */
159 fe->ops.set_voltage = lnbp21_set_voltage; 159 fe->ops.set_voltage = lnbp21_set_voltage;
160 fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage; 160 fe->ops.enable_high_lnb_voltage = lnbp21_enable_high_lnb_voltage;
161 fe->ops.set_tone = lnbp21_set_tone; 161 if (!(override_clear & LNBH24_TEN)) /*22kHz logic controlled by demod*/
162 fe->ops.set_tone = lnbp21_set_tone;
162 printk(KERN_INFO "LNBx2x attached on addr=%x\n", lnbp21->i2c_addr); 163 printk(KERN_INFO "LNBx2x attached on addr=%x\n", lnbp21->i2c_addr);
163 164
164 return fe; 165 return fe;
diff --git a/drivers/media/dvb/frontends/si21xx.c b/drivers/media/dvb/frontends/si21xx.c
index 9552a22ccffb..d21a327db629 100644
--- a/drivers/media/dvb/frontends/si21xx.c
+++ b/drivers/media/dvb/frontends/si21xx.c
@@ -97,8 +97,6 @@
97#define LNB_SUPPLY_CTRL_REG_4 0xce 97#define LNB_SUPPLY_CTRL_REG_4 0xce
98#define LNB_SUPPLY_STATUS_REG 0xcf 98#define LNB_SUPPLY_STATUS_REG 0xcf
99 99
100#define FALSE 0
101#define TRUE 1
102#define FAIL -1 100#define FAIL -1
103#define PASS 0 101#define PASS 0
104 102
@@ -718,7 +716,7 @@ static int si21xx_set_frontend(struct dvb_frontend *fe,
718 int fine_tune_freq; 716 int fine_tune_freq;
719 unsigned char sample_rate = 0; 717 unsigned char sample_rate = 0;
720 /* boolean */ 718 /* boolean */
721 unsigned int inband_interferer_ind; 719 bool inband_interferer_ind;
722 720
723 /* INTERMEDIATE VALUES */ 721 /* INTERMEDIATE VALUES */
724 int icoarse_tune_freq; /* MHz */ 722 int icoarse_tune_freq; /* MHz */
@@ -728,15 +726,8 @@ static int si21xx_set_frontend(struct dvb_frontend *fe,
728 unsigned int x1; 726 unsigned int x1;
729 unsigned int x2; 727 unsigned int x2;
730 int i; 728 int i;
731 unsigned int inband_interferer_div2[ALLOWABLE_FS_COUNT] = { 729 bool inband_interferer_div2[ALLOWABLE_FS_COUNT];
732 FALSE, FALSE, FALSE, FALSE, FALSE, 730 bool inband_interferer_div4[ALLOWABLE_FS_COUNT];
733 FALSE, FALSE, FALSE, FALSE, FALSE
734 };
735 unsigned int inband_interferer_div4[ALLOWABLE_FS_COUNT] = {
736 FALSE, FALSE, FALSE, FALSE, FALSE,
737 FALSE, FALSE, FALSE, FALSE, FALSE
738 };
739
740 int status; 731 int status;
741 732
742 /* allowable sample rates for ADC in MHz */ 733 /* allowable sample rates for ADC in MHz */
@@ -762,7 +753,7 @@ static int si21xx_set_frontend(struct dvb_frontend *fe,
762 } 753 }
763 754
764 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) 755 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i)
765 inband_interferer_div2[i] = inband_interferer_div4[i] = FALSE; 756 inband_interferer_div2[i] = inband_interferer_div4[i] = false;
766 757
767 if_limit_high = -700000; 758 if_limit_high = -700000;
768 if_limit_low = -100000; 759 if_limit_low = -100000;
@@ -798,7 +789,7 @@ static int si21xx_set_frontend(struct dvb_frontend *fe,
798 789
799 if (((band_low < x1) && (x1 < band_high)) || 790 if (((band_low < x1) && (x1 < band_high)) ||
800 ((band_low < x2) && (x2 < band_high))) 791 ((band_low < x2) && (x2 < band_high)))
801 inband_interferer_div4[i] = TRUE; 792 inband_interferer_div4[i] = true;
802 793
803 } 794 }
804 795
@@ -811,25 +802,28 @@ static int si21xx_set_frontend(struct dvb_frontend *fe,
811 802
812 if (((band_low < x1) && (x1 < band_high)) || 803 if (((band_low < x1) && (x1 < band_high)) ||
813 ((band_low < x2) && (x2 < band_high))) 804 ((band_low < x2) && (x2 < band_high)))
814 inband_interferer_div2[i] = TRUE; 805 inband_interferer_div2[i] = true;
815 } 806 }
816 807
817 inband_interferer_ind = TRUE; 808 inband_interferer_ind = true;
818 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) 809 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
819 inband_interferer_ind &= inband_interferer_div2[i] | 810 if (inband_interferer_div2[i] || inband_interferer_div4[i]) {
820 inband_interferer_div4[i]; 811 inband_interferer_ind = false;
812 break;
813 }
814 }
821 815
822 if (inband_interferer_ind) { 816 if (inband_interferer_ind) {
823 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) { 817 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
824 if (inband_interferer_div2[i] == FALSE) { 818 if (!inband_interferer_div2[i]) {
825 sample_rate = (u8) afs[i]; 819 sample_rate = (u8) afs[i];
826 break; 820 break;
827 } 821 }
828 } 822 }
829 } else { 823 } else {
830 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) { 824 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
831 if ((inband_interferer_div2[i] | 825 if ((inband_interferer_div2[i] ||
832 inband_interferer_div4[i]) == FALSE) { 826 !inband_interferer_div4[i])) {
833 sample_rate = (u8) afs[i]; 827 sample_rate = (u8) afs[i];
834 break; 828 break;
835 } 829 }
diff --git a/drivers/media/dvb/frontends/stv0900.h b/drivers/media/dvb/frontends/stv0900.h
index 29c3fa85c227..e3e35d1ce838 100644
--- a/drivers/media/dvb/frontends/stv0900.h
+++ b/drivers/media/dvb/frontends/stv0900.h
@@ -49,6 +49,8 @@ struct stv0900_config {
49 u8 tun2_maddress; 49 u8 tun2_maddress;
50 u8 tun1_adc;/* 1 for stv6110, 2 for stb6100 */ 50 u8 tun1_adc;/* 1 for stv6110, 2 for stb6100 */
51 u8 tun2_adc; 51 u8 tun2_adc;
52 u8 tun1_type;/* for now 3 for stb6100 auto, else - software */
53 u8 tun2_type;
52 /* Set device param to start dma */ 54 /* Set device param to start dma */
53 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured); 55 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
54}; 56};
diff --git a/drivers/media/dvb/frontends/stv0900_core.c b/drivers/media/dvb/frontends/stv0900_core.c
index 8762c86044a5..01f8f1f802fd 100644
--- a/drivers/media/dvb/frontends/stv0900_core.c
+++ b/drivers/media/dvb/frontends/stv0900_core.c
@@ -177,7 +177,7 @@ u8 stv0900_read_reg(struct stv0900_internal *intp, u16 reg)
177 return buf; 177 return buf;
178} 178}
179 179
180void extract_mask_pos(u32 label, u8 *mask, u8 *pos) 180static void extract_mask_pos(u32 label, u8 *mask, u8 *pos)
181{ 181{
182 u8 position = 0, i = 0; 182 u8 position = 0, i = 0;
183 183
@@ -218,7 +218,7 @@ u8 stv0900_get_bits(struct stv0900_internal *intp, u32 label)
218 return val; 218 return val;
219} 219}
220 220
221enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *intp) 221static enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *intp)
222{ 222{
223 s32 i; 223 s32 i;
224 224
@@ -282,7 +282,7 @@ enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *intp)
282 return STV0900_NO_ERROR; 282 return STV0900_NO_ERROR;
283} 283}
284 284
285u32 stv0900_get_mclk_freq(struct stv0900_internal *intp, u32 ext_clk) 285static u32 stv0900_get_mclk_freq(struct stv0900_internal *intp, u32 ext_clk)
286{ 286{
287 u32 mclk = 90000000, div = 0, ad_div = 0; 287 u32 mclk = 90000000, div = 0, ad_div = 0;
288 288
@@ -296,7 +296,7 @@ u32 stv0900_get_mclk_freq(struct stv0900_internal *intp, u32 ext_clk)
296 return mclk; 296 return mclk;
297} 297}
298 298
299enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *intp, u32 mclk) 299static enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *intp, u32 mclk)
300{ 300{
301 u32 m_div, clk_sel; 301 u32 m_div, clk_sel;
302 302
@@ -334,7 +334,7 @@ enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *intp, u32 mclk)
334 return STV0900_NO_ERROR; 334 return STV0900_NO_ERROR;
335} 335}
336 336
337u32 stv0900_get_err_count(struct stv0900_internal *intp, int cntr, 337static u32 stv0900_get_err_count(struct stv0900_internal *intp, int cntr,
338 enum fe_stv0900_demod_num demod) 338 enum fe_stv0900_demod_num demod)
339{ 339{
340 u32 lsb, msb, hsb, err_val; 340 u32 lsb, msb, hsb, err_val;
@@ -567,6 +567,46 @@ void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
567 } 567 }
568} 568}
569 569
570u32 stv0900_get_freq_auto(struct stv0900_internal *intp, int demod)
571{
572 u32 freq, round;
573 /* Formulat :
574 Tuner_Frequency(MHz) = Regs / 64
575 Tuner_granularity(MHz) = Regs / 2048
576 real_Tuner_Frequency = Tuner_Frequency(MHz) - Tuner_granularity(MHz)
577 */
578 freq = (stv0900_get_bits(intp, TUN_RFFREQ2) << 10) +
579 (stv0900_get_bits(intp, TUN_RFFREQ1) << 2) +
580 stv0900_get_bits(intp, TUN_RFFREQ0);
581
582 freq = (freq * 1000) / 64;
583
584 round = (stv0900_get_bits(intp, TUN_RFRESTE1) >> 2) +
585 stv0900_get_bits(intp, TUN_RFRESTE0);
586
587 round = (round * 1000) / 2048;
588
589 return freq + round;
590}
591
592void stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency,
593 u32 Bandwidth, int demod)
594{
595 u32 tunerFrequency;
596 /* Formulat:
597 Tuner_frequency_reg= Frequency(MHz)*64
598 */
599 tunerFrequency = (Frequency * 64) / 1000;
600
601 stv0900_write_bits(intp, TUN_RFFREQ2, (tunerFrequency >> 10));
602 stv0900_write_bits(intp, TUN_RFFREQ1, (tunerFrequency >> 2) & 0xff);
603 stv0900_write_bits(intp, TUN_RFFREQ0, (tunerFrequency & 0x03));
604 /* Low Pass Filter = BW /2 (MHz)*/
605 stv0900_write_bits(intp, TUN_BW, Bandwidth / 2000000);
606 /* Tuner Write trig */
607 stv0900_write_reg(intp, TNRLD, 1);
608}
609
570static s32 stv0900_get_rf_level(struct stv0900_internal *intp, 610static s32 stv0900_get_rf_level(struct stv0900_internal *intp,
571 const struct stv0900_table *lookup, 611 const struct stv0900_table *lookup,
572 enum fe_stv0900_demod_num demod) 612 enum fe_stv0900_demod_num demod)
@@ -1329,7 +1369,6 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe,
1329 enum fe_stv0900_error error = STV0900_NO_ERROR; 1369 enum fe_stv0900_error error = STV0900_NO_ERROR;
1330 enum fe_stv0900_error demodError = STV0900_NO_ERROR; 1370 enum fe_stv0900_error demodError = STV0900_NO_ERROR;
1331 struct stv0900_internal *intp = NULL; 1371 struct stv0900_internal *intp = NULL;
1332
1333 int selosci, i; 1372 int selosci, i;
1334 1373
1335 struct stv0900_inode *temp_int = find_inode(state->i2c_adap, 1374 struct stv0900_inode *temp_int = find_inode(state->i2c_adap,
@@ -1345,7 +1384,14 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe,
1345 } else { 1384 } else {
1346 state->internal = kmalloc(sizeof(struct stv0900_internal), 1385 state->internal = kmalloc(sizeof(struct stv0900_internal),
1347 GFP_KERNEL); 1386 GFP_KERNEL);
1387 if (state->internal == NULL)
1388 return STV0900_INVALID_HANDLE;
1348 temp_int = append_internal(state->internal); 1389 temp_int = append_internal(state->internal);
1390 if (temp_int == NULL) {
1391 kfree(state->internal);
1392 state->internal = NULL;
1393 return STV0900_INVALID_HANDLE;
1394 }
1349 state->internal->dmds_used = 1; 1395 state->internal->dmds_used = 1;
1350 state->internal->i2c_adap = state->i2c_adap; 1396 state->internal->i2c_adap = state->i2c_adap;
1351 state->internal->i2c_addr = state->config->demod_address; 1397 state->internal->i2c_addr = state->config->demod_address;
@@ -1371,11 +1417,6 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe,
1371 return error; 1417 return error;
1372 } 1418 }
1373 1419
1374 if (state->internal == NULL) {
1375 error = STV0900_INVALID_HANDLE;
1376 return error;
1377 }
1378
1379 intp = state->internal; 1420 intp = state->internal;
1380 1421
1381 intp->demod_mode = p_init->demod_mode; 1422 intp->demod_mode = p_init->demod_mode;
@@ -1404,6 +1445,27 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe,
1404 stv0900_write_bits(intp, F0900_P1_RST_HWARE, 0); 1445 stv0900_write_bits(intp, F0900_P1_RST_HWARE, 0);
1405 } 1446 }
1406 1447
1448 intp->tuner_type[0] = p_init->tuner1_type;
1449 intp->tuner_type[1] = p_init->tuner2_type;
1450 /* tuner init */
1451 switch (p_init->tuner1_type) {
1452 case 3: /*FE_AUTO_STB6100:*/
1453 stv0900_write_reg(intp, R0900_P1_TNRCFG, 0x3c);
1454 stv0900_write_reg(intp, R0900_P1_TNRCFG2, 0x86);
1455 stv0900_write_reg(intp, R0900_P1_TNRCFG3, 0x18);
1456 stv0900_write_reg(intp, R0900_P1_TNRXTAL, 27); /* 27MHz */
1457 stv0900_write_reg(intp, R0900_P1_TNRSTEPS, 0x05);
1458 stv0900_write_reg(intp, R0900_P1_TNRGAIN, 0x17);
1459 stv0900_write_reg(intp, R0900_P1_TNRADJ, 0x1f);
1460 stv0900_write_reg(intp, R0900_P1_TNRCTL2, 0x0);
1461 stv0900_write_bits(intp, F0900_P1_TUN_TYPE, 3);
1462 break;
1463 /* case FE_SW_TUNER: */
1464 default:
1465 stv0900_write_bits(intp, F0900_P1_TUN_TYPE, 6);
1466 break;
1467 }
1468
1407 stv0900_write_bits(intp, F0900_P1_TUN_MADDRESS, p_init->tun1_maddress); 1469 stv0900_write_bits(intp, F0900_P1_TUN_MADDRESS, p_init->tun1_maddress);
1408 switch (p_init->tuner1_adc) { 1470 switch (p_init->tuner1_adc) {
1409 case 1: 1471 case 1:
@@ -1413,6 +1475,27 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe,
1413 break; 1475 break;
1414 } 1476 }
1415 1477
1478 stv0900_write_reg(intp, R0900_P1_TNRLD, 1); /* hw tuner */
1479
1480 /* tuner init */
1481 switch (p_init->tuner2_type) {
1482 case 3: /*FE_AUTO_STB6100:*/
1483 stv0900_write_reg(intp, R0900_P2_TNRCFG, 0x3c);
1484 stv0900_write_reg(intp, R0900_P2_TNRCFG2, 0x86);
1485 stv0900_write_reg(intp, R0900_P2_TNRCFG3, 0x18);
1486 stv0900_write_reg(intp, R0900_P2_TNRXTAL, 27); /* 27MHz */
1487 stv0900_write_reg(intp, R0900_P2_TNRSTEPS, 0x05);
1488 stv0900_write_reg(intp, R0900_P2_TNRGAIN, 0x17);
1489 stv0900_write_reg(intp, R0900_P2_TNRADJ, 0x1f);
1490 stv0900_write_reg(intp, R0900_P2_TNRCTL2, 0x0);
1491 stv0900_write_bits(intp, F0900_P2_TUN_TYPE, 3);
1492 break;
1493 /* case FE_SW_TUNER: */
1494 default:
1495 stv0900_write_bits(intp, F0900_P2_TUN_TYPE, 6);
1496 break;
1497 }
1498
1416 stv0900_write_bits(intp, F0900_P2_TUN_MADDRESS, p_init->tun2_maddress); 1499 stv0900_write_bits(intp, F0900_P2_TUN_MADDRESS, p_init->tun2_maddress);
1417 switch (p_init->tuner2_adc) { 1500 switch (p_init->tuner2_adc) {
1418 case 1: 1501 case 1:
@@ -1422,6 +1505,8 @@ static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe,
1422 break; 1505 break;
1423 } 1506 }
1424 1507
1508 stv0900_write_reg(intp, R0900_P2_TNRLD, 1); /* hw tuner */
1509
1425 stv0900_write_bits(intp, F0900_P1_TUN_IQSWAP, p_init->tun1_iq_inv); 1510 stv0900_write_bits(intp, F0900_P1_TUN_IQSWAP, p_init->tun1_iq_inv);
1426 stv0900_write_bits(intp, F0900_P2_TUN_IQSWAP, p_init->tun2_iq_inv); 1511 stv0900_write_bits(intp, F0900_P2_TUN_IQSWAP, p_init->tun2_iq_inv);
1427 stv0900_set_mclk(intp, 135000000); 1512 stv0900_set_mclk(intp, 135000000);
@@ -1824,10 +1909,12 @@ struct dvb_frontend *stv0900_attach(const struct stv0900_config *config,
1824 init_params.tun1_maddress = config->tun1_maddress; 1909 init_params.tun1_maddress = config->tun1_maddress;
1825 init_params.tun1_iq_inv = STV0900_IQ_NORMAL; 1910 init_params.tun1_iq_inv = STV0900_IQ_NORMAL;
1826 init_params.tuner1_adc = config->tun1_adc; 1911 init_params.tuner1_adc = config->tun1_adc;
1912 init_params.tuner1_type = config->tun1_type;
1827 init_params.path2_ts_clock = config->path2_mode; 1913 init_params.path2_ts_clock = config->path2_mode;
1828 init_params.ts_config = config->ts_config_regs; 1914 init_params.ts_config = config->ts_config_regs;
1829 init_params.tun2_maddress = config->tun2_maddress; 1915 init_params.tun2_maddress = config->tun2_maddress;
1830 init_params.tuner2_adc = config->tun2_adc; 1916 init_params.tuner2_adc = config->tun2_adc;
1917 init_params.tuner2_type = config->tun2_type;
1831 init_params.tun2_iq_inv = STV0900_IQ_SWAPPED; 1918 init_params.tun2_iq_inv = STV0900_IQ_SWAPPED;
1832 1919
1833 err_stv0900 = stv0900_init_internal(&state->frontend, 1920 err_stv0900 = stv0900_init_internal(&state->frontend,
diff --git a/drivers/media/dvb/frontends/stv0900_priv.h b/drivers/media/dvb/frontends/stv0900_priv.h
index d8ba8a984abe..b62b0f0a4fef 100644
--- a/drivers/media/dvb/frontends/stv0900_priv.h
+++ b/drivers/media/dvb/frontends/stv0900_priv.h
@@ -247,6 +247,7 @@ struct stv0900_init_params{
247 247
248 u8 tun1_maddress; 248 u8 tun1_maddress;
249 int tuner1_adc; 249 int tuner1_adc;
250 int tuner1_type;
250 251
251 /* IQ from the tuner1 to the demod */ 252 /* IQ from the tuner1 to the demod */
252 enum stv0900_iq_inversion tun1_iq_inv; 253 enum stv0900_iq_inversion tun1_iq_inv;
@@ -254,6 +255,7 @@ struct stv0900_init_params{
254 255
255 u8 tun2_maddress; 256 u8 tun2_maddress;
256 int tuner2_adc; 257 int tuner2_adc;
258 int tuner2_type;
257 259
258 /* IQ from the tuner2 to the demod */ 260 /* IQ from the tuner2 to the demod */
259 enum stv0900_iq_inversion tun2_iq_inv; 261 enum stv0900_iq_inversion tun2_iq_inv;
@@ -309,6 +311,8 @@ struct stv0900_internal{
309 s32 bw[2]; 311 s32 bw[2];
310 s32 symbol_rate[2]; 312 s32 symbol_rate[2];
311 s32 srch_range[2]; 313 s32 srch_range[2];
314 /* for software/auto tuner */
315 int tuner_type[2];
312 316
313 /* algorithm for search Blind, Cold or Warm*/ 317 /* algorithm for search Blind, Cold or Warm*/
314 enum fe_stv0900_search_algo srch_algo[2]; 318 enum fe_stv0900_search_algo srch_algo[2];
@@ -394,4 +398,11 @@ extern enum
394fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe, 398fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe,
395 enum fe_stv0900_demod_num demod); 399 enum fe_stv0900_demod_num demod);
396 400
401extern u32
402stv0900_get_freq_auto(struct stv0900_internal *intp, int demod);
403
404extern void
405stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency,
406 u32 Bandwidth, int demod);
407
397#endif 408#endif
diff --git a/drivers/media/dvb/frontends/stv0900_reg.h b/drivers/media/dvb/frontends/stv0900_reg.h
index 7b8edf192e97..731afe93a823 100644
--- a/drivers/media/dvb/frontends/stv0900_reg.h
+++ b/drivers/media/dvb/frontends/stv0900_reg.h
@@ -3174,17 +3174,21 @@ extern s32 shiftx(s32 x, int demod, s32 shift);
3174#define R0900_P1_TNRRF1 0xf4e9 3174#define R0900_P1_TNRRF1 0xf4e9
3175#define TNRRF1 REGx(R0900_P1_TNRRF1) 3175#define TNRRF1 REGx(R0900_P1_TNRRF1)
3176#define F0900_P1_TUN_RFFREQ2 0xf4e900ff 3176#define F0900_P1_TUN_RFFREQ2 0xf4e900ff
3177#define TUN_RFFREQ2 FLDx(F0900_P1_TUN_RFFREQ2)
3177 3178
3178/*P1_TNRRF0*/ 3179/*P1_TNRRF0*/
3179#define R0900_P1_TNRRF0 0xf4ea 3180#define R0900_P1_TNRRF0 0xf4ea
3180#define TNRRF0 REGx(R0900_P1_TNRRF0) 3181#define TNRRF0 REGx(R0900_P1_TNRRF0)
3181#define F0900_P1_TUN_RFFREQ1 0xf4ea00ff 3182#define F0900_P1_TUN_RFFREQ1 0xf4ea00ff
3183#define TUN_RFFREQ1 FLDx(F0900_P1_TUN_RFFREQ1)
3182 3184
3183/*P1_TNRBW*/ 3185/*P1_TNRBW*/
3184#define R0900_P1_TNRBW 0xf4eb 3186#define R0900_P1_TNRBW 0xf4eb
3185#define TNRBW REGx(R0900_P1_TNRBW) 3187#define TNRBW REGx(R0900_P1_TNRBW)
3186#define F0900_P1_TUN_RFFREQ0 0xf4eb00c0 3188#define F0900_P1_TUN_RFFREQ0 0xf4eb00c0
3189#define TUN_RFFREQ0 FLDx(F0900_P1_TUN_RFFREQ0)
3187#define F0900_P1_TUN_BW 0xf4eb003f 3190#define F0900_P1_TUN_BW 0xf4eb003f
3191#define TUN_BW FLDx(F0900_P1_TUN_BW)
3188 3192
3189/*P1_TNRADJ*/ 3193/*P1_TNRADJ*/
3190#define R0900_P1_TNRADJ 0xf4ec 3194#define R0900_P1_TNRADJ 0xf4ec
@@ -3234,11 +3238,13 @@ extern s32 shiftx(s32 x, int demod, s32 shift);
3234#define F0900_P1_TUN_I2CLOCKED 0xf4f60010 3238#define F0900_P1_TUN_I2CLOCKED 0xf4f60010
3235#define F0900_P1_TUN_PROGDONE 0xf4f6000c 3239#define F0900_P1_TUN_PROGDONE 0xf4f6000c
3236#define F0900_P1_TUN_RFRESTE1 0xf4f60003 3240#define F0900_P1_TUN_RFRESTE1 0xf4f60003
3241#define TUN_RFRESTE1 FLDx(F0900_P1_TUN_RFRESTE1)
3237 3242
3238/*P1_TNRRESTE*/ 3243/*P1_TNRRESTE*/
3239#define R0900_P1_TNRRESTE 0xf4f7 3244#define R0900_P1_TNRRESTE 0xf4f7
3240#define TNRRESTE REGx(R0900_P1_TNRRESTE) 3245#define TNRRESTE REGx(R0900_P1_TNRRESTE)
3241#define F0900_P1_TUN_RFRESTE0 0xf4f700ff 3246#define F0900_P1_TUN_RFRESTE0 0xf4f700ff
3247#define TUN_RFRESTE0 FLDx(F0900_P1_TUN_RFRESTE0)
3242 3248
3243/*P1_SMAPCOEF7*/ 3249/*P1_SMAPCOEF7*/
3244#define R0900_P1_SMAPCOEF7 0xf500 3250#define R0900_P1_SMAPCOEF7 0xf500
diff --git a/drivers/media/dvb/frontends/stv0900_sw.c b/drivers/media/dvb/frontends/stv0900_sw.c
index b8da87fa637f..ba0709b2d433 100644
--- a/drivers/media/dvb/frontends/stv0900_sw.c
+++ b/drivers/media/dvb/frontends/stv0900_sw.c
@@ -193,7 +193,7 @@ static int stv0900_search_carr_sw_loop(struct stv0900_internal *intp,
193 return lock; 193 return lock;
194} 194}
195 195
196int stv0900_sw_algo(struct stv0900_internal *intp, 196static int stv0900_sw_algo(struct stv0900_internal *intp,
197 enum fe_stv0900_demod_num demod) 197 enum fe_stv0900_demod_num demod)
198{ 198{
199 int lock = FALSE, 199 int lock = FALSE,
@@ -606,7 +606,12 @@ static int stv0900_get_demod_cold_lock(struct dvb_frontend *fe,
606 tuner_freq -= (current_step * currier_step); 606 tuner_freq -= (current_step * currier_step);
607 607
608 if (intp->chip_id <= 0x20) { 608 if (intp->chip_id <= 0x20) {
609 stv0900_set_tuner(fe, tuner_freq, intp->bw[d]); 609 if (intp->tuner_type[d] == 3)
610 stv0900_set_tuner_auto(intp, tuner_freq,
611 intp->bw[d], demod);
612 else
613 stv0900_set_tuner(fe, tuner_freq, intp->bw[d]);
614
610 stv0900_write_reg(intp, DMDISTATE, 0x1c); 615 stv0900_write_reg(intp, DMDISTATE, 0x1c);
611 stv0900_write_reg(intp, CFRINIT1, 0); 616 stv0900_write_reg(intp, CFRINIT1, 0);
612 stv0900_write_reg(intp, CFRINIT0, 0); 617 stv0900_write_reg(intp, CFRINIT0, 0);
@@ -790,7 +795,7 @@ static enum fe_stv0900_fec stv0900_get_vit_fec(struct stv0900_internal *intp,
790 return prate; 795 return prate;
791} 796}
792 797
793void stv0900_set_dvbs1_track_car_loop(struct stv0900_internal *intp, 798static void stv0900_set_dvbs1_track_car_loop(struct stv0900_internal *intp,
794 enum fe_stv0900_demod_num demod, 799 enum fe_stv0900_demod_num demod,
795 u32 srate) 800 u32 srate)
796{ 801{
@@ -976,8 +981,16 @@ static void stv0900_track_optimization(struct dvb_frontend *fe)
976 intp->rolloff) + 10000000; 981 intp->rolloff) + 10000000;
977 982
978 if ((intp->chip_id >= 0x20) || (blind_tun_sw == 1)) { 983 if ((intp->chip_id >= 0x20) || (blind_tun_sw == 1)) {
979 if (intp->srch_algo[demod] != STV0900_WARM_START) 984 if (intp->srch_algo[demod] != STV0900_WARM_START) {
980 stv0900_set_bandwidth(fe, intp->bw[demod]); 985 if (intp->tuner_type[demod] == 3)
986 stv0900_set_tuner_auto(intp,
987 intp->freq[demod],
988 intp->bw[demod],
989 demod);
990 else
991 stv0900_set_bandwidth(fe,
992 intp->bw[demod]);
993 }
981 } 994 }
982 995
983 if ((intp->srch_algo[demod] == STV0900_BLIND_SEARCH) || 996 if ((intp->srch_algo[demod] == STV0900_BLIND_SEARCH) ||
@@ -1202,7 +1215,11 @@ fe_stv0900_signal_type stv0900_get_signal_params(struct dvb_frontend *fe)
1202 } 1215 }
1203 1216
1204 result->standard = stv0900_get_standard(fe, d); 1217 result->standard = stv0900_get_standard(fe, d);
1205 result->frequency = stv0900_get_tuner_freq(fe); 1218 if (intp->tuner_type[demod] == 3)
1219 result->frequency = stv0900_get_freq_auto(intp, d);
1220 else
1221 result->frequency = stv0900_get_tuner_freq(fe);
1222
1206 offsetFreq = stv0900_get_carr_freq(intp, intp->mclk, d) / 1000; 1223 offsetFreq = stv0900_get_carr_freq(intp, intp->mclk, d) / 1000;
1207 result->frequency += offsetFreq; 1224 result->frequency += offsetFreq;
1208 result->symbol_rate = stv0900_get_symbol_rate(intp, intp->mclk, d); 1225 result->symbol_rate = stv0900_get_symbol_rate(intp, intp->mclk, d);
@@ -1213,6 +1230,9 @@ fe_stv0900_signal_type stv0900_get_signal_params(struct dvb_frontend *fe)
1213 result->pilot = stv0900_get_bits(intp, DEMOD_TYPE) & 0x01; 1230 result->pilot = stv0900_get_bits(intp, DEMOD_TYPE) & 0x01;
1214 result->frame_len = ((u32)stv0900_get_bits(intp, DEMOD_TYPE)) >> 1; 1231 result->frame_len = ((u32)stv0900_get_bits(intp, DEMOD_TYPE)) >> 1;
1215 result->rolloff = stv0900_get_bits(intp, ROLLOFF_STATUS); 1232 result->rolloff = stv0900_get_bits(intp, ROLLOFF_STATUS);
1233
1234 dprintk("%s: modcode=0x%x \n", __func__, result->modcode);
1235
1216 switch (result->standard) { 1236 switch (result->standard) {
1217 case STV0900_DVBS2_STANDARD: 1237 case STV0900_DVBS2_STANDARD:
1218 result->spectrum = stv0900_get_bits(intp, SPECINV_DEMOD); 1238 result->spectrum = stv0900_get_bits(intp, SPECINV_DEMOD);
@@ -1239,7 +1259,11 @@ fe_stv0900_signal_type stv0900_get_signal_params(struct dvb_frontend *fe)
1239 if ((intp->srch_algo[d] == STV0900_BLIND_SEARCH) || 1259 if ((intp->srch_algo[d] == STV0900_BLIND_SEARCH) ||
1240 (intp->symbol_rate[d] < 10000000)) { 1260 (intp->symbol_rate[d] < 10000000)) {
1241 offsetFreq = result->frequency - intp->freq[d]; 1261 offsetFreq = result->frequency - intp->freq[d];
1242 intp->freq[d] = stv0900_get_tuner_freq(fe); 1262 if (intp->tuner_type[demod] == 3)
1263 intp->freq[d] = stv0900_get_freq_auto(intp, d);
1264 else
1265 intp->freq[d] = stv0900_get_tuner_freq(fe);
1266
1243 if (ABS(offsetFreq) <= ((intp->srch_range[d] / 2000) + 500)) 1267 if (ABS(offsetFreq) <= ((intp->srch_range[d] / 2000) + 500))
1244 range = STV0900_RANGEOK; 1268 range = STV0900_RANGEOK;
1245 else if (ABS(offsetFreq) <= 1269 else if (ABS(offsetFreq) <=
@@ -1481,7 +1505,12 @@ static u32 stv0900_search_srate_coarse(struct dvb_frontend *fe)
1481 else 1505 else
1482 tuner_freq -= (current_step * currier_step); 1506 tuner_freq -= (current_step * currier_step);
1483 1507
1484 stv0900_set_tuner(fe, tuner_freq, intp->bw[demod]); 1508 if (intp->tuner_type[demod] == 3)
1509 stv0900_set_tuner_auto(intp, tuner_freq,
1510 intp->bw[demod], demod);
1511 else
1512 stv0900_set_tuner(fe, tuner_freq,
1513 intp->bw[demod]);
1485 } 1514 }
1486 } 1515 }
1487 1516
@@ -1608,7 +1637,8 @@ static int stv0900_blind_search_algo(struct dvb_frontend *fe)
1608 1637
1609 agc2_int = stv0900_blind_check_agc2_min_level(intp, demod); 1638 agc2_int = stv0900_blind_check_agc2_min_level(intp, demod);
1610 1639
1611 if (agc2_int > STV0900_BLIND_SEARCH_AGC2_TH) 1640 dprintk("%s agc2_int=%d agc2_th=%d \n", __func__, agc2_int, agc2_th);
1641 if (agc2_int > agc2_th)
1612 return FALSE; 1642 return FALSE;
1613 1643
1614 if (intp->chip_id == 0x10) 1644 if (intp->chip_id == 0x10)
@@ -1875,7 +1905,11 @@ enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe)
1875 1905
1876 } 1906 }
1877 1907
1878 stv0900_set_tuner(fe, intp->freq[demod], intp->bw[demod]); 1908 if (intp->tuner_type[demod] == 3)
1909 stv0900_set_tuner_auto(intp, intp->freq[demod],
1910 intp->bw[demod], demod);
1911 else
1912 stv0900_set_tuner(fe, intp->freq[demod], intp->bw[demod]);
1879 1913
1880 agc1_power = MAKEWORD(stv0900_get_bits(intp, AGCIQ_VALUE1), 1914 agc1_power = MAKEWORD(stv0900_get_bits(intp, AGCIQ_VALUE1),
1881 stv0900_get_bits(intp, AGCIQ_VALUE0)); 1915 stv0900_get_bits(intp, AGCIQ_VALUE0));
diff --git a/drivers/media/dvb/frontends/stv090x.c b/drivers/media/dvb/frontends/stv090x.c
index 1573466a5c74..c52c3357dc54 100644
--- a/drivers/media/dvb/frontends/stv090x.c
+++ b/drivers/media/dvb/frontends/stv090x.c
@@ -37,7 +37,82 @@
37static unsigned int verbose; 37static unsigned int verbose;
38module_param(verbose, int, 0644); 38module_param(verbose, int, 0644);
39 39
40struct mutex demod_lock; 40/* internal params node */
41struct stv090x_dev {
42 /* pointer for internal params, one for each pair of demods */
43 struct stv090x_internal *internal;
44 struct stv090x_dev *next_dev;
45};
46
47/* first internal params */
48static struct stv090x_dev *stv090x_first_dev;
49
50/* find chip by i2c adapter and i2c address */
51static struct stv090x_dev *find_dev(struct i2c_adapter *i2c_adap,
52 u8 i2c_addr)
53{
54 struct stv090x_dev *temp_dev = stv090x_first_dev;
55
56 /*
57 Search of the last stv0900 chip or
58 find it by i2c adapter and i2c address */
59 while ((temp_dev != NULL) &&
60 ((temp_dev->internal->i2c_adap != i2c_adap) ||
61 (temp_dev->internal->i2c_addr != i2c_addr))) {
62
63 temp_dev = temp_dev->next_dev;
64 }
65
66 return temp_dev;
67}
68
69/* deallocating chip */
70static void remove_dev(struct stv090x_internal *internal)
71{
72 struct stv090x_dev *prev_dev = stv090x_first_dev;
73 struct stv090x_dev *del_dev = find_dev(internal->i2c_adap,
74 internal->i2c_addr);
75
76 if (del_dev != NULL) {
77 if (del_dev == stv090x_first_dev) {
78 stv090x_first_dev = del_dev->next_dev;
79 } else {
80 while (prev_dev->next_dev != del_dev)
81 prev_dev = prev_dev->next_dev;
82
83 prev_dev->next_dev = del_dev->next_dev;
84 }
85
86 kfree(del_dev);
87 }
88}
89
90/* allocating new chip */
91static struct stv090x_dev *append_internal(struct stv090x_internal *internal)
92{
93 struct stv090x_dev *new_dev;
94 struct stv090x_dev *temp_dev;
95
96 new_dev = kmalloc(sizeof(struct stv090x_dev), GFP_KERNEL);
97 if (new_dev != NULL) {
98 new_dev->internal = internal;
99 new_dev->next_dev = NULL;
100
101 /* append to list */
102 if (stv090x_first_dev == NULL) {
103 stv090x_first_dev = new_dev;
104 } else {
105 temp_dev = stv090x_first_dev;
106 while (temp_dev->next_dev != NULL)
107 temp_dev = temp_dev->next_dev;
108
109 temp_dev->next_dev = new_dev;
110 }
111 }
112
113 return new_dev;
114}
115
41 116
42/* DVBS1 and DSS C/N Lookup table */ 117/* DVBS1 and DSS C/N Lookup table */
43static const struct stv090x_tab stv090x_s1cn_tab[] = { 118static const struct stv090x_tab stv090x_s1cn_tab[] = {
@@ -683,6 +758,9 @@ static int stv090x_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
683 struct stv090x_state *state = fe->demodulator_priv; 758 struct stv090x_state *state = fe->demodulator_priv;
684 u32 reg; 759 u32 reg;
685 760
761 if (enable)
762 mutex_lock(&state->internal->tuner_lock);
763
686 reg = STV090x_READ_DEMOD(state, I2CRPT); 764 reg = STV090x_READ_DEMOD(state, I2CRPT);
687 if (enable) { 765 if (enable) {
688 dprintk(FE_DEBUG, 1, "Enable Gate"); 766 dprintk(FE_DEBUG, 1, "Enable Gate");
@@ -696,9 +774,14 @@ static int stv090x_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
696 if ((STV090x_WRITE_DEMOD(state, I2CRPT, reg)) < 0) 774 if ((STV090x_WRITE_DEMOD(state, I2CRPT, reg)) < 0)
697 goto err; 775 goto err;
698 } 776 }
777
778 if (!enable)
779 mutex_unlock(&state->internal->tuner_lock);
780
699 return 0; 781 return 0;
700err: 782err:
701 dprintk(FE_ERROR, 1, "I/O error"); 783 dprintk(FE_ERROR, 1, "I/O error");
784 mutex_unlock(&state->internal->tuner_lock);
702 return -1; 785 return -1;
703} 786}
704 787
@@ -755,13 +838,13 @@ static int stv090x_set_srate(struct stv090x_state *state, u32 srate)
755 838
756 if (srate > 60000000) { 839 if (srate > 60000000) {
757 sym = (srate << 4); /* SR * 2^16 / master_clk */ 840 sym = (srate << 4); /* SR * 2^16 / master_clk */
758 sym /= (state->mclk >> 12); 841 sym /= (state->internal->mclk >> 12);
759 } else if (srate > 6000000) { 842 } else if (srate > 6000000) {
760 sym = (srate << 6); 843 sym = (srate << 6);
761 sym /= (state->mclk >> 10); 844 sym /= (state->internal->mclk >> 10);
762 } else { 845 } else {
763 sym = (srate << 9); 846 sym = (srate << 9);
764 sym /= (state->mclk >> 7); 847 sym /= (state->internal->mclk >> 7);
765 } 848 }
766 849
767 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0x7f) < 0) /* MSB */ 850 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0x7f) < 0) /* MSB */
@@ -782,13 +865,13 @@ static int stv090x_set_max_srate(struct stv090x_state *state, u32 clk, u32 srate
782 srate = 105 * (srate / 100); 865 srate = 105 * (srate / 100);
783 if (srate > 60000000) { 866 if (srate > 60000000) {
784 sym = (srate << 4); /* SR * 2^16 / master_clk */ 867 sym = (srate << 4); /* SR * 2^16 / master_clk */
785 sym /= (state->mclk >> 12); 868 sym /= (state->internal->mclk >> 12);
786 } else if (srate > 6000000) { 869 } else if (srate > 6000000) {
787 sym = (srate << 6); 870 sym = (srate << 6);
788 sym /= (state->mclk >> 10); 871 sym /= (state->internal->mclk >> 10);
789 } else { 872 } else {
790 sym = (srate << 9); 873 sym = (srate << 9);
791 sym /= (state->mclk >> 7); 874 sym /= (state->internal->mclk >> 7);
792 } 875 }
793 876
794 if (sym < 0x7fff) { 877 if (sym < 0x7fff) {
@@ -816,13 +899,13 @@ static int stv090x_set_min_srate(struct stv090x_state *state, u32 clk, u32 srate
816 srate = 95 * (srate / 100); 899 srate = 95 * (srate / 100);
817 if (srate > 60000000) { 900 if (srate > 60000000) {
818 sym = (srate << 4); /* SR * 2^16 / master_clk */ 901 sym = (srate << 4); /* SR * 2^16 / master_clk */
819 sym /= (state->mclk >> 12); 902 sym /= (state->internal->mclk >> 12);
820 } else if (srate > 6000000) { 903 } else if (srate > 6000000) {
821 sym = (srate << 6); 904 sym = (srate << 6);
822 sym /= (state->mclk >> 10); 905 sym /= (state->internal->mclk >> 10);
823 } else { 906 } else {
824 sym = (srate << 9); 907 sym = (srate << 9);
825 sym /= (state->mclk >> 7); 908 sym /= (state->internal->mclk >> 7);
826 } 909 }
827 910
828 if (STV090x_WRITE_DEMOD(state, SFRLOW1, ((sym >> 8) & 0x7f)) < 0) /* MSB */ 911 if (STV090x_WRITE_DEMOD(state, SFRLOW1, ((sym >> 8) & 0x7f)) < 0) /* MSB */
@@ -1103,21 +1186,21 @@ static int stv090x_vitclk_ctl(struct stv090x_state *state, int enable)
1103 1186
1104 switch (state->demod) { 1187 switch (state->demod) {
1105 case STV090x_DEMODULATOR_0: 1188 case STV090x_DEMODULATOR_0:
1106 mutex_lock(&demod_lock); 1189 mutex_lock(&state->internal->demod_lock);
1107 reg = stv090x_read_reg(state, STV090x_STOPCLK2); 1190 reg = stv090x_read_reg(state, STV090x_STOPCLK2);
1108 STV090x_SETFIELD(reg, STOP_CLKVIT1_FIELD, enable); 1191 STV090x_SETFIELD(reg, STOP_CLKVIT1_FIELD, enable);
1109 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) 1192 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0)
1110 goto err; 1193 goto err;
1111 mutex_unlock(&demod_lock); 1194 mutex_unlock(&state->internal->demod_lock);
1112 break; 1195 break;
1113 1196
1114 case STV090x_DEMODULATOR_1: 1197 case STV090x_DEMODULATOR_1:
1115 mutex_lock(&demod_lock); 1198 mutex_lock(&state->internal->demod_lock);
1116 reg = stv090x_read_reg(state, STV090x_STOPCLK2); 1199 reg = stv090x_read_reg(state, STV090x_STOPCLK2);
1117 STV090x_SETFIELD(reg, STOP_CLKVIT2_FIELD, enable); 1200 STV090x_SETFIELD(reg, STOP_CLKVIT2_FIELD, enable);
1118 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0) 1201 if (stv090x_write_reg(state, STV090x_STOPCLK2, reg) < 0)
1119 goto err; 1202 goto err;
1120 mutex_unlock(&demod_lock); 1203 mutex_unlock(&state->internal->demod_lock);
1121 break; 1204 break;
1122 1205
1123 default: 1206 default:
@@ -1126,14 +1209,14 @@ static int stv090x_vitclk_ctl(struct stv090x_state *state, int enable)
1126 } 1209 }
1127 return 0; 1210 return 0;
1128err: 1211err:
1129 mutex_unlock(&demod_lock); 1212 mutex_unlock(&state->internal->demod_lock);
1130 dprintk(FE_ERROR, 1, "I/O error"); 1213 dprintk(FE_ERROR, 1, "I/O error");
1131 return -1; 1214 return -1;
1132} 1215}
1133 1216
1134static int stv090x_dvbs_track_crl(struct stv090x_state *state) 1217static int stv090x_dvbs_track_crl(struct stv090x_state *state)
1135{ 1218{
1136 if (state->dev_ver >= 0x30) { 1219 if (state->internal->dev_ver >= 0x30) {
1137 /* Set ACLC BCLC optimised value vs SR */ 1220 /* Set ACLC BCLC optimised value vs SR */
1138 if (state->srate >= 15000000) { 1221 if (state->srate >= 15000000) {
1139 if (STV090x_WRITE_DEMOD(state, ACLC, 0x2b) < 0) 1222 if (STV090x_WRITE_DEMOD(state, ACLC, 0x2b) < 0)
@@ -1215,7 +1298,7 @@ static int stv090x_delivery_search(struct stv090x_state *state)
1215 if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0) 1298 if (STV090x_WRITE_DEMOD(state, BCLC, 0x09) < 0)
1216 goto err; 1299 goto err;
1217 1300
1218 if (state->dev_ver <= 0x20) { 1301 if (state->internal->dev_ver <= 0x20) {
1219 /* enable S2 carrier loop */ 1302 /* enable S2 carrier loop */
1220 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) 1303 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0)
1221 goto err; 1304 goto err;
@@ -1246,6 +1329,10 @@ static int stv090x_delivery_search(struct stv090x_state *state)
1246 default: 1329 default:
1247 /* enable DVB-S2 and DVB-S2 in Auto MODE */ 1330 /* enable DVB-S2 and DVB-S2 in Auto MODE */
1248 reg = STV090x_READ_DEMOD(state, DMDCFGMD); 1331 reg = STV090x_READ_DEMOD(state, DMDCFGMD);
1332 STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 0);
1333 STV090x_SETFIELD_Px(reg, DVBS2_ENABLE_FIELD, 0);
1334 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0)
1335 goto err;
1249 STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 1); 1336 STV090x_SETFIELD_Px(reg, DVBS1_ENABLE_FIELD, 1);
1250 STV090x_SETFIELD_Px(reg, DVBS2_ENABLE_FIELD, 1); 1337 STV090x_SETFIELD_Px(reg, DVBS2_ENABLE_FIELD, 1);
1251 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0) 1338 if (STV090x_WRITE_DEMOD(state, DMDCFGMD, reg) < 0)
@@ -1257,7 +1344,7 @@ static int stv090x_delivery_search(struct stv090x_state *state)
1257 if (stv090x_dvbs_track_crl(state) < 0) 1344 if (stv090x_dvbs_track_crl(state) < 0)
1258 goto err; 1345 goto err;
1259 1346
1260 if (state->dev_ver <= 0x20) { 1347 if (state->internal->dev_ver <= 0x20) {
1261 /* enable S2 carrier loop */ 1348 /* enable S2 carrier loop */
1262 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0) 1349 if (STV090x_WRITE_DEMOD(state, CAR2CFG, 0x26) < 0)
1263 goto err; 1350 goto err;
@@ -1304,7 +1391,7 @@ static int stv090x_start_search(struct stv090x_state *state)
1304 if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0) 1391 if (STV090x_WRITE_DEMOD(state, DMDISTATE, reg) < 0)
1305 goto err; 1392 goto err;
1306 1393
1307 if (state->dev_ver <= 0x20) { 1394 if (state->internal->dev_ver <= 0x20) {
1308 if (state->srate <= 5000000) { 1395 if (state->srate <= 5000000) {
1309 if (STV090x_WRITE_DEMOD(state, CARCFG, 0x44) < 0) 1396 if (STV090x_WRITE_DEMOD(state, CARCFG, 0x44) < 0)
1310 goto err; 1397 goto err;
@@ -1348,7 +1435,7 @@ static int stv090x_start_search(struct stv090x_state *state)
1348 * CFR max = +1MHz 1435 * CFR max = +1MHz
1349 */ 1436 */
1350 freq_abs = 1000 << 16; 1437 freq_abs = 1000 << 16;
1351 freq_abs /= (state->mclk / 1000); 1438 freq_abs /= (state->internal->mclk / 1000);
1352 freq = (s16) freq_abs; 1439 freq = (s16) freq_abs;
1353 } else { 1440 } else {
1354 /* COLD Start 1441 /* COLD Start
@@ -1358,7 +1445,7 @@ static int stv090x_start_search(struct stv090x_state *state)
1358 */ 1445 */
1359 freq_abs = (state->search_range / 2000) + 600; 1446 freq_abs = (state->search_range / 2000) + 600;
1360 freq_abs = freq_abs << 16; 1447 freq_abs = freq_abs << 16;
1361 freq_abs /= (state->mclk / 1000); 1448 freq_abs /= (state->internal->mclk / 1000);
1362 freq = (s16) freq_abs; 1449 freq = (s16) freq_abs;
1363 } 1450 }
1364 1451
@@ -1381,7 +1468,7 @@ static int stv090x_start_search(struct stv090x_state *state)
1381 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0) < 0) 1468 if (STV090x_WRITE_DEMOD(state, CFRINIT0, 0) < 0)
1382 goto err; 1469 goto err;
1383 1470
1384 if (state->dev_ver >= 0x20) { 1471 if (state->internal->dev_ver >= 0x20) {
1385 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) 1472 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0)
1386 goto err; 1473 goto err;
1387 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) 1474 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0)
@@ -1418,10 +1505,10 @@ static int stv090x_start_search(struct stv090x_state *state)
1418 if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0) 1505 if (STV090x_WRITE_DEMOD(state, RTC, 0x88) < 0)
1419 goto err; 1506 goto err;
1420 1507
1421 if (state->dev_ver >= 0x20) { 1508 if (state->internal->dev_ver >= 0x20) {
1422 /*Frequency offset detector setting*/ 1509 /*Frequency offset detector setting*/
1423 if (state->srate < 2000000) { 1510 if (state->srate < 2000000) {
1424 if (state->dev_ver <= 0x20) { 1511 if (state->internal->dev_ver <= 0x20) {
1425 /* Cut 2 */ 1512 /* Cut 2 */
1426 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x39) < 0) 1513 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x39) < 0)
1427 goto err; 1514 goto err;
@@ -1512,7 +1599,7 @@ static int stv090x_get_agc2_min_level(struct stv090x_state *state)
1512 steps = 1; 1599 steps = 1;
1513 1600
1514 dir = 1; 1601 dir = 1;
1515 freq_step = (1000000 * 256) / (state->mclk / 256); 1602 freq_step = (1000000 * 256) / (state->internal->mclk / 256);
1516 freq_init = 0; 1603 freq_init = 0;
1517 1604
1518 for (i = 0; i < steps; i++) { 1605 for (i = 0; i < steps; i++) {
@@ -1583,7 +1670,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1583 u32 srate_coarse = 0, agc2 = 0, car_step = 1200, reg; 1670 u32 srate_coarse = 0, agc2 = 0, car_step = 1200, reg;
1584 u32 agc2th; 1671 u32 agc2th;
1585 1672
1586 if (state->dev_ver >= 0x30) 1673 if (state->internal->dev_ver >= 0x30)
1587 agc2th = 0x2e00; 1674 agc2th = 0x2e00;
1588 else 1675 else
1589 agc2th = 0x1f00; 1676 agc2th = 0x1f00;
@@ -1619,13 +1706,13 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1619 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x50) < 0) 1706 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x50) < 0)
1620 goto err; 1707 goto err;
1621 1708
1622 if (state->dev_ver >= 0x30) { 1709 if (state->internal->dev_ver >= 0x30) {
1623 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x99) < 0) 1710 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x99) < 0)
1624 goto err; 1711 goto err;
1625 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x98) < 0) 1712 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x98) < 0)
1626 goto err; 1713 goto err;
1627 1714
1628 } else if (state->dev_ver >= 0x20) { 1715 } else if (state->internal->dev_ver >= 0x20) {
1629 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x6a) < 0) 1716 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x6a) < 0)
1630 goto err; 1717 goto err;
1631 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x95) < 0) 1718 if (STV090x_WRITE_DEMOD(state, SFRSTEP, 0x95) < 0)
@@ -1677,7 +1764,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1677 STV090x_READ_DEMOD(state, AGC2I0); 1764 STV090x_READ_DEMOD(state, AGC2I0);
1678 } 1765 }
1679 agc2 /= 10; 1766 agc2 /= 10;
1680 srate_coarse = stv090x_get_srate(state, state->mclk); 1767 srate_coarse = stv090x_get_srate(state, state->internal->mclk);
1681 cur_step++; 1768 cur_step++;
1682 dir *= -1; 1769 dir *= -1;
1683 if ((tmg_cpt >= 5) && (agc2 < agc2th) && 1770 if ((tmg_cpt >= 5) && (agc2 < agc2th) &&
@@ -1695,12 +1782,12 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1695 1782
1696 if (state->config->tuner_set_frequency) { 1783 if (state->config->tuner_set_frequency) {
1697 if (state->config->tuner_set_frequency(fe, freq) < 0) 1784 if (state->config->tuner_set_frequency(fe, freq) < 0)
1698 goto err; 1785 goto err_gateoff;
1699 } 1786 }
1700 1787
1701 if (state->config->tuner_set_bandwidth) { 1788 if (state->config->tuner_set_bandwidth) {
1702 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) 1789 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0)
1703 goto err; 1790 goto err_gateoff;
1704 } 1791 }
1705 1792
1706 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 1793 if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
@@ -1713,7 +1800,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1713 1800
1714 if (state->config->tuner_get_status) { 1801 if (state->config->tuner_get_status) {
1715 if (state->config->tuner_get_status(fe, &reg) < 0) 1802 if (state->config->tuner_get_status(fe, &reg) < 0)
1716 goto err; 1803 goto err_gateoff;
1717 } 1804 }
1718 1805
1719 if (reg) 1806 if (reg)
@@ -1729,9 +1816,12 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
1729 if (!tmg_lock) 1816 if (!tmg_lock)
1730 srate_coarse = 0; 1817 srate_coarse = 0;
1731 else 1818 else
1732 srate_coarse = stv090x_get_srate(state, state->mclk); 1819 srate_coarse = stv090x_get_srate(state, state->internal->mclk);
1733 1820
1734 return srate_coarse; 1821 return srate_coarse;
1822
1823err_gateoff:
1824 stv090x_i2c_gate_ctrl(fe, 0);
1735err: 1825err:
1736 dprintk(FE_ERROR, 1, "I/O error"); 1826 dprintk(FE_ERROR, 1, "I/O error");
1737 return -1; 1827 return -1;
@@ -1741,7 +1831,7 @@ static u32 stv090x_srate_srch_fine(struct stv090x_state *state)
1741{ 1831{
1742 u32 srate_coarse, freq_coarse, sym, reg; 1832 u32 srate_coarse, freq_coarse, sym, reg;
1743 1833
1744 srate_coarse = stv090x_get_srate(state, state->mclk); 1834 srate_coarse = stv090x_get_srate(state, state->internal->mclk);
1745 freq_coarse = STV090x_READ_DEMOD(state, CFR2) << 8; 1835 freq_coarse = STV090x_READ_DEMOD(state, CFR2) << 8;
1746 freq_coarse |= STV090x_READ_DEMOD(state, CFR1); 1836 freq_coarse |= STV090x_READ_DEMOD(state, CFR1);
1747 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ 1837 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */
@@ -1767,10 +1857,10 @@ static u32 stv090x_srate_srch_fine(struct stv090x_state *state)
1767 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) 1857 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0)
1768 goto err; 1858 goto err;
1769 1859
1770 if (state->dev_ver >= 0x30) { 1860 if (state->internal->dev_ver >= 0x30) {
1771 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x79) < 0) 1861 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x79) < 0)
1772 goto err; 1862 goto err;
1773 } else if (state->dev_ver >= 0x20) { 1863 } else if (state->internal->dev_ver >= 0x20) {
1774 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) 1864 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0)
1775 goto err; 1865 goto err;
1776 } 1866 }
@@ -1778,20 +1868,20 @@ static u32 stv090x_srate_srch_fine(struct stv090x_state *state)
1778 if (srate_coarse > 3000000) { 1868 if (srate_coarse > 3000000) {
1779 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ 1869 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */
1780 sym = (sym / 1000) * 65536; 1870 sym = (sym / 1000) * 65536;
1781 sym /= (state->mclk / 1000); 1871 sym /= (state->internal->mclk / 1000);
1782 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) 1872 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0)
1783 goto err; 1873 goto err;
1784 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) 1874 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0)
1785 goto err; 1875 goto err;
1786 sym = 10 * (srate_coarse / 13); /* SFRLOW = SFR - 30% */ 1876 sym = 10 * (srate_coarse / 13); /* SFRLOW = SFR - 30% */
1787 sym = (sym / 1000) * 65536; 1877 sym = (sym / 1000) * 65536;
1788 sym /= (state->mclk / 1000); 1878 sym /= (state->internal->mclk / 1000);
1789 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) 1879 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0)
1790 goto err; 1880 goto err;
1791 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) 1881 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0)
1792 goto err; 1882 goto err;
1793 sym = (srate_coarse / 1000) * 65536; 1883 sym = (srate_coarse / 1000) * 65536;
1794 sym /= (state->mclk / 1000); 1884 sym /= (state->internal->mclk / 1000);
1795 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) 1885 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0)
1796 goto err; 1886 goto err;
1797 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) 1887 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0)
@@ -1799,20 +1889,20 @@ static u32 stv090x_srate_srch_fine(struct stv090x_state *state)
1799 } else { 1889 } else {
1800 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */ 1890 sym = 13 * (srate_coarse / 10); /* SFRUP = SFR + 30% */
1801 sym = (sym / 100) * 65536; 1891 sym = (sym / 100) * 65536;
1802 sym /= (state->mclk / 100); 1892 sym /= (state->internal->mclk / 100);
1803 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0) 1893 if (STV090x_WRITE_DEMOD(state, SFRUP1, (sym >> 8) & 0x7f) < 0)
1804 goto err; 1894 goto err;
1805 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0) 1895 if (STV090x_WRITE_DEMOD(state, SFRUP0, sym & 0xff) < 0)
1806 goto err; 1896 goto err;
1807 sym = 10 * (srate_coarse / 14); /* SFRLOW = SFR - 30% */ 1897 sym = 10 * (srate_coarse / 14); /* SFRLOW = SFR - 30% */
1808 sym = (sym / 100) * 65536; 1898 sym = (sym / 100) * 65536;
1809 sym /= (state->mclk / 100); 1899 sym /= (state->internal->mclk / 100);
1810 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0) 1900 if (STV090x_WRITE_DEMOD(state, SFRLOW1, (sym >> 8) & 0x7f) < 0)
1811 goto err; 1901 goto err;
1812 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0) 1902 if (STV090x_WRITE_DEMOD(state, SFRLOW0, sym & 0xff) < 0)
1813 goto err; 1903 goto err;
1814 sym = (srate_coarse / 100) * 65536; 1904 sym = (srate_coarse / 100) * 65536;
1815 sym /= (state->mclk / 100); 1905 sym /= (state->internal->mclk / 100);
1816 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0) 1906 if (STV090x_WRITE_DEMOD(state, SFRINIT1, (sym >> 8) & 0xff) < 0)
1817 goto err; 1907 goto err;
1818 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0) 1908 if (STV090x_WRITE_DEMOD(state, SFRINIT0, sym & 0xff) < 0)
@@ -1874,18 +1964,19 @@ static int stv090x_blind_search(struct stv090x_state *state)
1874 u32 agc2, reg, srate_coarse; 1964 u32 agc2, reg, srate_coarse;
1875 s32 cpt_fail, agc2_ovflw, i; 1965 s32 cpt_fail, agc2_ovflw, i;
1876 u8 k_ref, k_max, k_min; 1966 u8 k_ref, k_max, k_min;
1877 int coarse_fail, lock; 1967 int coarse_fail = 0;
1968 int lock;
1878 1969
1879 k_max = 110; 1970 k_max = 110;
1880 k_min = 10; 1971 k_min = 10;
1881 1972
1882 agc2 = stv090x_get_agc2_min_level(state); 1973 agc2 = stv090x_get_agc2_min_level(state);
1883 1974
1884 if (agc2 > STV090x_SEARCH_AGC2_TH(state->dev_ver)) { 1975 if (agc2 > STV090x_SEARCH_AGC2_TH(state->internal->dev_ver)) {
1885 lock = 0; 1976 lock = 0;
1886 } else { 1977 } else {
1887 1978
1888 if (state->dev_ver <= 0x20) { 1979 if (state->internal->dev_ver <= 0x20) {
1889 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0) 1980 if (STV090x_WRITE_DEMOD(state, CARCFG, 0xc4) < 0)
1890 goto err; 1981 goto err;
1891 } else { 1982 } else {
@@ -1897,7 +1988,7 @@ static int stv090x_blind_search(struct stv090x_state *state)
1897 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0) 1988 if (STV090x_WRITE_DEMOD(state, RTCS2, 0x44) < 0)
1898 goto err; 1989 goto err;
1899 1990
1900 if (state->dev_ver >= 0x20) { 1991 if (state->internal->dev_ver >= 0x20) {
1901 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0) 1992 if (STV090x_WRITE_DEMOD(state, EQUALCFG, 0x41) < 0)
1902 goto err; 1993 goto err;
1903 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0) 1994 if (STV090x_WRITE_DEMOD(state, FFECFG, 0x41) < 0)
@@ -1956,7 +2047,7 @@ static int stv090x_chk_tmg(struct stv090x_state *state)
1956 u32 reg; 2047 u32 reg;
1957 s32 tmg_cpt = 0, i; 2048 s32 tmg_cpt = 0, i;
1958 u8 freq, tmg_thh, tmg_thl; 2049 u8 freq, tmg_thh, tmg_thl;
1959 int tmg_lock; 2050 int tmg_lock = 0;
1960 2051
1961 freq = STV090x_READ_DEMOD(state, CARFREQ); 2052 freq = STV090x_READ_DEMOD(state, CARFREQ);
1962 tmg_thh = STV090x_READ_DEMOD(state, TMGTHRISE); 2053 tmg_thh = STV090x_READ_DEMOD(state, TMGTHRISE);
@@ -2080,12 +2171,12 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
2080 2171
2081 if (state->config->tuner_set_frequency) { 2172 if (state->config->tuner_set_frequency) {
2082 if (state->config->tuner_set_frequency(fe, freq) < 0) 2173 if (state->config->tuner_set_frequency(fe, freq) < 0)
2083 goto err; 2174 goto err_gateoff;
2084 } 2175 }
2085 2176
2086 if (state->config->tuner_set_bandwidth) { 2177 if (state->config->tuner_set_bandwidth) {
2087 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) 2178 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0)
2088 goto err; 2179 goto err_gateoff;
2089 } 2180 }
2090 2181
2091 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 2182 if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
@@ -2098,7 +2189,7 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
2098 2189
2099 if (state->config->tuner_get_status) { 2190 if (state->config->tuner_get_status) {
2100 if (state->config->tuner_get_status(fe, &reg) < 0) 2191 if (state->config->tuner_get_status(fe, &reg) < 0)
2101 goto err; 2192 goto err_gateoff;
2102 } 2193 }
2103 2194
2104 if (reg) 2195 if (reg)
@@ -2129,6 +2220,8 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
2129 2220
2130 return lock; 2221 return lock;
2131 2222
2223err_gateoff:
2224 stv090x_i2c_gate_ctrl(fe, 0);
2132err: 2225err:
2133 dprintk(FE_ERROR, 1, "I/O error"); 2226 dprintk(FE_ERROR, 1, "I/O error");
2134 return -1; 2227 return -1;
@@ -2142,13 +2235,13 @@ static int stv090x_get_loop_params(struct stv090x_state *state, s32 *freq_inc, s
2142 car_max = state->search_range / 1000; 2235 car_max = state->search_range / 1000;
2143 car_max += car_max / 10; 2236 car_max += car_max / 10;
2144 car_max = 65536 * (car_max / 2); 2237 car_max = 65536 * (car_max / 2);
2145 car_max /= (state->mclk / 1000); 2238 car_max /= (state->internal->mclk / 1000);
2146 2239
2147 if (car_max > 0x4000) 2240 if (car_max > 0x4000)
2148 car_max = 0x4000 ; /* maxcarrier should be<= +-1/4 Mclk */ 2241 car_max = 0x4000 ; /* maxcarrier should be<= +-1/4 Mclk */
2149 2242
2150 inc = srate; 2243 inc = srate;
2151 inc /= state->mclk / 1000; 2244 inc /= state->internal->mclk / 1000;
2152 inc *= 256; 2245 inc *= 256;
2153 inc *= 256; 2246 inc *= 256;
2154 inc /= 1000; 2247 inc /= 1000;
@@ -2209,7 +2302,7 @@ static int stv090x_chk_signal(struct stv090x_state *state)
2209 2302
2210 car_max += (car_max / 10); /* 10% margin */ 2303 car_max += (car_max / 10); /* 10% margin */
2211 car_max = (65536 * car_max / 2); 2304 car_max = (65536 * car_max / 2);
2212 car_max /= state->mclk / 1000; 2305 car_max /= state->internal->mclk / 1000;
2213 2306
2214 if (car_max > 0x4000) 2307 if (car_max > 0x4000)
2215 car_max = 0x4000; 2308 car_max = 0x4000;
@@ -2234,7 +2327,7 @@ static int stv090x_search_car_loop(struct stv090x_state *state, s32 inc, s32 tim
2234 car_max = state->search_range / 1000; 2327 car_max = state->search_range / 1000;
2235 car_max += (car_max / 10); 2328 car_max += (car_max / 10);
2236 car_max = (65536 * car_max / 2); 2329 car_max = (65536 * car_max / 2);
2237 car_max /= (state->mclk / 1000); 2330 car_max /= (state->internal->mclk / 1000);
2238 if (car_max > 0x4000) 2331 if (car_max > 0x4000)
2239 car_max = 0x4000; 2332 car_max = 0x4000;
2240 2333
@@ -2304,7 +2397,7 @@ static int stv090x_sw_algo(struct stv090x_state *state)
2304 case STV090x_SEARCH_DVBS1: 2397 case STV090x_SEARCH_DVBS1:
2305 case STV090x_SEARCH_DSS: 2398 case STV090x_SEARCH_DSS:
2306 /* accelerate the frequency detector */ 2399 /* accelerate the frequency detector */
2307 if (state->dev_ver >= 0x20) { 2400 if (state->internal->dev_ver >= 0x20) {
2308 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3B) < 0) 2401 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3B) < 0)
2309 goto err; 2402 goto err;
2310 } 2403 }
@@ -2315,7 +2408,7 @@ static int stv090x_sw_algo(struct stv090x_state *state)
2315 break; 2408 break;
2316 2409
2317 case STV090x_SEARCH_DVBS2: 2410 case STV090x_SEARCH_DVBS2:
2318 if (state->dev_ver >= 0x20) { 2411 if (state->internal->dev_ver >= 0x20) {
2319 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) 2412 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0)
2320 goto err; 2413 goto err;
2321 } 2414 }
@@ -2328,7 +2421,7 @@ static int stv090x_sw_algo(struct stv090x_state *state)
2328 case STV090x_SEARCH_AUTO: 2421 case STV090x_SEARCH_AUTO:
2329 default: 2422 default:
2330 /* accelerate the frequency detector */ 2423 /* accelerate the frequency detector */
2331 if (state->dev_ver >= 0x20) { 2424 if (state->internal->dev_ver >= 0x20) {
2332 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3b) < 0) 2425 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x3b) < 0)
2333 goto err; 2426 goto err;
2334 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) 2427 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0)
@@ -2350,7 +2443,7 @@ static int stv090x_sw_algo(struct stv090x_state *state)
2350 /*run the SW search 2 times maximum*/ 2443 /*run the SW search 2 times maximum*/
2351 if (lock || no_signal || (trials == 2)) { 2444 if (lock || no_signal || (trials == 2)) {
2352 /*Check if the demod is not losing lock in DVBS2*/ 2445 /*Check if the demod is not losing lock in DVBS2*/
2353 if (state->dev_ver >= 0x20) { 2446 if (state->internal->dev_ver >= 0x20) {
2354 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) 2447 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0)
2355 goto err; 2448 goto err;
2356 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) 2449 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0)
@@ -2372,7 +2465,7 @@ static int stv090x_sw_algo(struct stv090x_state *state)
2372 /*FALSE lock, The demod is loosing lock */ 2465 /*FALSE lock, The demod is loosing lock */
2373 lock = 0; 2466 lock = 0;
2374 if (trials < 2) { 2467 if (trials < 2) {
2375 if (state->dev_ver >= 0x20) { 2468 if (state->internal->dev_ver >= 0x20) {
2376 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0) 2469 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x79) < 0)
2377 goto err; 2470 goto err;
2378 } 2471 }
@@ -2422,11 +2515,11 @@ static s32 stv090x_get_car_freq(struct stv090x_state *state, u32 mclk)
2422 derot |= STV090x_READ_DEMOD(state, CFR0); 2515 derot |= STV090x_READ_DEMOD(state, CFR0);
2423 2516
2424 derot = comp2(derot, 24); 2517 derot = comp2(derot, 24);
2425 int_1 = state->mclk >> 12; 2518 int_1 = mclk >> 12;
2426 int_2 = derot >> 12; 2519 int_2 = derot >> 12;
2427 2520
2428 /* carrier_frequency = MasterClock * Reg / 2^24 */ 2521 /* carrier_frequency = MasterClock * Reg / 2^24 */
2429 tmp_1 = state->mclk % 0x1000; 2522 tmp_1 = mclk % 0x1000;
2430 tmp_2 = derot % 0x1000; 2523 tmp_2 = derot % 0x1000;
2431 2524
2432 derot = (int_1 * int_2) + 2525 derot = (int_1 * int_2) +
@@ -2502,13 +2595,13 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
2502 2595
2503 if (state->config->tuner_get_frequency) { 2596 if (state->config->tuner_get_frequency) {
2504 if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) 2597 if (state->config->tuner_get_frequency(fe, &state->frequency) < 0)
2505 goto err; 2598 goto err_gateoff;
2506 } 2599 }
2507 2600
2508 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 2601 if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
2509 goto err; 2602 goto err;
2510 2603
2511 offst_freq = stv090x_get_car_freq(state, state->mclk) / 1000; 2604 offst_freq = stv090x_get_car_freq(state, state->internal->mclk) / 1000;
2512 state->frequency += offst_freq; 2605 state->frequency += offst_freq;
2513 2606
2514 if (stv090x_get_viterbi(state) < 0) 2607 if (stv090x_get_viterbi(state) < 0)
@@ -2530,7 +2623,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
2530 2623
2531 if (state->config->tuner_get_frequency) { 2624 if (state->config->tuner_get_frequency) {
2532 if (state->config->tuner_get_frequency(fe, &state->frequency) < 0) 2625 if (state->config->tuner_get_frequency(fe, &state->frequency) < 0)
2533 goto err; 2626 goto err_gateoff;
2534 } 2627 }
2535 2628
2536 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 2629 if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
@@ -2550,6 +2643,9 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
2550 } 2643 }
2551 2644
2552 return STV090x_OUTOFRANGE; 2645 return STV090x_OUTOFRANGE;
2646
2647err_gateoff:
2648 stv090x_i2c_gate_ctrl(fe, 0);
2553err: 2649err:
2554 dprintk(FE_ERROR, 1, "I/O error"); 2650 dprintk(FE_ERROR, 1, "I/O error");
2555 return -1; 2651 return -1;
@@ -2579,7 +2675,7 @@ static u8 stv090x_optimize_carloop(struct stv090x_state *state, enum stv090x_mod
2579 s32 i; 2675 s32 i;
2580 struct stv090x_long_frame_crloop *car_loop, *car_loop_qpsk_low, *car_loop_apsk_low; 2676 struct stv090x_long_frame_crloop *car_loop, *car_loop_qpsk_low, *car_loop_apsk_low;
2581 2677
2582 if (state->dev_ver == 0x20) { 2678 if (state->internal->dev_ver == 0x20) {
2583 car_loop = stv090x_s2_crl_cut20; 2679 car_loop = stv090x_s2_crl_cut20;
2584 car_loop_qpsk_low = stv090x_s2_lowqpsk_crl_cut20; 2680 car_loop_qpsk_low = stv090x_s2_lowqpsk_crl_cut20;
2585 car_loop_apsk_low = stv090x_s2_apsk_crl_cut20; 2681 car_loop_apsk_low = stv090x_s2_apsk_crl_cut20;
@@ -2700,7 +2796,7 @@ static u8 stv090x_optimize_carloop_short(struct stv090x_state *state)
2700 break; 2796 break;
2701 } 2797 }
2702 2798
2703 if (state->dev_ver >= 0x30) { 2799 if (state->internal->dev_ver >= 0x30) {
2704 /* Cut 3.0 and up */ 2800 /* Cut 3.0 and up */
2705 short_crl = stv090x_s2_short_crl_cut30; 2801 short_crl = stv090x_s2_short_crl_cut30;
2706 } else { 2802 } else {
@@ -2732,7 +2828,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2732 s32 srate, pilots, aclc, f_1, f_0, i = 0, blind_tune = 0; 2828 s32 srate, pilots, aclc, f_1, f_0, i = 0, blind_tune = 0;
2733 u32 reg; 2829 u32 reg;
2734 2830
2735 srate = stv090x_get_srate(state, state->mclk); 2831 srate = stv090x_get_srate(state, state->internal->mclk);
2736 srate += stv090x_get_tmgoffst(state, srate); 2832 srate += stv090x_get_tmgoffst(state, srate);
2737 2833
2738 switch (state->delsys) { 2834 switch (state->delsys) {
@@ -2751,7 +2847,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2751 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0) 2847 if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0)
2752 goto err; 2848 goto err;
2753 2849
2754 if (state->dev_ver >= 0x30) { 2850 if (state->internal->dev_ver >= 0x30) {
2755 if (stv090x_get_viterbi(state) < 0) 2851 if (stv090x_get_viterbi(state) < 0)
2756 goto err; 2852 goto err;
2757 2853
@@ -2868,7 +2964,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2868 goto err; 2964 goto err;
2869 } 2965 }
2870 2966
2871 if (state->dev_ver >= 0x20) { 2967 if (state->internal->dev_ver >= 0x20) {
2872 if ((state->search_mode == STV090x_SEARCH_DVBS1) || 2968 if ((state->search_mode == STV090x_SEARCH_DVBS1) ||
2873 (state->search_mode == STV090x_SEARCH_DSS) || 2969 (state->search_mode == STV090x_SEARCH_DSS) ||
2874 (state->search_mode == STV090x_SEARCH_AUTO)) { 2970 (state->search_mode == STV090x_SEARCH_AUTO)) {
@@ -2890,7 +2986,8 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2890 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x80) < 0) 2986 if (STV090x_WRITE_DEMOD(state, SFRLOW1, 0x80) < 0)
2891 goto err; 2987 goto err;
2892 2988
2893 if ((state->dev_ver >= 0x20) || (blind_tune == 1) || (state->srate < 10000000)) { 2989 if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1) ||
2990 (state->srate < 10000000)) {
2894 /* update initial carrier freq with the found freq offset */ 2991 /* update initial carrier freq with the found freq offset */
2895 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0) 2992 if (STV090x_WRITE_DEMOD(state, CFRINIT1, f_1) < 0)
2896 goto err; 2993 goto err;
@@ -2898,7 +2995,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2898 goto err; 2995 goto err;
2899 state->tuner_bw = stv090x_car_width(srate, state->rolloff) + 10000000; 2996 state->tuner_bw = stv090x_car_width(srate, state->rolloff) + 10000000;
2900 2997
2901 if ((state->dev_ver >= 0x20) || (blind_tune == 1)) { 2998 if ((state->internal->dev_ver >= 0x20) || (blind_tune == 1)) {
2902 2999
2903 if (state->algo != STV090x_WARM_SEARCH) { 3000 if (state->algo != STV090x_WARM_SEARCH) {
2904 3001
@@ -2907,7 +3004,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2907 3004
2908 if (state->config->tuner_set_bandwidth) { 3005 if (state->config->tuner_set_bandwidth) {
2909 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) 3006 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0)
2910 goto err; 3007 goto err_gateoff;
2911 } 3008 }
2912 3009
2913 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 3010 if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
@@ -2950,7 +3047,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2950 3047
2951 } 3048 }
2952 3049
2953 if (state->dev_ver >= 0x20) { 3050 if (state->internal->dev_ver >= 0x20) {
2954 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0) 3051 if (STV090x_WRITE_DEMOD(state, CARFREQ, 0x49) < 0)
2955 goto err; 3052 goto err;
2956 } 3053 }
@@ -2959,6 +3056,9 @@ static int stv090x_optimize_track(struct stv090x_state *state)
2959 stv090x_set_vit_thtracq(state); 3056 stv090x_set_vit_thtracq(state);
2960 3057
2961 return 0; 3058 return 0;
3059
3060err_gateoff:
3061 stv090x_i2c_gate_ctrl(fe, 0);
2962err: 3062err:
2963 dprintk(FE_ERROR, 1, "I/O error"); 3063 dprintk(FE_ERROR, 1, "I/O error");
2964 return -1; 3064 return -1;
@@ -3026,7 +3126,7 @@ static int stv090x_set_s2rolloff(struct stv090x_state *state)
3026{ 3126{
3027 u32 reg; 3127 u32 reg;
3028 3128
3029 if (state->dev_ver <= 0x20) { 3129 if (state->internal->dev_ver <= 0x20) {
3030 /* rolloff to auto mode if DVBS2 */ 3130 /* rolloff to auto mode if DVBS2 */
3031 reg = STV090x_READ_DEMOD(state, DEMOD); 3131 reg = STV090x_READ_DEMOD(state, DEMOD);
3032 STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 0x00); 3132 STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 0x00);
@@ -3062,7 +3162,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3062 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod stop */ 3162 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Demod stop */
3063 goto err; 3163 goto err;
3064 3164
3065 if (state->dev_ver >= 0x20) { 3165 if (state->internal->dev_ver >= 0x20) {
3066 if (state->srate > 5000000) { 3166 if (state->srate > 5000000) {
3067 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0) 3167 if (STV090x_WRITE_DEMOD(state, CORRELABS, 0x9e) < 0)
3068 goto err; 3168 goto err;
@@ -3102,7 +3202,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3102 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0) 3202 if (STV090x_WRITE_DEMOD(state, AGC2REF, 0x38) < 0)
3103 goto err; 3203 goto err;
3104 3204
3105 if (state->dev_ver >= 0x20) { 3205 if (state->internal->dev_ver >= 0x20) {
3106 if (STV090x_WRITE_DEMOD(state, KREFTMG, 0x5a) < 0) 3206 if (STV090x_WRITE_DEMOD(state, KREFTMG, 0x5a) < 0)
3107 goto err; 3207 goto err;
3108 if (state->algo == STV090x_COLD_SEARCH) 3208 if (state->algo == STV090x_COLD_SEARCH)
@@ -3120,9 +3220,11 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3120 if (stv090x_set_srate(state, state->srate) < 0) 3220 if (stv090x_set_srate(state, state->srate) < 0)
3121 goto err; 3221 goto err;
3122 3222
3123 if (stv090x_set_max_srate(state, state->mclk, state->srate) < 0) 3223 if (stv090x_set_max_srate(state, state->internal->mclk,
3224 state->srate) < 0)
3124 goto err; 3225 goto err;
3125 if (stv090x_set_min_srate(state, state->mclk, state->srate) < 0) 3226 if (stv090x_set_min_srate(state, state->internal->mclk,
3227 state->srate) < 0)
3126 goto err; 3228 goto err;
3127 3229
3128 if (state->srate >= 10000000) 3230 if (state->srate >= 10000000)
@@ -3136,18 +3238,21 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3136 goto err; 3238 goto err;
3137 3239
3138 if (state->config->tuner_set_bbgain) { 3240 if (state->config->tuner_set_bbgain) {
3139 if (state->config->tuner_set_bbgain(fe, 10) < 0) /* 10dB */ 3241 reg = state->config->tuner_bbgain;
3140 goto err; 3242 if (reg == 0)
3243 reg = 10; /* default: 10dB */
3244 if (state->config->tuner_set_bbgain(fe, reg) < 0)
3245 goto err_gateoff;
3141 } 3246 }
3142 3247
3143 if (state->config->tuner_set_frequency) { 3248 if (state->config->tuner_set_frequency) {
3144 if (state->config->tuner_set_frequency(fe, state->frequency) < 0) 3249 if (state->config->tuner_set_frequency(fe, state->frequency) < 0)
3145 goto err; 3250 goto err_gateoff;
3146 } 3251 }
3147 3252
3148 if (state->config->tuner_set_bandwidth) { 3253 if (state->config->tuner_set_bandwidth) {
3149 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0) 3254 if (state->config->tuner_set_bandwidth(fe, state->tuner_bw) < 0)
3150 goto err; 3255 goto err_gateoff;
3151 } 3256 }
3152 3257
3153 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 3258 if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
@@ -3155,21 +3260,21 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3155 3260
3156 msleep(50); 3261 msleep(50);
3157 3262
3158 if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
3159 goto err;
3160
3161 if (state->config->tuner_get_status) { 3263 if (state->config->tuner_get_status) {
3264 if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
3265 goto err;
3162 if (state->config->tuner_get_status(fe, &reg) < 0) 3266 if (state->config->tuner_get_status(fe, &reg) < 0)
3267 goto err_gateoff;
3268 if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
3163 goto err; 3269 goto err;
3164 }
3165 3270
3166 if (reg) 3271 if (reg)
3167 dprintk(FE_DEBUG, 1, "Tuner phase locked"); 3272 dprintk(FE_DEBUG, 1, "Tuner phase locked");
3168 else 3273 else {
3169 dprintk(FE_DEBUG, 1, "Tuner unlocked"); 3274 dprintk(FE_DEBUG, 1, "Tuner unlocked");
3170 3275 return STV090x_NOCARRIER;
3171 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 3276 }
3172 goto err; 3277 }
3173 3278
3174 msleep(10); 3279 msleep(10);
3175 agc1_power = MAKEWORD16(STV090x_READ_DEMOD(state, AGCIQIN1), 3280 agc1_power = MAKEWORD16(STV090x_READ_DEMOD(state, AGCIQIN1),
@@ -3194,7 +3299,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3194 reg = STV090x_READ_DEMOD(state, DEMOD); 3299 reg = STV090x_READ_DEMOD(state, DEMOD);
3195 STV090x_SETFIELD_Px(reg, SPECINV_CONTROL_FIELD, state->inversion); 3300 STV090x_SETFIELD_Px(reg, SPECINV_CONTROL_FIELD, state->inversion);
3196 3301
3197 if (state->dev_ver <= 0x20) { 3302 if (state->internal->dev_ver <= 0x20) {
3198 /* rolloff to auto mode if DVBS2 */ 3303 /* rolloff to auto mode if DVBS2 */
3199 STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 1); 3304 STV090x_SETFIELD_Px(reg, MANUAL_SXROLLOFF_FIELD, 1);
3200 } else { 3305 } else {
@@ -3238,7 +3343,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3238 if ((lock) && (signal_state == STV090x_RANGEOK)) { /* signal within Range */ 3343 if ((lock) && (signal_state == STV090x_RANGEOK)) { /* signal within Range */
3239 stv090x_optimize_track(state); 3344 stv090x_optimize_track(state);
3240 3345
3241 if (state->dev_ver >= 0x20) { 3346 if (state->internal->dev_ver >= 0x20) {
3242 /* >= Cut 2.0 :release TS reset after 3347 /* >= Cut 2.0 :release TS reset after
3243 * demod lock and optimized Tracking 3348 * demod lock and optimized Tracking
3244 */ 3349 */
@@ -3293,6 +3398,8 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
3293 } 3398 }
3294 return signal_state; 3399 return signal_state;
3295 3400
3401err_gateoff:
3402 stv090x_i2c_gate_ctrl(fe, 0);
3296err: 3403err:
3297 dprintk(FE_ERROR, 1, "I/O error"); 3404 dprintk(FE_ERROR, 1, "I/O error");
3298 return -1; 3405 return -1;
@@ -3303,6 +3410,9 @@ static enum dvbfe_search stv090x_search(struct dvb_frontend *fe, struct dvb_fron
3303 struct stv090x_state *state = fe->demodulator_priv; 3410 struct stv090x_state *state = fe->demodulator_priv;
3304 struct dtv_frontend_properties *props = &fe->dtv_property_cache; 3411 struct dtv_frontend_properties *props = &fe->dtv_property_cache;
3305 3412
3413 if (p->frequency == 0)
3414 return DVBFE_ALGO_SEARCH_INVALID;
3415
3306 state->delsys = props->delivery_system; 3416 state->delsys = props->delivery_system;
3307 state->frequency = p->frequency; 3417 state->frequency = p->frequency;
3308 state->srate = p->u.qpsk.symbol_rate; 3418 state->srate = p->u.qpsk.symbol_rate;
@@ -3353,7 +3463,8 @@ static int stv090x_read_status(struct dvb_frontend *fe, enum fe_status *status)
3353 if (STV090x_GETFIELD_Px(reg, PKTDELIN_LOCK_FIELD)) { 3463 if (STV090x_GETFIELD_Px(reg, PKTDELIN_LOCK_FIELD)) {
3354 reg = STV090x_READ_DEMOD(state, TSSTATUS); 3464 reg = STV090x_READ_DEMOD(state, TSSTATUS);
3355 if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) { 3465 if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) {
3356 *status = FE_HAS_CARRIER | 3466 *status = FE_HAS_SIGNAL |
3467 FE_HAS_CARRIER |
3357 FE_HAS_VITERBI | 3468 FE_HAS_VITERBI |
3358 FE_HAS_SYNC | 3469 FE_HAS_SYNC |
3359 FE_HAS_LOCK; 3470 FE_HAS_LOCK;
@@ -3370,7 +3481,11 @@ static int stv090x_read_status(struct dvb_frontend *fe, enum fe_status *status)
3370 if (STV090x_GETFIELD_Px(reg, LOCKEDVIT_FIELD)) { 3481 if (STV090x_GETFIELD_Px(reg, LOCKEDVIT_FIELD)) {
3371 reg = STV090x_READ_DEMOD(state, TSSTATUS); 3482 reg = STV090x_READ_DEMOD(state, TSSTATUS);
3372 if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) { 3483 if (STV090x_GETFIELD_Px(reg, TSFIFO_LINEOK_FIELD)) {
3373 *status = FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; 3484 *status = FE_HAS_SIGNAL |
3485 FE_HAS_CARRIER |
3486 FE_HAS_VITERBI |
3487 FE_HAS_SYNC |
3488 FE_HAS_LOCK;
3374 } 3489 }
3375 } 3490 }
3376 } 3491 }
@@ -3770,6 +3885,15 @@ static void stv090x_release(struct dvb_frontend *fe)
3770{ 3885{
3771 struct stv090x_state *state = fe->demodulator_priv; 3886 struct stv090x_state *state = fe->demodulator_priv;
3772 3887
3888 state->internal->num_used--;
3889 if (state->internal->num_used <= 0) {
3890
3891 dprintk(FE_ERROR, 1, "Actually removing");
3892
3893 remove_dev(state->internal);
3894 kfree(state->internal);
3895 }
3896
3773 kfree(state); 3897 kfree(state);
3774} 3898}
3775 3899
@@ -3901,10 +4025,10 @@ static int stv090x_set_mclk(struct stv090x_state *state, u32 mclk, u32 clk)
3901 if (stv090x_write_reg(state, STV090x_NCOARSE, reg) < 0) 4025 if (stv090x_write_reg(state, STV090x_NCOARSE, reg) < 0)
3902 goto err; 4026 goto err;
3903 4027
3904 state->mclk = stv090x_get_mclk(state); 4028 state->internal->mclk = stv090x_get_mclk(state);
3905 4029
3906 /*Set the DiseqC frequency to 22KHz */ 4030 /*Set the DiseqC frequency to 22KHz */
3907 div = state->mclk / 704000; 4031 div = state->internal->mclk / 704000;
3908 if (STV090x_WRITE_DEMOD(state, F22TX, div) < 0) 4032 if (STV090x_WRITE_DEMOD(state, F22TX, div) < 0)
3909 goto err; 4033 goto err;
3910 if (STV090x_WRITE_DEMOD(state, F22RX, div) < 0) 4034 if (STV090x_WRITE_DEMOD(state, F22RX, div) < 0)
@@ -3920,7 +4044,7 @@ static int stv090x_set_tspath(struct stv090x_state *state)
3920{ 4044{
3921 u32 reg; 4045 u32 reg;
3922 4046
3923 if (state->dev_ver >= 0x20) { 4047 if (state->internal->dev_ver >= 0x20) {
3924 switch (state->config->ts1_mode) { 4048 switch (state->config->ts1_mode) {
3925 case STV090x_TSMODE_PARALLEL_PUNCTURED: 4049 case STV090x_TSMODE_PARALLEL_PUNCTURED:
3926 case STV090x_TSMODE_DVBCI: 4050 case STV090x_TSMODE_DVBCI:
@@ -4092,6 +4216,71 @@ static int stv090x_set_tspath(struct stv090x_state *state)
4092 default: 4216 default:
4093 break; 4217 break;
4094 } 4218 }
4219
4220 if (state->config->ts1_clk > 0) {
4221 u32 speed;
4222
4223 switch (state->config->ts1_mode) {
4224 case STV090x_TSMODE_PARALLEL_PUNCTURED:
4225 case STV090x_TSMODE_DVBCI:
4226 default:
4227 speed = state->internal->mclk /
4228 (state->config->ts1_clk / 4);
4229 if (speed < 0x08)
4230 speed = 0x08;
4231 if (speed > 0xFF)
4232 speed = 0xFF;
4233 break;
4234 case STV090x_TSMODE_SERIAL_PUNCTURED:
4235 case STV090x_TSMODE_SERIAL_CONTINUOUS:
4236 speed = state->internal->mclk /
4237 (state->config->ts1_clk / 32);
4238 if (speed < 0x20)
4239 speed = 0x20;
4240 if (speed > 0xFF)
4241 speed = 0xFF;
4242 break;
4243 }
4244 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM);
4245 STV090x_SETFIELD_Px(reg, TSFIFO_MANSPEED_FIELD, 3);
4246 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0)
4247 goto err;
4248 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, speed) < 0)
4249 goto err;
4250 }
4251
4252 if (state->config->ts2_clk > 0) {
4253 u32 speed;
4254
4255 switch (state->config->ts2_mode) {
4256 case STV090x_TSMODE_PARALLEL_PUNCTURED:
4257 case STV090x_TSMODE_DVBCI:
4258 default:
4259 speed = state->internal->mclk /
4260 (state->config->ts2_clk / 4);
4261 if (speed < 0x08)
4262 speed = 0x08;
4263 if (speed > 0xFF)
4264 speed = 0xFF;
4265 break;
4266 case STV090x_TSMODE_SERIAL_PUNCTURED:
4267 case STV090x_TSMODE_SERIAL_CONTINUOUS:
4268 speed = state->internal->mclk /
4269 (state->config->ts2_clk / 32);
4270 if (speed < 0x20)
4271 speed = 0x20;
4272 if (speed > 0xFF)
4273 speed = 0xFF;
4274 break;
4275 }
4276 reg = stv090x_read_reg(state, STV090x_P2_TSCFGM);
4277 STV090x_SETFIELD_Px(reg, TSFIFO_MANSPEED_FIELD, 3);
4278 if (stv090x_write_reg(state, STV090x_P2_TSCFGM, reg) < 0)
4279 goto err;
4280 if (stv090x_write_reg(state, STV090x_P2_TSSPEED, speed) < 0)
4281 goto err;
4282 }
4283
4095 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH); 4284 reg = stv090x_read_reg(state, STV090x_P2_TSCFGH);
4096 STV090x_SETFIELD_Px(reg, RST_HWARE_FIELD, 0x01); 4285 STV090x_SETFIELD_Px(reg, RST_HWARE_FIELD, 0x01);
4097 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0) 4286 if (stv090x_write_reg(state, STV090x_P2_TSCFGH, reg) < 0)
@@ -4120,6 +4309,15 @@ static int stv090x_init(struct dvb_frontend *fe)
4120 const struct stv090x_config *config = state->config; 4309 const struct stv090x_config *config = state->config;
4121 u32 reg; 4310 u32 reg;
4122 4311
4312 if (state->internal->mclk == 0) {
4313 stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */
4314 msleep(5);
4315 if (stv090x_write_reg(state, STV090x_SYNTCTRL,
4316 0x20 | config->clk_mode) < 0)
4317 goto err;
4318 stv090x_get_mclk(state);
4319 }
4320
4123 if (stv090x_wakeup(fe) < 0) { 4321 if (stv090x_wakeup(fe) < 0) {
4124 dprintk(FE_ERROR, 1, "Error waking device"); 4322 dprintk(FE_ERROR, 1, "Error waking device");
4125 goto err; 4323 goto err;
@@ -4142,12 +4340,12 @@ static int stv090x_init(struct dvb_frontend *fe)
4142 4340
4143 if (config->tuner_set_mode) { 4341 if (config->tuner_set_mode) {
4144 if (config->tuner_set_mode(fe, TUNER_WAKE) < 0) 4342 if (config->tuner_set_mode(fe, TUNER_WAKE) < 0)
4145 goto err; 4343 goto err_gateoff;
4146 } 4344 }
4147 4345
4148 if (config->tuner_init) { 4346 if (config->tuner_init) {
4149 if (config->tuner_init(fe) < 0) 4347 if (config->tuner_init(fe) < 0)
4150 goto err; 4348 goto err_gateoff;
4151 } 4349 }
4152 4350
4153 if (stv090x_i2c_gate_ctrl(fe, 0) < 0) 4351 if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
@@ -4157,6 +4355,9 @@ static int stv090x_init(struct dvb_frontend *fe)
4157 goto err; 4355 goto err;
4158 4356
4159 return 0; 4357 return 0;
4358
4359err_gateoff:
4360 stv090x_i2c_gate_ctrl(fe, 0);
4160err: 4361err:
4161 dprintk(FE_ERROR, 1, "I/O error"); 4362 dprintk(FE_ERROR, 1, "I/O error");
4162 return -1; 4363 return -1;
@@ -4188,16 +4389,26 @@ static int stv090x_setup(struct dvb_frontend *fe)
4188 } 4389 }
4189 4390
4190 /* STV090x init */ 4391 /* STV090x init */
4191 if (STV090x_WRITE_DEMOD(state, DMDISTATE, 0x5c) < 0) /* Stop Demod */ 4392
4393 /* Stop Demod */
4394 if (stv090x_write_reg(state, STV090x_P1_DMDISTATE, 0x5c) < 0)
4395 goto err;
4396 if (stv090x_write_reg(state, STV090x_P2_DMDISTATE, 0x5c) < 0)
4192 goto err; 4397 goto err;
4193 4398
4194 msleep(5); 4399 msleep(5);
4195 4400
4196 if (STV090x_WRITE_DEMOD(state, TNRCFG, 0x6c) < 0) /* check register ! (No Tuner Mode) */ 4401 /* Set No Tuner Mode */
4402 if (stv090x_write_reg(state, STV090x_P1_TNRCFG, 0x6c) < 0)
4403 goto err;
4404 if (stv090x_write_reg(state, STV090x_P2_TNRCFG, 0x6c) < 0)
4197 goto err; 4405 goto err;
4198 4406
4407 /* I2C repeater OFF */
4199 STV090x_SETFIELD_Px(reg, ENARPT_LEVEL_FIELD, config->repeater_level); 4408 STV090x_SETFIELD_Px(reg, ENARPT_LEVEL_FIELD, config->repeater_level);
4200 if (STV090x_WRITE_DEMOD(state, I2CRPT, reg) < 0) /* repeater OFF */ 4409 if (stv090x_write_reg(state, STV090x_P1_I2CRPT, reg) < 0)
4410 goto err;
4411 if (stv090x_write_reg(state, STV090x_P2_I2CRPT, reg) < 0)
4201 goto err; 4412 goto err;
4202 4413
4203 if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */ 4414 if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */
@@ -4216,8 +4427,8 @@ static int stv090x_setup(struct dvb_frontend *fe)
4216 goto err; 4427 goto err;
4217 } 4428 }
4218 4429
4219 state->dev_ver = stv090x_read_reg(state, STV090x_MID); 4430 state->internal->dev_ver = stv090x_read_reg(state, STV090x_MID);
4220 if (state->dev_ver >= 0x20) { 4431 if (state->internal->dev_ver >= 0x20) {
4221 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0) 4432 if (stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c) < 0)
4222 goto err; 4433 goto err;
4223 4434
@@ -4228,27 +4439,35 @@ static int stv090x_setup(struct dvb_frontend *fe)
4228 goto err; 4439 goto err;
4229 } 4440 }
4230 4441
4231 } else if (state->dev_ver < 0x20) { 4442 } else if (state->internal->dev_ver < 0x20) {
4232 dprintk(FE_ERROR, 1, "ERROR: Unsupported Cut: 0x%02x!", 4443 dprintk(FE_ERROR, 1, "ERROR: Unsupported Cut: 0x%02x!",
4233 state->dev_ver); 4444 state->internal->dev_ver);
4234 4445
4235 goto err; 4446 goto err;
4236 } else if (state->dev_ver > 0x30) { 4447 } else if (state->internal->dev_ver > 0x30) {
4237 /* we shouldn't bail out from here */ 4448 /* we shouldn't bail out from here */
4238 dprintk(FE_ERROR, 1, "INFO: Cut: 0x%02x probably incomplete support!", 4449 dprintk(FE_ERROR, 1, "INFO: Cut: 0x%02x probably incomplete support!",
4239 state->dev_ver); 4450 state->internal->dev_ver);
4240 } 4451 }
4241 4452
4242 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x80) < 0) 4453 /* ADC1 range */
4454 reg = stv090x_read_reg(state, STV090x_TSTTNR1);
4455 STV090x_SETFIELD(reg, ADC1_INMODE_FIELD,
4456 (config->adc1_range == STV090x_ADC_1Vpp) ? 0 : 1);
4457 if (stv090x_write_reg(state, STV090x_TSTTNR1, reg) < 0)
4243 goto err; 4458 goto err;
4244 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x00) < 0) 4459
4460 /* ADC2 range */
4461 reg = stv090x_read_reg(state, STV090x_TSTTNR3);
4462 STV090x_SETFIELD(reg, ADC2_INMODE_FIELD,
4463 (config->adc2_range == STV090x_ADC_1Vpp) ? 0 : 1);
4464 if (stv090x_write_reg(state, STV090x_TSTTNR3, reg) < 0)
4245 goto err; 4465 goto err;
4246 4466
4247 stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */ 4467 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x80) < 0)
4248 msleep(5); 4468 goto err;
4249 if (stv090x_write_reg(state, STV090x_SYNTCTRL, 0x20 | config->clk_mode) < 0) 4469 if (stv090x_write_reg(state, STV090x_TSTRES0, 0x00) < 0)
4250 goto err; 4470 goto err;
4251 stv090x_get_mclk(state);
4252 4471
4253 return 0; 4472 return 0;
4254err: 4473err:
@@ -4299,6 +4518,7 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
4299 enum stv090x_demodulator demod) 4518 enum stv090x_demodulator demod)
4300{ 4519{
4301 struct stv090x_state *state = NULL; 4520 struct stv090x_state *state = NULL;
4521 struct stv090x_dev *temp_int;
4302 4522
4303 state = kzalloc(sizeof (struct stv090x_state), GFP_KERNEL); 4523 state = kzalloc(sizeof (struct stv090x_state), GFP_KERNEL);
4304 if (state == NULL) 4524 if (state == NULL)
@@ -4314,8 +4534,32 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
4314 state->device = config->device; 4534 state->device = config->device;
4315 state->rolloff = STV090x_RO_35; /* default */ 4535 state->rolloff = STV090x_RO_35; /* default */
4316 4536
4317 if (state->demod == STV090x_DEMODULATOR_0) 4537 temp_int = find_dev(state->i2c,
4318 mutex_init(&demod_lock); 4538 state->config->address);
4539
4540 if ((temp_int != NULL) && (state->demod_mode == STV090x_DUAL)) {
4541 state->internal = temp_int->internal;
4542 state->internal->num_used++;
4543 dprintk(FE_INFO, 1, "Found Internal Structure!");
4544 dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x",
4545 state->device == STV0900 ? "STV0900" : "STV0903",
4546 demod,
4547 state->internal->dev_ver);
4548 return &state->frontend;
4549 } else {
4550 state->internal = kmalloc(sizeof(struct stv090x_internal),
4551 GFP_KERNEL);
4552 temp_int = append_internal(state->internal);
4553 state->internal->num_used = 1;
4554 state->internal->mclk = 0;
4555 state->internal->dev_ver = 0;
4556 state->internal->i2c_adap = state->i2c;
4557 state->internal->i2c_addr = state->config->address;
4558 dprintk(FE_INFO, 1, "Create New Internal Structure!");
4559 }
4560
4561 mutex_init(&state->internal->demod_lock);
4562 mutex_init(&state->internal->tuner_lock);
4319 4563
4320 if (stv090x_sleep(&state->frontend) < 0) { 4564 if (stv090x_sleep(&state->frontend) < 0) {
4321 dprintk(FE_ERROR, 1, "Error putting device to sleep"); 4565 dprintk(FE_ERROR, 1, "Error putting device to sleep");
@@ -4331,10 +4575,10 @@ struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
4331 goto error; 4575 goto error;
4332 } 4576 }
4333 4577
4334 dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x\n", 4578 dprintk(FE_ERROR, 1, "Attaching %s demodulator(%d) Cut=0x%02x",
4335 state->device == STV0900 ? "STV0900" : "STV0903", 4579 state->device == STV0900 ? "STV0900" : "STV0903",
4336 demod, 4580 demod,
4337 state->dev_ver); 4581 state->internal->dev_ver);
4338 4582
4339 return &state->frontend; 4583 return &state->frontend;
4340 4584
diff --git a/drivers/media/dvb/frontends/stv090x.h b/drivers/media/dvb/frontends/stv090x.h
index b133807663ea..30f01a6902ac 100644
--- a/drivers/media/dvb/frontends/stv090x.h
+++ b/drivers/media/dvb/frontends/stv090x.h
@@ -60,6 +60,11 @@ enum stv090x_i2crpt {
60 STV090x_RPTLEVEL_2 = 7, 60 STV090x_RPTLEVEL_2 = 7,
61}; 61};
62 62
63enum stv090x_adc_range {
64 STV090x_ADC_2Vpp = 0,
65 STV090x_ADC_1Vpp = 1
66};
67
63struct stv090x_config { 68struct stv090x_config {
64 enum stv090x_device device; 69 enum stv090x_device device;
65 enum stv090x_mode demod_mode; 70 enum stv090x_mode demod_mode;
@@ -68,13 +73,17 @@ struct stv090x_config {
68 u32 xtal; /* default: 8000000 */ 73 u32 xtal; /* default: 8000000 */
69 u8 address; /* default: 0x68 */ 74 u8 address; /* default: 0x68 */
70 75
71 u32 ref_clk; /* default: 16000000 FIXME to tuner config */
72
73 u8 ts1_mode; 76 u8 ts1_mode;
74 u8 ts2_mode; 77 u8 ts2_mode;
78 u32 ts1_clk;
79 u32 ts2_clk;
75 80
76 enum stv090x_i2crpt repeater_level; 81 enum stv090x_i2crpt repeater_level;
77 82
83 u8 tuner_bbgain; /* default: 10db */
84 enum stv090x_adc_range adc1_range; /* default: 2Vpp */
85 enum stv090x_adc_range adc2_range; /* default: 2Vpp */
86
78 bool diseqc_envelope_mode; 87 bool diseqc_envelope_mode;
79 88
80 int (*tuner_init) (struct dvb_frontend *fe); 89 int (*tuner_init) (struct dvb_frontend *fe);
diff --git a/drivers/media/dvb/frontends/stv090x_priv.h b/drivers/media/dvb/frontends/stv090x_priv.h
index 5921a8d6c89f..5b780c80d496 100644
--- a/drivers/media/dvb/frontends/stv090x_priv.h
+++ b/drivers/media/dvb/frontends/stv090x_priv.h
@@ -230,11 +230,23 @@ struct stv090x_tab {
230 s32 read; 230 s32 read;
231}; 231};
232 232
233struct stv090x_internal {
234 struct i2c_adapter *i2c_adap;
235 u8 i2c_addr;
236
237 struct mutex demod_lock; /* Lock access to shared register */
238 struct mutex tuner_lock; /* Lock access to tuners */
239 s32 mclk; /* Masterclock Divider factor */
240 u32 dev_ver;
241
242 int num_used;
243};
244
233struct stv090x_state { 245struct stv090x_state {
234 enum stv090x_device device; 246 enum stv090x_device device;
235 enum stv090x_demodulator demod; 247 enum stv090x_demodulator demod;
236 enum stv090x_mode demod_mode; 248 enum stv090x_mode demod_mode;
237 u32 dev_ver; 249 struct stv090x_internal *internal;
238 250
239 struct i2c_adapter *i2c; 251 struct i2c_adapter *i2c;
240 const struct stv090x_config *config; 252 const struct stv090x_config *config;
@@ -256,11 +268,8 @@ struct stv090x_state {
256 u32 frequency; 268 u32 frequency;
257 u32 srate; 269 u32 srate;
258 270
259 s32 mclk; /* Masterclock Divider factor */
260 s32 tuner_bw; 271 s32 tuner_bw;
261 272
262 u32 tuner_refclk;
263
264 s32 search_range; 273 s32 search_range;
265 274
266 s32 DemodTimeout; 275 s32 DemodTimeout;
diff --git a/drivers/media/dvb/frontends/stv6110x.c b/drivers/media/dvb/frontends/stv6110x.c
index bcfcb652464c..f931ed07e92d 100644
--- a/drivers/media/dvb/frontends/stv6110x.c
+++ b/drivers/media/dvb/frontends/stv6110x.c
@@ -35,8 +35,6 @@ static unsigned int verbose;
35module_param(verbose, int, 0644); 35module_param(verbose, int, 0644);
36MODULE_PARM_DESC(verbose, "Set Verbosity level"); 36MODULE_PARM_DESC(verbose, "Set Verbosity level");
37 37
38static u8 stv6110x_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e};
39
40static int stv6110x_read_reg(struct stv6110x_state *stv6110x, u8 reg, u8 *data) 38static int stv6110x_read_reg(struct stv6110x_state *stv6110x, u8 reg, u8 *data)
41{ 39{
42 int ret; 40 int ret;
@@ -58,12 +56,23 @@ static int stv6110x_read_reg(struct stv6110x_state *stv6110x, u8 reg, u8 *data)
58 return 0; 56 return 0;
59} 57}
60 58
61static int stv6110x_write_reg(struct stv6110x_state *stv6110x, u8 reg, u8 data) 59static int stv6110x_write_regs(struct stv6110x_state *stv6110x, int start, u8 data[], int len)
62{ 60{
63 int ret; 61 int ret;
64 const struct stv6110x_config *config = stv6110x->config; 62 const struct stv6110x_config *config = stv6110x->config;
65 u8 buf[] = { reg, data }; 63 u8 buf[len + 1];
66 struct i2c_msg msg = { .addr = config->addr, .flags = 0, . buf = buf, .len = 2 }; 64 struct i2c_msg msg = {
65 .addr = config->addr,
66 .flags = 0,
67 .buf = buf,
68 .len = len + 1
69 };
70
71 if (start + len > 8)
72 return -EINVAL;
73
74 buf[0] = start;
75 memcpy(&buf[1], data, len);
67 76
68 ret = i2c_transfer(stv6110x->i2c, &msg, 1); 77 ret = i2c_transfer(stv6110x->i2c, &msg, 1);
69 if (ret != 1) { 78 if (ret != 1) {
@@ -74,18 +83,21 @@ static int stv6110x_write_reg(struct stv6110x_state *stv6110x, u8 reg, u8 data)
74 return 0; 83 return 0;
75} 84}
76 85
86static int stv6110x_write_reg(struct stv6110x_state *stv6110x, u8 reg, u8 data)
87{
88 return stv6110x_write_regs(stv6110x, reg, &data, 1);
89}
90
77static int stv6110x_init(struct dvb_frontend *fe) 91static int stv6110x_init(struct dvb_frontend *fe)
78{ 92{
79 struct stv6110x_state *stv6110x = fe->tuner_priv; 93 struct stv6110x_state *stv6110x = fe->tuner_priv;
80 int ret; 94 int ret;
81 u8 i;
82 95
83 for (i = 0; i < ARRAY_SIZE(stv6110x_regs); i++) { 96 ret = stv6110x_write_regs(stv6110x, 0, stv6110x->regs,
84 ret = stv6110x_write_reg(stv6110x, i, stv6110x_regs[i]); 97 ARRAY_SIZE(stv6110x->regs));
85 if (ret < 0) { 98 if (ret < 0) {
86 dprintk(FE_ERROR, 1, "Initialization failed"); 99 dprintk(FE_ERROR, 1, "Initialization failed");
87 return -1; 100 return -1;
88 }
89 } 101 }
90 102
91 return 0; 103 return 0;
@@ -98,23 +110,23 @@ static int stv6110x_set_frequency(struct dvb_frontend *fe, u32 frequency)
98 s32 pVal, pCalc, rDivOpt = 0, pCalcOpt = 1000; 110 s32 pVal, pCalc, rDivOpt = 0, pCalcOpt = 1000;
99 u8 i; 111 u8 i;
100 112
101 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_K, (REFCLOCK_MHz - 16)); 113 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_K, (REFCLOCK_MHz - 16));
102 114
103 if (frequency <= 1023000) { 115 if (frequency <= 1023000) {
104 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_DIV4SEL, 1); 116 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 1);
105 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0); 117 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0);
106 pVal = 40; 118 pVal = 40;
107 } else if (frequency <= 1300000) { 119 } else if (frequency <= 1300000) {
108 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_DIV4SEL, 1); 120 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 1);
109 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1); 121 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1);
110 pVal = 40; 122 pVal = 40;
111 } else if (frequency <= 2046000) { 123 } else if (frequency <= 2046000) {
112 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_DIV4SEL, 0); 124 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 0);
113 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0); 125 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 0);
114 pVal = 20; 126 pVal = 20;
115 } else { 127 } else {
116 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_DIV4SEL, 0); 128 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_DIV4SEL, 0);
117 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1); 129 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_PRESC32_ON, 1);
118 pVal = 20; 130 pVal = 20;
119 } 131 }
120 132
@@ -130,21 +142,21 @@ static int stv6110x_set_frequency(struct dvb_frontend *fe, u32 frequency)
130 divider = (frequency * R_DIV(rDivOpt) * pVal) / REFCLOCK_kHz; 142 divider = (frequency * R_DIV(rDivOpt) * pVal) / REFCLOCK_kHz;
131 divider = (divider + 5) / 10; 143 divider = (divider + 5) / 10;
132 144
133 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_R_DIV, rDivOpt); 145 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_R_DIV, rDivOpt);
134 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG1], TNG1_N_DIV_11_8, MSB(divider)); 146 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG1], TNG1_N_DIV_11_8, MSB(divider));
135 STV6110x_SETFIELD(stv6110x_regs[STV6110x_TNG0], TNG0_N_DIV_7_0, LSB(divider)); 147 STV6110x_SETFIELD(stv6110x->regs[STV6110x_TNG0], TNG0_N_DIV_7_0, LSB(divider));
136 148
137 /* VCO Auto calibration */ 149 /* VCO Auto calibration */
138 STV6110x_SETFIELD(stv6110x_regs[STV6110x_STAT1], STAT1_CALVCO_STRT, 1); 150 STV6110x_SETFIELD(stv6110x->regs[STV6110x_STAT1], STAT1_CALVCO_STRT, 1);
139 151
140 stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x_regs[STV6110x_CTRL1]); 152 stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x->regs[STV6110x_CTRL1]);
141 stv6110x_write_reg(stv6110x, STV6110x_TNG1, stv6110x_regs[STV6110x_TNG1]); 153 stv6110x_write_reg(stv6110x, STV6110x_TNG1, stv6110x->regs[STV6110x_TNG1]);
142 stv6110x_write_reg(stv6110x, STV6110x_TNG0, stv6110x_regs[STV6110x_TNG0]); 154 stv6110x_write_reg(stv6110x, STV6110x_TNG0, stv6110x->regs[STV6110x_TNG0]);
143 stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x_regs[STV6110x_STAT1]); 155 stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x->regs[STV6110x_STAT1]);
144 156
145 for (i = 0; i < TRIALS; i++) { 157 for (i = 0; i < TRIALS; i++) {
146 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x_regs[STV6110x_STAT1]); 158 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
147 if (!STV6110x_GETFIELD(STAT1_CALVCO_STRT, stv6110x_regs[STV6110x_STAT1])) 159 if (!STV6110x_GETFIELD(STAT1_CALVCO_STRT, stv6110x->regs[STV6110x_STAT1]))
148 break; 160 break;
149 msleep(1); 161 msleep(1);
150 } 162 }
@@ -156,14 +168,14 @@ static int stv6110x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
156{ 168{
157 struct stv6110x_state *stv6110x = fe->tuner_priv; 169 struct stv6110x_state *stv6110x = fe->tuner_priv;
158 170
159 stv6110x_read_reg(stv6110x, STV6110x_TNG1, &stv6110x_regs[STV6110x_TNG1]); 171 stv6110x_read_reg(stv6110x, STV6110x_TNG1, &stv6110x->regs[STV6110x_TNG1]);
160 stv6110x_read_reg(stv6110x, STV6110x_TNG0, &stv6110x_regs[STV6110x_TNG0]); 172 stv6110x_read_reg(stv6110x, STV6110x_TNG0, &stv6110x->regs[STV6110x_TNG0]);
161 173
162 *frequency = (MAKEWORD16(STV6110x_GETFIELD(TNG1_N_DIV_11_8, stv6110x_regs[STV6110x_TNG1]), 174 *frequency = (MAKEWORD16(STV6110x_GETFIELD(TNG1_N_DIV_11_8, stv6110x->regs[STV6110x_TNG1]),
163 STV6110x_GETFIELD(TNG0_N_DIV_7_0, stv6110x_regs[STV6110x_TNG0]))) * REFCLOCK_kHz; 175 STV6110x_GETFIELD(TNG0_N_DIV_7_0, stv6110x->regs[STV6110x_TNG0]))) * REFCLOCK_kHz;
164 176
165 *frequency /= (1 << (STV6110x_GETFIELD(TNG1_R_DIV, stv6110x_regs[STV6110x_TNG1]) + 177 *frequency /= (1 << (STV6110x_GETFIELD(TNG1_R_DIV, stv6110x->regs[STV6110x_TNG1]) +
166 STV6110x_GETFIELD(TNG1_DIV4SEL, stv6110x_regs[STV6110x_TNG1]))); 178 STV6110x_GETFIELD(TNG1_DIV4SEL, stv6110x->regs[STV6110x_TNG1])));
167 179
168 *frequency >>= 2; 180 *frequency >>= 2;
169 181
@@ -179,27 +191,27 @@ static int stv6110x_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
179 halfbw = bandwidth >> 1; 191 halfbw = bandwidth >> 1;
180 192
181 if (halfbw > 36000000) 193 if (halfbw > 36000000)
182 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_CF, 31); /* LPF */ 194 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, 31); /* LPF */
183 else if (halfbw < 5000000) 195 else if (halfbw < 5000000)
184 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_CF, 0); /* LPF */ 196 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, 0); /* LPF */
185 else 197 else
186 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_CF, ((halfbw / 1000000) - 5)); /* LPF */ 198 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_CF, ((halfbw / 1000000) - 5)); /* LPF */
187 199
188 200
189 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x0); /* cal. clk activated */ 201 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x0); /* cal. clk activated */
190 STV6110x_SETFIELD(stv6110x_regs[STV6110x_STAT1], STAT1_CALRC_STRT, 0x1); /* LPF auto cal */ 202 STV6110x_SETFIELD(stv6110x->regs[STV6110x_STAT1], STAT1_CALRC_STRT, 0x1); /* LPF auto cal */
191 203
192 stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x_regs[STV6110x_CTRL3]); 204 stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x->regs[STV6110x_CTRL3]);
193 stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x_regs[STV6110x_STAT1]); 205 stv6110x_write_reg(stv6110x, STV6110x_STAT1, stv6110x->regs[STV6110x_STAT1]);
194 206
195 for (i = 0; i < TRIALS; i++) { 207 for (i = 0; i < TRIALS; i++) {
196 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x_regs[STV6110x_STAT1]); 208 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
197 if (!STV6110x_GETFIELD(STAT1_CALRC_STRT, stv6110x_regs[STV6110x_STAT1])) 209 if (!STV6110x_GETFIELD(STAT1_CALRC_STRT, stv6110x->regs[STV6110x_STAT1]))
198 break; 210 break;
199 msleep(1); 211 msleep(1);
200 } 212 }
201 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x1); /* cal. done */ 213 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL3], CTRL3_RCCLK_OFF, 0x1); /* cal. done */
202 stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x_regs[STV6110x_CTRL3]); 214 stv6110x_write_reg(stv6110x, STV6110x_CTRL3, stv6110x->regs[STV6110x_CTRL3]);
203 215
204 return 0; 216 return 0;
205} 217}
@@ -208,8 +220,8 @@ static int stv6110x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
208{ 220{
209 struct stv6110x_state *stv6110x = fe->tuner_priv; 221 struct stv6110x_state *stv6110x = fe->tuner_priv;
210 222
211 stv6110x_read_reg(stv6110x, STV6110x_CTRL3, &stv6110x_regs[STV6110x_CTRL3]); 223 stv6110x_read_reg(stv6110x, STV6110x_CTRL3, &stv6110x->regs[STV6110x_CTRL3]);
212 *bandwidth = (STV6110x_GETFIELD(CTRL3_CF, stv6110x_regs[STV6110x_CTRL3]) + 5) * 2000000; 224 *bandwidth = (STV6110x_GETFIELD(CTRL3_CF, stv6110x->regs[STV6110x_CTRL3]) + 5) * 2000000;
213 225
214 return 0; 226 return 0;
215} 227}
@@ -222,20 +234,20 @@ static int stv6110x_set_refclock(struct dvb_frontend *fe, u32 refclock)
222 switch (refclock) { 234 switch (refclock) {
223 default: 235 default:
224 case 1: 236 case 1:
225 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0); 237 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0);
226 break; 238 break;
227 case 2: 239 case 2:
228 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1); 240 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1);
229 break; 241 break;
230 case 4: 242 case 4:
231 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2); 243 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2);
232 break; 244 break;
233 case 8: 245 case 8:
234 case 0: 246 case 0:
235 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3); 247 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3);
236 break; 248 break;
237 } 249 }
238 stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x_regs[STV6110x_CTRL2]); 250 stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x->regs[STV6110x_CTRL2]);
239 251
240 return 0; 252 return 0;
241} 253}
@@ -244,8 +256,8 @@ static int stv6110x_get_bbgain(struct dvb_frontend *fe, u32 *gain)
244{ 256{
245 struct stv6110x_state *stv6110x = fe->tuner_priv; 257 struct stv6110x_state *stv6110x = fe->tuner_priv;
246 258
247 stv6110x_read_reg(stv6110x, STV6110x_CTRL2, &stv6110x_regs[STV6110x_CTRL2]); 259 stv6110x_read_reg(stv6110x, STV6110x_CTRL2, &stv6110x->regs[STV6110x_CTRL2]);
248 *gain = 2 * STV6110x_GETFIELD(CTRL2_BBGAIN, stv6110x_regs[STV6110x_CTRL2]); 260 *gain = 2 * STV6110x_GETFIELD(CTRL2_BBGAIN, stv6110x->regs[STV6110x_CTRL2]);
249 261
250 return 0; 262 return 0;
251} 263}
@@ -254,8 +266,8 @@ static int stv6110x_set_bbgain(struct dvb_frontend *fe, u32 gain)
254{ 266{
255 struct stv6110x_state *stv6110x = fe->tuner_priv; 267 struct stv6110x_state *stv6110x = fe->tuner_priv;
256 268
257 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL2], CTRL2_BBGAIN, gain / 2); 269 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_BBGAIN, gain / 2);
258 stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x_regs[STV6110x_CTRL2]); 270 stv6110x_write_reg(stv6110x, STV6110x_CTRL2, stv6110x->regs[STV6110x_CTRL2]);
259 271
260 return 0; 272 return 0;
261} 273}
@@ -267,19 +279,19 @@ static int stv6110x_set_mode(struct dvb_frontend *fe, enum tuner_mode mode)
267 279
268 switch (mode) { 280 switch (mode) {
269 case TUNER_SLEEP: 281 case TUNER_SLEEP:
270 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_SYN, 0); 282 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_SYN, 0);
271 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_RX, 0); 283 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_RX, 0);
272 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_LPT, 0); 284 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_LPT, 0);
273 break; 285 break;
274 286
275 case TUNER_WAKE: 287 case TUNER_WAKE:
276 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_SYN, 1); 288 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_SYN, 1);
277 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_RX, 1); 289 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_RX, 1);
278 STV6110x_SETFIELD(stv6110x_regs[STV6110x_CTRL1], CTRL1_LPT, 1); 290 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL1], CTRL1_LPT, 1);
279 break; 291 break;
280 } 292 }
281 293
282 ret = stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x_regs[STV6110x_CTRL1]); 294 ret = stv6110x_write_reg(stv6110x, STV6110x_CTRL1, stv6110x->regs[STV6110x_CTRL1]);
283 if (ret < 0) { 295 if (ret < 0) {
284 dprintk(FE_ERROR, 1, "I/O Error"); 296 dprintk(FE_ERROR, 1, "I/O Error");
285 return -EIO; 297 return -EIO;
@@ -297,9 +309,9 @@ static int stv6110x_get_status(struct dvb_frontend *fe, u32 *status)
297{ 309{
298 struct stv6110x_state *stv6110x = fe->tuner_priv; 310 struct stv6110x_state *stv6110x = fe->tuner_priv;
299 311
300 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x_regs[STV6110x_STAT1]); 312 stv6110x_read_reg(stv6110x, STV6110x_STAT1, &stv6110x->regs[STV6110x_STAT1]);
301 313
302 if (STV6110x_GETFIELD(STAT1_LOCK, stv6110x_regs[STV6110x_STAT1])) 314 if (STV6110x_GETFIELD(STAT1_LOCK, stv6110x->regs[STV6110x_STAT1]))
303 *status = TUNER_PHASELOCKED; 315 *status = TUNER_PHASELOCKED;
304 else 316 else
305 *status = 0; 317 *status = 0;
@@ -349,6 +361,8 @@ struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
349 struct i2c_adapter *i2c) 361 struct i2c_adapter *i2c)
350{ 362{
351 struct stv6110x_state *stv6110x; 363 struct stv6110x_state *stv6110x;
364 u8 default_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e};
365 int ret;
352 366
353 stv6110x = kzalloc(sizeof (struct stv6110x_state), GFP_KERNEL); 367 stv6110x = kzalloc(sizeof (struct stv6110x_state), GFP_KERNEL);
354 if (stv6110x == NULL) 368 if (stv6110x == NULL)
@@ -357,6 +371,44 @@ struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
357 stv6110x->i2c = i2c; 371 stv6110x->i2c = i2c;
358 stv6110x->config = config; 372 stv6110x->config = config;
359 stv6110x->devctl = &stv6110x_ctl; 373 stv6110x->devctl = &stv6110x_ctl;
374 memcpy(stv6110x->regs, default_regs, 8);
375
376 /* setup divider */
377 switch (stv6110x->config->clk_div) {
378 default:
379 case 1:
380 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 0);
381 break;
382 case 2:
383 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 1);
384 break;
385 case 4:
386 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 2);
387 break;
388 case 8:
389 case 0:
390 STV6110x_SETFIELD(stv6110x->regs[STV6110x_CTRL2], CTRL2_CO_DIV, 3);
391 break;
392 }
393
394 if (fe->ops.i2c_gate_ctrl) {
395 ret = fe->ops.i2c_gate_ctrl(fe, 1);
396 if (ret < 0)
397 goto error;
398 }
399
400 ret = stv6110x_write_regs(stv6110x, 0, stv6110x->regs,
401 ARRAY_SIZE(stv6110x->regs));
402 if (ret < 0) {
403 dprintk(FE_ERROR, 1, "Initialization failed");
404 goto error;
405 }
406
407 if (fe->ops.i2c_gate_ctrl) {
408 ret = fe->ops.i2c_gate_ctrl(fe, 0);
409 if (ret < 0)
410 goto error;
411 }
360 412
361 fe->tuner_priv = stv6110x; 413 fe->tuner_priv = stv6110x;
362 fe->ops.tuner_ops = stv6110x_ops; 414 fe->ops.tuner_ops = stv6110x_ops;
diff --git a/drivers/media/dvb/frontends/stv6110x.h b/drivers/media/dvb/frontends/stv6110x.h
index a38257080e01..2429ae6d7847 100644
--- a/drivers/media/dvb/frontends/stv6110x.h
+++ b/drivers/media/dvb/frontends/stv6110x.h
@@ -26,6 +26,7 @@
26struct stv6110x_config { 26struct stv6110x_config {
27 u8 addr; 27 u8 addr;
28 u32 refclk; 28 u32 refclk;
29 u8 clk_div; /* divisor value for the output clock */
29}; 30};
30 31
31enum tuner_mode { 32enum tuner_mode {
diff --git a/drivers/media/dvb/frontends/stv6110x_priv.h b/drivers/media/dvb/frontends/stv6110x_priv.h
index 7260da633d49..0ec936a660a7 100644
--- a/drivers/media/dvb/frontends/stv6110x_priv.h
+++ b/drivers/media/dvb/frontends/stv6110x_priv.h
@@ -68,6 +68,7 @@
68struct stv6110x_state { 68struct stv6110x_state {
69 struct i2c_adapter *i2c; 69 struct i2c_adapter *i2c;
70 const struct stv6110x_config *config; 70 const struct stv6110x_config *config;
71 u8 regs[8];
71 72
72 struct stv6110x_devctl *devctl; 73 struct stv6110x_devctl *devctl;
73}; 74};
diff --git a/drivers/media/dvb/frontends/tda665x.c b/drivers/media/dvb/frontends/tda665x.c
index 87d52739c828..c44fefe92d97 100644
--- a/drivers/media/dvb/frontends/tda665x.c
+++ b/drivers/media/dvb/frontends/tda665x.c
@@ -133,7 +133,7 @@ static int tda665x_set_state(struct dvb_frontend *fe,
133 frequency += config->ref_divider >> 1; 133 frequency += config->ref_divider >> 1;
134 frequency /= config->ref_divider; 134 frequency /= config->ref_divider;
135 135
136 buf[0] = (u8) (frequency & 0x7f00) >> 8; 136 buf[0] = (u8) ((frequency & 0x7f00) >> 8);
137 buf[1] = (u8) (frequency & 0x00ff) >> 0; 137 buf[1] = (u8) (frequency & 0x00ff) >> 0;
138 buf[2] = 0x80 | 0x40 | 0x02; 138 buf[2] = 0x80 | 0x40 | 0x02;
139 buf[3] = 0x00; 139 buf[3] = 0x00;
diff --git a/drivers/media/dvb/frontends/tda8261.c b/drivers/media/dvb/frontends/tda8261.c
index 320c3c36d8b2..614afcec05f1 100644
--- a/drivers/media/dvb/frontends/tda8261.c
+++ b/drivers/media/dvb/frontends/tda8261.c
@@ -39,7 +39,7 @@ static int tda8261_read(struct tda8261_state *state, u8 *buf)
39{ 39{
40 const struct tda8261_config *config = state->config; 40 const struct tda8261_config *config = state->config;
41 int err = 0; 41 int err = 0;
42 struct i2c_msg msg = { .addr = config->addr, .flags = I2C_M_RD,.buf = buf, .len = 2 }; 42 struct i2c_msg msg = { .addr = config->addr, .flags = I2C_M_RD,.buf = buf, .len = 1 };
43 43
44 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) 44 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1)
45 printk("%s: read error, err=%d\n", __func__, err); 45 printk("%s: read error, err=%d\n", __func__, err);
diff --git a/drivers/media/dvb/frontends/zl10036.c b/drivers/media/dvb/frontends/zl10036.c
index 4e814ff22b23..34c5de491d2b 100644
--- a/drivers/media/dvb/frontends/zl10036.c
+++ b/drivers/media/dvb/frontends/zl10036.c
@@ -411,7 +411,7 @@ static int zl10036_init_regs(struct zl10036_state *state)
411 state->bf = 0xff; 411 state->bf = 0xff;
412 412
413 if (!state->config->rf_loop_enable) 413 if (!state->config->rf_loop_enable)
414 zl10036_init_tab[1][2] |= 0x01; 414 zl10036_init_tab[1][0] |= 0x01;
415 415
416 deb_info("%s\n", __func__); 416 deb_info("%s\n", __func__);
417 417
diff --git a/drivers/media/dvb/frontends/zl10039.c b/drivers/media/dvb/frontends/zl10039.c
index 11b29cb883e6..c085e58a94bf 100644
--- a/drivers/media/dvb/frontends/zl10039.c
+++ b/drivers/media/dvb/frontends/zl10039.c
@@ -287,7 +287,6 @@ struct dvb_frontend *zl10039_attach(struct dvb_frontend *fe,
287 break; 287 break;
288 default: 288 default:
289 dprintk("Chip ID=%x does not match a known type\n", state->id); 289 dprintk("Chip ID=%x does not match a known type\n", state->id);
290 break;
291 goto error; 290 goto error;
292 } 291 }
293 292
diff --git a/drivers/media/dvb/mantis/mantis_hif.c b/drivers/media/dvb/mantis/mantis_hif.c
index 7477dac628b4..5772ebb3a69e 100644
--- a/drivers/media/dvb/mantis/mantis_hif.c
+++ b/drivers/media/dvb/mantis/mantis_hif.c
@@ -22,8 +22,6 @@
22#include <linux/signal.h> 22#include <linux/signal.h>
23#include <linux/sched.h> 23#include <linux/sched.h>
24 24
25#include <linux/signal.h>
26#include <linux/sched.h>
27#include <linux/interrupt.h> 25#include <linux/interrupt.h>
28 26
29#include "dmxdev.h" 27#include "dmxdev.h"
diff --git a/drivers/media/dvb/mantis/mantis_input.c b/drivers/media/dvb/mantis/mantis_input.c
index 6a9df779441f..4675a3b53c7d 100644
--- a/drivers/media/dvb/mantis/mantis_input.c
+++ b/drivers/media/dvb/mantis/mantis_input.c
@@ -126,7 +126,7 @@ int mantis_input_init(struct mantis_pci *mantis)
126 rc->id.version = 1; 126 rc->id.version = 1;
127 rc->dev = mantis->pdev->dev; 127 rc->dev = mantis->pdev->dev;
128 128
129 err = ir_input_register(rc, &ir_mantis); 129 err = ir_input_register(rc, &ir_mantis, NULL);
130 if (err) { 130 if (err) {
131 dprintk(MANTIS_ERROR, 1, "IR device registration failed, ret = %d", err); 131 dprintk(MANTIS_ERROR, 1, "IR device registration failed, ret = %d", err);
132 input_free_device(rc); 132 input_free_device(rc);
diff --git a/drivers/media/dvb/mantis/mantis_pci.c b/drivers/media/dvb/mantis/mantis_pci.c
index 6c7534af6b44..59feeb84aec7 100644
--- a/drivers/media/dvb/mantis/mantis_pci.c
+++ b/drivers/media/dvb/mantis/mantis_pci.c
@@ -41,11 +41,6 @@
41#include "dvb_frontend.h" 41#include "dvb_frontend.h"
42#include "dvb_net.h" 42#include "dvb_net.h"
43 43
44#include <asm/irq.h>
45#include <linux/signal.h>
46#include <linux/sched.h>
47#include <linux/interrupt.h>
48
49#include "mantis_common.h" 44#include "mantis_common.h"
50#include "mantis_reg.h" 45#include "mantis_reg.h"
51#include "mantis_pci.h" 46#include "mantis_pci.h"
diff --git a/drivers/media/dvb/ngene/Kconfig b/drivers/media/dvb/ngene/Kconfig
new file mode 100644
index 000000000000..3ec8e6fcbb1d
--- /dev/null
+++ b/drivers/media/dvb/ngene/Kconfig
@@ -0,0 +1,9 @@
1config DVB_NGENE
2 tristate "Micronas nGene support"
3 depends on DVB_CORE && PCI && I2C
4 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
5 select DVB_STV6110x if !DVB_FE_CUSTOMISE
6 select DVB_STV090x if !DVB_FE_CUSTOMISE
7 ---help---
8 Support for Micronas PCI express cards with nGene bridge.
9
diff --git a/drivers/media/dvb/ngene/Makefile b/drivers/media/dvb/ngene/Makefile
new file mode 100644
index 000000000000..40435cad4819
--- /dev/null
+++ b/drivers/media/dvb/ngene/Makefile
@@ -0,0 +1,11 @@
1#
2# Makefile for the nGene device driver
3#
4
5ngene-objs := ngene-core.o
6
7obj-$(CONFIG_DVB_NGENE) += ngene.o
8
9EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
10EXTRA_CFLAGS += -Idrivers/media/dvb/frontends/
11
diff --git a/drivers/media/dvb/ngene/ngene-core.c b/drivers/media/dvb/ngene/ngene-core.c
new file mode 100644
index 000000000000..0150dfe7cfbb
--- /dev/null
+++ b/drivers/media/dvb/ngene/ngene-core.c
@@ -0,0 +1,2024 @@
1/*
2 * ngene.c: nGene PCIe bridge driver
3 *
4 * Copyright (C) 2005-2007 Micronas
5 *
6 * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de>
7 * Modifications for new nGene firmware,
8 * support for EEPROM-copying,
9 * support for new dual DVB-S2 card prototype
10 *
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * version 2 only, as published by the Free Software Foundation.
15 *
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 *
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., 51 Franklin Street, Fifth Floor, Boston, MA
26 * 02110-1301, USA
27 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
28 */
29
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/delay.h>
33#include <linux/slab.h>
34#include <linux/poll.h>
35#include <linux/io.h>
36#include <asm/div64.h>
37#include <linux/pci.h>
38#include <linux/pci_ids.h>
39#include <linux/smp_lock.h>
40#include <linux/timer.h>
41#include <linux/version.h>
42#include <linux/byteorder/generic.h>
43#include <linux/firmware.h>
44#include <linux/vmalloc.h>
45
46#include "ngene.h"
47
48#include "stv6110x.h"
49#include "stv090x.h"
50#include "lnbh24.h"
51
52static int one_adapter = 1;
53module_param(one_adapter, int, 0444);
54MODULE_PARM_DESC(one_adapter, "Use only one adapter.");
55
56
57static int debug;
58module_param(debug, int, 0444);
59MODULE_PARM_DESC(debug, "Print debugging information.");
60
61DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
62
63#define COMMAND_TIMEOUT_WORKAROUND
64
65#define dprintk if (debug) printk
66
67#define DEVICE_NAME "ngene"
68
69#define ngwriteb(dat, adr) writeb((dat), (char *)(dev->iomem + (adr)))
70#define ngwritel(dat, adr) writel((dat), (char *)(dev->iomem + (adr)))
71#define ngwriteb(dat, adr) writeb((dat), (char *)(dev->iomem + (adr)))
72#define ngreadl(adr) readl(dev->iomem + (adr))
73#define ngreadb(adr) readb(dev->iomem + (adr))
74#define ngcpyto(adr, src, count) memcpy_toio((char *) \
75 (dev->iomem + (adr)), (src), (count))
76#define ngcpyfrom(dst, adr, count) memcpy_fromio((dst), (char *) \
77 (dev->iomem + (adr)), (count))
78
79/****************************************************************************/
80/* nGene interrupt handler **************************************************/
81/****************************************************************************/
82
83static void event_tasklet(unsigned long data)
84{
85 struct ngene *dev = (struct ngene *)data;
86
87 while (dev->EventQueueReadIndex != dev->EventQueueWriteIndex) {
88 struct EVENT_BUFFER Event =
89 dev->EventQueue[dev->EventQueueReadIndex];
90 dev->EventQueueReadIndex =
91 (dev->EventQueueReadIndex + 1) & (EVENT_QUEUE_SIZE - 1);
92
93 if ((Event.UARTStatus & 0x01) && (dev->TxEventNotify))
94 dev->TxEventNotify(dev, Event.TimeStamp);
95 if ((Event.UARTStatus & 0x02) && (dev->RxEventNotify))
96 dev->RxEventNotify(dev, Event.TimeStamp,
97 Event.RXCharacter);
98 }
99}
100
101static void demux_tasklet(unsigned long data)
102{
103 struct ngene_channel *chan = (struct ngene_channel *)data;
104 struct SBufferHeader *Cur = chan->nextBuffer;
105
106 spin_lock_irq(&chan->state_lock);
107
108 while (Cur->ngeneBuffer.SR.Flags & 0x80) {
109 if (chan->mode & NGENE_IO_TSOUT) {
110 u32 Flags = chan->DataFormatFlags;
111 if (Cur->ngeneBuffer.SR.Flags & 0x20)
112 Flags |= BEF_OVERFLOW;
113 if (chan->pBufferExchange) {
114 if (!chan->pBufferExchange(chan,
115 Cur->Buffer1,
116 chan->Capture1Length,
117 Cur->ngeneBuffer.SR.
118 Clock, Flags)) {
119 /*
120 We didn't get data
121 Clear in service flag to make sure we
122 get called on next interrupt again.
123 leave fill/empty (0x80) flag alone
124 to avoid hardware running out of
125 buffers during startup, we hold only
126 in run state ( the source may be late
127 delivering data )
128 */
129
130 if (chan->HWState == HWSTATE_RUN) {
131 Cur->ngeneBuffer.SR.Flags &=
132 ~0x40;
133 break;
134 /* Stop proccessing stream */
135 }
136 } else {
137 /* We got a valid buffer,
138 so switch to run state */
139 chan->HWState = HWSTATE_RUN;
140 }
141 } else {
142 printk(KERN_ERR DEVICE_NAME ": OOPS\n");
143 if (chan->HWState == HWSTATE_RUN) {
144 Cur->ngeneBuffer.SR.Flags &= ~0x40;
145 break; /* Stop proccessing stream */
146 }
147 }
148 if (chan->AudioDTOUpdated) {
149 printk(KERN_INFO DEVICE_NAME
150 ": Update AudioDTO = %d\n",
151 chan->AudioDTOValue);
152 Cur->ngeneBuffer.SR.DTOUpdate =
153 chan->AudioDTOValue;
154 chan->AudioDTOUpdated = 0;
155 }
156 } else {
157 if (chan->HWState == HWSTATE_RUN) {
158 u32 Flags = 0;
159 if (Cur->ngeneBuffer.SR.Flags & 0x01)
160 Flags |= BEF_EVEN_FIELD;
161 if (Cur->ngeneBuffer.SR.Flags & 0x20)
162 Flags |= BEF_OVERFLOW;
163 if (chan->pBufferExchange)
164 chan->pBufferExchange(chan,
165 Cur->Buffer1,
166 chan->
167 Capture1Length,
168 Cur->ngeneBuffer.
169 SR.Clock, Flags);
170 if (chan->pBufferExchange2)
171 chan->pBufferExchange2(chan,
172 Cur->Buffer2,
173 chan->
174 Capture2Length,
175 Cur->ngeneBuffer.
176 SR.Clock, Flags);
177 } else if (chan->HWState != HWSTATE_STOP)
178 chan->HWState = HWSTATE_RUN;
179 }
180 Cur->ngeneBuffer.SR.Flags = 0x00;
181 Cur = Cur->Next;
182 }
183 chan->nextBuffer = Cur;
184
185 spin_unlock_irq(&chan->state_lock);
186}
187
188static irqreturn_t irq_handler(int irq, void *dev_id)
189{
190 struct ngene *dev = (struct ngene *)dev_id;
191 u32 icounts = 0;
192 irqreturn_t rc = IRQ_NONE;
193 u32 i = MAX_STREAM;
194 u8 *tmpCmdDoneByte;
195
196 if (dev->BootFirmware) {
197 icounts = ngreadl(NGENE_INT_COUNTS);
198 if (icounts != dev->icounts) {
199 ngwritel(0, FORCE_NMI);
200 dev->cmd_done = 1;
201 wake_up(&dev->cmd_wq);
202 dev->icounts = icounts;
203 rc = IRQ_HANDLED;
204 }
205 return rc;
206 }
207
208 ngwritel(0, FORCE_NMI);
209
210 spin_lock(&dev->cmd_lock);
211 tmpCmdDoneByte = dev->CmdDoneByte;
212 if (tmpCmdDoneByte &&
213 (*tmpCmdDoneByte ||
214 (dev->ngenetohost[0] == 1 && dev->ngenetohost[1] != 0))) {
215 dev->CmdDoneByte = NULL;
216 dev->cmd_done = 1;
217 wake_up(&dev->cmd_wq);
218 rc = IRQ_HANDLED;
219 }
220 spin_unlock(&dev->cmd_lock);
221
222 if (dev->EventBuffer->EventStatus & 0x80) {
223 u8 nextWriteIndex =
224 (dev->EventQueueWriteIndex + 1) &
225 (EVENT_QUEUE_SIZE - 1);
226 if (nextWriteIndex != dev->EventQueueReadIndex) {
227 dev->EventQueue[dev->EventQueueWriteIndex] =
228 *(dev->EventBuffer);
229 dev->EventQueueWriteIndex = nextWriteIndex;
230 } else {
231 printk(KERN_ERR DEVICE_NAME ": event overflow\n");
232 dev->EventQueueOverflowCount += 1;
233 dev->EventQueueOverflowFlag = 1;
234 }
235 dev->EventBuffer->EventStatus &= ~0x80;
236 tasklet_schedule(&dev->event_tasklet);
237 rc = IRQ_HANDLED;
238 }
239
240 while (i > 0) {
241 i--;
242 spin_lock(&dev->channel[i].state_lock);
243 /* if (dev->channel[i].State>=KSSTATE_RUN) { */
244 if (dev->channel[i].nextBuffer) {
245 if ((dev->channel[i].nextBuffer->
246 ngeneBuffer.SR.Flags & 0xC0) == 0x80) {
247 dev->channel[i].nextBuffer->
248 ngeneBuffer.SR.Flags |= 0x40;
249 tasklet_schedule(
250 &dev->channel[i].demux_tasklet);
251 rc = IRQ_HANDLED;
252 }
253 }
254 spin_unlock(&dev->channel[i].state_lock);
255 }
256
257 /* Request might have been processed by a previous call. */
258 return IRQ_HANDLED;
259}
260
261/****************************************************************************/
262/* nGene command interface **************************************************/
263/****************************************************************************/
264
265static void dump_command_io(struct ngene *dev)
266{
267 u8 buf[8], *b;
268
269 ngcpyfrom(buf, HOST_TO_NGENE, 8);
270 printk(KERN_ERR "host_to_ngene (%04x): %02x %02x %02x %02x %02x %02x %02x %02x\n",
271 HOST_TO_NGENE, buf[0], buf[1], buf[2], buf[3],
272 buf[4], buf[5], buf[6], buf[7]);
273
274 ngcpyfrom(buf, NGENE_TO_HOST, 8);
275 printk(KERN_ERR "ngene_to_host (%04x): %02x %02x %02x %02x %02x %02x %02x %02x\n",
276 NGENE_TO_HOST, buf[0], buf[1], buf[2], buf[3],
277 buf[4], buf[5], buf[6], buf[7]);
278
279 b = dev->hosttongene;
280 printk(KERN_ERR "dev->hosttongene (%p): %02x %02x %02x %02x %02x %02x %02x %02x\n",
281 b, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
282
283 b = dev->ngenetohost;
284 printk(KERN_ERR "dev->ngenetohost (%p): %02x %02x %02x %02x %02x %02x %02x %02x\n",
285 b, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
286}
287
288static int ngene_command_mutex(struct ngene *dev, struct ngene_command *com)
289{
290 int ret;
291 u8 *tmpCmdDoneByte;
292
293 dev->cmd_done = 0;
294
295 if (com->cmd.hdr.Opcode == CMD_FWLOAD_PREPARE) {
296 dev->BootFirmware = 1;
297 dev->icounts = ngreadl(NGENE_INT_COUNTS);
298 ngwritel(0, NGENE_COMMAND);
299 ngwritel(0, NGENE_COMMAND_HI);
300 ngwritel(0, NGENE_STATUS);
301 ngwritel(0, NGENE_STATUS_HI);
302 ngwritel(0, NGENE_EVENT);
303 ngwritel(0, NGENE_EVENT_HI);
304 } else if (com->cmd.hdr.Opcode == CMD_FWLOAD_FINISH) {
305 u64 fwio = dev->PAFWInterfaceBuffer;
306
307 ngwritel(fwio & 0xffffffff, NGENE_COMMAND);
308 ngwritel(fwio >> 32, NGENE_COMMAND_HI);
309 ngwritel((fwio + 256) & 0xffffffff, NGENE_STATUS);
310 ngwritel((fwio + 256) >> 32, NGENE_STATUS_HI);
311 ngwritel((fwio + 512) & 0xffffffff, NGENE_EVENT);
312 ngwritel((fwio + 512) >> 32, NGENE_EVENT_HI);
313 }
314
315 memcpy(dev->FWInterfaceBuffer, com->cmd.raw8, com->in_len + 2);
316
317 if (dev->BootFirmware)
318 ngcpyto(HOST_TO_NGENE, com->cmd.raw8, com->in_len + 2);
319
320 spin_lock_irq(&dev->cmd_lock);
321 tmpCmdDoneByte = dev->ngenetohost + com->out_len;
322 if (!com->out_len)
323 tmpCmdDoneByte++;
324 *tmpCmdDoneByte = 0;
325 dev->ngenetohost[0] = 0;
326 dev->ngenetohost[1] = 0;
327 dev->CmdDoneByte = tmpCmdDoneByte;
328 spin_unlock_irq(&dev->cmd_lock);
329
330 /* Notify 8051. */
331 ngwritel(1, FORCE_INT);
332
333 ret = wait_event_timeout(dev->cmd_wq, dev->cmd_done == 1, 2 * HZ);
334 if (!ret) {
335 /*ngwritel(0, FORCE_NMI);*/
336
337 printk(KERN_ERR DEVICE_NAME
338 ": Command timeout cmd=%02x prev=%02x\n",
339 com->cmd.hdr.Opcode, dev->prev_cmd);
340 dump_command_io(dev);
341 return -1;
342 }
343 if (com->cmd.hdr.Opcode == CMD_FWLOAD_FINISH)
344 dev->BootFirmware = 0;
345
346 dev->prev_cmd = com->cmd.hdr.Opcode;
347
348 if (!com->out_len)
349 return 0;
350
351 memcpy(com->cmd.raw8, dev->ngenetohost, com->out_len);
352
353 return 0;
354}
355
356static int ngene_command(struct ngene *dev, struct ngene_command *com)
357{
358 int result;
359
360 down(&dev->cmd_mutex);
361 result = ngene_command_mutex(dev, com);
362 up(&dev->cmd_mutex);
363 return result;
364}
365
366
367static int ngene_command_i2c_read(struct ngene *dev, u8 adr,
368 u8 *out, u8 outlen, u8 *in, u8 inlen, int flag)
369{
370 struct ngene_command com;
371
372 com.cmd.hdr.Opcode = CMD_I2C_READ;
373 com.cmd.hdr.Length = outlen + 3;
374 com.cmd.I2CRead.Device = adr << 1;
375 memcpy(com.cmd.I2CRead.Data, out, outlen);
376 com.cmd.I2CRead.Data[outlen] = inlen;
377 com.cmd.I2CRead.Data[outlen + 1] = 0;
378 com.in_len = outlen + 3;
379 com.out_len = inlen + 1;
380
381 if (ngene_command(dev, &com) < 0)
382 return -EIO;
383
384 if ((com.cmd.raw8[0] >> 1) != adr)
385 return -EIO;
386
387 if (flag)
388 memcpy(in, com.cmd.raw8, inlen + 1);
389 else
390 memcpy(in, com.cmd.raw8 + 1, inlen);
391 return 0;
392}
393
394static int ngene_command_i2c_write(struct ngene *dev, u8 adr,
395 u8 *out, u8 outlen)
396{
397 struct ngene_command com;
398
399
400 com.cmd.hdr.Opcode = CMD_I2C_WRITE;
401 com.cmd.hdr.Length = outlen + 1;
402 com.cmd.I2CRead.Device = adr << 1;
403 memcpy(com.cmd.I2CRead.Data, out, outlen);
404 com.in_len = outlen + 1;
405 com.out_len = 1;
406
407 if (ngene_command(dev, &com) < 0)
408 return -EIO;
409
410 if (com.cmd.raw8[0] == 1)
411 return -EIO;
412
413 return 0;
414}
415
416static int ngene_command_load_firmware(struct ngene *dev,
417 u8 *ngene_fw, u32 size)
418{
419#define FIRSTCHUNK (1024)
420 u32 cleft;
421 struct ngene_command com;
422
423 com.cmd.hdr.Opcode = CMD_FWLOAD_PREPARE;
424 com.cmd.hdr.Length = 0;
425 com.in_len = 0;
426 com.out_len = 0;
427
428 ngene_command(dev, &com);
429
430 cleft = (size + 3) & ~3;
431 if (cleft > FIRSTCHUNK) {
432 ngcpyto(PROGRAM_SRAM + FIRSTCHUNK, ngene_fw + FIRSTCHUNK,
433 cleft - FIRSTCHUNK);
434 cleft = FIRSTCHUNK;
435 }
436 ngcpyto(DATA_FIFO_AREA, ngene_fw, cleft);
437
438 memset(&com, 0, sizeof(struct ngene_command));
439 com.cmd.hdr.Opcode = CMD_FWLOAD_FINISH;
440 com.cmd.hdr.Length = 4;
441 com.cmd.FWLoadFinish.Address = DATA_FIFO_AREA;
442 com.cmd.FWLoadFinish.Length = (unsigned short)cleft;
443 com.in_len = 4;
444 com.out_len = 0;
445
446 return ngene_command(dev, &com);
447}
448
449
450static int ngene_command_config_buf(struct ngene *dev, u8 config)
451{
452 struct ngene_command com;
453
454 com.cmd.hdr.Opcode = CMD_CONFIGURE_BUFFER;
455 com.cmd.hdr.Length = 1;
456 com.cmd.ConfigureBuffers.config = config;
457 com.in_len = 1;
458 com.out_len = 0;
459
460 if (ngene_command(dev, &com) < 0)
461 return -EIO;
462 return 0;
463}
464
465static int ngene_command_config_free_buf(struct ngene *dev, u8 *config)
466{
467 struct ngene_command com;
468
469 com.cmd.hdr.Opcode = CMD_CONFIGURE_FREE_BUFFER;
470 com.cmd.hdr.Length = 6;
471 memcpy(&com.cmd.ConfigureBuffers.config, config, 6);
472 com.in_len = 6;
473 com.out_len = 0;
474
475 if (ngene_command(dev, &com) < 0)
476 return -EIO;
477
478 return 0;
479}
480
481static int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level)
482{
483 struct ngene_command com;
484
485 com.cmd.hdr.Opcode = CMD_SET_GPIO_PIN;
486 com.cmd.hdr.Length = 1;
487 com.cmd.SetGpioPin.select = select | (level << 7);
488 com.in_len = 1;
489 com.out_len = 0;
490
491 return ngene_command(dev, &com);
492}
493
494
495/*
496 02000640 is sample on rising edge.
497 02000740 is sample on falling edge.
498 02000040 is ignore "valid" signal
499
500 0: FD_CTL1 Bit 7,6 must be 0,1
501 7 disable(fw controlled)
502 6 0-AUX,1-TS
503 5 0-par,1-ser
504 4 0-lsb/1-msb
505 3,2 reserved
506 1,0 0-no sync, 1-use ext. start, 2-use 0x47, 3-both
507 1: FD_CTL2 has 3-valid must be hi, 2-use valid, 1-edge
508 2: FD_STA is read-only. 0-sync
509 3: FD_INSYNC is number of 47s to trigger "in sync".
510 4: FD_OUTSYNC is number of 47s to trigger "out of sync".
511 5: FD_MAXBYTE1 is low-order of bytes per packet.
512 6: FD_MAXBYTE2 is high-order of bytes per packet.
513 7: Top byte is unused.
514*/
515
516/****************************************************************************/
517
518static u8 TSFeatureDecoderSetup[8 * 4] = {
519 0x42, 0x00, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00,
520 0x40, 0x06, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00, /* DRXH */
521 0x71, 0x07, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00, /* DRXHser */
522 0x72, 0x06, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00, /* S2ser */
523};
524
525/* Set NGENE I2S Config to 16 bit packed */
526static u8 I2SConfiguration[] = {
527 0x00, 0x10, 0x00, 0x00,
528 0x80, 0x10, 0x00, 0x00,
529};
530
531static u8 SPDIFConfiguration[10] = {
532 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
533};
534
535/* Set NGENE I2S Config to transport stream compatible mode */
536
537static u8 TS_I2SConfiguration[4] = { 0x3E, 0x1A, 0x00, 0x00 }; /*3e 18 00 00 ?*/
538
539static u8 TS_I2SOutConfiguration[4] = { 0x80, 0x20, 0x00, 0x00 };
540
541static u8 ITUDecoderSetup[4][16] = {
542 {0x1c, 0x13, 0x01, 0x68, 0x3d, 0x90, 0x14, 0x20, /* SDTV */
543 0x00, 0x00, 0x01, 0xb0, 0x9c, 0x00, 0x00, 0x00},
544 {0x9c, 0x03, 0x23, 0xC0, 0x60, 0x0E, 0x13, 0x00,
545 0x00, 0x00, 0x00, 0x01, 0xB0, 0x00, 0x00, 0x00},
546 {0x9f, 0x00, 0x23, 0xC0, 0x60, 0x0F, 0x13, 0x00, /* HDTV 1080i50 */
547 0x00, 0x00, 0x00, 0x01, 0xB0, 0x00, 0x00, 0x00},
548 {0x9c, 0x01, 0x23, 0xC0, 0x60, 0x0E, 0x13, 0x00, /* HDTV 1080i60 */
549 0x00, 0x00, 0x00, 0x01, 0xB0, 0x00, 0x00, 0x00},
550};
551
552/*
553 * 50 48 60 gleich
554 * 27p50 9f 00 22 80 42 69 18 ...
555 * 27p60 93 00 22 80 82 69 1c ...
556 */
557
558/* Maxbyte to 1144 (for raw data) */
559static u8 ITUFeatureDecoderSetup[8] = {
560 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x04, 0x00
561};
562
563static void FillTSBuffer(void *Buffer, int Length, u32 Flags)
564{
565 u32 *ptr = Buffer;
566
567 memset(Buffer, 0xff, Length);
568 while (Length > 0) {
569 if (Flags & DF_SWAP32)
570 *ptr = 0x471FFF10;
571 else
572 *ptr = 0x10FF1F47;
573 ptr += (188 / 4);
574 Length -= 188;
575 }
576}
577
578
579static void flush_buffers(struct ngene_channel *chan)
580{
581 u8 val;
582
583 do {
584 msleep(1);
585 spin_lock_irq(&chan->state_lock);
586 val = chan->nextBuffer->ngeneBuffer.SR.Flags & 0x80;
587 spin_unlock_irq(&chan->state_lock);
588 } while (val);
589}
590
591static void clear_buffers(struct ngene_channel *chan)
592{
593 struct SBufferHeader *Cur = chan->nextBuffer;
594
595 do {
596 memset(&Cur->ngeneBuffer.SR, 0, sizeof(Cur->ngeneBuffer.SR));
597 if (chan->mode & NGENE_IO_TSOUT)
598 FillTSBuffer(Cur->Buffer1,
599 chan->Capture1Length,
600 chan->DataFormatFlags);
601 Cur = Cur->Next;
602 } while (Cur != chan->nextBuffer);
603
604 if (chan->mode & NGENE_IO_TSOUT) {
605 chan->nextBuffer->ngeneBuffer.SR.DTOUpdate =
606 chan->AudioDTOValue;
607 chan->AudioDTOUpdated = 0;
608
609 Cur = chan->TSIdleBuffer.Head;
610
611 do {
612 memset(&Cur->ngeneBuffer.SR, 0,
613 sizeof(Cur->ngeneBuffer.SR));
614 FillTSBuffer(Cur->Buffer1,
615 chan->Capture1Length,
616 chan->DataFormatFlags);
617 Cur = Cur->Next;
618 } while (Cur != chan->TSIdleBuffer.Head);
619 }
620}
621
622static int ngene_command_stream_control(struct ngene *dev, u8 stream,
623 u8 control, u8 mode, u8 flags)
624{
625 struct ngene_channel *chan = &dev->channel[stream];
626 struct ngene_command com;
627 u16 BsUVI = ((stream & 1) ? 0x9400 : 0x9300);
628 u16 BsSDI = ((stream & 1) ? 0x9600 : 0x9500);
629 u16 BsSPI = ((stream & 1) ? 0x9800 : 0x9700);
630 u16 BsSDO = 0x9B00;
631
632 /* down(&dev->stream_mutex); */
633 while (down_trylock(&dev->stream_mutex)) {
634 printk(KERN_INFO DEVICE_NAME ": SC locked\n");
635 msleep(1);
636 }
637 memset(&com, 0, sizeof(com));
638 com.cmd.hdr.Opcode = CMD_CONTROL;
639 com.cmd.hdr.Length = sizeof(struct FW_STREAM_CONTROL) - 2;
640 com.cmd.StreamControl.Stream = stream | (control ? 8 : 0);
641 if (chan->mode & NGENE_IO_TSOUT)
642 com.cmd.StreamControl.Stream |= 0x07;
643 com.cmd.StreamControl.Control = control |
644 (flags & SFLAG_ORDER_LUMA_CHROMA);
645 com.cmd.StreamControl.Mode = mode;
646 com.in_len = sizeof(struct FW_STREAM_CONTROL);
647 com.out_len = 0;
648
649 dprintk(KERN_INFO DEVICE_NAME
650 ": Stream=%02x, Control=%02x, Mode=%02x\n",
651 com.cmd.StreamControl.Stream, com.cmd.StreamControl.Control,
652 com.cmd.StreamControl.Mode);
653
654 chan->Mode = mode;
655
656 if (!(control & 0x80)) {
657 spin_lock_irq(&chan->state_lock);
658 if (chan->State == KSSTATE_RUN) {
659 chan->State = KSSTATE_ACQUIRE;
660 chan->HWState = HWSTATE_STOP;
661 spin_unlock_irq(&chan->state_lock);
662 if (ngene_command(dev, &com) < 0) {
663 up(&dev->stream_mutex);
664 return -1;
665 }
666 /* clear_buffers(chan); */
667 flush_buffers(chan);
668 up(&dev->stream_mutex);
669 return 0;
670 }
671 spin_unlock_irq(&chan->state_lock);
672 up(&dev->stream_mutex);
673 return 0;
674 }
675
676 if (mode & SMODE_AUDIO_CAPTURE) {
677 com.cmd.StreamControl.CaptureBlockCount =
678 chan->Capture1Length / AUDIO_BLOCK_SIZE;
679 com.cmd.StreamControl.Buffer_Address = chan->RingBuffer.PAHead;
680 } else if (mode & SMODE_TRANSPORT_STREAM) {
681 com.cmd.StreamControl.CaptureBlockCount =
682 chan->Capture1Length / TS_BLOCK_SIZE;
683 com.cmd.StreamControl.MaxLinesPerField =
684 chan->Capture1Length / TS_BLOCK_SIZE;
685 com.cmd.StreamControl.Buffer_Address =
686 chan->TSRingBuffer.PAHead;
687 if (chan->mode & NGENE_IO_TSOUT) {
688 com.cmd.StreamControl.BytesPerVBILine =
689 chan->Capture1Length / TS_BLOCK_SIZE;
690 com.cmd.StreamControl.Stream |= 0x07;
691 }
692 } else {
693 com.cmd.StreamControl.BytesPerVideoLine = chan->nBytesPerLine;
694 com.cmd.StreamControl.MaxLinesPerField = chan->nLines;
695 com.cmd.StreamControl.MinLinesPerField = 100;
696 com.cmd.StreamControl.Buffer_Address = chan->RingBuffer.PAHead;
697
698 if (mode & SMODE_VBI_CAPTURE) {
699 com.cmd.StreamControl.MaxVBILinesPerField =
700 chan->nVBILines;
701 com.cmd.StreamControl.MinVBILinesPerField = 0;
702 com.cmd.StreamControl.BytesPerVBILine =
703 chan->nBytesPerVBILine;
704 }
705 if (flags & SFLAG_COLORBAR)
706 com.cmd.StreamControl.Stream |= 0x04;
707 }
708
709 spin_lock_irq(&chan->state_lock);
710 if (mode & SMODE_AUDIO_CAPTURE) {
711 chan->nextBuffer = chan->RingBuffer.Head;
712 if (mode & SMODE_AUDIO_SPDIF) {
713 com.cmd.StreamControl.SetupDataLen =
714 sizeof(SPDIFConfiguration);
715 com.cmd.StreamControl.SetupDataAddr = BsSPI;
716 memcpy(com.cmd.StreamControl.SetupData,
717 SPDIFConfiguration, sizeof(SPDIFConfiguration));
718 } else {
719 com.cmd.StreamControl.SetupDataLen = 4;
720 com.cmd.StreamControl.SetupDataAddr = BsSDI;
721 memcpy(com.cmd.StreamControl.SetupData,
722 I2SConfiguration +
723 4 * dev->card_info->i2s[stream], 4);
724 }
725 } else if (mode & SMODE_TRANSPORT_STREAM) {
726 chan->nextBuffer = chan->TSRingBuffer.Head;
727 if (stream >= STREAM_AUDIOIN1) {
728 if (chan->mode & NGENE_IO_TSOUT) {
729 com.cmd.StreamControl.SetupDataLen =
730 sizeof(TS_I2SOutConfiguration);
731 com.cmd.StreamControl.SetupDataAddr = BsSDO;
732 memcpy(com.cmd.StreamControl.SetupData,
733 TS_I2SOutConfiguration,
734 sizeof(TS_I2SOutConfiguration));
735 } else {
736 com.cmd.StreamControl.SetupDataLen =
737 sizeof(TS_I2SConfiguration);
738 com.cmd.StreamControl.SetupDataAddr = BsSDI;
739 memcpy(com.cmd.StreamControl.SetupData,
740 TS_I2SConfiguration,
741 sizeof(TS_I2SConfiguration));
742 }
743 } else {
744 com.cmd.StreamControl.SetupDataLen = 8;
745 com.cmd.StreamControl.SetupDataAddr = BsUVI + 0x10;
746 memcpy(com.cmd.StreamControl.SetupData,
747 TSFeatureDecoderSetup +
748 8 * dev->card_info->tsf[stream], 8);
749 }
750 } else {
751 chan->nextBuffer = chan->RingBuffer.Head;
752 com.cmd.StreamControl.SetupDataLen =
753 16 + sizeof(ITUFeatureDecoderSetup);
754 com.cmd.StreamControl.SetupDataAddr = BsUVI;
755 memcpy(com.cmd.StreamControl.SetupData,
756 ITUDecoderSetup[chan->itumode], 16);
757 memcpy(com.cmd.StreamControl.SetupData + 16,
758 ITUFeatureDecoderSetup, sizeof(ITUFeatureDecoderSetup));
759 }
760 clear_buffers(chan);
761 chan->State = KSSTATE_RUN;
762 if (mode & SMODE_TRANSPORT_STREAM)
763 chan->HWState = HWSTATE_RUN;
764 else
765 chan->HWState = HWSTATE_STARTUP;
766 spin_unlock_irq(&chan->state_lock);
767
768 if (ngene_command(dev, &com) < 0) {
769 up(&dev->stream_mutex);
770 return -1;
771 }
772 up(&dev->stream_mutex);
773 return 0;
774}
775
776
777/****************************************************************************/
778/* I2C **********************************************************************/
779/****************************************************************************/
780
781static void ngene_i2c_set_bus(struct ngene *dev, int bus)
782{
783 if (!(dev->card_info->i2c_access & 2))
784 return;
785 if (dev->i2c_current_bus == bus)
786 return;
787
788 switch (bus) {
789 case 0:
790 ngene_command_gpio_set(dev, 3, 0);
791 ngene_command_gpio_set(dev, 2, 1);
792 break;
793
794 case 1:
795 ngene_command_gpio_set(dev, 2, 0);
796 ngene_command_gpio_set(dev, 3, 1);
797 break;
798 }
799 dev->i2c_current_bus = bus;
800}
801
802static int ngene_i2c_master_xfer(struct i2c_adapter *adapter,
803 struct i2c_msg msg[], int num)
804{
805 struct ngene_channel *chan =
806 (struct ngene_channel *)i2c_get_adapdata(adapter);
807 struct ngene *dev = chan->dev;
808
809 down(&dev->i2c_switch_mutex);
810 ngene_i2c_set_bus(dev, chan->number);
811
812 if (num == 2 && msg[1].flags & I2C_M_RD && !(msg[0].flags & I2C_M_RD))
813 if (!ngene_command_i2c_read(dev, msg[0].addr,
814 msg[0].buf, msg[0].len,
815 msg[1].buf, msg[1].len, 0))
816 goto done;
817
818 if (num == 1 && !(msg[0].flags & I2C_M_RD))
819 if (!ngene_command_i2c_write(dev, msg[0].addr,
820 msg[0].buf, msg[0].len))
821 goto done;
822 if (num == 1 && (msg[0].flags & I2C_M_RD))
823 if (!ngene_command_i2c_read(dev, msg[0].addr, 0, 0,
824 msg[0].buf, msg[0].len, 0))
825 goto done;
826
827 up(&dev->i2c_switch_mutex);
828 return -EIO;
829
830done:
831 up(&dev->i2c_switch_mutex);
832 return num;
833}
834
835
836static u32 ngene_i2c_functionality(struct i2c_adapter *adap)
837{
838 return I2C_FUNC_SMBUS_EMUL;
839}
840
841static struct i2c_algorithm ngene_i2c_algo = {
842 .master_xfer = ngene_i2c_master_xfer,
843 .functionality = ngene_i2c_functionality,
844};
845
846static int ngene_i2c_init(struct ngene *dev, int dev_nr)
847{
848 struct i2c_adapter *adap = &(dev->channel[dev_nr].i2c_adapter);
849
850 i2c_set_adapdata(adap, &(dev->channel[dev_nr]));
851 adap->class = I2C_CLASS_TV_DIGITAL | I2C_CLASS_TV_ANALOG;
852
853 strcpy(adap->name, "nGene");
854
855 adap->algo = &ngene_i2c_algo;
856 adap->algo_data = (void *)&(dev->channel[dev_nr]);
857 adap->dev.parent = &dev->pci_dev->dev;
858
859 return i2c_add_adapter(adap);
860}
861
862
863/****************************************************************************/
864/* DVB functions and API interface ******************************************/
865/****************************************************************************/
866
867static void swap_buffer(u32 *p, u32 len)
868{
869 while (len) {
870 *p = swab32(*p);
871 p++;
872 len -= 4;
873 }
874}
875
876
877static void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
878{
879 struct ngene_channel *chan = priv;
880
881
882#ifdef COMMAND_TIMEOUT_WORKAROUND
883 if (chan->users > 0)
884#endif
885 dvb_dmx_swfilter(&chan->demux, buf, len);
886 return 0;
887}
888
889u8 fill_ts[188] = { 0x47, 0x1f, 0xff, 0x10 };
890
891static void *tsout_exchange(void *priv, void *buf, u32 len,
892 u32 clock, u32 flags)
893{
894 struct ngene_channel *chan = priv;
895 struct ngene *dev = chan->dev;
896 u32 alen;
897
898 alen = dvb_ringbuffer_avail(&dev->tsout_rbuf);
899 alen -= alen % 188;
900
901 if (alen < len)
902 FillTSBuffer(buf + alen, len - alen, flags);
903 else
904 alen = len;
905 dvb_ringbuffer_read(&dev->tsout_rbuf, buf, alen);
906 if (flags & DF_SWAP32)
907 swap_buffer((u32 *)buf, alen);
908 wake_up_interruptible(&dev->tsout_rbuf.queue);
909 return buf;
910}
911
912
913static void set_transfer(struct ngene_channel *chan, int state)
914{
915 u8 control = 0, mode = 0, flags = 0;
916 struct ngene *dev = chan->dev;
917 int ret;
918
919 /*
920 printk(KERN_INFO DEVICE_NAME ": st %d\n", state);
921 msleep(100);
922 */
923
924 if (state) {
925 if (chan->running) {
926 printk(KERN_INFO DEVICE_NAME ": already running\n");
927 return;
928 }
929 } else {
930 if (!chan->running) {
931 printk(KERN_INFO DEVICE_NAME ": already stopped\n");
932 return;
933 }
934 }
935
936 if (dev->card_info->switch_ctrl)
937 dev->card_info->switch_ctrl(chan, 1, state ^ 1);
938
939 if (state) {
940 spin_lock_irq(&chan->state_lock);
941
942 /* printk(KERN_INFO DEVICE_NAME ": lock=%08x\n",
943 ngreadl(0x9310)); */
944 dvb_ringbuffer_flush(&dev->tsout_rbuf);
945 control = 0x80;
946 if (chan->mode & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) {
947 chan->Capture1Length = 512 * 188;
948 mode = SMODE_TRANSPORT_STREAM;
949 }
950 if (chan->mode & NGENE_IO_TSOUT) {
951 chan->pBufferExchange = tsout_exchange;
952 /* 0x66666666 = 50MHz *2^33 /250MHz */
953 chan->AudioDTOValue = 0x66666666;
954 /* set_dto(chan, 38810700+1000); */
955 /* set_dto(chan, 19392658); */
956 }
957 if (chan->mode & NGENE_IO_TSIN)
958 chan->pBufferExchange = tsin_exchange;
959 /* ngwritel(0, 0x9310); */
960 spin_unlock_irq(&chan->state_lock);
961 } else
962 ;/* printk(KERN_INFO DEVICE_NAME ": lock=%08x\n",
963 ngreadl(0x9310)); */
964
965 ret = ngene_command_stream_control(dev, chan->number,
966 control, mode, flags);
967 if (!ret)
968 chan->running = state;
969 else
970 printk(KERN_ERR DEVICE_NAME ": set_transfer %d failed\n",
971 state);
972 if (!state) {
973 spin_lock_irq(&chan->state_lock);
974 chan->pBufferExchange = 0;
975 dvb_ringbuffer_flush(&dev->tsout_rbuf);
976 spin_unlock_irq(&chan->state_lock);
977 }
978}
979
980static int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed)
981{
982 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
983 struct ngene_channel *chan = dvbdmx->priv;
984
985 if (chan->users == 0) {
986#ifdef COMMAND_TIMEOUT_WORKAROUND
987 if (!chan->running)
988#endif
989 set_transfer(chan, 1);
990 /* msleep(10); */
991 }
992
993 return ++chan->users;
994}
995
996static int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
997{
998 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
999 struct ngene_channel *chan = dvbdmx->priv;
1000
1001 if (--chan->users)
1002 return chan->users;
1003
1004#ifndef COMMAND_TIMEOUT_WORKAROUND
1005 set_transfer(chan, 0);
1006#endif
1007
1008 return 0;
1009}
1010
1011
1012
1013static int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
1014 int (*start_feed)(struct dvb_demux_feed *),
1015 int (*stop_feed)(struct dvb_demux_feed *),
1016 void *priv)
1017{
1018 dvbdemux->priv = priv;
1019
1020 dvbdemux->filternum = 256;
1021 dvbdemux->feednum = 256;
1022 dvbdemux->start_feed = start_feed;
1023 dvbdemux->stop_feed = stop_feed;
1024 dvbdemux->write_to_decoder = 0;
1025 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
1026 DMX_SECTION_FILTERING |
1027 DMX_MEMORY_BASED_FILTERING);
1028 return dvb_dmx_init(dvbdemux);
1029}
1030
1031static int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
1032 struct dvb_demux *dvbdemux,
1033 struct dmx_frontend *hw_frontend,
1034 struct dmx_frontend *mem_frontend,
1035 struct dvb_adapter *dvb_adapter)
1036{
1037 int ret;
1038
1039 dmxdev->filternum = 256;
1040 dmxdev->demux = &dvbdemux->dmx;
1041 dmxdev->capabilities = 0;
1042 ret = dvb_dmxdev_init(dmxdev, dvb_adapter);
1043 if (ret < 0)
1044 return ret;
1045
1046 hw_frontend->source = DMX_FRONTEND_0;
1047 dvbdemux->dmx.add_frontend(&dvbdemux->dmx, hw_frontend);
1048 mem_frontend->source = DMX_MEMORY_FE;
1049 dvbdemux->dmx.add_frontend(&dvbdemux->dmx, mem_frontend);
1050 return dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, hw_frontend);
1051}
1052
1053
1054/****************************************************************************/
1055/* nGene hardware init and release functions ********************************/
1056/****************************************************************************/
1057
1058static void free_ringbuffer(struct ngene *dev, struct SRingBufferDescriptor *rb)
1059{
1060 struct SBufferHeader *Cur = rb->Head;
1061 u32 j;
1062
1063 if (!Cur)
1064 return;
1065
1066 for (j = 0; j < rb->NumBuffers; j++, Cur = Cur->Next) {
1067 if (Cur->Buffer1)
1068 pci_free_consistent(dev->pci_dev,
1069 rb->Buffer1Length,
1070 Cur->Buffer1,
1071 Cur->scList1->Address);
1072
1073 if (Cur->Buffer2)
1074 pci_free_consistent(dev->pci_dev,
1075 rb->Buffer2Length,
1076 Cur->Buffer2,
1077 Cur->scList2->Address);
1078 }
1079
1080 if (rb->SCListMem)
1081 pci_free_consistent(dev->pci_dev, rb->SCListMemSize,
1082 rb->SCListMem, rb->PASCListMem);
1083
1084 pci_free_consistent(dev->pci_dev, rb->MemSize, rb->Head, rb->PAHead);
1085}
1086
1087static void free_idlebuffer(struct ngene *dev,
1088 struct SRingBufferDescriptor *rb,
1089 struct SRingBufferDescriptor *tb)
1090{
1091 int j;
1092 struct SBufferHeader *Cur = tb->Head;
1093
1094 if (!rb->Head)
1095 return;
1096 free_ringbuffer(dev, rb);
1097 for (j = 0; j < tb->NumBuffers; j++, Cur = Cur->Next) {
1098 Cur->Buffer2 = 0;
1099 Cur->scList2 = 0;
1100 Cur->ngeneBuffer.Address_of_first_entry_2 = 0;
1101 Cur->ngeneBuffer.Number_of_entries_2 = 0;
1102 }
1103}
1104
1105static void free_common_buffers(struct ngene *dev)
1106{
1107 u32 i;
1108 struct ngene_channel *chan;
1109
1110 for (i = STREAM_VIDEOIN1; i < MAX_STREAM; i++) {
1111 chan = &dev->channel[i];
1112 free_idlebuffer(dev, &chan->TSIdleBuffer, &chan->TSRingBuffer);
1113 free_ringbuffer(dev, &chan->RingBuffer);
1114 free_ringbuffer(dev, &chan->TSRingBuffer);
1115 }
1116
1117 if (dev->OverflowBuffer)
1118 pci_free_consistent(dev->pci_dev,
1119 OVERFLOW_BUFFER_SIZE,
1120 dev->OverflowBuffer, dev->PAOverflowBuffer);
1121
1122 if (dev->FWInterfaceBuffer)
1123 pci_free_consistent(dev->pci_dev,
1124 4096,
1125 dev->FWInterfaceBuffer,
1126 dev->PAFWInterfaceBuffer);
1127}
1128
1129/****************************************************************************/
1130/* Ring buffer handling *****************************************************/
1131/****************************************************************************/
1132
1133static int create_ring_buffer(struct pci_dev *pci_dev,
1134 struct SRingBufferDescriptor *descr, u32 NumBuffers)
1135{
1136 dma_addr_t tmp;
1137 struct SBufferHeader *Head;
1138 u32 i;
1139 u32 MemSize = SIZEOF_SBufferHeader * NumBuffers;
1140 u64 PARingBufferHead;
1141 u64 PARingBufferCur;
1142 u64 PARingBufferNext;
1143 struct SBufferHeader *Cur, *Next;
1144
1145 descr->Head = 0;
1146 descr->MemSize = 0;
1147 descr->PAHead = 0;
1148 descr->NumBuffers = 0;
1149
1150 if (MemSize < 4096)
1151 MemSize = 4096;
1152
1153 Head = pci_alloc_consistent(pci_dev, MemSize, &tmp);
1154 PARingBufferHead = tmp;
1155
1156 if (!Head)
1157 return -ENOMEM;
1158
1159 memset(Head, 0, MemSize);
1160
1161 PARingBufferCur = PARingBufferHead;
1162 Cur = Head;
1163
1164 for (i = 0; i < NumBuffers - 1; i++) {
1165 Next = (struct SBufferHeader *)
1166 (((u8 *) Cur) + SIZEOF_SBufferHeader);
1167 PARingBufferNext = PARingBufferCur + SIZEOF_SBufferHeader;
1168 Cur->Next = Next;
1169 Cur->ngeneBuffer.Next = PARingBufferNext;
1170 Cur = Next;
1171 PARingBufferCur = PARingBufferNext;
1172 }
1173 /* Last Buffer points back to first one */
1174 Cur->Next = Head;
1175 Cur->ngeneBuffer.Next = PARingBufferHead;
1176
1177 descr->Head = Head;
1178 descr->MemSize = MemSize;
1179 descr->PAHead = PARingBufferHead;
1180 descr->NumBuffers = NumBuffers;
1181
1182 return 0;
1183}
1184
1185static int AllocateRingBuffers(struct pci_dev *pci_dev,
1186 dma_addr_t of,
1187 struct SRingBufferDescriptor *pRingBuffer,
1188 u32 Buffer1Length, u32 Buffer2Length)
1189{
1190 dma_addr_t tmp;
1191 u32 i, j;
1192 int status = 0;
1193 u32 SCListMemSize = pRingBuffer->NumBuffers
1194 * ((Buffer2Length != 0) ? (NUM_SCATTER_GATHER_ENTRIES * 2) :
1195 NUM_SCATTER_GATHER_ENTRIES)
1196 * sizeof(struct HW_SCATTER_GATHER_ELEMENT);
1197
1198 u64 PASCListMem;
1199 struct HW_SCATTER_GATHER_ELEMENT *SCListEntry;
1200 u64 PASCListEntry;
1201 struct SBufferHeader *Cur;
1202 void *SCListMem;
1203
1204 if (SCListMemSize < 4096)
1205 SCListMemSize = 4096;
1206
1207 SCListMem = pci_alloc_consistent(pci_dev, SCListMemSize, &tmp);
1208
1209 PASCListMem = tmp;
1210 if (SCListMem == NULL)
1211 return -ENOMEM;
1212
1213 memset(SCListMem, 0, SCListMemSize);
1214
1215 pRingBuffer->SCListMem = SCListMem;
1216 pRingBuffer->PASCListMem = PASCListMem;
1217 pRingBuffer->SCListMemSize = SCListMemSize;
1218 pRingBuffer->Buffer1Length = Buffer1Length;
1219 pRingBuffer->Buffer2Length = Buffer2Length;
1220
1221 SCListEntry = SCListMem;
1222 PASCListEntry = PASCListMem;
1223 Cur = pRingBuffer->Head;
1224
1225 for (i = 0; i < pRingBuffer->NumBuffers; i += 1, Cur = Cur->Next) {
1226 u64 PABuffer;
1227
1228 void *Buffer = pci_alloc_consistent(pci_dev, Buffer1Length,
1229 &tmp);
1230 PABuffer = tmp;
1231
1232 if (Buffer == NULL)
1233 return -ENOMEM;
1234
1235 Cur->Buffer1 = Buffer;
1236
1237 SCListEntry->Address = PABuffer;
1238 SCListEntry->Length = Buffer1Length;
1239
1240 Cur->scList1 = SCListEntry;
1241 Cur->ngeneBuffer.Address_of_first_entry_1 = PASCListEntry;
1242 Cur->ngeneBuffer.Number_of_entries_1 =
1243 NUM_SCATTER_GATHER_ENTRIES;
1244
1245 SCListEntry += 1;
1246 PASCListEntry += sizeof(struct HW_SCATTER_GATHER_ELEMENT);
1247
1248#if NUM_SCATTER_GATHER_ENTRIES > 1
1249 for (j = 0; j < NUM_SCATTER_GATHER_ENTRIES - 1; j += 1) {
1250 SCListEntry->Address = of;
1251 SCListEntry->Length = OVERFLOW_BUFFER_SIZE;
1252 SCListEntry += 1;
1253 PASCListEntry +=
1254 sizeof(struct HW_SCATTER_GATHER_ELEMENT);
1255 }
1256#endif
1257
1258 if (!Buffer2Length)
1259 continue;
1260
1261 Buffer = pci_alloc_consistent(pci_dev, Buffer2Length, &tmp);
1262 PABuffer = tmp;
1263
1264 if (Buffer == NULL)
1265 return -ENOMEM;
1266
1267 Cur->Buffer2 = Buffer;
1268
1269 SCListEntry->Address = PABuffer;
1270 SCListEntry->Length = Buffer2Length;
1271
1272 Cur->scList2 = SCListEntry;
1273 Cur->ngeneBuffer.Address_of_first_entry_2 = PASCListEntry;
1274 Cur->ngeneBuffer.Number_of_entries_2 =
1275 NUM_SCATTER_GATHER_ENTRIES;
1276
1277 SCListEntry += 1;
1278 PASCListEntry += sizeof(struct HW_SCATTER_GATHER_ELEMENT);
1279
1280#if NUM_SCATTER_GATHER_ENTRIES > 1
1281 for (j = 0; j < NUM_SCATTER_GATHER_ENTRIES - 1; j++) {
1282 SCListEntry->Address = of;
1283 SCListEntry->Length = OVERFLOW_BUFFER_SIZE;
1284 SCListEntry += 1;
1285 PASCListEntry +=
1286 sizeof(struct HW_SCATTER_GATHER_ELEMENT);
1287 }
1288#endif
1289
1290 }
1291
1292 return status;
1293}
1294
1295static int FillTSIdleBuffer(struct SRingBufferDescriptor *pIdleBuffer,
1296 struct SRingBufferDescriptor *pRingBuffer)
1297{
1298 int status = 0;
1299
1300 /* Copy pointer to scatter gather list in TSRingbuffer
1301 structure for buffer 2
1302 Load number of buffer
1303 */
1304 u32 n = pRingBuffer->NumBuffers;
1305
1306 /* Point to first buffer entry */
1307 struct SBufferHeader *Cur = pRingBuffer->Head;
1308 int i;
1309 /* Loop thru all buffer and set Buffer 2 pointers to TSIdlebuffer */
1310 for (i = 0; i < n; i++) {
1311 Cur->Buffer2 = pIdleBuffer->Head->Buffer1;
1312 Cur->scList2 = pIdleBuffer->Head->scList1;
1313 Cur->ngeneBuffer.Address_of_first_entry_2 =
1314 pIdleBuffer->Head->ngeneBuffer.
1315 Address_of_first_entry_1;
1316 Cur->ngeneBuffer.Number_of_entries_2 =
1317 pIdleBuffer->Head->ngeneBuffer.Number_of_entries_1;
1318 Cur = Cur->Next;
1319 }
1320 return status;
1321}
1322
1323static u32 RingBufferSizes[MAX_STREAM] = {
1324 RING_SIZE_VIDEO,
1325 RING_SIZE_VIDEO,
1326 RING_SIZE_AUDIO,
1327 RING_SIZE_AUDIO,
1328 RING_SIZE_AUDIO,
1329};
1330
1331static u32 Buffer1Sizes[MAX_STREAM] = {
1332 MAX_VIDEO_BUFFER_SIZE,
1333 MAX_VIDEO_BUFFER_SIZE,
1334 MAX_AUDIO_BUFFER_SIZE,
1335 MAX_AUDIO_BUFFER_SIZE,
1336 MAX_AUDIO_BUFFER_SIZE
1337};
1338
1339static u32 Buffer2Sizes[MAX_STREAM] = {
1340 MAX_VBI_BUFFER_SIZE,
1341 MAX_VBI_BUFFER_SIZE,
1342 0,
1343 0,
1344 0
1345};
1346
1347
1348static int AllocCommonBuffers(struct ngene *dev)
1349{
1350 int status = 0, i;
1351
1352 dev->FWInterfaceBuffer = pci_alloc_consistent(dev->pci_dev, 4096,
1353 &dev->PAFWInterfaceBuffer);
1354 if (!dev->FWInterfaceBuffer)
1355 return -ENOMEM;
1356 dev->hosttongene = dev->FWInterfaceBuffer;
1357 dev->ngenetohost = dev->FWInterfaceBuffer + 256;
1358 dev->EventBuffer = dev->FWInterfaceBuffer + 512;
1359
1360 dev->OverflowBuffer = pci_alloc_consistent(dev->pci_dev,
1361 OVERFLOW_BUFFER_SIZE,
1362 &dev->PAOverflowBuffer);
1363 if (!dev->OverflowBuffer)
1364 return -ENOMEM;
1365 memset(dev->OverflowBuffer, 0, OVERFLOW_BUFFER_SIZE);
1366
1367 for (i = STREAM_VIDEOIN1; i < MAX_STREAM; i++) {
1368 int type = dev->card_info->io_type[i];
1369
1370 dev->channel[i].State = KSSTATE_STOP;
1371
1372 if (type & (NGENE_IO_TV | NGENE_IO_HDTV | NGENE_IO_AIN)) {
1373 status = create_ring_buffer(dev->pci_dev,
1374 &dev->channel[i].RingBuffer,
1375 RingBufferSizes[i]);
1376 if (status < 0)
1377 break;
1378
1379 if (type & (NGENE_IO_TV | NGENE_IO_AIN)) {
1380 status = AllocateRingBuffers(dev->pci_dev,
1381 dev->
1382 PAOverflowBuffer,
1383 &dev->channel[i].
1384 RingBuffer,
1385 Buffer1Sizes[i],
1386 Buffer2Sizes[i]);
1387 if (status < 0)
1388 break;
1389 } else if (type & NGENE_IO_HDTV) {
1390 status = AllocateRingBuffers(dev->pci_dev,
1391 dev->
1392 PAOverflowBuffer,
1393 &dev->channel[i].
1394 RingBuffer,
1395 MAX_HDTV_BUFFER_SIZE,
1396 0);
1397 if (status < 0)
1398 break;
1399 }
1400 }
1401
1402 if (type & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) {
1403
1404 status = create_ring_buffer(dev->pci_dev,
1405 &dev->channel[i].
1406 TSRingBuffer, RING_SIZE_TS);
1407 if (status < 0)
1408 break;
1409
1410 status = AllocateRingBuffers(dev->pci_dev,
1411 dev->PAOverflowBuffer,
1412 &dev->channel[i].
1413 TSRingBuffer,
1414 MAX_TS_BUFFER_SIZE, 0);
1415 if (status)
1416 break;
1417 }
1418
1419 if (type & NGENE_IO_TSOUT) {
1420 status = create_ring_buffer(dev->pci_dev,
1421 &dev->channel[i].
1422 TSIdleBuffer, 1);
1423 if (status < 0)
1424 break;
1425 status = AllocateRingBuffers(dev->pci_dev,
1426 dev->PAOverflowBuffer,
1427 &dev->channel[i].
1428 TSIdleBuffer,
1429 MAX_TS_BUFFER_SIZE, 0);
1430 if (status)
1431 break;
1432 FillTSIdleBuffer(&dev->channel[i].TSIdleBuffer,
1433 &dev->channel[i].TSRingBuffer);
1434 }
1435 }
1436 return status;
1437}
1438
1439static void ngene_release_buffers(struct ngene *dev)
1440{
1441 if (dev->iomem)
1442 iounmap(dev->iomem);
1443 free_common_buffers(dev);
1444 vfree(dev->tsout_buf);
1445 vfree(dev->ain_buf);
1446 vfree(dev->vin_buf);
1447 vfree(dev);
1448}
1449
1450static int ngene_get_buffers(struct ngene *dev)
1451{
1452 if (AllocCommonBuffers(dev))
1453 return -ENOMEM;
1454 if (dev->card_info->io_type[4] & NGENE_IO_TSOUT) {
1455 dev->tsout_buf = vmalloc(TSOUT_BUF_SIZE);
1456 if (!dev->tsout_buf)
1457 return -ENOMEM;
1458 dvb_ringbuffer_init(&dev->tsout_rbuf,
1459 dev->tsout_buf, TSOUT_BUF_SIZE);
1460 }
1461 if (dev->card_info->io_type[2] & NGENE_IO_AIN) {
1462 dev->ain_buf = vmalloc(AIN_BUF_SIZE);
1463 if (!dev->ain_buf)
1464 return -ENOMEM;
1465 dvb_ringbuffer_init(&dev->ain_rbuf, dev->ain_buf, AIN_BUF_SIZE);
1466 }
1467 if (dev->card_info->io_type[0] & NGENE_IO_HDTV) {
1468 dev->vin_buf = vmalloc(VIN_BUF_SIZE);
1469 if (!dev->vin_buf)
1470 return -ENOMEM;
1471 dvb_ringbuffer_init(&dev->vin_rbuf, dev->vin_buf, VIN_BUF_SIZE);
1472 }
1473 dev->iomem = ioremap(pci_resource_start(dev->pci_dev, 0),
1474 pci_resource_len(dev->pci_dev, 0));
1475 if (!dev->iomem)
1476 return -ENOMEM;
1477
1478 return 0;
1479}
1480
1481static void ngene_init(struct ngene *dev)
1482{
1483 int i;
1484
1485 tasklet_init(&dev->event_tasklet, event_tasklet, (unsigned long)dev);
1486
1487 memset_io(dev->iomem + 0xc000, 0x00, 0x220);
1488 memset_io(dev->iomem + 0xc400, 0x00, 0x100);
1489
1490 for (i = 0; i < MAX_STREAM; i++) {
1491 dev->channel[i].dev = dev;
1492 dev->channel[i].number = i;
1493 }
1494
1495 dev->fw_interface_version = 0;
1496
1497 ngwritel(0, NGENE_INT_ENABLE);
1498
1499 dev->icounts = ngreadl(NGENE_INT_COUNTS);
1500
1501 dev->device_version = ngreadl(DEV_VER) & 0x0f;
1502 printk(KERN_INFO DEVICE_NAME ": Device version %d\n",
1503 dev->device_version);
1504}
1505
1506static int ngene_load_firm(struct ngene *dev)
1507{
1508 u32 size;
1509 const struct firmware *fw = NULL;
1510 u8 *ngene_fw;
1511 char *fw_name;
1512 int err, version;
1513
1514 version = dev->card_info->fw_version;
1515
1516 switch (version) {
1517 default:
1518 case 15:
1519 version = 15;
1520 size = 23466;
1521 fw_name = "ngene_15.fw";
1522 break;
1523 case 16:
1524 size = 23498;
1525 fw_name = "ngene_16.fw";
1526 break;
1527 case 17:
1528 size = 24446;
1529 fw_name = "ngene_17.fw";
1530 break;
1531 }
1532
1533 if (request_firmware(&fw, fw_name, &dev->pci_dev->dev) < 0) {
1534 printk(KERN_ERR DEVICE_NAME
1535 ": Could not load firmware file %s.\n", fw_name);
1536 printk(KERN_INFO DEVICE_NAME
1537 ": Copy %s to your hotplug directory!\n", fw_name);
1538 return -1;
1539 }
1540 if (size != fw->size) {
1541 printk(KERN_ERR DEVICE_NAME
1542 ": Firmware %s has invalid size!", fw_name);
1543 err = -1;
1544 } else {
1545 printk(KERN_INFO DEVICE_NAME
1546 ": Loading firmware file %s.\n", fw_name);
1547 ngene_fw = (u8 *) fw->data;
1548 err = ngene_command_load_firmware(dev, ngene_fw, size);
1549 }
1550
1551 release_firmware(fw);
1552
1553 return err;
1554}
1555
1556static void ngene_stop(struct ngene *dev)
1557{
1558 down(&dev->cmd_mutex);
1559 i2c_del_adapter(&(dev->channel[0].i2c_adapter));
1560 i2c_del_adapter(&(dev->channel[1].i2c_adapter));
1561 ngwritel(0, NGENE_INT_ENABLE);
1562 ngwritel(0, NGENE_COMMAND);
1563 ngwritel(0, NGENE_COMMAND_HI);
1564 ngwritel(0, NGENE_STATUS);
1565 ngwritel(0, NGENE_STATUS_HI);
1566 ngwritel(0, NGENE_EVENT);
1567 ngwritel(0, NGENE_EVENT_HI);
1568 free_irq(dev->pci_dev->irq, dev);
1569}
1570
1571static int ngene_start(struct ngene *dev)
1572{
1573 int stat;
1574 int i;
1575
1576 pci_set_master(dev->pci_dev);
1577 ngene_init(dev);
1578
1579 stat = request_irq(dev->pci_dev->irq, irq_handler,
1580 IRQF_SHARED, "nGene",
1581 (void *)dev);
1582 if (stat < 0)
1583 return stat;
1584
1585 init_waitqueue_head(&dev->cmd_wq);
1586 init_waitqueue_head(&dev->tx_wq);
1587 init_waitqueue_head(&dev->rx_wq);
1588 sema_init(&dev->cmd_mutex, 1);
1589 sema_init(&dev->stream_mutex, 1);
1590 sema_init(&dev->pll_mutex, 1);
1591 sema_init(&dev->i2c_switch_mutex, 1);
1592 spin_lock_init(&dev->cmd_lock);
1593 for (i = 0; i < MAX_STREAM; i++)
1594 spin_lock_init(&dev->channel[i].state_lock);
1595 ngwritel(1, TIMESTAMPS);
1596
1597 ngwritel(1, NGENE_INT_ENABLE);
1598
1599 stat = ngene_load_firm(dev);
1600 if (stat < 0)
1601 goto fail;
1602
1603 stat = ngene_i2c_init(dev, 0);
1604 if (stat < 0)
1605 goto fail;
1606
1607 stat = ngene_i2c_init(dev, 1);
1608 if (stat < 0)
1609 goto fail;
1610
1611 if (dev->card_info->fw_version == 17) {
1612 u8 tsin4_config[6] = {
1613 3072 / 64, 3072 / 64, 0, 3072 / 64, 3072 / 64, 0};
1614 u8 default_config[6] = {
1615 4096 / 64, 4096 / 64, 0, 2048 / 64, 2048 / 64, 0};
1616 u8 *bconf = default_config;
1617
1618 if (dev->card_info->io_type[3] == NGENE_IO_TSIN)
1619 bconf = tsin4_config;
1620 dprintk(KERN_DEBUG DEVICE_NAME ": FW 17 buffer config\n");
1621 stat = ngene_command_config_free_buf(dev, bconf);
1622 } else {
1623 int bconf = BUFFER_CONFIG_4422;
1624 if (dev->card_info->io_type[3] == NGENE_IO_TSIN)
1625 bconf = BUFFER_CONFIG_3333;
1626 stat = ngene_command_config_buf(dev, bconf);
1627 }
1628 return stat;
1629fail:
1630 ngwritel(0, NGENE_INT_ENABLE);
1631 free_irq(dev->pci_dev->irq, dev);
1632 return stat;
1633}
1634
1635
1636
1637/****************************************************************************/
1638/* Switch control (I2C gates, etc.) *****************************************/
1639/****************************************************************************/
1640
1641
1642/****************************************************************************/
1643/* Demod/tuner attachment ***************************************************/
1644/****************************************************************************/
1645
1646static int tuner_attach_stv6110(struct ngene_channel *chan)
1647{
1648 struct stv090x_config *feconf = (struct stv090x_config *)
1649 chan->dev->card_info->fe_config[chan->number];
1650 struct stv6110x_config *tunerconf = (struct stv6110x_config *)
1651 chan->dev->card_info->tuner_config[chan->number];
1652 struct stv6110x_devctl *ctl;
1653
1654 ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf,
1655 &chan->i2c_adapter);
1656 if (ctl == NULL) {
1657 printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
1658 return -ENODEV;
1659 }
1660
1661 feconf->tuner_init = ctl->tuner_init;
1662 feconf->tuner_set_mode = ctl->tuner_set_mode;
1663 feconf->tuner_set_frequency = ctl->tuner_set_frequency;
1664 feconf->tuner_get_frequency = ctl->tuner_get_frequency;
1665 feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
1666 feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
1667 feconf->tuner_set_bbgain = ctl->tuner_set_bbgain;
1668 feconf->tuner_get_bbgain = ctl->tuner_get_bbgain;
1669 feconf->tuner_set_refclk = ctl->tuner_set_refclk;
1670 feconf->tuner_get_status = ctl->tuner_get_status;
1671
1672 return 0;
1673}
1674
1675
1676static int demod_attach_stv0900(struct ngene_channel *chan)
1677{
1678 struct stv090x_config *feconf = (struct stv090x_config *)
1679 chan->dev->card_info->fe_config[chan->number];
1680
1681 chan->fe = dvb_attach(stv090x_attach,
1682 feconf,
1683 &chan->i2c_adapter,
1684 chan->number == 0 ? STV090x_DEMODULATOR_0 :
1685 STV090x_DEMODULATOR_1);
1686 if (chan->fe == NULL) {
1687 printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
1688 return -ENODEV;
1689 }
1690
1691 if (!dvb_attach(lnbh24_attach, chan->fe, &chan->i2c_adapter, 0,
1692 0, chan->dev->card_info->lnb[chan->number])) {
1693 printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
1694 dvb_frontend_detach(chan->fe);
1695 return -ENODEV;
1696 }
1697
1698 return 0;
1699}
1700
1701/****************************************************************************/
1702/****************************************************************************/
1703/****************************************************************************/
1704
1705static void release_channel(struct ngene_channel *chan)
1706{
1707 struct dvb_demux *dvbdemux = &chan->demux;
1708 struct ngene *dev = chan->dev;
1709 struct ngene_info *ni = dev->card_info;
1710 int io = ni->io_type[chan->number];
1711
1712#ifdef COMMAND_TIMEOUT_WORKAROUND
1713 if (chan->running)
1714 set_transfer(chan, 0);
1715#endif
1716
1717 tasklet_kill(&chan->demux_tasklet);
1718
1719 if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) {
1720 if (chan->fe) {
1721 dvb_unregister_frontend(chan->fe);
1722 dvb_frontend_detach(chan->fe);
1723 chan->fe = 0;
1724 }
1725 dvbdemux->dmx.close(&dvbdemux->dmx);
1726 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx,
1727 &chan->hw_frontend);
1728 dvbdemux->dmx.remove_frontend(&dvbdemux->dmx,
1729 &chan->mem_frontend);
1730 dvb_dmxdev_release(&chan->dmxdev);
1731 dvb_dmx_release(&chan->demux);
1732
1733 if (chan->number == 0 || !one_adapter)
1734 dvb_unregister_adapter(&dev->adapter[chan->number]);
1735 }
1736}
1737
1738static int init_channel(struct ngene_channel *chan)
1739{
1740 int ret = 0, nr = chan->number;
1741 struct dvb_adapter *adapter = NULL;
1742 struct dvb_demux *dvbdemux = &chan->demux;
1743 struct ngene *dev = chan->dev;
1744 struct ngene_info *ni = dev->card_info;
1745 int io = ni->io_type[nr];
1746
1747 tasklet_init(&chan->demux_tasklet, demux_tasklet, (unsigned long)chan);
1748 chan->users = 0;
1749 chan->type = io;
1750 chan->mode = chan->type; /* for now only one mode */
1751
1752 if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) {
1753 if (nr >= STREAM_AUDIOIN1)
1754 chan->DataFormatFlags = DF_SWAP32;
1755 if (nr == 0 || !one_adapter) {
1756 adapter = &dev->adapter[nr];
1757 ret = dvb_register_adapter(adapter, "nGene",
1758 THIS_MODULE,
1759 &chan->dev->pci_dev->dev,
1760 adapter_nr);
1761 if (ret < 0)
1762 return ret;
1763 } else {
1764 adapter = &dev->adapter[0];
1765 }
1766
1767 ret = my_dvb_dmx_ts_card_init(dvbdemux, "SW demux",
1768 ngene_start_feed,
1769 ngene_stop_feed, chan);
1770 ret = my_dvb_dmxdev_ts_card_init(&chan->dmxdev, &chan->demux,
1771 &chan->hw_frontend,
1772 &chan->mem_frontend, adapter);
1773 }
1774
1775 if (io & NGENE_IO_TSIN) {
1776 chan->fe = NULL;
1777 if (ni->demod_attach[nr])
1778 ni->demod_attach[nr](chan);
1779 if (chan->fe) {
1780 if (dvb_register_frontend(adapter, chan->fe) < 0) {
1781 if (chan->fe->ops.release)
1782 chan->fe->ops.release(chan->fe);
1783 chan->fe = NULL;
1784 }
1785 }
1786 if (chan->fe && ni->tuner_attach[nr])
1787 if (ni->tuner_attach[nr] (chan) < 0) {
1788 printk(KERN_ERR DEVICE_NAME
1789 ": Tuner attach failed on channel %d!\n",
1790 nr);
1791 }
1792 }
1793 return ret;
1794}
1795
1796static int init_channels(struct ngene *dev)
1797{
1798 int i, j;
1799
1800 for (i = 0; i < MAX_STREAM; i++) {
1801 if (init_channel(&dev->channel[i]) < 0) {
1802 for (j = i - 1; j >= 0; j--)
1803 release_channel(&dev->channel[j]);
1804 return -1;
1805 }
1806 }
1807 return 0;
1808}
1809
1810/****************************************************************************/
1811/* device probe/remove calls ************************************************/
1812/****************************************************************************/
1813
1814static void __devexit ngene_remove(struct pci_dev *pdev)
1815{
1816 struct ngene *dev = (struct ngene *)pci_get_drvdata(pdev);
1817 int i;
1818
1819 tasklet_kill(&dev->event_tasklet);
1820 for (i = MAX_STREAM - 1; i >= 0; i--)
1821 release_channel(&dev->channel[i]);
1822 ngene_stop(dev);
1823 ngene_release_buffers(dev);
1824 pci_set_drvdata(pdev, 0);
1825 pci_disable_device(pdev);
1826}
1827
1828static int __devinit ngene_probe(struct pci_dev *pci_dev,
1829 const struct pci_device_id *id)
1830{
1831 struct ngene *dev;
1832 int stat = 0;
1833
1834 if (pci_enable_device(pci_dev) < 0)
1835 return -ENODEV;
1836
1837 dev = vmalloc(sizeof(struct ngene));
1838 if (dev == NULL) {
1839 stat = -ENOMEM;
1840 goto fail0;
1841 }
1842 memset(dev, 0, sizeof(struct ngene));
1843
1844 dev->pci_dev = pci_dev;
1845 dev->card_info = (struct ngene_info *)id->driver_data;
1846 printk(KERN_INFO DEVICE_NAME ": Found %s\n", dev->card_info->name);
1847
1848 pci_set_drvdata(pci_dev, dev);
1849
1850 /* Alloc buffers and start nGene */
1851 stat = ngene_get_buffers(dev);
1852 if (stat < 0)
1853 goto fail1;
1854 stat = ngene_start(dev);
1855 if (stat < 0)
1856 goto fail1;
1857
1858 dev->i2c_current_bus = -1;
1859
1860 /* Register DVB adapters and devices for both channels */
1861 if (init_channels(dev) < 0)
1862 goto fail2;
1863
1864 return 0;
1865
1866fail2:
1867 ngene_stop(dev);
1868fail1:
1869 ngene_release_buffers(dev);
1870fail0:
1871 pci_disable_device(pci_dev);
1872 pci_set_drvdata(pci_dev, 0);
1873 return stat;
1874}
1875
1876/****************************************************************************/
1877/* Card configs *************************************************************/
1878/****************************************************************************/
1879
1880static struct stv090x_config fe_cineS2 = {
1881 .device = STV0900,
1882 .demod_mode = STV090x_DUAL,
1883 .clk_mode = STV090x_CLK_EXT,
1884
1885 .xtal = 27000000,
1886 .address = 0x68,
1887
1888 .ts1_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
1889 .ts2_mode = STV090x_TSMODE_SERIAL_PUNCTURED,
1890
1891 .repeater_level = STV090x_RPTLEVEL_16,
1892
1893 .adc1_range = STV090x_ADC_1Vpp,
1894 .adc2_range = STV090x_ADC_1Vpp,
1895
1896 .diseqc_envelope_mode = true,
1897};
1898
1899static struct stv6110x_config tuner_cineS2_0 = {
1900 .addr = 0x60,
1901 .refclk = 27000000,
1902 .clk_div = 1,
1903};
1904
1905static struct stv6110x_config tuner_cineS2_1 = {
1906 .addr = 0x63,
1907 .refclk = 27000000,
1908 .clk_div = 1,
1909};
1910
1911static struct ngene_info ngene_info_cineS2 = {
1912 .type = NGENE_SIDEWINDER,
1913 .name = "Linux4Media cineS2 DVB-S2 Twin Tuner",
1914 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
1915 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
1916 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
1917 .fe_config = {&fe_cineS2, &fe_cineS2},
1918 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
1919 .lnb = {0x0b, 0x08},
1920 .tsf = {3, 3},
1921 .fw_version = 15,
1922};
1923
1924static struct ngene_info ngene_info_satixs2 = {
1925 .type = NGENE_SIDEWINDER,
1926 .name = "Mystique SaTiX-S2 Dual",
1927 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
1928 .demod_attach = {demod_attach_stv0900, demod_attach_stv0900},
1929 .tuner_attach = {tuner_attach_stv6110, tuner_attach_stv6110},
1930 .fe_config = {&fe_cineS2, &fe_cineS2},
1931 .tuner_config = {&tuner_cineS2_0, &tuner_cineS2_1},
1932 .lnb = {0x0b, 0x08},
1933 .tsf = {3, 3},
1934 .fw_version = 15,
1935};
1936
1937/****************************************************************************/
1938
1939
1940
1941/****************************************************************************/
1942/* PCI Subsystem ID *********************************************************/
1943/****************************************************************************/
1944
1945#define NGENE_ID(_subvend, _subdev, _driverdata) { \
1946 .vendor = NGENE_VID, .device = NGENE_PID, \
1947 .subvendor = _subvend, .subdevice = _subdev, \
1948 .driver_data = (unsigned long) &_driverdata }
1949
1950/****************************************************************************/
1951
1952static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
1953 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
1954 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
1955 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixs2),
1956 {0}
1957};
1958MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
1959
1960/****************************************************************************/
1961/* Init/Exit ****************************************************************/
1962/****************************************************************************/
1963
1964static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
1965 enum pci_channel_state state)
1966{
1967 printk(KERN_ERR DEVICE_NAME ": PCI error\n");
1968 if (state == pci_channel_io_perm_failure)
1969 return PCI_ERS_RESULT_DISCONNECT;
1970 if (state == pci_channel_io_frozen)
1971 return PCI_ERS_RESULT_NEED_RESET;
1972 return PCI_ERS_RESULT_CAN_RECOVER;
1973}
1974
1975static pci_ers_result_t ngene_link_reset(struct pci_dev *dev)
1976{
1977 printk(KERN_INFO DEVICE_NAME ": link reset\n");
1978 return 0;
1979}
1980
1981static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
1982{
1983 printk(KERN_INFO DEVICE_NAME ": slot reset\n");
1984 return 0;
1985}
1986
1987static void ngene_resume(struct pci_dev *dev)
1988{
1989 printk(KERN_INFO DEVICE_NAME ": resume\n");
1990}
1991
1992static struct pci_error_handlers ngene_errors = {
1993 .error_detected = ngene_error_detected,
1994 .link_reset = ngene_link_reset,
1995 .slot_reset = ngene_slot_reset,
1996 .resume = ngene_resume,
1997};
1998
1999static struct pci_driver ngene_pci_driver = {
2000 .name = "ngene",
2001 .id_table = ngene_id_tbl,
2002 .probe = ngene_probe,
2003 .remove = __devexit_p(ngene_remove),
2004 .err_handler = &ngene_errors,
2005};
2006
2007static __init int module_init_ngene(void)
2008{
2009 printk(KERN_INFO
2010 "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
2011 return pci_register_driver(&ngene_pci_driver);
2012}
2013
2014static __exit void module_exit_ngene(void)
2015{
2016 pci_unregister_driver(&ngene_pci_driver);
2017}
2018
2019module_init(module_init_ngene);
2020module_exit(module_exit_ngene);
2021
2022MODULE_DESCRIPTION("nGene");
2023MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
2024MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/ngene/ngene.h b/drivers/media/dvb/ngene/ngene.h
new file mode 100644
index 000000000000..a7eb29846310
--- /dev/null
+++ b/drivers/media/dvb/ngene/ngene.h
@@ -0,0 +1,859 @@
1/*
2 * ngene.h: nGene PCIe bridge driver
3 *
4 * Copyright (C) 2005-2007 Micronas
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
8 * version 2 only, as published by the Free Software Foundation.
9 *
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 *
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., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 */
23
24#ifndef _NGENE_H_
25#define _NGENE_H_
26
27#include <linux/types.h>
28#include <linux/sched.h>
29#include <linux/interrupt.h>
30#include <linux/i2c.h>
31#include <asm/dma.h>
32#include <linux/scatterlist.h>
33
34#include <linux/dvb/frontend.h>
35
36#include "dmxdev.h"
37#include "dvbdev.h"
38#include "dvb_demux.h"
39#include "dvb_frontend.h"
40#include "dvb_ringbuffer.h"
41
42#define NGENE_VID 0x18c3
43#define NGENE_PID 0x0720
44
45#ifndef VIDEO_CAP_VC1
46#define VIDEO_CAP_AVC 128
47#define VIDEO_CAP_H264 128
48#define VIDEO_CAP_VC1 256
49#define VIDEO_CAP_WMV9 256
50#define VIDEO_CAP_MPEG4 512
51#endif
52
53enum STREAM {
54 STREAM_VIDEOIN1 = 0, /* ITU656 or TS Input */
55 STREAM_VIDEOIN2,
56 STREAM_AUDIOIN1, /* I2S or SPI Input */
57 STREAM_AUDIOIN2,
58 STREAM_AUDIOOUT,
59 MAX_STREAM
60};
61
62enum SMODE_BITS {
63 SMODE_AUDIO_SPDIF = 0x20,
64 SMODE_AVSYNC = 0x10,
65 SMODE_TRANSPORT_STREAM = 0x08,
66 SMODE_AUDIO_CAPTURE = 0x04,
67 SMODE_VBI_CAPTURE = 0x02,
68 SMODE_VIDEO_CAPTURE = 0x01
69};
70
71enum STREAM_FLAG_BITS {
72 SFLAG_CHROMA_FORMAT_2COMP = 0x01, /* Chroma Format : 2's complement */
73 SFLAG_CHROMA_FORMAT_OFFSET = 0x00, /* Chroma Format : Binary offset */
74 SFLAG_ORDER_LUMA_CHROMA = 0x02, /* Byte order: Y,Cb,Y,Cr */
75 SFLAG_ORDER_CHROMA_LUMA = 0x00, /* Byte order: Cb,Y,Cr,Y */
76 SFLAG_COLORBAR = 0x04, /* Select colorbar */
77};
78
79#define PROGRAM_ROM 0x0000
80#define PROGRAM_SRAM 0x1000
81#define PERIPHERALS0 0x8000
82#define PERIPHERALS1 0x9000
83#define SHARED_BUFFER 0xC000
84
85#define HOST_TO_NGENE (SHARED_BUFFER+0x0000)
86#define NGENE_TO_HOST (SHARED_BUFFER+0x0100)
87#define NGENE_COMMAND (SHARED_BUFFER+0x0200)
88#define NGENE_COMMAND_HI (SHARED_BUFFER+0x0204)
89#define NGENE_STATUS (SHARED_BUFFER+0x0208)
90#define NGENE_STATUS_HI (SHARED_BUFFER+0x020C)
91#define NGENE_EVENT (SHARED_BUFFER+0x0210)
92#define NGENE_EVENT_HI (SHARED_BUFFER+0x0214)
93#define VARIABLES (SHARED_BUFFER+0x0210)
94
95#define NGENE_INT_COUNTS (SHARED_BUFFER+0x0260)
96#define NGENE_INT_ENABLE (SHARED_BUFFER+0x0264)
97#define NGENE_VBI_LINE_COUNT (SHARED_BUFFER+0x0268)
98
99#define BUFFER_GP_XMIT (SHARED_BUFFER+0x0800)
100#define BUFFER_GP_RECV (SHARED_BUFFER+0x0900)
101#define EEPROM_AREA (SHARED_BUFFER+0x0A00)
102
103#define SG_V_IN_1 (SHARED_BUFFER+0x0A80)
104#define SG_VBI_1 (SHARED_BUFFER+0x0B00)
105#define SG_A_IN_1 (SHARED_BUFFER+0x0B80)
106#define SG_V_IN_2 (SHARED_BUFFER+0x0C00)
107#define SG_VBI_2 (SHARED_BUFFER+0x0C80)
108#define SG_A_IN_2 (SHARED_BUFFER+0x0D00)
109#define SG_V_OUT (SHARED_BUFFER+0x0D80)
110#define SG_A_OUT2 (SHARED_BUFFER+0x0E00)
111
112#define DATA_A_IN_1 (SHARED_BUFFER+0x0E80)
113#define DATA_A_IN_2 (SHARED_BUFFER+0x0F00)
114#define DATA_A_OUT (SHARED_BUFFER+0x0F80)
115#define DATA_V_IN_1 (SHARED_BUFFER+0x1000)
116#define DATA_V_IN_2 (SHARED_BUFFER+0x2000)
117#define DATA_V_OUT (SHARED_BUFFER+0x3000)
118
119#define DATA_FIFO_AREA (SHARED_BUFFER+0x1000)
120
121#define TIMESTAMPS 0xA000
122#define SCRATCHPAD 0xA080
123#define FORCE_INT 0xA088
124#define FORCE_NMI 0xA090
125#define INT_STATUS 0xA0A0
126
127#define DEV_VER 0x9004
128
129#define FW_DEBUG_DEFAULT (PROGRAM_SRAM+0x00FF)
130
131struct SG_ADDR {
132 u64 start;
133 u64 curr;
134 u16 curr_ptr;
135 u16 elements;
136 u32 pad[3];
137} __attribute__ ((__packed__));
138
139struct SHARED_MEMORY {
140 /* C000 */
141 u32 HostToNgene[64];
142
143 /* C100 */
144 u32 NgeneToHost[64];
145
146 /* C200 */
147 u64 NgeneCommand;
148 u64 NgeneStatus;
149 u64 NgeneEvent;
150
151 /* C210 */
152 u8 pad1[0xc260 - 0xc218];
153
154 /* C260 */
155 u32 IntCounts;
156 u32 IntEnable;
157
158 /* C268 */
159 u8 pad2[0xd000 - 0xc268];
160
161} __attribute__ ((__packed__));
162
163struct BUFFER_STREAM_RESULTS {
164 u32 Clock; /* Stream time in 100ns units */
165 u16 RemainingLines; /* Remaining lines in this field.
166 0 for complete field */
167 u8 FieldCount; /* Video field number */
168 u8 Flags; /* Bit 7 = Done, Bit 6 = seen, Bit 5 = overflow,
169 Bit 0 = FieldID */
170 u16 BlockCount; /* Audio block count (unused) */
171 u8 Reserved[2];
172 u32 DTOUpdate;
173} __attribute__ ((__packed__));
174
175struct HW_SCATTER_GATHER_ELEMENT {
176 u64 Address;
177 u32 Length;
178 u32 Reserved;
179} __attribute__ ((__packed__));
180
181struct BUFFER_HEADER {
182 u64 Next;
183 struct BUFFER_STREAM_RESULTS SR;
184
185 u32 Number_of_entries_1;
186 u32 Reserved5;
187 u64 Address_of_first_entry_1;
188
189 u32 Number_of_entries_2;
190 u32 Reserved7;
191 u64 Address_of_first_entry_2;
192} __attribute__ ((__packed__));
193
194struct EVENT_BUFFER {
195 u32 TimeStamp;
196 u8 GPIOStatus;
197 u8 UARTStatus;
198 u8 RXCharacter;
199 u8 EventStatus;
200 u32 Reserved[2];
201} __attribute__ ((__packed__));
202
203/* Firmware commands. */
204
205enum OPCODES {
206 CMD_NOP = 0,
207 CMD_FWLOAD_PREPARE = 0x01,
208 CMD_FWLOAD_FINISH = 0x02,
209 CMD_I2C_READ = 0x03,
210 CMD_I2C_WRITE = 0x04,
211
212 CMD_I2C_WRITE_NOSTOP = 0x05,
213 CMD_I2C_CONTINUE_WRITE = 0x06,
214 CMD_I2C_CONTINUE_WRITE_NOSTOP = 0x07,
215
216 CMD_DEBUG_OUTPUT = 0x09,
217
218 CMD_CONTROL = 0x10,
219 CMD_CONFIGURE_BUFFER = 0x11,
220 CMD_CONFIGURE_FREE_BUFFER = 0x12,
221
222 CMD_SPI_READ = 0x13,
223 CMD_SPI_WRITE = 0x14,
224
225 CMD_MEM_READ = 0x20,
226 CMD_MEM_WRITE = 0x21,
227 CMD_SFR_READ = 0x22,
228 CMD_SFR_WRITE = 0x23,
229 CMD_IRAM_READ = 0x24,
230 CMD_IRAM_WRITE = 0x25,
231 CMD_SET_GPIO_PIN = 0x26,
232 CMD_SET_GPIO_INT = 0x27,
233 CMD_CONFIGURE_UART = 0x28,
234 CMD_WRITE_UART = 0x29,
235 MAX_CMD
236};
237
238enum RESPONSES {
239 OK = 0,
240 ERROR = 1
241};
242
243struct FW_HEADER {
244 u8 Opcode;
245 u8 Length;
246} __attribute__ ((__packed__));
247
248struct FW_I2C_WRITE {
249 struct FW_HEADER hdr;
250 u8 Device;
251 u8 Data[250];
252} __attribute__ ((__packed__));
253
254struct FW_I2C_CONTINUE_WRITE {
255 struct FW_HEADER hdr;
256 u8 Data[250];
257} __attribute__ ((__packed__));
258
259struct FW_I2C_READ {
260 struct FW_HEADER hdr;
261 u8 Device;
262 u8 Data[252]; /* followed by two bytes of read data count */
263} __attribute__ ((__packed__));
264
265struct FW_SPI_WRITE {
266 struct FW_HEADER hdr;
267 u8 ModeSelect;
268 u8 Data[250];
269} __attribute__ ((__packed__));
270
271struct FW_SPI_READ {
272 struct FW_HEADER hdr;
273 u8 ModeSelect;
274 u8 Data[252]; /* followed by two bytes of read data count */
275} __attribute__ ((__packed__));
276
277struct FW_FWLOAD_PREPARE {
278 struct FW_HEADER hdr;
279} __attribute__ ((__packed__));
280
281struct FW_FWLOAD_FINISH {
282 struct FW_HEADER hdr;
283 u16 Address; /* address of final block */
284 u16 Length;
285} __attribute__ ((__packed__));
286
287/*
288 * Meaning of FW_STREAM_CONTROL::Mode bits:
289 * Bit 7: Loopback PEXin to PEXout using TVOut channel
290 * Bit 6: AVLOOP
291 * Bit 5: Audio select; 0=I2S, 1=SPDIF
292 * Bit 4: AVSYNC
293 * Bit 3: Enable transport stream
294 * Bit 2: Enable audio capture
295 * Bit 1: Enable ITU-Video VBI capture
296 * Bit 0: Enable ITU-Video capture
297 *
298 * Meaning of FW_STREAM_CONTROL::Control bits (see UVI1_CTL)
299 * Bit 7: continuous capture
300 * Bit 6: capture one field
301 * Bit 5: capture one frame
302 * Bit 4: unused
303 * Bit 3: starting field; 0=odd, 1=even
304 * Bit 2: sample size; 0=8-bit, 1=10-bit
305 * Bit 1: data format; 0=UYVY, 1=YUY2
306 * Bit 0: resets buffer pointers
307*/
308
309enum FSC_MODE_BITS {
310 SMODE_LOOPBACK = 0x80,
311 SMODE_AVLOOP = 0x40,
312 _SMODE_AUDIO_SPDIF = 0x20,
313 _SMODE_AVSYNC = 0x10,
314 _SMODE_TRANSPORT_STREAM = 0x08,
315 _SMODE_AUDIO_CAPTURE = 0x04,
316 _SMODE_VBI_CAPTURE = 0x02,
317 _SMODE_VIDEO_CAPTURE = 0x01
318};
319
320
321/* Meaning of FW_STREAM_CONTROL::Stream bits:
322 * Bit 3: Audio sample count: 0 = relative, 1 = absolute
323 * Bit 2: color bar select; 1=color bars, 0=CV3 decoder
324 * Bits 1-0: stream select, UVI1, UVI2, TVOUT
325 */
326
327struct FW_STREAM_CONTROL {
328 struct FW_HEADER hdr;
329 u8 Stream; /* Stream number (UVI1, UVI2, TVOUT) */
330 u8 Control; /* Value written to UVI1_CTL */
331 u8 Mode; /* Controls clock source */
332 u8 SetupDataLen; /* Length of setup data, MSB=1 write
333 backwards */
334 u16 CaptureBlockCount; /* Blocks (a 256 Bytes) to capture per buffer
335 for TS and Audio */
336 u64 Buffer_Address; /* Address of first buffer header */
337 u16 BytesPerVideoLine;
338 u16 MaxLinesPerField;
339 u16 MinLinesPerField;
340 u16 Reserved_1;
341 u16 BytesPerVBILine;
342 u16 MaxVBILinesPerField;
343 u16 MinVBILinesPerField;
344 u16 SetupDataAddr; /* ngene relative address of setup data */
345 u8 SetupData[32]; /* setup data */
346} __attribute__((__packed__));
347
348#define AUDIO_BLOCK_SIZE 256
349#define TS_BLOCK_SIZE 256
350
351struct FW_MEM_READ {
352 struct FW_HEADER hdr;
353 u16 address;
354} __attribute__ ((__packed__));
355
356struct FW_MEM_WRITE {
357 struct FW_HEADER hdr;
358 u16 address;
359 u8 data;
360} __attribute__ ((__packed__));
361
362struct FW_SFR_IRAM_READ {
363 struct FW_HEADER hdr;
364 u8 address;
365} __attribute__ ((__packed__));
366
367struct FW_SFR_IRAM_WRITE {
368 struct FW_HEADER hdr;
369 u8 address;
370 u8 data;
371} __attribute__ ((__packed__));
372
373struct FW_SET_GPIO_PIN {
374 struct FW_HEADER hdr;
375 u8 select;
376} __attribute__ ((__packed__));
377
378struct FW_SET_GPIO_INT {
379 struct FW_HEADER hdr;
380 u8 select;
381} __attribute__ ((__packed__));
382
383struct FW_SET_DEBUGMODE {
384 struct FW_HEADER hdr;
385 u8 debug_flags;
386} __attribute__ ((__packed__));
387
388struct FW_CONFIGURE_BUFFERS {
389 struct FW_HEADER hdr;
390 u8 config;
391} __attribute__ ((__packed__));
392
393enum _BUFFER_CONFIGS {
394 /* 4k UVI1, 4k UVI2, 2k AUD1, 2k AUD2 (standard usage) */
395 BUFFER_CONFIG_4422 = 0,
396 /* 3k UVI1, 3k UVI2, 3k AUD1, 3k AUD2 (4x TS input usage) */
397 BUFFER_CONFIG_3333 = 1,
398 /* 8k UVI1, 0k UVI2, 2k AUD1, 2k I2SOut (HDTV decoder usage) */
399 BUFFER_CONFIG_8022 = 2,
400 BUFFER_CONFIG_FW17 = 255, /* Use new FW 17 command */
401};
402
403struct FW_CONFIGURE_FREE_BUFFERS {
404 struct FW_HEADER hdr;
405 u8 UVI1_BufferLength;
406 u8 UVI2_BufferLength;
407 u8 TVO_BufferLength;
408 u8 AUD1_BufferLength;
409 u8 AUD2_BufferLength;
410 u8 TVA_BufferLength;
411} __attribute__ ((__packed__));
412
413struct FW_CONFIGURE_UART {
414 struct FW_HEADER hdr;
415 u8 UartControl;
416} __attribute__ ((__packed__));
417
418enum _UART_CONFIG {
419 _UART_BAUDRATE_19200 = 0,
420 _UART_BAUDRATE_9600 = 1,
421 _UART_BAUDRATE_4800 = 2,
422 _UART_BAUDRATE_2400 = 3,
423 _UART_RX_ENABLE = 0x40,
424 _UART_TX_ENABLE = 0x80,
425};
426
427struct FW_WRITE_UART {
428 struct FW_HEADER hdr;
429 u8 Data[252];
430} __attribute__ ((__packed__));
431
432
433struct ngene_command {
434 u32 in_len;
435 u32 out_len;
436 union {
437 u32 raw[64];
438 u8 raw8[256];
439 struct FW_HEADER hdr;
440 struct FW_I2C_WRITE I2CWrite;
441 struct FW_I2C_CONTINUE_WRITE I2CContinueWrite;
442 struct FW_I2C_READ I2CRead;
443 struct FW_STREAM_CONTROL StreamControl;
444 struct FW_FWLOAD_PREPARE FWLoadPrepare;
445 struct FW_FWLOAD_FINISH FWLoadFinish;
446 struct FW_MEM_READ MemoryRead;
447 struct FW_MEM_WRITE MemoryWrite;
448 struct FW_SFR_IRAM_READ SfrIramRead;
449 struct FW_SFR_IRAM_WRITE SfrIramWrite;
450 struct FW_SPI_WRITE SPIWrite;
451 struct FW_SPI_READ SPIRead;
452 struct FW_SET_GPIO_PIN SetGpioPin;
453 struct FW_SET_GPIO_INT SetGpioInt;
454 struct FW_SET_DEBUGMODE SetDebugMode;
455 struct FW_CONFIGURE_BUFFERS ConfigureBuffers;
456 struct FW_CONFIGURE_FREE_BUFFERS ConfigureFreeBuffers;
457 struct FW_CONFIGURE_UART ConfigureUart;
458 struct FW_WRITE_UART WriteUart;
459 } cmd;
460} __attribute__ ((__packed__));
461
462#define NGENE_INTERFACE_VERSION 0x103
463#define MAX_VIDEO_BUFFER_SIZE (417792) /* 288*1440 rounded up to next page */
464#define MAX_AUDIO_BUFFER_SIZE (8192) /* Gives room for about 23msec@48KHz */
465#define MAX_VBI_BUFFER_SIZE (28672) /* 1144*18 rounded up to next page */
466#define MAX_TS_BUFFER_SIZE (98304) /* 512*188 rounded up to next page */
467#define MAX_HDTV_BUFFER_SIZE (2080768) /* 541*1920*2 rounded up to next page
468 Max: (1920x1080i60) */
469
470#define OVERFLOW_BUFFER_SIZE (8192)
471
472#define RING_SIZE_VIDEO 4
473#define RING_SIZE_AUDIO 8
474#define RING_SIZE_TS 8
475
476#define NUM_SCATTER_GATHER_ENTRIES 8
477
478#define MAX_DMA_LENGTH (((MAX_VIDEO_BUFFER_SIZE + MAX_VBI_BUFFER_SIZE) * \
479 RING_SIZE_VIDEO * 2) + \
480 (MAX_AUDIO_BUFFER_SIZE * RING_SIZE_AUDIO * 2) + \
481 (MAX_TS_BUFFER_SIZE * RING_SIZE_TS * 4) + \
482 (RING_SIZE_VIDEO * PAGE_SIZE * 2) + \
483 (RING_SIZE_AUDIO * PAGE_SIZE * 2) + \
484 (RING_SIZE_TS * PAGE_SIZE * 4) + \
485 8 * PAGE_SIZE + OVERFLOW_BUFFER_SIZE + PAGE_SIZE)
486
487#define EVENT_QUEUE_SIZE 16
488
489/* Gathers the current state of a single channel. */
490
491struct SBufferHeader {
492 struct BUFFER_HEADER ngeneBuffer; /* Physical descriptor */
493 struct SBufferHeader *Next;
494 void *Buffer1;
495 struct HW_SCATTER_GATHER_ELEMENT *scList1;
496 void *Buffer2;
497 struct HW_SCATTER_GATHER_ELEMENT *scList2;
498};
499
500/* Sizeof SBufferHeader aligned to next 64 Bit boundary (hw restriction) */
501#define SIZEOF_SBufferHeader ((sizeof(struct SBufferHeader) + 63) & ~63)
502
503enum HWSTATE {
504 HWSTATE_STOP,
505 HWSTATE_STARTUP,
506 HWSTATE_RUN,
507 HWSTATE_PAUSE,
508};
509
510enum KSSTATE {
511 KSSTATE_STOP,
512 KSSTATE_ACQUIRE,
513 KSSTATE_PAUSE,
514 KSSTATE_RUN,
515};
516
517struct SRingBufferDescriptor {
518 struct SBufferHeader *Head; /* Points to first buffer in ring buffer
519 structure*/
520 u64 PAHead; /* Physical address of first buffer */
521 u32 MemSize; /* Memory size of allocated ring buffers
522 (needed for freeing) */
523 u32 NumBuffers; /* Number of buffers in the ring */
524 u32 Buffer1Length; /* Allocated length of Buffer 1 */
525 u32 Buffer2Length; /* Allocated length of Buffer 2 */
526 void *SCListMem; /* Memory to hold scatter gather lists for this
527 ring */
528 u64 PASCListMem; /* Physical address .. */
529 u32 SCListMemSize; /* Size of this memory */
530};
531
532enum STREAMMODEFLAGS {
533 StreamMode_NONE = 0, /* Stream not used */
534 StreamMode_ANALOG = 1, /* Analog: Stream 0,1 = Video, 2,3 = Audio */
535 StreamMode_TSIN = 2, /* Transport stream input (all) */
536 StreamMode_HDTV = 4, /* HDTV: Maximum 1920x1080p30,1920x1080i60
537 (only stream 0) */
538 StreamMode_TSOUT = 8, /* Transport stream output (only stream 3) */
539};
540
541
542enum BufferExchangeFlags {
543 BEF_EVEN_FIELD = 0x00000001,
544 BEF_CONTINUATION = 0x00000002,
545 BEF_MORE_DATA = 0x00000004,
546 BEF_OVERFLOW = 0x00000008,
547 DF_SWAP32 = 0x00010000,
548};
549
550typedef void *(IBufferExchange)(void *, void *, u32, u32, u32);
551
552struct MICI_STREAMINFO {
553 IBufferExchange *pExchange;
554 IBufferExchange *pExchangeVBI; /* Secondary (VBI, ancillary) */
555 u8 Stream;
556 u8 Flags;
557 u8 Mode;
558 u8 Reserved;
559 u16 nLinesVideo;
560 u16 nBytesPerLineVideo;
561 u16 nLinesVBI;
562 u16 nBytesPerLineVBI;
563 u32 CaptureLength; /* Used for audio and transport stream */
564};
565
566/****************************************************************************/
567/* STRUCTS ******************************************************************/
568/****************************************************************************/
569
570/* sound hardware definition */
571#define MIXER_ADDR_TVTUNER 0
572#define MIXER_ADDR_LAST 0
573
574struct ngene_channel;
575
576/*struct sound chip*/
577
578struct mychip {
579 struct ngene_channel *chan;
580 struct snd_card *card;
581 struct pci_dev *pci;
582 struct snd_pcm_substream *substream;
583 struct snd_pcm *pcm;
584 unsigned long port;
585 int irq;
586 spinlock_t mixer_lock;
587 spinlock_t lock;
588 int mixer_volume[MIXER_ADDR_LAST + 1][2];
589 int capture_source[MIXER_ADDR_LAST + 1][2];
590};
591
592#ifdef NGENE_V4L
593struct ngene_overlay {
594 int tvnorm;
595 struct v4l2_rect w;
596 enum v4l2_field field;
597 struct v4l2_clip *clips;
598 int nclips;
599 int setup_ok;
600};
601
602struct ngene_tvnorm {
603 int v4l2_id;
604 char *name;
605 u16 swidth, sheight; /* scaled standard width, height */
606 int tuner_norm;
607 int soundstd;
608};
609
610struct ngene_vopen {
611 struct ngene_channel *ch;
612 enum v4l2_priority prio;
613 int width;
614 int height;
615 int depth;
616 struct videobuf_queue vbuf_q;
617 struct videobuf_queue vbi;
618 int fourcc;
619 int picxcount;
620 int resources;
621 enum v4l2_buf_type type;
622 const struct ngene_format *fmt;
623
624 const struct ngene_format *ovfmt;
625 struct ngene_overlay ov;
626};
627#endif
628
629struct ngene_channel {
630 struct device device;
631 struct i2c_adapter i2c_adapter;
632
633 struct ngene *dev;
634 int number;
635 int type;
636 int mode;
637
638 struct dvb_frontend *fe;
639 struct dmxdev dmxdev;
640 struct dvb_demux demux;
641 struct dmx_frontend hw_frontend;
642 struct dmx_frontend mem_frontend;
643 int users;
644 struct video_device *v4l_dev;
645 struct tasklet_struct demux_tasklet;
646
647 struct SBufferHeader *nextBuffer;
648 enum KSSTATE State;
649 enum HWSTATE HWState;
650 u8 Stream;
651 u8 Flags;
652 u8 Mode;
653 IBufferExchange *pBufferExchange;
654 IBufferExchange *pBufferExchange2;
655
656 spinlock_t state_lock;
657 u16 nLines;
658 u16 nBytesPerLine;
659 u16 nVBILines;
660 u16 nBytesPerVBILine;
661 u16 itumode;
662 u32 Capture1Length;
663 u32 Capture2Length;
664 struct SRingBufferDescriptor RingBuffer;
665 struct SRingBufferDescriptor TSRingBuffer;
666 struct SRingBufferDescriptor TSIdleBuffer;
667
668 u32 DataFormatFlags;
669
670 int AudioDTOUpdated;
671 u32 AudioDTOValue;
672
673 int (*set_tone)(struct dvb_frontend *, fe_sec_tone_mode_t);
674 u8 lnbh;
675
676 /* stuff from analog driver */
677
678 int minor;
679 struct mychip *mychip;
680 struct snd_card *soundcard;
681 u8 *evenbuffer;
682 u8 dma_on;
683 int soundstreamon;
684 int audiomute;
685 int soundbuffisallocated;
686 int sndbuffflag;
687 int tun_rdy;
688 int dec_rdy;
689 int tun_dec_rdy;
690 int lastbufferflag;
691
692 struct ngene_tvnorm *tvnorms;
693 int tvnorm_num;
694 int tvnorm;
695
696#ifdef NGENE_V4L
697 int videousers;
698 struct v4l2_prio_state prio;
699 struct ngene_vopen init;
700 int resources;
701 struct v4l2_framebuffer fbuf;
702 struct ngene_buffer *screen; /* overlay */
703 struct list_head capture; /* video capture queue */
704 spinlock_t s_lock;
705 struct semaphore reslock;
706#endif
707
708 int running;
709};
710
711struct ngene;
712
713typedef void (rx_cb_t)(struct ngene *, u32, u8);
714typedef void (tx_cb_t)(struct ngene *, u32);
715
716struct ngene {
717 int nr;
718 struct pci_dev *pci_dev;
719 unsigned char *iomem;
720
721 /*struct i2c_adapter i2c_adapter;*/
722
723 u32 device_version;
724 u32 fw_interface_version;
725 u32 icounts;
726
727 u8 *CmdDoneByte;
728 int BootFirmware;
729 void *OverflowBuffer;
730 dma_addr_t PAOverflowBuffer;
731 void *FWInterfaceBuffer;
732 dma_addr_t PAFWInterfaceBuffer;
733 u8 *ngenetohost;
734 u8 *hosttongene;
735
736 struct EVENT_BUFFER EventQueue[EVENT_QUEUE_SIZE];
737 int EventQueueOverflowCount;
738 int EventQueueOverflowFlag;
739 struct tasklet_struct event_tasklet;
740 struct EVENT_BUFFER *EventBuffer;
741 int EventQueueWriteIndex;
742 int EventQueueReadIndex;
743
744 wait_queue_head_t cmd_wq;
745 int cmd_done;
746 struct semaphore cmd_mutex;
747 struct semaphore stream_mutex;
748 struct semaphore pll_mutex;
749 struct semaphore i2c_switch_mutex;
750 int i2c_current_channel;
751 int i2c_current_bus;
752 spinlock_t cmd_lock;
753
754 struct dvb_adapter adapter[MAX_STREAM];
755 struct ngene_channel channel[MAX_STREAM];
756
757 struct ngene_info *card_info;
758
759 tx_cb_t *TxEventNotify;
760 rx_cb_t *RxEventNotify;
761 int tx_busy;
762 wait_queue_head_t tx_wq;
763 wait_queue_head_t rx_wq;
764#define UART_RBUF_LEN 4096
765 u8 uart_rbuf[UART_RBUF_LEN];
766 int uart_rp, uart_wp;
767
768 u8 *tsout_buf;
769#define TSOUT_BUF_SIZE (512*188*8)
770 struct dvb_ringbuffer tsout_rbuf;
771
772 u8 *ain_buf;
773#define AIN_BUF_SIZE (128*1024)
774 struct dvb_ringbuffer ain_rbuf;
775
776
777 u8 *vin_buf;
778#define VIN_BUF_SIZE (4*1920*1080)
779 struct dvb_ringbuffer vin_rbuf;
780
781 unsigned long exp_val;
782 int prev_cmd;
783};
784
785struct ngene_info {
786 int type;
787#define NGENE_APP 0
788#define NGENE_TERRATEC 1
789#define NGENE_SIDEWINDER 2
790#define NGENE_RACER 3
791#define NGENE_VIPER 4
792#define NGENE_PYTHON 5
793#define NGENE_VBOX_V1 6
794#define NGENE_VBOX_V2 7
795
796 int fw_version;
797 char *name;
798
799 int io_type[MAX_STREAM];
800#define NGENE_IO_NONE 0
801#define NGENE_IO_TV 1
802#define NGENE_IO_HDTV 2
803#define NGENE_IO_TSIN 4
804#define NGENE_IO_TSOUT 8
805#define NGENE_IO_AIN 16
806
807 void *fe_config[4];
808 void *tuner_config[4];
809
810 int (*demod_attach[4])(struct ngene_channel *);
811 int (*tuner_attach[4])(struct ngene_channel *);
812
813 u8 avf[4];
814 u8 msp[4];
815 u8 demoda[4];
816 u8 lnb[4];
817 int i2c_access;
818 u8 ntsc;
819 u8 tsf[4];
820 u8 i2s[4];
821
822 int (*gate_ctrl)(struct dvb_frontend *, int);
823 int (*switch_ctrl)(struct ngene_channel *, int, int);
824};
825
826#ifdef NGENE_V4L
827struct ngene_format{
828 char *name;
829 int fourcc; /* video4linux 2 */
830 int btformat; /* BT848_COLOR_FMT_* */
831 int format;
832 int btswap; /* BT848_COLOR_CTL_* */
833 int depth; /* bit/pixel */
834 int flags;
835 int hshift, vshift; /* for planar modes */
836 int palette;
837};
838
839#define RESOURCE_OVERLAY 1
840#define RESOURCE_VIDEO 2
841#define RESOURCE_VBI 4
842
843struct ngene_buffer {
844 /* common v4l buffer stuff -- must be first */
845 struct videobuf_buffer vb;
846
847 /* ngene specific */
848 const struct ngene_format *fmt;
849 int tvnorm;
850 int btformat;
851 int btswap;
852};
853#endif
854
855
856#endif
857
858/* LocalWords: Endif
859 */
diff --git a/drivers/media/dvb/siano/sms-cards.c b/drivers/media/dvb/siano/sms-cards.c
index 1067b22eb0c6..cff77e2eb557 100644
--- a/drivers/media/dvb/siano/sms-cards.c
+++ b/drivers/media/dvb/siano/sms-cards.c
@@ -62,6 +62,7 @@ static struct sms_board sms_boards[] = {
62 [SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = { 62 [SMS1XXX_BOARD_HAUPPAUGE_WINDHAM] = {
63 .name = "Hauppauge WinTV MiniStick", 63 .name = "Hauppauge WinTV MiniStick",
64 .type = SMS_NOVA_B0, 64 .type = SMS_NOVA_B0,
65 .fw[DEVICE_MODE_ISDBT_BDA] = "sms1xxx-hcw-55xxx-isdbt-02.fw",
65 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw", 66 .fw[DEVICE_MODE_DVBT_BDA] = "sms1xxx-hcw-55xxx-dvbt-02.fw",
66 .board_cfg.leds_power = 26, 67 .board_cfg.leds_power = 26,
67 .board_cfg.led0 = 27, 68 .board_cfg.led0 = 27,
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index ca758bcb48c9..4bfd3451b568 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -1459,8 +1459,10 @@ int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
1459 if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) { 1459 if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) {
1460 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_REQ; 1460 pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_REQ;
1461 if (GetGpioPinParams(PinNum, &TranslatedPinNum, &GroupNum, 1461 if (GetGpioPinParams(PinNum, &TranslatedPinNum, &GroupNum,
1462 &groupCfg) != 0) 1462 &groupCfg) != 0) {
1463 return -EINVAL; 1463 rc = -EINVAL;
1464 goto free;
1465 }
1464 1466
1465 pMsg->msgData[1] = TranslatedPinNum; 1467 pMsg->msgData[1] = TranslatedPinNum;
1466 pMsg->msgData[2] = GroupNum; 1468 pMsg->msgData[2] = GroupNum;
@@ -1490,6 +1492,7 @@ int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
1490 else 1492 else
1491 sms_err("smscore_gpio_configure error"); 1493 sms_err("smscore_gpio_configure error");
1492 } 1494 }
1495free:
1493 kfree(buffer); 1496 kfree(buffer);
1494 1497
1495 return rc; 1498 return rc;
diff --git a/drivers/media/dvb/siano/smscoreapi.h b/drivers/media/dvb/siano/smscoreapi.h
index eec18aaf5512..8ecadecaa9d0 100644
--- a/drivers/media/dvb/siano/smscoreapi.h
+++ b/drivers/media/dvb/siano/smscoreapi.h
@@ -212,6 +212,8 @@ struct smscore_device_t {
212#define MSG_SMS_DAB_CHANNEL 607 212#define MSG_SMS_DAB_CHANNEL 607
213#define MSG_SMS_GET_PID_FILTER_LIST_REQ 608 213#define MSG_SMS_GET_PID_FILTER_LIST_REQ 608
214#define MSG_SMS_GET_PID_FILTER_LIST_RES 609 214#define MSG_SMS_GET_PID_FILTER_LIST_RES 609
215#define MSG_SMS_GET_STATISTICS_RES 616
216#define MSG_SMS_GET_STATISTICS_REQ 615
215#define MSG_SMS_HO_PER_SLICES_IND 630 217#define MSG_SMS_HO_PER_SLICES_IND 630
216#define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651 218#define MSG_SMS_SET_ANTENNA_CONFIG_REQ 651
217#define MSG_SMS_SET_ANTENNA_CONFIG_RES 652 219#define MSG_SMS_SET_ANTENNA_CONFIG_RES 652
@@ -339,7 +341,7 @@ struct SmsFirmware_ST {
339 341
340/* Statistics information returned as response for 342/* Statistics information returned as response for
341 * SmsHostApiGetStatistics_Req */ 343 * SmsHostApiGetStatistics_Req */
342struct SMSHOSTLIB_STATISTICS_S { 344struct SMSHOSTLIB_STATISTICS_ST {
343 u32 Reserved; /* Reserved */ 345 u32 Reserved; /* Reserved */
344 346
345 /* Common parameters */ 347 /* Common parameters */
@@ -424,6 +426,79 @@ struct SMSHOSTLIB_STATISTICS_S {
424 u32 ReservedFields[10]; /* Reserved */ 426 u32 ReservedFields[10]; /* Reserved */
425}; 427};
426 428
429struct SmsMsgStatisticsInfo_ST {
430 u32 RequestResult;
431
432 struct SMSHOSTLIB_STATISTICS_ST Stat;
433
434 /* Split the calc of the SNR in DAB */
435 u32 Signal; /* dB */
436 u32 Noise; /* dB */
437
438};
439
440struct SMSHOSTLIB_ISDBT_LAYER_STAT_ST {
441 /* Per-layer information */
442 u32 CodeRate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET,
443 * 255 means layer does not exist */
444 u32 Constellation; /* Constellation from SMSHOSTLIB_CONSTELLATION_ET,
445 * 255 means layer does not exist */
446 u32 BER; /* Post Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A */
447 u32 BERErrorCount; /* Post Viterbi Error Bits Count */
448 u32 BERBitCount; /* Post Viterbi Total Bits Count */
449 u32 PreBER; /* Pre Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A */
450 u32 TS_PER; /* Transport stream PER [%], 0xFFFFFFFF indicate N/A */
451 u32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
452 u32 TotalTSPackets; /* Total number of transport-stream packets */
453 u32 TILdepthI; /* Time interleaver depth I parameter,
454 * 255 means layer does not exist */
455 u32 NumberOfSegments; /* Number of segments in layer A,
456 * 255 means layer does not exist */
457 u32 TMCCErrors; /* TMCC errors */
458};
459
460struct SMSHOSTLIB_STATISTICS_ISDBT_ST {
461 u32 StatisticsType; /* Enumerator identifying the type of the
462 * structure. Values are the same as
463 * SMSHOSTLIB_DEVICE_MODES_E
464 *
465 * This field MUST always be first in any
466 * statistics structure */
467
468 u32 FullSize; /* Total size of the structure returned by the modem.
469 * If the size requested by the host is smaller than
470 * FullSize, the struct will be truncated */
471
472 /* Common parameters */
473 u32 IsRfLocked; /* 0 - not locked, 1 - locked */
474 u32 IsDemodLocked; /* 0 - not locked, 1 - locked */
475 u32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
476
477 /* Reception quality */
478 s32 SNR; /* dB */
479 s32 RSSI; /* dBm */
480 s32 InBandPwr; /* In band power in dBM */
481 s32 CarrierOffset; /* Carrier Offset in Hz */
482
483 /* Transmission parameters */
484 u32 Frequency; /* Frequency in Hz */
485 u32 Bandwidth; /* Bandwidth in MHz */
486 u32 TransmissionMode; /* ISDB-T transmission mode */
487 u32 ModemState; /* 0 - Acquisition, 1 - Locked */
488 u32 GuardInterval; /* Guard Interval, 1 divided by value */
489 u32 SystemType; /* ISDB-T system type (ISDB-T / ISDB-Tsb) */
490 u32 PartialReception; /* TRUE - partial reception, FALSE otherwise */
491 u32 NumOfLayers; /* Number of ISDB-T layers in the network */
492
493 /* Per-layer information */
494 /* Layers A, B and C */
495 struct SMSHOSTLIB_ISDBT_LAYER_STAT_ST LayerInfo[3];
496 /* Per-layer statistics, see SMSHOSTLIB_ISDBT_LAYER_STAT_ST */
497
498 /* Interface information */
499 u32 SmsToHostTxErrors; /* Total number of transmission errors. */
500};
501
427struct PID_STATISTICS_DATA_S { 502struct PID_STATISTICS_DATA_S {
428 struct PID_BURST_S { 503 struct PID_BURST_S {
429 u32 size; 504 u32 size;
diff --git a/drivers/media/dvb/siano/smsdvb.c b/drivers/media/dvb/siano/smsdvb.c
index 68bf9fbd8fed..5f3939821ca3 100644
--- a/drivers/media/dvb/siano/smsdvb.c
+++ b/drivers/media/dvb/siano/smsdvb.c
@@ -116,6 +116,118 @@ static void sms_board_dvb3_event(struct smsdvb_client_t *client,
116 } 116 }
117} 117}
118 118
119
120static void smsdvb_update_dvb_stats(struct RECEPTION_STATISTICS_S *pReceptionData,
121 struct SMSHOSTLIB_STATISTICS_ST *p)
122{
123 if (sms_dbg & 2) {
124 printk(KERN_DEBUG "Reserved = %d", p->Reserved);
125 printk(KERN_DEBUG "IsRfLocked = %d", p->IsRfLocked);
126 printk(KERN_DEBUG "IsDemodLocked = %d", p->IsDemodLocked);
127 printk(KERN_DEBUG "IsExternalLNAOn = %d", p->IsExternalLNAOn);
128 printk(KERN_DEBUG "SNR = %d", p->SNR);
129 printk(KERN_DEBUG "BER = %d", p->BER);
130 printk(KERN_DEBUG "FIB_CRC = %d", p->FIB_CRC);
131 printk(KERN_DEBUG "TS_PER = %d", p->TS_PER);
132 printk(KERN_DEBUG "MFER = %d", p->MFER);
133 printk(KERN_DEBUG "RSSI = %d", p->RSSI);
134 printk(KERN_DEBUG "InBandPwr = %d", p->InBandPwr);
135 printk(KERN_DEBUG "CarrierOffset = %d", p->CarrierOffset);
136 printk(KERN_DEBUG "Frequency = %d", p->Frequency);
137 printk(KERN_DEBUG "Bandwidth = %d", p->Bandwidth);
138 printk(KERN_DEBUG "TransmissionMode = %d", p->TransmissionMode);
139 printk(KERN_DEBUG "ModemState = %d", p->ModemState);
140 printk(KERN_DEBUG "GuardInterval = %d", p->GuardInterval);
141 printk(KERN_DEBUG "CodeRate = %d", p->CodeRate);
142 printk(KERN_DEBUG "LPCodeRate = %d", p->LPCodeRate);
143 printk(KERN_DEBUG "Hierarchy = %d", p->Hierarchy);
144 printk(KERN_DEBUG "Constellation = %d", p->Constellation);
145 printk(KERN_DEBUG "BurstSize = %d", p->BurstSize);
146 printk(KERN_DEBUG "BurstDuration = %d", p->BurstDuration);
147 printk(KERN_DEBUG "BurstCycleTime = %d", p->BurstCycleTime);
148 printk(KERN_DEBUG "CalculatedBurstCycleTime = %d", p->CalculatedBurstCycleTime);
149 printk(KERN_DEBUG "NumOfRows = %d", p->NumOfRows);
150 printk(KERN_DEBUG "NumOfPaddCols = %d", p->NumOfPaddCols);
151 printk(KERN_DEBUG "NumOfPunctCols = %d", p->NumOfPunctCols);
152 printk(KERN_DEBUG "ErrorTSPackets = %d", p->ErrorTSPackets);
153 printk(KERN_DEBUG "TotalTSPackets = %d", p->TotalTSPackets);
154 printk(KERN_DEBUG "NumOfValidMpeTlbs = %d", p->NumOfValidMpeTlbs);
155 printk(KERN_DEBUG "NumOfInvalidMpeTlbs = %d", p->NumOfInvalidMpeTlbs);
156 printk(KERN_DEBUG "NumOfCorrectedMpeTlbs = %d", p->NumOfCorrectedMpeTlbs);
157 printk(KERN_DEBUG "BERErrorCount = %d", p->BERErrorCount);
158 printk(KERN_DEBUG "BERBitCount = %d", p->BERBitCount);
159 printk(KERN_DEBUG "SmsToHostTxErrors = %d", p->SmsToHostTxErrors);
160 printk(KERN_DEBUG "PreBER = %d", p->PreBER);
161 printk(KERN_DEBUG "CellId = %d", p->CellId);
162 printk(KERN_DEBUG "DvbhSrvIndHP = %d", p->DvbhSrvIndHP);
163 printk(KERN_DEBUG "DvbhSrvIndLP = %d", p->DvbhSrvIndLP);
164 printk(KERN_DEBUG "NumMPEReceived = %d", p->NumMPEReceived);
165 }
166
167 pReceptionData->IsDemodLocked = p->IsDemodLocked;
168
169 pReceptionData->SNR = p->SNR;
170 pReceptionData->BER = p->BER;
171 pReceptionData->BERErrorCount = p->BERErrorCount;
172 pReceptionData->InBandPwr = p->InBandPwr;
173 pReceptionData->ErrorTSPackets = p->ErrorTSPackets;
174};
175
176
177static void smsdvb_update_isdbt_stats(struct RECEPTION_STATISTICS_S *pReceptionData,
178 struct SMSHOSTLIB_STATISTICS_ISDBT_ST *p)
179{
180 int i;
181
182 if (sms_dbg & 2) {
183 printk(KERN_DEBUG "IsRfLocked = %d", p->IsRfLocked);
184 printk(KERN_DEBUG "IsDemodLocked = %d", p->IsDemodLocked);
185 printk(KERN_DEBUG "IsExternalLNAOn = %d", p->IsExternalLNAOn);
186 printk(KERN_DEBUG "SNR = %d", p->SNR);
187 printk(KERN_DEBUG "RSSI = %d", p->RSSI);
188 printk(KERN_DEBUG "InBandPwr = %d", p->InBandPwr);
189 printk(KERN_DEBUG "CarrierOffset = %d", p->CarrierOffset);
190 printk(KERN_DEBUG "Frequency = %d", p->Frequency);
191 printk(KERN_DEBUG "Bandwidth = %d", p->Bandwidth);
192 printk(KERN_DEBUG "TransmissionMode = %d", p->TransmissionMode);
193 printk(KERN_DEBUG "ModemState = %d", p->ModemState);
194 printk(KERN_DEBUG "GuardInterval = %d", p->GuardInterval);
195 printk(KERN_DEBUG "SystemType = %d", p->SystemType);
196 printk(KERN_DEBUG "PartialReception = %d", p->PartialReception);
197 printk(KERN_DEBUG "NumOfLayers = %d", p->NumOfLayers);
198 printk(KERN_DEBUG "SmsToHostTxErrors = %d", p->SmsToHostTxErrors);
199
200 for (i = 0; i < 3; i++) {
201 printk(KERN_DEBUG "%d: CodeRate = %d", i, p->LayerInfo[i].CodeRate);
202 printk(KERN_DEBUG "%d: Constellation = %d", i, p->LayerInfo[i].Constellation);
203 printk(KERN_DEBUG "%d: BER = %d", i, p->LayerInfo[i].BER);
204 printk(KERN_DEBUG "%d: BERErrorCount = %d", i, p->LayerInfo[i].BERErrorCount);
205 printk(KERN_DEBUG "%d: BERBitCount = %d", i, p->LayerInfo[i].BERBitCount);
206 printk(KERN_DEBUG "%d: PreBER = %d", i, p->LayerInfo[i].PreBER);
207 printk(KERN_DEBUG "%d: TS_PER = %d", i, p->LayerInfo[i].TS_PER);
208 printk(KERN_DEBUG "%d: ErrorTSPackets = %d", i, p->LayerInfo[i].ErrorTSPackets);
209 printk(KERN_DEBUG "%d: TotalTSPackets = %d", i, p->LayerInfo[i].TotalTSPackets);
210 printk(KERN_DEBUG "%d: TILdepthI = %d", i, p->LayerInfo[i].TILdepthI);
211 printk(KERN_DEBUG "%d: NumberOfSegments = %d", i, p->LayerInfo[i].NumberOfSegments);
212 printk(KERN_DEBUG "%d: TMCCErrors = %d", i, p->LayerInfo[i].TMCCErrors);
213 }
214 }
215
216 pReceptionData->IsDemodLocked = p->IsDemodLocked;
217
218 pReceptionData->SNR = p->SNR;
219 pReceptionData->InBandPwr = p->InBandPwr;
220
221 pReceptionData->ErrorTSPackets = 0;
222 pReceptionData->BER = 0;
223 pReceptionData->BERErrorCount = 0;
224 for (i = 0; i < 3; i++) {
225 pReceptionData->BER += p->LayerInfo[i].BER;
226 pReceptionData->BERErrorCount += p->LayerInfo[i].BERErrorCount;
227 pReceptionData->ErrorTSPackets += p->LayerInfo[i].ErrorTSPackets;
228 }
229}
230
119static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb) 231static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
120{ 232{
121 struct smsdvb_client_t *client = (struct smsdvb_client_t *) context; 233 struct smsdvb_client_t *client = (struct smsdvb_client_t *) context;
@@ -134,6 +246,7 @@ static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
134 break; 246 break;
135 247
136 case MSG_SMS_RF_TUNE_RES: 248 case MSG_SMS_RF_TUNE_RES:
249 case MSG_SMS_ISDBT_TUNE_RES:
137 complete(&client->tune_done); 250 complete(&client->tune_done);
138 break; 251 break;
139 252
@@ -217,6 +330,40 @@ static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
217 is_status_update = true; 330 is_status_update = true;
218 break; 331 break;
219 } 332 }
333 case MSG_SMS_GET_STATISTICS_RES: {
334 union {
335 struct SMSHOSTLIB_STATISTICS_ISDBT_ST isdbt;
336 struct SmsMsgStatisticsInfo_ST dvb;
337 } *p = (void *) (phdr + 1);
338 struct RECEPTION_STATISTICS_S *pReceptionData =
339 &client->sms_stat_dvb.ReceptionData;
340
341 sms_info("MSG_SMS_GET_STATISTICS_RES");
342
343 is_status_update = true;
344
345 switch (smscore_get_device_mode(client->coredev)) {
346 case DEVICE_MODE_ISDBT:
347 case DEVICE_MODE_ISDBT_BDA:
348 smsdvb_update_isdbt_stats(pReceptionData, &p->isdbt);
349 break;
350 default:
351 smsdvb_update_dvb_stats(pReceptionData, &p->dvb.Stat);
352 }
353 if (!pReceptionData->IsDemodLocked) {
354 pReceptionData->SNR = 0;
355 pReceptionData->BER = 0;
356 pReceptionData->BERErrorCount = 0;
357 pReceptionData->InBandPwr = 0;
358 pReceptionData->ErrorTSPackets = 0;
359 }
360
361 complete(&client->tune_done);
362 break;
363 }
364 default:
365 sms_info("Unhandled message %d", phdr->msgType);
366
220 } 367 }
221 smscore_putbuffer(client->coredev, cb); 368 smscore_putbuffer(client->coredev, cb);
222 369
@@ -233,10 +380,10 @@ static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
233 DVB3_EVENT_UNC_ERR); 380 DVB3_EVENT_UNC_ERR);
234 381
235 } else { 382 } else {
236 /*client->fe_status = 383 if (client->sms_stat_dvb.ReceptionData.IsRfLocked)
237 (phdr->msgType == MSG_SMS_NO_SIGNAL_IND) ? 384 client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
238 0 : FE_HAS_SIGNAL;*/ 385 else
239 client->fe_status = 0; 386 client->fe_status = 0;
240 sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK); 387 sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK);
241 } 388 }
242 } 389 }
@@ -325,6 +472,20 @@ static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
325 0 : -ETIME; 472 0 : -ETIME;
326} 473}
327 474
475static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
476{
477 int rc;
478 struct SmsMsgHdr_ST Msg = { MSG_SMS_GET_STATISTICS_REQ,
479 DVBT_BDA_CONTROL_MSG_ID,
480 HIF_TASK,
481 sizeof(struct SmsMsgHdr_ST), 0 };
482
483 rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
484 &client->tune_done);
485
486 return rc;
487}
488
328static inline int led_feedback(struct smsdvb_client_t *client) 489static inline int led_feedback(struct smsdvb_client_t *client)
329{ 490{
330 if (client->fe_status & FE_HAS_LOCK) 491 if (client->fe_status & FE_HAS_LOCK)
@@ -337,33 +498,43 @@ static inline int led_feedback(struct smsdvb_client_t *client)
337 498
338static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat) 499static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat)
339{ 500{
501 int rc;
340 struct smsdvb_client_t *client; 502 struct smsdvb_client_t *client;
341 client = container_of(fe, struct smsdvb_client_t, frontend); 503 client = container_of(fe, struct smsdvb_client_t, frontend);
342 504
505 rc = smsdvb_send_statistics_request(client);
506
343 *stat = client->fe_status; 507 *stat = client->fe_status;
344 508
345 led_feedback(client); 509 led_feedback(client);
346 510
347 return 0; 511 return rc;
348} 512}
349 513
350static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber) 514static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber)
351{ 515{
516 int rc;
352 struct smsdvb_client_t *client; 517 struct smsdvb_client_t *client;
353 client = container_of(fe, struct smsdvb_client_t, frontend); 518 client = container_of(fe, struct smsdvb_client_t, frontend);
354 519
520 rc = smsdvb_send_statistics_request(client);
521
355 *ber = client->sms_stat_dvb.ReceptionData.BER; 522 *ber = client->sms_stat_dvb.ReceptionData.BER;
356 523
357 led_feedback(client); 524 led_feedback(client);
358 525
359 return 0; 526 return rc;
360} 527}
361 528
362static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength) 529static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
363{ 530{
531 int rc;
532
364 struct smsdvb_client_t *client; 533 struct smsdvb_client_t *client;
365 client = container_of(fe, struct smsdvb_client_t, frontend); 534 client = container_of(fe, struct smsdvb_client_t, frontend);
366 535
536 rc = smsdvb_send_statistics_request(client);
537
367 if (client->sms_stat_dvb.ReceptionData.InBandPwr < -95) 538 if (client->sms_stat_dvb.ReceptionData.InBandPwr < -95)
368 *strength = 0; 539 *strength = 0;
369 else if (client->sms_stat_dvb.ReceptionData.InBandPwr > -29) 540 else if (client->sms_stat_dvb.ReceptionData.InBandPwr > -29)
@@ -375,31 +546,37 @@ static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
375 546
376 led_feedback(client); 547 led_feedback(client);
377 548
378 return 0; 549 return rc;
379} 550}
380 551
381static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr) 552static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr)
382{ 553{
554 int rc;
383 struct smsdvb_client_t *client; 555 struct smsdvb_client_t *client;
384 client = container_of(fe, struct smsdvb_client_t, frontend); 556 client = container_of(fe, struct smsdvb_client_t, frontend);
385 557
558 rc = smsdvb_send_statistics_request(client);
559
386 *snr = client->sms_stat_dvb.ReceptionData.SNR; 560 *snr = client->sms_stat_dvb.ReceptionData.SNR;
387 561
388 led_feedback(client); 562 led_feedback(client);
389 563
390 return 0; 564 return rc;
391} 565}
392 566
393static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 567static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
394{ 568{
569 int rc;
395 struct smsdvb_client_t *client; 570 struct smsdvb_client_t *client;
396 client = container_of(fe, struct smsdvb_client_t, frontend); 571 client = container_of(fe, struct smsdvb_client_t, frontend);
397 572
573 rc = smsdvb_send_statistics_request(client);
574
398 *ucblocks = client->sms_stat_dvb.ReceptionData.ErrorTSPackets; 575 *ucblocks = client->sms_stat_dvb.ReceptionData.ErrorTSPackets;
399 576
400 led_feedback(client); 577 led_feedback(client);
401 578
402 return 0; 579 return rc;
403} 580}
404 581
405static int smsdvb_get_tune_settings(struct dvb_frontend *fe, 582static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
@@ -413,9 +590,10 @@ static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
413 return 0; 590 return 0;
414} 591}
415 592
416static int smsdvb_set_frontend(struct dvb_frontend *fe, 593static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe,
417 struct dvb_frontend_parameters *fep) 594 struct dvb_frontend_parameters *p)
418{ 595{
596 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
419 struct smsdvb_client_t *client = 597 struct smsdvb_client_t *client =
420 container_of(fe, struct smsdvb_client_t, frontend); 598 container_of(fe, struct smsdvb_client_t, frontend);
421 599
@@ -429,24 +607,33 @@ static int smsdvb_set_frontend(struct dvb_frontend *fe,
429 client->fe_status = FE_HAS_SIGNAL; 607 client->fe_status = FE_HAS_SIGNAL;
430 client->event_fe_state = -1; 608 client->event_fe_state = -1;
431 client->event_unc_state = -1; 609 client->event_unc_state = -1;
610 fe->dtv_property_cache.delivery_system = SYS_DVBT;
432 611
433 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; 612 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
434 Msg.Msg.msgDstId = HIF_TASK; 613 Msg.Msg.msgDstId = HIF_TASK;
435 Msg.Msg.msgFlags = 0; 614 Msg.Msg.msgFlags = 0;
436 Msg.Msg.msgType = MSG_SMS_RF_TUNE_REQ; 615 Msg.Msg.msgType = MSG_SMS_RF_TUNE_REQ;
437 Msg.Msg.msgLength = sizeof(Msg); 616 Msg.Msg.msgLength = sizeof(Msg);
438 Msg.Data[0] = fep->frequency; 617 Msg.Data[0] = c->frequency;
439 Msg.Data[2] = 12000000; 618 Msg.Data[2] = 12000000;
440 619
441 sms_debug("freq %d band %d", 620 sms_info("%s: freq %d band %d", __func__, c->frequency,
442 fep->frequency, fep->u.ofdm.bandwidth); 621 c->bandwidth_hz);
443 622
444 switch (fep->u.ofdm.bandwidth) { 623 switch (c->bandwidth_hz / 1000000) {
445 case BANDWIDTH_8_MHZ: Msg.Data[1] = BW_8_MHZ; break; 624 case 8:
446 case BANDWIDTH_7_MHZ: Msg.Data[1] = BW_7_MHZ; break; 625 Msg.Data[1] = BW_8_MHZ;
447 case BANDWIDTH_6_MHZ: Msg.Data[1] = BW_6_MHZ; break; 626 break;
448 case BANDWIDTH_AUTO: return -EOPNOTSUPP; 627 case 7:
449 default: return -EINVAL; 628 Msg.Data[1] = BW_7_MHZ;
629 break;
630 case 6:
631 Msg.Data[1] = BW_6_MHZ;
632 break;
633 case 0:
634 return -EOPNOTSUPP;
635 default:
636 return -EINVAL;
450 } 637 }
451 /* Disable LNA, if any. An error is returned if no LNA is present */ 638 /* Disable LNA, if any. An error is returned if no LNA is present */
452 ret = sms_board_lna_control(client->coredev, 0); 639 ret = sms_board_lna_control(client->coredev, 0);
@@ -470,6 +657,90 @@ static int smsdvb_set_frontend(struct dvb_frontend *fe,
470 &client->tune_done); 657 &client->tune_done);
471} 658}
472 659
660static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe,
661 struct dvb_frontend_parameters *p)
662{
663 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
664 struct smsdvb_client_t *client =
665 container_of(fe, struct smsdvb_client_t, frontend);
666
667 struct {
668 struct SmsMsgHdr_ST Msg;
669 u32 Data[4];
670 } Msg;
671
672 fe->dtv_property_cache.delivery_system = SYS_ISDBT;
673
674 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
675 Msg.Msg.msgDstId = HIF_TASK;
676 Msg.Msg.msgFlags = 0;
677 Msg.Msg.msgType = MSG_SMS_ISDBT_TUNE_REQ;
678 Msg.Msg.msgLength = sizeof(Msg);
679
680 if (c->isdbt_sb_segment_idx == -1)
681 c->isdbt_sb_segment_idx = 0;
682
683 switch (c->isdbt_sb_segment_count) {
684 case 3:
685 Msg.Data[1] = BW_ISDBT_3SEG;
686 break;
687 case 1:
688 Msg.Data[1] = BW_ISDBT_1SEG;
689 break;
690 case 0: /* AUTO */
691 switch (c->bandwidth_hz / 1000000) {
692 case 8:
693 case 7:
694 c->isdbt_sb_segment_count = 3;
695 Msg.Data[1] = BW_ISDBT_3SEG;
696 break;
697 case 6:
698 c->isdbt_sb_segment_count = 1;
699 Msg.Data[1] = BW_ISDBT_1SEG;
700 break;
701 default: /* Assumes 6 MHZ bw */
702 c->isdbt_sb_segment_count = 1;
703 c->bandwidth_hz = 6000;
704 Msg.Data[1] = BW_ISDBT_1SEG;
705 break;
706 }
707 break;
708 default:
709 sms_info("Segment count %d not supported", c->isdbt_sb_segment_count);
710 return -EINVAL;
711 }
712
713 Msg.Data[0] = c->frequency;
714 Msg.Data[2] = 12000000;
715 Msg.Data[3] = c->isdbt_sb_segment_idx;
716
717 sms_info("%s: freq %d segwidth %d segindex %d\n", __func__,
718 c->frequency, c->isdbt_sb_segment_count,
719 c->isdbt_sb_segment_idx);
720
721 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
722 &client->tune_done);
723}
724
725static int smsdvb_set_frontend(struct dvb_frontend *fe,
726 struct dvb_frontend_parameters *fep)
727{
728 struct smsdvb_client_t *client =
729 container_of(fe, struct smsdvb_client_t, frontend);
730 struct smscore_device_t *coredev = client->coredev;
731
732 switch (smscore_get_device_mode(coredev)) {
733 case DEVICE_MODE_DVBT:
734 case DEVICE_MODE_DVBT_BDA:
735 return smsdvb_dvbt_set_frontend(fe, fep);
736 case DEVICE_MODE_ISDBT:
737 case DEVICE_MODE_ISDBT_BDA:
738 return smsdvb_isdbt_set_frontend(fe, fep);
739 default:
740 return -EINVAL;
741 }
742}
743
473static int smsdvb_get_frontend(struct dvb_frontend *fe, 744static int smsdvb_get_frontend(struct dvb_frontend *fe,
474 struct dvb_frontend_parameters *fep) 745 struct dvb_frontend_parameters *fep)
475{ 746{
@@ -557,13 +828,6 @@ static int smsdvb_hotplug(struct smscore_device_t *coredev,
557 /* device removal handled by onremove callback */ 828 /* device removal handled by onremove callback */
558 if (!arrival) 829 if (!arrival)
559 return 0; 830 return 0;
560
561 if (smscore_get_device_mode(coredev) != DEVICE_MODE_DVBT_BDA) {
562 sms_err("SMS Device mode is not set for "
563 "DVB operation.");
564 return 0;
565 }
566
567 client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL); 831 client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL);
568 if (!client) { 832 if (!client) {
569 sms_err("kmalloc() failed"); 833 sms_err("kmalloc() failed");
diff --git a/drivers/media/dvb/siano/smsir.c b/drivers/media/dvb/siano/smsir.c
index e3d776feeaca..a56eac76e0f0 100644
--- a/drivers/media/dvb/siano/smsir.c
+++ b/drivers/media/dvb/siano/smsir.c
@@ -85,9 +85,9 @@ static struct keyboard_layout_map_t keyboard_layout_maps[] = {
85 { } /* Terminating entry */ 85 { } /* Terminating entry */
86}; 86};
87 87
88u32 ir_pos; 88static u32 ir_pos;
89u32 ir_word; 89static u32 ir_word;
90u32 ir_toggle; 90static u32 ir_toggle;
91 91
92#define RC5_PUSH_BIT(dst, bit, pos) \ 92#define RC5_PUSH_BIT(dst, bit, pos) \
93 { dst <<= 1; dst |= bit; pos++; } 93 { dst <<= 1; dst |= bit; pos++; }
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index 23a1c6380d3f..b070e88d8c6b 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -268,8 +268,8 @@ int av7110_check_ir_config(struct av7110 *av7110, int force)
268 268
269 269
270/* /proc/av7110_ir interface */ 270/* /proc/av7110_ir interface */
271static int av7110_ir_write_proc(struct file *file, const char __user *buffer, 271static ssize_t av7110_ir_proc_write(struct file *file, const char __user *buffer,
272 unsigned long count, void *data) 272 size_t count, loff_t *pos)
273{ 273{
274 char *page; 274 char *page;
275 u32 ir_config; 275 u32 ir_config;
@@ -309,6 +309,10 @@ static int av7110_ir_write_proc(struct file *file, const char __user *buffer,
309 return count; 309 return count;
310} 310}
311 311
312static const struct file_operations av7110_ir_proc_fops = {
313 .owner = THIS_MODULE,
314 .write = av7110_ir_proc_write,
315};
312 316
313/* interrupt handler */ 317/* interrupt handler */
314static void ir_handler(struct av7110 *av7110, u32 ircom) 318static void ir_handler(struct av7110 *av7110, u32 ircom)
@@ -368,11 +372,9 @@ int __devinit av7110_ir_init(struct av7110 *av7110)
368 input_dev->timer.data = (unsigned long) &av7110->ir; 372 input_dev->timer.data = (unsigned long) &av7110->ir;
369 373
370 if (av_cnt == 1) { 374 if (av_cnt == 1) {
371 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL); 375 e = proc_create("av7110_ir", S_IWUSR, NULL, &av7110_ir_proc_fops);
372 if (e) { 376 if (e)
373 e->write_proc = av7110_ir_write_proc;
374 e->size = 4 + 256 * sizeof(u16); 377 e->size = 4 + 256 * sizeof(u16);
375 }
376 } 378 }
377 379
378 tasklet_init(&av7110->ir.ir_tasklet, av7110_emit_key, (unsigned long) &av7110->ir); 380 tasklet_init(&av7110->ir.ir_tasklet, av7110_emit_key, (unsigned long) &av7110->ir);
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 9782e0593733..49c2a817a06f 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -254,7 +254,7 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
254 budget_ci->ir.timer_keyup.function = msp430_ir_keyup; 254 budget_ci->ir.timer_keyup.function = msp430_ir_keyup;
255 budget_ci->ir.timer_keyup.data = (unsigned long) &budget_ci->ir; 255 budget_ci->ir.timer_keyup.data = (unsigned long) &budget_ci->ir;
256 budget_ci->ir.last_raw = 0xffff; /* An impossible value */ 256 budget_ci->ir.last_raw = 0xffff; /* An impossible value */
257 error = ir_input_register(input_dev, ir_codes); 257 error = ir_input_register(input_dev, ir_codes, NULL);
258 if (error) { 258 if (error) {
259 printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error); 259 printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
260 return error; 260 return error;
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index e48380c48990..9fdf26cc6998 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -433,9 +433,8 @@ static struct stv090x_config tt1600_stv090x_config = {
433 .demod_mode = STV090x_SINGLE, 433 .demod_mode = STV090x_SINGLE,
434 .clk_mode = STV090x_CLK_EXT, 434 .clk_mode = STV090x_CLK_EXT,
435 435
436 .xtal = 27000000, 436 .xtal = 13500000,
437 .address = 0x68, 437 .address = 0x68,
438 .ref_clk = 27000000,
439 438
440 .ts1_mode = STV090x_TSMODE_DVBCI, 439 .ts1_mode = STV090x_TSMODE_DVBCI,
441 .ts2_mode = STV090x_TSMODE_SERIAL_CONTINUOUS, 440 .ts2_mode = STV090x_TSMODE_SERIAL_CONTINUOUS,
@@ -457,6 +456,7 @@ static struct stv090x_config tt1600_stv090x_config = {
457static struct stv6110x_config tt1600_stv6110x_config = { 456static struct stv6110x_config tt1600_stv6110x_config = {
458 .addr = 0x60, 457 .addr = 0x60,
459 .refclk = 27000000, 458 .refclk = 27000000,
459 .clk_div = 2,
460}; 460};
461 461
462static struct isl6423_config tt1600_isl6423_config = { 462static struct isl6423_config tt1600_isl6423_config = {
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 3f40f375981b..83567b898d09 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -417,6 +417,18 @@ config RADIO_TEA5764_XTAL
417 Say Y here if TEA5764 have a 32768 Hz crystal in circuit, say N 417 Say Y here if TEA5764 have a 32768 Hz crystal in circuit, say N
418 here if TEA5764 reference frequency is connected in FREQIN. 418 here if TEA5764 reference frequency is connected in FREQIN.
419 419
420config RADIO_SAA7706H
421 tristate "SAA7706H Car Radio DSP"
422 depends on I2C && VIDEO_V4L2
423 ---help---
424 Say Y here if you want to use the SAA7706H Car radio Digital
425 Signal Processor, found for instance on the Russellville development
426 board. On the russellville the device is connected to internal
427 timberdale I2C bus.
428
429 To compile this driver as a module, choose M here: the
430 module will be called SAA7706H.
431
420config RADIO_TEF6862 432config RADIO_TEF6862
421 tristate "TEF6862 Car Radio Enhanced Selectivity Tuner" 433 tristate "TEF6862 Car Radio Enhanced Selectivity Tuner"
422 depends on I2C && VIDEO_V4L2 434 depends on I2C && VIDEO_V4L2
@@ -429,4 +441,15 @@ config RADIO_TEF6862
429 To compile this driver as a module, choose M here: the 441 To compile this driver as a module, choose M here: the
430 module will be called TEF6862. 442 module will be called TEF6862.
431 443
444config RADIO_TIMBERDALE
445 tristate "Enable the Timberdale radio driver"
446 depends on MFD_TIMBERDALE && VIDEO_V4L2
447 depends on I2C # for RADIO_SAA7706H
448 select RADIO_TEF6862
449 select RADIO_SAA7706H
450 ---help---
451 This is a kind of umbrella driver for the Radio Tuner and DSP
452 found behind the Timberdale FPGA on the Russellville board.
453 Enabling this driver will automatically select the DSP and tuner.
454
432endif # RADIO_ADAPTERS 455endif # RADIO_ADAPTERS
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index 01922ada6914..f615583b4837 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -23,6 +23,8 @@ obj-$(CONFIG_USB_DSBR) += dsbr100.o
23obj-$(CONFIG_RADIO_SI470X) += si470x/ 23obj-$(CONFIG_RADIO_SI470X) += si470x/
24obj-$(CONFIG_USB_MR800) += radio-mr800.o 24obj-$(CONFIG_USB_MR800) += radio-mr800.o
25obj-$(CONFIG_RADIO_TEA5764) += radio-tea5764.o 25obj-$(CONFIG_RADIO_TEA5764) += radio-tea5764.o
26obj-$(CONFIG_RADIO_SAA7706H) += saa7706h.o
26obj-$(CONFIG_RADIO_TEF6862) += tef6862.o 27obj-$(CONFIG_RADIO_TEF6862) += tef6862.o
28obj-$(CONFIG_RADIO_TIMBERDALE) += radio-timb.o
27 29
28EXTRA_CFLAGS += -Isound 30EXTRA_CFLAGS += -Isound
diff --git a/drivers/media/radio/radio-timb.c b/drivers/media/radio/radio-timb.c
new file mode 100644
index 000000000000..0de457f6e6eb
--- /dev/null
+++ b/drivers/media/radio/radio-timb.c
@@ -0,0 +1,244 @@
1/*
2 * radio-timb.c Timberdale FPGA Radio driver
3 * Copyright (c) 2009 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include <linux/version.h>
20#include <linux/io.h>
21#include <media/v4l2-ioctl.h>
22#include <media/v4l2-device.h>
23#include <linux/platform_device.h>
24#include <linux/interrupt.h>
25#include <linux/i2c.h>
26#include <media/timb_radio.h>
27
28#define DRIVER_NAME "timb-radio"
29
30struct timbradio {
31 struct timb_radio_platform_data pdata;
32 struct v4l2_subdev *sd_tuner;
33 struct v4l2_subdev *sd_dsp;
34 struct video_device video_dev;
35 struct v4l2_device v4l2_dev;
36};
37
38
39static int timbradio_vidioc_querycap(struct file *file, void *priv,
40 struct v4l2_capability *v)
41{
42 strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver));
43 strlcpy(v->card, "Timberdale Radio", sizeof(v->card));
44 snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
45 v->version = KERNEL_VERSION(0, 0, 1);
46 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
47 return 0;
48}
49
50static int timbradio_vidioc_g_tuner(struct file *file, void *priv,
51 struct v4l2_tuner *v)
52{
53 struct timbradio *tr = video_drvdata(file);
54 return v4l2_subdev_call(tr->sd_tuner, tuner, g_tuner, v);
55}
56
57static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
58 struct v4l2_tuner *v)
59{
60 struct timbradio *tr = video_drvdata(file);
61 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
62}
63
64static int timbradio_vidioc_g_input(struct file *filp, void *priv,
65 unsigned int *i)
66{
67 *i = 0;
68 return 0;
69}
70
71static int timbradio_vidioc_s_input(struct file *filp, void *priv,
72 unsigned int i)
73{
74 return i ? -EINVAL : 0;
75}
76
77static int timbradio_vidioc_g_audio(struct file *file, void *priv,
78 struct v4l2_audio *a)
79{
80 a->index = 0;
81 strlcpy(a->name, "Radio", sizeof(a->name));
82 a->capability = V4L2_AUDCAP_STEREO;
83 return 0;
84}
85
86static int timbradio_vidioc_s_audio(struct file *file, void *priv,
87 struct v4l2_audio *a)
88{
89 return a->index ? -EINVAL : 0;
90}
91
92static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
93 struct v4l2_frequency *f)
94{
95 struct timbradio *tr = video_drvdata(file);
96 return v4l2_subdev_call(tr->sd_tuner, tuner, s_frequency, f);
97}
98
99static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
100 struct v4l2_frequency *f)
101{
102 struct timbradio *tr = video_drvdata(file);
103 return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
104}
105
106static int timbradio_vidioc_queryctrl(struct file *file, void *priv,
107 struct v4l2_queryctrl *qc)
108{
109 struct timbradio *tr = video_drvdata(file);
110 return v4l2_subdev_call(tr->sd_dsp, core, queryctrl, qc);
111}
112
113static int timbradio_vidioc_g_ctrl(struct file *file, void *priv,
114 struct v4l2_control *ctrl)
115{
116 struct timbradio *tr = video_drvdata(file);
117 return v4l2_subdev_call(tr->sd_dsp, core, g_ctrl, ctrl);
118}
119
120static int timbradio_vidioc_s_ctrl(struct file *file, void *priv,
121 struct v4l2_control *ctrl)
122{
123 struct timbradio *tr = video_drvdata(file);
124 return v4l2_subdev_call(tr->sd_dsp, core, s_ctrl, ctrl);
125}
126
127static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
128 .vidioc_querycap = timbradio_vidioc_querycap,
129 .vidioc_g_tuner = timbradio_vidioc_g_tuner,
130 .vidioc_s_tuner = timbradio_vidioc_s_tuner,
131 .vidioc_g_frequency = timbradio_vidioc_g_frequency,
132 .vidioc_s_frequency = timbradio_vidioc_s_frequency,
133 .vidioc_g_input = timbradio_vidioc_g_input,
134 .vidioc_s_input = timbradio_vidioc_s_input,
135 .vidioc_g_audio = timbradio_vidioc_g_audio,
136 .vidioc_s_audio = timbradio_vidioc_s_audio,
137 .vidioc_queryctrl = timbradio_vidioc_queryctrl,
138 .vidioc_g_ctrl = timbradio_vidioc_g_ctrl,
139 .vidioc_s_ctrl = timbradio_vidioc_s_ctrl
140};
141
142static const struct v4l2_file_operations timbradio_fops = {
143 .owner = THIS_MODULE,
144 .ioctl = video_ioctl2,
145};
146
147static int __devinit timbradio_probe(struct platform_device *pdev)
148{
149 struct timb_radio_platform_data *pdata = pdev->dev.platform_data;
150 struct timbradio *tr;
151 int err;
152
153 if (!pdata) {
154 dev_err(&pdev->dev, "Platform data missing\n");
155 err = -EINVAL;
156 goto err;
157 }
158
159 tr = kzalloc(sizeof(*tr), GFP_KERNEL);
160 if (!tr) {
161 err = -ENOMEM;
162 goto err;
163 }
164
165 tr->pdata = *pdata;
166
167 strlcpy(tr->video_dev.name, "Timberdale Radio",
168 sizeof(tr->video_dev.name));
169 tr->video_dev.fops = &timbradio_fops;
170 tr->video_dev.ioctl_ops = &timbradio_ioctl_ops;
171 tr->video_dev.release = video_device_release_empty;
172 tr->video_dev.minor = -1;
173
174 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
175 err = v4l2_device_register(NULL, &tr->v4l2_dev);
176 if (err)
177 goto err_v4l2_dev;
178
179 tr->video_dev.v4l2_dev = &tr->v4l2_dev;
180
181 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
182 if (err) {
183 dev_err(&pdev->dev, "Error reg video\n");
184 goto err_video_req;
185 }
186
187 video_set_drvdata(&tr->video_dev, tr);
188
189 platform_set_drvdata(pdev, tr);
190 return 0;
191
192err_video_req:
193 video_device_release_empty(&tr->video_dev);
194 v4l2_device_unregister(&tr->v4l2_dev);
195err_v4l2_dev:
196 kfree(tr);
197err:
198 dev_err(&pdev->dev, "Failed to register: %d\n", err);
199
200 return err;
201}
202
203static int __devexit timbradio_remove(struct platform_device *pdev)
204{
205 struct timbradio *tr = platform_get_drvdata(pdev);
206
207 video_unregister_device(&tr->video_dev);
208 video_device_release_empty(&tr->video_dev);
209
210 v4l2_device_unregister(&tr->v4l2_dev);
211
212 kfree(tr);
213
214 return 0;
215}
216
217static struct platform_driver timbradio_platform_driver = {
218 .driver = {
219 .name = DRIVER_NAME,
220 .owner = THIS_MODULE,
221 },
222 .probe = timbradio_probe,
223 .remove = timbradio_remove,
224};
225
226/*--------------------------------------------------------------------------*/
227
228static int __init timbradio_init(void)
229{
230 return platform_driver_register(&timbradio_platform_driver);
231}
232
233static void __exit timbradio_exit(void)
234{
235 platform_driver_unregister(&timbradio_platform_driver);
236}
237
238module_init(timbradio_init);
239module_exit(timbradio_exit);
240
241MODULE_DESCRIPTION("Timberdale Radio driver");
242MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
243MODULE_LICENSE("GPL v2");
244MODULE_ALIAS("platform:"DRIVER_NAME);
diff --git a/drivers/media/radio/saa7706h.c b/drivers/media/radio/saa7706h.c
new file mode 100644
index 000000000000..5db5528a8b25
--- /dev/null
+++ b/drivers/media/radio/saa7706h.c
@@ -0,0 +1,451 @@
1/*
2 * saa7706.c Philips SAA7706H Car Radio DSP driver
3 * Copyright (c) 2009 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/delay.h>
22#include <linux/errno.h>
23#include <linux/kernel.h>
24#include <linux/interrupt.h>
25#include <linux/i2c.h>
26#include <media/v4l2-device.h>
27#include <media/v4l2-chip-ident.h>
28
29#define DRIVER_NAME "saa7706h"
30
31/* the I2C memory map looks like this
32
33 $1C00 - $FFFF Not Used
34 $2200 - $3FFF Reserved YRAM (DSP2) space
35 $2000 - $21FF YRAM (DSP2)
36 $1FF0 - $1FFF Hardware Registers
37 $1280 - $1FEF Reserved XRAM (DSP2) space
38 $1000 - $127F XRAM (DSP2)
39 $0FFF DSP CONTROL
40 $0A00 - $0FFE Reserved
41 $0980 - $09FF Reserved YRAM (DSP1) space
42 $0800 - $097F YRAM (DSP1)
43 $0200 - $07FF Not Used
44 $0180 - $01FF Reserved XRAM (DSP1) space
45 $0000 - $017F XRAM (DSP1)
46*/
47
48#define SAA7706H_REG_CTRL 0x0fff
49#define SAA7706H_CTRL_BYP_PLL 0x0001
50#define SAA7706H_CTRL_PLL_DIV_MASK 0x003e
51#define SAA7706H_CTRL_PLL3_62975MHZ 0x003e
52#define SAA7706H_CTRL_DSP_TURBO 0x0040
53#define SAA7706H_CTRL_PC_RESET_DSP1 0x0080
54#define SAA7706H_CTRL_PC_RESET_DSP2 0x0100
55#define SAA7706H_CTRL_DSP1_ROM_EN_MASK 0x0600
56#define SAA7706H_CTRL_DSP1_FUNC_PROM 0x0000
57#define SAA7706H_CTRL_DSP2_ROM_EN_MASK 0x1800
58#define SAA7706H_CTRL_DSP2_FUNC_PROM 0x0000
59#define SAA7706H_CTRL_DIG_SIL_INTERPOL 0x8000
60
61#define SAA7706H_REG_EVALUATION 0x1ff0
62#define SAA7706H_EVAL_DISABLE_CHARGE_PUMP 0x000001
63#define SAA7706H_EVAL_DCS_CLOCK 0x000002
64#define SAA7706H_EVAL_GNDRC1_ENABLE 0x000004
65#define SAA7706H_EVAL_GNDRC2_ENABLE 0x000008
66
67#define SAA7706H_REG_CL_GEN1 0x1ff3
68#define SAA7706H_CL_GEN1_MIN_LOOPGAIN_MASK 0x00000f
69#define SAA7706H_CL_GEN1_LOOPGAIN_MASK 0x0000f0
70#define SAA7706H_CL_GEN1_COARSE_RATION 0xffff00
71
72#define SAA7706H_REG_CL_GEN2 0x1ff4
73#define SAA7706H_CL_GEN2_WSEDGE_FALLING 0x000001
74#define SAA7706H_CL_GEN2_STOP_VCO 0x000002
75#define SAA7706H_CL_GEN2_FRERUN 0x000004
76#define SAA7706H_CL_GEN2_ADAPTIVE 0x000008
77#define SAA7706H_CL_GEN2_FINE_RATIO_MASK 0x0ffff0
78
79#define SAA7706H_REG_CL_GEN4 0x1ff6
80#define SAA7706H_CL_GEN4_BYPASS_PLL1 0x001000
81#define SAA7706H_CL_GEN4_PLL1_DIV_MASK 0x03e000
82#define SAA7706H_CL_GEN4_DSP1_TURBO 0x040000
83
84#define SAA7706H_REG_SEL 0x1ff7
85#define SAA7706H_SEL_DSP2_SRCA_MASK 0x000007
86#define SAA7706H_SEL_DSP2_FMTA_MASK 0x000031
87#define SAA7706H_SEL_DSP2_SRCB_MASK 0x0001c0
88#define SAA7706H_SEL_DSP2_FMTB_MASK 0x000e00
89#define SAA7706H_SEL_DSP1_SRC_MASK 0x003000
90#define SAA7706H_SEL_DSP1_FMT_MASK 0x01c003
91#define SAA7706H_SEL_SPDIF2 0x020000
92#define SAA7706H_SEL_HOST_IO_FMT_MASK 0x1c0000
93#define SAA7706H_SEL_EN_HOST_IO 0x200000
94
95#define SAA7706H_REG_IAC 0x1ff8
96#define SAA7706H_REG_CLK_SET 0x1ff9
97#define SAA7706H_REG_CLK_COEFF 0x1ffa
98#define SAA7706H_REG_INPUT_SENS 0x1ffb
99#define SAA7706H_INPUT_SENS_RDS_VOL_MASK 0x0003f
100#define SAA7706H_INPUT_SENS_FM_VOL_MASK 0x00fc0
101#define SAA7706H_INPUT_SENS_FM_MPX 0x01000
102#define SAA7706H_INPUT_SENS_OFF_FILTER_A_EN 0x02000
103#define SAA7706H_INPUT_SENS_OFF_FILTER_B_EN 0x04000
104#define SAA7706H_REG_PHONE_NAV_AUDIO 0x1ffc
105#define SAA7706H_REG_IO_CONF_DSP2 0x1ffd
106#define SAA7706H_REG_STATUS_DSP2 0x1ffe
107#define SAA7706H_REG_PC_DSP2 0x1fff
108
109#define SAA7706H_DSP1_MOD0 0x0800
110#define SAA7706H_DSP1_ROM_VER 0x097f
111#define SAA7706H_DSP2_MPTR0 0x1000
112
113#define SAA7706H_DSP1_MODPNTR 0x0000
114
115#define SAA7706H_DSP2_XMEM_CONTLLCW 0x113e
116#define SAA7706H_DSP2_XMEM_BUSAMP 0x114a
117#define SAA7706H_DSP2_XMEM_FDACPNTR 0x11f9
118#define SAA7706H_DSP2_XMEM_IIS1PNTR 0x11fb
119
120#define SAA7706H_DSP2_YMEM_PVGA 0x212a
121#define SAA7706H_DSP2_YMEM_PVAT1 0x212b
122#define SAA7706H_DSP2_YMEM_PVAT 0x212c
123#define SAA7706H_DSP2_YMEM_ROM_VER 0x21ff
124
125#define SUPPORTED_DSP1_ROM_VER 0x667
126
127struct saa7706h_state {
128 struct v4l2_subdev sd;
129 unsigned muted;
130};
131
132static inline struct saa7706h_state *to_state(struct v4l2_subdev *sd)
133{
134 return container_of(sd, struct saa7706h_state, sd);
135}
136
137static int saa7706h_i2c_send(struct i2c_client *client, const u8 *data, int len)
138{
139 int err = i2c_master_send(client, data, len);
140 if (err == len)
141 return 0;
142 return err > 0 ? -EIO : err;
143}
144
145static int saa7706h_i2c_transfer(struct i2c_client *client,
146 struct i2c_msg *msgs, int num)
147{
148 int err = i2c_transfer(client->adapter, msgs, num);
149 if (err == num)
150 return 0;
151 return err > 0 ? -EIO : err;
152}
153
154static int saa7706h_set_reg24(struct v4l2_subdev *sd, u16 reg, u32 val)
155{
156 struct i2c_client *client = v4l2_get_subdevdata(sd);
157 u8 buf[5];
158 int pos = 0;
159
160 buf[pos++] = reg >> 8;
161 buf[pos++] = reg;
162 buf[pos++] = val >> 16;
163 buf[pos++] = val >> 8;
164 buf[pos++] = val;
165
166 return saa7706h_i2c_send(client, buf, pos);
167}
168
169static int saa7706h_set_reg24_err(struct v4l2_subdev *sd, u16 reg, u32 val,
170 int *err)
171{
172 return *err ? *err : saa7706h_set_reg24(sd, reg, val);
173}
174
175static int saa7706h_set_reg16(struct v4l2_subdev *sd, u16 reg, u16 val)
176{
177 struct i2c_client *client = v4l2_get_subdevdata(sd);
178 u8 buf[4];
179 int pos = 0;
180
181 buf[pos++] = reg >> 8;
182 buf[pos++] = reg;
183 buf[pos++] = val >> 8;
184 buf[pos++] = val;
185
186 return saa7706h_i2c_send(client, buf, pos);
187}
188
189static int saa7706h_set_reg16_err(struct v4l2_subdev *sd, u16 reg, u16 val,
190 int *err)
191{
192 return *err ? *err : saa7706h_set_reg16(sd, reg, val);
193}
194
195static int saa7706h_get_reg16(struct v4l2_subdev *sd, u16 reg)
196{
197 struct i2c_client *client = v4l2_get_subdevdata(sd);
198 u8 buf[2];
199 int err;
200 u8 regaddr[] = {reg >> 8, reg};
201 struct i2c_msg msg[] = { {client->addr, 0, sizeof(regaddr), regaddr},
202 {client->addr, I2C_M_RD, sizeof(buf), buf} };
203
204 err = saa7706h_i2c_transfer(client, msg, ARRAY_SIZE(msg));
205 if (err)
206 return err;
207
208 return buf[0] << 8 | buf[1];
209}
210
211static int saa7706h_unmute(struct v4l2_subdev *sd)
212{
213 struct saa7706h_state *state = to_state(sd);
214 int err = 0;
215
216 err = saa7706h_set_reg16_err(sd, SAA7706H_REG_CTRL,
217 SAA7706H_CTRL_PLL3_62975MHZ | SAA7706H_CTRL_PC_RESET_DSP1 |
218 SAA7706H_CTRL_PC_RESET_DSP2, &err);
219
220 /* newer versions of the chip requires a small sleep after reset */
221 msleep(1);
222
223 err = saa7706h_set_reg16_err(sd, SAA7706H_REG_CTRL,
224 SAA7706H_CTRL_PLL3_62975MHZ, &err);
225
226 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_EVALUATION, 0, &err);
227
228 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_CL_GEN1, 0x040022, &err);
229
230 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_CL_GEN2,
231 SAA7706H_CL_GEN2_WSEDGE_FALLING, &err);
232
233 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_CL_GEN4, 0x024080, &err);
234
235 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_SEL, 0x200080, &err);
236
237 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_IAC, 0xf4caed, &err);
238
239 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_CLK_SET, 0x124334, &err);
240
241 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_CLK_COEFF, 0x004a1a,
242 &err);
243
244 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_INPUT_SENS, 0x0071c7,
245 &err);
246
247 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_PHONE_NAV_AUDIO,
248 0x0e22ff, &err);
249
250 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_IO_CONF_DSP2, 0x001ff8,
251 &err);
252
253 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_STATUS_DSP2, 0x080003,
254 &err);
255
256 err = saa7706h_set_reg24_err(sd, SAA7706H_REG_PC_DSP2, 0x000004, &err);
257
258 err = saa7706h_set_reg16_err(sd, SAA7706H_DSP1_MOD0, 0x0c6c, &err);
259
260 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP2_MPTR0, 0x000b4b, &err);
261
262 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP1_MODPNTR, 0x000600, &err);
263
264 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP1_MODPNTR, 0x0000c0, &err);
265
266 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP2_XMEM_CONTLLCW, 0x000819,
267 &err);
268
269 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP2_XMEM_CONTLLCW, 0x00085a,
270 &err);
271
272 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP2_XMEM_BUSAMP, 0x7fffff,
273 &err);
274
275 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP2_XMEM_FDACPNTR, 0x2000cb,
276 &err);
277
278 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP2_XMEM_IIS1PNTR, 0x2000cb,
279 &err);
280
281 err = saa7706h_set_reg16_err(sd, SAA7706H_DSP2_YMEM_PVGA, 0x0f80, &err);
282
283 err = saa7706h_set_reg16_err(sd, SAA7706H_DSP2_YMEM_PVAT1, 0x0800,
284 &err);
285
286 err = saa7706h_set_reg16_err(sd, SAA7706H_DSP2_YMEM_PVAT, 0x0800, &err);
287
288 err = saa7706h_set_reg24_err(sd, SAA7706H_DSP2_XMEM_CONTLLCW, 0x000905,
289 &err);
290 if (!err)
291 state->muted = 0;
292 return err;
293}
294
295static int saa7706h_mute(struct v4l2_subdev *sd)
296{
297 struct saa7706h_state *state = to_state(sd);
298 int err;
299
300 err = saa7706h_set_reg16(sd, SAA7706H_REG_CTRL,
301 SAA7706H_CTRL_PLL3_62975MHZ | SAA7706H_CTRL_PC_RESET_DSP1 |
302 SAA7706H_CTRL_PC_RESET_DSP2);
303 if (!err)
304 state->muted = 1;
305 return err;
306}
307
308static int saa7706h_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
309{
310 switch (qc->id) {
311 case V4L2_CID_AUDIO_MUTE:
312 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
313 }
314 return -EINVAL;
315}
316
317static int saa7706h_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
318{
319 struct saa7706h_state *state = to_state(sd);
320
321 switch (ctrl->id) {
322 case V4L2_CID_AUDIO_MUTE:
323 ctrl->value = state->muted;
324 return 0;
325 }
326 return -EINVAL;
327}
328
329static int saa7706h_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
330{
331 switch (ctrl->id) {
332 case V4L2_CID_AUDIO_MUTE:
333 if (ctrl->value)
334 return saa7706h_mute(sd);
335 return saa7706h_unmute(sd);
336 }
337 return -EINVAL;
338}
339
340static int saa7706h_g_chip_ident(struct v4l2_subdev *sd,
341 struct v4l2_dbg_chip_ident *chip)
342{
343 struct i2c_client *client = v4l2_get_subdevdata(sd);
344
345 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7706H, 0);
346}
347
348static const struct v4l2_subdev_core_ops saa7706h_core_ops = {
349 .g_chip_ident = saa7706h_g_chip_ident,
350 .queryctrl = saa7706h_queryctrl,
351 .g_ctrl = saa7706h_g_ctrl,
352 .s_ctrl = saa7706h_s_ctrl,
353};
354
355static const struct v4l2_subdev_ops saa7706h_ops = {
356 .core = &saa7706h_core_ops,
357};
358
359/*
360 * Generic i2c probe
361 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
362 */
363
364static int __devinit saa7706h_probe(struct i2c_client *client,
365 const struct i2c_device_id *id)
366{
367 struct saa7706h_state *state;
368 struct v4l2_subdev *sd;
369 int err;
370
371 /* Check if the adapter supports the needed features */
372 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
373 return -EIO;
374
375 v4l_info(client, "chip found @ 0x%02x (%s)\n",
376 client->addr << 1, client->adapter->name);
377
378 state = kmalloc(sizeof(struct saa7706h_state), GFP_KERNEL);
379 if (state == NULL)
380 return -ENOMEM;
381 sd = &state->sd;
382 v4l2_i2c_subdev_init(sd, client, &saa7706h_ops);
383
384 /* check the rom versions */
385 err = saa7706h_get_reg16(sd, SAA7706H_DSP1_ROM_VER);
386 if (err < 0)
387 goto err;
388 if (err != SUPPORTED_DSP1_ROM_VER)
389 v4l2_warn(sd, "Unknown DSP1 ROM code version: 0x%x\n", err);
390
391 state->muted = 1;
392
393 /* startup in a muted state */
394 err = saa7706h_mute(sd);
395 if (err)
396 goto err;
397
398 return 0;
399
400err:
401 v4l2_device_unregister_subdev(sd);
402 kfree(to_state(sd));
403
404 printk(KERN_ERR DRIVER_NAME ": Failed to probe: %d\n", err);
405
406 return err;
407}
408
409static int __devexit saa7706h_remove(struct i2c_client *client)
410{
411 struct v4l2_subdev *sd = i2c_get_clientdata(client);
412
413 saa7706h_mute(sd);
414 v4l2_device_unregister_subdev(sd);
415 kfree(to_state(sd));
416 return 0;
417}
418
419static const struct i2c_device_id saa7706h_id[] = {
420 {DRIVER_NAME, 0},
421 {},
422};
423
424MODULE_DEVICE_TABLE(i2c, saa7706h_id);
425
426static struct i2c_driver saa7706h_driver = {
427 .driver = {
428 .owner = THIS_MODULE,
429 .name = DRIVER_NAME,
430 },
431 .probe = saa7706h_probe,
432 .remove = saa7706h_remove,
433 .id_table = saa7706h_id,
434};
435
436static __init int saa7706h_init(void)
437{
438 return i2c_add_driver(&saa7706h_driver);
439}
440
441static __exit void saa7706h_exit(void)
442{
443 i2c_del_driver(&saa7706h_driver);
444}
445
446module_init(saa7706h_init);
447module_exit(saa7706h_exit);
448
449MODULE_DESCRIPTION("SAA7706H Car Radio DSP driver");
450MODULE_AUTHOR("Mocean Laboratories");
451MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/radio/si470x/radio-si470x-common.c b/drivers/media/radio/si470x/radio-si470x-common.c
index 4da0f150c6e2..47075fc71f11 100644
--- a/drivers/media/radio/si470x/radio-si470x-common.c
+++ b/drivers/media/radio/si470x/radio-si470x-common.c
@@ -724,7 +724,7 @@ static int si470x_vidioc_g_tuner(struct file *file, void *priv,
724 tuner->audmode = V4L2_TUNER_MODE_MONO; 724 tuner->audmode = V4L2_TUNER_MODE_MONO;
725 725
726 /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */ 726 /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */
727 /* measured in units of db쨉V in 1 db increments (max at ~75 db쨉V) */ 727 /* measured in units of dbµV in 1 db increments (max at ~75 dbµV) */
728 tuner->signal = (radio->registers[STATUSRSSI] & STATUSRSSI_RSSI); 728 tuner->signal = (radio->registers[STATUSRSSI] & STATUSRSSI_RSSI);
729 /* the ideal factor is 0xffff/75 = 873,8 */ 729 /* the ideal factor is 0xffff/75 = 873,8 */
730 tuner->signal = (tuner->signal * 873) + (8 * tuner->signal / 10); 730 tuner->signal = (tuner->signal * 873) + (8 * tuner->signal / 10);
diff --git a/drivers/media/radio/si470x/radio-si470x-usb.c b/drivers/media/radio/si470x/radio-si470x-usb.c
index a96e1b9dd646..6f60841828da 100644
--- a/drivers/media/radio/si470x/radio-si470x-usb.c
+++ b/drivers/media/radio/si470x/radio-si470x-usb.c
@@ -590,8 +590,9 @@ int si470x_fops_release(struct file *file)
590 video_unregister_device(radio->videodev); 590 video_unregister_device(radio->videodev);
591 kfree(radio->int_in_buffer); 591 kfree(radio->int_in_buffer);
592 kfree(radio->buffer); 592 kfree(radio->buffer);
593 mutex_unlock(&radio->disconnect_lock);
593 kfree(radio); 594 kfree(radio);
594 goto unlock; 595 goto done;
595 } 596 }
596 597
597 /* cancel read processes */ 598 /* cancel read processes */
@@ -601,7 +602,6 @@ int si470x_fops_release(struct file *file)
601 retval = si470x_stop(radio); 602 retval = si470x_stop(radio);
602 usb_autopm_put_interface(radio->intf); 603 usb_autopm_put_interface(radio->intf);
603 } 604 }
604unlock:
605 mutex_unlock(&radio->disconnect_lock); 605 mutex_unlock(&radio->disconnect_lock);
606done: 606done:
607 return retval; 607 return retval;
@@ -842,9 +842,11 @@ static void si470x_usb_driver_disconnect(struct usb_interface *intf)
842 kfree(radio->int_in_buffer); 842 kfree(radio->int_in_buffer);
843 video_unregister_device(radio->videodev); 843 video_unregister_device(radio->videodev);
844 kfree(radio->buffer); 844 kfree(radio->buffer);
845 mutex_unlock(&radio->disconnect_lock);
845 kfree(radio); 846 kfree(radio);
847 } else {
848 mutex_unlock(&radio->disconnect_lock);
846 } 849 }
847 mutex_unlock(&radio->disconnect_lock);
848} 850}
849 851
850 852
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 2f83be766d9f..f8fc8654693d 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -388,6 +388,15 @@ config VIDEO_TVP5150
388 To compile this driver as a module, choose M here: the 388 To compile this driver as a module, choose M here: the
389 module will be called tvp5150. 389 module will be called tvp5150.
390 390
391config VIDEO_TVP7002
392 tristate "Texas Instruments TVP7002 video decoder"
393 depends on VIDEO_V4L2 && I2C
394 ---help---
395 Support for the Texas Instruments TVP7002 video decoder.
396
397 To compile this driver as a module, choose M here: the
398 module will be called tvp7002.
399
391config VIDEO_VPX3220 400config VIDEO_VPX3220
392 tristate "vpx3220a, vpx3216b & vpx3214c video decoders" 401 tristate "vpx3220a, vpx3216b & vpx3214c video decoders"
393 depends on VIDEO_V4L2 && I2C 402 depends on VIDEO_V4L2 && I2C
@@ -548,7 +557,6 @@ config VIDEO_VPSS_SYSTEM
548 depends on ARCH_DAVINCI 557 depends on ARCH_DAVINCI
549 help 558 help
550 Support for vpss system module for video driver 559 Support for vpss system module for video driver
551 default y
552 560
553config VIDEO_VPFE_CAPTURE 561config VIDEO_VPFE_CAPTURE
554 tristate "VPFE Video Capture Driver" 562 tristate "VPFE Video Capture Driver"
@@ -592,6 +600,19 @@ config VIDEO_DM355_CCDC
592 To compile this driver as a module, choose M here: the 600 To compile this driver as a module, choose M here: the
593 module will be called vpfe. 601 module will be called vpfe.
594 602
603config VIDEO_ISIF
604 tristate "ISIF HW module"
605 depends on ARCH_DAVINCI_DM365 && VIDEO_VPFE_CAPTURE
606 select VIDEO_VPSS_SYSTEM
607 default y
608 help
609 Enables ISIF hw module. This is the hardware module for
610 configuring ISIF in VPFE to capture Raw Bayer RGB data from
611 a image sensor or YUV data from a YUV source.
612
613 To compile this driver as a module, choose M here: the
614 module will be called vpfe.
615
595source "drivers/media/video/bt8xx/Kconfig" 616source "drivers/media/video/bt8xx/Kconfig"
596 617
597config VIDEO_PMS 618config VIDEO_PMS
@@ -638,9 +659,14 @@ config VIDEO_W9966
638 information. 659 information.
639 660
640config VIDEO_CPIA 661config VIDEO_CPIA
641 tristate "CPiA Video For Linux" 662 tristate "CPiA Video For Linux (DEPRECATED)"
642 depends on VIDEO_V4L1 663 depends on VIDEO_V4L1
664 default n
643 ---help--- 665 ---help---
666 This driver is DEPRECATED please use the gspca cpia1 module
667 instead. Note that you need atleast version 0.6.4 of libv4l for
668 the cpia1 gspca module.
669
644 This is the video4linux driver for cameras based on Vision's CPiA 670 This is the video4linux driver for cameras based on Vision's CPiA
645 (Colour Processor Interface ASIC), such as the Creative Labs Video 671 (Colour Processor Interface ASIC), such as the Creative Labs Video
646 Blaster Webcam II. If you have one of these cameras, say Y here 672 Blaster Webcam II. If you have one of these cameras, say Y here
@@ -944,6 +970,8 @@ source "drivers/media/video/hdpvr/Kconfig"
944 970
945source "drivers/media/video/em28xx/Kconfig" 971source "drivers/media/video/em28xx/Kconfig"
946 972
973source "drivers/media/video/tlg2300/Kconfig"
974
947source "drivers/media/video/cx231xx/Kconfig" 975source "drivers/media/video/cx231xx/Kconfig"
948 976
949source "drivers/media/video/usbvision/Kconfig" 977source "drivers/media/video/usbvision/Kconfig"
@@ -955,6 +983,7 @@ source "drivers/media/video/et61x251/Kconfig"
955config VIDEO_OVCAMCHIP 983config VIDEO_OVCAMCHIP
956 tristate "OmniVision Camera Chip support (DEPRECATED)" 984 tristate "OmniVision Camera Chip support (DEPRECATED)"
957 depends on I2C && VIDEO_V4L1 985 depends on I2C && VIDEO_V4L1
986 default n
958 ---help--- 987 ---help---
959 This driver is DEPRECATED please use the gspca ov519 module 988 This driver is DEPRECATED please use the gspca ov519 module
960 instead. Note that for the ov511 / ov518 support of the gspca module 989 instead. Note that for the ov511 / ov518 support of the gspca module
@@ -971,6 +1000,7 @@ config VIDEO_OVCAMCHIP
971config USB_W9968CF 1000config USB_W9968CF
972 tristate "USB W996[87]CF JPEG Dual Mode Camera support (DEPRECATED)" 1001 tristate "USB W996[87]CF JPEG Dual Mode Camera support (DEPRECATED)"
973 depends on VIDEO_V4L1 && I2C && VIDEO_OVCAMCHIP 1002 depends on VIDEO_V4L1 && I2C && VIDEO_OVCAMCHIP
1003 default n
974 ---help--- 1004 ---help---
975 This driver is DEPRECATED please use the gspca ov519 module 1005 This driver is DEPRECATED please use the gspca ov519 module
976 instead. Note that for the w9968cf support of the gspca module 1006 instead. Note that for the w9968cf support of the gspca module
@@ -992,6 +1022,7 @@ config USB_W9968CF
992config USB_OV511 1022config USB_OV511
993 tristate "USB OV511 Camera support (DEPRECATED)" 1023 tristate "USB OV511 Camera support (DEPRECATED)"
994 depends on VIDEO_V4L1 1024 depends on VIDEO_V4L1
1025 default n
995 ---help--- 1026 ---help---
996 This driver is DEPRECATED please use the gspca ov519 module 1027 This driver is DEPRECATED please use the gspca ov519 module
997 instead. Note that for the ov511 / ov518 support of the gspca module 1028 instead. Note that for the ov511 / ov518 support of the gspca module
@@ -1020,6 +1051,7 @@ source "drivers/media/video/sn9c102/Kconfig"
1020config USB_STV680 1051config USB_STV680
1021 tristate "USB STV680 (Pencam) Camera support (DEPRECATED)" 1052 tristate "USB STV680 (Pencam) Camera support (DEPRECATED)"
1022 depends on VIDEO_V4L1 1053 depends on VIDEO_V4L1
1054 default n
1023 ---help--- 1055 ---help---
1024 This driver is DEPRECATED please use the gspca stv0680 module 1056 This driver is DEPRECATED please use the gspca stv0680 module
1025 instead. Note that for the gspca stv0680 module you need 1057 instead. Note that for the gspca stv0680 module you need
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 2af68ee84122..b88b6174a331 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_VIDEO_THS7303) += ths7303.o
56obj-$(CONFIG_VIDEO_VINO) += indycam.o 56obj-$(CONFIG_VIDEO_VINO) += indycam.o
57obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o 57obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
58obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o 58obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o
59obj-$(CONFIG_VIDEO_TVP7002) += tvp7002.o
59obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o 60obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
60obj-$(CONFIG_VIDEO_CS5345) += cs5345.o 61obj-$(CONFIG_VIDEO_CS5345) += cs5345.o
61obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o 62obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
@@ -99,6 +100,7 @@ obj-$(CONFIG_VIDEO_MEYE) += meye.o
99obj-$(CONFIG_VIDEO_SAA7134) += saa7134/ 100obj-$(CONFIG_VIDEO_SAA7134) += saa7134/
100obj-$(CONFIG_VIDEO_CX88) += cx88/ 101obj-$(CONFIG_VIDEO_CX88) += cx88/
101obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ 102obj-$(CONFIG_VIDEO_EM28XX) += em28xx/
103obj-$(CONFIG_VIDEO_TLG2300) += tlg2300/
102obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/ 104obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/
103obj-$(CONFIG_VIDEO_USBVISION) += usbvision/ 105obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
104obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ 106obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index 5bb0f9e71583..547e1a93c421 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -254,7 +254,7 @@ static int bt819_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
254 v4l2_err(sd, "no notify found!\n"); 254 v4l2_err(sd, "no notify found!\n");
255 255
256 if (std & V4L2_STD_NTSC) { 256 if (std & V4L2_STD_NTSC) {
257 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0); 257 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, NULL);
258 bt819_setbit(decoder, 0x01, 0, 1); 258 bt819_setbit(decoder, 0x01, 0, 1);
259 bt819_setbit(decoder, 0x01, 1, 0); 259 bt819_setbit(decoder, 0x01, 1, 0);
260 bt819_setbit(decoder, 0x01, 5, 0); 260 bt819_setbit(decoder, 0x01, 5, 0);
@@ -263,7 +263,7 @@ static int bt819_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
263 /* bt819_setbit(decoder, 0x1a, 5, 1); */ 263 /* bt819_setbit(decoder, 0x1a, 5, 1); */
264 timing = &timing_data[1]; 264 timing = &timing_data[1];
265 } else if (std & V4L2_STD_PAL) { 265 } else if (std & V4L2_STD_PAL) {
266 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0); 266 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, NULL);
267 bt819_setbit(decoder, 0x01, 0, 1); 267 bt819_setbit(decoder, 0x01, 0, 1);
268 bt819_setbit(decoder, 0x01, 1, 1); 268 bt819_setbit(decoder, 0x01, 1, 1);
269 bt819_setbit(decoder, 0x01, 5, 1); 269 bt819_setbit(decoder, 0x01, 5, 1);
@@ -288,7 +288,7 @@ static int bt819_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
288 bt819_write(decoder, 0x08, (timing->hscale >> 8) & 0xff); 288 bt819_write(decoder, 0x08, (timing->hscale >> 8) & 0xff);
289 bt819_write(decoder, 0x09, timing->hscale & 0xff); 289 bt819_write(decoder, 0x09, timing->hscale & 0xff);
290 decoder->norm = std; 290 decoder->norm = std;
291 v4l2_subdev_notify(sd, BT819_FIFO_RESET_HIGH, 0); 291 v4l2_subdev_notify(sd, BT819_FIFO_RESET_HIGH, NULL);
292 return 0; 292 return 0;
293} 293}
294 294
@@ -306,7 +306,7 @@ static int bt819_s_routing(struct v4l2_subdev *sd,
306 v4l2_err(sd, "no notify found!\n"); 306 v4l2_err(sd, "no notify found!\n");
307 307
308 if (decoder->input != input) { 308 if (decoder->input != input) {
309 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0); 309 v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, NULL);
310 decoder->input = input; 310 decoder->input = input;
311 /* select mode */ 311 /* select mode */
312 if (decoder->input == 0) { 312 if (decoder->input == 0) {
@@ -316,7 +316,7 @@ static int bt819_s_routing(struct v4l2_subdev *sd,
316 bt819_setbit(decoder, 0x0b, 6, 1); 316 bt819_setbit(decoder, 0x0b, 6, 1);
317 bt819_setbit(decoder, 0x1a, 1, 0); 317 bt819_setbit(decoder, 0x1a, 1, 0);
318 } 318 }
319 v4l2_subdev_notify(sd, BT819_FIFO_RESET_HIGH, 0); 319 v4l2_subdev_notify(sd, BT819_FIFO_RESET_HIGH, NULL);
320 } 320 }
321 return 0; 321 return 0;
322} 322}
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 3182a406bdd1..cb46e8fa8aaa 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -81,6 +81,7 @@ static int video_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
81static int radio_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 }; 81static int radio_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
82static int vbi_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 }; 82static int vbi_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
83static int debug_latency; 83static int debug_latency;
84static int disable_ir;
84 85
85static unsigned int fdsr; 86static unsigned int fdsr;
86 87
@@ -107,6 +108,7 @@ module_param(bttv_gpio, int, 0644);
107module_param(bttv_debug, int, 0644); 108module_param(bttv_debug, int, 0644);
108module_param(irq_debug, int, 0644); 109module_param(irq_debug, int, 0644);
109module_param(debug_latency, int, 0644); 110module_param(debug_latency, int, 0644);
111module_param(disable_ir, int, 0444);
110 112
111module_param(fdsr, int, 0444); 113module_param(fdsr, int, 0444);
112module_param(gbuffers, int, 0444); 114module_param(gbuffers, int, 0444);
@@ -139,6 +141,7 @@ MODULE_PARM_DESC(bttv_verbose,"verbose startup messages, default is 1 (yes)");
139MODULE_PARM_DESC(bttv_gpio,"log gpio changes, default is 0 (no)"); 141MODULE_PARM_DESC(bttv_gpio,"log gpio changes, default is 0 (no)");
140MODULE_PARM_DESC(bttv_debug,"debug messages, default is 0 (no)"); 142MODULE_PARM_DESC(bttv_debug,"debug messages, default is 0 (no)");
141MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)"); 143MODULE_PARM_DESC(irq_debug,"irq handler debug messages, default is 0 (no)");
144MODULE_PARM_DESC(disable_ir, "disable infrared remote support");
142MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8"); 145MODULE_PARM_DESC(gbuffers,"number of capture buffers. range 2-32, default 8");
143MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000"); 146MODULE_PARM_DESC(gbufsize,"size of the capture buffers, default is 0x208000");
144MODULE_PARM_DESC(reset_crop,"reset cropping parameters at open(), default " 147MODULE_PARM_DESC(reset_crop,"reset cropping parameters at open(), default "
@@ -4461,7 +4464,10 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4461 request_modules(btv); 4464 request_modules(btv);
4462 } 4465 }
4463 4466
4464 bttv_input_init(btv); 4467 if (!disable_ir) {
4468 init_bttv_i2c_ir(btv);
4469 bttv_input_init(btv);
4470 }
4465 4471
4466 /* everything is fine */ 4472 /* everything is fine */
4467 bttv_num++; 4473 bttv_num++;
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index 63aa31a041e8..407fa61e4cda 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -388,7 +388,12 @@ int __devinit init_bttv_i2c(struct bttv *btv)
388 if (0 == btv->i2c_rc && i2c_scan) 388 if (0 == btv->i2c_rc && i2c_scan)
389 do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client); 389 do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client);
390 390
391 /* Instantiate the IR receiver device, if present */ 391 return btv->i2c_rc;
392}
393
394/* Instantiate the I2C IR receiver device, if present */
395void __devinit init_bttv_i2c_ir(struct bttv *btv)
396{
392 if (0 == btv->i2c_rc) { 397 if (0 == btv->i2c_rc) {
393 struct i2c_board_info info; 398 struct i2c_board_info info;
394 /* The external IR receiver is at i2c address 0x34 (0x35 for 399 /* The external IR receiver is at i2c address 0x34 (0x35 for
@@ -408,7 +413,6 @@ int __devinit init_bttv_i2c(struct bttv *btv)
408 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 413 strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
409 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list); 414 i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list);
410 } 415 }
411 return btv->i2c_rc;
412} 416}
413 417
414int __devexit fini_bttv_i2c(struct bttv *btv) 418int __devexit fini_bttv_i2c(struct bttv *btv)
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 277a092e1214..b320dbd635aa 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -247,7 +247,7 @@ int bttv_input_init(struct bttv *btv)
247 struct card_ir *ir; 247 struct card_ir *ir;
248 struct ir_scancode_table *ir_codes = NULL; 248 struct ir_scancode_table *ir_codes = NULL;
249 struct input_dev *input_dev; 249 struct input_dev *input_dev;
250 int ir_type = IR_TYPE_OTHER; 250 u64 ir_type = IR_TYPE_OTHER;
251 int err = -ENOMEM; 251 int err = -ENOMEM;
252 252
253 if (!btv->has_remote) 253 if (!btv->has_remote)
@@ -389,7 +389,7 @@ int bttv_input_init(struct bttv *btv)
389 bttv_ir_start(btv, ir); 389 bttv_ir_start(btv, ir);
390 390
391 /* all done */ 391 /* all done */
392 err = ir_input_register(btv->remote->dev, ir_codes); 392 err = ir_input_register(btv->remote->dev, ir_codes, NULL);
393 if (err) 393 if (err)
394 goto err_out_stop; 394 goto err_out_stop;
395 395
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index a1d0e9c9f286..6cccc2a17eee 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -279,6 +279,7 @@ extern unsigned int bttv_debug;
279extern unsigned int bttv_gpio; 279extern unsigned int bttv_gpio;
280extern void bttv_gpio_tracking(struct bttv *btv, char *comment); 280extern void bttv_gpio_tracking(struct bttv *btv, char *comment);
281extern int init_bttv_i2c(struct bttv *btv); 281extern int init_bttv_i2c(struct bttv *btv);
282extern void init_bttv_i2c_ir(struct bttv *btv);
282extern int fini_bttv_i2c(struct bttv *btv); 283extern int fini_bttv_i2c(struct bttv *btv);
283 284
284#define bttv_printk if (bttv_verbose) printk 285#define bttv_printk if (bttv_verbose) printk
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 7bb9c1ec7819..cbbf7e80d2cf 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -1907,7 +1907,6 @@ static int cafe_pci_probe(struct pci_dev *pdev,
1907 goto out_free; 1907 goto out_free;
1908 1908
1909 mutex_init(&cam->s_mutex); 1909 mutex_init(&cam->s_mutex);
1910 mutex_lock(&cam->s_mutex);
1911 spin_lock_init(&cam->dev_lock); 1910 spin_lock_init(&cam->dev_lock);
1912 cam->state = S_NOTREADY; 1911 cam->state = S_NOTREADY;
1913 cafe_set_config_needed(cam, 1); 1912 cafe_set_config_needed(cam, 1);
@@ -1947,7 +1946,6 @@ static int cafe_pci_probe(struct pci_dev *pdev,
1947 * because the sensor could attach in this call chain, leading to 1946 * because the sensor could attach in this call chain, leading to
1948 * unsightly deadlocks. 1947 * unsightly deadlocks.
1949 */ 1948 */
1950 mutex_unlock(&cam->s_mutex); /* attach can deadlock */
1951 ret = cafe_smbus_setup(cam); 1949 ret = cafe_smbus_setup(cam);
1952 if (ret) 1950 if (ret)
1953 goto out_freeirq; 1951 goto out_freeirq;
@@ -1973,7 +1971,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
1973 cam->vdev.v4l2_dev = &cam->v4l2_dev; 1971 cam->vdev.v4l2_dev = &cam->v4l2_dev;
1974 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); 1972 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
1975 if (ret) 1973 if (ret)
1976 goto out_smbus; 1974 goto out_unlock;
1977 video_set_drvdata(&cam->vdev, cam); 1975 video_set_drvdata(&cam->vdev, cam);
1978 1976
1979 /* 1977 /*
@@ -1988,6 +1986,8 @@ static int cafe_pci_probe(struct pci_dev *pdev,
1988 mutex_unlock(&cam->s_mutex); 1986 mutex_unlock(&cam->s_mutex);
1989 return 0; 1987 return 0;
1990 1988
1989out_unlock:
1990 mutex_unlock(&cam->s_mutex);
1991out_smbus: 1991out_smbus:
1992 cafe_smbus_shutdown(cam); 1992 cafe_smbus_shutdown(cam);
1993out_freeirq: 1993out_freeirq:
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 551ddf216a4b..933ae4c8cb9a 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -3737,9 +3737,6 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3737 if (size > FRAME_NUM*CPIA_MAX_FRAME_SIZE) 3737 if (size > FRAME_NUM*CPIA_MAX_FRAME_SIZE)
3738 return -EINVAL; 3738 return -EINVAL;
3739 3739
3740 if (!cam || !cam->ops)
3741 return -ENODEV;
3742
3743 /* make this _really_ smp-safe */ 3740 /* make this _really_ smp-safe */
3744 if (mutex_lock_interruptible(&cam->busy_lock)) 3741 if (mutex_lock_interruptible(&cam->busy_lock))
3745 return -EINTR; 3742 return -EINTR;
diff --git a/drivers/media/video/cx18/Kconfig b/drivers/media/video/cx18/Kconfig
index e8a50a611ebc..baf7e91ee0f5 100644
--- a/drivers/media/video/cx18/Kconfig
+++ b/drivers/media/video/cx18/Kconfig
@@ -19,3 +19,14 @@ config VIDEO_CX18
19 19
20 To compile this driver as a module, choose M here: the 20 To compile this driver as a module, choose M here: the
21 module will be called cx18. 21 module will be called cx18.
22
23config VIDEO_CX18_ALSA
24 tristate "Conexant 23418 DMA audio support"
25 depends on VIDEO_CX18 && SND && EXPERIMENTAL
26 select SND_PCM
27 ---help---
28 This is a video4linux driver for direct (DMA) audio on
29 Conexant 23418 based TV cards using ALSA.
30
31 To compile this driver as a module, choose M here: the
32 module will be called cx18-alsa.
diff --git a/drivers/media/video/cx18/Makefile b/drivers/media/video/cx18/Makefile
index f7bf0edf93f9..2fadd9ded340 100644
--- a/drivers/media/video/cx18/Makefile
+++ b/drivers/media/video/cx18/Makefile
@@ -3,8 +3,10 @@ cx18-objs := cx18-driver.o cx18-cards.o cx18-i2c.o cx18-firmware.o cx18-gpio.
3 cx18-mailbox.o cx18-vbi.o cx18-audio.o cx18-video.o cx18-irq.o \ 3 cx18-mailbox.o cx18-vbi.o cx18-audio.o cx18-video.o cx18-irq.o \
4 cx18-av-core.o cx18-av-audio.o cx18-av-firmware.o cx18-av-vbi.o cx18-scb.o \ 4 cx18-av-core.o cx18-av-audio.o cx18-av-firmware.o cx18-av-vbi.o cx18-scb.o \
5 cx18-dvb.o cx18-io.o 5 cx18-dvb.o cx18-io.o
6cx18-alsa-objs := cx18-alsa-main.o cx18-alsa-pcm.o
6 7
7obj-$(CONFIG_VIDEO_CX18) += cx18.o 8obj-$(CONFIG_VIDEO_CX18) += cx18.o
9obj-$(CONFIG_VIDEO_CX18_ALSA) += cx18-alsa.o
8 10
9EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 11EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
10EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 12EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff --git a/drivers/media/video/cx18/cx18-alsa-main.c b/drivers/media/video/cx18/cx18-alsa-main.c
new file mode 100644
index 000000000000..eb41d7ec65b9
--- /dev/null
+++ b/drivers/media/video/cx18/cx18-alsa-main.c
@@ -0,0 +1,293 @@
1/*
2 * ALSA interface to cx18 PCM capture streams
3 *
4 * Copyright (C) 2009 Andy Walls <awalls@radix.net>
5 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
6 *
7 * Portions of this work were sponsored by ONELAN Limited.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 * 02111-1307 USA
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/kernel.h>
28#include <linux/device.h>
29#include <linux/spinlock.h>
30
31#include <media/v4l2-device.h>
32
33#include <sound/core.h>
34#include <sound/initval.h>
35
36#include "cx18-driver.h"
37#include "cx18-version.h"
38#include "cx18-alsa.h"
39#include "cx18-alsa-mixer.h"
40#include "cx18-alsa-pcm.h"
41
42int cx18_alsa_debug;
43
44#define CX18_DEBUG_ALSA_INFO(fmt, arg...) \
45 do { \
46 if (cx18_alsa_debug & 2) \
47 printk(KERN_INFO "%s: " fmt, "cx18-alsa", ## arg); \
48 } while (0);
49
50module_param_named(debug, cx18_alsa_debug, int, 0644);
51MODULE_PARM_DESC(debug,
52 "Debug level (bitmask). Default: 0\n"
53 "\t\t\t 1/0x0001: warning\n"
54 "\t\t\t 2/0x0002: info\n");
55
56MODULE_AUTHOR("Andy Walls");
57MODULE_DESCRIPTION("CX23418 ALSA Interface");
58MODULE_SUPPORTED_DEVICE("CX23418 MPEG2 encoder");
59MODULE_LICENSE("GPL");
60
61MODULE_VERSION(CX18_VERSION);
62
63static inline
64struct snd_cx18_card *to_snd_cx18_card(struct v4l2_device *v4l2_dev)
65{
66 return to_cx18(v4l2_dev)->alsa;
67}
68
69static inline
70struct snd_cx18_card *p_to_snd_cx18_card(struct v4l2_device **v4l2_dev)
71{
72 return container_of(v4l2_dev, struct snd_cx18_card, v4l2_dev);
73}
74
75static void snd_cx18_card_free(struct snd_cx18_card *cxsc)
76{
77 if (cxsc == NULL)
78 return;
79
80 if (cxsc->v4l2_dev != NULL)
81 to_cx18(cxsc->v4l2_dev)->alsa = NULL;
82
83 /* FIXME - take any other stopping actions needed */
84
85 kfree(cxsc);
86}
87
88static void snd_cx18_card_private_free(struct snd_card *sc)
89{
90 if (sc == NULL)
91 return;
92 snd_cx18_card_free(sc->private_data);
93 sc->private_data = NULL;
94 sc->private_free = NULL;
95}
96
97static int snd_cx18_card_create(struct v4l2_device *v4l2_dev,
98 struct snd_card *sc,
99 struct snd_cx18_card **cxsc)
100{
101 *cxsc = kzalloc(sizeof(struct snd_cx18_card), GFP_KERNEL);
102 if (*cxsc == NULL)
103 return -ENOMEM;
104
105 (*cxsc)->v4l2_dev = v4l2_dev;
106 (*cxsc)->sc = sc;
107
108 sc->private_data = *cxsc;
109 sc->private_free = snd_cx18_card_private_free;
110
111 return 0;
112}
113
114static int snd_cx18_card_set_names(struct snd_cx18_card *cxsc)
115{
116 struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
117 struct snd_card *sc = cxsc->sc;
118
119 /* sc->driver is used by alsa-lib's configurator: simple, unique */
120 strlcpy(sc->driver, "CX23418", sizeof(sc->driver));
121
122 /* sc->shortname is a symlink in /proc/asound: CX18-M -> cardN */
123 snprintf(sc->shortname, sizeof(sc->shortname), "CX18-%d",
124 cx->instance);
125
126 /* sc->longname is read from /proc/asound/cards */
127 snprintf(sc->longname, sizeof(sc->longname),
128 "CX23418 #%d %s TV/FM Radio/Line-In Capture",
129 cx->instance, cx->card_name);
130
131 return 0;
132}
133
134static int snd_cx18_init(struct v4l2_device *v4l2_dev)
135{
136 struct cx18 *cx = to_cx18(v4l2_dev);
137 struct snd_card *sc = NULL;
138 struct snd_cx18_card *cxsc;
139 int ret;
140
141 /* Numbrs steps from "Writing an ALSA Driver" by Takashi Iwai */
142
143 /* (1) Check and increment the device index */
144 /* This is a no-op for us. We'll use the cx->instance */
145
146 /* (2) Create a card instance */
147 ret = snd_card_create(SNDRV_DEFAULT_IDX1, /* use first available id */
148 SNDRV_DEFAULT_STR1, /* xid from end of shortname*/
149 THIS_MODULE, 0, &sc);
150 if (ret) {
151 CX18_ALSA_ERR("%s: snd_card_create() failed with err %d\n",
152 __func__, ret);
153 goto err_exit;
154 }
155
156 /* (3) Create a main component */
157 ret = snd_cx18_card_create(v4l2_dev, sc, &cxsc);
158 if (ret) {
159 CX18_ALSA_ERR("%s: snd_cx18_card_create() failed with err %d\n",
160 __func__, ret);
161 goto err_exit_free;
162 }
163
164 /* (4) Set the driver ID and name strings */
165 snd_cx18_card_set_names(cxsc);
166
167
168 ret = snd_cx18_pcm_create(cxsc);
169 if (ret) {
170 CX18_ALSA_ERR("%s: snd_cx18_pcm_create() failed with err %d\n",
171 __func__, ret);
172 goto err_exit_free;
173 }
174 /* FIXME - proc files */
175
176 /* (7) Set the driver data and return 0 */
177 /* We do this out of normal order for PCI drivers to avoid races */
178 cx->alsa = cxsc;
179
180 /* (6) Register the card instance */
181 ret = snd_card_register(sc);
182 if (ret) {
183 cx->alsa = NULL;
184 CX18_ALSA_ERR("%s: snd_card_register() failed with err %d\n",
185 __func__, ret);
186 goto err_exit_free;
187 }
188
189 return 0;
190
191err_exit_free:
192 if (sc != NULL)
193 snd_card_free(sc);
194err_exit:
195 return ret;
196}
197
198int cx18_alsa_load(struct cx18 *cx)
199{
200 struct v4l2_device *v4l2_dev = &cx->v4l2_dev;
201 struct cx18_stream *s;
202
203 if (v4l2_dev == NULL) {
204 printk(KERN_ERR "cx18-alsa: %s: struct v4l2_device * is NULL\n",
205 __func__);
206 return 0;
207 }
208
209 cx = to_cx18(v4l2_dev);
210 if (cx == NULL) {
211 printk(KERN_ERR "cx18-alsa cx is NULL\n");
212 return 0;
213 }
214
215 s = &cx->streams[CX18_ENC_STREAM_TYPE_PCM];
216 if (s->video_dev == NULL) {
217 CX18_DEBUG_ALSA_INFO("%s: PCM stream for card is disabled - "
218 "skipping\n", __func__);
219 return 0;
220 }
221
222 if (cx->alsa != NULL) {
223 CX18_ALSA_ERR("%s: struct snd_cx18_card * already exists\n",
224 __func__);
225 return 0;
226 }
227
228 if (snd_cx18_init(v4l2_dev)) {
229 CX18_ALSA_ERR("%s: failed to create struct snd_cx18_card\n",
230 __func__);
231 } else {
232 CX18_DEBUG_ALSA_INFO("%s: created cx18 ALSA interface instance "
233 "\n", __func__);
234 }
235 return 0;
236}
237
238static int __init cx18_alsa_init(void)
239{
240 printk(KERN_INFO "cx18-alsa: module loading...\n");
241 cx18_ext_init = &cx18_alsa_load;
242 return 0;
243}
244
245static void __exit snd_cx18_exit(struct snd_cx18_card *cxsc)
246{
247 struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
248
249 /* FIXME - pointer checks & shutdown cxsc */
250
251 snd_card_free(cxsc->sc);
252 cx->alsa = NULL;
253}
254
255static int __exit cx18_alsa_exit_callback(struct device *dev, void *data)
256{
257 struct v4l2_device *v4l2_dev = dev_get_drvdata(dev);
258 struct snd_cx18_card *cxsc;
259
260 if (v4l2_dev == NULL) {
261 printk(KERN_ERR "cx18-alsa: %s: struct v4l2_device * is NULL\n",
262 __func__);
263 return 0;
264 }
265
266 cxsc = to_snd_cx18_card(v4l2_dev);
267 if (cxsc == NULL) {
268 CX18_ALSA_WARN("%s: struct snd_cx18_card * is NULL\n",
269 __func__);
270 return 0;
271 }
272
273 snd_cx18_exit(cxsc);
274 return 0;
275}
276
277static void __exit cx18_alsa_exit(void)
278{
279 struct device_driver *drv;
280 int ret;
281
282 printk(KERN_INFO "cx18-alsa: module unloading...\n");
283
284 drv = driver_find("cx18", &pci_bus_type);
285 ret = driver_for_each_device(drv, NULL, NULL, cx18_alsa_exit_callback);
286 put_driver(drv);
287
288 cx18_ext_init = NULL;
289 printk(KERN_INFO "cx18-alsa: module unload complete\n");
290}
291
292module_init(cx18_alsa_init);
293module_exit(cx18_alsa_exit);
diff --git a/drivers/media/video/cx18/cx18-alsa-mixer.c b/drivers/media/video/cx18/cx18-alsa-mixer.c
new file mode 100644
index 000000000000..ef21114309fe
--- /dev/null
+++ b/drivers/media/video/cx18/cx18-alsa-mixer.c
@@ -0,0 +1,175 @@
1/*
2 * ALSA mixer controls for the
3 * ALSA interface to cx18 PCM capture streams
4 *
5 * Copyright (C) 2009 Andy Walls <awalls@radix.net>
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., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/device.h>
26#include <linux/spinlock.h>
27#include <linux/videodev2.h>
28
29#include <media/v4l2-device.h>
30
31#include <sound/core.h>
32#include <sound/control.h>
33#include <sound/tlv.h>
34
35#include "cx18-alsa.h"
36#include "cx18-driver.h"
37
38/*
39 * Note the cx18-av-core volume scale is funny, due to the alignment of the
40 * scale with another chip's range:
41 *
42 * v4l2_control value /512 indicated dB actual dB reg 0x8d4
43 * 0x0000 - 0x01ff 0 -119 -96 228
44 * 0x0200 - 0x02ff 1 -118 -96 228
45 * ...
46 * 0x2c00 - 0x2dff 22 -97 -96 228
47 * 0x2e00 - 0x2fff 23 -96 -96 228
48 * 0x3000 - 0x31ff 24 -95 -95 226
49 * ...
50 * 0xee00 - 0xefff 119 0 0 36
51 * ...
52 * 0xfe00 - 0xffff 127 +8 +8 20
53 */
54static inline int dB_to_cx18_av_vol(int dB)
55{
56 if (dB < -96)
57 dB = -96;
58 else if (dB > 8)
59 dB = 8;
60 return (dB + 119) << 9;
61}
62
63static inline int cx18_av_vol_to_dB(int v)
64{
65 if (v < (23 << 9))
66 v = (23 << 9);
67 else if (v > (127 << 9))
68 v = (127 << 9);
69 return (v >> 9) - 119;
70}
71
72static int snd_cx18_mixer_tv_vol_info(struct snd_kcontrol *kcontrol,
73 struct snd_ctl_elem_info *uinfo)
74{
75 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
76 uinfo->count = 1;
77 /* We're already translating values, just keep this control in dB */
78 uinfo->value.integer.min = -96;
79 uinfo->value.integer.max = 8;
80 uinfo->value.integer.step = 1;
81 return 0;
82}
83
84static int snd_cx18_mixer_tv_vol_get(struct snd_kcontrol *kctl,
85 struct snd_ctl_elem_value *uctl)
86{
87 struct snd_cx18_card *cxsc = snd_kcontrol_chip(kctl);
88 struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
89 struct v4l2_control vctrl;
90 int ret;
91
92 vctrl.id = V4L2_CID_AUDIO_VOLUME;
93 vctrl.value = dB_to_cx18_av_vol(uctl->value.integer.value[0]);
94
95 snd_cx18_lock(cxsc);
96 ret = v4l2_subdev_call(cx->sd_av, core, g_ctrl, &vctrl);
97 snd_cx18_unlock(cxsc);
98
99 if (!ret)
100 uctl->value.integer.value[0] = cx18_av_vol_to_dB(vctrl.value);
101 return ret;
102}
103
104static int snd_cx18_mixer_tv_vol_put(struct snd_kcontrol *kctl,
105 struct snd_ctl_elem_value *uctl)
106{
107 struct snd_cx18_card *cxsc = snd_kcontrol_chip(kctl);
108 struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
109 struct v4l2_control vctrl;
110 int ret;
111
112 vctrl.id = V4L2_CID_AUDIO_VOLUME;
113 vctrl.value = dB_to_cx18_av_vol(uctl->value.integer.value[0]);
114
115 snd_cx18_lock(cxsc);
116
117 /* Fetch current state */
118 ret = v4l2_subdev_call(cx->sd_av, core, g_ctrl, &vctrl);
119
120 if (ret ||
121 (cx18_av_vol_to_dB(vctrl.value) != uctl->value.integer.value[0])) {
122
123 /* Set, if needed */
124 vctrl.value = dB_to_cx18_av_vol(uctl->value.integer.value[0]);
125 ret = v4l2_subdev_call(cx->sd_av, core, s_ctrl, &vctrl);
126 if (!ret)
127 ret = 1; /* Indicate control was changed w/o error */
128 }
129 snd_cx18_unlock(cxsc);
130
131 return ret;
132}
133
134
135/* This is a bit of overkill, the slider is already in dB internally */
136static DECLARE_TLV_DB_SCALE(snd_cx18_mixer_tv_vol_db_scale, -9600, 100, 0);
137
138static struct snd_kcontrol_new snd_cx18_mixer_tv_vol __initdata = {
139 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
140 .name = "Analog TV Capture Volume",
141 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
142 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
143 .info = snd_cx18_mixer_tv_volume_info,
144 .get = snd_cx18_mixer_tv_volume_get,
145 .put = snd_cx18_mixer_tv_volume_put,
146 .tlv.p = snd_cx18_mixer_tv_vol_db_scale
147};
148
149/* FIXME - add mute switch and balance, bass, treble sliders:
150 V4L2_CID_AUDIO_MUTE
151
152 V4L2_CID_AUDIO_BALANCE
153
154 V4L2_CID_AUDIO_BASS
155 V4L2_CID_AUDIO_TREBLE
156*/
157
158/* FIXME - add stereo, lang1, lang2, mono menu */
159/* FIXME - add CS5345 I2S volume for HVR-1600 */
160
161int __init snd_cx18_mixer_create(struct snd_cx18_card *cxsc)
162{
163 struct v4l2_device *v4l2_dev = cxsc->v4l2_dev;
164 struct snd_card *sc = cxsc->sc;
165 int ret;
166
167 strlcpy(sc->mixername, "CX23418 Mixer", sizeof(sc->mixername));
168
169 ret = snd_ctl_add(sc, snd_ctl_new1(snd_cx18_mixer_tv_vol, cxsc));
170 if (ret) {
171 CX18_ALSA_WARN("%s: failed to add %s control, err %d\n",
172 __func__, snd_cx18_mixer_tv_vol.name, ret);
173 }
174 return ret;
175}
diff --git a/drivers/media/video/cx18/cx18-alsa-mixer.h b/drivers/media/video/cx18/cx18-alsa-mixer.h
new file mode 100644
index 000000000000..2d418db000fe
--- /dev/null
+++ b/drivers/media/video/cx18/cx18-alsa-mixer.h
@@ -0,0 +1,23 @@
1/*
2 * ALSA mixer controls for the
3 * ALSA interface to cx18 PCM capture streams
4 *
5 * Copyright (C) 2009 Andy Walls <awalls@radix.net>
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., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23int __init snd_cx18_mixer_create(struct snd_cx18_card *cxsc);
diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.c b/drivers/media/video/cx18/cx18-alsa-pcm.c
new file mode 100644
index 000000000000..2bd312daeb1e
--- /dev/null
+++ b/drivers/media/video/cx18/cx18-alsa-pcm.c
@@ -0,0 +1,354 @@
1/*
2 * ALSA PCM device for the
3 * ALSA interface to cx18 PCM capture streams
4 *
5 * Copyright (C) 2009 Andy Walls <awalls@radix.net>
6 * Copyright (C) 2009 Devin Heitmueller <dheitmueller@kernellabs.com>
7 *
8 * Portions of this work were sponsored by ONELAN Limited.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307 USA
24 */
25
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/vmalloc.h>
29
30#include <media/v4l2-device.h>
31
32#include <sound/core.h>
33#include <sound/pcm.h>
34
35#include "cx18-driver.h"
36#include "cx18-queue.h"
37#include "cx18-streams.h"
38#include "cx18-fileops.h"
39#include "cx18-alsa.h"
40
41static unsigned int pcm_debug;
42module_param(pcm_debug, int, 0644);
43MODULE_PARM_DESC(pcm_debug, "enable debug messages for pcm");
44
45#define dprintk(fmt, arg...) do { \
46 if (pcm_debug) \
47 printk(KERN_INFO "cx18-alsa-pcm %s: " fmt, \
48 __func__, ##arg); \
49 } while (0)
50
51static struct snd_pcm_hardware snd_cx18_hw_capture = {
52 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
53 SNDRV_PCM_INFO_MMAP |
54 SNDRV_PCM_INFO_INTERLEAVED |
55 SNDRV_PCM_INFO_MMAP_VALID,
56
57 .formats = SNDRV_PCM_FMTBIT_S16_LE,
58
59 .rates = SNDRV_PCM_RATE_48000,
60
61 .rate_min = 48000,
62 .rate_max = 48000,
63 .channels_min = 2,
64 .channels_max = 2,
65 .buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */
66 .period_bytes_min = 64, /* 12544/2, */
67 .period_bytes_max = 12544,
68 .periods_min = 2,
69 .periods_max = 98, /* 12544, */
70};
71
72void cx18_alsa_announce_pcm_data(struct snd_cx18_card *cxsc, u8 *pcm_data,
73 size_t num_bytes)
74{
75 struct snd_pcm_substream *substream;
76 struct snd_pcm_runtime *runtime;
77 unsigned int oldptr;
78 unsigned int stride;
79 int period_elapsed = 0;
80 int length;
81
82 dprintk("cx18 alsa announce ptr=%p data=%p num_bytes=%zd\n", cxsc,
83 pcm_data, num_bytes);
84
85 substream = cxsc->capture_pcm_substream;
86 if (substream == NULL) {
87 dprintk("substream was NULL\n");
88 return;
89 }
90
91 runtime = substream->runtime;
92 if (runtime == NULL) {
93 dprintk("runtime was NULL\n");
94 return;
95 }
96
97 stride = runtime->frame_bits >> 3;
98 if (stride == 0) {
99 dprintk("stride is zero\n");
100 return;
101 }
102
103 length = num_bytes / stride;
104 if (length == 0) {
105 dprintk("%s: length was zero\n", __func__);
106 return;
107 }
108
109 if (runtime->dma_area == NULL) {
110 dprintk("dma area was NULL - ignoring\n");
111 return;
112 }
113
114 oldptr = cxsc->hwptr_done_capture;
115 if (oldptr + length >= runtime->buffer_size) {
116 unsigned int cnt =
117 runtime->buffer_size - oldptr;
118 memcpy(runtime->dma_area + oldptr * stride, pcm_data,
119 cnt * stride);
120 memcpy(runtime->dma_area, pcm_data + cnt * stride,
121 length * stride - cnt * stride);
122 } else {
123 memcpy(runtime->dma_area + oldptr * stride, pcm_data,
124 length * stride);
125 }
126 snd_pcm_stream_lock(substream);
127
128 cxsc->hwptr_done_capture += length;
129 if (cxsc->hwptr_done_capture >=
130 runtime->buffer_size)
131 cxsc->hwptr_done_capture -=
132 runtime->buffer_size;
133
134 cxsc->capture_transfer_done += length;
135 if (cxsc->capture_transfer_done >=
136 runtime->period_size) {
137 cxsc->capture_transfer_done -=
138 runtime->period_size;
139 period_elapsed = 1;
140 }
141
142 snd_pcm_stream_unlock(substream);
143
144 if (period_elapsed)
145 snd_pcm_period_elapsed(substream);
146}
147
148static int snd_cx18_pcm_capture_open(struct snd_pcm_substream *substream)
149{
150 struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream);
151 struct snd_pcm_runtime *runtime = substream->runtime;
152 struct v4l2_device *v4l2_dev = cxsc->v4l2_dev;
153 struct cx18 *cx = to_cx18(v4l2_dev);
154 struct cx18_stream *s;
155 struct cx18_open_id item;
156 int ret;
157
158 /* Instruct the cx18 to start sending packets */
159 snd_cx18_lock(cxsc);
160 s = &cx->streams[CX18_ENC_STREAM_TYPE_PCM];
161
162 item.cx = cx;
163 item.type = s->type;
164 item.open_id = cx->open_id++;
165
166 /* See if the stream is available */
167 if (cx18_claim_stream(&item, item.type)) {
168 /* No, it's already in use */
169 snd_cx18_unlock(cxsc);
170 return -EBUSY;
171 }
172
173 if (test_bit(CX18_F_S_STREAMOFF, &s->s_flags) ||
174 test_and_set_bit(CX18_F_S_STREAMING, &s->s_flags)) {
175 /* We're already streaming. No additional action required */
176 snd_cx18_unlock(cxsc);
177 return 0;
178 }
179
180
181 runtime->hw = snd_cx18_hw_capture;
182 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
183 cxsc->capture_pcm_substream = substream;
184 runtime->private_data = cx;
185
186 cx->pcm_announce_callback = cx18_alsa_announce_pcm_data;
187
188 /* Not currently streaming, so start it up */
189 set_bit(CX18_F_S_STREAMING, &s->s_flags);
190 ret = cx18_start_v4l2_encode_stream(s);
191 snd_cx18_unlock(cxsc);
192
193 return 0;
194}
195
196static int snd_cx18_pcm_capture_close(struct snd_pcm_substream *substream)
197{
198 struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream);
199 struct v4l2_device *v4l2_dev = cxsc->v4l2_dev;
200 struct cx18 *cx = to_cx18(v4l2_dev);
201 struct cx18_stream *s;
202 int ret;
203
204 /* Instruct the cx18 to stop sending packets */
205 snd_cx18_lock(cxsc);
206 s = &cx->streams[CX18_ENC_STREAM_TYPE_PCM];
207 ret = cx18_stop_v4l2_encode_stream(s, 0);
208 clear_bit(CX18_F_S_STREAMING, &s->s_flags);
209
210 cx18_release_stream(s);
211
212 cx->pcm_announce_callback = NULL;
213 snd_cx18_unlock(cxsc);
214
215 return 0;
216}
217
218static int snd_cx18_pcm_ioctl(struct snd_pcm_substream *substream,
219 unsigned int cmd, void *arg)
220{
221 return snd_pcm_lib_ioctl(substream, cmd, arg);
222}
223
224
225static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
226 size_t size)
227{
228 struct snd_pcm_runtime *runtime = subs->runtime;
229
230 dprintk("Allocating vbuffer\n");
231 if (runtime->dma_area) {
232 if (runtime->dma_bytes > size)
233 return 0;
234
235 vfree(runtime->dma_area);
236 }
237 runtime->dma_area = vmalloc(size);
238 if (!runtime->dma_area)
239 return -ENOMEM;
240
241 runtime->dma_bytes = size;
242
243 return 0;
244}
245
246static int snd_cx18_pcm_hw_params(struct snd_pcm_substream *substream,
247 struct snd_pcm_hw_params *params)
248{
249 int ret;
250
251 dprintk("%s called\n", __func__);
252
253 ret = snd_pcm_alloc_vmalloc_buffer(substream,
254 params_buffer_bytes(params));
255 return 0;
256}
257
258static int snd_cx18_pcm_hw_free(struct snd_pcm_substream *substream)
259{
260 struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream);
261 unsigned long flags;
262
263 spin_lock_irqsave(&cxsc->slock, flags);
264 if (substream->runtime->dma_area) {
265 dprintk("freeing pcm capture region\n");
266 vfree(substream->runtime->dma_area);
267 substream->runtime->dma_area = NULL;
268 }
269 spin_unlock_irqrestore(&cxsc->slock, flags);
270
271 return 0;
272}
273
274static int snd_cx18_pcm_prepare(struct snd_pcm_substream *substream)
275{
276 struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream);
277
278 cxsc->hwptr_done_capture = 0;
279 cxsc->capture_transfer_done = 0;
280
281 return 0;
282}
283
284static int snd_cx18_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
285{
286 return 0;
287}
288
289static
290snd_pcm_uframes_t snd_cx18_pcm_pointer(struct snd_pcm_substream *substream)
291{
292 unsigned long flags;
293 snd_pcm_uframes_t hwptr_done;
294 struct snd_cx18_card *cxsc = snd_pcm_substream_chip(substream);
295
296 spin_lock_irqsave(&cxsc->slock, flags);
297 hwptr_done = cxsc->hwptr_done_capture;
298 spin_unlock_irqrestore(&cxsc->slock, flags);
299
300 return hwptr_done;
301}
302
303static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
304 unsigned long offset)
305{
306 void *pageptr = subs->runtime->dma_area + offset;
307
308 return vmalloc_to_page(pageptr);
309}
310
311static struct snd_pcm_ops snd_cx18_pcm_capture_ops = {
312 .open = snd_cx18_pcm_capture_open,
313 .close = snd_cx18_pcm_capture_close,
314 .ioctl = snd_cx18_pcm_ioctl,
315 .hw_params = snd_cx18_pcm_hw_params,
316 .hw_free = snd_cx18_pcm_hw_free,
317 .prepare = snd_cx18_pcm_prepare,
318 .trigger = snd_cx18_pcm_trigger,
319 .pointer = snd_cx18_pcm_pointer,
320 .page = snd_pcm_get_vmalloc_page,
321};
322
323int snd_cx18_pcm_create(struct snd_cx18_card *cxsc)
324{
325 struct snd_pcm *sp;
326 struct snd_card *sc = cxsc->sc;
327 struct v4l2_device *v4l2_dev = cxsc->v4l2_dev;
328 struct cx18 *cx = to_cx18(v4l2_dev);
329 int ret;
330
331 ret = snd_pcm_new(sc, "CX23418 PCM",
332 0, /* PCM device 0, the only one for this card */
333 0, /* 0 playback substreams */
334 1, /* 1 capture substream */
335 &sp);
336 if (ret) {
337 CX18_ALSA_ERR("%s: snd_cx18_pcm_create() failed with err %d\n",
338 __func__, ret);
339 goto err_exit;
340 }
341
342 spin_lock_init(&cxsc->slock);
343
344 snd_pcm_set_ops(sp, SNDRV_PCM_STREAM_CAPTURE,
345 &snd_cx18_pcm_capture_ops);
346 sp->info_flags = 0;
347 sp->private_data = cxsc;
348 strlcpy(sp->name, cx->card_name, sizeof(sp->name));
349
350 return 0;
351
352err_exit:
353 return ret;
354}
diff --git a/drivers/media/video/cx18/cx18-alsa-pcm.h b/drivers/media/video/cx18/cx18-alsa-pcm.h
new file mode 100644
index 000000000000..325662c647a0
--- /dev/null
+++ b/drivers/media/video/cx18/cx18-alsa-pcm.h
@@ -0,0 +1,27 @@
1/*
2 * ALSA PCM device for the
3 * ALSA interface to cx18 PCM capture streams
4 *
5 * Copyright (C) 2009 Andy Walls <awalls@radix.net>
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., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23int __init snd_cx18_pcm_create(struct snd_cx18_card *cxsc);
24
25/* Used by cx18-mailbox to announce the PCM data to the module */
26void cx18_alsa_announce_pcm_data(struct snd_cx18_card *card, u8 *pcm_data,
27 size_t num_bytes);
diff --git a/drivers/media/video/cx18/cx18-alsa.h b/drivers/media/video/cx18/cx18-alsa.h
new file mode 100644
index 000000000000..88a1cde7540b
--- /dev/null
+++ b/drivers/media/video/cx18/cx18-alsa.h
@@ -0,0 +1,75 @@
1/*
2 * ALSA interface to cx18 PCM capture streams
3 *
4 * Copyright (C) 2009 Andy Walls <awalls@radix.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * 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
19 * 02111-1307 USA
20 */
21
22struct snd_card;
23
24struct snd_cx18_card {
25 struct v4l2_device *v4l2_dev;
26 struct snd_card *sc;
27 unsigned int capture_transfer_done;
28 unsigned int hwptr_done_capture;
29 struct snd_pcm_substream *capture_pcm_substream;
30 spinlock_t slock;
31};
32
33extern int cx18_alsa_debug;
34
35/*
36 * File operations that manipulate the encoder or video or audio subdevices
37 * need to be serialized. Use the same lock we use for v4l2 file ops.
38 */
39static inline void snd_cx18_lock(struct snd_cx18_card *cxsc)
40{
41 struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
42 mutex_lock(&cx->serialize_lock);
43}
44
45static inline void snd_cx18_unlock(struct snd_cx18_card *cxsc)
46{
47 struct cx18 *cx = to_cx18(cxsc->v4l2_dev);
48 mutex_unlock(&cx->serialize_lock);
49}
50
51#define CX18_ALSA_DBGFLG_WARN (1 << 0)
52#define CX18_ALSA_DBGFLG_WARN (1 << 0)
53#define CX18_ALSA_DBGFLG_INFO (1 << 1)
54
55#define CX18_ALSA_DEBUG(x, type, fmt, args...) \
56 do { \
57 if ((x) & cx18_alsa_debug) \
58 printk(KERN_INFO "%s-alsa: " type ": " fmt, \
59 v4l2_dev->name , ## args); \
60 } while (0)
61
62#define CX18_ALSA_DEBUG_WARN(fmt, args...) \
63 CX18_ALSA_DEBUG(CX18_ALSA_DBGFLG_WARN, "warning", fmt , ## args)
64
65#define CX18_ALSA_DEBUG_INFO(fmt, args...) \
66 CX18_ALSA_DEBUG(CX18_ALSA_DBGFLG_INFO, "info", fmt , ## args)
67
68#define CX18_ALSA_ERR(fmt, args...) \
69 printk(KERN_ERR "%s-alsa: " fmt, v4l2_dev->name , ## args)
70
71#define CX18_ALSA_WARN(fmt, args...) \
72 printk(KERN_WARNING "%s-alsa: " fmt, v4l2_dev->name , ## args)
73
74#define CX18_ALSA_INFO(fmt, args...) \
75 printk(KERN_INFO "%s-alsa: " fmt, v4l2_dev->name , ## args)
diff --git a/drivers/media/video/cx18/cx18-cards.c b/drivers/media/video/cx18/cx18-cards.c
index f11e47a58286..f808fb6fc1c1 100644
--- a/drivers/media/video/cx18/cx18-cards.c
+++ b/drivers/media/video/cx18/cx18-cards.c
@@ -393,7 +393,7 @@ static const struct cx18_card cx18_card_leadtek_pvr2100 = {
393 .gpio_init.direction = 0x7, 393 .gpio_init.direction = 0x7,
394 .gpio_audio_input = { .mask = 0x7, 394 .gpio_audio_input = { .mask = 0x7,
395 .tuner = 0x6, .linein = 0x2, .radio = 0x2 }, 395 .tuner = 0x6, .linein = 0x2, .radio = 0x2 },
396 .xceive_pin = 15, 396 .xceive_pin = 1,
397 .pci_list = cx18_pci_leadtek_pvr2100, 397 .pci_list = cx18_pci_leadtek_pvr2100,
398 .i2c = &cx18_i2c_std, 398 .i2c = &cx18_i2c_std,
399}; 399};
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index 7f65a47f12e1..c95a86ba33b0 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -47,6 +47,10 @@
47 setting this to 1 you ensure that radio0 is now also radio1. */ 47 setting this to 1 you ensure that radio0 is now also radio1. */
48int cx18_first_minor; 48int cx18_first_minor;
49 49
50/* Callback for registering extensions */
51int (*cx18_ext_init)(struct cx18 *);
52EXPORT_SYMBOL(cx18_ext_init);
53
50/* add your revision and whatnot here */ 54/* add your revision and whatnot here */
51static struct pci_device_id cx18_pci_tbl[] __devinitdata = { 55static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
52 {PCI_VENDOR_ID_CX, PCI_DEVICE_ID_CX23418, 56 {PCI_VENDOR_ID_CX, PCI_DEVICE_ID_CX23418,
@@ -91,7 +95,7 @@ static int enc_pcm_bufsize = CX18_DEFAULT_ENC_PCM_BUFSIZE;
91 95
92static int enc_ts_bufs = -1; 96static int enc_ts_bufs = -1;
93static int enc_mpg_bufs = -1; 97static int enc_mpg_bufs = -1;
94static int enc_idx_bufs = -1; 98static int enc_idx_bufs = CX18_MAX_FW_MDLS_PER_STREAM;
95static int enc_yuv_bufs = -1; 99static int enc_yuv_bufs = -1;
96static int enc_vbi_bufs = -1; 100static int enc_vbi_bufs = -1;
97static int enc_pcm_bufs = -1; 101static int enc_pcm_bufs = -1;
@@ -196,14 +200,17 @@ MODULE_PARM_DESC(enc_mpg_bufs,
196 "Number of encoder MPG buffers\n" 200 "Number of encoder MPG buffers\n"
197 "\t\t\tDefault is computed from other enc_mpg_* parameters"); 201 "\t\t\tDefault is computed from other enc_mpg_* parameters");
198MODULE_PARM_DESC(enc_idx_buffers, 202MODULE_PARM_DESC(enc_idx_buffers,
199 "Encoder IDX buffer memory (MB). (enc_idx_bufs can override)\n" 203 "(Deprecated) Encoder IDX buffer memory (MB)\n"
200 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_IDX_BUFFERS)); 204 "\t\t\tIgnored, except 0 disables IDX buffer allocations\n"
205 "\t\t\tDefault: 1 [Enabled]");
201MODULE_PARM_DESC(enc_idx_bufsize, 206MODULE_PARM_DESC(enc_idx_bufsize,
202 "Size of an encoder IDX buffer (kB)\n" 207 "Size of an encoder IDX buffer (kB)\n"
203 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_IDX_BUFSIZE)); 208 "\t\t\tAllowed values are multiples of 1.5 kB rounded up\n"
209 "\t\t\t(multiples of size required for 64 index entries)\n"
210 "\t\t\tDefault: 2");
204MODULE_PARM_DESC(enc_idx_bufs, 211MODULE_PARM_DESC(enc_idx_bufs,
205 "Number of encoder IDX buffers\n" 212 "Number of encoder IDX buffers\n"
206 "\t\t\tDefault is computed from other enc_idx_* parameters"); 213 "\t\t\tDefault: " __stringify(CX18_MAX_FW_MDLS_PER_STREAM));
207MODULE_PARM_DESC(enc_yuv_buffers, 214MODULE_PARM_DESC(enc_yuv_buffers,
208 "Encoder YUV buffer memory (MB). (enc_yuv_bufs can override)\n" 215 "Encoder YUV buffer memory (MB). (enc_yuv_bufs can override)\n"
209 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_YUV_BUFFERS)); 216 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_YUV_BUFFERS));
@@ -231,7 +238,8 @@ MODULE_PARM_DESC(enc_pcm_bufs,
231 "Number of encoder PCM buffers\n" 238 "Number of encoder PCM buffers\n"
232 "\t\t\tDefault is computed from other enc_pcm_* parameters"); 239 "\t\t\tDefault is computed from other enc_pcm_* parameters");
233 240
234MODULE_PARM_DESC(cx18_first_minor, "Set device node number assigned to first card"); 241MODULE_PARM_DESC(cx18_first_minor,
242 "Set device node number assigned to first card");
235 243
236MODULE_AUTHOR("Hans Verkuil"); 244MODULE_AUTHOR("Hans Verkuil");
237MODULE_DESCRIPTION("CX23418 driver"); 245MODULE_DESCRIPTION("CX23418 driver");
@@ -240,6 +248,28 @@ MODULE_LICENSE("GPL");
240 248
241MODULE_VERSION(CX18_VERSION); 249MODULE_VERSION(CX18_VERSION);
242 250
251#if defined(CONFIG_MODULES) && defined(MODULE)
252static void request_module_async(struct work_struct *work)
253{
254 struct cx18 *dev = container_of(work, struct cx18, request_module_wk);
255
256 /* Make sure cx18-alsa module is loaded */
257 request_module("cx18-alsa");
258
259 /* Initialize cx18-alsa for this instance of the cx18 device */
260 if (cx18_ext_init != NULL)
261 cx18_ext_init(dev);
262}
263
264static void request_modules(struct cx18 *dev)
265{
266 INIT_WORK(&dev->request_module_wk, request_module_async);
267 schedule_work(&dev->request_module_wk);
268}
269#else
270#define request_modules(dev)
271#endif /* CONFIG_MODULES */
272
243/* Generic utility functions */ 273/* Generic utility functions */
244int cx18_msleep_timeout(unsigned int msecs, int intr) 274int cx18_msleep_timeout(unsigned int msecs, int intr)
245{ 275{
@@ -501,7 +531,12 @@ static void cx18_process_options(struct cx18 *cx)
501 /* 531 /*
502 * YUV is a special case where the stream_buf_size needs to be 532 * YUV is a special case where the stream_buf_size needs to be
503 * an integral multiple of 33.75 kB (storage for 32 screens 533 * an integral multiple of 33.75 kB (storage for 32 screens
504 * lines to maintain alignment in case of lost buffers 534 * lines to maintain alignment in case of lost buffers).
535 *
536 * IDX is a special case where the stream_buf_size should be
537 * an integral multiple of 1.5 kB (storage for 64 index entries
538 * to maintain alignment in case of lost buffers).
539 *
505 */ 540 */
506 if (i == CX18_ENC_STREAM_TYPE_YUV) { 541 if (i == CX18_ENC_STREAM_TYPE_YUV) {
507 cx->stream_buf_size[i] *= 1024; 542 cx->stream_buf_size[i] *= 1024;
@@ -511,15 +546,24 @@ static void cx18_process_options(struct cx18 *cx)
511 if (cx->stream_buf_size[i] < CX18_UNIT_ENC_YUV_BUFSIZE) 546 if (cx->stream_buf_size[i] < CX18_UNIT_ENC_YUV_BUFSIZE)
512 cx->stream_buf_size[i] = 547 cx->stream_buf_size[i] =
513 CX18_UNIT_ENC_YUV_BUFSIZE; 548 CX18_UNIT_ENC_YUV_BUFSIZE;
549 } else if (i == CX18_ENC_STREAM_TYPE_IDX) {
550 cx->stream_buf_size[i] *= 1024;
551 cx->stream_buf_size[i] -=
552 (cx->stream_buf_size[i] % CX18_UNIT_ENC_IDX_BUFSIZE);
553
554 if (cx->stream_buf_size[i] < CX18_UNIT_ENC_IDX_BUFSIZE)
555 cx->stream_buf_size[i] =
556 CX18_UNIT_ENC_IDX_BUFSIZE;
514 } 557 }
515 /* 558 /*
516 * YUV is a special case where the stream_buf_size is 559 * YUV and IDX are special cases where the stream_buf_size is
517 * now in bytes. 560 * now in bytes.
518 * VBI is a special case where the stream_buf_size is fixed 561 * VBI is a special case where the stream_buf_size is fixed
519 * and already in bytes 562 * and already in bytes
520 */ 563 */
521 if (i == CX18_ENC_STREAM_TYPE_VBI || 564 if (i == CX18_ENC_STREAM_TYPE_VBI ||
522 i == CX18_ENC_STREAM_TYPE_YUV) { 565 i == CX18_ENC_STREAM_TYPE_YUV ||
566 i == CX18_ENC_STREAM_TYPE_IDX) {
523 if (cx->stream_buffers[i] < 0) { 567 if (cx->stream_buffers[i] < 0) {
524 cx->stream_buffers[i] = 568 cx->stream_buffers[i] =
525 cx->options.megabytes[i] * 1024 * 1024 569 cx->options.megabytes[i] * 1024 * 1024
@@ -1032,6 +1076,10 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev,
1032 } 1076 }
1033 1077
1034 CX18_INFO("Initialized card: %s\n", cx->card_name); 1078 CX18_INFO("Initialized card: %s\n", cx->card_name);
1079
1080 /* Load cx18 submodules (cx18-alsa) */
1081 request_modules(cx);
1082
1035 return 0; 1083 return 0;
1036 1084
1037free_streams: 1085free_streams:
@@ -1220,6 +1268,7 @@ static void cx18_remove(struct pci_dev *pci_dev)
1220 kfree(cx); 1268 kfree(cx);
1221} 1269}
1222 1270
1271
1223/* define a pci_driver for card detection */ 1272/* define a pci_driver for card detection */
1224static struct pci_driver cx18_pci_driver = { 1273static struct pci_driver cx18_pci_driver = {
1225 .name = "cx18", 1274 .name = "cx18",
@@ -1230,7 +1279,8 @@ static struct pci_driver cx18_pci_driver = {
1230 1279
1231static int __init module_start(void) 1280static int __init module_start(void)
1232{ 1281{
1233 printk(KERN_INFO "cx18: Start initialization, version %s\n", CX18_VERSION); 1282 printk(KERN_INFO "cx18: Start initialization, version %s\n",
1283 CX18_VERSION);
1234 1284
1235 /* Validate parameters */ 1285 /* Validate parameters */
1236 if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) { 1286 if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) {
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h
index e3f7911a7385..23ad6d548dc5 100644
--- a/drivers/media/video/cx18/cx18-driver.h
+++ b/drivers/media/video/cx18/cx18-driver.h
@@ -126,10 +126,22 @@
126#define CX18_625_LINE_ENC_YUV_BUFSIZE (CX18_UNIT_ENC_YUV_BUFSIZE * 576/32) 126#define CX18_625_LINE_ENC_YUV_BUFSIZE (CX18_UNIT_ENC_YUV_BUFSIZE * 576/32)
127#define CX18_525_LINE_ENC_YUV_BUFSIZE (CX18_UNIT_ENC_YUV_BUFSIZE * 480/32) 127#define CX18_525_LINE_ENC_YUV_BUFSIZE (CX18_UNIT_ENC_YUV_BUFSIZE * 480/32)
128 128
129/* IDX buffer size should be a multiple of the index entry size from the chip */
130struct cx18_enc_idx_entry {
131 __le32 length;
132 __le32 offset_low;
133 __le32 offset_high;
134 __le32 flags;
135 __le32 pts_low;
136 __le32 pts_high;
137} __attribute__ ((packed));
138#define CX18_UNIT_ENC_IDX_BUFSIZE \
139 (sizeof(struct cx18_enc_idx_entry) * V4L2_ENC_IDX_ENTRIES)
140
129/* DMA buffer, default size in kB allocated */ 141/* DMA buffer, default size in kB allocated */
130#define CX18_DEFAULT_ENC_TS_BUFSIZE 32 142#define CX18_DEFAULT_ENC_TS_BUFSIZE 32
131#define CX18_DEFAULT_ENC_MPG_BUFSIZE 32 143#define CX18_DEFAULT_ENC_MPG_BUFSIZE 32
132#define CX18_DEFAULT_ENC_IDX_BUFSIZE 32 144#define CX18_DEFAULT_ENC_IDX_BUFSIZE (CX18_UNIT_ENC_IDX_BUFSIZE * 1 / 1024 + 1)
133#define CX18_DEFAULT_ENC_YUV_BUFSIZE (CX18_UNIT_ENC_YUV_BUFSIZE * 3 / 1024 + 1) 145#define CX18_DEFAULT_ENC_YUV_BUFSIZE (CX18_UNIT_ENC_YUV_BUFSIZE * 3 / 1024 + 1)
134#define CX18_DEFAULT_ENC_PCM_BUFSIZE 4 146#define CX18_DEFAULT_ENC_PCM_BUFSIZE 4
135 147
@@ -234,16 +246,8 @@
234#define CX18_WARN_DEV(dev, fmt, args...) v4l2_warn(dev, fmt , ## args) 246#define CX18_WARN_DEV(dev, fmt, args...) v4l2_warn(dev, fmt , ## args)
235#define CX18_INFO_DEV(dev, fmt, args...) v4l2_info(dev, fmt , ## args) 247#define CX18_INFO_DEV(dev, fmt, args...) v4l2_info(dev, fmt , ## args)
236 248
237/* Values for CX18_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */
238#define MPEG_FRAME_TYPE_IFRAME 1
239#define MPEG_FRAME_TYPE_IFRAME_PFRAME 3
240#define MPEG_FRAME_TYPE_ALL 7
241
242#define CX18_MAX_PGM_INDEX (400)
243
244extern int cx18_debug; 249extern int cx18_debug;
245 250
246
247struct cx18_options { 251struct cx18_options {
248 int megabytes[CX18_MAX_STREAMS]; /* Size in megabytes of each stream */ 252 int megabytes[CX18_MAX_STREAMS]; /* Size in megabytes of each stream */
249 int cardtype; /* force card type on load */ 253 int cardtype; /* force card type on load */
@@ -276,6 +280,18 @@ struct cx18_options {
276#define CX18_SLICED_TYPE_WSS_625 (5) 280#define CX18_SLICED_TYPE_WSS_625 (5)
277#define CX18_SLICED_TYPE_VPS (7) 281#define CX18_SLICED_TYPE_VPS (7)
278 282
283/**
284 * list_entry_is_past_end - check if a previous loop cursor is off list end
285 * @pos: the type * previously used as a loop cursor.
286 * @head: the head for your list.
287 * @member: the name of the list_struct within the struct.
288 *
289 * Check if the entry's list_head is the head of the list, thus it's not a
290 * real entry but was the loop cursor that walked past the end
291 */
292#define list_entry_is_past_end(pos, head, member) \
293 (&pos->member == (head))
294
279struct cx18_buffer { 295struct cx18_buffer {
280 struct list_head list; 296 struct list_head list;
281 dma_addr_t dma_handle; 297 dma_addr_t dma_handle;
@@ -558,6 +574,10 @@ struct cx18 {
558 int stream_buffers[CX18_MAX_STREAMS]; /* # of buffers for each stream */ 574 int stream_buffers[CX18_MAX_STREAMS]; /* # of buffers for each stream */
559 int stream_buf_size[CX18_MAX_STREAMS]; /* Stream buffer size */ 575 int stream_buf_size[CX18_MAX_STREAMS]; /* Stream buffer size */
560 struct cx18_stream streams[CX18_MAX_STREAMS]; /* Stream data */ 576 struct cx18_stream streams[CX18_MAX_STREAMS]; /* Stream data */
577 struct snd_cx18_card *alsa; /* ALSA interface for PCM capture stream */
578 void (*pcm_announce_callback)(struct snd_cx18_card *card, u8 *pcm_data,
579 size_t num_bytes);
580
561 unsigned long i_flags; /* global cx18 flags */ 581 unsigned long i_flags; /* global cx18 flags */
562 atomic_t ana_capturing; /* count number of active analog capture streams */ 582 atomic_t ana_capturing; /* count number of active analog capture streams */
563 atomic_t tot_capturing; /* total count number of active capture streams */ 583 atomic_t tot_capturing; /* total count number of active capture streams */
@@ -575,12 +595,6 @@ struct cx18 {
575 595
576 struct vbi_info vbi; 596 struct vbi_info vbi;
577 597
578 u32 pgm_info_offset;
579 u32 pgm_info_num;
580 u32 pgm_info_write_idx;
581 u32 pgm_info_read_idx;
582 struct v4l2_enc_idx_entry pgm_info[CX18_MAX_PGM_INDEX];
583
584 u64 mpg_data_received; 598 u64 mpg_data_received;
585 u64 vbi_data_inserted; 599 u64 vbi_data_inserted;
586 600
@@ -623,6 +637,9 @@ struct cx18 {
623 u32 active_input; 637 u32 active_input;
624 v4l2_std_id std; 638 v4l2_std_id std;
625 v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */ 639 v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */
640
641 /* Used for cx18-alsa module loading */
642 struct work_struct request_module_wk;
626}; 643};
627 644
628static inline struct cx18 *to_cx18(struct v4l2_device *v4l2_dev) 645static inline struct cx18 *to_cx18(struct v4l2_device *v4l2_dev)
@@ -630,6 +647,9 @@ static inline struct cx18 *to_cx18(struct v4l2_device *v4l2_dev)
630 return container_of(v4l2_dev, struct cx18, v4l2_dev); 647 return container_of(v4l2_dev, struct cx18, v4l2_dev);
631} 648}
632 649
650/* cx18 extensions to be loaded */
651extern int (*cx18_ext_init)(struct cx18 *);
652
633/* Globals */ 653/* Globals */
634extern int cx18_first_minor; 654extern int cx18_first_minor;
635 655
diff --git a/drivers/media/video/cx18/cx18-dvb.c b/drivers/media/video/cx18/cx18-dvb.c
index 71ad2d1b4c2c..0ae2c2e1eab5 100644
--- a/drivers/media/video/cx18/cx18-dvb.c
+++ b/drivers/media/video/cx18/cx18-dvb.c
@@ -213,10 +213,14 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
213{ 213{
214 struct dvb_demux *demux = feed->demux; 214 struct dvb_demux *demux = feed->demux;
215 struct cx18_stream *stream = (struct cx18_stream *) demux->priv; 215 struct cx18_stream *stream = (struct cx18_stream *) demux->priv;
216 struct cx18 *cx = stream->cx; 216 struct cx18 *cx;
217 int ret; 217 int ret;
218 u32 v; 218 u32 v;
219 219
220 if (!stream)
221 return -EINVAL;
222
223 cx = stream->cx;
220 CX18_DEBUG_INFO("Start feed: pid = 0x%x index = %d\n", 224 CX18_DEBUG_INFO("Start feed: pid = 0x%x index = %d\n",
221 feed->pid, feed->index); 225 feed->pid, feed->index);
222 226
@@ -253,12 +257,10 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
253 if (!demux->dmx.frontend) 257 if (!demux->dmx.frontend)
254 return -EINVAL; 258 return -EINVAL;
255 259
256 if (!stream)
257 return -EINVAL;
258
259 mutex_lock(&stream->dvb.feedlock); 260 mutex_lock(&stream->dvb.feedlock);
260 if (stream->dvb.feeding++ == 0) { 261 if (stream->dvb.feeding++ == 0) {
261 CX18_DEBUG_INFO("Starting Transport DMA\n"); 262 CX18_DEBUG_INFO("Starting Transport DMA\n");
263 mutex_lock(&cx->serialize_lock);
262 set_bit(CX18_F_S_STREAMING, &stream->s_flags); 264 set_bit(CX18_F_S_STREAMING, &stream->s_flags);
263 ret = cx18_start_v4l2_encode_stream(stream); 265 ret = cx18_start_v4l2_encode_stream(stream);
264 if (ret < 0) { 266 if (ret < 0) {
@@ -267,6 +269,7 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
267 if (stream->dvb.feeding == 0) 269 if (stream->dvb.feeding == 0)
268 clear_bit(CX18_F_S_STREAMING, &stream->s_flags); 270 clear_bit(CX18_F_S_STREAMING, &stream->s_flags);
269 } 271 }
272 mutex_unlock(&cx->serialize_lock);
270 } else 273 } else
271 ret = 0; 274 ret = 0;
272 mutex_unlock(&stream->dvb.feedlock); 275 mutex_unlock(&stream->dvb.feedlock);
@@ -279,17 +282,20 @@ static int cx18_dvb_stop_feed(struct dvb_demux_feed *feed)
279{ 282{
280 struct dvb_demux *demux = feed->demux; 283 struct dvb_demux *demux = feed->demux;
281 struct cx18_stream *stream = (struct cx18_stream *)demux->priv; 284 struct cx18_stream *stream = (struct cx18_stream *)demux->priv;
282 struct cx18 *cx = stream->cx; 285 struct cx18 *cx;
283 int ret = -EINVAL; 286 int ret = -EINVAL;
284 287
285 CX18_DEBUG_INFO("Stop feed: pid = 0x%x index = %d\n",
286 feed->pid, feed->index);
287
288 if (stream) { 288 if (stream) {
289 cx = stream->cx;
290 CX18_DEBUG_INFO("Stop feed: pid = 0x%x index = %d\n",
291 feed->pid, feed->index);
292
289 mutex_lock(&stream->dvb.feedlock); 293 mutex_lock(&stream->dvb.feedlock);
290 if (--stream->dvb.feeding == 0) { 294 if (--stream->dvb.feeding == 0) {
291 CX18_DEBUG_INFO("Stopping Transport DMA\n"); 295 CX18_DEBUG_INFO("Stopping Transport DMA\n");
296 mutex_lock(&cx->serialize_lock);
292 ret = cx18_stop_v4l2_encode_stream(stream, 0); 297 ret = cx18_stop_v4l2_encode_stream(stream, 0);
298 mutex_unlock(&cx->serialize_lock);
293 } else 299 } else
294 ret = 0; 300 ret = 0;
295 mutex_unlock(&stream->dvb.feedlock); 301 mutex_unlock(&stream->dvb.feedlock);
diff --git a/drivers/media/video/cx18/cx18-fileops.c b/drivers/media/video/cx18/cx18-fileops.c
index c0885c69fd89..863ce7758239 100644
--- a/drivers/media/video/cx18/cx18-fileops.c
+++ b/drivers/media/video/cx18/cx18-fileops.c
@@ -37,15 +37,21 @@
37 37
38/* This function tries to claim the stream for a specific file descriptor. 38/* This function tries to claim the stream for a specific file descriptor.
39 If no one else is using this stream then the stream is claimed and 39 If no one else is using this stream then the stream is claimed and
40 associated VBI streams are also automatically claimed. 40 associated VBI and IDX streams are also automatically claimed.
41 Possible error returns: -EBUSY if someone else has claimed 41 Possible error returns: -EBUSY if someone else has claimed
42 the stream or 0 on success. */ 42 the stream or 0 on success. */
43static int cx18_claim_stream(struct cx18_open_id *id, int type) 43int cx18_claim_stream(struct cx18_open_id *id, int type)
44{ 44{
45 struct cx18 *cx = id->cx; 45 struct cx18 *cx = id->cx;
46 struct cx18_stream *s = &cx->streams[type]; 46 struct cx18_stream *s = &cx->streams[type];
47 struct cx18_stream *s_vbi; 47 struct cx18_stream *s_assoc;
48 int vbi_type; 48
49 /* Nothing should ever try to directly claim the IDX stream */
50 if (type == CX18_ENC_STREAM_TYPE_IDX) {
51 CX18_WARN("MPEG Index stream cannot be claimed "
52 "directly, but something tried.\n");
53 return -EINVAL;
54 }
49 55
50 if (test_and_set_bit(CX18_F_S_CLAIMED, &s->s_flags)) { 56 if (test_and_set_bit(CX18_F_S_CLAIMED, &s->s_flags)) {
51 /* someone already claimed this stream */ 57 /* someone already claimed this stream */
@@ -67,32 +73,47 @@ static int cx18_claim_stream(struct cx18_open_id *id, int type)
67 } 73 }
68 s->id = id->open_id; 74 s->id = id->open_id;
69 75
70 /* CX18_ENC_STREAM_TYPE_MPG needs to claim CX18_ENC_STREAM_TYPE_VBI 76 /*
71 (provided VBI insertion is on and sliced VBI is selected), for all 77 * CX18_ENC_STREAM_TYPE_MPG needs to claim:
72 other streams we're done */ 78 * CX18_ENC_STREAM_TYPE_VBI, if VBI insertion is on for sliced VBI, or
73 if (type == CX18_ENC_STREAM_TYPE_MPG && 79 * CX18_ENC_STREAM_TYPE_IDX, if VBI insertion is off for sliced VBI
74 cx->vbi.insert_mpeg && !cx18_raw_vbi(cx)) { 80 * (We don't yet fix up MPEG Index entries for our inserted packets).
75 vbi_type = CX18_ENC_STREAM_TYPE_VBI; 81 *
76 } else { 82 * For all other streams we're done.
83 */
84 if (type != CX18_ENC_STREAM_TYPE_MPG)
77 return 0; 85 return 0;
78 }
79 s_vbi = &cx->streams[vbi_type];
80 86
81 set_bit(CX18_F_S_CLAIMED, &s_vbi->s_flags); 87 s_assoc = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
88 if (cx->vbi.insert_mpeg && !cx18_raw_vbi(cx))
89 s_assoc = &cx->streams[CX18_ENC_STREAM_TYPE_VBI];
90 else if (!cx18_stream_enabled(s_assoc))
91 return 0;
92
93 set_bit(CX18_F_S_CLAIMED, &s_assoc->s_flags);
82 94
83 /* mark that it is used internally */ 95 /* mark that it is used internally */
84 set_bit(CX18_F_S_INTERNAL_USE, &s_vbi->s_flags); 96 set_bit(CX18_F_S_INTERNAL_USE, &s_assoc->s_flags);
85 return 0; 97 return 0;
86} 98}
99EXPORT_SYMBOL(cx18_claim_stream);
87 100
88/* This function releases a previously claimed stream. It will take into 101/* This function releases a previously claimed stream. It will take into
89 account associated VBI streams. */ 102 account associated VBI streams. */
90static void cx18_release_stream(struct cx18_stream *s) 103void cx18_release_stream(struct cx18_stream *s)
91{ 104{
92 struct cx18 *cx = s->cx; 105 struct cx18 *cx = s->cx;
93 struct cx18_stream *s_vbi; 106 struct cx18_stream *s_assoc;
94 107
95 s->id = -1; 108 s->id = -1;
109 if (s->type == CX18_ENC_STREAM_TYPE_IDX) {
110 /*
111 * The IDX stream is only used internally, and can
112 * only be indirectly unclaimed by unclaiming the MPG stream.
113 */
114 return;
115 }
116
96 if (s->type == CX18_ENC_STREAM_TYPE_VBI && 117 if (s->type == CX18_ENC_STREAM_TYPE_VBI &&
97 test_bit(CX18_F_S_INTERNAL_USE, &s->s_flags)) { 118 test_bit(CX18_F_S_INTERNAL_USE, &s->s_flags)) {
98 /* this stream is still in use internally */ 119 /* this stream is still in use internally */
@@ -105,25 +126,36 @@ static void cx18_release_stream(struct cx18_stream *s)
105 126
106 cx18_flush_queues(s); 127 cx18_flush_queues(s);
107 128
108 /* CX18_ENC_STREAM_TYPE_MPG needs to release CX18_ENC_STREAM_TYPE_VBI, 129 /*
109 for all other streams we're done */ 130 * CX18_ENC_STREAM_TYPE_MPG needs to release the
110 if (s->type == CX18_ENC_STREAM_TYPE_MPG) 131 * CX18_ENC_STREAM_TYPE_VBI and/or CX18_ENC_STREAM_TYPE_IDX streams.
111 s_vbi = &cx->streams[CX18_ENC_STREAM_TYPE_VBI]; 132 *
112 else 133 * For all other streams we're done.
134 */
135 if (s->type != CX18_ENC_STREAM_TYPE_MPG)
113 return; 136 return;
114 137
115 /* clear internal use flag */ 138 /* Unclaim the associated MPEG Index stream */
116 if (!test_and_clear_bit(CX18_F_S_INTERNAL_USE, &s_vbi->s_flags)) { 139 s_assoc = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
117 /* was already cleared */ 140 if (test_and_clear_bit(CX18_F_S_INTERNAL_USE, &s_assoc->s_flags)) {
118 return; 141 clear_bit(CX18_F_S_CLAIMED, &s_assoc->s_flags);
142 cx18_flush_queues(s_assoc);
119 } 143 }
120 if (s_vbi->id != -1) { 144
121 /* VBI stream still claimed by a file descriptor */ 145 /* Unclaim the associated VBI stream */
122 return; 146 s_assoc = &cx->streams[CX18_ENC_STREAM_TYPE_VBI];
147 if (test_and_clear_bit(CX18_F_S_INTERNAL_USE, &s_assoc->s_flags)) {
148 if (s_assoc->id == -1) {
149 /*
150 * The VBI stream is not still claimed by a file
151 * descriptor, so completely unclaim it.
152 */
153 clear_bit(CX18_F_S_CLAIMED, &s_assoc->s_flags);
154 cx18_flush_queues(s_assoc);
155 }
123 } 156 }
124 clear_bit(CX18_F_S_CLAIMED, &s_vbi->s_flags);
125 cx18_flush_queues(s_vbi);
126} 157}
158EXPORT_SYMBOL(cx18_release_stream);
127 159
128static void cx18_dualwatch(struct cx18 *cx) 160static void cx18_dualwatch(struct cx18 *cx)
129{ 161{
@@ -177,9 +209,7 @@ static struct cx18_mdl *cx18_get_mdl(struct cx18_stream *s, int non_block,
177 *err = 0; 209 *err = 0;
178 while (1) { 210 while (1) {
179 if (s->type == CX18_ENC_STREAM_TYPE_MPG) { 211 if (s->type == CX18_ENC_STREAM_TYPE_MPG) {
180 /* Process pending program info updates and pending 212 /* Process pending program updates and VBI data */
181 VBI data */
182
183 if (time_after(jiffies, cx->dualwatch_jiffies + msecs_to_jiffies(1000))) { 213 if (time_after(jiffies, cx->dualwatch_jiffies + msecs_to_jiffies(1000))) {
184 cx->dualwatch_jiffies = jiffies; 214 cx->dualwatch_jiffies = jiffies;
185 cx18_dualwatch(cx); 215 cx18_dualwatch(cx);
@@ -362,18 +392,6 @@ static size_t cx18_copy_buf_to_user(struct cx18_stream *s,
362 return len; 392 return len;
363} 393}
364 394
365/**
366 * list_entry_is_past_end - check if a previous loop cursor is off list end
367 * @pos: the type * previously used as a loop cursor.
368 * @head: the head for your list.
369 * @member: the name of the list_struct within the struct.
370 *
371 * Check if the entry's list_head is the head of the list, thus it's not a
372 * real entry but was the loop cursor that walked past the end
373 */
374#define list_entry_is_past_end(pos, head, member) \
375 (&pos->member == (head))
376
377static size_t cx18_copy_mdl_to_user(struct cx18_stream *s, 395static size_t cx18_copy_mdl_to_user(struct cx18_stream *s,
378 struct cx18_mdl *mdl, char __user *ubuf, size_t ucount) 396 struct cx18_mdl *mdl, char __user *ubuf, size_t ucount)
379{ 397{
@@ -498,6 +516,7 @@ int cx18_start_capture(struct cx18_open_id *id)
498 struct cx18 *cx = id->cx; 516 struct cx18 *cx = id->cx;
499 struct cx18_stream *s = &cx->streams[id->type]; 517 struct cx18_stream *s = &cx->streams[id->type];
500 struct cx18_stream *s_vbi; 518 struct cx18_stream *s_vbi;
519 struct cx18_stream *s_idx;
501 520
502 if (s->type == CX18_ENC_STREAM_TYPE_RAD) { 521 if (s->type == CX18_ENC_STREAM_TYPE_RAD) {
503 /* you cannot read from these stream types. */ 522 /* you cannot read from these stream types. */
@@ -516,25 +535,33 @@ int cx18_start_capture(struct cx18_open_id *id)
516 return 0; 535 return 0;
517 } 536 }
518 537
519 /* Start VBI capture if required */ 538 /* Start associated VBI or IDX stream capture if required */
520 s_vbi = &cx->streams[CX18_ENC_STREAM_TYPE_VBI]; 539 s_vbi = &cx->streams[CX18_ENC_STREAM_TYPE_VBI];
521 if (s->type == CX18_ENC_STREAM_TYPE_MPG && 540 s_idx = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
522 test_bit(CX18_F_S_INTERNAL_USE, &s_vbi->s_flags) && 541 if (s->type == CX18_ENC_STREAM_TYPE_MPG) {
523 !test_and_set_bit(CX18_F_S_STREAMING, &s_vbi->s_flags)) { 542 /*
524 /* Note: the CX18_ENC_STREAM_TYPE_VBI is claimed 543 * The VBI and IDX streams should have been claimed
525 automatically when the MPG stream is claimed. 544 * automatically, if for internal use, when the MPG stream was
526 We only need to start the VBI capturing. */ 545 * claimed. We only need to start these streams capturing.
527 if (cx18_start_v4l2_encode_stream(s_vbi)) { 546 */
528 CX18_DEBUG_WARN("VBI capture start failed\n"); 547 if (test_bit(CX18_F_S_INTERNAL_USE, &s_idx->s_flags) &&
529 548 !test_and_set_bit(CX18_F_S_STREAMING, &s_idx->s_flags)) {
530 /* Failure, clean up and return an error */ 549 if (cx18_start_v4l2_encode_stream(s_idx)) {
531 clear_bit(CX18_F_S_STREAMING, &s_vbi->s_flags); 550 CX18_DEBUG_WARN("IDX capture start failed\n");
532 clear_bit(CX18_F_S_STREAMING, &s->s_flags); 551 clear_bit(CX18_F_S_STREAMING, &s_idx->s_flags);
533 /* also releases the associated VBI stream */ 552 goto start_failed;
534 cx18_release_stream(s); 553 }
535 return -EIO; 554 CX18_DEBUG_INFO("IDX capture started\n");
555 }
556 if (test_bit(CX18_F_S_INTERNAL_USE, &s_vbi->s_flags) &&
557 !test_and_set_bit(CX18_F_S_STREAMING, &s_vbi->s_flags)) {
558 if (cx18_start_v4l2_encode_stream(s_vbi)) {
559 CX18_DEBUG_WARN("VBI capture start failed\n");
560 clear_bit(CX18_F_S_STREAMING, &s_vbi->s_flags);
561 goto start_failed;
562 }
563 CX18_DEBUG_INFO("VBI insertion started\n");
536 } 564 }
537 CX18_DEBUG_INFO("VBI insertion started\n");
538 } 565 }
539 566
540 /* Tell the card to start capturing */ 567 /* Tell the card to start capturing */
@@ -547,19 +574,29 @@ int cx18_start_capture(struct cx18_open_id *id)
547 return 0; 574 return 0;
548 } 575 }
549 576
550 /* failure, clean up */ 577start_failed:
551 CX18_DEBUG_WARN("Failed to start capturing for stream %s\n", s->name); 578 CX18_DEBUG_WARN("Failed to start capturing for stream %s\n", s->name);
552 579
553 /* Note: the CX18_ENC_STREAM_TYPE_VBI is released 580 /*
554 automatically when the MPG stream is released. 581 * The associated VBI and IDX streams for internal use are released
555 We only need to stop the VBI capturing. */ 582 * automatically when the MPG stream is released. We only need to stop
556 if (s->type == CX18_ENC_STREAM_TYPE_MPG && 583 * the associated stream.
557 test_bit(CX18_F_S_STREAMING, &s_vbi->s_flags)) { 584 */
558 cx18_stop_v4l2_encode_stream(s_vbi, 0); 585 if (s->type == CX18_ENC_STREAM_TYPE_MPG) {
559 clear_bit(CX18_F_S_STREAMING, &s_vbi->s_flags); 586 /* Stop the IDX stream which is always for internal use */
587 if (test_bit(CX18_F_S_STREAMING, &s_idx->s_flags)) {
588 cx18_stop_v4l2_encode_stream(s_idx, 0);
589 clear_bit(CX18_F_S_STREAMING, &s_idx->s_flags);
590 }
591 /* Stop the VBI stream, if only running for internal use */
592 if (test_bit(CX18_F_S_STREAMING, &s_vbi->s_flags) &&
593 !test_bit(CX18_F_S_APPL_IO, &s_vbi->s_flags)) {
594 cx18_stop_v4l2_encode_stream(s_vbi, 0);
595 clear_bit(CX18_F_S_STREAMING, &s_vbi->s_flags);
596 }
560 } 597 }
561 clear_bit(CX18_F_S_STREAMING, &s->s_flags); 598 clear_bit(CX18_F_S_STREAMING, &s->s_flags);
562 cx18_release_stream(s); 599 cx18_release_stream(s); /* Also releases associated streams */
563 return -EIO; 600 return -EIO;
564} 601}
565 602
@@ -618,6 +655,8 @@ void cx18_stop_capture(struct cx18_open_id *id, int gop_end)
618{ 655{
619 struct cx18 *cx = id->cx; 656 struct cx18 *cx = id->cx;
620 struct cx18_stream *s = &cx->streams[id->type]; 657 struct cx18_stream *s = &cx->streams[id->type];
658 struct cx18_stream *s_vbi = &cx->streams[CX18_ENC_STREAM_TYPE_VBI];
659 struct cx18_stream *s_idx = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
621 660
622 CX18_DEBUG_IOCTL("close() of %s\n", s->name); 661 CX18_DEBUG_IOCTL("close() of %s\n", s->name);
623 662
@@ -625,17 +664,19 @@ void cx18_stop_capture(struct cx18_open_id *id, int gop_end)
625 664
626 /* Stop capturing */ 665 /* Stop capturing */
627 if (test_bit(CX18_F_S_STREAMING, &s->s_flags)) { 666 if (test_bit(CX18_F_S_STREAMING, &s->s_flags)) {
628 struct cx18_stream *s_vbi =
629 &cx->streams[CX18_ENC_STREAM_TYPE_VBI];
630
631 CX18_DEBUG_INFO("close stopping capture\n"); 667 CX18_DEBUG_INFO("close stopping capture\n");
632 /* Special case: a running VBI capture for VBI insertion 668 if (id->type == CX18_ENC_STREAM_TYPE_MPG) {
633 in the mpeg stream. Need to stop that too. */ 669 /* Stop internal use associated VBI and IDX streams */
634 if (id->type == CX18_ENC_STREAM_TYPE_MPG && 670 if (test_bit(CX18_F_S_STREAMING, &s_vbi->s_flags) &&
635 test_bit(CX18_F_S_STREAMING, &s_vbi->s_flags) && 671 !test_bit(CX18_F_S_APPL_IO, &s_vbi->s_flags)) {
636 !test_bit(CX18_F_S_APPL_IO, &s_vbi->s_flags)) { 672 CX18_DEBUG_INFO("close stopping embedded VBI "
637 CX18_DEBUG_INFO("close stopping embedded VBI capture\n"); 673 "capture\n");
638 cx18_stop_v4l2_encode_stream(s_vbi, 0); 674 cx18_stop_v4l2_encode_stream(s_vbi, 0);
675 }
676 if (test_bit(CX18_F_S_STREAMING, &s_idx->s_flags)) {
677 CX18_DEBUG_INFO("close stopping IDX capture\n");
678 cx18_stop_v4l2_encode_stream(s_idx, 0);
679 }
639 } 680 }
640 if (id->type == CX18_ENC_STREAM_TYPE_VBI && 681 if (id->type == CX18_ENC_STREAM_TYPE_VBI &&
641 test_bit(CX18_F_S_INTERNAL_USE, &s->s_flags)) 682 test_bit(CX18_F_S_INTERNAL_USE, &s->s_flags))
diff --git a/drivers/media/video/cx18/cx18-fileops.h b/drivers/media/video/cx18/cx18-fileops.h
index 92e2d5dab936..5c8fcb884f0a 100644
--- a/drivers/media/video/cx18/cx18-fileops.h
+++ b/drivers/media/video/cx18/cx18-fileops.h
@@ -34,3 +34,6 @@ void cx18_stop_capture(struct cx18_open_id *id, int gop_end);
34void cx18_mute(struct cx18 *cx); 34void cx18_mute(struct cx18 *cx);
35void cx18_unmute(struct cx18 *cx); 35void cx18_unmute(struct cx18 *cx);
36 36
37/* Shared with cx18-alsa module */
38int cx18_claim_stream(struct cx18_open_id *id, int type);
39void cx18_release_stream(struct cx18_stream *s);
diff --git a/drivers/media/video/cx18/cx18-ioctl.c b/drivers/media/video/cx18/cx18-ioctl.c
index 3e4fc192fdec..b81dd0ea8eb9 100644
--- a/drivers/media/video/cx18/cx18-ioctl.c
+++ b/drivers/media/video/cx18/cx18-ioctl.c
@@ -775,10 +775,143 @@ static int cx18_g_sliced_vbi_cap(struct file *file, void *fh,
775 return 0; 775 return 0;
776} 776}
777 777
778static int _cx18_process_idx_data(struct cx18_buffer *buf,
779 struct v4l2_enc_idx *idx)
780{
781 int consumed, remaining;
782 struct v4l2_enc_idx_entry *e_idx;
783 struct cx18_enc_idx_entry *e_buf;
784
785 /* Frame type lookup: 1=I, 2=P, 4=B */
786 const int mapping[8] = {
787 -1, V4L2_ENC_IDX_FRAME_I, V4L2_ENC_IDX_FRAME_P,
788 -1, V4L2_ENC_IDX_FRAME_B, -1, -1, -1
789 };
790
791 /*
792 * Assumption here is that a buf holds an integral number of
793 * struct cx18_enc_idx_entry objects and is properly aligned.
794 * This is enforced by the module options on IDX buffer sizes.
795 */
796 remaining = buf->bytesused - buf->readpos;
797 consumed = 0;
798 e_idx = &idx->entry[idx->entries];
799 e_buf = (struct cx18_enc_idx_entry *) &buf->buf[buf->readpos];
800
801 while (remaining >= sizeof(struct cx18_enc_idx_entry) &&
802 idx->entries < V4L2_ENC_IDX_ENTRIES) {
803
804 e_idx->offset = (((u64) le32_to_cpu(e_buf->offset_high)) << 32)
805 | le32_to_cpu(e_buf->offset_low);
806
807 e_idx->pts = (((u64) (le32_to_cpu(e_buf->pts_high) & 1)) << 32)
808 | le32_to_cpu(e_buf->pts_low);
809
810 e_idx->length = le32_to_cpu(e_buf->length);
811
812 e_idx->flags = mapping[le32_to_cpu(e_buf->flags) & 0x7];
813
814 e_idx->reserved[0] = 0;
815 e_idx->reserved[1] = 0;
816
817 idx->entries++;
818 e_idx = &idx->entry[idx->entries];
819 e_buf++;
820
821 remaining -= sizeof(struct cx18_enc_idx_entry);
822 consumed += sizeof(struct cx18_enc_idx_entry);
823 }
824
825 /* Swallow any partial entries at the end, if there are any */
826 if (remaining > 0 && remaining < sizeof(struct cx18_enc_idx_entry))
827 consumed += remaining;
828
829 buf->readpos += consumed;
830 return consumed;
831}
832
833static int cx18_process_idx_data(struct cx18_stream *s, struct cx18_mdl *mdl,
834 struct v4l2_enc_idx *idx)
835{
836 if (s->type != CX18_ENC_STREAM_TYPE_IDX)
837 return -EINVAL;
838
839 if (mdl->curr_buf == NULL)
840 mdl->curr_buf = list_first_entry(&mdl->buf_list,
841 struct cx18_buffer, list);
842
843 if (list_entry_is_past_end(mdl->curr_buf, &mdl->buf_list, list)) {
844 /*
845 * For some reason we've exhausted the buffers, but the MDL
846 * object still said some data was unread.
847 * Fix that and bail out.
848 */
849 mdl->readpos = mdl->bytesused;
850 return 0;
851 }
852
853 list_for_each_entry_from(mdl->curr_buf, &mdl->buf_list, list) {
854
855 /* Skip any empty buffers in the MDL */
856 if (mdl->curr_buf->readpos >= mdl->curr_buf->bytesused)
857 continue;
858
859 mdl->readpos += _cx18_process_idx_data(mdl->curr_buf, idx);
860
861 /* exit when MDL drained or request satisfied */
862 if (idx->entries >= V4L2_ENC_IDX_ENTRIES ||
863 mdl->curr_buf->readpos < mdl->curr_buf->bytesused ||
864 mdl->readpos >= mdl->bytesused)
865 break;
866 }
867 return 0;
868}
869
778static int cx18_g_enc_index(struct file *file, void *fh, 870static int cx18_g_enc_index(struct file *file, void *fh,
779 struct v4l2_enc_idx *idx) 871 struct v4l2_enc_idx *idx)
780{ 872{
781 return -EINVAL; 873 struct cx18 *cx = ((struct cx18_open_id *)fh)->cx;
874 struct cx18_stream *s = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
875 s32 tmp;
876 struct cx18_mdl *mdl;
877
878 if (!cx18_stream_enabled(s)) /* Module options inhibited IDX stream */
879 return -EINVAL;
880
881 /* Compute the best case number of entries we can buffer */
882 tmp = s->buffers -
883 s->bufs_per_mdl * CX18_ENC_STREAM_TYPE_IDX_FW_MDL_MIN;
884 if (tmp <= 0)
885 tmp = 1;
886 tmp = tmp * s->buf_size / sizeof(struct cx18_enc_idx_entry);
887
888 /* Fill out the header of the return structure */
889 idx->entries = 0;
890 idx->entries_cap = tmp;
891 memset(idx->reserved, 0, sizeof(idx->reserved));
892
893 /* Pull IDX MDLs and buffers from q_full and populate the entries */
894 do {
895 mdl = cx18_dequeue(s, &s->q_full);
896 if (mdl == NULL) /* No more IDX data right now */
897 break;
898
899 /* Extract the Index entry data from the MDL and buffers */
900 cx18_process_idx_data(s, mdl, idx);
901 if (mdl->readpos < mdl->bytesused) {
902 /* We finished with data remaining, push the MDL back */
903 cx18_push(s, mdl, &s->q_full);
904 break;
905 }
906
907 /* We drained this MDL, schedule it to go to the firmware */
908 cx18_enqueue(s, mdl, &s->q_free);
909
910 } while (idx->entries < V4L2_ENC_IDX_ENTRIES);
911
912 /* Tell the work handler to send free IDX MDLs to the firmware */
913 cx18_stream_load_fw_queue(s);
914 return 0;
782} 915}
783 916
784static int cx18_encoder_cmd(struct file *file, void *fh, 917static int cx18_encoder_cmd(struct file *file, void *fh,
diff --git a/drivers/media/video/cx18/cx18-mailbox.c b/drivers/media/video/cx18/cx18-mailbox.c
index f231dd09c720..6dcce297752f 100644
--- a/drivers/media/video/cx18/cx18-mailbox.c
+++ b/drivers/media/video/cx18/cx18-mailbox.c
@@ -29,6 +29,7 @@
29#include "cx18-mailbox.h" 29#include "cx18-mailbox.h"
30#include "cx18-queue.h" 30#include "cx18-queue.h"
31#include "cx18-streams.h" 31#include "cx18-streams.h"
32#include "cx18-alsa-pcm.h" /* FIXME make configurable */
32 33
33static const char *rpu_str[] = { "APU", "CPU", "EPU", "HPU" }; 34static const char *rpu_str[] = { "APU", "CPU", "EPU", "HPU" };
34 35
@@ -157,6 +158,34 @@ static void cx18_mdl_send_to_dvb(struct cx18_stream *s, struct cx18_mdl *mdl)
157 } 158 }
158} 159}
159 160
161
162static void cx18_mdl_send_to_alsa(struct cx18 *cx, struct cx18_stream *s,
163 struct cx18_mdl *mdl)
164{
165 struct cx18_buffer *buf;
166
167 if (mdl->bytesused == 0)
168 return;
169
170 /* We ignore mdl and buf readpos accounting here - it doesn't matter */
171
172 /* The likely case */
173 if (list_is_singular(&mdl->buf_list)) {
174 buf = list_first_entry(&mdl->buf_list, struct cx18_buffer,
175 list);
176 if (buf->bytesused)
177 cx->pcm_announce_callback(cx->alsa, buf->buf,
178 buf->bytesused);
179 return;
180 }
181
182 list_for_each_entry(buf, &mdl->buf_list, list) {
183 if (buf->bytesused == 0)
184 break;
185 cx->pcm_announce_callback(cx->alsa, buf->buf, buf->bytesused);
186 }
187}
188
160static void epu_dma_done(struct cx18 *cx, struct cx18_in_work_order *order) 189static void epu_dma_done(struct cx18 *cx, struct cx18_in_work_order *order)
161{ 190{
162 u32 handle, mdl_ack_count, id; 191 u32 handle, mdl_ack_count, id;
@@ -223,11 +252,21 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_in_work_order *order)
223 CX18_DEBUG_HI_DMA("%s recv bytesused = %d\n", 252 CX18_DEBUG_HI_DMA("%s recv bytesused = %d\n",
224 s->name, mdl->bytesused); 253 s->name, mdl->bytesused);
225 254
226 if (s->type != CX18_ENC_STREAM_TYPE_TS) 255 if (s->type == CX18_ENC_STREAM_TYPE_TS) {
227 cx18_enqueue(s, mdl, &s->q_full);
228 else {
229 cx18_mdl_send_to_dvb(s, mdl); 256 cx18_mdl_send_to_dvb(s, mdl);
230 cx18_enqueue(s, mdl, &s->q_free); 257 cx18_enqueue(s, mdl, &s->q_free);
258 } else if (s->type == CX18_ENC_STREAM_TYPE_PCM) {
259 /* Pass the data to cx18-alsa */
260 if (cx->pcm_announce_callback != NULL) {
261 cx18_mdl_send_to_alsa(cx, s, mdl);
262 cx18_enqueue(s, mdl, &s->q_free);
263 } else {
264 cx18_enqueue(s, mdl, &s->q_full);
265 }
266 } else {
267 cx18_enqueue(s, mdl, &s->q_full);
268 if (s->type == CX18_ENC_STREAM_TYPE_IDX)
269 cx18_stream_rotate_idx_mdls(cx);
231 } 270 }
232 } 271 }
233 /* Put as many MDLs as possible back into fw use */ 272 /* Put as many MDLs as possible back into fw use */
diff --git a/drivers/media/video/cx18/cx18-queue.c b/drivers/media/video/cx18/cx18-queue.c
index 63304823cef5..aefc8c8cf3c1 100644
--- a/drivers/media/video/cx18/cx18-queue.c
+++ b/drivers/media/video/cx18/cx18-queue.c
@@ -419,6 +419,9 @@ void cx18_stream_free(struct cx18_stream *s)
419{ 419{
420 struct cx18_mdl *mdl; 420 struct cx18_mdl *mdl;
421 struct cx18_buffer *buf; 421 struct cx18_buffer *buf;
422 struct cx18 *cx = s->cx;
423
424 CX18_DEBUG_INFO("Deallocating buffers for %s stream\n", s->name);
422 425
423 /* move all buffers to buf_pool and all MDLs to q_idle */ 426 /* move all buffers to buf_pool and all MDLs to q_idle */
424 cx18_unload_queues(s); 427 cx18_unload_queues(s);
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index 987a9308d938..054450f65a60 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -319,11 +319,27 @@ void cx18_streams_cleanup(struct cx18 *cx, int unregister)
319 319
320 /* Teardown all streams */ 320 /* Teardown all streams */
321 for (type = 0; type < CX18_MAX_STREAMS; type++) { 321 for (type = 0; type < CX18_MAX_STREAMS; type++) {
322 if (cx->streams[type].dvb.enabled) { 322
323 cx18_dvb_unregister(&cx->streams[type]); 323 /* No struct video_device, but can have buffers allocated */
324 cx->streams[type].dvb.enabled = false; 324 if (type == CX18_ENC_STREAM_TYPE_TS) {
325 if (cx->streams[type].dvb.enabled) {
326 cx18_dvb_unregister(&cx->streams[type]);
327 cx->streams[type].dvb.enabled = false;
328 cx18_stream_free(&cx->streams[type]);
329 }
330 continue;
331 }
332
333 /* No struct video_device, but can have buffers allocated */
334 if (type == CX18_ENC_STREAM_TYPE_IDX) {
335 if (cx->stream_buffers[type] != 0) {
336 cx->stream_buffers[type] = 0;
337 cx18_stream_free(&cx->streams[type]);
338 }
339 continue;
325 } 340 }
326 341
342 /* If struct video_device exists, can have buffers allocated */
327 vdev = cx->streams[type].video_dev; 343 vdev = cx->streams[type].video_dev;
328 344
329 cx->streams[type].video_dev = NULL; 345 cx->streams[type].video_dev = NULL;
@@ -447,6 +463,32 @@ static void cx18_vbi_setup(struct cx18_stream *s)
447 cx18_api(cx, CX18_CPU_SET_RAW_VBI_PARAM, 6, data); 463 cx18_api(cx, CX18_CPU_SET_RAW_VBI_PARAM, 6, data);
448} 464}
449 465
466void cx18_stream_rotate_idx_mdls(struct cx18 *cx)
467{
468 struct cx18_stream *s = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
469 struct cx18_mdl *mdl;
470
471 if (!cx18_stream_enabled(s))
472 return;
473
474 /* Return if the firmware is not running low on MDLs */
475 if ((atomic_read(&s->q_free.depth) + atomic_read(&s->q_busy.depth)) >=
476 CX18_ENC_STREAM_TYPE_IDX_FW_MDL_MIN)
477 return;
478
479 /* Return if there are no MDLs to rotate back to the firmware */
480 if (atomic_read(&s->q_full.depth) < 2)
481 return;
482
483 /*
484 * Take the oldest IDX MDL still holding data, and discard its index
485 * entries by scheduling the MDL to go back to the firmware
486 */
487 mdl = cx18_dequeue(s, &s->q_full);
488 if (mdl != NULL)
489 cx18_enqueue(s, mdl, &s->q_free);
490}
491
450static 492static
451struct cx18_queue *_cx18_stream_put_mdl_fw(struct cx18_stream *s, 493struct cx18_queue *_cx18_stream_put_mdl_fw(struct cx18_stream *s,
452 struct cx18_mdl *mdl) 494 struct cx18_mdl *mdl)
@@ -546,8 +588,9 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
546 struct cx18 *cx = s->cx; 588 struct cx18 *cx = s->cx;
547 int captype = 0; 589 int captype = 0;
548 struct cx18_api_func_private priv; 590 struct cx18_api_func_private priv;
591 struct cx18_stream *s_idx;
549 592
550 if (s->video_dev == NULL && s->dvb.enabled == 0) 593 if (!cx18_stream_enabled(s))
551 return -EINVAL; 594 return -EINVAL;
552 595
553 CX18_DEBUG_INFO("Start encoder stream %s\n", s->name); 596 CX18_DEBUG_INFO("Start encoder stream %s\n", s->name);
@@ -561,6 +604,9 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
561 cx->search_pack_header = 0; 604 cx->search_pack_header = 0;
562 break; 605 break;
563 606
607 case CX18_ENC_STREAM_TYPE_IDX:
608 captype = CAPTURE_CHANNEL_TYPE_INDEX;
609 break;
564 case CX18_ENC_STREAM_TYPE_TS: 610 case CX18_ENC_STREAM_TYPE_TS:
565 captype = CAPTURE_CHANNEL_TYPE_TS; 611 captype = CAPTURE_CHANNEL_TYPE_TS;
566 break; 612 break;
@@ -635,11 +681,13 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
635 cx18_vbi_setup(s); 681 cx18_vbi_setup(s);
636 682
637 /* 683 /*
638 * assign program index info. 684 * Select to receive I, P, and B frame index entries, if the
639 * Mask 7: select I/P/B, Num_req: 400 max 685 * index stream is enabled. Otherwise disable index entry
640 * FIXME - currently we have this hardcoded as disabled 686 * generation.
641 */ 687 */
642 cx18_vapi_result(cx, data, CX18_CPU_SET_INDEXTABLE, 1, 0); 688 s_idx = &cx->streams[CX18_ENC_STREAM_TYPE_IDX];
689 cx18_vapi_result(cx, data, CX18_CPU_SET_INDEXTABLE, 2,
690 s->handle, cx18_stream_enabled(s_idx) ? 7 : 0);
643 691
644 /* Call out to the common CX2341x API setup for user controls */ 692 /* Call out to the common CX2341x API setup for user controls */
645 priv.cx = cx; 693 priv.cx = cx;
@@ -697,6 +745,7 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
697 atomic_inc(&cx->tot_capturing); 745 atomic_inc(&cx->tot_capturing);
698 return 0; 746 return 0;
699} 747}
748EXPORT_SYMBOL(cx18_start_v4l2_encode_stream);
700 749
701void cx18_stop_all_captures(struct cx18 *cx) 750void cx18_stop_all_captures(struct cx18 *cx)
702{ 751{
@@ -705,7 +754,7 @@ void cx18_stop_all_captures(struct cx18 *cx)
705 for (i = CX18_MAX_STREAMS - 1; i >= 0; i--) { 754 for (i = CX18_MAX_STREAMS - 1; i >= 0; i--) {
706 struct cx18_stream *s = &cx->streams[i]; 755 struct cx18_stream *s = &cx->streams[i];
707 756
708 if (s->video_dev == NULL && s->dvb.enabled == 0) 757 if (!cx18_stream_enabled(s))
709 continue; 758 continue;
710 if (test_bit(CX18_F_S_STREAMING, &s->s_flags)) 759 if (test_bit(CX18_F_S_STREAMING, &s->s_flags))
711 cx18_stop_v4l2_encode_stream(s, 0); 760 cx18_stop_v4l2_encode_stream(s, 0);
@@ -717,7 +766,7 @@ int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
717 struct cx18 *cx = s->cx; 766 struct cx18 *cx = s->cx;
718 unsigned long then; 767 unsigned long then;
719 768
720 if (s->video_dev == NULL && s->dvb.enabled == 0) 769 if (!cx18_stream_enabled(s))
721 return -EINVAL; 770 return -EINVAL;
722 771
723 /* This function assumes that you are allowed to stop the capture 772 /* This function assumes that you are allowed to stop the capture
@@ -762,6 +811,7 @@ int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
762 811
763 return 0; 812 return 0;
764} 813}
814EXPORT_SYMBOL(cx18_stop_v4l2_encode_stream);
765 815
766u32 cx18_find_handle(struct cx18 *cx) 816u32 cx18_find_handle(struct cx18 *cx)
767{ 817{
@@ -789,7 +839,7 @@ struct cx18_stream *cx18_handle_to_stream(struct cx18 *cx, u32 handle)
789 s = &cx->streams[i]; 839 s = &cx->streams[i];
790 if (s->handle != handle) 840 if (s->handle != handle)
791 continue; 841 continue;
792 if (s->video_dev || s->dvb.enabled) 842 if (cx18_stream_enabled(s))
793 return s; 843 return s;
794 } 844 }
795 return NULL; 845 return NULL;
diff --git a/drivers/media/video/cx18/cx18-streams.h b/drivers/media/video/cx18/cx18-streams.h
index 4a01db5e5a35..0bff0fa29763 100644
--- a/drivers/media/video/cx18/cx18-streams.h
+++ b/drivers/media/video/cx18/cx18-streams.h
@@ -28,6 +28,16 @@ int cx18_streams_setup(struct cx18 *cx);
28int cx18_streams_register(struct cx18 *cx); 28int cx18_streams_register(struct cx18 *cx);
29void cx18_streams_cleanup(struct cx18 *cx, int unregister); 29void cx18_streams_cleanup(struct cx18 *cx, int unregister);
30 30
31#define CX18_ENC_STREAM_TYPE_IDX_FW_MDL_MIN (3)
32void cx18_stream_rotate_idx_mdls(struct cx18 *cx);
33
34static inline bool cx18_stream_enabled(struct cx18_stream *s)
35{
36 return s->video_dev || s->dvb.enabled ||
37 (s->type == CX18_ENC_STREAM_TYPE_IDX &&
38 s->cx->stream_buffers[CX18_ENC_STREAM_TYPE_IDX] != 0);
39}
40
31/* Related to submission of mdls to firmware */ 41/* Related to submission of mdls to firmware */
32static inline void cx18_stream_load_fw_queue(struct cx18_stream *s) 42static inline void cx18_stream_load_fw_queue(struct cx18_stream *s)
33{ 43{
diff --git a/drivers/media/video/cx18/cx18-version.h b/drivers/media/video/cx18/cx18-version.h
index 9c0b5bb1b019..3e1aec4bcfde 100644
--- a/drivers/media/video/cx18/cx18-version.h
+++ b/drivers/media/video/cx18/cx18-version.h
@@ -24,7 +24,7 @@
24 24
25#define CX18_DRIVER_NAME "cx18" 25#define CX18_DRIVER_NAME "cx18"
26#define CX18_DRIVER_VERSION_MAJOR 1 26#define CX18_DRIVER_VERSION_MAJOR 1
27#define CX18_DRIVER_VERSION_MINOR 3 27#define CX18_DRIVER_VERSION_MINOR 4
28#define CX18_DRIVER_VERSION_PATCHLEVEL 0 28#define CX18_DRIVER_VERSION_PATCHLEVEL 0
29 29
30#define CX18_VERSION __stringify(CX18_DRIVER_VERSION_MAJOR) "." __stringify(CX18_DRIVER_VERSION_MINOR) "." __stringify(CX18_DRIVER_VERSION_PATCHLEVEL) 30#define CX18_VERSION __stringify(CX18_DRIVER_VERSION_MAJOR) "." __stringify(CX18_DRIVER_VERSION_MINOR) "." __stringify(CX18_DRIVER_VERSION_PATCHLEVEL)
diff --git a/drivers/media/video/cx18/cx23418.h b/drivers/media/video/cx18/cx23418.h
index 868806effdcf..2c00980acfcb 100644
--- a/drivers/media/video/cx18/cx23418.h
+++ b/drivers/media/video/cx18/cx23418.h
@@ -191,7 +191,8 @@
191#define CX18_CPU_SET_MEDIAN_CORING (CPU_CMD_MASK_CAPTURE | 0x000E) 191#define CX18_CPU_SET_MEDIAN_CORING (CPU_CMD_MASK_CAPTURE | 0x000E)
192 192
193/* Description: This command set the picture type mask for index file 193/* Description: This command set the picture type mask for index file
194 IN[0] - 0 = disable index file output 194 IN[0] - Task handle (ignored by firmware)
195 IN[1] - 0 = disable index file output
195 1 = output I picture 196 1 = output I picture
196 2 = P picture 197 2 = P picture
197 4 = B picture 198 4 = B picture
diff --git a/drivers/media/video/cx231xx/cx231xx-dvb.c b/drivers/media/video/cx231xx/cx231xx-dvb.c
index c5082a4e8ced..64e025e2bdf1 100644
--- a/drivers/media/video/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/video/cx231xx/cx231xx-dvb.c
@@ -464,9 +464,9 @@ static int dvb_init(struct cx231xx *dev)
464 /* define general-purpose callback pointer */ 464 /* define general-purpose callback pointer */
465 dvb->frontend->callback = cx231xx_tuner_callback; 465 dvb->frontend->callback = cx231xx_tuner_callback;
466 466
467 if (dvb_attach(xc5000_attach, dev->dvb->frontend, 467 if (!dvb_attach(xc5000_attach, dev->dvb->frontend,
468 &dev->i2c_bus[1].i2c_adap, 468 &dev->i2c_bus[1].i2c_adap,
469 &cnxt_rde250_tunerconfig) < 0) { 469 &cnxt_rde250_tunerconfig)) {
470 result = -EINVAL; 470 result = -EINVAL;
471 goto out_free; 471 goto out_free;
472 } 472 }
@@ -486,9 +486,9 @@ static int dvb_init(struct cx231xx *dev)
486 /* define general-purpose callback pointer */ 486 /* define general-purpose callback pointer */
487 dvb->frontend->callback = cx231xx_tuner_callback; 487 dvb->frontend->callback = cx231xx_tuner_callback;
488 488
489 if (dvb_attach(xc5000_attach, dev->dvb->frontend, 489 if (!dvb_attach(xc5000_attach, dev->dvb->frontend,
490 &dev->i2c_bus[1].i2c_adap, 490 &dev->i2c_bus[1].i2c_adap,
491 &cnxt_rde250_tunerconfig) < 0) { 491 &cnxt_rde250_tunerconfig)) {
492 result = -EINVAL; 492 result = -EINVAL;
493 goto out_free; 493 goto out_free;
494 } 494 }
diff --git a/drivers/media/video/cx231xx/cx231xx-input.c b/drivers/media/video/cx231xx/cx231xx-input.c
index 15826f98b688..c5771db3bfce 100644
--- a/drivers/media/video/cx231xx/cx231xx-input.c
+++ b/drivers/media/video/cx231xx/cx231xx-input.c
@@ -216,7 +216,7 @@ int cx231xx_ir_init(struct cx231xx *dev)
216 cx231xx_ir_start(ir); 216 cx231xx_ir_start(ir);
217 217
218 /* all done */ 218 /* all done */
219 err = ir_input_register(ir->input, dev->board.ir_codes); 219 err = ir_input_register(ir->input, dev->board.ir_codes, NULL);
220 if (err) 220 if (err)
221 goto err_out_stop; 221 goto err_out_stop;
222 222
diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c
index 88c0d2481118..2ab97ad7b6fb 100644
--- a/drivers/media/video/cx23885/cx23885-417.c
+++ b/drivers/media/video/cx23885/cx23885-417.c
@@ -681,7 +681,7 @@ static char *cmd_to_str(int cmd)
681 case CX2341X_ENC_SET_VIDEO_ID: 681 case CX2341X_ENC_SET_VIDEO_ID:
682 return "SET_VIDEO_ID"; 682 return "SET_VIDEO_ID";
683 case CX2341X_ENC_SET_PCR_ID: 683 case CX2341X_ENC_SET_PCR_ID:
684 return "SET_PCR_PID"; 684 return "SET_PCR_ID";
685 case CX2341X_ENC_SET_FRAME_RATE: 685 case CX2341X_ENC_SET_FRAME_RATE:
686 return "SET_FRAME_RATE"; 686 return "SET_FRAME_RATE";
687 case CX2341X_ENC_SET_FRAME_SIZE: 687 case CX2341X_ENC_SET_FRAME_SIZE:
@@ -693,7 +693,7 @@ static char *cmd_to_str(int cmd)
693 case CX2341X_ENC_SET_ASPECT_RATIO: 693 case CX2341X_ENC_SET_ASPECT_RATIO:
694 return "SET_ASPECT_RATIO"; 694 return "SET_ASPECT_RATIO";
695 case CX2341X_ENC_SET_DNR_FILTER_MODE: 695 case CX2341X_ENC_SET_DNR_FILTER_MODE:
696 return "SET_DNR_FILTER_PROPS"; 696 return "SET_DNR_FILTER_MODE";
697 case CX2341X_ENC_SET_DNR_FILTER_PROPS: 697 case CX2341X_ENC_SET_DNR_FILTER_PROPS:
698 return "SET_DNR_FILTER_PROPS"; 698 return "SET_DNR_FILTER_PROPS";
699 case CX2341X_ENC_SET_CORING_LEVELS: 699 case CX2341X_ENC_SET_CORING_LEVELS:
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index 1ec48169277d..d639186f645d 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -274,6 +274,31 @@ struct cx23885_board cx23885_boards[] = {
274 .portb = CX23885_MPEG_DVB, 274 .portb = CX23885_MPEG_DVB,
275 .portc = CX23885_MPEG_DVB, 275 .portc = CX23885_MPEG_DVB,
276 }, 276 },
277 [CX23885_BOARD_LEADTEK_WINFAST_PXTV1200] = {
278 .name = "LEADTEK WinFast PxTV1200",
279 .porta = CX23885_ANALOG_VIDEO,
280 .tuner_type = TUNER_XC2028,
281 .tuner_addr = 0x61,
282 .input = {{
283 .type = CX23885_VMUX_TELEVISION,
284 .vmux = CX25840_VIN2_CH1 |
285 CX25840_VIN5_CH2 |
286 CX25840_NONE0_CH3,
287 }, {
288 .type = CX23885_VMUX_COMPOSITE1,
289 .vmux = CX25840_COMPOSITE1,
290 }, {
291 .type = CX23885_VMUX_SVIDEO,
292 .vmux = CX25840_SVIDEO_LUMA3 |
293 CX25840_SVIDEO_CHROMA4,
294 }, {
295 .type = CX23885_VMUX_COMPONENT,
296 .vmux = CX25840_VIN7_CH1 |
297 CX25840_VIN6_CH2 |
298 CX25840_VIN8_CH3 |
299 CX25840_COMPONENT_ON,
300 } },
301 },
277}; 302};
278const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 303const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
279 304
@@ -417,6 +442,10 @@ struct cx23885_subid cx23885_subids[] = {
417 .subvendor = 0x14f1, 442 .subvendor = 0x14f1,
418 .subdevice = 0x8578, 443 .subdevice = 0x8578,
419 .card = CX23885_BOARD_MYGICA_X8558PRO, 444 .card = CX23885_BOARD_MYGICA_X8558PRO,
445 }, {
446 .subvendor = 0x107d,
447 .subdevice = 0x6f22,
448 .card = CX23885_BOARD_LEADTEK_WINFAST_PXTV1200,
420 }, 449 },
421}; 450};
422const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 451const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -617,6 +646,7 @@ int cx23885_tuner_callback(void *priv, int component, int command, int arg)
617 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H: 646 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
618 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F: 647 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
619 case CX23885_BOARD_COMPRO_VIDEOMATE_E800: 648 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
649 case CX23885_BOARD_LEADTEK_WINFAST_PXTV1200:
620 /* Tuner Reset Command */ 650 /* Tuner Reset Command */
621 bitmask = 0x04; 651 bitmask = 0x04;
622 break; 652 break;
@@ -769,6 +799,7 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
769 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H: 799 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
770 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F: 800 case CX23885_BOARD_COMPRO_VIDEOMATE_E650F:
771 case CX23885_BOARD_COMPRO_VIDEOMATE_E800: 801 case CX23885_BOARD_COMPRO_VIDEOMATE_E800:
802 case CX23885_BOARD_LEADTEK_WINFAST_PXTV1200:
772 /* GPIO-2 xc3028 tuner reset */ 803 /* GPIO-2 xc3028 tuner reset */
773 804
774 /* The following GPIO's are on the internal AVCore (cx25840) */ 805 /* The following GPIO's are on the internal AVCore (cx25840) */
@@ -1076,6 +1107,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1076 case CX23885_BOARD_MYGICA_X8506: 1107 case CX23885_BOARD_MYGICA_X8506:
1077 case CX23885_BOARD_MAGICPRO_PROHDTVE2: 1108 case CX23885_BOARD_MAGICPRO_PROHDTVE2:
1078 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1109 case CX23885_BOARD_HAUPPAUGE_HVR1290:
1110 case CX23885_BOARD_LEADTEK_WINFAST_PXTV1200:
1079 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1111 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1080 &dev->i2c_bus[2].i2c_adap, 1112 &dev->i2c_bus[2].i2c_adap,
1081 "cx25840", "cx25840", 0x88 >> 1, NULL); 1113 "cx25840", "cx25840", 0x88 >> 1, NULL);
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index e45d2df08138..939079d7bbb9 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -542,6 +542,9 @@ static struct atbm8830_config mygica_x8558pro_atbm8830_cfg1 = {
542 .osc_clk_freq = 30400, /* in kHz */ 542 .osc_clk_freq = 30400, /* in kHz */
543 .if_freq = 0, /* zero IF */ 543 .if_freq = 0, /* zero IF */
544 .zif_swap_iq = 1, 544 .zif_swap_iq = 1,
545 .agc_min = 0x2E,
546 .agc_max = 0xFF,
547 .agc_hold_loop = 0,
545}; 548};
546 549
547static struct max2165_config mygic_x8558pro_max2165_cfg1 = { 550static struct max2165_config mygic_x8558pro_max2165_cfg1 = {
@@ -558,6 +561,9 @@ static struct atbm8830_config mygica_x8558pro_atbm8830_cfg2 = {
558 .osc_clk_freq = 30400, /* in kHz */ 561 .osc_clk_freq = 30400, /* in kHz */
559 .if_freq = 0, /* zero IF */ 562 .if_freq = 0, /* zero IF */
560 .zif_swap_iq = 1, 563 .zif_swap_iq = 1,
564 .agc_min = 0x2E,
565 .agc_max = 0xFF,
566 .agc_hold_loop = 0,
561}; 567};
562 568
563static struct max2165_config mygic_x8558pro_max2165_cfg2 = { 569static struct max2165_config mygic_x8558pro_max2165_cfg2 = {
@@ -994,15 +1000,8 @@ static int dvb_register(struct cx23885_tsport *port)
994 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo); 1000 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
995 memcpy(port->frontends.adapter.proposed_mac, 1001 memcpy(port->frontends.adapter.proposed_mac,
996 cinfo.port[port->nr - 1].mac, 6); 1002 cinfo.port[port->nr - 1].mac, 6);
997 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=" 1003 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
998 "%02X:%02X:%02X:%02X:%02X:%02X\n", 1004 port->nr, port->frontends.adapter.proposed_mac);
999 port->nr,
1000 port->frontends.adapter.proposed_mac[0],
1001 port->frontends.adapter.proposed_mac[1],
1002 port->frontends.adapter.proposed_mac[2],
1003 port->frontends.adapter.proposed_mac[3],
1004 port->frontends.adapter.proposed_mac[4],
1005 port->frontends.adapter.proposed_mac[5]);
1006 1005
1007 netup_ci_init(port); 1006 netup_ci_init(port);
1008 break; 1007 break;
diff --git a/drivers/media/video/cx23885/cx23885-input.c b/drivers/media/video/cx23885/cx23885-input.c
index 768eec92ccf9..9c6620f86dca 100644
--- a/drivers/media/video/cx23885/cx23885-input.c
+++ b/drivers/media/video/cx23885/cx23885-input.c
@@ -397,7 +397,7 @@ int cx23885_input_init(struct cx23885_dev *dev)
397 dev->ir_input = ir; 397 dev->ir_input = ir;
398 cx23885_input_ir_start(dev); 398 cx23885_input_ir_start(dev);
399 399
400 ret = ir_input_register(ir->dev, ir_codes); 400 ret = ir_input_register(ir->dev, ir_codes, NULL);
401 if (ret) 401 if (ret)
402 goto err_out_stop; 402 goto err_out_stop;
403 403
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index 8934d61cf660..2d3ac8b83dc3 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -36,6 +36,7 @@
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include "cx23885-ioctl.h" 38#include "cx23885-ioctl.h"
39#include "tuner-xc2028.h"
39 40
40MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards"); 41MODULE_DESCRIPTION("v4l2 driver module for cx23885 based TV cards");
41MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>"); 42MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
@@ -1505,6 +1506,18 @@ int cx23885_video_register(struct cx23885_dev *dev)
1505 tun_setup.tuner_callback = cx23885_tuner_callback; 1506 tun_setup.tuner_callback = cx23885_tuner_callback;
1506 1507
1507 v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup); 1508 v4l2_subdev_call(sd, tuner, s_type_addr, &tun_setup);
1509
1510 if (dev->board == CX23885_BOARD_LEADTEK_WINFAST_PXTV1200) {
1511 struct xc2028_ctrl ctrl = {
1512 .fname = XC2028_DEFAULT_FIRMWARE,
1513 .max_len = 64
1514 };
1515 struct v4l2_priv_tun_config cfg = {
1516 .tuner = dev->tuner_type,
1517 .priv = &ctrl
1518 };
1519 v4l2_subdev_call(sd, tuner, s_config, &cfg);
1520 }
1508 } 1521 }
1509 } 1522 }
1510 1523
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index 08b3f6b136a0..0e3a98d243c5 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -81,6 +81,7 @@
81#define CX23885_BOARD_COMPRO_VIDEOMATE_E800 25 81#define CX23885_BOARD_COMPRO_VIDEOMATE_E800 25
82#define CX23885_BOARD_HAUPPAUGE_HVR1290 26 82#define CX23885_BOARD_HAUPPAUGE_HVR1290 26
83#define CX23885_BOARD_MYGICA_X8558PRO 27 83#define CX23885_BOARD_MYGICA_X8558PRO 27
84#define CX23885_BOARD_LEADTEK_WINFAST_PXTV1200 28
84 85
85#define GPIO_0 0x00000001 86#define GPIO_0 0x00000001
86#define GPIO_1 0x00000002 87#define GPIO_1 0x00000002
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 385ecd58f1c0..f2461cd3de5a 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -734,10 +734,8 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
734 v4l_dbg(1, cx25840_debug, client, "vid_input 0x%x\n", 734 v4l_dbg(1, cx25840_debug, client, "vid_input 0x%x\n",
735 vid_input); 735 vid_input);
736 reg = vid_input & 0xff; 736 reg = vid_input & 0xff;
737 if ((vid_input & CX25840_SVIDEO_ON) == CX25840_SVIDEO_ON) 737 is_composite = !is_component &&
738 is_composite = 0; 738 ((vid_input & CX25840_SVIDEO_ON) != CX25840_SVIDEO_ON);
739 else if ((vid_input & CX25840_COMPONENT_ON) == 0)
740 is_composite = 1;
741 739
742 v4l_dbg(1, cx25840_debug, client, "mux cfg 0x%x comp=%d\n", 740 v4l_dbg(1, cx25840_debug, client, "mux cfg 0x%x comp=%d\n",
743 reg, is_composite); 741 reg, is_composite);
@@ -1347,30 +1345,59 @@ static int cx25840_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1347} 1345}
1348#endif 1346#endif
1349 1347
1348static int cx25840_s_audio_stream(struct v4l2_subdev *sd, int enable)
1349{
1350 struct cx25840_state *state = to_state(sd);
1351 struct i2c_client *client = v4l2_get_subdevdata(sd);
1352 u8 v;
1353
1354 if (is_cx2583x(state) || is_cx2388x(state) || is_cx231xx(state))
1355 return 0;
1356
1357 v4l_dbg(1, cx25840_debug, client, "%s audio output\n",
1358 enable ? "enable" : "disable");
1359
1360 if (enable) {
1361 v = cx25840_read(client, 0x115) | 0x80;
1362 cx25840_write(client, 0x115, v);
1363 v = cx25840_read(client, 0x116) | 0x03;
1364 cx25840_write(client, 0x116, v);
1365 } else {
1366 v = cx25840_read(client, 0x115) & ~(0x80);
1367 cx25840_write(client, 0x115, v);
1368 v = cx25840_read(client, 0x116) & ~(0x03);
1369 cx25840_write(client, 0x116, v);
1370 }
1371 return 0;
1372}
1373
1350static int cx25840_s_stream(struct v4l2_subdev *sd, int enable) 1374static int cx25840_s_stream(struct v4l2_subdev *sd, int enable)
1351{ 1375{
1352 struct cx25840_state *state = to_state(sd); 1376 struct cx25840_state *state = to_state(sd);
1353 struct i2c_client *client = v4l2_get_subdevdata(sd); 1377 struct i2c_client *client = v4l2_get_subdevdata(sd);
1378 u8 v;
1354 1379
1355 v4l_dbg(1, cx25840_debug, client, "%s output\n", 1380 v4l_dbg(1, cx25840_debug, client, "%s video output\n",
1356 enable ? "enable" : "disable"); 1381 enable ? "enable" : "disable");
1357 if (enable) { 1382 if (enable) {
1358 if (is_cx2388x(state) || is_cx231xx(state)) { 1383 if (is_cx2388x(state) || is_cx231xx(state)) {
1359 u8 v = (cx25840_read(client, 0x421) | 0x0b); 1384 v = cx25840_read(client, 0x421) | 0x0b;
1360 cx25840_write(client, 0x421, v); 1385 cx25840_write(client, 0x421, v);
1361 } else { 1386 } else {
1362 cx25840_write(client, 0x115, 1387 v = cx25840_read(client, 0x115) | 0x0c;
1363 is_cx2583x(state) ? 0x0c : 0x8c); 1388 cx25840_write(client, 0x115, v);
1364 cx25840_write(client, 0x116, 1389 v = cx25840_read(client, 0x116) | 0x04;
1365 is_cx2583x(state) ? 0x04 : 0x07); 1390 cx25840_write(client, 0x116, v);
1366 } 1391 }
1367 } else { 1392 } else {
1368 if (is_cx2388x(state) || is_cx231xx(state)) { 1393 if (is_cx2388x(state) || is_cx231xx(state)) {
1369 u8 v = cx25840_read(client, 0x421) & ~(0x0b); 1394 v = cx25840_read(client, 0x421) & ~(0x0b);
1370 cx25840_write(client, 0x421, v); 1395 cx25840_write(client, 0x421, v);
1371 } else { 1396 } else {
1372 cx25840_write(client, 0x115, 0x00); 1397 v = cx25840_read(client, 0x115) & ~(0x0c);
1373 cx25840_write(client, 0x116, 0x00); 1398 cx25840_write(client, 0x115, v);
1399 v = cx25840_read(client, 0x116) & ~(0x04);
1400 cx25840_write(client, 0x116, v);
1374 } 1401 }
1375 } 1402 }
1376 return 0; 1403 return 0;
@@ -1601,6 +1628,7 @@ static const struct v4l2_subdev_tuner_ops cx25840_tuner_ops = {
1601static const struct v4l2_subdev_audio_ops cx25840_audio_ops = { 1628static const struct v4l2_subdev_audio_ops cx25840_audio_ops = {
1602 .s_clock_freq = cx25840_s_clock_freq, 1629 .s_clock_freq = cx25840_s_clock_freq,
1603 .s_routing = cx25840_s_audio_routing, 1630 .s_routing = cx25840_s_audio_routing,
1631 .s_stream = cx25840_s_audio_stream,
1604}; 1632};
1605 1633
1606static const struct v4l2_subdev_video_ops cx25840_video_ops = { 1634static const struct v4l2_subdev_video_ops cx25840_video_ops = {
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 5a67445dd6ed..64b350df78e3 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -583,16 +583,18 @@ static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol,
583{ 583{
584 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 584 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
585 struct cx88_core *core=chip->core; 585 struct cx88_core *core=chip->core;
586 int v, b; 586 int left, right, v, b;
587 int changed = 0; 587 int changed = 0;
588 u32 old; 588 u32 old;
589 589
590 b = value->value.integer.value[1] - value->value.integer.value[0]; 590 left = value->value.integer.value[0] & 0x3f;
591 right = value->value.integer.value[1] & 0x3f;
592 b = right - left;
591 if (b < 0) { 593 if (b < 0) {
592 v = 0x3f - value->value.integer.value[0]; 594 v = 0x3f - left;
593 b = (-b) | 0x40; 595 b = (-b) | 0x40;
594 } else { 596 } else {
595 v = 0x3f - value->value.integer.value[1]; 597 v = 0x3f - right;
596 } 598 }
597 /* Do we really know this will always be called with IRQs on? */ 599 /* Do we really know this will always be called with IRQs on? */
598 spin_lock_irq(&chip->reg_lock); 600 spin_lock_irq(&chip->reg_lock);
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index d844f2aaa01d..eaf0ee7de832 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1466,6 +1466,18 @@ static const struct cx88_board cx88_boards[] = {
1466 .audioroute = 8, 1466 .audioroute = 8,
1467 }, 1467 },
1468 }, 1468 },
1469 [CX88_BOARD_SAMSUNG_SMT_7020] = {
1470 .name = "Samsung SMT 7020 DVB-S",
1471 .tuner_type = TUNER_ABSENT,
1472 .radio_type = UNSET,
1473 .tuner_addr = ADDR_UNSET,
1474 .radio_addr = ADDR_UNSET,
1475 .input = { {
1476 .type = CX88_VMUX_DVB,
1477 .vmux = 0,
1478 } },
1479 .mpeg = CX88_MPEG_DVB,
1480 },
1469 [CX88_BOARD_ADSTECH_PTV_390] = { 1481 [CX88_BOARD_ADSTECH_PTV_390] = {
1470 .name = "ADS Tech Instant Video PCI", 1482 .name = "ADS Tech Instant Video PCI",
1471 .tuner_type = TUNER_ABSENT, 1483 .tuner_type = TUNER_ABSENT,
@@ -2355,6 +2367,14 @@ static const struct cx88_subid cx88_subids[] = {
2355 .subvendor = 0x0070, 2367 .subvendor = 0x0070,
2356 .subdevice = 0x1404, 2368 .subdevice = 0x1404,
2357 .card = CX88_BOARD_HAUPPAUGE_HVR3000, 2369 .card = CX88_BOARD_HAUPPAUGE_HVR3000,
2370 }, {
2371 .subvendor = 0x18ac,
2372 .subdevice = 0xdc00,
2373 .card = CX88_BOARD_SAMSUNG_SMT_7020,
2374 }, {
2375 .subvendor = 0x18ac,
2376 .subdevice = 0xdccd,
2377 .card = CX88_BOARD_SAMSUNG_SMT_7020,
2358 },{ 2378 },{
2359 .subvendor = 0x1461, 2379 .subvendor = 0x1461,
2360 .subdevice = 0xc111, /* AverMedia M150-D */ 2380 .subdevice = 0xc111, /* AverMedia M150-D */
@@ -2633,6 +2653,9 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
2633 case 98559: /* WinTV-HVR1100LP (Video no IR, Retail - Low Profile) */ 2653 case 98559: /* WinTV-HVR1100LP (Video no IR, Retail - Low Profile) */
2634 /* known */ 2654 /* known */
2635 break; 2655 break;
2656 case CX88_BOARD_SAMSUNG_SMT_7020:
2657 cx_set(MO_GP0_IO, 0x008989FF);
2658 break;
2636 default: 2659 default:
2637 warn_printk(core, "warning: unknown hauppauge model #%d\n", 2660 warn_printk(core, "warning: unknown hauppauge model #%d\n",
2638 tv.model); 2661 tv.model);
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index b14296923250..94ab862f0219 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -674,6 +674,194 @@ static int cx8802_alloc_frontends(struct cx8802_dev *dev)
674 return 0; 674 return 0;
675} 675}
676 676
677
678
679static u8 samsung_smt_7020_inittab[] = {
680 0x01, 0x15,
681 0x02, 0x00,
682 0x03, 0x00,
683 0x04, 0x7D,
684 0x05, 0x0F,
685 0x06, 0x02,
686 0x07, 0x00,
687 0x08, 0x60,
688
689 0x0A, 0xC2,
690 0x0B, 0x00,
691 0x0C, 0x01,
692 0x0D, 0x81,
693 0x0E, 0x44,
694 0x0F, 0x09,
695 0x10, 0x3C,
696 0x11, 0x84,
697 0x12, 0xDA,
698 0x13, 0x99,
699 0x14, 0x8D,
700 0x15, 0xCE,
701 0x16, 0xE8,
702 0x17, 0x43,
703 0x18, 0x1C,
704 0x19, 0x1B,
705 0x1A, 0x1D,
706
707 0x1C, 0x12,
708 0x1D, 0x00,
709 0x1E, 0x00,
710 0x1F, 0x00,
711 0x20, 0x00,
712 0x21, 0x00,
713 0x22, 0x00,
714 0x23, 0x00,
715
716 0x28, 0x02,
717 0x29, 0x28,
718 0x2A, 0x14,
719 0x2B, 0x0F,
720 0x2C, 0x09,
721 0x2D, 0x05,
722
723 0x31, 0x1F,
724 0x32, 0x19,
725 0x33, 0xFC,
726 0x34, 0x13,
727 0xff, 0xff,
728};
729
730
731static int samsung_smt_7020_tuner_set_params(struct dvb_frontend *fe,
732 struct dvb_frontend_parameters *params)
733{
734 struct cx8802_dev *dev = fe->dvb->priv;
735 u8 buf[4];
736 u32 div;
737 struct i2c_msg msg = {
738 .addr = 0x61,
739 .flags = 0,
740 .buf = buf,
741 .len = sizeof(buf) };
742
743 div = params->frequency / 125;
744
745 buf[0] = (div >> 8) & 0x7f;
746 buf[1] = div & 0xff;
747 buf[2] = 0x84; /* 0xC4 */
748 buf[3] = 0x00;
749
750 if (params->frequency < 1500000)
751 buf[3] |= 0x10;
752
753 if (fe->ops.i2c_gate_ctrl)
754 fe->ops.i2c_gate_ctrl(fe, 1);
755
756 if (i2c_transfer(&dev->core->i2c_adap, &msg, 1) != 1)
757 return -EIO;
758
759 return 0;
760}
761
762static int samsung_smt_7020_set_tone(struct dvb_frontend *fe,
763 fe_sec_tone_mode_t tone)
764{
765 struct cx8802_dev *dev = fe->dvb->priv;
766 struct cx88_core *core = dev->core;
767
768 cx_set(MO_GP0_IO, 0x0800);
769
770 switch (tone) {
771 case SEC_TONE_ON:
772 cx_set(MO_GP0_IO, 0x08);
773 break;
774 case SEC_TONE_OFF:
775 cx_clear(MO_GP0_IO, 0x08);
776 break;
777 default:
778 return -EINVAL;
779 }
780
781 return 0;
782}
783
784static int samsung_smt_7020_set_voltage(struct dvb_frontend *fe,
785 fe_sec_voltage_t voltage)
786{
787 struct cx8802_dev *dev = fe->dvb->priv;
788 struct cx88_core *core = dev->core;
789
790 u8 data;
791 struct i2c_msg msg = {
792 .addr = 8,
793 .flags = 0,
794 .buf = &data,
795 .len = sizeof(data) };
796
797 cx_set(MO_GP0_IO, 0x8000);
798
799 switch (voltage) {
800 case SEC_VOLTAGE_OFF:
801 break;
802 case SEC_VOLTAGE_13:
803 data = ISL6421_EN1 | ISL6421_LLC1;
804 cx_clear(MO_GP0_IO, 0x80);
805 break;
806 case SEC_VOLTAGE_18:
807 data = ISL6421_EN1 | ISL6421_LLC1 | ISL6421_VSEL1;
808 cx_clear(MO_GP0_IO, 0x80);
809 break;
810 default:
811 return -EINVAL;
812 };
813
814 return (i2c_transfer(&dev->core->i2c_adap, &msg, 1) == 1) ? 0 : -EIO;
815}
816
817static int samsung_smt_7020_stv0299_set_symbol_rate(struct dvb_frontend *fe,
818 u32 srate, u32 ratio)
819{
820 u8 aclk = 0;
821 u8 bclk = 0;
822
823 if (srate < 1500000) {
824 aclk = 0xb7;
825 bclk = 0x47;
826 } else if (srate < 3000000) {
827 aclk = 0xb7;
828 bclk = 0x4b;
829 } else if (srate < 7000000) {
830 aclk = 0xb7;
831 bclk = 0x4f;
832 } else if (srate < 14000000) {
833 aclk = 0xb7;
834 bclk = 0x53;
835 } else if (srate < 30000000) {
836 aclk = 0xb6;
837 bclk = 0x53;
838 } else if (srate < 45000000) {
839 aclk = 0xb4;
840 bclk = 0x51;
841 }
842
843 stv0299_writereg(fe, 0x13, aclk);
844 stv0299_writereg(fe, 0x14, bclk);
845 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
846 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
847 stv0299_writereg(fe, 0x21, ratio & 0xf0);
848
849 return 0;
850}
851
852
853static struct stv0299_config samsung_stv0299_config = {
854 .demod_address = 0x68,
855 .inittab = samsung_smt_7020_inittab,
856 .mclk = 88000000UL,
857 .invert = 0,
858 .skip_reinit = 0,
859 .lock_output = STV0299_LOCKOUTPUT_LK,
860 .volt13_op0_op1 = STV0299_VOLT13_OP1,
861 .min_delay_ms = 100,
862 .set_symbol_rate = samsung_smt_7020_stv0299_set_symbol_rate,
863};
864
677static int dvb_register(struct cx8802_dev *dev) 865static int dvb_register(struct cx8802_dev *dev)
678{ 866{
679 struct cx88_core *core = dev->core; 867 struct cx88_core *core = dev->core;
@@ -1203,6 +1391,32 @@ static int dvb_register(struct cx8802_dev *dev)
1203 } 1391 }
1204 break; 1392 break;
1205 } 1393 }
1394 case CX88_BOARD_SAMSUNG_SMT_7020:
1395 dev->ts_gen_cntrl = 0x08;
1396
1397 cx_set(MO_GP0_IO, 0x0101);
1398
1399 cx_clear(MO_GP0_IO, 0x01);
1400 mdelay(100);
1401 cx_set(MO_GP0_IO, 0x01);
1402 mdelay(200);
1403
1404 fe0->dvb.frontend = dvb_attach(stv0299_attach,
1405 &samsung_stv0299_config,
1406 &dev->core->i2c_adap);
1407 if (fe0->dvb.frontend) {
1408 fe0->dvb.frontend->ops.tuner_ops.set_params =
1409 samsung_smt_7020_tuner_set_params;
1410 fe0->dvb.frontend->tuner_priv =
1411 &dev->core->i2c_adap;
1412 fe0->dvb.frontend->ops.set_voltage =
1413 samsung_smt_7020_set_voltage;
1414 fe0->dvb.frontend->ops.set_tone =
1415 samsung_smt_7020_set_tone;
1416 }
1417
1418 break;
1419
1206 default: 1420 default:
1207 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n", 1421 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
1208 core->name); 1422 core->name);
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index f9fda18b410c..de180d4d5a21 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -192,7 +192,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
192 struct cx88_IR *ir; 192 struct cx88_IR *ir;
193 struct input_dev *input_dev; 193 struct input_dev *input_dev;
194 struct ir_scancode_table *ir_codes = NULL; 194 struct ir_scancode_table *ir_codes = NULL;
195 int ir_type = IR_TYPE_OTHER; 195 u64 ir_type = IR_TYPE_OTHER;
196 int err = -ENOMEM; 196 int err = -ENOMEM;
197 197
198 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 198 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
@@ -383,7 +383,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
383 cx88_ir_start(core, ir); 383 cx88_ir_start(core, ir);
384 384
385 /* all done */ 385 /* all done */
386 err = ir_input_register(ir->input, ir_codes); 386 err = ir_input_register(ir->input, ir_codes, NULL);
387 if (err) 387 if (err)
388 goto err_out_stop; 388 goto err_out_stop;
389 389
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index bb5104893411..338af77f7f01 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -110,6 +110,9 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
110 case CX88_BOARD_PCHDTV_HD5500: 110 case CX88_BOARD_PCHDTV_HD5500:
111 cx_write(TS_SOP_STAT, 1<<13); 111 cx_write(TS_SOP_STAT, 1<<13);
112 break; 112 break;
113 case CX88_BOARD_SAMSUNG_SMT_7020:
114 cx_write(TS_SOP_STAT, 0x00);
115 break;
113 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 116 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
114 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1: 117 case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
115 cx_write(MO_PINMUX_IO, 0x88); /* Enable MPEG parallel IO and video signal pins */ 118 cx_write(MO_PINMUX_IO, 0x88); /* Enable MPEG parallel IO and video signal pins */
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index b1499bf604ea..48b6c04fb497 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -239,6 +239,7 @@ extern struct sram_channel cx88_sram_channels[];
239#define CX88_BOARD_WINFAST_DTV1800H 81 239#define CX88_BOARD_WINFAST_DTV1800H 81
240#define CX88_BOARD_WINFAST_DTV2000H_J 82 240#define CX88_BOARD_WINFAST_DTV2000H_J 82
241#define CX88_BOARD_PROF_7301 83 241#define CX88_BOARD_PROF_7301 83
242#define CX88_BOARD_SAMSUNG_SMT_7020 84
242 243
243enum cx88_itype { 244enum cx88_itype {
244 CX88_VMUX_COMPOSITE1 = 1, 245 CX88_VMUX_COMPOSITE1 = 1,
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index ee43876adb06..9b413a35e048 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -913,6 +913,8 @@ static void __exit dabusb_cleanup (void)
913MODULE_AUTHOR( DRIVER_AUTHOR ); 913MODULE_AUTHOR( DRIVER_AUTHOR );
914MODULE_DESCRIPTION( DRIVER_DESC ); 914MODULE_DESCRIPTION( DRIVER_DESC );
915MODULE_LICENSE("GPL"); 915MODULE_LICENSE("GPL");
916MODULE_FIRMWARE("dabusb/firmware.fw");
917MODULE_FIRMWARE("dabusb/bitstream.bin");
916 918
917module_param(buffers, int, 0); 919module_param(buffers, int, 0);
918MODULE_PARM_DESC (buffers, "Number of buffers (default=256)"); 920MODULE_PARM_DESC (buffers, "Number of buffers (default=256)");
diff --git a/drivers/media/video/davinci/Makefile b/drivers/media/video/davinci/Makefile
index 1a8b8f3f182e..a37955745aaa 100644
--- a/drivers/media/video/davinci/Makefile
+++ b/drivers/media/video/davinci/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_VIDEO_VPSS_SYSTEM) += vpss.o
15obj-$(CONFIG_VIDEO_VPFE_CAPTURE) += vpfe_capture.o 15obj-$(CONFIG_VIDEO_VPFE_CAPTURE) += vpfe_capture.o
16obj-$(CONFIG_VIDEO_DM6446_CCDC) += dm644x_ccdc.o 16obj-$(CONFIG_VIDEO_DM6446_CCDC) += dm644x_ccdc.o
17obj-$(CONFIG_VIDEO_DM355_CCDC) += dm355_ccdc.o 17obj-$(CONFIG_VIDEO_DM355_CCDC) += dm355_ccdc.o
18obj-$(CONFIG_VIDEO_ISIF) += isif.o
diff --git a/drivers/media/video/davinci/dm355_ccdc.c b/drivers/media/video/davinci/dm355_ccdc.c
index 314390016370..c29ac88ffd78 100644
--- a/drivers/media/video/davinci/dm355_ccdc.c
+++ b/drivers/media/video/davinci/dm355_ccdc.c
@@ -37,8 +37,12 @@
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/videodev2.h> 39#include <linux/videodev2.h>
40#include <linux/clk.h>
41#include <linux/err.h>
42
40#include <media/davinci/dm355_ccdc.h> 43#include <media/davinci/dm355_ccdc.h>
41#include <media/davinci/vpss.h> 44#include <media/davinci/vpss.h>
45
42#include "dm355_ccdc_regs.h" 46#include "dm355_ccdc_regs.h"
43#include "ccdc_hw_device.h" 47#include "ccdc_hw_device.h"
44 48
@@ -46,67 +50,75 @@ MODULE_LICENSE("GPL");
46MODULE_DESCRIPTION("CCDC Driver for DM355"); 50MODULE_DESCRIPTION("CCDC Driver for DM355");
47MODULE_AUTHOR("Texas Instruments"); 51MODULE_AUTHOR("Texas Instruments");
48 52
49static struct device *dev; 53static struct ccdc_oper_config {
50 54 struct device *dev;
51/* Object for CCDC raw mode */ 55 /* CCDC interface type */
52static struct ccdc_params_raw ccdc_hw_params_raw = { 56 enum vpfe_hw_if_type if_type;
53 .pix_fmt = CCDC_PIXFMT_RAW, 57 /* Raw Bayer configuration */
54 .frm_fmt = CCDC_FRMFMT_PROGRESSIVE, 58 struct ccdc_params_raw bayer;
55 .win = CCDC_WIN_VGA, 59 /* YCbCr configuration */
56 .fid_pol = VPFE_PINPOL_POSITIVE, 60 struct ccdc_params_ycbcr ycbcr;
57 .vd_pol = VPFE_PINPOL_POSITIVE, 61 /* Master clock */
58 .hd_pol = VPFE_PINPOL_POSITIVE, 62 struct clk *mclk;
59 .gain = { 63 /* slave clock */
60 .r_ye = 256, 64 struct clk *sclk;
61 .gb_g = 256, 65 /* ccdc base address */
62 .gr_cy = 256, 66 void __iomem *base_addr;
63 .b_mg = 256 67} ccdc_cfg = {
64 }, 68 /* Raw configurations */
65 .config_params = { 69 .bayer = {
66 .datasft = 2, 70 .pix_fmt = CCDC_PIXFMT_RAW,
67 .data_sz = CCDC_DATA_10BITS, 71 .frm_fmt = CCDC_FRMFMT_PROGRESSIVE,
68 .mfilt1 = CCDC_NO_MEDIAN_FILTER1, 72 .win = CCDC_WIN_VGA,
69 .mfilt2 = CCDC_NO_MEDIAN_FILTER2, 73 .fid_pol = VPFE_PINPOL_POSITIVE,
70 .alaw = { 74 .vd_pol = VPFE_PINPOL_POSITIVE,
71 .gama_wd = 2, 75 .hd_pol = VPFE_PINPOL_POSITIVE,
76 .gain = {
77 .r_ye = 256,
78 .gb_g = 256,
79 .gr_cy = 256,
80 .b_mg = 256
72 }, 81 },
73 .blk_clamp = { 82 .config_params = {
74 .sample_pixel = 1, 83 .datasft = 2,
75 .dc_sub = 25 84 .mfilt1 = CCDC_NO_MEDIAN_FILTER1,
76 }, 85 .mfilt2 = CCDC_NO_MEDIAN_FILTER2,
77 .col_pat_field0 = { 86 .alaw = {
78 .olop = CCDC_GREEN_BLUE, 87 .gama_wd = 2,
79 .olep = CCDC_BLUE, 88 },
80 .elop = CCDC_RED, 89 .blk_clamp = {
81 .elep = CCDC_GREEN_RED 90 .sample_pixel = 1,
82 }, 91 .dc_sub = 25
83 .col_pat_field1 = { 92 },
84 .olop = CCDC_GREEN_BLUE, 93 .col_pat_field0 = {
85 .olep = CCDC_BLUE, 94 .olop = CCDC_GREEN_BLUE,
86 .elop = CCDC_RED, 95 .olep = CCDC_BLUE,
87 .elep = CCDC_GREEN_RED 96 .elop = CCDC_RED,
97 .elep = CCDC_GREEN_RED
98 },
99 .col_pat_field1 = {
100 .olop = CCDC_GREEN_BLUE,
101 .olep = CCDC_BLUE,
102 .elop = CCDC_RED,
103 .elep = CCDC_GREEN_RED
104 },
88 }, 105 },
89 }, 106 },
107 /* YCbCr configuration */
108 .ycbcr = {
109 .win = CCDC_WIN_PAL,
110 .pix_fmt = CCDC_PIXFMT_YCBCR_8BIT,
111 .frm_fmt = CCDC_FRMFMT_INTERLACED,
112 .fid_pol = VPFE_PINPOL_POSITIVE,
113 .vd_pol = VPFE_PINPOL_POSITIVE,
114 .hd_pol = VPFE_PINPOL_POSITIVE,
115 .bt656_enable = 1,
116 .pix_order = CCDC_PIXORDER_CBYCRY,
117 .buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED
118 },
90}; 119};
91 120
92 121
93/* Object for CCDC ycbcr mode */
94static struct ccdc_params_ycbcr ccdc_hw_params_ycbcr = {
95 .win = CCDC_WIN_PAL,
96 .pix_fmt = CCDC_PIXFMT_YCBCR_8BIT,
97 .frm_fmt = CCDC_FRMFMT_INTERLACED,
98 .fid_pol = VPFE_PINPOL_POSITIVE,
99 .vd_pol = VPFE_PINPOL_POSITIVE,
100 .hd_pol = VPFE_PINPOL_POSITIVE,
101 .bt656_enable = 1,
102 .pix_order = CCDC_PIXORDER_CBYCRY,
103 .buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED
104};
105
106static enum vpfe_hw_if_type ccdc_if_type;
107static void *__iomem ccdc_base_addr;
108static int ccdc_addr_size;
109
110/* Raw Bayer formats */ 122/* Raw Bayer formats */
111static u32 ccdc_raw_bayer_pix_formats[] = 123static u32 ccdc_raw_bayer_pix_formats[] =
112 {V4L2_PIX_FMT_SBGGR8, V4L2_PIX_FMT_SBGGR16}; 124 {V4L2_PIX_FMT_SBGGR8, V4L2_PIX_FMT_SBGGR16};
@@ -118,18 +130,12 @@ static u32 ccdc_raw_yuv_pix_formats[] =
118/* register access routines */ 130/* register access routines */
119static inline u32 regr(u32 offset) 131static inline u32 regr(u32 offset)
120{ 132{
121 return __raw_readl(ccdc_base_addr + offset); 133 return __raw_readl(ccdc_cfg.base_addr + offset);
122} 134}
123 135
124static inline void regw(u32 val, u32 offset) 136static inline void regw(u32 val, u32 offset)
125{ 137{
126 __raw_writel(val, ccdc_base_addr + offset); 138 __raw_writel(val, ccdc_cfg.base_addr + offset);
127}
128
129static void ccdc_set_ccdc_base(void *addr, int size)
130{
131 ccdc_base_addr = addr;
132 ccdc_addr_size = size;
133} 139}
134 140
135static void ccdc_enable(int en) 141static void ccdc_enable(int en)
@@ -153,12 +159,12 @@ static void ccdc_enable_output_to_sdram(int en)
153static void ccdc_config_gain_offset(void) 159static void ccdc_config_gain_offset(void)
154{ 160{
155 /* configure gain */ 161 /* configure gain */
156 regw(ccdc_hw_params_raw.gain.r_ye, RYEGAIN); 162 regw(ccdc_cfg.bayer.gain.r_ye, RYEGAIN);
157 regw(ccdc_hw_params_raw.gain.gr_cy, GRCYGAIN); 163 regw(ccdc_cfg.bayer.gain.gr_cy, GRCYGAIN);
158 regw(ccdc_hw_params_raw.gain.gb_g, GBGGAIN); 164 regw(ccdc_cfg.bayer.gain.gb_g, GBGGAIN);
159 regw(ccdc_hw_params_raw.gain.b_mg, BMGGAIN); 165 regw(ccdc_cfg.bayer.gain.b_mg, BMGGAIN);
160 /* configure offset */ 166 /* configure offset */
161 regw(ccdc_hw_params_raw.ccdc_offset, OFFSET); 167 regw(ccdc_cfg.bayer.ccdc_offset, OFFSET);
162} 168}
163 169
164/* 170/*
@@ -169,7 +175,7 @@ static int ccdc_restore_defaults(void)
169{ 175{
170 int i; 176 int i;
171 177
172 dev_dbg(dev, "\nstarting ccdc_restore_defaults..."); 178 dev_dbg(ccdc_cfg.dev, "\nstarting ccdc_restore_defaults...");
173 /* set all registers to zero */ 179 /* set all registers to zero */
174 for (i = 0; i <= CCDC_REG_LAST; i += 4) 180 for (i = 0; i <= CCDC_REG_LAST; i += 4)
175 regw(0, i); 181 regw(0, i);
@@ -180,30 +186,29 @@ static int ccdc_restore_defaults(void)
180 regw(CULH_DEFAULT, CULH); 186 regw(CULH_DEFAULT, CULH);
181 regw(CULV_DEFAULT, CULV); 187 regw(CULV_DEFAULT, CULV);
182 /* Set default Gain and Offset */ 188 /* Set default Gain and Offset */
183 ccdc_hw_params_raw.gain.r_ye = GAIN_DEFAULT; 189 ccdc_cfg.bayer.gain.r_ye = GAIN_DEFAULT;
184 ccdc_hw_params_raw.gain.gb_g = GAIN_DEFAULT; 190 ccdc_cfg.bayer.gain.gb_g = GAIN_DEFAULT;
185 ccdc_hw_params_raw.gain.gr_cy = GAIN_DEFAULT; 191 ccdc_cfg.bayer.gain.gr_cy = GAIN_DEFAULT;
186 ccdc_hw_params_raw.gain.b_mg = GAIN_DEFAULT; 192 ccdc_cfg.bayer.gain.b_mg = GAIN_DEFAULT;
187 ccdc_config_gain_offset(); 193 ccdc_config_gain_offset();
188 regw(OUTCLIP_DEFAULT, OUTCLIP); 194 regw(OUTCLIP_DEFAULT, OUTCLIP);
189 regw(LSCCFG2_DEFAULT, LSCCFG2); 195 regw(LSCCFG2_DEFAULT, LSCCFG2);
190 /* select ccdc input */ 196 /* select ccdc input */
191 if (vpss_select_ccdc_source(VPSS_CCDCIN)) { 197 if (vpss_select_ccdc_source(VPSS_CCDCIN)) {
192 dev_dbg(dev, "\ncouldn't select ccdc input source"); 198 dev_dbg(ccdc_cfg.dev, "\ncouldn't select ccdc input source");
193 return -EFAULT; 199 return -EFAULT;
194 } 200 }
195 /* select ccdc clock */ 201 /* select ccdc clock */
196 if (vpss_enable_clock(VPSS_CCDC_CLOCK, 1) < 0) { 202 if (vpss_enable_clock(VPSS_CCDC_CLOCK, 1) < 0) {
197 dev_dbg(dev, "\ncouldn't enable ccdc clock"); 203 dev_dbg(ccdc_cfg.dev, "\ncouldn't enable ccdc clock");
198 return -EFAULT; 204 return -EFAULT;
199 } 205 }
200 dev_dbg(dev, "\nEnd of ccdc_restore_defaults..."); 206 dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_restore_defaults...");
201 return 0; 207 return 0;
202} 208}
203 209
204static int ccdc_open(struct device *device) 210static int ccdc_open(struct device *device)
205{ 211{
206 dev = device;
207 return ccdc_restore_defaults(); 212 return ccdc_restore_defaults();
208} 213}
209 214
@@ -226,7 +231,7 @@ static void ccdc_setwin(struct v4l2_rect *image_win,
226 int vert_start, vert_nr_lines; 231 int vert_start, vert_nr_lines;
227 int mid_img = 0; 232 int mid_img = 0;
228 233
229 dev_dbg(dev, "\nStarting ccdc_setwin..."); 234 dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_setwin...");
230 235
231 /* 236 /*
232 * ppc - per pixel count. indicates how many pixels per cell 237 * ppc - per pixel count. indicates how many pixels per cell
@@ -260,45 +265,46 @@ static void ccdc_setwin(struct v4l2_rect *image_win,
260 regw(vert_start & CCDC_START_VER_ONE_MASK, SLV0); 265 regw(vert_start & CCDC_START_VER_ONE_MASK, SLV0);
261 regw(vert_start & CCDC_START_VER_TWO_MASK, SLV1); 266 regw(vert_start & CCDC_START_VER_TWO_MASK, SLV1);
262 regw(vert_nr_lines & CCDC_NUM_LINES_VER, NLV); 267 regw(vert_nr_lines & CCDC_NUM_LINES_VER, NLV);
263 dev_dbg(dev, "\nEnd of ccdc_setwin..."); 268 dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_setwin...");
264} 269}
265 270
266static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam) 271static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
267{ 272{
268 if (ccdcparam->datasft < CCDC_DATA_NO_SHIFT || 273 if (ccdcparam->datasft < CCDC_DATA_NO_SHIFT ||
269 ccdcparam->datasft > CCDC_DATA_SHIFT_6BIT) { 274 ccdcparam->datasft > CCDC_DATA_SHIFT_6BIT) {
270 dev_dbg(dev, "Invalid value of data shift\n"); 275 dev_dbg(ccdc_cfg.dev, "Invalid value of data shift\n");
271 return -EINVAL; 276 return -EINVAL;
272 } 277 }
273 278
274 if (ccdcparam->mfilt1 < CCDC_NO_MEDIAN_FILTER1 || 279 if (ccdcparam->mfilt1 < CCDC_NO_MEDIAN_FILTER1 ||
275 ccdcparam->mfilt1 > CCDC_MEDIAN_FILTER1) { 280 ccdcparam->mfilt1 > CCDC_MEDIAN_FILTER1) {
276 dev_dbg(dev, "Invalid value of median filter1\n"); 281 dev_dbg(ccdc_cfg.dev, "Invalid value of median filter1\n");
277 return -EINVAL; 282 return -EINVAL;
278 } 283 }
279 284
280 if (ccdcparam->mfilt2 < CCDC_NO_MEDIAN_FILTER2 || 285 if (ccdcparam->mfilt2 < CCDC_NO_MEDIAN_FILTER2 ||
281 ccdcparam->mfilt2 > CCDC_MEDIAN_FILTER2) { 286 ccdcparam->mfilt2 > CCDC_MEDIAN_FILTER2) {
282 dev_dbg(dev, "Invalid value of median filter2\n"); 287 dev_dbg(ccdc_cfg.dev, "Invalid value of median filter2\n");
283 return -EINVAL; 288 return -EINVAL;
284 } 289 }
285 290
286 if ((ccdcparam->med_filt_thres < 0) || 291 if ((ccdcparam->med_filt_thres < 0) ||
287 (ccdcparam->med_filt_thres > CCDC_MED_FILT_THRESH)) { 292 (ccdcparam->med_filt_thres > CCDC_MED_FILT_THRESH)) {
288 dev_dbg(dev, "Invalid value of median filter threshold\n"); 293 dev_dbg(ccdc_cfg.dev,
294 "Invalid value of median filter thresold\n");
289 return -EINVAL; 295 return -EINVAL;
290 } 296 }
291 297
292 if (ccdcparam->data_sz < CCDC_DATA_16BITS || 298 if (ccdcparam->data_sz < CCDC_DATA_16BITS ||
293 ccdcparam->data_sz > CCDC_DATA_8BITS) { 299 ccdcparam->data_sz > CCDC_DATA_8BITS) {
294 dev_dbg(dev, "Invalid value of data size\n"); 300 dev_dbg(ccdc_cfg.dev, "Invalid value of data size\n");
295 return -EINVAL; 301 return -EINVAL;
296 } 302 }
297 303
298 if (ccdcparam->alaw.enable) { 304 if (ccdcparam->alaw.enable) {
299 if (ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_13_4 || 305 if (ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_13_4 ||
300 ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) { 306 ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) {
301 dev_dbg(dev, "Invalid value of ALAW\n"); 307 dev_dbg(ccdc_cfg.dev, "Invalid value of ALAW\n");
302 return -EINVAL; 308 return -EINVAL;
303 } 309 }
304 } 310 }
@@ -306,12 +312,14 @@ static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
306 if (ccdcparam->blk_clamp.b_clamp_enable) { 312 if (ccdcparam->blk_clamp.b_clamp_enable) {
307 if (ccdcparam->blk_clamp.sample_pixel < CCDC_SAMPLE_1PIXELS || 313 if (ccdcparam->blk_clamp.sample_pixel < CCDC_SAMPLE_1PIXELS ||
308 ccdcparam->blk_clamp.sample_pixel > CCDC_SAMPLE_16PIXELS) { 314 ccdcparam->blk_clamp.sample_pixel > CCDC_SAMPLE_16PIXELS) {
309 dev_dbg(dev, "Invalid value of sample pixel\n"); 315 dev_dbg(ccdc_cfg.dev,
316 "Invalid value of sample pixel\n");
310 return -EINVAL; 317 return -EINVAL;
311 } 318 }
312 if (ccdcparam->blk_clamp.sample_ln < CCDC_SAMPLE_1LINES || 319 if (ccdcparam->blk_clamp.sample_ln < CCDC_SAMPLE_1LINES ||
313 ccdcparam->blk_clamp.sample_ln > CCDC_SAMPLE_16LINES) { 320 ccdcparam->blk_clamp.sample_ln > CCDC_SAMPLE_16LINES) {
314 dev_dbg(dev, "Invalid value of sample lines\n"); 321 dev_dbg(ccdc_cfg.dev,
322 "Invalid value of sample lines\n");
315 return -EINVAL; 323 return -EINVAL;
316 } 324 }
317 } 325 }
@@ -325,18 +333,18 @@ static int ccdc_set_params(void __user *params)
325 int x; 333 int x;
326 334
327 /* only raw module parameters can be set through the IOCTL */ 335 /* only raw module parameters can be set through the IOCTL */
328 if (ccdc_if_type != VPFE_RAW_BAYER) 336 if (ccdc_cfg.if_type != VPFE_RAW_BAYER)
329 return -EINVAL; 337 return -EINVAL;
330 338
331 x = copy_from_user(&ccdc_raw_params, params, sizeof(ccdc_raw_params)); 339 x = copy_from_user(&ccdc_raw_params, params, sizeof(ccdc_raw_params));
332 if (x) { 340 if (x) {
333 dev_dbg(dev, "ccdc_set_params: error in copying ccdc" 341 dev_dbg(ccdc_cfg.dev, "ccdc_set_params: error in copying ccdc"
334 "params, %d\n", x); 342 "params, %d\n", x);
335 return -EFAULT; 343 return -EFAULT;
336 } 344 }
337 345
338 if (!validate_ccdc_param(&ccdc_raw_params)) { 346 if (!validate_ccdc_param(&ccdc_raw_params)) {
339 memcpy(&ccdc_hw_params_raw.config_params, 347 memcpy(&ccdc_cfg.bayer.config_params,
340 &ccdc_raw_params, 348 &ccdc_raw_params,
341 sizeof(ccdc_raw_params)); 349 sizeof(ccdc_raw_params));
342 return 0; 350 return 0;
@@ -347,11 +355,11 @@ static int ccdc_set_params(void __user *params)
347/* This function will configure CCDC for YCbCr video capture */ 355/* This function will configure CCDC for YCbCr video capture */
348static void ccdc_config_ycbcr(void) 356static void ccdc_config_ycbcr(void)
349{ 357{
350 struct ccdc_params_ycbcr *params = &ccdc_hw_params_ycbcr; 358 struct ccdc_params_ycbcr *params = &ccdc_cfg.ycbcr;
351 u32 temp; 359 u32 temp;
352 360
353 /* first set the CCDC power on defaults values in all registers */ 361 /* first set the CCDC power on defaults values in all registers */
354 dev_dbg(dev, "\nStarting ccdc_config_ycbcr..."); 362 dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_config_ycbcr...");
355 ccdc_restore_defaults(); 363 ccdc_restore_defaults();
356 364
357 /* configure pixel format & video frame format */ 365 /* configure pixel format & video frame format */
@@ -403,7 +411,7 @@ static void ccdc_config_ycbcr(void)
403 regw(CCDC_SDOFST_FIELD_INTERLEAVED, SDOFST); 411 regw(CCDC_SDOFST_FIELD_INTERLEAVED, SDOFST);
404 } 412 }
405 413
406 dev_dbg(dev, "\nEnd of ccdc_config_ycbcr...\n"); 414 dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_config_ycbcr...\n");
407} 415}
408 416
409/* 417/*
@@ -483,7 +491,7 @@ int ccdc_write_dfc_entry(int index, struct ccdc_vertical_dft *dfc)
483 */ 491 */
484 492
485 if (count) { 493 if (count) {
486 dev_err(dev, "defect table write timeout !!!\n"); 494 dev_err(ccdc_cfg.dev, "defect table write timeout !!!\n");
487 return -1; 495 return -1;
488 } 496 }
489 return 0; 497 return 0;
@@ -605,12 +613,12 @@ static void ccdc_config_color_patterns(struct ccdc_col_pat *pat0,
605/* This function will configure CCDC for Raw mode image capture */ 613/* This function will configure CCDC for Raw mode image capture */
606static int ccdc_config_raw(void) 614static int ccdc_config_raw(void)
607{ 615{
608 struct ccdc_params_raw *params = &ccdc_hw_params_raw; 616 struct ccdc_params_raw *params = &ccdc_cfg.bayer;
609 struct ccdc_config_params_raw *config_params = 617 struct ccdc_config_params_raw *config_params =
610 &ccdc_hw_params_raw.config_params; 618 &ccdc_cfg.bayer.config_params;
611 unsigned int val; 619 unsigned int val;
612 620
613 dev_dbg(dev, "\nStarting ccdc_config_raw..."); 621 dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_config_raw...");
614 622
615 /* restore power on defaults to register */ 623 /* restore power on defaults to register */
616 ccdc_restore_defaults(); 624 ccdc_restore_defaults();
@@ -659,7 +667,7 @@ static int ccdc_config_raw(void)
659 val |= (config_params->datasft & CCDC_DATASFT_MASK) << 667 val |= (config_params->datasft & CCDC_DATASFT_MASK) <<
660 CCDC_DATASFT_SHIFT; 668 CCDC_DATASFT_SHIFT;
661 regw(val , MODESET); 669 regw(val , MODESET);
662 dev_dbg(dev, "\nWriting 0x%x to MODESET...\n", val); 670 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to MODESET...\n", val);
663 671
664 /* Configure the Median Filter threshold */ 672 /* Configure the Median Filter threshold */
665 regw((config_params->med_filt_thres) & CCDC_MED_FILT_THRESH, MEDFILT); 673 regw((config_params->med_filt_thres) & CCDC_MED_FILT_THRESH, MEDFILT);
@@ -681,7 +689,7 @@ static int ccdc_config_raw(void)
681 (config_params->mfilt2 << CCDC_MFILT2_SHIFT)); 689 (config_params->mfilt2 << CCDC_MFILT2_SHIFT));
682 690
683 regw(val, GAMMAWD); 691 regw(val, GAMMAWD);
684 dev_dbg(dev, "\nWriting 0x%x to GAMMAWD...\n", val); 692 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to GAMMAWD...\n", val);
685 693
686 /* configure video window */ 694 /* configure video window */
687 ccdc_setwin(&params->win, params->frm_fmt, 1); 695 ccdc_setwin(&params->win, params->frm_fmt, 1);
@@ -706,7 +714,7 @@ static int ccdc_config_raw(void)
706 /* Configure the Gain & offset control */ 714 /* Configure the Gain & offset control */
707 ccdc_config_gain_offset(); 715 ccdc_config_gain_offset();
708 716
709 dev_dbg(dev, "\nWriting %x to COLPTN...\n", val); 717 dev_dbg(ccdc_cfg.dev, "\nWriting %x to COLPTN...\n", val);
710 718
711 /* Configure DATAOFST register */ 719 /* Configure DATAOFST register */
712 val = (config_params->data_offset.horz_offset & CCDC_DATAOFST_MASK) << 720 val = (config_params->data_offset.horz_offset & CCDC_DATAOFST_MASK) <<
@@ -726,7 +734,7 @@ static int ccdc_config_raw(void)
726 CCDC_HSIZE_VAL_MASK; 734 CCDC_HSIZE_VAL_MASK;
727 735
728 /* adjust to multiple of 32 */ 736 /* adjust to multiple of 32 */
729 dev_dbg(dev, "\nWriting 0x%x to HSIZE...\n", 737 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to HSIZE...\n",
730 (((params->win.width) + 31) >> 5) & 738 (((params->win.width) + 31) >> 5) &
731 CCDC_HSIZE_VAL_MASK); 739 CCDC_HSIZE_VAL_MASK);
732 } else { 740 } else {
@@ -734,7 +742,7 @@ static int ccdc_config_raw(void)
734 val |= (((params->win.width * 2) + 31) >> 5) & 742 val |= (((params->win.width * 2) + 31) >> 5) &
735 CCDC_HSIZE_VAL_MASK; 743 CCDC_HSIZE_VAL_MASK;
736 744
737 dev_dbg(dev, "\nWriting 0x%x to HSIZE...\n", 745 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to HSIZE...\n",
738 (((params->win.width * 2) + 31) >> 5) & 746 (((params->win.width * 2) + 31) >> 5) &
739 CCDC_HSIZE_VAL_MASK); 747 CCDC_HSIZE_VAL_MASK);
740 } 748 }
@@ -745,34 +753,34 @@ static int ccdc_config_raw(void)
745 if (params->image_invert_enable) { 753 if (params->image_invert_enable) {
746 /* For interlace inverse mode */ 754 /* For interlace inverse mode */
747 regw(CCDC_SDOFST_INTERLACE_INVERSE, SDOFST); 755 regw(CCDC_SDOFST_INTERLACE_INVERSE, SDOFST);
748 dev_dbg(dev, "\nWriting %x to SDOFST...\n", 756 dev_dbg(ccdc_cfg.dev, "\nWriting %x to SDOFST...\n",
749 CCDC_SDOFST_INTERLACE_INVERSE); 757 CCDC_SDOFST_INTERLACE_INVERSE);
750 } else { 758 } else {
751 /* For interlace non inverse mode */ 759 /* For interlace non inverse mode */
752 regw(CCDC_SDOFST_INTERLACE_NORMAL, SDOFST); 760 regw(CCDC_SDOFST_INTERLACE_NORMAL, SDOFST);
753 dev_dbg(dev, "\nWriting %x to SDOFST...\n", 761 dev_dbg(ccdc_cfg.dev, "\nWriting %x to SDOFST...\n",
754 CCDC_SDOFST_INTERLACE_NORMAL); 762 CCDC_SDOFST_INTERLACE_NORMAL);
755 } 763 }
756 } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) { 764 } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
757 if (params->image_invert_enable) { 765 if (params->image_invert_enable) {
758 /* For progessive inverse mode */ 766 /* For progessive inverse mode */
759 regw(CCDC_SDOFST_PROGRESSIVE_INVERSE, SDOFST); 767 regw(CCDC_SDOFST_PROGRESSIVE_INVERSE, SDOFST);
760 dev_dbg(dev, "\nWriting %x to SDOFST...\n", 768 dev_dbg(ccdc_cfg.dev, "\nWriting %x to SDOFST...\n",
761 CCDC_SDOFST_PROGRESSIVE_INVERSE); 769 CCDC_SDOFST_PROGRESSIVE_INVERSE);
762 } else { 770 } else {
763 /* For progessive non inverse mode */ 771 /* For progessive non inverse mode */
764 regw(CCDC_SDOFST_PROGRESSIVE_NORMAL, SDOFST); 772 regw(CCDC_SDOFST_PROGRESSIVE_NORMAL, SDOFST);
765 dev_dbg(dev, "\nWriting %x to SDOFST...\n", 773 dev_dbg(ccdc_cfg.dev, "\nWriting %x to SDOFST...\n",
766 CCDC_SDOFST_PROGRESSIVE_NORMAL); 774 CCDC_SDOFST_PROGRESSIVE_NORMAL);
767 } 775 }
768 } 776 }
769 dev_dbg(dev, "\nend of ccdc_config_raw..."); 777 dev_dbg(ccdc_cfg.dev, "\nend of ccdc_config_raw...");
770 return 0; 778 return 0;
771} 779}
772 780
773static int ccdc_configure(void) 781static int ccdc_configure(void)
774{ 782{
775 if (ccdc_if_type == VPFE_RAW_BAYER) 783 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
776 return ccdc_config_raw(); 784 return ccdc_config_raw();
777 else 785 else
778 ccdc_config_ycbcr(); 786 ccdc_config_ycbcr();
@@ -781,23 +789,23 @@ static int ccdc_configure(void)
781 789
782static int ccdc_set_buftype(enum ccdc_buftype buf_type) 790static int ccdc_set_buftype(enum ccdc_buftype buf_type)
783{ 791{
784 if (ccdc_if_type == VPFE_RAW_BAYER) 792 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
785 ccdc_hw_params_raw.buf_type = buf_type; 793 ccdc_cfg.bayer.buf_type = buf_type;
786 else 794 else
787 ccdc_hw_params_ycbcr.buf_type = buf_type; 795 ccdc_cfg.ycbcr.buf_type = buf_type;
788 return 0; 796 return 0;
789} 797}
790static enum ccdc_buftype ccdc_get_buftype(void) 798static enum ccdc_buftype ccdc_get_buftype(void)
791{ 799{
792 if (ccdc_if_type == VPFE_RAW_BAYER) 800 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
793 return ccdc_hw_params_raw.buf_type; 801 return ccdc_cfg.bayer.buf_type;
794 return ccdc_hw_params_ycbcr.buf_type; 802 return ccdc_cfg.ycbcr.buf_type;
795} 803}
796 804
797static int ccdc_enum_pix(u32 *pix, int i) 805static int ccdc_enum_pix(u32 *pix, int i)
798{ 806{
799 int ret = -EINVAL; 807 int ret = -EINVAL;
800 if (ccdc_if_type == VPFE_RAW_BAYER) { 808 if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
801 if (i < ARRAY_SIZE(ccdc_raw_bayer_pix_formats)) { 809 if (i < ARRAY_SIZE(ccdc_raw_bayer_pix_formats)) {
802 *pix = ccdc_raw_bayer_pix_formats[i]; 810 *pix = ccdc_raw_bayer_pix_formats[i];
803 ret = 0; 811 ret = 0;
@@ -813,20 +821,19 @@ static int ccdc_enum_pix(u32 *pix, int i)
813 821
814static int ccdc_set_pixel_format(u32 pixfmt) 822static int ccdc_set_pixel_format(u32 pixfmt)
815{ 823{
816 struct ccdc_a_law *alaw = 824 struct ccdc_a_law *alaw = &ccdc_cfg.bayer.config_params.alaw;
817 &ccdc_hw_params_raw.config_params.alaw;
818 825
819 if (ccdc_if_type == VPFE_RAW_BAYER) { 826 if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
820 ccdc_hw_params_raw.pix_fmt = CCDC_PIXFMT_RAW; 827 ccdc_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
821 if (pixfmt == V4L2_PIX_FMT_SBGGR8) 828 if (pixfmt == V4L2_PIX_FMT_SBGGR8)
822 alaw->enable = 1; 829 alaw->enable = 1;
823 else if (pixfmt != V4L2_PIX_FMT_SBGGR16) 830 else if (pixfmt != V4L2_PIX_FMT_SBGGR16)
824 return -EINVAL; 831 return -EINVAL;
825 } else { 832 } else {
826 if (pixfmt == V4L2_PIX_FMT_YUYV) 833 if (pixfmt == V4L2_PIX_FMT_YUYV)
827 ccdc_hw_params_ycbcr.pix_order = CCDC_PIXORDER_YCBYCR; 834 ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_YCBYCR;
828 else if (pixfmt == V4L2_PIX_FMT_UYVY) 835 else if (pixfmt == V4L2_PIX_FMT_UYVY)
829 ccdc_hw_params_ycbcr.pix_order = CCDC_PIXORDER_CBYCRY; 836 ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
830 else 837 else
831 return -EINVAL; 838 return -EINVAL;
832 } 839 }
@@ -834,17 +841,16 @@ static int ccdc_set_pixel_format(u32 pixfmt)
834} 841}
835static u32 ccdc_get_pixel_format(void) 842static u32 ccdc_get_pixel_format(void)
836{ 843{
837 struct ccdc_a_law *alaw = 844 struct ccdc_a_law *alaw = &ccdc_cfg.bayer.config_params.alaw;
838 &ccdc_hw_params_raw.config_params.alaw;
839 u32 pixfmt; 845 u32 pixfmt;
840 846
841 if (ccdc_if_type == VPFE_RAW_BAYER) 847 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
842 if (alaw->enable) 848 if (alaw->enable)
843 pixfmt = V4L2_PIX_FMT_SBGGR8; 849 pixfmt = V4L2_PIX_FMT_SBGGR8;
844 else 850 else
845 pixfmt = V4L2_PIX_FMT_SBGGR16; 851 pixfmt = V4L2_PIX_FMT_SBGGR16;
846 else { 852 else {
847 if (ccdc_hw_params_ycbcr.pix_order == CCDC_PIXORDER_YCBYCR) 853 if (ccdc_cfg.ycbcr.pix_order == CCDC_PIXORDER_YCBYCR)
848 pixfmt = V4L2_PIX_FMT_YUYV; 854 pixfmt = V4L2_PIX_FMT_YUYV;
849 else 855 else
850 pixfmt = V4L2_PIX_FMT_UYVY; 856 pixfmt = V4L2_PIX_FMT_UYVY;
@@ -853,53 +859,53 @@ static u32 ccdc_get_pixel_format(void)
853} 859}
854static int ccdc_set_image_window(struct v4l2_rect *win) 860static int ccdc_set_image_window(struct v4l2_rect *win)
855{ 861{
856 if (ccdc_if_type == VPFE_RAW_BAYER) 862 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
857 ccdc_hw_params_raw.win = *win; 863 ccdc_cfg.bayer.win = *win;
858 else 864 else
859 ccdc_hw_params_ycbcr.win = *win; 865 ccdc_cfg.ycbcr.win = *win;
860 return 0; 866 return 0;
861} 867}
862 868
863static void ccdc_get_image_window(struct v4l2_rect *win) 869static void ccdc_get_image_window(struct v4l2_rect *win)
864{ 870{
865 if (ccdc_if_type == VPFE_RAW_BAYER) 871 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
866 *win = ccdc_hw_params_raw.win; 872 *win = ccdc_cfg.bayer.win;
867 else 873 else
868 *win = ccdc_hw_params_ycbcr.win; 874 *win = ccdc_cfg.ycbcr.win;
869} 875}
870 876
871static unsigned int ccdc_get_line_length(void) 877static unsigned int ccdc_get_line_length(void)
872{ 878{
873 struct ccdc_config_params_raw *config_params = 879 struct ccdc_config_params_raw *config_params =
874 &ccdc_hw_params_raw.config_params; 880 &ccdc_cfg.bayer.config_params;
875 unsigned int len; 881 unsigned int len;
876 882
877 if (ccdc_if_type == VPFE_RAW_BAYER) { 883 if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
878 if ((config_params->alaw.enable) || 884 if ((config_params->alaw.enable) ||
879 (config_params->data_sz == CCDC_DATA_8BITS)) 885 (config_params->data_sz == CCDC_DATA_8BITS))
880 len = ccdc_hw_params_raw.win.width; 886 len = ccdc_cfg.bayer.win.width;
881 else 887 else
882 len = ccdc_hw_params_raw.win.width * 2; 888 len = ccdc_cfg.bayer.win.width * 2;
883 } else 889 } else
884 len = ccdc_hw_params_ycbcr.win.width * 2; 890 len = ccdc_cfg.ycbcr.win.width * 2;
885 return ALIGN(len, 32); 891 return ALIGN(len, 32);
886} 892}
887 893
888static int ccdc_set_frame_format(enum ccdc_frmfmt frm_fmt) 894static int ccdc_set_frame_format(enum ccdc_frmfmt frm_fmt)
889{ 895{
890 if (ccdc_if_type == VPFE_RAW_BAYER) 896 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
891 ccdc_hw_params_raw.frm_fmt = frm_fmt; 897 ccdc_cfg.bayer.frm_fmt = frm_fmt;
892 else 898 else
893 ccdc_hw_params_ycbcr.frm_fmt = frm_fmt; 899 ccdc_cfg.ycbcr.frm_fmt = frm_fmt;
894 return 0; 900 return 0;
895} 901}
896 902
897static enum ccdc_frmfmt ccdc_get_frame_format(void) 903static enum ccdc_frmfmt ccdc_get_frame_format(void)
898{ 904{
899 if (ccdc_if_type == VPFE_RAW_BAYER) 905 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
900 return ccdc_hw_params_raw.frm_fmt; 906 return ccdc_cfg.bayer.frm_fmt;
901 else 907 else
902 return ccdc_hw_params_ycbcr.frm_fmt; 908 return ccdc_cfg.ycbcr.frm_fmt;
903} 909}
904 910
905static int ccdc_getfid(void) 911static int ccdc_getfid(void)
@@ -916,14 +922,14 @@ static inline void ccdc_setfbaddr(unsigned long addr)
916 922
917static int ccdc_set_hw_if_params(struct vpfe_hw_if_param *params) 923static int ccdc_set_hw_if_params(struct vpfe_hw_if_param *params)
918{ 924{
919 ccdc_if_type = params->if_type; 925 ccdc_cfg.if_type = params->if_type;
920 926
921 switch (params->if_type) { 927 switch (params->if_type) {
922 case VPFE_BT656: 928 case VPFE_BT656:
923 case VPFE_YCBCR_SYNC_16: 929 case VPFE_YCBCR_SYNC_16:
924 case VPFE_YCBCR_SYNC_8: 930 case VPFE_YCBCR_SYNC_8:
925 ccdc_hw_params_ycbcr.vd_pol = params->vdpol; 931 ccdc_cfg.ycbcr.vd_pol = params->vdpol;
926 ccdc_hw_params_ycbcr.hd_pol = params->hdpol; 932 ccdc_cfg.ycbcr.hd_pol = params->hdpol;
927 break; 933 break;
928 default: 934 default:
929 /* TODO add support for raw bayer here */ 935 /* TODO add support for raw bayer here */
@@ -938,7 +944,6 @@ static struct ccdc_hw_device ccdc_hw_dev = {
938 .hw_ops = { 944 .hw_ops = {
939 .open = ccdc_open, 945 .open = ccdc_open,
940 .close = ccdc_close, 946 .close = ccdc_close,
941 .set_ccdc_base = ccdc_set_ccdc_base,
942 .enable = ccdc_enable, 947 .enable = ccdc_enable,
943 .enable_out_to_sdram = ccdc_enable_output_to_sdram, 948 .enable_out_to_sdram = ccdc_enable_output_to_sdram,
944 .set_hw_if_params = ccdc_set_hw_if_params, 949 .set_hw_if_params = ccdc_set_hw_if_params,
@@ -959,19 +964,118 @@ static struct ccdc_hw_device ccdc_hw_dev = {
959 }, 964 },
960}; 965};
961 966
962static int __init dm355_ccdc_init(void) 967static int __init dm355_ccdc_probe(struct platform_device *pdev)
963{ 968{
964 printk(KERN_NOTICE "dm355_ccdc_init\n"); 969 void (*setup_pinmux)(void);
965 if (vpfe_register_ccdc_device(&ccdc_hw_dev) < 0) 970 struct resource *res;
966 return -1; 971 int status = 0;
967 printk(KERN_NOTICE "%s is registered with vpfe.\n", 972
968 ccdc_hw_dev.name); 973 /*
974 * first try to register with vpfe. If not correct platform, then we
975 * don't have to iomap
976 */
977 status = vpfe_register_ccdc_device(&ccdc_hw_dev);
978 if (status < 0)
979 return status;
980
981 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
982 if (!res) {
983 status = -ENODEV;
984 goto fail_nores;
985 }
986
987 res = request_mem_region(res->start, resource_size(res), res->name);
988 if (!res) {
989 status = -EBUSY;
990 goto fail_nores;
991 }
992
993 ccdc_cfg.base_addr = ioremap_nocache(res->start, resource_size(res));
994 if (!ccdc_cfg.base_addr) {
995 status = -ENOMEM;
996 goto fail_nomem;
997 }
998
999 /* Get and enable Master clock */
1000 ccdc_cfg.mclk = clk_get(&pdev->dev, "master");
1001 if (IS_ERR(ccdc_cfg.mclk)) {
1002 status = PTR_ERR(ccdc_cfg.mclk);
1003 goto fail_nomap;
1004 }
1005 if (clk_enable(ccdc_cfg.mclk)) {
1006 status = -ENODEV;
1007 goto fail_mclk;
1008 }
1009
1010 /* Get and enable Slave clock */
1011 ccdc_cfg.sclk = clk_get(&pdev->dev, "slave");
1012 if (IS_ERR(ccdc_cfg.sclk)) {
1013 status = PTR_ERR(ccdc_cfg.sclk);
1014 goto fail_mclk;
1015 }
1016 if (clk_enable(ccdc_cfg.sclk)) {
1017 status = -ENODEV;
1018 goto fail_sclk;
1019 }
1020
1021 /* Platform data holds setup_pinmux function ptr */
1022 if (NULL == pdev->dev.platform_data) {
1023 status = -ENODEV;
1024 goto fail_sclk;
1025 }
1026 setup_pinmux = pdev->dev.platform_data;
1027 /*
1028 * setup Mux configuration for ccdc which may be different for
1029 * different SoCs using this CCDC
1030 */
1031 setup_pinmux();
1032 ccdc_cfg.dev = &pdev->dev;
1033 printk(KERN_NOTICE "%s is registered with vpfe.\n", ccdc_hw_dev.name);
969 return 0; 1034 return 0;
1035fail_sclk:
1036 clk_put(ccdc_cfg.sclk);
1037fail_mclk:
1038 clk_put(ccdc_cfg.mclk);
1039fail_nomap:
1040 iounmap(ccdc_cfg.base_addr);
1041fail_nomem:
1042 release_mem_region(res->start, resource_size(res));
1043fail_nores:
1044 vpfe_unregister_ccdc_device(&ccdc_hw_dev);
1045 return status;
970} 1046}
971 1047
972static void __exit dm355_ccdc_exit(void) 1048static int dm355_ccdc_remove(struct platform_device *pdev)
973{ 1049{
1050 struct resource *res;
1051
1052 clk_put(ccdc_cfg.mclk);
1053 clk_put(ccdc_cfg.sclk);
1054 iounmap(ccdc_cfg.base_addr);
1055 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1056 if (res)
1057 release_mem_region(res->start, resource_size(res));
974 vpfe_unregister_ccdc_device(&ccdc_hw_dev); 1058 vpfe_unregister_ccdc_device(&ccdc_hw_dev);
1059 return 0;
1060}
1061
1062static struct platform_driver dm355_ccdc_driver = {
1063 .driver = {
1064 .name = "dm355_ccdc",
1065 .owner = THIS_MODULE,
1066 },
1067 .remove = __devexit_p(dm355_ccdc_remove),
1068 .probe = dm355_ccdc_probe,
1069};
1070
1071static int __init dm355_ccdc_init(void)
1072{
1073 return platform_driver_register(&dm355_ccdc_driver);
1074}
1075
1076static void __exit dm355_ccdc_exit(void)
1077{
1078 platform_driver_unregister(&dm355_ccdc_driver);
975} 1079}
976 1080
977module_init(dm355_ccdc_init); 1081module_init(dm355_ccdc_init);
diff --git a/drivers/media/video/davinci/dm644x_ccdc.c b/drivers/media/video/davinci/dm644x_ccdc.c
index d5fa193f32d2..0c394cade22a 100644
--- a/drivers/media/video/davinci/dm644x_ccdc.c
+++ b/drivers/media/video/davinci/dm644x_ccdc.c
@@ -37,8 +37,12 @@
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/videodev2.h> 39#include <linux/videodev2.h>
40#include <linux/clk.h>
41#include <linux/err.h>
42
40#include <media/davinci/dm644x_ccdc.h> 43#include <media/davinci/dm644x_ccdc.h>
41#include <media/davinci/vpss.h> 44#include <media/davinci/vpss.h>
45
42#include "dm644x_ccdc_regs.h" 46#include "dm644x_ccdc_regs.h"
43#include "ccdc_hw_device.h" 47#include "ccdc_hw_device.h"
44 48
@@ -46,32 +50,44 @@ MODULE_LICENSE("GPL");
46MODULE_DESCRIPTION("CCDC Driver for DM6446"); 50MODULE_DESCRIPTION("CCDC Driver for DM6446");
47MODULE_AUTHOR("Texas Instruments"); 51MODULE_AUTHOR("Texas Instruments");
48 52
49static struct device *dev; 53static struct ccdc_oper_config {
50 54 struct device *dev;
51/* Object for CCDC raw mode */ 55 /* CCDC interface type */
52static struct ccdc_params_raw ccdc_hw_params_raw = { 56 enum vpfe_hw_if_type if_type;
53 .pix_fmt = CCDC_PIXFMT_RAW, 57 /* Raw Bayer configuration */
54 .frm_fmt = CCDC_FRMFMT_PROGRESSIVE, 58 struct ccdc_params_raw bayer;
55 .win = CCDC_WIN_VGA, 59 /* YCbCr configuration */
56 .fid_pol = VPFE_PINPOL_POSITIVE, 60 struct ccdc_params_ycbcr ycbcr;
57 .vd_pol = VPFE_PINPOL_POSITIVE, 61 /* Master clock */
58 .hd_pol = VPFE_PINPOL_POSITIVE, 62 struct clk *mclk;
59 .config_params = { 63 /* slave clock */
60 .data_sz = CCDC_DATA_10BITS, 64 struct clk *sclk;
65 /* ccdc base address */
66 void __iomem *base_addr;
67} ccdc_cfg = {
68 /* Raw configurations */
69 .bayer = {
70 .pix_fmt = CCDC_PIXFMT_RAW,
71 .frm_fmt = CCDC_FRMFMT_PROGRESSIVE,
72 .win = CCDC_WIN_VGA,
73 .fid_pol = VPFE_PINPOL_POSITIVE,
74 .vd_pol = VPFE_PINPOL_POSITIVE,
75 .hd_pol = VPFE_PINPOL_POSITIVE,
76 .config_params = {
77 .data_sz = CCDC_DATA_10BITS,
78 },
79 },
80 .ycbcr = {
81 .pix_fmt = CCDC_PIXFMT_YCBCR_8BIT,
82 .frm_fmt = CCDC_FRMFMT_INTERLACED,
83 .win = CCDC_WIN_PAL,
84 .fid_pol = VPFE_PINPOL_POSITIVE,
85 .vd_pol = VPFE_PINPOL_POSITIVE,
86 .hd_pol = VPFE_PINPOL_POSITIVE,
87 .bt656_enable = 1,
88 .pix_order = CCDC_PIXORDER_CBYCRY,
89 .buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED
61 }, 90 },
62};
63
64/* Object for CCDC ycbcr mode */
65static struct ccdc_params_ycbcr ccdc_hw_params_ycbcr = {
66 .pix_fmt = CCDC_PIXFMT_YCBCR_8BIT,
67 .frm_fmt = CCDC_FRMFMT_INTERLACED,
68 .win = CCDC_WIN_PAL,
69 .fid_pol = VPFE_PINPOL_POSITIVE,
70 .vd_pol = VPFE_PINPOL_POSITIVE,
71 .hd_pol = VPFE_PINPOL_POSITIVE,
72 .bt656_enable = 1,
73 .pix_order = CCDC_PIXORDER_CBYCRY,
74 .buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED
75}; 91};
76 92
77#define CCDC_MAX_RAW_YUV_FORMATS 2 93#define CCDC_MAX_RAW_YUV_FORMATS 2
@@ -84,25 +100,15 @@ static u32 ccdc_raw_bayer_pix_formats[] =
84static u32 ccdc_raw_yuv_pix_formats[] = 100static u32 ccdc_raw_yuv_pix_formats[] =
85 {V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_YUYV}; 101 {V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_YUYV};
86 102
87static void *__iomem ccdc_base_addr;
88static int ccdc_addr_size;
89static enum vpfe_hw_if_type ccdc_if_type;
90
91/* register access routines */ 103/* register access routines */
92static inline u32 regr(u32 offset) 104static inline u32 regr(u32 offset)
93{ 105{
94 return __raw_readl(ccdc_base_addr + offset); 106 return __raw_readl(ccdc_cfg.base_addr + offset);
95} 107}
96 108
97static inline void regw(u32 val, u32 offset) 109static inline void regw(u32 val, u32 offset)
98{ 110{
99 __raw_writel(val, ccdc_base_addr + offset); 111 __raw_writel(val, ccdc_cfg.base_addr + offset);
100}
101
102static void ccdc_set_ccdc_base(void *addr, int size)
103{
104 ccdc_base_addr = addr;
105 ccdc_addr_size = size;
106} 112}
107 113
108static void ccdc_enable(int flag) 114static void ccdc_enable(int flag)
@@ -132,7 +138,7 @@ void ccdc_setwin(struct v4l2_rect *image_win,
132 int vert_start, vert_nr_lines; 138 int vert_start, vert_nr_lines;
133 int val = 0, mid_img = 0; 139 int val = 0, mid_img = 0;
134 140
135 dev_dbg(dev, "\nStarting ccdc_setwin..."); 141 dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_setwin...");
136 /* 142 /*
137 * ppc - per pixel count. indicates how many pixels per cell 143 * ppc - per pixel count. indicates how many pixels per cell
138 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2. 144 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
@@ -171,7 +177,7 @@ void ccdc_setwin(struct v4l2_rect *image_win,
171 regw((vert_start << CCDC_VERT_START_SLV0_SHIFT) | vert_start, 177 regw((vert_start << CCDC_VERT_START_SLV0_SHIFT) | vert_start,
172 CCDC_VERT_START); 178 CCDC_VERT_START);
173 regw(vert_nr_lines, CCDC_VERT_LINES); 179 regw(vert_nr_lines, CCDC_VERT_LINES);
174 dev_dbg(dev, "\nEnd of ccdc_setwin..."); 180 dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_setwin...");
175} 181}
176 182
177static void ccdc_readregs(void) 183static void ccdc_readregs(void)
@@ -179,39 +185,39 @@ static void ccdc_readregs(void)
179 unsigned int val = 0; 185 unsigned int val = 0;
180 186
181 val = regr(CCDC_ALAW); 187 val = regr(CCDC_ALAW);
182 dev_notice(dev, "\nReading 0x%x to ALAW...\n", val); 188 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to ALAW...\n", val);
183 val = regr(CCDC_CLAMP); 189 val = regr(CCDC_CLAMP);
184 dev_notice(dev, "\nReading 0x%x to CLAMP...\n", val); 190 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to CLAMP...\n", val);
185 val = regr(CCDC_DCSUB); 191 val = regr(CCDC_DCSUB);
186 dev_notice(dev, "\nReading 0x%x to DCSUB...\n", val); 192 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to DCSUB...\n", val);
187 val = regr(CCDC_BLKCMP); 193 val = regr(CCDC_BLKCMP);
188 dev_notice(dev, "\nReading 0x%x to BLKCMP...\n", val); 194 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to BLKCMP...\n", val);
189 val = regr(CCDC_FPC_ADDR); 195 val = regr(CCDC_FPC_ADDR);
190 dev_notice(dev, "\nReading 0x%x to FPC_ADDR...\n", val); 196 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FPC_ADDR...\n", val);
191 val = regr(CCDC_FPC); 197 val = regr(CCDC_FPC);
192 dev_notice(dev, "\nReading 0x%x to FPC...\n", val); 198 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FPC...\n", val);
193 val = regr(CCDC_FMTCFG); 199 val = regr(CCDC_FMTCFG);
194 dev_notice(dev, "\nReading 0x%x to FMTCFG...\n", val); 200 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMTCFG...\n", val);
195 val = regr(CCDC_COLPTN); 201 val = regr(CCDC_COLPTN);
196 dev_notice(dev, "\nReading 0x%x to COLPTN...\n", val); 202 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to COLPTN...\n", val);
197 val = regr(CCDC_FMT_HORZ); 203 val = regr(CCDC_FMT_HORZ);
198 dev_notice(dev, "\nReading 0x%x to FMT_HORZ...\n", val); 204 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMT_HORZ...\n", val);
199 val = regr(CCDC_FMT_VERT); 205 val = regr(CCDC_FMT_VERT);
200 dev_notice(dev, "\nReading 0x%x to FMT_VERT...\n", val); 206 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMT_VERT...\n", val);
201 val = regr(CCDC_HSIZE_OFF); 207 val = regr(CCDC_HSIZE_OFF);
202 dev_notice(dev, "\nReading 0x%x to HSIZE_OFF...\n", val); 208 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to HSIZE_OFF...\n", val);
203 val = regr(CCDC_SDOFST); 209 val = regr(CCDC_SDOFST);
204 dev_notice(dev, "\nReading 0x%x to SDOFST...\n", val); 210 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to SDOFST...\n", val);
205 val = regr(CCDC_VP_OUT); 211 val = regr(CCDC_VP_OUT);
206 dev_notice(dev, "\nReading 0x%x to VP_OUT...\n", val); 212 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VP_OUT...\n", val);
207 val = regr(CCDC_SYN_MODE); 213 val = regr(CCDC_SYN_MODE);
208 dev_notice(dev, "\nReading 0x%x to SYN_MODE...\n", val); 214 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to SYN_MODE...\n", val);
209 val = regr(CCDC_HORZ_INFO); 215 val = regr(CCDC_HORZ_INFO);
210 dev_notice(dev, "\nReading 0x%x to HORZ_INFO...\n", val); 216 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to HORZ_INFO...\n", val);
211 val = regr(CCDC_VERT_START); 217 val = regr(CCDC_VERT_START);
212 dev_notice(dev, "\nReading 0x%x to VERT_START...\n", val); 218 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VERT_START...\n", val);
213 val = regr(CCDC_VERT_LINES); 219 val = regr(CCDC_VERT_LINES);
214 dev_notice(dev, "\nReading 0x%x to VERT_LINES...\n", val); 220 dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VERT_LINES...\n", val);
215} 221}
216 222
217static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam) 223static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
@@ -220,7 +226,7 @@ static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
220 if ((ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) || 226 if ((ccdcparam->alaw.gama_wd > CCDC_GAMMA_BITS_09_0) ||
221 (ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_15_6) || 227 (ccdcparam->alaw.gama_wd < CCDC_GAMMA_BITS_15_6) ||
222 (ccdcparam->alaw.gama_wd < ccdcparam->data_sz)) { 228 (ccdcparam->alaw.gama_wd < ccdcparam->data_sz)) {
223 dev_dbg(dev, "\nInvalid data line select"); 229 dev_dbg(ccdc_cfg.dev, "\nInvalid data line select");
224 return -1; 230 return -1;
225 } 231 }
226 } 232 }
@@ -230,7 +236,7 @@ static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
230static int ccdc_update_raw_params(struct ccdc_config_params_raw *raw_params) 236static int ccdc_update_raw_params(struct ccdc_config_params_raw *raw_params)
231{ 237{
232 struct ccdc_config_params_raw *config_params = 238 struct ccdc_config_params_raw *config_params =
233 &ccdc_hw_params_raw.config_params; 239 &ccdc_cfg.bayer.config_params;
234 unsigned int *fpc_virtaddr = NULL; 240 unsigned int *fpc_virtaddr = NULL;
235 unsigned int *fpc_physaddr = NULL; 241 unsigned int *fpc_physaddr = NULL;
236 242
@@ -266,7 +272,7 @@ static int ccdc_update_raw_params(struct ccdc_config_params_raw *raw_params)
266 FP_NUM_BYTES)); 272 FP_NUM_BYTES));
267 273
268 if (fpc_virtaddr == NULL) { 274 if (fpc_virtaddr == NULL) {
269 dev_dbg(dev, 275 dev_dbg(ccdc_cfg.dev,
270 "\nUnable to allocate memory for FPC"); 276 "\nUnable to allocate memory for FPC");
271 return -EFAULT; 277 return -EFAULT;
272 } 278 }
@@ -279,7 +285,7 @@ static int ccdc_update_raw_params(struct ccdc_config_params_raw *raw_params)
279 if (copy_from_user(fpc_virtaddr, 285 if (copy_from_user(fpc_virtaddr,
280 (void __user *)raw_params->fault_pxl.fpc_table_addr, 286 (void __user *)raw_params->fault_pxl.fpc_table_addr,
281 config_params->fault_pxl.fp_num * FP_NUM_BYTES)) { 287 config_params->fault_pxl.fp_num * FP_NUM_BYTES)) {
282 dev_dbg(dev, "\n copy_from_user failed"); 288 dev_dbg(ccdc_cfg.dev, "\n copy_from_user failed");
283 return -EFAULT; 289 return -EFAULT;
284 } 290 }
285 config_params->fault_pxl.fpc_table_addr = (unsigned int)fpc_physaddr; 291 config_params->fault_pxl.fpc_table_addr = (unsigned int)fpc_physaddr;
@@ -289,7 +295,7 @@ static int ccdc_update_raw_params(struct ccdc_config_params_raw *raw_params)
289static int ccdc_close(struct device *dev) 295static int ccdc_close(struct device *dev)
290{ 296{
291 struct ccdc_config_params_raw *config_params = 297 struct ccdc_config_params_raw *config_params =
292 &ccdc_hw_params_raw.config_params; 298 &ccdc_cfg.bayer.config_params;
293 unsigned int *fpc_physaddr = NULL, *fpc_virtaddr = NULL; 299 unsigned int *fpc_physaddr = NULL, *fpc_virtaddr = NULL;
294 300
295 fpc_physaddr = (unsigned int *)config_params->fault_pxl.fpc_table_addr; 301 fpc_physaddr = (unsigned int *)config_params->fault_pxl.fpc_table_addr;
@@ -323,9 +329,8 @@ static void ccdc_restore_defaults(void)
323 329
324static int ccdc_open(struct device *device) 330static int ccdc_open(struct device *device)
325{ 331{
326 dev = device;
327 ccdc_restore_defaults(); 332 ccdc_restore_defaults();
328 if (ccdc_if_type == VPFE_RAW_BAYER) 333 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
329 ccdc_enable_vport(1); 334 ccdc_enable_vport(1);
330 return 0; 335 return 0;
331} 336}
@@ -341,12 +346,12 @@ static int ccdc_set_params(void __user *params)
341 struct ccdc_config_params_raw ccdc_raw_params; 346 struct ccdc_config_params_raw ccdc_raw_params;
342 int x; 347 int x;
343 348
344 if (ccdc_if_type != VPFE_RAW_BAYER) 349 if (ccdc_cfg.if_type != VPFE_RAW_BAYER)
345 return -EINVAL; 350 return -EINVAL;
346 351
347 x = copy_from_user(&ccdc_raw_params, params, sizeof(ccdc_raw_params)); 352 x = copy_from_user(&ccdc_raw_params, params, sizeof(ccdc_raw_params));
348 if (x) { 353 if (x) {
349 dev_dbg(dev, "ccdc_set_params: error in copying" 354 dev_dbg(ccdc_cfg.dev, "ccdc_set_params: error in copying"
350 "ccdc params, %d\n", x); 355 "ccdc params, %d\n", x);
351 return -EFAULT; 356 return -EFAULT;
352 } 357 }
@@ -364,10 +369,10 @@ static int ccdc_set_params(void __user *params)
364 */ 369 */
365void ccdc_config_ycbcr(void) 370void ccdc_config_ycbcr(void)
366{ 371{
367 struct ccdc_params_ycbcr *params = &ccdc_hw_params_ycbcr; 372 struct ccdc_params_ycbcr *params = &ccdc_cfg.ycbcr;
368 u32 syn_mode; 373 u32 syn_mode;
369 374
370 dev_dbg(dev, "\nStarting ccdc_config_ycbcr..."); 375 dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_config_ycbcr...");
371 /* 376 /*
372 * first restore the CCDC registers to default values 377 * first restore the CCDC registers to default values
373 * This is important since we assume default values to be set in 378 * This is important since we assume default values to be set in
@@ -428,7 +433,7 @@ void ccdc_config_ycbcr(void)
428 regw(CCDC_SDOFST_FIELD_INTERLEAVED, CCDC_SDOFST); 433 regw(CCDC_SDOFST_FIELD_INTERLEAVED, CCDC_SDOFST);
429 434
430 ccdc_sbl_reset(); 435 ccdc_sbl_reset();
431 dev_dbg(dev, "\nEnd of ccdc_config_ycbcr...\n"); 436 dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_config_ycbcr...\n");
432 ccdc_readregs(); 437 ccdc_readregs();
433} 438}
434 439
@@ -440,9 +445,9 @@ static void ccdc_config_black_clamp(struct ccdc_black_clamp *bclamp)
440 /* configure DCSub */ 445 /* configure DCSub */
441 val = (bclamp->dc_sub) & CCDC_BLK_DC_SUB_MASK; 446 val = (bclamp->dc_sub) & CCDC_BLK_DC_SUB_MASK;
442 regw(val, CCDC_DCSUB); 447 regw(val, CCDC_DCSUB);
443 dev_dbg(dev, "\nWriting 0x%x to DCSUB...\n", val); 448 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to DCSUB...\n", val);
444 regw(CCDC_CLAMP_DEFAULT_VAL, CCDC_CLAMP); 449 regw(CCDC_CLAMP_DEFAULT_VAL, CCDC_CLAMP);
445 dev_dbg(dev, "\nWriting 0x0000 to CLAMP...\n"); 450 dev_dbg(ccdc_cfg.dev, "\nWriting 0x0000 to CLAMP...\n");
446 return; 451 return;
447 } 452 }
448 /* 453 /*
@@ -457,10 +462,10 @@ static void ccdc_config_black_clamp(struct ccdc_black_clamp *bclamp)
457 ((bclamp->sample_pixel & CCDC_BLK_SAMPLE_LN_MASK) << 462 ((bclamp->sample_pixel & CCDC_BLK_SAMPLE_LN_MASK) <<
458 CCDC_BLK_SAMPLE_LN_SHIFT) | CCDC_BLK_CLAMP_ENABLE); 463 CCDC_BLK_SAMPLE_LN_SHIFT) | CCDC_BLK_CLAMP_ENABLE);
459 regw(val, CCDC_CLAMP); 464 regw(val, CCDC_CLAMP);
460 dev_dbg(dev, "\nWriting 0x%x to CLAMP...\n", val); 465 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to CLAMP...\n", val);
461 /* If Black clamping is enable then make dcsub 0 */ 466 /* If Black clamping is enable then make dcsub 0 */
462 regw(CCDC_DCSUB_DEFAULT_VAL, CCDC_DCSUB); 467 regw(CCDC_DCSUB_DEFAULT_VAL, CCDC_DCSUB);
463 dev_dbg(dev, "\nWriting 0x00000000 to DCSUB...\n"); 468 dev_dbg(ccdc_cfg.dev, "\nWriting 0x00000000 to DCSUB...\n");
464} 469}
465 470
466static void ccdc_config_black_compense(struct ccdc_black_compensation *bcomp) 471static void ccdc_config_black_compense(struct ccdc_black_compensation *bcomp)
@@ -490,17 +495,17 @@ static void ccdc_config_fpc(struct ccdc_fault_pixel *fpc)
490 495
491 /* Configure Fault pixel if needed */ 496 /* Configure Fault pixel if needed */
492 regw(fpc->fpc_table_addr, CCDC_FPC_ADDR); 497 regw(fpc->fpc_table_addr, CCDC_FPC_ADDR);
493 dev_dbg(dev, "\nWriting 0x%x to FPC_ADDR...\n", 498 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC_ADDR...\n",
494 (fpc->fpc_table_addr)); 499 (fpc->fpc_table_addr));
495 /* Write the FPC params with FPC disable */ 500 /* Write the FPC params with FPC disable */
496 val = fpc->fp_num & CCDC_FPC_FPC_NUM_MASK; 501 val = fpc->fp_num & CCDC_FPC_FPC_NUM_MASK;
497 regw(val, CCDC_FPC); 502 regw(val, CCDC_FPC);
498 503
499 dev_dbg(dev, "\nWriting 0x%x to FPC...\n", val); 504 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC...\n", val);
500 /* read the FPC register */ 505 /* read the FPC register */
501 val = regr(CCDC_FPC) | CCDC_FPC_ENABLE; 506 val = regr(CCDC_FPC) | CCDC_FPC_ENABLE;
502 regw(val, CCDC_FPC); 507 regw(val, CCDC_FPC);
503 dev_dbg(dev, "\nWriting 0x%x to FPC...\n", val); 508 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC...\n", val);
504} 509}
505 510
506/* 511/*
@@ -509,13 +514,13 @@ static void ccdc_config_fpc(struct ccdc_fault_pixel *fpc)
509 */ 514 */
510void ccdc_config_raw(void) 515void ccdc_config_raw(void)
511{ 516{
512 struct ccdc_params_raw *params = &ccdc_hw_params_raw; 517 struct ccdc_params_raw *params = &ccdc_cfg.bayer;
513 struct ccdc_config_params_raw *config_params = 518 struct ccdc_config_params_raw *config_params =
514 &ccdc_hw_params_raw.config_params; 519 &ccdc_cfg.bayer.config_params;
515 unsigned int syn_mode = 0; 520 unsigned int syn_mode = 0;
516 unsigned int val; 521 unsigned int val;
517 522
518 dev_dbg(dev, "\nStarting ccdc_config_raw..."); 523 dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_config_raw...");
519 524
520 /* Reset CCDC */ 525 /* Reset CCDC */
521 ccdc_restore_defaults(); 526 ccdc_restore_defaults();
@@ -545,7 +550,7 @@ void ccdc_config_raw(void)
545 val = ((config_params->alaw.gama_wd & 550 val = ((config_params->alaw.gama_wd &
546 CCDC_ALAW_GAMA_WD_MASK) | CCDC_ALAW_ENABLE); 551 CCDC_ALAW_GAMA_WD_MASK) | CCDC_ALAW_ENABLE);
547 regw(val, CCDC_ALAW); 552 regw(val, CCDC_ALAW);
548 dev_dbg(dev, "\nWriting 0x%x to ALAW...\n", val); 553 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to ALAW...\n", val);
549 } 554 }
550 555
551 /* Configure video window */ 556 /* Configure video window */
@@ -582,11 +587,11 @@ void ccdc_config_raw(void)
582 /* Write value in FMTCFG */ 587 /* Write value in FMTCFG */
583 regw(val, CCDC_FMTCFG); 588 regw(val, CCDC_FMTCFG);
584 589
585 dev_dbg(dev, "\nWriting 0x%x to FMTCFG...\n", val); 590 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMTCFG...\n", val);
586 /* Configure the color pattern according to mt9t001 sensor */ 591 /* Configure the color pattern according to mt9t001 sensor */
587 regw(CCDC_COLPTN_VAL, CCDC_COLPTN); 592 regw(CCDC_COLPTN_VAL, CCDC_COLPTN);
588 593
589 dev_dbg(dev, "\nWriting 0xBB11BB11 to COLPTN...\n"); 594 dev_dbg(ccdc_cfg.dev, "\nWriting 0xBB11BB11 to COLPTN...\n");
590 /* 595 /*
591 * Configure Data formatter(Video port) pixel selection 596 * Configure Data formatter(Video port) pixel selection
592 * (FMT_HORZ, FMT_VERT) 597 * (FMT_HORZ, FMT_VERT)
@@ -596,7 +601,7 @@ void ccdc_config_raw(void)
596 (params->win.width & CCDC_FMT_HORZ_FMTLNH_MASK); 601 (params->win.width & CCDC_FMT_HORZ_FMTLNH_MASK);
597 regw(val, CCDC_FMT_HORZ); 602 regw(val, CCDC_FMT_HORZ);
598 603
599 dev_dbg(dev, "\nWriting 0x%x to FMT_HORZ...\n", val); 604 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMT_HORZ...\n", val);
600 val = (params->win.top & CCDC_FMT_VERT_FMTSLV_MASK) 605 val = (params->win.top & CCDC_FMT_VERT_FMTSLV_MASK)
601 << CCDC_FMT_VERT_FMTSLV_SHIFT; 606 << CCDC_FMT_VERT_FMTSLV_SHIFT;
602 if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) 607 if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE)
@@ -604,13 +609,13 @@ void ccdc_config_raw(void)
604 else 609 else
605 val |= (params->win.height >> 1) & CCDC_FMT_VERT_FMTLNV_MASK; 610 val |= (params->win.height >> 1) & CCDC_FMT_VERT_FMTLNV_MASK;
606 611
607 dev_dbg(dev, "\nparams->win.height 0x%x ...\n", 612 dev_dbg(ccdc_cfg.dev, "\nparams->win.height 0x%x ...\n",
608 params->win.height); 613 params->win.height);
609 regw(val, CCDC_FMT_VERT); 614 regw(val, CCDC_FMT_VERT);
610 615
611 dev_dbg(dev, "\nWriting 0x%x to FMT_VERT...\n", val); 616 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMT_VERT...\n", val);
612 617
613 dev_dbg(dev, "\nbelow regw(val, FMT_VERT)..."); 618 dev_dbg(ccdc_cfg.dev, "\nbelow regw(val, FMT_VERT)...");
614 619
615 /* 620 /*
616 * Configure Horizontal offset register. If pack 8 is enabled then 621 * Configure Horizontal offset register. If pack 8 is enabled then
@@ -631,17 +636,17 @@ void ccdc_config_raw(void)
631 if (params->image_invert_enable) { 636 if (params->image_invert_enable) {
632 /* For intelace inverse mode */ 637 /* For intelace inverse mode */
633 regw(CCDC_INTERLACED_IMAGE_INVERT, CCDC_SDOFST); 638 regw(CCDC_INTERLACED_IMAGE_INVERT, CCDC_SDOFST);
634 dev_dbg(dev, "\nWriting 0x4B6D to SDOFST...\n"); 639 dev_dbg(ccdc_cfg.dev, "\nWriting 0x4B6D to SDOFST..\n");
635 } 640 }
636 641
637 else { 642 else {
638 /* For intelace non inverse mode */ 643 /* For intelace non inverse mode */
639 regw(CCDC_INTERLACED_NO_IMAGE_INVERT, CCDC_SDOFST); 644 regw(CCDC_INTERLACED_NO_IMAGE_INVERT, CCDC_SDOFST);
640 dev_dbg(dev, "\nWriting 0x0249 to SDOFST...\n"); 645 dev_dbg(ccdc_cfg.dev, "\nWriting 0x0249 to SDOFST..\n");
641 } 646 }
642 } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) { 647 } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
643 regw(CCDC_PROGRESSIVE_NO_IMAGE_INVERT, CCDC_SDOFST); 648 regw(CCDC_PROGRESSIVE_NO_IMAGE_INVERT, CCDC_SDOFST);
644 dev_dbg(dev, "\nWriting 0x0000 to SDOFST...\n"); 649 dev_dbg(ccdc_cfg.dev, "\nWriting 0x0000 to SDOFST...\n");
645 } 650 }
646 651
647 /* 652 /*
@@ -662,18 +667,18 @@ void ccdc_config_raw(void)
662 val |= (params->win.left) & CCDC_VP_OUT_HORZ_ST_MASK; 667 val |= (params->win.left) & CCDC_VP_OUT_HORZ_ST_MASK;
663 regw(val, CCDC_VP_OUT); 668 regw(val, CCDC_VP_OUT);
664 669
665 dev_dbg(dev, "\nWriting 0x%x to VP_OUT...\n", val); 670 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to VP_OUT...\n", val);
666 regw(syn_mode, CCDC_SYN_MODE); 671 regw(syn_mode, CCDC_SYN_MODE);
667 dev_dbg(dev, "\nWriting 0x%x to SYN_MODE...\n", syn_mode); 672 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to SYN_MODE...\n", syn_mode);
668 673
669 ccdc_sbl_reset(); 674 ccdc_sbl_reset();
670 dev_dbg(dev, "\nend of ccdc_config_raw..."); 675 dev_dbg(ccdc_cfg.dev, "\nend of ccdc_config_raw...");
671 ccdc_readregs(); 676 ccdc_readregs();
672} 677}
673 678
674static int ccdc_configure(void) 679static int ccdc_configure(void)
675{ 680{
676 if (ccdc_if_type == VPFE_RAW_BAYER) 681 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
677 ccdc_config_raw(); 682 ccdc_config_raw();
678 else 683 else
679 ccdc_config_ycbcr(); 684 ccdc_config_ycbcr();
@@ -682,24 +687,24 @@ static int ccdc_configure(void)
682 687
683static int ccdc_set_buftype(enum ccdc_buftype buf_type) 688static int ccdc_set_buftype(enum ccdc_buftype buf_type)
684{ 689{
685 if (ccdc_if_type == VPFE_RAW_BAYER) 690 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
686 ccdc_hw_params_raw.buf_type = buf_type; 691 ccdc_cfg.bayer.buf_type = buf_type;
687 else 692 else
688 ccdc_hw_params_ycbcr.buf_type = buf_type; 693 ccdc_cfg.ycbcr.buf_type = buf_type;
689 return 0; 694 return 0;
690} 695}
691 696
692static enum ccdc_buftype ccdc_get_buftype(void) 697static enum ccdc_buftype ccdc_get_buftype(void)
693{ 698{
694 if (ccdc_if_type == VPFE_RAW_BAYER) 699 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
695 return ccdc_hw_params_raw.buf_type; 700 return ccdc_cfg.bayer.buf_type;
696 return ccdc_hw_params_ycbcr.buf_type; 701 return ccdc_cfg.ycbcr.buf_type;
697} 702}
698 703
699static int ccdc_enum_pix(u32 *pix, int i) 704static int ccdc_enum_pix(u32 *pix, int i)
700{ 705{
701 int ret = -EINVAL; 706 int ret = -EINVAL;
702 if (ccdc_if_type == VPFE_RAW_BAYER) { 707 if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
703 if (i < ARRAY_SIZE(ccdc_raw_bayer_pix_formats)) { 708 if (i < ARRAY_SIZE(ccdc_raw_bayer_pix_formats)) {
704 *pix = ccdc_raw_bayer_pix_formats[i]; 709 *pix = ccdc_raw_bayer_pix_formats[i];
705 ret = 0; 710 ret = 0;
@@ -715,17 +720,17 @@ static int ccdc_enum_pix(u32 *pix, int i)
715 720
716static int ccdc_set_pixel_format(u32 pixfmt) 721static int ccdc_set_pixel_format(u32 pixfmt)
717{ 722{
718 if (ccdc_if_type == VPFE_RAW_BAYER) { 723 if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
719 ccdc_hw_params_raw.pix_fmt = CCDC_PIXFMT_RAW; 724 ccdc_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
720 if (pixfmt == V4L2_PIX_FMT_SBGGR8) 725 if (pixfmt == V4L2_PIX_FMT_SBGGR8)
721 ccdc_hw_params_raw.config_params.alaw.enable = 1; 726 ccdc_cfg.bayer.config_params.alaw.enable = 1;
722 else if (pixfmt != V4L2_PIX_FMT_SBGGR16) 727 else if (pixfmt != V4L2_PIX_FMT_SBGGR16)
723 return -EINVAL; 728 return -EINVAL;
724 } else { 729 } else {
725 if (pixfmt == V4L2_PIX_FMT_YUYV) 730 if (pixfmt == V4L2_PIX_FMT_YUYV)
726 ccdc_hw_params_ycbcr.pix_order = CCDC_PIXORDER_YCBYCR; 731 ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_YCBYCR;
727 else if (pixfmt == V4L2_PIX_FMT_UYVY) 732 else if (pixfmt == V4L2_PIX_FMT_UYVY)
728 ccdc_hw_params_ycbcr.pix_order = CCDC_PIXORDER_CBYCRY; 733 ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
729 else 734 else
730 return -EINVAL; 735 return -EINVAL;
731 } 736 }
@@ -734,17 +739,16 @@ static int ccdc_set_pixel_format(u32 pixfmt)
734 739
735static u32 ccdc_get_pixel_format(void) 740static u32 ccdc_get_pixel_format(void)
736{ 741{
737 struct ccdc_a_law *alaw = 742 struct ccdc_a_law *alaw = &ccdc_cfg.bayer.config_params.alaw;
738 &ccdc_hw_params_raw.config_params.alaw;
739 u32 pixfmt; 743 u32 pixfmt;
740 744
741 if (ccdc_if_type == VPFE_RAW_BAYER) 745 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
742 if (alaw->enable) 746 if (alaw->enable)
743 pixfmt = V4L2_PIX_FMT_SBGGR8; 747 pixfmt = V4L2_PIX_FMT_SBGGR8;
744 else 748 else
745 pixfmt = V4L2_PIX_FMT_SBGGR16; 749 pixfmt = V4L2_PIX_FMT_SBGGR16;
746 else { 750 else {
747 if (ccdc_hw_params_ycbcr.pix_order == CCDC_PIXORDER_YCBYCR) 751 if (ccdc_cfg.ycbcr.pix_order == CCDC_PIXORDER_YCBYCR)
748 pixfmt = V4L2_PIX_FMT_YUYV; 752 pixfmt = V4L2_PIX_FMT_YUYV;
749 else 753 else
750 pixfmt = V4L2_PIX_FMT_UYVY; 754 pixfmt = V4L2_PIX_FMT_UYVY;
@@ -754,53 +758,53 @@ static u32 ccdc_get_pixel_format(void)
754 758
755static int ccdc_set_image_window(struct v4l2_rect *win) 759static int ccdc_set_image_window(struct v4l2_rect *win)
756{ 760{
757 if (ccdc_if_type == VPFE_RAW_BAYER) 761 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
758 ccdc_hw_params_raw.win = *win; 762 ccdc_cfg.bayer.win = *win;
759 else 763 else
760 ccdc_hw_params_ycbcr.win = *win; 764 ccdc_cfg.ycbcr.win = *win;
761 return 0; 765 return 0;
762} 766}
763 767
764static void ccdc_get_image_window(struct v4l2_rect *win) 768static void ccdc_get_image_window(struct v4l2_rect *win)
765{ 769{
766 if (ccdc_if_type == VPFE_RAW_BAYER) 770 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
767 *win = ccdc_hw_params_raw.win; 771 *win = ccdc_cfg.bayer.win;
768 else 772 else
769 *win = ccdc_hw_params_ycbcr.win; 773 *win = ccdc_cfg.ycbcr.win;
770} 774}
771 775
772static unsigned int ccdc_get_line_length(void) 776static unsigned int ccdc_get_line_length(void)
773{ 777{
774 struct ccdc_config_params_raw *config_params = 778 struct ccdc_config_params_raw *config_params =
775 &ccdc_hw_params_raw.config_params; 779 &ccdc_cfg.bayer.config_params;
776 unsigned int len; 780 unsigned int len;
777 781
778 if (ccdc_if_type == VPFE_RAW_BAYER) { 782 if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
779 if ((config_params->alaw.enable) || 783 if ((config_params->alaw.enable) ||
780 (config_params->data_sz == CCDC_DATA_8BITS)) 784 (config_params->data_sz == CCDC_DATA_8BITS))
781 len = ccdc_hw_params_raw.win.width; 785 len = ccdc_cfg.bayer.win.width;
782 else 786 else
783 len = ccdc_hw_params_raw.win.width * 2; 787 len = ccdc_cfg.bayer.win.width * 2;
784 } else 788 } else
785 len = ccdc_hw_params_ycbcr.win.width * 2; 789 len = ccdc_cfg.ycbcr.win.width * 2;
786 return ALIGN(len, 32); 790 return ALIGN(len, 32);
787} 791}
788 792
789static int ccdc_set_frame_format(enum ccdc_frmfmt frm_fmt) 793static int ccdc_set_frame_format(enum ccdc_frmfmt frm_fmt)
790{ 794{
791 if (ccdc_if_type == VPFE_RAW_BAYER) 795 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
792 ccdc_hw_params_raw.frm_fmt = frm_fmt; 796 ccdc_cfg.bayer.frm_fmt = frm_fmt;
793 else 797 else
794 ccdc_hw_params_ycbcr.frm_fmt = frm_fmt; 798 ccdc_cfg.ycbcr.frm_fmt = frm_fmt;
795 return 0; 799 return 0;
796} 800}
797 801
798static enum ccdc_frmfmt ccdc_get_frame_format(void) 802static enum ccdc_frmfmt ccdc_get_frame_format(void)
799{ 803{
800 if (ccdc_if_type == VPFE_RAW_BAYER) 804 if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
801 return ccdc_hw_params_raw.frm_fmt; 805 return ccdc_cfg.bayer.frm_fmt;
802 else 806 else
803 return ccdc_hw_params_ycbcr.frm_fmt; 807 return ccdc_cfg.ycbcr.frm_fmt;
804} 808}
805 809
806static int ccdc_getfid(void) 810static int ccdc_getfid(void)
@@ -816,14 +820,14 @@ static inline void ccdc_setfbaddr(unsigned long addr)
816 820
817static int ccdc_set_hw_if_params(struct vpfe_hw_if_param *params) 821static int ccdc_set_hw_if_params(struct vpfe_hw_if_param *params)
818{ 822{
819 ccdc_if_type = params->if_type; 823 ccdc_cfg.if_type = params->if_type;
820 824
821 switch (params->if_type) { 825 switch (params->if_type) {
822 case VPFE_BT656: 826 case VPFE_BT656:
823 case VPFE_YCBCR_SYNC_16: 827 case VPFE_YCBCR_SYNC_16:
824 case VPFE_YCBCR_SYNC_8: 828 case VPFE_YCBCR_SYNC_8:
825 ccdc_hw_params_ycbcr.vd_pol = params->vdpol; 829 ccdc_cfg.ycbcr.vd_pol = params->vdpol;
826 ccdc_hw_params_ycbcr.hd_pol = params->hdpol; 830 ccdc_cfg.ycbcr.hd_pol = params->hdpol;
827 break; 831 break;
828 default: 832 default:
829 /* TODO add support for raw bayer here */ 833 /* TODO add support for raw bayer here */
@@ -838,7 +842,6 @@ static struct ccdc_hw_device ccdc_hw_dev = {
838 .hw_ops = { 842 .hw_ops = {
839 .open = ccdc_open, 843 .open = ccdc_open,
840 .close = ccdc_close, 844 .close = ccdc_close,
841 .set_ccdc_base = ccdc_set_ccdc_base,
842 .reset = ccdc_sbl_reset, 845 .reset = ccdc_sbl_reset,
843 .enable = ccdc_enable, 846 .enable = ccdc_enable,
844 .set_hw_if_params = ccdc_set_hw_if_params, 847 .set_hw_if_params = ccdc_set_hw_if_params,
@@ -859,19 +862,105 @@ static struct ccdc_hw_device ccdc_hw_dev = {
859 }, 862 },
860}; 863};
861 864
862static int __init dm644x_ccdc_init(void) 865static int __init dm644x_ccdc_probe(struct platform_device *pdev)
863{ 866{
864 printk(KERN_NOTICE "dm644x_ccdc_init\n"); 867 struct resource *res;
865 if (vpfe_register_ccdc_device(&ccdc_hw_dev) < 0) 868 int status = 0;
866 return -1; 869
867 printk(KERN_NOTICE "%s is registered with vpfe.\n", 870 /*
868 ccdc_hw_dev.name); 871 * first try to register with vpfe. If not correct platform, then we
872 * don't have to iomap
873 */
874 status = vpfe_register_ccdc_device(&ccdc_hw_dev);
875 if (status < 0)
876 return status;
877
878 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
879 if (!res) {
880 status = -ENODEV;
881 goto fail_nores;
882 }
883
884 res = request_mem_region(res->start, resource_size(res), res->name);
885 if (!res) {
886 status = -EBUSY;
887 goto fail_nores;
888 }
889
890 ccdc_cfg.base_addr = ioremap_nocache(res->start, resource_size(res));
891 if (!ccdc_cfg.base_addr) {
892 status = -ENOMEM;
893 goto fail_nomem;
894 }
895
896 /* Get and enable Master clock */
897 ccdc_cfg.mclk = clk_get(&pdev->dev, "master");
898 if (IS_ERR(ccdc_cfg.mclk)) {
899 status = PTR_ERR(ccdc_cfg.mclk);
900 goto fail_nomap;
901 }
902 if (clk_enable(ccdc_cfg.mclk)) {
903 status = -ENODEV;
904 goto fail_mclk;
905 }
906
907 /* Get and enable Slave clock */
908 ccdc_cfg.sclk = clk_get(&pdev->dev, "slave");
909 if (IS_ERR(ccdc_cfg.sclk)) {
910 status = PTR_ERR(ccdc_cfg.sclk);
911 goto fail_mclk;
912 }
913 if (clk_enable(ccdc_cfg.sclk)) {
914 status = -ENODEV;
915 goto fail_sclk;
916 }
917 ccdc_cfg.dev = &pdev->dev;
918 printk(KERN_NOTICE "%s is registered with vpfe.\n", ccdc_hw_dev.name);
869 return 0; 919 return 0;
920fail_sclk:
921 clk_put(ccdc_cfg.sclk);
922fail_mclk:
923 clk_put(ccdc_cfg.mclk);
924fail_nomap:
925 iounmap(ccdc_cfg.base_addr);
926fail_nomem:
927 release_mem_region(res->start, resource_size(res));
928fail_nores:
929 vpfe_unregister_ccdc_device(&ccdc_hw_dev);
930 return status;
870} 931}
871 932
872static void __exit dm644x_ccdc_exit(void) 933static int dm644x_ccdc_remove(struct platform_device *pdev)
873{ 934{
935 struct resource *res;
936
937 clk_put(ccdc_cfg.mclk);
938 clk_put(ccdc_cfg.sclk);
939 iounmap(ccdc_cfg.base_addr);
940 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
941 if (res)
942 release_mem_region(res->start, resource_size(res));
874 vpfe_unregister_ccdc_device(&ccdc_hw_dev); 943 vpfe_unregister_ccdc_device(&ccdc_hw_dev);
944 return 0;
945}
946
947static struct platform_driver dm644x_ccdc_driver = {
948 .driver = {
949 .name = "dm644x_ccdc",
950 .owner = THIS_MODULE,
951 },
952 .remove = __devexit_p(dm644x_ccdc_remove),
953 .probe = dm644x_ccdc_probe,
954};
955
956static int __init dm644x_ccdc_init(void)
957{
958 return platform_driver_register(&dm644x_ccdc_driver);
959}
960
961static void __exit dm644x_ccdc_exit(void)
962{
963 platform_driver_unregister(&dm644x_ccdc_driver);
875} 964}
876 965
877module_init(dm644x_ccdc_init); 966module_init(dm644x_ccdc_init);
diff --git a/drivers/media/video/davinci/isif.c b/drivers/media/video/davinci/isif.c
new file mode 100644
index 000000000000..29c29c668596
--- /dev/null
+++ b/drivers/media/video/davinci/isif.c
@@ -0,0 +1,1172 @@
1/*
2 * Copyright (C) 2008-2009 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Image Sensor Interface (ISIF) driver
19 *
20 * This driver is for configuring the ISIF IP available on DM365 or any other
21 * TI SoCs. This is used for capturing yuv or bayer video or image data
22 * from a decoder or sensor. This IP is similar to the CCDC IP on DM355
23 * and DM6446, but with enhanced or additional ip blocks. The driver
24 * configures the ISIF upon commands from the vpfe bridge driver through
25 * ccdc_hw_device interface.
26 *
27 * TODO: 1) Raw bayer parameter settings and bayer capture
28 * 2) Add support for control ioctl
29 */
30#include <linux/delay.h>
31#include <linux/platform_device.h>
32#include <linux/uaccess.h>
33#include <linux/io.h>
34#include <linux/videodev2.h>
35#include <linux/clk.h>
36#include <linux/err.h>
37
38#include <mach/mux.h>
39
40#include <media/davinci/isif.h>
41#include <media/davinci/vpss.h>
42
43#include "isif_regs.h"
44#include "ccdc_hw_device.h"
45
46/* Defaults for module configuration parameters */
47static struct isif_config_params_raw isif_config_defaults = {
48 .linearize = {
49 .en = 0,
50 .corr_shft = ISIF_NO_SHIFT,
51 .scale_fact = {1, 0},
52 },
53 .df_csc = {
54 .df_or_csc = 0,
55 .csc = {
56 .en = 0,
57 },
58 },
59 .dfc = {
60 .en = 0,
61 },
62 .bclamp = {
63 .en = 0,
64 },
65 .gain_offset = {
66 .gain = {
67 .r_ye = {1, 0},
68 .gr_cy = {1, 0},
69 .gb_g = {1, 0},
70 .b_mg = {1, 0},
71 },
72 },
73 .culling = {
74 .hcpat_odd = 0xff,
75 .hcpat_even = 0xff,
76 .vcpat = 0xff,
77 },
78 .compress = {
79 .alg = ISIF_ALAW,
80 },
81};
82
83/* ISIF operation configuration */
84static struct isif_oper_config {
85 struct device *dev;
86 enum vpfe_hw_if_type if_type;
87 struct isif_ycbcr_config ycbcr;
88 struct isif_params_raw bayer;
89 enum isif_data_pack data_pack;
90 /* Master clock */
91 struct clk *mclk;
92 /* ISIF base address */
93 void __iomem *base_addr;
94 /* ISIF Linear Table 0 */
95 void __iomem *linear_tbl0_addr;
96 /* ISIF Linear Table 1 */
97 void __iomem *linear_tbl1_addr;
98} isif_cfg = {
99 .ycbcr = {
100 .pix_fmt = CCDC_PIXFMT_YCBCR_8BIT,
101 .frm_fmt = CCDC_FRMFMT_INTERLACED,
102 .win = ISIF_WIN_NTSC,
103 .fid_pol = VPFE_PINPOL_POSITIVE,
104 .vd_pol = VPFE_PINPOL_POSITIVE,
105 .hd_pol = VPFE_PINPOL_POSITIVE,
106 .pix_order = CCDC_PIXORDER_CBYCRY,
107 .buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED,
108 },
109 .bayer = {
110 .pix_fmt = CCDC_PIXFMT_RAW,
111 .frm_fmt = CCDC_FRMFMT_PROGRESSIVE,
112 .win = ISIF_WIN_VGA,
113 .fid_pol = VPFE_PINPOL_POSITIVE,
114 .vd_pol = VPFE_PINPOL_POSITIVE,
115 .hd_pol = VPFE_PINPOL_POSITIVE,
116 .gain = {
117 .r_ye = {1, 0},
118 .gr_cy = {1, 0},
119 .gb_g = {1, 0},
120 .b_mg = {1, 0},
121 },
122 .cfa_pat = ISIF_CFA_PAT_MOSAIC,
123 .data_msb = ISIF_BIT_MSB_11,
124 .config_params = {
125 .data_shift = ISIF_NO_SHIFT,
126 .col_pat_field0 = {
127 .olop = ISIF_GREEN_BLUE,
128 .olep = ISIF_BLUE,
129 .elop = ISIF_RED,
130 .elep = ISIF_GREEN_RED,
131 },
132 .col_pat_field1 = {
133 .olop = ISIF_GREEN_BLUE,
134 .olep = ISIF_BLUE,
135 .elop = ISIF_RED,
136 .elep = ISIF_GREEN_RED,
137 },
138 .test_pat_gen = 0,
139 },
140 },
141 .data_pack = ISIF_DATA_PACK8,
142};
143
144/* Raw Bayer formats */
145static const u32 isif_raw_bayer_pix_formats[] = {
146 V4L2_PIX_FMT_SBGGR8, V4L2_PIX_FMT_SBGGR16};
147
148/* Raw YUV formats */
149static const u32 isif_raw_yuv_pix_formats[] = {
150 V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_YUYV};
151
152/* register access routines */
153static inline u32 regr(u32 offset)
154{
155 return __raw_readl(isif_cfg.base_addr + offset);
156}
157
158static inline void regw(u32 val, u32 offset)
159{
160 __raw_writel(val, isif_cfg.base_addr + offset);
161}
162
163/* reg_modify() - read, modify and write register */
164static inline u32 reg_modify(u32 mask, u32 val, u32 offset)
165{
166 u32 new_val = (regr(offset) & ~mask) | (val & mask);
167
168 regw(new_val, offset);
169 return new_val;
170}
171
172static inline void regw_lin_tbl(u32 val, u32 offset, int i)
173{
174 if (!i)
175 __raw_writel(val, isif_cfg.linear_tbl0_addr + offset);
176 else
177 __raw_writel(val, isif_cfg.linear_tbl1_addr + offset);
178}
179
180static void isif_disable_all_modules(void)
181{
182 /* disable BC */
183 regw(0, CLAMPCFG);
184 /* disable vdfc */
185 regw(0, DFCCTL);
186 /* disable CSC */
187 regw(0, CSCCTL);
188 /* disable linearization */
189 regw(0, LINCFG0);
190 /* disable other modules here as they are supported */
191}
192
193static void isif_enable(int en)
194{
195 if (!en) {
196 /* Before disable isif, disable all ISIF modules */
197 isif_disable_all_modules();
198 /*
199 * wait for next VD. Assume lowest scan rate is 12 Hz. So
200 * 100 msec delay is good enough
201 */
202 msleep(100);
203 }
204 reg_modify(ISIF_SYNCEN_VDHDEN_MASK, en, SYNCEN);
205}
206
207static void isif_enable_output_to_sdram(int en)
208{
209 reg_modify(ISIF_SYNCEN_WEN_MASK, en << ISIF_SYNCEN_WEN_SHIFT, SYNCEN);
210}
211
212static void isif_config_culling(struct isif_cul *cul)
213{
214 u32 val;
215
216 /* Horizontal pattern */
217 val = (cul->hcpat_even << CULL_PAT_EVEN_LINE_SHIFT) | cul->hcpat_odd;
218 regw(val, CULH);
219
220 /* vertical pattern */
221 regw(cul->vcpat, CULV);
222
223 /* LPF */
224 reg_modify(ISIF_LPF_MASK << ISIF_LPF_SHIFT,
225 cul->en_lpf << ISIF_LPF_SHIFT, MODESET);
226}
227
228static void isif_config_gain_offset(void)
229{
230 struct isif_gain_offsets_adj *gain_off_p =
231 &isif_cfg.bayer.config_params.gain_offset;
232 u32 val;
233
234 val = (!!gain_off_p->gain_sdram_en << GAIN_SDRAM_EN_SHIFT) |
235 (!!gain_off_p->gain_ipipe_en << GAIN_IPIPE_EN_SHIFT) |
236 (!!gain_off_p->gain_h3a_en << GAIN_H3A_EN_SHIFT) |
237 (!!gain_off_p->offset_sdram_en << OFST_SDRAM_EN_SHIFT) |
238 (!!gain_off_p->offset_ipipe_en << OFST_IPIPE_EN_SHIFT) |
239 (!!gain_off_p->offset_h3a_en << OFST_H3A_EN_SHIFT);
240
241 reg_modify(GAIN_OFFSET_EN_MASK, val, CGAMMAWD);
242
243 val = (gain_off_p->gain.r_ye.integer << GAIN_INTEGER_SHIFT) |
244 gain_off_p->gain.r_ye.decimal;
245 regw(val, CRGAIN);
246
247 val = (gain_off_p->gain.gr_cy.integer << GAIN_INTEGER_SHIFT) |
248 gain_off_p->gain.gr_cy.decimal;
249 regw(val, CGRGAIN);
250
251 val = (gain_off_p->gain.gb_g.integer << GAIN_INTEGER_SHIFT) |
252 gain_off_p->gain.gb_g.decimal;
253 regw(val, CGBGAIN);
254
255 val = (gain_off_p->gain.b_mg.integer << GAIN_INTEGER_SHIFT) |
256 gain_off_p->gain.b_mg.decimal;
257 regw(val, CBGAIN);
258
259 regw(gain_off_p->offset, COFSTA);
260}
261
262static void isif_restore_defaults(void)
263{
264 enum vpss_ccdc_source_sel source = VPSS_CCDCIN;
265
266 dev_dbg(isif_cfg.dev, "\nstarting isif_restore_defaults...");
267 isif_cfg.bayer.config_params = isif_config_defaults;
268 /* Enable clock to ISIF, IPIPEIF and BL */
269 vpss_enable_clock(VPSS_CCDC_CLOCK, 1);
270 vpss_enable_clock(VPSS_IPIPEIF_CLOCK, 1);
271 vpss_enable_clock(VPSS_BL_CLOCK, 1);
272 /* Set default offset and gain */
273 isif_config_gain_offset();
274 vpss_select_ccdc_source(source);
275 dev_dbg(isif_cfg.dev, "\nEnd of isif_restore_defaults...");
276}
277
278static int isif_open(struct device *device)
279{
280 isif_restore_defaults();
281 return 0;
282}
283
284/* This function will configure the window size to be capture in ISIF reg */
285static void isif_setwin(struct v4l2_rect *image_win,
286 enum ccdc_frmfmt frm_fmt, int ppc)
287{
288 int horz_start, horz_nr_pixels;
289 int vert_start, vert_nr_lines;
290 int mid_img = 0;
291
292 dev_dbg(isif_cfg.dev, "\nStarting isif_setwin...");
293 /*
294 * ppc - per pixel count. indicates how many pixels per cell
295 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
296 * raw capture this is 1
297 */
298 horz_start = image_win->left << (ppc - 1);
299 horz_nr_pixels = ((image_win->width) << (ppc - 1)) - 1;
300
301 /* Writing the horizontal info into the registers */
302 regw(horz_start & START_PX_HOR_MASK, SPH);
303 regw(horz_nr_pixels & NUM_PX_HOR_MASK, LNH);
304 vert_start = image_win->top;
305
306 if (frm_fmt == CCDC_FRMFMT_INTERLACED) {
307 vert_nr_lines = (image_win->height >> 1) - 1;
308 vert_start >>= 1;
309 /* To account for VD since line 0 doesn't have any data */
310 vert_start += 1;
311 } else {
312 /* To account for VD since line 0 doesn't have any data */
313 vert_start += 1;
314 vert_nr_lines = image_win->height - 1;
315 /* configure VDINT0 and VDINT1 */
316 mid_img = vert_start + (image_win->height / 2);
317 regw(mid_img, VDINT1);
318 }
319
320 regw(0, VDINT0);
321 regw(vert_start & START_VER_ONE_MASK, SLV0);
322 regw(vert_start & START_VER_TWO_MASK, SLV1);
323 regw(vert_nr_lines & NUM_LINES_VER, LNV);
324}
325
326static void isif_config_bclamp(struct isif_black_clamp *bc)
327{
328 u32 val;
329
330 /*
331 * DC Offset is always added to image data irrespective of bc enable
332 * status
333 */
334 regw(bc->dc_offset, CLDCOFST);
335
336 if (bc->en) {
337 val = bc->bc_mode_color << ISIF_BC_MODE_COLOR_SHIFT;
338
339 /* Enable BC and horizontal clamp caculation paramaters */
340 val = val | 1 | (bc->horz.mode << ISIF_HORZ_BC_MODE_SHIFT);
341
342 regw(val, CLAMPCFG);
343
344 if (bc->horz.mode != ISIF_HORZ_BC_DISABLE) {
345 /*
346 * Window count for calculation
347 * Base window selection
348 * pixel limit
349 * Horizontal size of window
350 * vertical size of the window
351 * Horizontal start position of the window
352 * Vertical start position of the window
353 */
354 val = bc->horz.win_count_calc |
355 ((!!bc->horz.base_win_sel_calc) <<
356 ISIF_HORZ_BC_WIN_SEL_SHIFT) |
357 ((!!bc->horz.clamp_pix_limit) <<
358 ISIF_HORZ_BC_PIX_LIMIT_SHIFT) |
359 (bc->horz.win_h_sz_calc <<
360 ISIF_HORZ_BC_WIN_H_SIZE_SHIFT) |
361 (bc->horz.win_v_sz_calc <<
362 ISIF_HORZ_BC_WIN_V_SIZE_SHIFT);
363 regw(val, CLHWIN0);
364
365 regw(bc->horz.win_start_h_calc, CLHWIN1);
366 regw(bc->horz.win_start_v_calc, CLHWIN2);
367 }
368
369 /* vertical clamp caculation paramaters */
370
371 /* Reset clamp value sel for previous line */
372 val |=
373 (bc->vert.reset_val_sel << ISIF_VERT_BC_RST_VAL_SEL_SHIFT) |
374 (bc->vert.line_ave_coef << ISIF_VERT_BC_LINE_AVE_COEF_SHIFT);
375 regw(val, CLVWIN0);
376
377 /* Optical Black horizontal start position */
378 regw(bc->vert.ob_start_h, CLVWIN1);
379 /* Optical Black vertical start position */
380 regw(bc->vert.ob_start_v, CLVWIN2);
381 /* Optical Black vertical size for calculation */
382 regw(bc->vert.ob_v_sz_calc, CLVWIN3);
383 /* Vertical start position for BC subtraction */
384 regw(bc->vert_start_sub, CLSV);
385 }
386}
387
388static void isif_config_linearization(struct isif_linearize *linearize)
389{
390 u32 val, i;
391
392 if (!linearize->en) {
393 regw(0, LINCFG0);
394 return;
395 }
396
397 /* shift value for correction & enable linearization (set lsb) */
398 val = (linearize->corr_shft << ISIF_LIN_CORRSFT_SHIFT) | 1;
399 regw(val, LINCFG0);
400
401 /* Scale factor */
402 val = ((!!linearize->scale_fact.integer) <<
403 ISIF_LIN_SCALE_FACT_INTEG_SHIFT) |
404 linearize->scale_fact.decimal;
405 regw(val, LINCFG1);
406
407 for (i = 0; i < ISIF_LINEAR_TAB_SIZE; i++) {
408 if (i % 2)
409 regw_lin_tbl(linearize->table[i], ((i >> 1) << 2), 1);
410 else
411 regw_lin_tbl(linearize->table[i], ((i >> 1) << 2), 0);
412 }
413}
414
415static int isif_config_dfc(struct isif_dfc *vdfc)
416{
417 /* initialize retries to loop for max ~ 250 usec */
418 u32 val, count, retries = loops_per_jiffy / (4000/HZ);
419 int i;
420
421 if (!vdfc->en)
422 return 0;
423
424 /* Correction mode */
425 val = (vdfc->corr_mode << ISIF_VDFC_CORR_MOD_SHIFT);
426
427 /* Correct whole line or partial */
428 if (vdfc->corr_whole_line)
429 val |= 1 << ISIF_VDFC_CORR_WHOLE_LN_SHIFT;
430
431 /* level shift value */
432 val |= vdfc->def_level_shift << ISIF_VDFC_LEVEL_SHFT_SHIFT;
433
434 regw(val, DFCCTL);
435
436 /* Defect saturation level */
437 regw(vdfc->def_sat_level, VDFSATLV);
438
439 regw(vdfc->table[0].pos_vert, DFCMEM0);
440 regw(vdfc->table[0].pos_horz, DFCMEM1);
441 if (vdfc->corr_mode == ISIF_VDFC_NORMAL ||
442 vdfc->corr_mode == ISIF_VDFC_HORZ_INTERPOL_IF_SAT) {
443 regw(vdfc->table[0].level_at_pos, DFCMEM2);
444 regw(vdfc->table[0].level_up_pixels, DFCMEM3);
445 regw(vdfc->table[0].level_low_pixels, DFCMEM4);
446 }
447
448 /* set DFCMARST and set DFCMWR */
449 val = regr(DFCMEMCTL) | (1 << ISIF_DFCMEMCTL_DFCMARST_SHIFT) | 1;
450 regw(val, DFCMEMCTL);
451
452 count = retries;
453 while (count && (regr(DFCMEMCTL) & 0x1))
454 count--;
455
456 if (!count) {
457 dev_dbg(isif_cfg.dev, "defect table write timeout !!!\n");
458 return -1;
459 }
460
461 for (i = 1; i < vdfc->num_vdefects; i++) {
462 regw(vdfc->table[i].pos_vert, DFCMEM0);
463 regw(vdfc->table[i].pos_horz, DFCMEM1);
464 if (vdfc->corr_mode == ISIF_VDFC_NORMAL ||
465 vdfc->corr_mode == ISIF_VDFC_HORZ_INTERPOL_IF_SAT) {
466 regw(vdfc->table[i].level_at_pos, DFCMEM2);
467 regw(vdfc->table[i].level_up_pixels, DFCMEM3);
468 regw(vdfc->table[i].level_low_pixels, DFCMEM4);
469 }
470 val = regr(DFCMEMCTL);
471 /* clear DFCMARST and set DFCMWR */
472 val &= ~BIT(ISIF_DFCMEMCTL_DFCMARST_SHIFT);
473 val |= 1;
474 regw(val, DFCMEMCTL);
475
476 count = retries;
477 while (count && (regr(DFCMEMCTL) & 0x1))
478 count--;
479
480 if (!count) {
481 dev_err(isif_cfg.dev,
482 "defect table write timeout !!!\n");
483 return -1;
484 }
485 }
486 if (vdfc->num_vdefects < ISIF_VDFC_TABLE_SIZE) {
487 /* Extra cycle needed */
488 regw(0, DFCMEM0);
489 regw(0x1FFF, DFCMEM1);
490 regw(1, DFCMEMCTL);
491 }
492
493 /* enable VDFC */
494 reg_modify((1 << ISIF_VDFC_EN_SHIFT), (1 << ISIF_VDFC_EN_SHIFT),
495 DFCCTL);
496 return 0;
497}
498
499static void isif_config_csc(struct isif_df_csc *df_csc)
500{
501 u32 val1 = 0, val2 = 0, i;
502
503 if (!df_csc->csc.en) {
504 regw(0, CSCCTL);
505 return;
506 }
507 for (i = 0; i < ISIF_CSC_NUM_COEFF; i++) {
508 if ((i % 2) == 0) {
509 /* CSCM - LSB */
510 val1 = (df_csc->csc.coeff[i].integer <<
511 ISIF_CSC_COEF_INTEG_SHIFT) |
512 df_csc->csc.coeff[i].decimal;
513 } else {
514
515 /* CSCM - MSB */
516 val2 = (df_csc->csc.coeff[i].integer <<
517 ISIF_CSC_COEF_INTEG_SHIFT) |
518 df_csc->csc.coeff[i].decimal;
519 val2 <<= ISIF_CSCM_MSB_SHIFT;
520 val2 |= val1;
521 regw(val2, (CSCM0 + ((i - 1) << 1)));
522 }
523 }
524
525 /* program the active area */
526 regw(df_csc->start_pix, FMTSPH);
527 /*
528 * one extra pixel as required for CSC. Actually number of
529 * pixel - 1 should be configured in this register. So we
530 * need to subtract 1 before writing to FMTSPH, but we will
531 * not do this since csc requires one extra pixel
532 */
533 regw(df_csc->num_pixels, FMTLNH);
534 regw(df_csc->start_line, FMTSLV);
535 /*
536 * one extra line as required for CSC. See reason documented for
537 * num_pixels
538 */
539 regw(df_csc->num_lines, FMTLNV);
540
541 /* Enable CSC */
542 regw(1, CSCCTL);
543}
544
545static int isif_config_raw(void)
546{
547 struct isif_params_raw *params = &isif_cfg.bayer;
548 struct isif_config_params_raw *module_params =
549 &isif_cfg.bayer.config_params;
550 struct vpss_pg_frame_size frame_size;
551 struct vpss_sync_pol sync;
552 u32 val;
553
554 dev_dbg(isif_cfg.dev, "\nStarting isif_config_raw..\n");
555
556 /*
557 * Configure CCDCFG register:-
558 * Set CCD Not to swap input since input is RAW data
559 * Set FID detection function to Latch at V-Sync
560 * Set WENLOG - isif valid area
561 * Set TRGSEL
562 * Set EXTRG
563 * Packed to 8 or 16 bits
564 */
565
566 val = ISIF_YCINSWP_RAW | ISIF_CCDCFG_FIDMD_LATCH_VSYNC |
567 ISIF_CCDCFG_WENLOG_AND | ISIF_CCDCFG_TRGSEL_WEN |
568 ISIF_CCDCFG_EXTRG_DISABLE | isif_cfg.data_pack;
569
570 dev_dbg(isif_cfg.dev, "Writing 0x%x to ...CCDCFG \n", val);
571 regw(val, CCDCFG);
572
573 /*
574 * Configure the vertical sync polarity(MODESET.VDPOL)
575 * Configure the horizontal sync polarity (MODESET.HDPOL)
576 * Configure frame id polarity (MODESET.FLDPOL)
577 * Configure data polarity
578 * Configure External WEN Selection
579 * Configure frame format(progressive or interlace)
580 * Configure pixel format (Input mode)
581 * Configure the data shift
582 */
583
584 val = ISIF_VDHDOUT_INPUT | (params->vd_pol << ISIF_VD_POL_SHIFT) |
585 (params->hd_pol << ISIF_HD_POL_SHIFT) |
586 (params->fid_pol << ISIF_FID_POL_SHIFT) |
587 (ISIF_DATAPOL_NORMAL << ISIF_DATAPOL_SHIFT) |
588 (ISIF_EXWEN_DISABLE << ISIF_EXWEN_SHIFT) |
589 (params->frm_fmt << ISIF_FRM_FMT_SHIFT) |
590 (params->pix_fmt << ISIF_INPUT_SHIFT) |
591 (params->config_params.data_shift << ISIF_DATASFT_SHIFT);
592
593 regw(val, MODESET);
594 dev_dbg(isif_cfg.dev, "Writing 0x%x to MODESET...\n", val);
595
596 /*
597 * Configure GAMMAWD register
598 * CFA pattern setting
599 */
600 val = params->cfa_pat << ISIF_GAMMAWD_CFA_SHIFT;
601
602 /* Gamma msb */
603 if (module_params->compress.alg == ISIF_ALAW)
604 val |= ISIF_ALAW_ENABLE;
605
606 val |= (params->data_msb << ISIF_ALAW_GAMA_WD_SHIFT);
607 regw(val, CGAMMAWD);
608
609 /* Configure DPCM compression settings */
610 if (module_params->compress.alg == ISIF_DPCM) {
611 val = BIT(ISIF_DPCM_EN_SHIFT) |
612 (module_params->compress.pred <<
613 ISIF_DPCM_PREDICTOR_SHIFT);
614 }
615
616 regw(val, MISC);
617
618 /* Configure Gain & Offset */
619 isif_config_gain_offset();
620
621 /* Configure Color pattern */
622 val = (params->config_params.col_pat_field0.olop) |
623 (params->config_params.col_pat_field0.olep << 2) |
624 (params->config_params.col_pat_field0.elop << 4) |
625 (params->config_params.col_pat_field0.elep << 6) |
626 (params->config_params.col_pat_field1.olop << 8) |
627 (params->config_params.col_pat_field1.olep << 10) |
628 (params->config_params.col_pat_field1.elop << 12) |
629 (params->config_params.col_pat_field1.elep << 14);
630 regw(val, CCOLP);
631 dev_dbg(isif_cfg.dev, "Writing %x to CCOLP ...\n", val);
632
633 /* Configure HSIZE register */
634 val = (!!params->horz_flip_en) << ISIF_HSIZE_FLIP_SHIFT;
635
636 /* calculate line offset in 32 bytes based on pack value */
637 if (isif_cfg.data_pack == ISIF_PACK_8BIT)
638 val |= ((params->win.width + 31) >> 5);
639 else if (isif_cfg.data_pack == ISIF_PACK_12BIT)
640 val |= (((params->win.width +
641 (params->win.width >> 2)) + 31) >> 5);
642 else
643 val |= (((params->win.width * 2) + 31) >> 5);
644 regw(val, HSIZE);
645
646 /* Configure SDOFST register */
647 if (params->frm_fmt == CCDC_FRMFMT_INTERLACED) {
648 if (params->image_invert_en) {
649 /* For interlace inverse mode */
650 regw(0x4B6D, SDOFST);
651 dev_dbg(isif_cfg.dev, "Writing 0x4B6D to SDOFST...\n");
652 } else {
653 /* For interlace non inverse mode */
654 regw(0x0B6D, SDOFST);
655 dev_dbg(isif_cfg.dev, "Writing 0x0B6D to SDOFST...\n");
656 }
657 } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
658 if (params->image_invert_en) {
659 /* For progressive inverse mode */
660 regw(0x4000, SDOFST);
661 dev_dbg(isif_cfg.dev, "Writing 0x4000 to SDOFST...\n");
662 } else {
663 /* For progressive non inverse mode */
664 regw(0x0000, SDOFST);
665 dev_dbg(isif_cfg.dev, "Writing 0x0000 to SDOFST...\n");
666 }
667 }
668
669 /* Configure video window */
670 isif_setwin(&params->win, params->frm_fmt, 1);
671
672 /* Configure Black Clamp */
673 isif_config_bclamp(&module_params->bclamp);
674
675 /* Configure Vertical Defection Pixel Correction */
676 if (isif_config_dfc(&module_params->dfc) < 0)
677 return -EFAULT;
678
679 if (!module_params->df_csc.df_or_csc)
680 /* Configure Color Space Conversion */
681 isif_config_csc(&module_params->df_csc);
682
683 isif_config_linearization(&module_params->linearize);
684
685 /* Configure Culling */
686 isif_config_culling(&module_params->culling);
687
688 /* Configure horizontal and vertical offsets(DFC,LSC,Gain) */
689 regw(module_params->horz_offset, DATAHOFST);
690 regw(module_params->vert_offset, DATAVOFST);
691
692 /* Setup test pattern if enabled */
693 if (params->config_params.test_pat_gen) {
694 /* Use the HD/VD pol settings from user */
695 sync.ccdpg_hdpol = params->hd_pol;
696 sync.ccdpg_vdpol = params->vd_pol;
697 dm365_vpss_set_sync_pol(sync);
698 frame_size.hlpfr = isif_cfg.bayer.win.width;
699 frame_size.pplen = isif_cfg.bayer.win.height;
700 dm365_vpss_set_pg_frame_size(frame_size);
701 vpss_select_ccdc_source(VPSS_PGLPBK);
702 }
703
704 dev_dbg(isif_cfg.dev, "\nEnd of isif_config_ycbcr...\n");
705 return 0;
706}
707
708static int isif_set_buftype(enum ccdc_buftype buf_type)
709{
710 if (isif_cfg.if_type == VPFE_RAW_BAYER)
711 isif_cfg.bayer.buf_type = buf_type;
712 else
713 isif_cfg.ycbcr.buf_type = buf_type;
714
715 return 0;
716
717}
718static enum ccdc_buftype isif_get_buftype(void)
719{
720 if (isif_cfg.if_type == VPFE_RAW_BAYER)
721 return isif_cfg.bayer.buf_type;
722
723 return isif_cfg.ycbcr.buf_type;
724}
725
726static int isif_enum_pix(u32 *pix, int i)
727{
728 int ret = -EINVAL;
729
730 if (isif_cfg.if_type == VPFE_RAW_BAYER) {
731 if (i < ARRAY_SIZE(isif_raw_bayer_pix_formats)) {
732 *pix = isif_raw_bayer_pix_formats[i];
733 ret = 0;
734 }
735 } else {
736 if (i < ARRAY_SIZE(isif_raw_yuv_pix_formats)) {
737 *pix = isif_raw_yuv_pix_formats[i];
738 ret = 0;
739 }
740 }
741
742 return ret;
743}
744
745static int isif_set_pixel_format(unsigned int pixfmt)
746{
747 if (isif_cfg.if_type == VPFE_RAW_BAYER) {
748 if (pixfmt == V4L2_PIX_FMT_SBGGR8) {
749 if ((isif_cfg.bayer.config_params.compress.alg !=
750 ISIF_ALAW) &&
751 (isif_cfg.bayer.config_params.compress.alg !=
752 ISIF_DPCM)) {
753 dev_dbg(isif_cfg.dev,
754 "Either configure A-Law or DPCM\n");
755 return -EINVAL;
756 }
757 isif_cfg.data_pack = ISIF_PACK_8BIT;
758 } else if (pixfmt == V4L2_PIX_FMT_SBGGR16) {
759 isif_cfg.bayer.config_params.compress.alg =
760 ISIF_NO_COMPRESSION;
761 isif_cfg.data_pack = ISIF_PACK_16BIT;
762 } else
763 return -EINVAL;
764 isif_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
765 } else {
766 if (pixfmt == V4L2_PIX_FMT_YUYV)
767 isif_cfg.ycbcr.pix_order = CCDC_PIXORDER_YCBYCR;
768 else if (pixfmt == V4L2_PIX_FMT_UYVY)
769 isif_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
770 else
771 return -EINVAL;
772 isif_cfg.data_pack = ISIF_PACK_8BIT;
773 }
774 return 0;
775}
776
777static u32 isif_get_pixel_format(void)
778{
779 u32 pixfmt;
780
781 if (isif_cfg.if_type == VPFE_RAW_BAYER)
782 if (isif_cfg.bayer.config_params.compress.alg == ISIF_ALAW ||
783 isif_cfg.bayer.config_params.compress.alg == ISIF_DPCM)
784 pixfmt = V4L2_PIX_FMT_SBGGR8;
785 else
786 pixfmt = V4L2_PIX_FMT_SBGGR16;
787 else {
788 if (isif_cfg.ycbcr.pix_order == CCDC_PIXORDER_YCBYCR)
789 pixfmt = V4L2_PIX_FMT_YUYV;
790 else
791 pixfmt = V4L2_PIX_FMT_UYVY;
792 }
793 return pixfmt;
794}
795
796static int isif_set_image_window(struct v4l2_rect *win)
797{
798 if (isif_cfg.if_type == VPFE_RAW_BAYER) {
799 isif_cfg.bayer.win.top = win->top;
800 isif_cfg.bayer.win.left = win->left;
801 isif_cfg.bayer.win.width = win->width;
802 isif_cfg.bayer.win.height = win->height;
803 } else {
804 isif_cfg.ycbcr.win.top = win->top;
805 isif_cfg.ycbcr.win.left = win->left;
806 isif_cfg.ycbcr.win.width = win->width;
807 isif_cfg.ycbcr.win.height = win->height;
808 }
809 return 0;
810}
811
812static void isif_get_image_window(struct v4l2_rect *win)
813{
814 if (isif_cfg.if_type == VPFE_RAW_BAYER)
815 *win = isif_cfg.bayer.win;
816 else
817 *win = isif_cfg.ycbcr.win;
818}
819
820static unsigned int isif_get_line_length(void)
821{
822 unsigned int len;
823
824 if (isif_cfg.if_type == VPFE_RAW_BAYER) {
825 if (isif_cfg.data_pack == ISIF_PACK_8BIT)
826 len = ((isif_cfg.bayer.win.width));
827 else if (isif_cfg.data_pack == ISIF_PACK_12BIT)
828 len = (((isif_cfg.bayer.win.width * 2) +
829 (isif_cfg.bayer.win.width >> 2)));
830 else
831 len = (((isif_cfg.bayer.win.width * 2)));
832 } else
833 len = (((isif_cfg.ycbcr.win.width * 2)));
834 return ALIGN(len, 32);
835}
836
837static int isif_set_frame_format(enum ccdc_frmfmt frm_fmt)
838{
839 if (isif_cfg.if_type == VPFE_RAW_BAYER)
840 isif_cfg.bayer.frm_fmt = frm_fmt;
841 else
842 isif_cfg.ycbcr.frm_fmt = frm_fmt;
843 return 0;
844}
845static enum ccdc_frmfmt isif_get_frame_format(void)
846{
847 if (isif_cfg.if_type == VPFE_RAW_BAYER)
848 return isif_cfg.bayer.frm_fmt;
849 return isif_cfg.ycbcr.frm_fmt;
850}
851
852static int isif_getfid(void)
853{
854 return (regr(MODESET) >> 15) & 0x1;
855}
856
857/* misc operations */
858static void isif_setfbaddr(unsigned long addr)
859{
860 regw((addr >> 21) & 0x07ff, CADU);
861 regw((addr >> 5) & 0x0ffff, CADL);
862}
863
864static int isif_set_hw_if_params(struct vpfe_hw_if_param *params)
865{
866 isif_cfg.if_type = params->if_type;
867
868 switch (params->if_type) {
869 case VPFE_BT656:
870 case VPFE_BT656_10BIT:
871 case VPFE_YCBCR_SYNC_8:
872 isif_cfg.ycbcr.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
873 isif_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
874 break;
875 case VPFE_BT1120:
876 case VPFE_YCBCR_SYNC_16:
877 isif_cfg.ycbcr.pix_fmt = CCDC_PIXFMT_YCBCR_16BIT;
878 isif_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
879 break;
880 case VPFE_RAW_BAYER:
881 isif_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
882 break;
883 default:
884 dev_dbg(isif_cfg.dev, "Invalid interface type\n");
885 return -EINVAL;
886 }
887
888 return 0;
889}
890
891/* This function will configure ISIF for YCbCr parameters. */
892static int isif_config_ycbcr(void)
893{
894 struct isif_ycbcr_config *params = &isif_cfg.ycbcr;
895 struct vpss_pg_frame_size frame_size;
896 u32 modeset = 0, ccdcfg = 0;
897 struct vpss_sync_pol sync;
898
899 dev_dbg(isif_cfg.dev, "\nStarting isif_config_ycbcr...");
900
901 /* configure pixel format or input mode */
902 modeset = modeset | (params->pix_fmt << ISIF_INPUT_SHIFT) |
903 (params->frm_fmt << ISIF_FRM_FMT_SHIFT) |
904 (params->fid_pol << ISIF_FID_POL_SHIFT) |
905 (params->hd_pol << ISIF_HD_POL_SHIFT) |
906 (params->vd_pol << ISIF_VD_POL_SHIFT);
907
908 /* pack the data to 8-bit ISIFCFG */
909 switch (isif_cfg.if_type) {
910 case VPFE_BT656:
911 if (params->pix_fmt != CCDC_PIXFMT_YCBCR_8BIT) {
912 dev_dbg(isif_cfg.dev, "Invalid pix_fmt(input mode)\n");
913 return -EINVAL;
914 }
915 modeset |= (VPFE_PINPOL_NEGATIVE << ISIF_VD_POL_SHIFT);
916 regw(3, REC656IF);
917 ccdcfg = ccdcfg | ISIF_DATA_PACK8 | ISIF_YCINSWP_YCBCR;
918 break;
919 case VPFE_BT656_10BIT:
920 if (params->pix_fmt != CCDC_PIXFMT_YCBCR_8BIT) {
921 dev_dbg(isif_cfg.dev, "Invalid pix_fmt(input mode)\n");
922 return -EINVAL;
923 }
924 /* setup BT.656, embedded sync */
925 regw(3, REC656IF);
926 /* enable 10 bit mode in ccdcfg */
927 ccdcfg = ccdcfg | ISIF_DATA_PACK8 | ISIF_YCINSWP_YCBCR |
928 ISIF_BW656_ENABLE;
929 break;
930 case VPFE_BT1120:
931 if (params->pix_fmt != CCDC_PIXFMT_YCBCR_16BIT) {
932 dev_dbg(isif_cfg.dev, "Invalid pix_fmt(input mode)\n");
933 return -EINVAL;
934 }
935 regw(3, REC656IF);
936 break;
937
938 case VPFE_YCBCR_SYNC_8:
939 ccdcfg |= ISIF_DATA_PACK8;
940 ccdcfg |= ISIF_YCINSWP_YCBCR;
941 if (params->pix_fmt != CCDC_PIXFMT_YCBCR_8BIT) {
942 dev_dbg(isif_cfg.dev, "Invalid pix_fmt(input mode)\n");
943 return -EINVAL;
944 }
945 break;
946 case VPFE_YCBCR_SYNC_16:
947 if (params->pix_fmt != CCDC_PIXFMT_YCBCR_16BIT) {
948 dev_dbg(isif_cfg.dev, "Invalid pix_fmt(input mode)\n");
949 return -EINVAL;
950 }
951 break;
952 default:
953 /* should never come here */
954 dev_dbg(isif_cfg.dev, "Invalid interface type\n");
955 return -EINVAL;
956 }
957
958 regw(modeset, MODESET);
959
960 /* Set up pix order */
961 ccdcfg |= params->pix_order << ISIF_PIX_ORDER_SHIFT;
962
963 regw(ccdcfg, CCDCFG);
964
965 /* configure video window */
966 if ((isif_cfg.if_type == VPFE_BT1120) ||
967 (isif_cfg.if_type == VPFE_YCBCR_SYNC_16))
968 isif_setwin(&params->win, params->frm_fmt, 1);
969 else
970 isif_setwin(&params->win, params->frm_fmt, 2);
971
972 /*
973 * configure the horizontal line offset
974 * this is done by rounding up width to a multiple of 16 pixels
975 * and multiply by two to account for y:cb:cr 4:2:2 data
976 */
977 regw(((((params->win.width * 2) + 31) & 0xffffffe0) >> 5), HSIZE);
978
979 /* configure the memory line offset */
980 if ((params->frm_fmt == CCDC_FRMFMT_INTERLACED) &&
981 (params->buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED))
982 /* two fields are interleaved in memory */
983 regw(0x00000249, SDOFST);
984
985 /* Setup test pattern if enabled */
986 if (isif_cfg.bayer.config_params.test_pat_gen) {
987 sync.ccdpg_hdpol = params->hd_pol;
988 sync.ccdpg_vdpol = params->vd_pol;
989 dm365_vpss_set_sync_pol(sync);
990 dm365_vpss_set_pg_frame_size(frame_size);
991 }
992 return 0;
993}
994
995static int isif_configure(void)
996{
997 if (isif_cfg.if_type == VPFE_RAW_BAYER)
998 return isif_config_raw();
999 return isif_config_ycbcr();
1000}
1001
1002static int isif_close(struct device *device)
1003{
1004 /* copy defaults to module params */
1005 isif_cfg.bayer.config_params = isif_config_defaults;
1006 return 0;
1007}
1008
1009static struct ccdc_hw_device isif_hw_dev = {
1010 .name = "ISIF",
1011 .owner = THIS_MODULE,
1012 .hw_ops = {
1013 .open = isif_open,
1014 .close = isif_close,
1015 .enable = isif_enable,
1016 .enable_out_to_sdram = isif_enable_output_to_sdram,
1017 .set_hw_if_params = isif_set_hw_if_params,
1018 .configure = isif_configure,
1019 .set_buftype = isif_set_buftype,
1020 .get_buftype = isif_get_buftype,
1021 .enum_pix = isif_enum_pix,
1022 .set_pixel_format = isif_set_pixel_format,
1023 .get_pixel_format = isif_get_pixel_format,
1024 .set_frame_format = isif_set_frame_format,
1025 .get_frame_format = isif_get_frame_format,
1026 .set_image_window = isif_set_image_window,
1027 .get_image_window = isif_get_image_window,
1028 .get_line_length = isif_get_line_length,
1029 .setfbaddr = isif_setfbaddr,
1030 .getfid = isif_getfid,
1031 },
1032};
1033
1034static int __init isif_probe(struct platform_device *pdev)
1035{
1036 void (*setup_pinmux)(void);
1037 struct resource *res;
1038 void *__iomem addr;
1039 int status = 0, i;
1040
1041 /*
1042 * first try to register with vpfe. If not correct platform, then we
1043 * don't have to iomap
1044 */
1045 status = vpfe_register_ccdc_device(&isif_hw_dev);
1046 if (status < 0)
1047 return status;
1048
1049 /* Get and enable Master clock */
1050 isif_cfg.mclk = clk_get(&pdev->dev, "master");
1051 if (IS_ERR(isif_cfg.mclk)) {
1052 status = PTR_ERR(isif_cfg.mclk);
1053 goto fail_mclk;
1054 }
1055 if (clk_enable(isif_cfg.mclk)) {
1056 status = -ENODEV;
1057 goto fail_mclk;
1058 }
1059
1060 /* Platform data holds setup_pinmux function ptr */
1061 if (NULL == pdev->dev.platform_data) {
1062 status = -ENODEV;
1063 goto fail_mclk;
1064 }
1065 setup_pinmux = pdev->dev.platform_data;
1066 /*
1067 * setup Mux configuration for ccdc which may be different for
1068 * different SoCs using this CCDC
1069 */
1070 setup_pinmux();
1071
1072 i = 0;
1073 /* Get the ISIF base address, linearization table0 and table1 addr. */
1074 while (i < 3) {
1075 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
1076 if (!res) {
1077 status = -ENODEV;
1078 goto fail_nobase_res;
1079 }
1080 res = request_mem_region(res->start, resource_size(res),
1081 res->name);
1082 if (!res) {
1083 status = -EBUSY;
1084 goto fail_nobase_res;
1085 }
1086 addr = ioremap_nocache(res->start, resource_size(res));
1087 if (!addr) {
1088 status = -ENOMEM;
1089 goto fail_base_iomap;
1090 }
1091 switch (i) {
1092 case 0:
1093 /* ISIF base address */
1094 isif_cfg.base_addr = addr;
1095 break;
1096 case 1:
1097 /* ISIF linear tbl0 address */
1098 isif_cfg.linear_tbl0_addr = addr;
1099 break;
1100 default:
1101 /* ISIF linear tbl0 address */
1102 isif_cfg.linear_tbl1_addr = addr;
1103 break;
1104 }
1105 i++;
1106 }
1107 isif_cfg.dev = &pdev->dev;
1108
1109 printk(KERN_NOTICE "%s is registered with vpfe.\n",
1110 isif_hw_dev.name);
1111 return 0;
1112fail_base_iomap:
1113 release_mem_region(res->start, resource_size(res));
1114 i--;
1115fail_nobase_res:
1116 if (isif_cfg.base_addr)
1117 iounmap(isif_cfg.base_addr);
1118 if (isif_cfg.linear_tbl0_addr)
1119 iounmap(isif_cfg.linear_tbl0_addr);
1120
1121 while (i >= 0) {
1122 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
1123 release_mem_region(res->start, resource_size(res));
1124 i--;
1125 }
1126fail_mclk:
1127 clk_put(isif_cfg.mclk);
1128 vpfe_unregister_ccdc_device(&isif_hw_dev);
1129 return status;
1130}
1131
1132static int isif_remove(struct platform_device *pdev)
1133{
1134 struct resource *res;
1135 int i = 0;
1136
1137 iounmap(isif_cfg.base_addr);
1138 iounmap(isif_cfg.linear_tbl0_addr);
1139 iounmap(isif_cfg.linear_tbl1_addr);
1140 while (i < 3) {
1141 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
1142 if (res)
1143 release_mem_region(res->start, resource_size(res));
1144 i++;
1145 }
1146 vpfe_unregister_ccdc_device(&isif_hw_dev);
1147 return 0;
1148}
1149
1150static struct platform_driver isif_driver = {
1151 .driver = {
1152 .name = "isif",
1153 .owner = THIS_MODULE,
1154 },
1155 .remove = __devexit_p(isif_remove),
1156 .probe = isif_probe,
1157};
1158
1159static int __init isif_init(void)
1160{
1161 return platform_driver_register(&isif_driver);
1162}
1163
1164static void isif_exit(void)
1165{
1166 platform_driver_unregister(&isif_driver);
1167}
1168
1169module_init(isif_init);
1170module_exit(isif_exit);
1171
1172MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/davinci/isif_regs.h b/drivers/media/video/davinci/isif_regs.h
new file mode 100644
index 000000000000..f7b8893a2957
--- /dev/null
+++ b/drivers/media/video/davinci/isif_regs.h
@@ -0,0 +1,269 @@
1/*
2 * Copyright (C) 2008-2009 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18#ifndef _ISIF_REGS_H
19#define _ISIF_REGS_H
20
21/* ISIF registers relative offsets */
22#define SYNCEN 0x00
23#define MODESET 0x04
24#define HDW 0x08
25#define VDW 0x0c
26#define PPLN 0x10
27#define LPFR 0x14
28#define SPH 0x18
29#define LNH 0x1c
30#define SLV0 0x20
31#define SLV1 0x24
32#define LNV 0x28
33#define CULH 0x2c
34#define CULV 0x30
35#define HSIZE 0x34
36#define SDOFST 0x38
37#define CADU 0x3c
38#define CADL 0x40
39#define LINCFG0 0x44
40#define LINCFG1 0x48
41#define CCOLP 0x4c
42#define CRGAIN 0x50
43#define CGRGAIN 0x54
44#define CGBGAIN 0x58
45#define CBGAIN 0x5c
46#define COFSTA 0x60
47#define FLSHCFG0 0x64
48#define FLSHCFG1 0x68
49#define FLSHCFG2 0x6c
50#define VDINT0 0x70
51#define VDINT1 0x74
52#define VDINT2 0x78
53#define MISC 0x7c
54#define CGAMMAWD 0x80
55#define REC656IF 0x84
56#define CCDCFG 0x88
57/*****************************************************
58* Defect Correction registers
59*****************************************************/
60#define DFCCTL 0x8c
61#define VDFSATLV 0x90
62#define DFCMEMCTL 0x94
63#define DFCMEM0 0x98
64#define DFCMEM1 0x9c
65#define DFCMEM2 0xa0
66#define DFCMEM3 0xa4
67#define DFCMEM4 0xa8
68/****************************************************
69* Black Clamp registers
70****************************************************/
71#define CLAMPCFG 0xac
72#define CLDCOFST 0xb0
73#define CLSV 0xb4
74#define CLHWIN0 0xb8
75#define CLHWIN1 0xbc
76#define CLHWIN2 0xc0
77#define CLVRV 0xc4
78#define CLVWIN0 0xc8
79#define CLVWIN1 0xcc
80#define CLVWIN2 0xd0
81#define CLVWIN3 0xd4
82/****************************************************
83* Lense Shading Correction
84****************************************************/
85#define DATAHOFST 0xd8
86#define DATAVOFST 0xdc
87#define LSCHVAL 0xe0
88#define LSCVVAL 0xe4
89#define TWODLSCCFG 0xe8
90#define TWODLSCOFST 0xec
91#define TWODLSCINI 0xf0
92#define TWODLSCGRBU 0xf4
93#define TWODLSCGRBL 0xf8
94#define TWODLSCGROF 0xfc
95#define TWODLSCORBU 0x100
96#define TWODLSCORBL 0x104
97#define TWODLSCOROF 0x108
98#define TWODLSCIRQEN 0x10c
99#define TWODLSCIRQST 0x110
100/****************************************************
101* Data formatter
102****************************************************/
103#define FMTCFG 0x114
104#define FMTPLEN 0x118
105#define FMTSPH 0x11c
106#define FMTLNH 0x120
107#define FMTSLV 0x124
108#define FMTLNV 0x128
109#define FMTRLEN 0x12c
110#define FMTHCNT 0x130
111#define FMTAPTR_BASE 0x134
112/* Below macro for addresses FMTAPTR0 - FMTAPTR15 */
113#define FMTAPTR(i) (FMTAPTR_BASE + (i * 4))
114#define FMTPGMVF0 0x174
115#define FMTPGMVF1 0x178
116#define FMTPGMAPU0 0x17c
117#define FMTPGMAPU1 0x180
118#define FMTPGMAPS0 0x184
119#define FMTPGMAPS1 0x188
120#define FMTPGMAPS2 0x18c
121#define FMTPGMAPS3 0x190
122#define FMTPGMAPS4 0x194
123#define FMTPGMAPS5 0x198
124#define FMTPGMAPS6 0x19c
125#define FMTPGMAPS7 0x1a0
126/************************************************
127* Color Space Converter
128************************************************/
129#define CSCCTL 0x1a4
130#define CSCM0 0x1a8
131#define CSCM1 0x1ac
132#define CSCM2 0x1b0
133#define CSCM3 0x1b4
134#define CSCM4 0x1b8
135#define CSCM5 0x1bc
136#define CSCM6 0x1c0
137#define CSCM7 0x1c4
138#define OBWIN0 0x1c8
139#define OBWIN1 0x1cc
140#define OBWIN2 0x1d0
141#define OBWIN3 0x1d4
142#define OBVAL0 0x1d8
143#define OBVAL1 0x1dc
144#define OBVAL2 0x1e0
145#define OBVAL3 0x1e4
146#define OBVAL4 0x1e8
147#define OBVAL5 0x1ec
148#define OBVAL6 0x1f0
149#define OBVAL7 0x1f4
150#define CLKCTL 0x1f8
151
152/* Masks & Shifts below */
153#define START_PX_HOR_MASK 0x7FFF
154#define NUM_PX_HOR_MASK 0x7FFF
155#define START_VER_ONE_MASK 0x7FFF
156#define START_VER_TWO_MASK 0x7FFF
157#define NUM_LINES_VER 0x7FFF
158
159/* gain - offset masks */
160#define GAIN_INTEGER_SHIFT 9
161#define OFFSET_MASK 0xFFF
162#define GAIN_SDRAM_EN_SHIFT 12
163#define GAIN_IPIPE_EN_SHIFT 13
164#define GAIN_H3A_EN_SHIFT 14
165#define OFST_SDRAM_EN_SHIFT 8
166#define OFST_IPIPE_EN_SHIFT 9
167#define OFST_H3A_EN_SHIFT 10
168#define GAIN_OFFSET_EN_MASK 0x7700
169
170/* Culling */
171#define CULL_PAT_EVEN_LINE_SHIFT 8
172
173/* CCDCFG register */
174#define ISIF_YCINSWP_RAW (0x00 << 4)
175#define ISIF_YCINSWP_YCBCR (0x01 << 4)
176#define ISIF_CCDCFG_FIDMD_LATCH_VSYNC (0x00 << 6)
177#define ISIF_CCDCFG_WENLOG_AND (0x00 << 8)
178#define ISIF_CCDCFG_TRGSEL_WEN (0x00 << 9)
179#define ISIF_CCDCFG_EXTRG_DISABLE (0x00 << 10)
180#define ISIF_LATCH_ON_VSYNC_DISABLE (0x01 << 15)
181#define ISIF_LATCH_ON_VSYNC_ENABLE (0x00 << 15)
182#define ISIF_DATA_PACK_MASK 3
183#define ISIF_DATA_PACK16 0
184#define ISIF_DATA_PACK12 1
185#define ISIF_DATA_PACK8 2
186#define ISIF_PIX_ORDER_SHIFT 11
187#define ISIF_BW656_ENABLE (0x01 << 5)
188
189/* MODESET registers */
190#define ISIF_VDHDOUT_INPUT (0x00 << 0)
191#define ISIF_INPUT_SHIFT 12
192#define ISIF_RAW_INPUT_MODE 0
193#define ISIF_FID_POL_SHIFT 4
194#define ISIF_HD_POL_SHIFT 3
195#define ISIF_VD_POL_SHIFT 2
196#define ISIF_DATAPOL_NORMAL 0
197#define ISIF_DATAPOL_SHIFT 6
198#define ISIF_EXWEN_DISABLE 0
199#define ISIF_EXWEN_SHIFT 5
200#define ISIF_FRM_FMT_SHIFT 7
201#define ISIF_DATASFT_SHIFT 8
202#define ISIF_LPF_SHIFT 14
203#define ISIF_LPF_MASK 1
204
205/* GAMMAWD registers */
206#define ISIF_ALAW_GAMA_WD_MASK 0xF
207#define ISIF_ALAW_GAMA_WD_SHIFT 1
208#define ISIF_ALAW_ENABLE 1
209#define ISIF_GAMMAWD_CFA_SHIFT 5
210
211/* HSIZE registers */
212#define ISIF_HSIZE_FLIP_MASK 1
213#define ISIF_HSIZE_FLIP_SHIFT 12
214
215/* MISC registers */
216#define ISIF_DPCM_EN_SHIFT 12
217#define ISIF_DPCM_PREDICTOR_SHIFT 13
218
219/* Black clamp related */
220#define ISIF_BC_MODE_COLOR_SHIFT 4
221#define ISIF_HORZ_BC_MODE_SHIFT 1
222#define ISIF_HORZ_BC_WIN_SEL_SHIFT 5
223#define ISIF_HORZ_BC_PIX_LIMIT_SHIFT 6
224#define ISIF_HORZ_BC_WIN_H_SIZE_SHIFT 8
225#define ISIF_HORZ_BC_WIN_V_SIZE_SHIFT 12
226#define ISIF_VERT_BC_RST_VAL_SEL_SHIFT 4
227#define ISIF_VERT_BC_LINE_AVE_COEF_SHIFT 8
228
229/* VDFC registers */
230#define ISIF_VDFC_EN_SHIFT 4
231#define ISIF_VDFC_CORR_MOD_SHIFT 5
232#define ISIF_VDFC_CORR_WHOLE_LN_SHIFT 7
233#define ISIF_VDFC_LEVEL_SHFT_SHIFT 8
234#define ISIF_VDFC_POS_MASK 0x1FFF
235#define ISIF_DFCMEMCTL_DFCMARST_SHIFT 2
236
237/* CSC registers */
238#define ISIF_CSC_COEF_INTEG_MASK 7
239#define ISIF_CSC_COEF_DECIMAL_MASK 0x1f
240#define ISIF_CSC_COEF_INTEG_SHIFT 5
241#define ISIF_CSCM_MSB_SHIFT 8
242#define ISIF_DF_CSC_SPH_MASK 0x1FFF
243#define ISIF_DF_CSC_LNH_MASK 0x1FFF
244#define ISIF_DF_CSC_SLV_MASK 0x1FFF
245#define ISIF_DF_CSC_LNV_MASK 0x1FFF
246#define ISIF_DF_NUMLINES 0x7FFF
247#define ISIF_DF_NUMPIX 0x1FFF
248
249/* Offsets for LSC/DFC/Gain */
250#define ISIF_DATA_H_OFFSET_MASK 0x1FFF
251#define ISIF_DATA_V_OFFSET_MASK 0x1FFF
252
253/* Linearization */
254#define ISIF_LIN_CORRSFT_SHIFT 4
255#define ISIF_LIN_SCALE_FACT_INTEG_SHIFT 10
256
257
258/* Pattern registers */
259#define ISIF_PG_EN (1 << 3)
260#define ISIF_SEL_PG_SRC (3 << 4)
261#define ISIF_PG_VD_POL_SHIFT 0
262#define ISIF_PG_HD_POL_SHIFT 1
263
264/*random other junk*/
265#define ISIF_SYNCEN_VDHDEN_MASK (1 << 0)
266#define ISIF_SYNCEN_WEN_MASK (1 << 1)
267#define ISIF_SYNCEN_WEN_SHIFT 1
268
269#endif
diff --git a/drivers/media/video/davinci/vpfe_capture.c b/drivers/media/video/davinci/vpfe_capture.c
index de22bc9faf21..885cd54499cf 100644
--- a/drivers/media/video/davinci/vpfe_capture.c
+++ b/drivers/media/video/davinci/vpfe_capture.c
@@ -107,9 +107,6 @@ struct ccdc_config {
107 int vpfe_probed; 107 int vpfe_probed;
108 /* name of ccdc device */ 108 /* name of ccdc device */
109 char name[32]; 109 char name[32];
110 /* for storing mem maps for CCDC */
111 int ccdc_addr_size;
112 void *__iomem ccdc_addr;
113}; 110};
114 111
115/* data structures */ 112/* data structures */
@@ -229,7 +226,6 @@ int vpfe_register_ccdc_device(struct ccdc_hw_device *dev)
229 BUG_ON(!dev->hw_ops.set_image_window); 226 BUG_ON(!dev->hw_ops.set_image_window);
230 BUG_ON(!dev->hw_ops.get_image_window); 227 BUG_ON(!dev->hw_ops.get_image_window);
231 BUG_ON(!dev->hw_ops.get_line_length); 228 BUG_ON(!dev->hw_ops.get_line_length);
232 BUG_ON(!dev->hw_ops.setfbaddr);
233 BUG_ON(!dev->hw_ops.getfid); 229 BUG_ON(!dev->hw_ops.getfid);
234 230
235 mutex_lock(&ccdc_lock); 231 mutex_lock(&ccdc_lock);
@@ -240,25 +236,23 @@ int vpfe_register_ccdc_device(struct ccdc_hw_device *dev)
240 * walk through it during vpfe probe 236 * walk through it during vpfe probe
241 */ 237 */
242 printk(KERN_ERR "vpfe capture not initialized\n"); 238 printk(KERN_ERR "vpfe capture not initialized\n");
243 ret = -1; 239 ret = -EFAULT;
244 goto unlock; 240 goto unlock;
245 } 241 }
246 242
247 if (strcmp(dev->name, ccdc_cfg->name)) { 243 if (strcmp(dev->name, ccdc_cfg->name)) {
248 /* ignore this ccdc */ 244 /* ignore this ccdc */
249 ret = -1; 245 ret = -EINVAL;
250 goto unlock; 246 goto unlock;
251 } 247 }
252 248
253 if (ccdc_dev) { 249 if (ccdc_dev) {
254 printk(KERN_ERR "ccdc already registered\n"); 250 printk(KERN_ERR "ccdc already registered\n");
255 ret = -1; 251 ret = -EINVAL;
256 goto unlock; 252 goto unlock;
257 } 253 }
258 254
259 ccdc_dev = dev; 255 ccdc_dev = dev;
260 dev->hw_ops.set_ccdc_base(ccdc_cfg->ccdc_addr,
261 ccdc_cfg->ccdc_addr_size);
262unlock: 256unlock:
263 mutex_unlock(&ccdc_lock); 257 mutex_unlock(&ccdc_lock);
264 return ret; 258 return ret;
@@ -1786,61 +1780,6 @@ static struct vpfe_device *vpfe_initialize(void)
1786 return vpfe_dev; 1780 return vpfe_dev;
1787} 1781}
1788 1782
1789static void vpfe_disable_clock(struct vpfe_device *vpfe_dev)
1790{
1791 struct vpfe_config *vpfe_cfg = vpfe_dev->cfg;
1792
1793 clk_disable(vpfe_cfg->vpssclk);
1794 clk_put(vpfe_cfg->vpssclk);
1795 clk_disable(vpfe_cfg->slaveclk);
1796 clk_put(vpfe_cfg->slaveclk);
1797 v4l2_info(vpfe_dev->pdev->driver,
1798 "vpfe vpss master & slave clocks disabled\n");
1799}
1800
1801static int vpfe_enable_clock(struct vpfe_device *vpfe_dev)
1802{
1803 struct vpfe_config *vpfe_cfg = vpfe_dev->cfg;
1804 int ret = -ENOENT;
1805
1806 vpfe_cfg->vpssclk = clk_get(vpfe_dev->pdev, "vpss_master");
1807 if (NULL == vpfe_cfg->vpssclk) {
1808 v4l2_err(vpfe_dev->pdev->driver, "No clock defined for"
1809 "vpss_master\n");
1810 return ret;
1811 }
1812
1813 if (clk_enable(vpfe_cfg->vpssclk)) {
1814 v4l2_err(vpfe_dev->pdev->driver,
1815 "vpfe vpss master clock not enabled\n");
1816 goto out;
1817 }
1818 v4l2_info(vpfe_dev->pdev->driver,
1819 "vpfe vpss master clock enabled\n");
1820
1821 vpfe_cfg->slaveclk = clk_get(vpfe_dev->pdev, "vpss_slave");
1822 if (NULL == vpfe_cfg->slaveclk) {
1823 v4l2_err(vpfe_dev->pdev->driver,
1824 "No clock defined for vpss slave\n");
1825 goto out;
1826 }
1827
1828 if (clk_enable(vpfe_cfg->slaveclk)) {
1829 v4l2_err(vpfe_dev->pdev->driver,
1830 "vpfe vpss slave clock not enabled\n");
1831 goto out;
1832 }
1833 v4l2_info(vpfe_dev->pdev->driver, "vpfe vpss slave clock enabled\n");
1834 return 0;
1835out:
1836 if (vpfe_cfg->vpssclk)
1837 clk_put(vpfe_cfg->vpssclk);
1838 if (vpfe_cfg->slaveclk)
1839 clk_put(vpfe_cfg->slaveclk);
1840
1841 return -1;
1842}
1843
1844/* 1783/*
1845 * vpfe_probe : This function creates device entries by register 1784 * vpfe_probe : This function creates device entries by register
1846 * itself to the V4L2 driver and initializes fields of each 1785 * itself to the V4L2 driver and initializes fields of each
@@ -1870,7 +1809,7 @@ static __init int vpfe_probe(struct platform_device *pdev)
1870 1809
1871 if (NULL == pdev->dev.platform_data) { 1810 if (NULL == pdev->dev.platform_data) {
1872 v4l2_err(pdev->dev.driver, "Unable to get vpfe config\n"); 1811 v4l2_err(pdev->dev.driver, "Unable to get vpfe config\n");
1873 ret = -ENOENT; 1812 ret = -ENODEV;
1874 goto probe_free_dev_mem; 1813 goto probe_free_dev_mem;
1875 } 1814 }
1876 1815
@@ -1884,18 +1823,13 @@ static __init int vpfe_probe(struct platform_device *pdev)
1884 goto probe_free_dev_mem; 1823 goto probe_free_dev_mem;
1885 } 1824 }
1886 1825
1887 /* enable vpss clocks */
1888 ret = vpfe_enable_clock(vpfe_dev);
1889 if (ret)
1890 goto probe_free_dev_mem;
1891
1892 mutex_lock(&ccdc_lock); 1826 mutex_lock(&ccdc_lock);
1893 /* Allocate memory for ccdc configuration */ 1827 /* Allocate memory for ccdc configuration */
1894 ccdc_cfg = kmalloc(sizeof(struct ccdc_config), GFP_KERNEL); 1828 ccdc_cfg = kmalloc(sizeof(struct ccdc_config), GFP_KERNEL);
1895 if (NULL == ccdc_cfg) { 1829 if (NULL == ccdc_cfg) {
1896 v4l2_err(pdev->dev.driver, 1830 v4l2_err(pdev->dev.driver,
1897 "Memory allocation failed for ccdc_cfg\n"); 1831 "Memory allocation failed for ccdc_cfg\n");
1898 goto probe_disable_clock; 1832 goto probe_free_dev_mem;
1899 } 1833 }
1900 1834
1901 strncpy(ccdc_cfg->name, vpfe_cfg->ccdc, 32); 1835 strncpy(ccdc_cfg->name, vpfe_cfg->ccdc, 32);
@@ -1904,61 +1838,34 @@ static __init int vpfe_probe(struct platform_device *pdev)
1904 if (!res1) { 1838 if (!res1) {
1905 v4l2_err(pdev->dev.driver, 1839 v4l2_err(pdev->dev.driver,
1906 "Unable to get interrupt for VINT0\n"); 1840 "Unable to get interrupt for VINT0\n");
1907 ret = -ENOENT; 1841 ret = -ENODEV;
1908 goto probe_disable_clock; 1842 goto probe_free_ccdc_cfg_mem;
1909 } 1843 }
1910 vpfe_dev->ccdc_irq0 = res1->start; 1844 vpfe_dev->ccdc_irq0 = res1->start;
1911 1845
1912 /* Get VINT1 irq resource */ 1846 /* Get VINT1 irq resource */
1913 res1 = platform_get_resource(pdev, 1847 res1 = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
1914 IORESOURCE_IRQ, 1);
1915 if (!res1) { 1848 if (!res1) {
1916 v4l2_err(pdev->dev.driver, 1849 v4l2_err(pdev->dev.driver,
1917 "Unable to get interrupt for VINT1\n"); 1850 "Unable to get interrupt for VINT1\n");
1918 ret = -ENOENT; 1851 ret = -ENODEV;
1919 goto probe_disable_clock; 1852 goto probe_free_ccdc_cfg_mem;
1920 } 1853 }
1921 vpfe_dev->ccdc_irq1 = res1->start; 1854 vpfe_dev->ccdc_irq1 = res1->start;
1922 1855
1923 /* Get address base of CCDC */
1924 res1 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1925 if (!res1) {
1926 v4l2_err(pdev->dev.driver,
1927 "Unable to get register address map\n");
1928 ret = -ENOENT;
1929 goto probe_disable_clock;
1930 }
1931
1932 ccdc_cfg->ccdc_addr_size = res1->end - res1->start + 1;
1933 if (!request_mem_region(res1->start, ccdc_cfg->ccdc_addr_size,
1934 pdev->dev.driver->name)) {
1935 v4l2_err(pdev->dev.driver,
1936 "Failed request_mem_region for ccdc base\n");
1937 ret = -ENXIO;
1938 goto probe_disable_clock;
1939 }
1940 ccdc_cfg->ccdc_addr = ioremap_nocache(res1->start,
1941 ccdc_cfg->ccdc_addr_size);
1942 if (!ccdc_cfg->ccdc_addr) {
1943 v4l2_err(pdev->dev.driver, "Unable to ioremap ccdc addr\n");
1944 ret = -ENXIO;
1945 goto probe_out_release_mem1;
1946 }
1947
1948 ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, IRQF_DISABLED, 1856 ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, IRQF_DISABLED,
1949 "vpfe_capture0", vpfe_dev); 1857 "vpfe_capture0", vpfe_dev);
1950 1858
1951 if (0 != ret) { 1859 if (0 != ret) {
1952 v4l2_err(pdev->dev.driver, "Unable to request interrupt\n"); 1860 v4l2_err(pdev->dev.driver, "Unable to request interrupt\n");
1953 goto probe_out_unmap1; 1861 goto probe_free_ccdc_cfg_mem;
1954 } 1862 }
1955 1863
1956 /* Allocate memory for video device */ 1864 /* Allocate memory for video device */
1957 vfd = video_device_alloc(); 1865 vfd = video_device_alloc();
1958 if (NULL == vfd) { 1866 if (NULL == vfd) {
1959 ret = -ENOMEM; 1867 ret = -ENOMEM;
1960 v4l2_err(pdev->dev.driver, 1868 v4l2_err(pdev->dev.driver, "Unable to alloc video device\n");
1961 "Unable to alloc video device\n");
1962 goto probe_out_release_irq; 1869 goto probe_out_release_irq;
1963 } 1870 }
1964 1871
@@ -2073,12 +1980,7 @@ probe_out_video_release:
2073 video_device_release(vpfe_dev->video_dev); 1980 video_device_release(vpfe_dev->video_dev);
2074probe_out_release_irq: 1981probe_out_release_irq:
2075 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev); 1982 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev);
2076probe_out_unmap1: 1983probe_free_ccdc_cfg_mem:
2077 iounmap(ccdc_cfg->ccdc_addr);
2078probe_out_release_mem1:
2079 release_mem_region(res1->start, res1->end - res1->start + 1);
2080probe_disable_clock:
2081 vpfe_disable_clock(vpfe_dev);
2082 mutex_unlock(&ccdc_lock); 1984 mutex_unlock(&ccdc_lock);
2083 kfree(ccdc_cfg); 1985 kfree(ccdc_cfg);
2084probe_free_dev_mem: 1986probe_free_dev_mem:
@@ -2092,7 +1994,6 @@ probe_free_dev_mem:
2092static int __devexit vpfe_remove(struct platform_device *pdev) 1994static int __devexit vpfe_remove(struct platform_device *pdev)
2093{ 1995{
2094 struct vpfe_device *vpfe_dev = platform_get_drvdata(pdev); 1996 struct vpfe_device *vpfe_dev = platform_get_drvdata(pdev);
2095 struct resource *res;
2096 1997
2097 v4l2_info(pdev->dev.driver, "vpfe_remove\n"); 1998 v4l2_info(pdev->dev.driver, "vpfe_remove\n");
2098 1999
@@ -2100,12 +2001,6 @@ static int __devexit vpfe_remove(struct platform_device *pdev)
2100 kfree(vpfe_dev->sd); 2001 kfree(vpfe_dev->sd);
2101 v4l2_device_unregister(&vpfe_dev->v4l2_dev); 2002 v4l2_device_unregister(&vpfe_dev->v4l2_dev);
2102 video_unregister_device(vpfe_dev->video_dev); 2003 video_unregister_device(vpfe_dev->video_dev);
2103 mutex_lock(&ccdc_lock);
2104 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2105 release_mem_region(res->start, res->end - res->start + 1);
2106 iounmap(ccdc_cfg->ccdc_addr);
2107 mutex_unlock(&ccdc_lock);
2108 vpfe_disable_clock(vpfe_dev);
2109 kfree(vpfe_dev); 2004 kfree(vpfe_dev);
2110 kfree(ccdc_cfg); 2005 kfree(ccdc_cfg);
2111 return 0; 2006 return 0;
diff --git a/drivers/media/video/davinci/vpss.c b/drivers/media/video/davinci/vpss.c
index 7ee72ecd3d81..7918680917d0 100644
--- a/drivers/media/video/davinci/vpss.c
+++ b/drivers/media/video/davinci/vpss.c
@@ -15,7 +15,7 @@
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 * 17 *
18 * common vpss driver for all video drivers. 18 * common vpss system module platform driver for all video drivers.
19 */ 19 */
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/sched.h> 21#include <linux/sched.h>
@@ -35,12 +35,52 @@ MODULE_AUTHOR("Texas Instruments");
35/* DM644x defines */ 35/* DM644x defines */
36#define DM644X_SBL_PCR_VPSS (4) 36#define DM644X_SBL_PCR_VPSS (4)
37 37
38#define DM355_VPSSBL_INTSEL 0x10
39#define DM355_VPSSBL_EVTSEL 0x14
38/* vpss BL register offsets */ 40/* vpss BL register offsets */
39#define DM355_VPSSBL_CCDCMUX 0x1c 41#define DM355_VPSSBL_CCDCMUX 0x1c
40/* vpss CLK register offsets */ 42/* vpss CLK register offsets */
41#define DM355_VPSSCLK_CLKCTRL 0x04 43#define DM355_VPSSCLK_CLKCTRL 0x04
42/* masks and shifts */ 44/* masks and shifts */
43#define VPSS_HSSISEL_SHIFT 4 45#define VPSS_HSSISEL_SHIFT 4
46/*
47 * VDINT0 - vpss_int0, VDINT1 - vpss_int1, H3A - vpss_int4,
48 * IPIPE_INT1_SDR - vpss_int5
49 */
50#define DM355_VPSSBL_INTSEL_DEFAULT 0xff83ff10
51/* VENCINT - vpss_int8 */
52#define DM355_VPSSBL_EVTSEL_DEFAULT 0x4
53
54#define DM365_ISP5_PCCR 0x04
55#define DM365_ISP5_INTSEL1 0x10
56#define DM365_ISP5_INTSEL2 0x14
57#define DM365_ISP5_INTSEL3 0x18
58#define DM365_ISP5_CCDCMUX 0x20
59#define DM365_ISP5_PG_FRAME_SIZE 0x28
60#define DM365_VPBE_CLK_CTRL 0x00
61/*
62 * vpss interrupts. VDINT0 - vpss_int0, VDINT1 - vpss_int1,
63 * AF - vpss_int3
64 */
65#define DM365_ISP5_INTSEL1_DEFAULT 0x0b1f0100
66/* AEW - vpss_int6, RSZ_INT_DMA - vpss_int5 */
67#define DM365_ISP5_INTSEL2_DEFAULT 0x1f0a0f1f
68/* VENC - vpss_int8 */
69#define DM365_ISP5_INTSEL3_DEFAULT 0x00000015
70
71/* masks and shifts for DM365*/
72#define DM365_CCDC_PG_VD_POL_SHIFT 0
73#define DM365_CCDC_PG_HD_POL_SHIFT 1
74
75#define CCD_SRC_SEL_MASK (BIT_MASK(5) | BIT_MASK(4))
76#define CCD_SRC_SEL_SHIFT 4
77
78/* Different SoC platforms supported by this driver */
79enum vpss_platform_type {
80 DM644X,
81 DM355,
82 DM365,
83};
44 84
45/* 85/*
46 * vpss operations. Depends on platform. Not all functions are available 86 * vpss operations. Depends on platform. Not all functions are available
@@ -59,13 +99,9 @@ struct vpss_hw_ops {
59 99
60/* vpss configuration */ 100/* vpss configuration */
61struct vpss_oper_config { 101struct vpss_oper_config {
62 __iomem void *vpss_bl_regs_base; 102 __iomem void *vpss_regs_base0;
63 __iomem void *vpss_regs_base; 103 __iomem void *vpss_regs_base1;
64 struct resource *r1; 104 enum vpss_platform_type platform;
65 resource_size_t len1;
66 struct resource *r2;
67 resource_size_t len2;
68 char vpss_name[32];
69 spinlock_t vpss_lock; 105 spinlock_t vpss_lock;
70 struct vpss_hw_ops hw_ops; 106 struct vpss_hw_ops hw_ops;
71}; 107};
@@ -75,22 +111,46 @@ static struct vpss_oper_config oper_cfg;
75/* register access routines */ 111/* register access routines */
76static inline u32 bl_regr(u32 offset) 112static inline u32 bl_regr(u32 offset)
77{ 113{
78 return __raw_readl(oper_cfg.vpss_bl_regs_base + offset); 114 return __raw_readl(oper_cfg.vpss_regs_base0 + offset);
79} 115}
80 116
81static inline void bl_regw(u32 val, u32 offset) 117static inline void bl_regw(u32 val, u32 offset)
82{ 118{
83 __raw_writel(val, oper_cfg.vpss_bl_regs_base + offset); 119 __raw_writel(val, oper_cfg.vpss_regs_base0 + offset);
84} 120}
85 121
86static inline u32 vpss_regr(u32 offset) 122static inline u32 vpss_regr(u32 offset)
87{ 123{
88 return __raw_readl(oper_cfg.vpss_regs_base + offset); 124 return __raw_readl(oper_cfg.vpss_regs_base1 + offset);
89} 125}
90 126
91static inline void vpss_regw(u32 val, u32 offset) 127static inline void vpss_regw(u32 val, u32 offset)
92{ 128{
93 __raw_writel(val, oper_cfg.vpss_regs_base + offset); 129 __raw_writel(val, oper_cfg.vpss_regs_base1 + offset);
130}
131
132/* For DM365 only */
133static inline u32 isp5_read(u32 offset)
134{
135 return __raw_readl(oper_cfg.vpss_regs_base0 + offset);
136}
137
138/* For DM365 only */
139static inline void isp5_write(u32 val, u32 offset)
140{
141 __raw_writel(val, oper_cfg.vpss_regs_base0 + offset);
142}
143
144static void dm365_select_ccdc_source(enum vpss_ccdc_source_sel src_sel)
145{
146 u32 temp = isp5_read(DM365_ISP5_CCDCMUX) & ~CCD_SRC_SEL_MASK;
147
148 /* if we are using pattern generator, enable it */
149 if (src_sel == VPSS_PGLPBK || src_sel == VPSS_CCDCPG)
150 temp |= 0x08;
151
152 temp |= (src_sel << CCD_SRC_SEL_SHIFT);
153 isp5_write(temp, DM365_ISP5_CCDCMUX);
94} 154}
95 155
96static void dm355_select_ccdc_source(enum vpss_ccdc_source_sel src_sel) 156static void dm355_select_ccdc_source(enum vpss_ccdc_source_sel src_sel)
@@ -101,9 +161,9 @@ static void dm355_select_ccdc_source(enum vpss_ccdc_source_sel src_sel)
101int vpss_select_ccdc_source(enum vpss_ccdc_source_sel src_sel) 161int vpss_select_ccdc_source(enum vpss_ccdc_source_sel src_sel)
102{ 162{
103 if (!oper_cfg.hw_ops.select_ccdc_source) 163 if (!oper_cfg.hw_ops.select_ccdc_source)
104 return -1; 164 return -EINVAL;
105 165
106 dm355_select_ccdc_source(src_sel); 166 oper_cfg.hw_ops.select_ccdc_source(src_sel);
107 return 0; 167 return 0;
108} 168}
109EXPORT_SYMBOL(vpss_select_ccdc_source); 169EXPORT_SYMBOL(vpss_select_ccdc_source);
@@ -114,7 +174,7 @@ static int dm644x_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel)
114 174
115 if (wbl_sel < VPSS_PCR_AEW_WBL_0 || 175 if (wbl_sel < VPSS_PCR_AEW_WBL_0 ||
116 wbl_sel > VPSS_PCR_CCDC_WBL_O) 176 wbl_sel > VPSS_PCR_CCDC_WBL_O)
117 return -1; 177 return -EINVAL;
118 178
119 /* writing a 0 clear the overflow */ 179 /* writing a 0 clear the overflow */
120 mask = ~(mask << wbl_sel); 180 mask = ~(mask << wbl_sel);
@@ -126,7 +186,7 @@ static int dm644x_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel)
126int vpss_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel) 186int vpss_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel)
127{ 187{
128 if (!oper_cfg.hw_ops.clear_wbl_overflow) 188 if (!oper_cfg.hw_ops.clear_wbl_overflow)
129 return -1; 189 return -EINVAL;
130 190
131 return oper_cfg.hw_ops.clear_wbl_overflow(wbl_sel); 191 return oper_cfg.hw_ops.clear_wbl_overflow(wbl_sel);
132} 192}
@@ -166,7 +226,7 @@ static int dm355_enable_clock(enum vpss_clock_sel clock_sel, int en)
166 default: 226 default:
167 printk(KERN_ERR "dm355_enable_clock:" 227 printk(KERN_ERR "dm355_enable_clock:"
168 " Invalid selector: %d\n", clock_sel); 228 " Invalid selector: %d\n", clock_sel);
169 return -1; 229 return -EINVAL;
170 } 230 }
171 231
172 spin_lock_irqsave(&oper_cfg.vpss_lock, flags); 232 spin_lock_irqsave(&oper_cfg.vpss_lock, flags);
@@ -181,100 +241,221 @@ static int dm355_enable_clock(enum vpss_clock_sel clock_sel, int en)
181 return 0; 241 return 0;
182} 242}
183 243
244static int dm365_enable_clock(enum vpss_clock_sel clock_sel, int en)
245{
246 unsigned long flags;
247 u32 utemp, mask = 0x1, shift = 0, offset = DM365_ISP5_PCCR;
248 u32 (*read)(u32 offset) = isp5_read;
249 void(*write)(u32 val, u32 offset) = isp5_write;
250
251 switch (clock_sel) {
252 case VPSS_BL_CLOCK:
253 break;
254 case VPSS_CCDC_CLOCK:
255 shift = 1;
256 break;
257 case VPSS_H3A_CLOCK:
258 shift = 2;
259 break;
260 case VPSS_RSZ_CLOCK:
261 shift = 3;
262 break;
263 case VPSS_IPIPE_CLOCK:
264 shift = 4;
265 break;
266 case VPSS_IPIPEIF_CLOCK:
267 shift = 5;
268 break;
269 case VPSS_PCLK_INTERNAL:
270 shift = 6;
271 break;
272 case VPSS_PSYNC_CLOCK_SEL:
273 shift = 7;
274 break;
275 case VPSS_VPBE_CLOCK:
276 read = vpss_regr;
277 write = vpss_regw;
278 offset = DM365_VPBE_CLK_CTRL;
279 break;
280 case VPSS_VENC_CLOCK_SEL:
281 shift = 2;
282 read = vpss_regr;
283 write = vpss_regw;
284 offset = DM365_VPBE_CLK_CTRL;
285 break;
286 case VPSS_LDC_CLOCK:
287 shift = 3;
288 read = vpss_regr;
289 write = vpss_regw;
290 offset = DM365_VPBE_CLK_CTRL;
291 break;
292 case VPSS_FDIF_CLOCK:
293 shift = 4;
294 read = vpss_regr;
295 write = vpss_regw;
296 offset = DM365_VPBE_CLK_CTRL;
297 break;
298 case VPSS_OSD_CLOCK_SEL:
299 shift = 6;
300 read = vpss_regr;
301 write = vpss_regw;
302 offset = DM365_VPBE_CLK_CTRL;
303 break;
304 case VPSS_LDC_CLOCK_SEL:
305 shift = 7;
306 read = vpss_regr;
307 write = vpss_regw;
308 offset = DM365_VPBE_CLK_CTRL;
309 break;
310 default:
311 printk(KERN_ERR "dm365_enable_clock: Invalid selector: %d\n",
312 clock_sel);
313 return -1;
314 }
315
316 spin_lock_irqsave(&oper_cfg.vpss_lock, flags);
317 utemp = read(offset);
318 if (!en) {
319 mask = ~mask;
320 utemp &= (mask << shift);
321 } else
322 utemp |= (mask << shift);
323
324 write(utemp, offset);
325 spin_unlock_irqrestore(&oper_cfg.vpss_lock, flags);
326
327 return 0;
328}
329
184int vpss_enable_clock(enum vpss_clock_sel clock_sel, int en) 330int vpss_enable_clock(enum vpss_clock_sel clock_sel, int en)
185{ 331{
186 if (!oper_cfg.hw_ops.enable_clock) 332 if (!oper_cfg.hw_ops.enable_clock)
187 return -1; 333 return -EINVAL;
188 334
189 return oper_cfg.hw_ops.enable_clock(clock_sel, en); 335 return oper_cfg.hw_ops.enable_clock(clock_sel, en);
190} 336}
191EXPORT_SYMBOL(vpss_enable_clock); 337EXPORT_SYMBOL(vpss_enable_clock);
192 338
339void dm365_vpss_set_sync_pol(struct vpss_sync_pol sync)
340{
341 int val = 0;
342 val = isp5_read(DM365_ISP5_CCDCMUX);
343
344 val |= (sync.ccdpg_hdpol << DM365_CCDC_PG_HD_POL_SHIFT);
345 val |= (sync.ccdpg_vdpol << DM365_CCDC_PG_VD_POL_SHIFT);
346
347 isp5_write(val, DM365_ISP5_CCDCMUX);
348}
349EXPORT_SYMBOL(dm365_vpss_set_sync_pol);
350
351void dm365_vpss_set_pg_frame_size(struct vpss_pg_frame_size frame_size)
352{
353 int current_reg = ((frame_size.hlpfr >> 1) - 1) << 16;
354
355 current_reg |= (frame_size.pplen - 1);
356 isp5_write(current_reg, DM365_ISP5_PG_FRAME_SIZE);
357}
358EXPORT_SYMBOL(dm365_vpss_set_pg_frame_size);
359
193static int __init vpss_probe(struct platform_device *pdev) 360static int __init vpss_probe(struct platform_device *pdev)
194{ 361{
195 int status, dm355 = 0; 362 struct resource *r1, *r2;
363 char *platform_name;
364 int status;
196 365
197 if (!pdev->dev.platform_data) { 366 if (!pdev->dev.platform_data) {
198 dev_err(&pdev->dev, "no platform data\n"); 367 dev_err(&pdev->dev, "no platform data\n");
199 return -ENOENT; 368 return -ENOENT;
200 } 369 }
201 strcpy(oper_cfg.vpss_name, pdev->dev.platform_data);
202 370
203 if (!strcmp(oper_cfg.vpss_name, "dm355_vpss")) 371 platform_name = pdev->dev.platform_data;
204 dm355 = 1; 372 if (!strcmp(platform_name, "dm355_vpss"))
205 else if (strcmp(oper_cfg.vpss_name, "dm644x_vpss")) { 373 oper_cfg.platform = DM355;
374 else if (!strcmp(platform_name, "dm365_vpss"))
375 oper_cfg.platform = DM365;
376 else if (!strcmp(platform_name, "dm644x_vpss"))
377 oper_cfg.platform = DM644X;
378 else {
206 dev_err(&pdev->dev, "vpss driver not supported on" 379 dev_err(&pdev->dev, "vpss driver not supported on"
207 " this platform\n"); 380 " this platform\n");
208 return -ENODEV; 381 return -ENODEV;
209 } 382 }
210 383
211 dev_info(&pdev->dev, "%s vpss probed\n", oper_cfg.vpss_name); 384 dev_info(&pdev->dev, "%s vpss probed\n", platform_name);
212 oper_cfg.r1 = platform_get_resource(pdev, IORESOURCE_MEM, 0); 385 r1 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
213 if (!oper_cfg.r1) 386 if (!r1)
214 return -ENOENT; 387 return -ENOENT;
215 388
216 oper_cfg.len1 = oper_cfg.r1->end - oper_cfg.r1->start + 1; 389 r1 = request_mem_region(r1->start, resource_size(r1), r1->name);
217 390 if (!r1)
218 oper_cfg.r1 = request_mem_region(oper_cfg.r1->start, oper_cfg.len1,
219 oper_cfg.r1->name);
220 if (!oper_cfg.r1)
221 return -EBUSY; 391 return -EBUSY;
222 392
223 oper_cfg.vpss_bl_regs_base = ioremap(oper_cfg.r1->start, oper_cfg.len1); 393 oper_cfg.vpss_regs_base0 = ioremap(r1->start, resource_size(r1));
224 if (!oper_cfg.vpss_bl_regs_base) { 394 if (!oper_cfg.vpss_regs_base0) {
225 status = -EBUSY; 395 status = -EBUSY;
226 goto fail1; 396 goto fail1;
227 } 397 }
228 398
229 if (dm355) { 399 if (oper_cfg.platform == DM355 || oper_cfg.platform == DM365) {
230 oper_cfg.r2 = platform_get_resource(pdev, IORESOURCE_MEM, 1); 400 r2 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
231 if (!oper_cfg.r2) { 401 if (!r2) {
232 status = -ENOENT; 402 status = -ENOENT;
233 goto fail2; 403 goto fail2;
234 } 404 }
235 oper_cfg.len2 = oper_cfg.r2->end - oper_cfg.r2->start + 1; 405 r2 = request_mem_region(r2->start, resource_size(r2), r2->name);
236 oper_cfg.r2 = request_mem_region(oper_cfg.r2->start, 406 if (!r2) {
237 oper_cfg.len2,
238 oper_cfg.r2->name);
239 if (!oper_cfg.r2) {
240 status = -EBUSY; 407 status = -EBUSY;
241 goto fail2; 408 goto fail2;
242 } 409 }
243 410
244 oper_cfg.vpss_regs_base = ioremap(oper_cfg.r2->start, 411 oper_cfg.vpss_regs_base1 = ioremap(r2->start,
245 oper_cfg.len2); 412 resource_size(r2));
246 if (!oper_cfg.vpss_regs_base) { 413 if (!oper_cfg.vpss_regs_base1) {
247 status = -EBUSY; 414 status = -EBUSY;
248 goto fail3; 415 goto fail3;
249 } 416 }
250 } 417 }
251 418
252 if (dm355) { 419 if (oper_cfg.platform == DM355) {
253 oper_cfg.hw_ops.enable_clock = dm355_enable_clock; 420 oper_cfg.hw_ops.enable_clock = dm355_enable_clock;
254 oper_cfg.hw_ops.select_ccdc_source = dm355_select_ccdc_source; 421 oper_cfg.hw_ops.select_ccdc_source = dm355_select_ccdc_source;
422 /* Setup vpss interrupts */
423 bl_regw(DM355_VPSSBL_INTSEL_DEFAULT, DM355_VPSSBL_INTSEL);
424 bl_regw(DM355_VPSSBL_EVTSEL_DEFAULT, DM355_VPSSBL_EVTSEL);
425 } else if (oper_cfg.platform == DM365) {
426 oper_cfg.hw_ops.enable_clock = dm365_enable_clock;
427 oper_cfg.hw_ops.select_ccdc_source = dm365_select_ccdc_source;
428 /* Setup vpss interrupts */
429 isp5_write(DM365_ISP5_INTSEL1_DEFAULT, DM365_ISP5_INTSEL1);
430 isp5_write(DM365_ISP5_INTSEL2_DEFAULT, DM365_ISP5_INTSEL2);
431 isp5_write(DM365_ISP5_INTSEL3_DEFAULT, DM365_ISP5_INTSEL3);
255 } else 432 } else
256 oper_cfg.hw_ops.clear_wbl_overflow = dm644x_clear_wbl_overflow; 433 oper_cfg.hw_ops.clear_wbl_overflow = dm644x_clear_wbl_overflow;
257 434
258 spin_lock_init(&oper_cfg.vpss_lock); 435 spin_lock_init(&oper_cfg.vpss_lock);
259 dev_info(&pdev->dev, "%s vpss probe success\n", oper_cfg.vpss_name); 436 dev_info(&pdev->dev, "%s vpss probe success\n", platform_name);
260 return 0; 437 return 0;
261 438
262fail3: 439fail3:
263 release_mem_region(oper_cfg.r2->start, oper_cfg.len2); 440 release_mem_region(r2->start, resource_size(r2));
264fail2: 441fail2:
265 iounmap(oper_cfg.vpss_bl_regs_base); 442 iounmap(oper_cfg.vpss_regs_base0);
266fail1: 443fail1:
267 release_mem_region(oper_cfg.r1->start, oper_cfg.len1); 444 release_mem_region(r1->start, resource_size(r1));
268 return status; 445 return status;
269} 446}
270 447
271static int __devexit vpss_remove(struct platform_device *pdev) 448static int __devexit vpss_remove(struct platform_device *pdev)
272{ 449{
273 iounmap(oper_cfg.vpss_bl_regs_base); 450 struct resource *res;
274 release_mem_region(oper_cfg.r1->start, oper_cfg.len1); 451
275 if (!strcmp(oper_cfg.vpss_name, "dm355_vpss")) { 452 iounmap(oper_cfg.vpss_regs_base0);
276 iounmap(oper_cfg.vpss_regs_base); 453 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
277 release_mem_region(oper_cfg.r2->start, oper_cfg.len2); 454 release_mem_region(res->start, resource_size(res));
455 if (oper_cfg.platform == DM355 || oper_cfg.platform == DM365) {
456 iounmap(oper_cfg.vpss_regs_base1);
457 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
458 release_mem_region(res->start, resource_size(res));
278 } 459 }
279 return 0; 460 return 0;
280} 461}
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 25100001ffff..ecbcefb08739 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -232,6 +232,12 @@ static struct em28xx_reg_seq vc211a_enable[] = {
232 { -1, -1, -1, -1}, 232 { -1, -1, -1, -1},
233}; 233};
234 234
235static struct em28xx_reg_seq dikom_dk300_digital[] = {
236 {EM28XX_R08_GPIO, 0x6e, ~EM_GPIO_4, 10},
237 {EM2880_R04_GPO, 0x08, 0xff, 10},
238 { -1, -1, -1, -1},
239};
240
235 241
236/* 242/*
237 * Board definitions 243 * Board definitions
@@ -461,21 +467,30 @@ struct em28xx_board em28xx_boards[] = {
461 .name = "Leadtek Winfast USB II Deluxe", 467 .name = "Leadtek Winfast USB II Deluxe",
462 .valid = EM28XX_BOARD_NOT_VALIDATED, 468 .valid = EM28XX_BOARD_NOT_VALIDATED,
463 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 469 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
464 .tda9887_conf = TDA9887_PRESENT, 470 .has_ir_i2c = 1,
471 .tvaudio_addr = 0x58,
472 .tda9887_conf = TDA9887_PRESENT |
473 TDA9887_PORT2_ACTIVE |
474 TDA9887_QSS,
465 .decoder = EM28XX_SAA711X, 475 .decoder = EM28XX_SAA711X,
476 .adecoder = EM28XX_TVAUDIO,
466 .input = { { 477 .input = { {
467 .type = EM28XX_VMUX_TELEVISION, 478 .type = EM28XX_VMUX_TELEVISION,
468 .vmux = SAA7115_COMPOSITE2, 479 .vmux = SAA7115_COMPOSITE4,
469 .amux = EM28XX_AMUX_VIDEO, 480 .amux = EM28XX_AMUX_AUX,
470 }, { 481 }, {
471 .type = EM28XX_VMUX_COMPOSITE1, 482 .type = EM28XX_VMUX_COMPOSITE1,
472 .vmux = SAA7115_COMPOSITE0, 483 .vmux = SAA7115_COMPOSITE5,
473 .amux = EM28XX_AMUX_LINE_IN, 484 .amux = EM28XX_AMUX_LINE_IN,
474 }, { 485 }, {
475 .type = EM28XX_VMUX_SVIDEO, 486 .type = EM28XX_VMUX_SVIDEO,
476 .vmux = SAA7115_COMPOSITE0, 487 .vmux = SAA7115_SVIDEO3,
477 .amux = EM28XX_AMUX_LINE_IN, 488 .amux = EM28XX_AMUX_LINE_IN,
478 } }, 489 } },
490 .radio = {
491 .type = EM28XX_RADIO,
492 .amux = EM28XX_AMUX_AUX,
493 }
479 }, 494 },
480 [EM2820_BOARD_VIDEOLOGY_20K14XUSB] = { 495 [EM2820_BOARD_VIDEOLOGY_20K14XUSB] = {
481 .name = "Videology 20K14XUSB USB2.0", 496 .name = "Videology 20K14XUSB USB2.0",
@@ -730,11 +745,12 @@ struct em28xx_board em28xx_boards[] = {
730 745
731 [EM2880_BOARD_TERRATEC_HYBRID_XS_FR] = { 746 [EM2880_BOARD_TERRATEC_HYBRID_XS_FR] = {
732 .name = "Terratec Hybrid XS Secam", 747 .name = "Terratec Hybrid XS Secam",
733 .valid = EM28XX_BOARD_NOT_VALIDATED,
734 .has_msp34xx = 1, 748 .has_msp34xx = 1,
735 .tuner_type = TUNER_XC2028, 749 .tuner_type = TUNER_XC2028,
736 .tuner_gpio = default_tuner_gpio, 750 .tuner_gpio = default_tuner_gpio,
737 .decoder = EM28XX_TVP5150, 751 .decoder = EM28XX_TVP5150,
752 .has_dvb = 1,
753 .dvb_gpio = default_digital,
738 .input = { { 754 .input = { {
739 .type = EM28XX_VMUX_TELEVISION, 755 .type = EM28XX_VMUX_TELEVISION,
740 .vmux = TVP5150_COMPOSITE0, 756 .vmux = TVP5150_COMPOSITE0,
@@ -1265,6 +1281,7 @@ struct em28xx_board em28xx_boards[] = {
1265 .decoder = EM28XX_SAA711X, 1281 .decoder = EM28XX_SAA711X,
1266 .has_dvb = 1, 1282 .has_dvb = 1,
1267 .dvb_gpio = em2882_kworld_315u_digital, 1283 .dvb_gpio = em2882_kworld_315u_digital,
1284 .ir_codes = &ir_codes_kworld_315u_table,
1268 .xclk = EM28XX_XCLK_FREQUENCY_12MHZ, 1285 .xclk = EM28XX_XCLK_FREQUENCY_12MHZ,
1269 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE, 1286 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE,
1270 /* Analog mode - still not ready */ 1287 /* Analog mode - still not ready */
@@ -1431,6 +1448,21 @@ struct em28xx_board em28xx_boards[] = {
1431 .gpio = hauppauge_wintv_hvr_900_analog, 1448 .gpio = hauppauge_wintv_hvr_900_analog,
1432 } }, 1449 } },
1433 }, 1450 },
1451 [EM2882_BOARD_DIKOM_DK300] = {
1452 .name = "Dikom DK300",
1453 .tuner_type = TUNER_XC2028,
1454 .tuner_gpio = default_tuner_gpio,
1455 .decoder = EM28XX_TVP5150,
1456 .mts_firmware = 1,
1457 .has_dvb = 1,
1458 .dvb_gpio = dikom_dk300_digital,
1459 .input = { {
1460 .type = EM28XX_VMUX_TELEVISION,
1461 .vmux = TVP5150_COMPOSITE0,
1462 .amux = EM28XX_AMUX_VIDEO,
1463 .gpio = default_analog,
1464 } },
1465 },
1434 [EM2883_BOARD_KWORLD_HYBRID_330U] = { 1466 [EM2883_BOARD_KWORLD_HYBRID_330U] = {
1435 .name = "Kworld PlusTV HD Hybrid 330", 1467 .name = "Kworld PlusTV HD Hybrid 330",
1436 .tuner_type = TUNER_XC2028, 1468 .tuner_type = TUNER_XC2028,
@@ -1751,6 +1783,7 @@ static struct em28xx_hash_table em28xx_eeprom_hash[] = {
1751 {0xcee44a99, EM2882_BOARD_EVGA_INDTUBE, TUNER_XC2028}, 1783 {0xcee44a99, EM2882_BOARD_EVGA_INDTUBE, TUNER_XC2028},
1752 {0xb8846b20, EM2881_BOARD_PINNACLE_HYBRID_PRO, TUNER_XC2028}, 1784 {0xb8846b20, EM2881_BOARD_PINNACLE_HYBRID_PRO, TUNER_XC2028},
1753 {0x63f653bd, EM2870_BOARD_REDDO_DVB_C_USB_BOX, TUNER_ABSENT}, 1785 {0x63f653bd, EM2870_BOARD_REDDO_DVB_C_USB_BOX, TUNER_ABSENT},
1786 {0x4e913442, EM2882_BOARD_DIKOM_DK300, TUNER_XC2028},
1754}; 1787};
1755 1788
1756/* I2C devicelist hash table for devices with generic USB IDs */ 1789/* I2C devicelist hash table for devices with generic USB IDs */
@@ -2103,6 +2136,7 @@ static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
2103 ctl->demod = XC3028_FE_DEFAULT; 2136 ctl->demod = XC3028_FE_DEFAULT;
2104 break; 2137 break;
2105 case EM2883_BOARD_KWORLD_HYBRID_330U: 2138 case EM2883_BOARD_KWORLD_HYBRID_330U:
2139 case EM2882_BOARD_DIKOM_DK300:
2106 ctl->demod = XC3028_FE_CHINA; 2140 ctl->demod = XC3028_FE_CHINA;
2107 ctl->fname = XC2028_DEFAULT_FIRMWARE; 2141 ctl->fname = XC2028_DEFAULT_FIRMWARE;
2108 break; 2142 break;
@@ -2259,9 +2293,12 @@ static int em28xx_hint_board(struct em28xx *dev)
2259/* ----------------------------------------------------------------------- */ 2293/* ----------------------------------------------------------------------- */
2260void em28xx_register_i2c_ir(struct em28xx *dev) 2294void em28xx_register_i2c_ir(struct em28xx *dev)
2261{ 2295{
2296 /* Leadtek winfast tv USBII deluxe can find a non working IR-device */
2297 /* at address 0x18, so if that address is needed for another board in */
2298 /* the future, please put it after 0x1f. */
2262 struct i2c_board_info info; 2299 struct i2c_board_info info;
2263 const unsigned short addr_list[] = { 2300 const unsigned short addr_list[] = {
2264 0x30, 0x47, I2C_CLIENT_END 2301 0x1f, 0x30, 0x47, I2C_CLIENT_END
2265 }; 2302 };
2266 2303
2267 if (disable_ir) 2304 if (disable_ir)
@@ -2288,6 +2325,10 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
2288 dev->init_data.ir_codes = &ir_codes_rc5_hauppauge_new_table; 2325 dev->init_data.ir_codes = &ir_codes_rc5_hauppauge_new_table;
2289 dev->init_data.get_key = em28xx_get_key_em_haup; 2326 dev->init_data.get_key = em28xx_get_key_em_haup;
2290 dev->init_data.name = "i2c IR (EM2840 Hauppauge)"; 2327 dev->init_data.name = "i2c IR (EM2840 Hauppauge)";
2328 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
2329 dev->init_data.ir_codes = &ir_codes_winfast_usbii_deluxe_table;;
2330 dev->init_data.get_key = em28xx_get_key_winfast_usbii_deluxe;
2331 dev->init_data.name = "i2c IR (EM2820 Winfast TV USBII Deluxe)";
2291 break; 2332 break;
2292 } 2333 }
2293 2334
@@ -2381,6 +2422,31 @@ void em28xx_card_setup(struct em28xx *dev)
2381 em28xx_gpio_set(dev, dev->board.tuner_gpio); 2422 em28xx_gpio_set(dev, dev->board.tuner_gpio);
2382 em28xx_set_mode(dev, EM28XX_ANALOG_MODE); 2423 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2383 break; 2424 break;
2425
2426/*
2427 * The Dikom DK300 is detected as an Kworld VS-DVB-T 323UR.
2428 *
2429 * This occurs because they share identical USB vendor and
2430 * product IDs.
2431 *
2432 * What we do here is look up the EEPROM hash of the Dikom
2433 * and if it is found then we decide that we do not have
2434 * a Kworld and reset the device to the Dikom instead.
2435 *
2436 * This solution is only valid if they do not share eeprom
2437 * hash identities which has not been determined as yet.
2438 */
2439 case EM2882_BOARD_KWORLD_VS_DVBT:
2440 if (!em28xx_hint_board(dev))
2441 em28xx_set_model(dev);
2442
2443 /* In cases where we had to use a board hint, the call to
2444 em28xx_set_mode() in em28xx_pre_card_setup() was a no-op,
2445 so make the call now so the analog GPIOs are set properly
2446 before probing the i2c bus. */
2447 em28xx_gpio_set(dev, dev->board.tuner_gpio);
2448 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2449 break;
2384 } 2450 }
2385 2451
2386#if defined(CONFIG_MODULES) && defined(MODULE) 2452#if defined(CONFIG_MODULES) && defined(MODULE)
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c
index b311d4514bdf..5a37eccbd7d6 100644
--- a/drivers/media/video/em28xx/em28xx-core.c
+++ b/drivers/media/video/em28xx/em28xx-core.c
@@ -691,9 +691,15 @@ int em28xx_set_outfmt(struct em28xx *dev)
691 if (em28xx_vbi_supported(dev) == 1) { 691 if (em28xx_vbi_supported(dev) == 1) {
692 vinctrl |= EM28XX_VINCTRL_VBI_RAW; 692 vinctrl |= EM28XX_VINCTRL_VBI_RAW;
693 em28xx_write_reg(dev, EM28XX_R34_VBI_START_H, 0x00); 693 em28xx_write_reg(dev, EM28XX_R34_VBI_START_H, 0x00);
694 em28xx_write_reg(dev, EM28XX_R35_VBI_START_V, 0x09); 694 em28xx_write_reg(dev, EM28XX_R36_VBI_WIDTH, dev->vbi_width/4);
695 em28xx_write_reg(dev, EM28XX_R36_VBI_WIDTH, 0xb4); 695 em28xx_write_reg(dev, EM28XX_R37_VBI_HEIGHT, dev->vbi_height);
696 em28xx_write_reg(dev, EM28XX_R37_VBI_HEIGHT, 0x0c); 696 if (dev->norm & V4L2_STD_525_60) {
697 /* NTSC */
698 em28xx_write_reg(dev, EM28XX_R35_VBI_START_V, 0x09);
699 } else if (dev->norm & V4L2_STD_625_50) {
700 /* PAL */
701 em28xx_write_reg(dev, EM28XX_R35_VBI_START_V, 0x07);
702 }
697 } 703 }
698 704
699 return em28xx_write_reg(dev, EM28XX_R11_VINCTRL, vinctrl); 705 return em28xx_write_reg(dev, EM28XX_R11_VINCTRL, vinctrl);
@@ -760,6 +766,13 @@ int em28xx_resolution_set(struct em28xx *dev)
760 width = norm_maxw(dev); 766 width = norm_maxw(dev);
761 height = norm_maxh(dev); 767 height = norm_maxh(dev);
762 768
769 /* Properly setup VBI */
770 dev->vbi_width = 720;
771 if (dev->norm & V4L2_STD_525_60)
772 dev->vbi_height = 12;
773 else
774 dev->vbi_height = 18;
775
763 if (!dev->progressive) 776 if (!dev->progressive)
764 height >>= norm_maxh(dev); 777 height >>= norm_maxh(dev);
765 778
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c
index cc0505eb900f..1b96356b3ab2 100644
--- a/drivers/media/video/em28xx/em28xx-dvb.c
+++ b/drivers/media/video/em28xx/em28xx-dvb.c
@@ -502,7 +502,9 @@ static int dvb_init(struct em28xx *dev)
502 } 502 }
503 break; 503 break;
504 case EM2880_BOARD_TERRATEC_HYBRID_XS: 504 case EM2880_BOARD_TERRATEC_HYBRID_XS:
505 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
505 case EM2881_BOARD_PINNACLE_HYBRID_PRO: 506 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
507 case EM2882_BOARD_DIKOM_DK300:
506 dvb->frontend = dvb_attach(zl10353_attach, 508 dvb->frontend = dvb_attach(zl10353_attach,
507 &em28xx_zl10353_xc3028_no_i2c_gate, 509 &em28xx_zl10353_xc3028_no_i2c_gate,
508 &dev->i2c_adap); 510 &dev->i2c_adap);
@@ -606,6 +608,7 @@ static int dvb_fini(struct em28xx *dev)
606 608
607 if (dev->dvb) { 609 if (dev->dvb) {
608 unregister_dvb(dev->dvb); 610 unregister_dvb(dev->dvb);
611 kfree(dev->dvb);
609 dev->dvb = NULL; 612 dev->dvb = NULL;
610 } 613 }
611 614
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index af0d935c29be..1fb754e20875 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -75,6 +75,10 @@ struct em28xx_IR {
75 unsigned int repeat_interval; 75 unsigned int repeat_interval;
76 76
77 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); 77 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *);
78
79 /* IR device properties */
80
81 struct ir_dev_props props;
78}; 82};
79 83
80/********************************************************** 84/**********************************************************
@@ -180,6 +184,36 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
180 return 1; 184 return 1;
181} 185}
182 186
187int em28xx_get_key_winfast_usbii_deluxe(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
188{
189 unsigned char subaddr, keydetect, key;
190
191 struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0, .buf = &subaddr, .len = 1},
192
193 { .addr = ir->c->addr, .flags = I2C_M_RD, .buf = &keydetect, .len = 1} };
194
195 subaddr = 0x10;
196 if (2 != i2c_transfer(ir->c->adapter, msg, 2)) {
197 i2cdprintk("read error\n");
198 return -EIO;
199 }
200 if (keydetect == 0x00)
201 return 0;
202
203 subaddr = 0x00;
204 msg[1].buf = &key;
205 if (2 != i2c_transfer(ir->c->adapter, msg, 2)) {
206 i2cdprintk("read error\n");
207 return -EIO;
208 }
209 if (key == 0x00)
210 return 0;
211
212 *ir_key = key;
213 *ir_raw = key;
214 return 1;
215}
216
183/********************************************************** 217/**********************************************************
184 Poll based get keycode functions 218 Poll based get keycode functions
185 **********************************************************/ 219 **********************************************************/
@@ -336,35 +370,28 @@ static void em28xx_ir_stop(struct em28xx_IR *ir)
336 cancel_delayed_work_sync(&ir->work); 370 cancel_delayed_work_sync(&ir->work);
337} 371}
338 372
339int em28xx_ir_init(struct em28xx *dev) 373int em28xx_ir_change_protocol(void *priv, u64 ir_type)
340{ 374{
341 struct em28xx_IR *ir; 375 int rc = 0;
342 struct input_dev *input_dev; 376 struct em28xx_IR *ir = priv;
343 u8 ir_config; 377 struct em28xx *dev = ir->dev;
344 int err = -ENOMEM; 378 u8 ir_config = EM2874_IR_RC5;
345
346 if (dev->board.ir_codes == NULL) {
347 /* No remote control support */
348 return 0;
349 }
350
351 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
352 input_dev = input_allocate_device();
353 if (!ir || !input_dev)
354 goto err_out_free;
355
356 ir->input = input_dev;
357 ir_config = EM2874_IR_RC5;
358 379
359 /* Adjust xclk based o IR table for RC5/NEC tables */ 380 /* Adjust xclk based o IR table for RC5/NEC tables */
360 if (dev->board.ir_codes->ir_type == IR_TYPE_RC5) { 381
382 dev->board.ir_codes->ir_type = IR_TYPE_OTHER;
383 if (ir_type == IR_TYPE_RC5) {
361 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; 384 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
362 ir->full_code = 1; 385 ir->full_code = 1;
363 } else if (dev->board.ir_codes->ir_type == IR_TYPE_NEC) { 386 } else if (ir_type == IR_TYPE_NEC) {
364 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE; 387 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
365 ir_config = EM2874_IR_NEC; 388 ir_config = EM2874_IR_NEC;
366 ir->full_code = 1; 389 ir->full_code = 1;
367 } 390 } else
391 rc = -EINVAL;
392
393 dev->board.ir_codes->ir_type = ir_type;
394
368 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk, 395 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
369 EM28XX_XCLK_IR_RC5_MODE); 396 EM28XX_XCLK_IR_RC5_MODE);
370 397
@@ -380,9 +407,42 @@ int em28xx_ir_init(struct em28xx *dev)
380 break; 407 break;
381 default: 408 default:
382 printk("Unrecognized em28xx chip id: IR not supported\n"); 409 printk("Unrecognized em28xx chip id: IR not supported\n");
383 goto err_out_free; 410 rc = -EINVAL;
411 }
412
413 return rc;
414}
415
416int em28xx_ir_init(struct em28xx *dev)
417{
418 struct em28xx_IR *ir;
419 struct input_dev *input_dev;
420 int err = -ENOMEM;
421
422 if (dev->board.ir_codes == NULL) {
423 /* No remote control support */
424 return 0;
384 } 425 }
385 426
427 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
428 input_dev = input_allocate_device();
429 if (!ir || !input_dev)
430 goto err_out_free;
431
432 /* record handles to ourself */
433 ir->dev = dev;
434 dev->ir = ir;
435
436 ir->input = input_dev;
437
438 /*
439 * em2874 supports more protocols. For now, let's just announce
440 * the two protocols that were already tested
441 */
442 ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
443 ir->props.priv = ir;
444 ir->props.change_protocol = em28xx_ir_change_protocol;
445
386 /* This is how often we ask the chip for IR information */ 446 /* This is how often we ask the chip for IR information */
387 ir->polling = 100; /* ms */ 447 ir->polling = 100; /* ms */
388 448
@@ -393,6 +453,8 @@ int em28xx_ir_init(struct em28xx *dev)
393 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); 453 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
394 strlcat(ir->phys, "/input0", sizeof(ir->phys)); 454 strlcat(ir->phys, "/input0", sizeof(ir->phys));
395 455
456 /* Set IR protocol */
457 em28xx_ir_change_protocol(ir, dev->board.ir_codes->ir_type);
396 err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER); 458 err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER);
397 if (err < 0) 459 if (err < 0)
398 goto err_out_free; 460 goto err_out_free;
@@ -405,14 +467,13 @@ int em28xx_ir_init(struct em28xx *dev)
405 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); 467 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
406 468
407 input_dev->dev.parent = &dev->udev->dev; 469 input_dev->dev.parent = &dev->udev->dev;
408 /* record handles to ourself */ 470
409 ir->dev = dev;
410 dev->ir = ir;
411 471
412 em28xx_ir_start(ir); 472 em28xx_ir_start(ir);
413 473
414 /* all done */ 474 /* all done */
415 err = ir_input_register(ir->input, dev->board.ir_codes); 475 err = ir_input_register(ir->input, dev->board.ir_codes,
476 &ir->props);
416 if (err) 477 if (err)
417 goto err_out_stop; 478 goto err_out_stop;
418 479
diff --git a/drivers/media/video/em28xx/em28xx-reg.h b/drivers/media/video/em28xx/em28xx-reg.h
index 058ac87639ce..91e90559642b 100644
--- a/drivers/media/video/em28xx/em28xx-reg.h
+++ b/drivers/media/video/em28xx/em28xx-reg.h
@@ -173,8 +173,8 @@
173/* em2874 IR config register (0x50) */ 173/* em2874 IR config register (0x50) */
174#define EM2874_IR_NEC 0x00 174#define EM2874_IR_NEC 0x00
175#define EM2874_IR_RC5 0x04 175#define EM2874_IR_RC5 0x04
176#define EM2874_IR_RC5_MODE_0 0x08 176#define EM2874_IR_RC6_MODE_0 0x08
177#define EM2874_IR_RC5_MODE_6A 0x0b 177#define EM2874_IR_RC6_MODE_6A 0x0b
178 178
179/* em2874 Transport Stream Enable Register (0x5f) */ 179/* em2874 Transport Stream Enable Register (0x5f) */
180#define EM2874_TS1_CAPTURE_ENABLE (1 << 0) 180#define EM2874_TS1_CAPTURE_ENABLE (1 << 0)
diff --git a/drivers/media/video/em28xx/em28xx-vbi.c b/drivers/media/video/em28xx/em28xx-vbi.c
index 94943e5a1529..c7dce39823d8 100644
--- a/drivers/media/video/em28xx/em28xx-vbi.c
+++ b/drivers/media/video/em28xx/em28xx-vbi.c
@@ -71,7 +71,11 @@ free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf)
71static int 71static int
72vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) 72vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
73{ 73{
74 *size = 720 * 12 * 2; 74 struct em28xx_fh *fh = q->priv_data;
75 struct em28xx *dev = fh->dev;
76
77 *size = dev->vbi_width * dev->vbi_height * 2;
78
75 if (0 == *count) 79 if (0 == *count)
76 *count = vbibufs; 80 *count = vbibufs;
77 if (*count < 2) 81 if (*count < 2)
@@ -85,19 +89,18 @@ static int
85vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, 89vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
86 enum v4l2_field field) 90 enum v4l2_field field)
87{ 91{
92 struct em28xx_fh *fh = q->priv_data;
93 struct em28xx *dev = fh->dev;
88 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); 94 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
89 int rc = 0; 95 int rc = 0;
90 unsigned int size;
91
92 size = 720 * 12 * 2;
93 96
94 buf->vb.size = size; 97 buf->vb.size = dev->vbi_width * dev->vbi_height * 2;
95 98
96 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 99 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
97 return -EINVAL; 100 return -EINVAL;
98 101
99 buf->vb.width = 720; 102 buf->vb.width = dev->vbi_width;
100 buf->vb.height = 12; 103 buf->vb.height = dev->vbi_height;
101 buf->vb.field = field; 104 buf->vb.field = field;
102 105
103 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { 106 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 849b18c94037..ac2bd935927e 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -282,7 +282,7 @@ static void em28xx_copy_vbi(struct em28xx *dev,
282{ 282{
283 void *startwrite, *startread; 283 void *startwrite, *startread;
284 int offset; 284 int offset;
285 int bytesperline = 720; 285 int bytesperline = dev->vbi_width;
286 286
287 if (dev == NULL) { 287 if (dev == NULL) {
288 em28xx_isocdbg("dev is null\n"); 288 em28xx_isocdbg("dev is null\n");
@@ -323,8 +323,8 @@ static void em28xx_copy_vbi(struct em28xx *dev,
323 323
324 /* Make sure the bottom field populates the second half of the frame */ 324 /* Make sure the bottom field populates the second half of the frame */
325 if (buf->top_field == 0) { 325 if (buf->top_field == 0) {
326 startwrite += bytesperline * 0x0c; 326 startwrite += bytesperline * dev->vbi_height;
327 offset += bytesperline * 0x0c; 327 offset += bytesperline * dev->vbi_height;
328 } 328 }
329 329
330 memcpy(startwrite, startread, len); 330 memcpy(startwrite, startread, len);
@@ -578,8 +578,7 @@ static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
578 dev->cur_field = p[2]; 578 dev->cur_field = p[2];
579 } 579 }
580 580
581 /* FIXME: get rid of hard-coded value */ 581 vbi_size = dev->vbi_width * dev->vbi_height;
582 vbi_size = 720 * 0x0c;
583 582
584 if (dev->capture_type == 0) { 583 if (dev->capture_type == 0) {
585 if (dev->vbi_read >= vbi_size) { 584 if (dev->vbi_read >= vbi_size) {
@@ -1850,18 +1849,27 @@ static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
1850static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, 1849static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1851 struct v4l2_format *format) 1850 struct v4l2_format *format)
1852{ 1851{
1853 format->fmt.vbi.samples_per_line = 720; 1852 struct em28xx_fh *fh = priv;
1853 struct em28xx *dev = fh->dev;
1854
1855 format->fmt.vbi.samples_per_line = dev->vbi_width;
1854 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 1856 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1855 format->fmt.vbi.offset = 0; 1857 format->fmt.vbi.offset = 0;
1856 format->fmt.vbi.flags = 0; 1858 format->fmt.vbi.flags = 0;
1859 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1860 format->fmt.vbi.count[0] = dev->vbi_height;
1861 format->fmt.vbi.count[1] = dev->vbi_height;
1857 1862
1858 /* Varies by video standard (NTSC, PAL, etc.) */ 1863 /* Varies by video standard (NTSC, PAL, etc.) */
1859 /* FIXME: hard-coded for NTSC support */ 1864 if (dev->norm & V4L2_STD_525_60) {
1860 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2; /* FIXME: ??? */ 1865 /* NTSC */
1861 format->fmt.vbi.count[0] = 12; 1866 format->fmt.vbi.start[0] = 10;
1862 format->fmt.vbi.count[1] = 12; 1867 format->fmt.vbi.start[1] = 273;
1863 format->fmt.vbi.start[0] = 10; 1868 } else if (dev->norm & V4L2_STD_625_50) {
1864 format->fmt.vbi.start[1] = 273; 1869 /* PAL */
1870 format->fmt.vbi.start[0] = 6;
1871 format->fmt.vbi.start[1] = 318;
1872 }
1865 1873
1866 return 0; 1874 return 0;
1867} 1875}
@@ -1869,18 +1877,27 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1869static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv, 1877static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
1870 struct v4l2_format *format) 1878 struct v4l2_format *format)
1871{ 1879{
1872 format->fmt.vbi.samples_per_line = 720; 1880 struct em28xx_fh *fh = priv;
1881 struct em28xx *dev = fh->dev;
1882
1883 format->fmt.vbi.samples_per_line = dev->vbi_width;
1873 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 1884 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1874 format->fmt.vbi.offset = 0; 1885 format->fmt.vbi.offset = 0;
1875 format->fmt.vbi.flags = 0; 1886 format->fmt.vbi.flags = 0;
1887 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1888 format->fmt.vbi.count[0] = dev->vbi_height;
1889 format->fmt.vbi.count[1] = dev->vbi_height;
1876 1890
1877 /* Varies by video standard (NTSC, PAL, etc.) */ 1891 /* Varies by video standard (NTSC, PAL, etc.) */
1878 /* FIXME: hard-coded for NTSC support */ 1892 if (dev->norm & V4L2_STD_525_60) {
1879 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2; /* FIXME: ??? */ 1893 /* NTSC */
1880 format->fmt.vbi.count[0] = 12; 1894 format->fmt.vbi.start[0] = 10;
1881 format->fmt.vbi.count[1] = 12; 1895 format->fmt.vbi.start[1] = 273;
1882 format->fmt.vbi.start[0] = 10; 1896 } else if (dev->norm & V4L2_STD_625_50) {
1883 format->fmt.vbi.start[1] = 273; 1897 /* PAL */
1898 format->fmt.vbi.start[0] = 6;
1899 format->fmt.vbi.start[1] = 318;
1900 }
1884 1901
1885 return 0; 1902 return 0;
1886} 1903}
@@ -1922,7 +1939,8 @@ static int vidioc_querybuf(struct file *file, void *priv,
1922 At a minimum, it causes a crash in zvbi since it does 1939 At a minimum, it causes a crash in zvbi since it does
1923 a memcpy based on the source buffer length */ 1940 a memcpy based on the source buffer length */
1924 int result = videobuf_querybuf(&fh->vb_vbiq, b); 1941 int result = videobuf_querybuf(&fh->vb_vbiq, b);
1925 b->length = 17280; 1942 b->length = dev->vbi_width * dev->vbi_height * 2;
1943
1926 return result; 1944 return result;
1927 } 1945 }
1928} 1946}
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 80d9b4fa1b97..ba6fe5daff84 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -111,6 +111,7 @@
111#define EM2861_BOARD_GADMEI_UTV330PLUS 72 111#define EM2861_BOARD_GADMEI_UTV330PLUS 72
112#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73 112#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73
113#define EM2800_BOARD_VC211A 74 113#define EM2800_BOARD_VC211A 74
114#define EM2882_BOARD_DIKOM_DK300 75
114 115
115/* Limits minimum and default number of buffers */ 116/* Limits minimum and default number of buffers */
116#define EM28XX_MIN_BUF 4 117#define EM28XX_MIN_BUF 4
@@ -552,7 +553,8 @@ struct em28xx {
552 int capture_type; 553 int capture_type;
553 int vbi_read; 554 int vbi_read;
554 unsigned char cur_field; 555 unsigned char cur_field;
555 556 unsigned int vbi_width;
557 unsigned int vbi_height; /* lines per field */
556 558
557 struct work_struct request_module_wk; 559 struct work_struct request_module_wk;
558 560
@@ -693,6 +695,8 @@ int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);
693int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw); 695int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);
694int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, 696int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
695 u32 *ir_raw); 697 u32 *ir_raw);
698int em28xx_get_key_winfast_usbii_deluxe(struct IR_i2c *ir, u32 *ir_key,
699 u32 *ir_raw);
696void em28xx_register_snapshot_button(struct em28xx *dev); 700void em28xx_register_snapshot_button(struct em28xx *dev);
697void em28xx_deregister_snapshot_button(struct em28xx *dev); 701void em28xx_deregister_snapshot_button(struct em28xx *dev);
698 702
diff --git a/drivers/media/video/et61x251/Kconfig b/drivers/media/video/et61x251/Kconfig
index dcc1a0335440..87981b078fe6 100644
--- a/drivers/media/video/et61x251/Kconfig
+++ b/drivers/media/video/et61x251/Kconfig
@@ -1,7 +1,11 @@
1config USB_ET61X251 1config USB_ET61X251
2 tristate "USB ET61X[12]51 PC Camera Controller support" 2 tristate "USB ET61X[12]51 PC Camera Controller support (DEPRECATED)"
3 depends on VIDEO_V4L2 3 depends on VIDEO_V4L2
4 default n
4 ---help--- 5 ---help---
6 This driver is DEPRECATED please use the gspca zc3xx module
7 instead.
8
5 Say Y here if you want support for cameras based on Etoms ET61X151 9 Say Y here if you want support for cameras based on Etoms ET61X151
6 or ET61X251 PC Camera Controllers. 10 or ET61X251 PC Camera Controllers.
7 11
diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig
index 609d65b0b10d..e0060c1f0544 100644
--- a/drivers/media/video/gspca/Kconfig
+++ b/drivers/media/video/gspca/Kconfig
@@ -21,6 +21,15 @@ source "drivers/media/video/gspca/m5602/Kconfig"
21source "drivers/media/video/gspca/stv06xx/Kconfig" 21source "drivers/media/video/gspca/stv06xx/Kconfig"
22source "drivers/media/video/gspca/gl860/Kconfig" 22source "drivers/media/video/gspca/gl860/Kconfig"
23 23
24config USB_GSPCA_BENQ
25 tristate "Benq USB Camera Driver"
26 depends on VIDEO_V4L2 && USB_GSPCA
27 help
28 Say Y here if you want support for the Benq DC E300 camera.
29
30 To compile this driver as a module, choose M here: the
31 module will be called gspca_benq.
32
24config USB_GSPCA_CONEX 33config USB_GSPCA_CONEX
25 tristate "Conexant Camera Driver" 34 tristate "Conexant Camera Driver"
26 depends on VIDEO_V4L2 && USB_GSPCA 35 depends on VIDEO_V4L2 && USB_GSPCA
@@ -30,6 +39,17 @@ config USB_GSPCA_CONEX
30 To compile this driver as a module, choose M here: the 39 To compile this driver as a module, choose M here: the
31 module will be called gspca_conex. 40 module will be called gspca_conex.
32 41
42config USB_GSPCA_CPIA1
43 tristate "cpia CPiA (version 1) Camera Driver"
44 depends on VIDEO_V4L2 && USB_GSPCA
45 help
46 Say Y here if you want support for USB cameras based on the cpia
47 CPiA chip. Note that you need atleast version 0.6.4 of libv4l for
48 applications to understand the videoformat generated by this driver.
49
50 To compile this driver as a module, choose M here: the
51 module will be called gspca_cpia1.
52
33config USB_GSPCA_ETOMS 53config USB_GSPCA_ETOMS
34 tristate "Etoms USB Camera Driver" 54 tristate "Etoms USB Camera Driver"
35 depends on VIDEO_V4L2 && USB_GSPCA 55 depends on VIDEO_V4L2 && USB_GSPCA
@@ -86,15 +106,25 @@ config USB_GSPCA_OV519
86 module will be called gspca_ov519. 106 module will be called gspca_ov519.
87 107
88config USB_GSPCA_OV534 108config USB_GSPCA_OV534
89 tristate "OV534 USB Camera Driver" 109 tristate "OV534 OV772x USB Camera Driver"
90 depends on VIDEO_V4L2 && USB_GSPCA 110 depends on VIDEO_V4L2 && USB_GSPCA
91 help 111 help
92 Say Y here if you want support for cameras based on the OV534 chip. 112 Say Y here if you want support for cameras based on the OV534 chip
93 (e.g. Sony Playstation EYE) 113 and sensor OV772x (e.g. Sony Playstation EYE)
94 114
95 To compile this driver as a module, choose M here: the 115 To compile this driver as a module, choose M here: the
96 module will be called gspca_ov534. 116 module will be called gspca_ov534.
97 117
118config USB_GSPCA_OV534_9
119 tristate "OV534 OV965x USB Camera Driver"
120 depends on VIDEO_V4L2 && USB_GSPCA
121 help
122 Say Y here if you want support for cameras based on the OV534 chip
123 and sensor OV965x (e.g. Hercules Dualpix)
124
125 To compile this driver as a module, choose M here: the
126 module will be called gspca_ov534_9.
127
98config USB_GSPCA_PAC207 128config USB_GSPCA_PAC207
99 tristate "Pixart PAC207 USB Camera Driver" 129 tristate "Pixart PAC207 USB Camera Driver"
100 depends on VIDEO_V4L2 && USB_GSPCA 130 depends on VIDEO_V4L2 && USB_GSPCA
@@ -122,6 +152,16 @@ config USB_GSPCA_PAC7311
122 To compile this driver as a module, choose M here: the 152 To compile this driver as a module, choose M here: the
123 module will be called gspca_pac7311. 153 module will be called gspca_pac7311.
124 154
155config USB_GSPCA_SN9C2028
156 tristate "SONIX Dual-Mode USB Camera Driver"
157 depends on VIDEO_V4L2 && USB_GSPCA
158 help
159 Say Y here if you want streaming support for Sonix SN9C2028 cameras.
160 These are supported as stillcams in libgphoto2/camlibs/sonix.
161
162 To compile this driver as a module, choose M here: the
163 module will be called gspca_sn9c2028.
164
125config USB_GSPCA_SN9C20X 165config USB_GSPCA_SN9C20X
126 tristate "SN9C20X USB Camera Driver" 166 tristate "SN9C20X USB Camera Driver"
127 depends on VIDEO_V4L2 && USB_GSPCA 167 depends on VIDEO_V4L2 && USB_GSPCA
diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile
index ff2c7279d82e..6e4cf1ce01c9 100644
--- a/drivers/media/video/gspca/Makefile
+++ b/drivers/media/video/gspca/Makefile
@@ -1,5 +1,7 @@
1obj-$(CONFIG_USB_GSPCA) += gspca_main.o 1obj-$(CONFIG_USB_GSPCA) += gspca_main.o
2obj-$(CONFIG_USB_GSPCA_BENQ) += gspca_benq.o
2obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o 3obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o
4obj-$(CONFIG_USB_GSPCA_CPIA1) += gspca_cpia1.o
3obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o 5obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o
4obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o 6obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o
5obj-$(CONFIG_USB_GSPCA_JEILINJ) += gspca_jeilinj.o 7obj-$(CONFIG_USB_GSPCA_JEILINJ) += gspca_jeilinj.o
@@ -7,9 +9,11 @@ obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o
7obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o 9obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o
8obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o 10obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o
9obj-$(CONFIG_USB_GSPCA_OV534) += gspca_ov534.o 11obj-$(CONFIG_USB_GSPCA_OV534) += gspca_ov534.o
12obj-$(CONFIG_USB_GSPCA_OV534_9) += gspca_ov534_9.o
10obj-$(CONFIG_USB_GSPCA_PAC207) += gspca_pac207.o 13obj-$(CONFIG_USB_GSPCA_PAC207) += gspca_pac207.o
11obj-$(CONFIG_USB_GSPCA_PAC7302) += gspca_pac7302.o 14obj-$(CONFIG_USB_GSPCA_PAC7302) += gspca_pac7302.o
12obj-$(CONFIG_USB_GSPCA_PAC7311) += gspca_pac7311.o 15obj-$(CONFIG_USB_GSPCA_PAC7311) += gspca_pac7311.o
16obj-$(CONFIG_USB_GSPCA_SN9C2028) += gspca_sn9c2028.o
13obj-$(CONFIG_USB_GSPCA_SN9C20X) += gspca_sn9c20x.o 17obj-$(CONFIG_USB_GSPCA_SN9C20X) += gspca_sn9c20x.o
14obj-$(CONFIG_USB_GSPCA_SONIXB) += gspca_sonixb.o 18obj-$(CONFIG_USB_GSPCA_SONIXB) += gspca_sonixb.o
15obj-$(CONFIG_USB_GSPCA_SONIXJ) += gspca_sonixj.o 19obj-$(CONFIG_USB_GSPCA_SONIXJ) += gspca_sonixj.o
@@ -30,7 +34,9 @@ obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o
30obj-$(CONFIG_USB_GSPCA_ZC3XX) += gspca_zc3xx.o 34obj-$(CONFIG_USB_GSPCA_ZC3XX) += gspca_zc3xx.o
31 35
32gspca_main-objs := gspca.o 36gspca_main-objs := gspca.o
37gspca_benq-objs := benq.o
33gspca_conex-objs := conex.o 38gspca_conex-objs := conex.o
39gspca_cpia1-objs := cpia1.o
34gspca_etoms-objs := etoms.o 40gspca_etoms-objs := etoms.o
35gspca_finepix-objs := finepix.o 41gspca_finepix-objs := finepix.o
36gspca_jeilinj-objs := jeilinj.o 42gspca_jeilinj-objs := jeilinj.o
@@ -38,9 +44,11 @@ gspca_mars-objs := mars.o
38gspca_mr97310a-objs := mr97310a.o 44gspca_mr97310a-objs := mr97310a.o
39gspca_ov519-objs := ov519.o 45gspca_ov519-objs := ov519.o
40gspca_ov534-objs := ov534.o 46gspca_ov534-objs := ov534.o
47gspca_ov534_9-objs := ov534_9.o
41gspca_pac207-objs := pac207.o 48gspca_pac207-objs := pac207.o
42gspca_pac7302-objs := pac7302.o 49gspca_pac7302-objs := pac7302.o
43gspca_pac7311-objs := pac7311.o 50gspca_pac7311-objs := pac7311.o
51gspca_sn9c2028-objs := sn9c2028.o
44gspca_sn9c20x-objs := sn9c20x.o 52gspca_sn9c20x-objs := sn9c20x.o
45gspca_sonixb-objs := sonixb.o 53gspca_sonixb-objs := sonixb.o
46gspca_sonixj-objs := sonixj.o 54gspca_sonixj-objs := sonixj.o
diff --git a/drivers/media/video/gspca/benq.c b/drivers/media/video/gspca/benq.c
new file mode 100644
index 000000000000..43ac4af8d3ed
--- /dev/null
+++ b/drivers/media/video/gspca/benq.c
@@ -0,0 +1,322 @@
1/*
2 * Benq DC E300 subdriver
3 *
4 * Copyright (C) 2009 Jean-Francois Moine (http://moinejf.free.fr)
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 * 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#define MODULE_NAME "benq"
22
23#include "gspca.h"
24
25MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
26MODULE_DESCRIPTION("Benq DC E300 USB Camera Driver");
27MODULE_LICENSE("GPL");
28
29/* specific webcam descriptor */
30struct sd {
31 struct gspca_dev gspca_dev; /* !! must be the first item */
32};
33
34/* V4L2 controls supported by the driver */
35static const struct ctrl sd_ctrls[] = {
36};
37
38static const struct v4l2_pix_format vga_mode[] = {
39 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
40 .bytesperline = 320,
41 .sizeimage = 320 * 240 * 3 / 8 + 590,
42 .colorspace = V4L2_COLORSPACE_JPEG},
43};
44
45static void sd_isoc_irq(struct urb *urb);
46
47/* -- write a register -- */
48static void reg_w(struct gspca_dev *gspca_dev,
49 u16 value, u16 index)
50{
51 struct usb_device *dev = gspca_dev->dev;
52 int ret;
53
54 if (gspca_dev->usb_err < 0)
55 return;
56 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
57 0x02,
58 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
59 value,
60 index,
61 NULL,
62 0,
63 500);
64 if (ret < 0) {
65 PDEBUG(D_ERR, "reg_w err %d", ret);
66 gspca_dev->usb_err = ret;
67 }
68}
69
70/* this function is called at probe time */
71static int sd_config(struct gspca_dev *gspca_dev,
72 const struct usb_device_id *id)
73{
74 gspca_dev->cam.cam_mode = vga_mode;
75 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
76 gspca_dev->cam.no_urb_create = 1;
77 gspca_dev->cam.reverse_alts = 1;
78 return 0;
79}
80
81/* this function is called at probe and resume time */
82static int sd_init(struct gspca_dev *gspca_dev)
83{
84 return 0;
85}
86
87static int sd_isoc_init(struct gspca_dev *gspca_dev)
88{
89 int ret;
90
91 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface,
92 gspca_dev->nbalt - 1);
93 if (ret < 0) {
94 err("usb_set_interface failed");
95 return ret;
96 }
97/* reg_w(gspca_dev, 0x0003, 0x0002); */
98 return 0;
99}
100
101/* -- start the camera -- */
102static int sd_start(struct gspca_dev *gspca_dev)
103{
104 struct urb *urb;
105 int i, n;
106
107 /* create 4 URBs - 2 on endpoint 0x83 and 2 on 0x082 */
108#if MAX_NURBS < 4
109#error "Not enough URBs in the gspca table"
110#endif
111#define SD_PKT_SZ 64
112#define SD_NPKT 32
113 for (n = 0; n < 4; n++) {
114 urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL);
115 if (!urb) {
116 err("usb_alloc_urb failed");
117 return -ENOMEM;
118 }
119 gspca_dev->urb[n] = urb;
120 urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev,
121 SD_PKT_SZ * SD_NPKT,
122 GFP_KERNEL,
123 &urb->transfer_dma);
124
125 if (urb->transfer_buffer == NULL) {
126 err("usb_buffer_alloc failed");
127 return -ENOMEM;
128 }
129 urb->dev = gspca_dev->dev;
130 urb->context = gspca_dev;
131 urb->transfer_buffer_length = SD_PKT_SZ * SD_NPKT;
132 urb->pipe = usb_rcvisocpipe(gspca_dev->dev,
133 n & 1 ? 0x82 : 0x83);
134 urb->transfer_flags = URB_ISO_ASAP
135 | URB_NO_TRANSFER_DMA_MAP;
136 urb->interval = 1;
137 urb->complete = sd_isoc_irq;
138 urb->number_of_packets = SD_NPKT;
139 for (i = 0; i < SD_NPKT; i++) {
140 urb->iso_frame_desc[i].length = SD_PKT_SZ;
141 urb->iso_frame_desc[i].offset = SD_PKT_SZ * i;
142 }
143 }
144
145 return gspca_dev->usb_err;
146}
147
148static void sd_stopN(struct gspca_dev *gspca_dev)
149{
150 reg_w(gspca_dev, 0x003c, 0x0003);
151 reg_w(gspca_dev, 0x003c, 0x0004);
152 reg_w(gspca_dev, 0x003c, 0x0005);
153 reg_w(gspca_dev, 0x003c, 0x0006);
154 reg_w(gspca_dev, 0x003c, 0x0007);
155 usb_set_interface(gspca_dev->dev, gspca_dev->iface, gspca_dev->nbalt - 1);
156}
157
158static void sd_pkt_scan(struct gspca_dev *gspca_dev,
159 u8 *data, /* isoc packet */
160 int len) /* iso packet length */
161{
162 /* unused */
163}
164
165/* reception of an URB */
166static void sd_isoc_irq(struct urb *urb)
167{
168 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
169 struct urb *urb0;
170 u8 *data;
171 int i, st;
172
173 PDEBUG(D_PACK, "sd isoc irq");
174 if (!gspca_dev->streaming)
175 return;
176 if (urb->status != 0) {
177 if (urb->status == -ESHUTDOWN)
178 return; /* disconnection */
179#ifdef CONFIG_PM
180 if (gspca_dev->frozen)
181 return;
182#endif
183 PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status);
184 return;
185 }
186
187 /* if this is a control URN (ep 0x83), wait */
188 if (urb == gspca_dev->urb[0] || urb == gspca_dev->urb[2])
189 return;
190
191 /* scan both received URBs */
192 if (urb == gspca_dev->urb[1])
193 urb0 = gspca_dev->urb[0];
194 else
195 urb0 = gspca_dev->urb[2];
196 for (i = 0; i < urb->number_of_packets; i++) {
197
198 /* check the packet status and length */
199 if (urb0->iso_frame_desc[i].actual_length != SD_PKT_SZ
200 || urb->iso_frame_desc[i].actual_length != SD_PKT_SZ) {
201 PDEBUG(D_ERR, "ISOC bad lengths %d / %d",
202 urb0->iso_frame_desc[i].actual_length,
203 urb->iso_frame_desc[i].actual_length);
204 gspca_dev->last_packet_type = DISCARD_PACKET;
205 continue;
206 }
207 st = urb0->iso_frame_desc[i].status;
208 if (st == 0)
209 st = urb->iso_frame_desc[i].status;
210 if (st) {
211 PDEBUG(D_ERR,
212 "ISOC data error: [%d] status=%d",
213 i, st);
214 gspca_dev->last_packet_type = DISCARD_PACKET;
215 continue;
216 }
217
218 /*
219 * The images are received in URBs of different endpoints
220 * (0x83 and 0x82).
221 * Image pieces in URBs of ep 0x83 are continuated in URBs of
222 * ep 0x82 of the same index.
223 * The packets in the URBs of endpoint 0x83 start with:
224 * - 80 ba/bb 00 00 = start of image followed by 'ff d8'
225 * - 04 ba/bb oo oo = image piece
226 * where 'oo oo' is the image offset
227 (not cheked)
228 * - (other -> bad frame)
229 * The images are JPEG encoded with full header and
230 * normal ff escape.
231 * The end of image ('ff d9') may occur in any URB.
232 * (not cheked)
233 */
234 data = (u8 *) urb0->transfer_buffer
235 + urb0->iso_frame_desc[i].offset;
236 if (data[0] == 0x80 && (data[1] & 0xfe) == 0xba) {
237
238 /* new image */
239 gspca_frame_add(gspca_dev, LAST_PACKET,
240 NULL, 0);
241 gspca_frame_add(gspca_dev, FIRST_PACKET,
242 data + 4, SD_PKT_SZ - 4);
243 } else if (data[0] == 0x04 && (data[1] & 0xfe) == 0xba) {
244 gspca_frame_add(gspca_dev, INTER_PACKET,
245 data + 4, SD_PKT_SZ - 4);
246 } else {
247 gspca_dev->last_packet_type = DISCARD_PACKET;
248 continue;
249 }
250 data = (u8 *) urb->transfer_buffer
251 + urb->iso_frame_desc[i].offset;
252 gspca_frame_add(gspca_dev, INTER_PACKET,
253 data, SD_PKT_SZ);
254 }
255
256 /* resubmit the URBs */
257 st = usb_submit_urb(urb0, GFP_ATOMIC);
258 if (st < 0)
259 PDEBUG(D_ERR|D_PACK, "usb_submit_urb(0) ret %d", st);
260 st = usb_submit_urb(urb, GFP_ATOMIC);
261 if (st < 0)
262 PDEBUG(D_ERR|D_PACK, "usb_submit_urb() ret %d", st);
263}
264
265/* sub-driver description */
266static const struct sd_desc sd_desc = {
267 .name = MODULE_NAME,
268 .ctrls = sd_ctrls,
269 .nctrls = ARRAY_SIZE(sd_ctrls),
270 .config = sd_config,
271 .init = sd_init,
272 .isoc_init = sd_isoc_init,
273 .start = sd_start,
274 .stopN = sd_stopN,
275 .pkt_scan = sd_pkt_scan,
276};
277
278/* -- module initialisation -- */
279static const __devinitdata struct usb_device_id device_table[] = {
280 {USB_DEVICE(0x04a5, 0x3035)},
281 {}
282};
283MODULE_DEVICE_TABLE(usb, device_table);
284
285/* -- device connect -- */
286static int sd_probe(struct usb_interface *intf,
287 const struct usb_device_id *id)
288{
289 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
290 THIS_MODULE);
291}
292
293static struct usb_driver sd_driver = {
294 .name = MODULE_NAME,
295 .id_table = device_table,
296 .probe = sd_probe,
297 .disconnect = gspca_disconnect,
298#ifdef CONFIG_PM
299 .suspend = gspca_suspend,
300 .resume = gspca_resume,
301#endif
302};
303
304/* -- module insert / remove -- */
305static int __init sd_mod_init(void)
306{
307 int ret;
308
309 ret = usb_register(&sd_driver);
310 if (ret < 0)
311 return ret;
312 info("registered");
313 return 0;
314}
315static void __exit sd_mod_exit(void)
316{
317 usb_deregister(&sd_driver);
318 info("deregistered");
319}
320
321module_init(sd_mod_init);
322module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/coarse_expo_autogain.h b/drivers/media/video/gspca/coarse_expo_autogain.h
new file mode 100644
index 000000000000..1cb9d941eaf6
--- /dev/null
+++ b/drivers/media/video/gspca/coarse_expo_autogain.h
@@ -0,0 +1,116 @@
1/*
2 * Auto gain algorithm for camera's with a coarse exposure control
3 *
4 * Copyright (C) 2010 Hans de Goede <hdegoede@redhat.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/* Autogain + exposure algorithm for cameras with a coarse exposure control
22 (usually this means we can only control the clockdiv to change exposure)
23 As changing the clockdiv so that the fps drops from 30 to 15 fps for
24 example, will lead to a huge exposure change (it effectively doubles),
25 this algorithm normally tries to only adjust the gain (between 40 and
26 80 %) and if that does not help, only then changes exposure. This leads
27 to a much more stable image then using the knee algorithm which at
28 certain points of the knee graph will only try to adjust exposure,
29 which leads to oscilating as one exposure step is huge.
30
31 Note this assumes that the sd struct for the cam in question has
32 exp_too_high_cnt and exp_too_high_cnt int members for use by this function.
33
34 Returns 0 if no changes were made, 1 if the gain and or exposure settings
35 where changed. */
36static int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev,
37 int avg_lum, int desired_avg_lum, int deadzone)
38{
39 int i, steps, gain, orig_gain, exposure, orig_exposure;
40 int gain_low, gain_high;
41 const struct ctrl *gain_ctrl = NULL;
42 const struct ctrl *exposure_ctrl = NULL;
43 struct sd *sd = (struct sd *) gspca_dev;
44 int retval = 0;
45
46 for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) {
47 if (gspca_dev->ctrl_dis & (1 << i))
48 continue;
49 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_GAIN)
50 gain_ctrl = &gspca_dev->sd_desc->ctrls[i];
51 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_EXPOSURE)
52 exposure_ctrl = &gspca_dev->sd_desc->ctrls[i];
53 }
54 if (!gain_ctrl || !exposure_ctrl) {
55 PDEBUG(D_ERR, "Error: gspca_coarse_grained_expo_autogain "
56 "called on cam without gain or exposure");
57 return 0;
58 }
59
60 if (gain_ctrl->get(gspca_dev, &gain) ||
61 exposure_ctrl->get(gspca_dev, &exposure))
62 return 0;
63
64 orig_gain = gain;
65 orig_exposure = exposure;
66 gain_low =
67 (gain_ctrl->qctrl.maximum - gain_ctrl->qctrl.minimum) / 5 * 2;
68 gain_low += gain_ctrl->qctrl.minimum;
69 gain_high =
70 (gain_ctrl->qctrl.maximum - gain_ctrl->qctrl.minimum) / 5 * 4;
71 gain_high += gain_ctrl->qctrl.minimum;
72
73 /* If we are of a multiple of deadzone, do multiple steps to reach the
74 desired lumination fast (with the risc of a slight overshoot) */
75 steps = (desired_avg_lum - avg_lum) / deadzone;
76
77 PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d",
78 avg_lum, desired_avg_lum, steps);
79
80 if ((gain + steps) > gain_high &&
81 sd->exposure < exposure_ctrl->qctrl.maximum) {
82 gain = gain_high;
83 sd->exp_too_low_cnt++;
84 } else if ((gain + steps) < gain_low &&
85 sd->exposure > exposure_ctrl->qctrl.minimum) {
86 gain = gain_low;
87 sd->exp_too_high_cnt++;
88 } else {
89 gain += steps;
90 if (gain > gain_ctrl->qctrl.maximum)
91 gain = gain_ctrl->qctrl.maximum;
92 else if (gain < gain_ctrl->qctrl.minimum)
93 gain = gain_ctrl->qctrl.minimum;
94 sd->exp_too_high_cnt = 0;
95 sd->exp_too_low_cnt = 0;
96 }
97
98 if (sd->exp_too_high_cnt > 3) {
99 exposure--;
100 sd->exp_too_high_cnt = 0;
101 } else if (sd->exp_too_low_cnt > 3) {
102 exposure++;
103 sd->exp_too_low_cnt = 0;
104 }
105
106 if (gain != orig_gain) {
107 gain_ctrl->set(gspca_dev, gain);
108 retval = 1;
109 }
110 if (exposure != orig_exposure) {
111 exposure_ctrl->set(gspca_dev, exposure);
112 retval = 1;
113 }
114
115 return retval;
116}
diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c
index c98b5d69c438..19fe6b24c9a3 100644
--- a/drivers/media/video/gspca/conex.c
+++ b/drivers/media/video/gspca/conex.c
@@ -52,7 +52,7 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
52static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); 52static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
53static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); 53static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
54 54
55static struct ctrl sd_ctrls[] = { 55static const struct ctrl sd_ctrls[] = {
56 { 56 {
57 { 57 {
58 .id = V4L2_CID_BRIGHTNESS, 58 .id = V4L2_CID_BRIGHTNESS,
@@ -1032,7 +1032,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev,
1032} 1032}
1033 1033
1034/* sub-driver description */ 1034/* sub-driver description */
1035static struct sd_desc sd_desc = { 1035static const struct sd_desc sd_desc = {
1036 .name = MODULE_NAME, 1036 .name = MODULE_NAME,
1037 .ctrls = sd_ctrls, 1037 .ctrls = sd_ctrls,
1038 .nctrls = ARRAY_SIZE(sd_ctrls), 1038 .nctrls = ARRAY_SIZE(sd_ctrls),
diff --git a/drivers/media/video/gspca/cpia1.c b/drivers/media/video/gspca/cpia1.c
new file mode 100644
index 000000000000..82945ed5cbe5
--- /dev/null
+++ b/drivers/media/video/gspca/cpia1.c
@@ -0,0 +1,2022 @@
1/*
2 * cpia CPiA (1) gspca driver
3 *
4 * Copyright (C) 2010 Hans de Goede <hdgoede@redhat.com>
5 *
6 * This module is adapted from the in kernel v4l1 cpia driver which is :
7 *
8 * (C) Copyright 1999-2000 Peter Pregler
9 * (C) Copyright 1999-2000 Scott J. Bertin
10 * (C) Copyright 1999-2000 Johannes Erdfelt <johannes@erdfelt.com>
11 * (C) Copyright 2000 STMicroelectronics
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 */
28
29#define MODULE_NAME "cpia1"
30
31#include "gspca.h"
32
33MODULE_AUTHOR("Hans de Goede <hdgoede@redhat.com>");
34MODULE_DESCRIPTION("Vision CPiA");
35MODULE_LICENSE("GPL");
36
37/* constant value's */
38#define MAGIC_0 0x19
39#define MAGIC_1 0x68
40#define DATA_IN 0xC0
41#define DATA_OUT 0x40
42#define VIDEOSIZE_QCIF 0 /* 176x144 */
43#define VIDEOSIZE_CIF 1 /* 352x288 */
44#define SUBSAMPLE_420 0
45#define SUBSAMPLE_422 1
46#define YUVORDER_YUYV 0
47#define YUVORDER_UYVY 1
48#define NOT_COMPRESSED 0
49#define COMPRESSED 1
50#define NO_DECIMATION 0
51#define DECIMATION_ENAB 1
52#define EOI 0xff /* End Of Image */
53#define EOL 0xfd /* End Of Line */
54#define FRAME_HEADER_SIZE 64
55
56/* Image grab modes */
57#define CPIA_GRAB_SINGLE 0
58#define CPIA_GRAB_CONTINEOUS 1
59
60/* Compression parameters */
61#define CPIA_COMPRESSION_NONE 0
62#define CPIA_COMPRESSION_AUTO 1
63#define CPIA_COMPRESSION_MANUAL 2
64#define CPIA_COMPRESSION_TARGET_QUALITY 0
65#define CPIA_COMPRESSION_TARGET_FRAMERATE 1
66
67/* Return offsets for GetCameraState */
68#define SYSTEMSTATE 0
69#define GRABSTATE 1
70#define STREAMSTATE 2
71#define FATALERROR 3
72#define CMDERROR 4
73#define DEBUGFLAGS 5
74#define VPSTATUS 6
75#define ERRORCODE 7
76
77/* SystemState */
78#define UNINITIALISED_STATE 0
79#define PASS_THROUGH_STATE 1
80#define LO_POWER_STATE 2
81#define HI_POWER_STATE 3
82#define WARM_BOOT_STATE 4
83
84/* GrabState */
85#define GRAB_IDLE 0
86#define GRAB_ACTIVE 1
87#define GRAB_DONE 2
88
89/* StreamState */
90#define STREAM_NOT_READY 0
91#define STREAM_READY 1
92#define STREAM_OPEN 2
93#define STREAM_PAUSED 3
94#define STREAM_FINISHED 4
95
96/* Fatal Error, CmdError, and DebugFlags */
97#define CPIA_FLAG 1
98#define SYSTEM_FLAG 2
99#define INT_CTRL_FLAG 4
100#define PROCESS_FLAG 8
101#define COM_FLAG 16
102#define VP_CTRL_FLAG 32
103#define CAPTURE_FLAG 64
104#define DEBUG_FLAG 128
105
106/* VPStatus */
107#define VP_STATE_OK 0x00
108
109#define VP_STATE_FAILED_VIDEOINIT 0x01
110#define VP_STATE_FAILED_AECACBINIT 0x02
111#define VP_STATE_AEC_MAX 0x04
112#define VP_STATE_ACB_BMAX 0x08
113
114#define VP_STATE_ACB_RMIN 0x10
115#define VP_STATE_ACB_GMIN 0x20
116#define VP_STATE_ACB_RMAX 0x40
117#define VP_STATE_ACB_GMAX 0x80
118
119/* default (minimum) compensation values */
120#define COMP_RED 220
121#define COMP_GREEN1 214
122#define COMP_GREEN2 COMP_GREEN1
123#define COMP_BLUE 230
124
125/* exposure status */
126#define EXPOSURE_VERY_LIGHT 0
127#define EXPOSURE_LIGHT 1
128#define EXPOSURE_NORMAL 2
129#define EXPOSURE_DARK 3
130#define EXPOSURE_VERY_DARK 4
131
132#define CPIA_MODULE_CPIA (0 << 5)
133#define CPIA_MODULE_SYSTEM (1 << 5)
134#define CPIA_MODULE_VP_CTRL (5 << 5)
135#define CPIA_MODULE_CAPTURE (6 << 5)
136#define CPIA_MODULE_DEBUG (7 << 5)
137
138#define INPUT (DATA_IN << 8)
139#define OUTPUT (DATA_OUT << 8)
140
141#define CPIA_COMMAND_GetCPIAVersion (INPUT | CPIA_MODULE_CPIA | 1)
142#define CPIA_COMMAND_GetPnPID (INPUT | CPIA_MODULE_CPIA | 2)
143#define CPIA_COMMAND_GetCameraStatus (INPUT | CPIA_MODULE_CPIA | 3)
144#define CPIA_COMMAND_GotoHiPower (OUTPUT | CPIA_MODULE_CPIA | 4)
145#define CPIA_COMMAND_GotoLoPower (OUTPUT | CPIA_MODULE_CPIA | 5)
146#define CPIA_COMMAND_GotoSuspend (OUTPUT | CPIA_MODULE_CPIA | 7)
147#define CPIA_COMMAND_GotoPassThrough (OUTPUT | CPIA_MODULE_CPIA | 8)
148#define CPIA_COMMAND_ModifyCameraStatus (OUTPUT | CPIA_MODULE_CPIA | 10)
149
150#define CPIA_COMMAND_ReadVCRegs (INPUT | CPIA_MODULE_SYSTEM | 1)
151#define CPIA_COMMAND_WriteVCReg (OUTPUT | CPIA_MODULE_SYSTEM | 2)
152#define CPIA_COMMAND_ReadMCPorts (INPUT | CPIA_MODULE_SYSTEM | 3)
153#define CPIA_COMMAND_WriteMCPort (OUTPUT | CPIA_MODULE_SYSTEM | 4)
154#define CPIA_COMMAND_SetBaudRate (OUTPUT | CPIA_MODULE_SYSTEM | 5)
155#define CPIA_COMMAND_SetECPTiming (OUTPUT | CPIA_MODULE_SYSTEM | 6)
156#define CPIA_COMMAND_ReadIDATA (INPUT | CPIA_MODULE_SYSTEM | 7)
157#define CPIA_COMMAND_WriteIDATA (OUTPUT | CPIA_MODULE_SYSTEM | 8)
158#define CPIA_COMMAND_GenericCall (OUTPUT | CPIA_MODULE_SYSTEM | 9)
159#define CPIA_COMMAND_I2CStart (OUTPUT | CPIA_MODULE_SYSTEM | 10)
160#define CPIA_COMMAND_I2CStop (OUTPUT | CPIA_MODULE_SYSTEM | 11)
161#define CPIA_COMMAND_I2CWrite (OUTPUT | CPIA_MODULE_SYSTEM | 12)
162#define CPIA_COMMAND_I2CRead (INPUT | CPIA_MODULE_SYSTEM | 13)
163
164#define CPIA_COMMAND_GetVPVersion (INPUT | CPIA_MODULE_VP_CTRL | 1)
165#define CPIA_COMMAND_ResetFrameCounter (INPUT | CPIA_MODULE_VP_CTRL | 2)
166#define CPIA_COMMAND_SetColourParams (OUTPUT | CPIA_MODULE_VP_CTRL | 3)
167#define CPIA_COMMAND_SetExposure (OUTPUT | CPIA_MODULE_VP_CTRL | 4)
168#define CPIA_COMMAND_SetColourBalance (OUTPUT | CPIA_MODULE_VP_CTRL | 6)
169#define CPIA_COMMAND_SetSensorFPS (OUTPUT | CPIA_MODULE_VP_CTRL | 7)
170#define CPIA_COMMAND_SetVPDefaults (OUTPUT | CPIA_MODULE_VP_CTRL | 8)
171#define CPIA_COMMAND_SetApcor (OUTPUT | CPIA_MODULE_VP_CTRL | 9)
172#define CPIA_COMMAND_SetFlickerCtrl (OUTPUT | CPIA_MODULE_VP_CTRL | 10)
173#define CPIA_COMMAND_SetVLOffset (OUTPUT | CPIA_MODULE_VP_CTRL | 11)
174#define CPIA_COMMAND_GetColourParams (INPUT | CPIA_MODULE_VP_CTRL | 16)
175#define CPIA_COMMAND_GetColourBalance (INPUT | CPIA_MODULE_VP_CTRL | 17)
176#define CPIA_COMMAND_GetExposure (INPUT | CPIA_MODULE_VP_CTRL | 18)
177#define CPIA_COMMAND_SetSensorMatrix (OUTPUT | CPIA_MODULE_VP_CTRL | 19)
178#define CPIA_COMMAND_ColourBars (OUTPUT | CPIA_MODULE_VP_CTRL | 25)
179#define CPIA_COMMAND_ReadVPRegs (INPUT | CPIA_MODULE_VP_CTRL | 30)
180#define CPIA_COMMAND_WriteVPReg (OUTPUT | CPIA_MODULE_VP_CTRL | 31)
181
182#define CPIA_COMMAND_GrabFrame (OUTPUT | CPIA_MODULE_CAPTURE | 1)
183#define CPIA_COMMAND_UploadFrame (OUTPUT | CPIA_MODULE_CAPTURE | 2)
184#define CPIA_COMMAND_SetGrabMode (OUTPUT | CPIA_MODULE_CAPTURE | 3)
185#define CPIA_COMMAND_InitStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 4)
186#define CPIA_COMMAND_FiniStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 5)
187#define CPIA_COMMAND_StartStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 6)
188#define CPIA_COMMAND_EndStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 7)
189#define CPIA_COMMAND_SetFormat (OUTPUT | CPIA_MODULE_CAPTURE | 8)
190#define CPIA_COMMAND_SetROI (OUTPUT | CPIA_MODULE_CAPTURE | 9)
191#define CPIA_COMMAND_SetCompression (OUTPUT | CPIA_MODULE_CAPTURE | 10)
192#define CPIA_COMMAND_SetCompressionTarget (OUTPUT | CPIA_MODULE_CAPTURE | 11)
193#define CPIA_COMMAND_SetYUVThresh (OUTPUT | CPIA_MODULE_CAPTURE | 12)
194#define CPIA_COMMAND_SetCompressionParams (OUTPUT | CPIA_MODULE_CAPTURE | 13)
195#define CPIA_COMMAND_DiscardFrame (OUTPUT | CPIA_MODULE_CAPTURE | 14)
196#define CPIA_COMMAND_GrabReset (OUTPUT | CPIA_MODULE_CAPTURE | 15)
197
198#define CPIA_COMMAND_OutputRS232 (OUTPUT | CPIA_MODULE_DEBUG | 1)
199#define CPIA_COMMAND_AbortProcess (OUTPUT | CPIA_MODULE_DEBUG | 4)
200#define CPIA_COMMAND_SetDramPage (OUTPUT | CPIA_MODULE_DEBUG | 5)
201#define CPIA_COMMAND_StartDramUpload (OUTPUT | CPIA_MODULE_DEBUG | 6)
202#define CPIA_COMMAND_StartDummyDtream (OUTPUT | CPIA_MODULE_DEBUG | 8)
203#define CPIA_COMMAND_AbortStream (OUTPUT | CPIA_MODULE_DEBUG | 9)
204#define CPIA_COMMAND_DownloadDRAM (OUTPUT | CPIA_MODULE_DEBUG | 10)
205#define CPIA_COMMAND_Null (OUTPUT | CPIA_MODULE_DEBUG | 11)
206
207#define ROUND_UP_EXP_FOR_FLICKER 15
208
209/* Constants for automatic frame rate adjustment */
210#define MAX_EXP 302
211#define MAX_EXP_102 255
212#define LOW_EXP 140
213#define VERY_LOW_EXP 70
214#define TC 94
215#define EXP_ACC_DARK 50
216#define EXP_ACC_LIGHT 90
217#define HIGH_COMP_102 160
218#define MAX_COMP 239
219#define DARK_TIME 3
220#define LIGHT_TIME 3
221
222#define FIRMWARE_VERSION(x, y) (sd->params.version.firmwareVersion == (x) && \
223 sd->params.version.firmwareRevision == (y))
224
225/* Developer's Guide Table 5 p 3-34
226 * indexed by [mains][sensorFps.baserate][sensorFps.divisor]*/
227static u8 flicker_jumps[2][2][4] =
228{ { { 76, 38, 19, 9 }, { 92, 46, 23, 11 } },
229 { { 64, 32, 16, 8 }, { 76, 38, 19, 9} }
230};
231
232struct cam_params {
233 struct {
234 u8 firmwareVersion;
235 u8 firmwareRevision;
236 u8 vcVersion;
237 u8 vcRevision;
238 } version;
239 struct {
240 u16 vendor;
241 u16 product;
242 u16 deviceRevision;
243 } pnpID;
244 struct {
245 u8 vpVersion;
246 u8 vpRevision;
247 u16 cameraHeadID;
248 } vpVersion;
249 struct {
250 u8 systemState;
251 u8 grabState;
252 u8 streamState;
253 u8 fatalError;
254 u8 cmdError;
255 u8 debugFlags;
256 u8 vpStatus;
257 u8 errorCode;
258 } status;
259 struct {
260 u8 brightness;
261 u8 contrast;
262 u8 saturation;
263 } colourParams;
264 struct {
265 u8 gainMode;
266 u8 expMode;
267 u8 compMode;
268 u8 centreWeight;
269 u8 gain;
270 u8 fineExp;
271 u8 coarseExpLo;
272 u8 coarseExpHi;
273 u8 redComp;
274 u8 green1Comp;
275 u8 green2Comp;
276 u8 blueComp;
277 } exposure;
278 struct {
279 u8 balanceMode;
280 u8 redGain;
281 u8 greenGain;
282 u8 blueGain;
283 } colourBalance;
284 struct {
285 u8 divisor;
286 u8 baserate;
287 } sensorFps;
288 struct {
289 u8 gain1;
290 u8 gain2;
291 u8 gain4;
292 u8 gain8;
293 } apcor;
294 struct {
295 u8 disabled;
296 u8 flickerMode;
297 u8 coarseJump;
298 u8 allowableOverExposure;
299 } flickerControl;
300 struct {
301 u8 gain1;
302 u8 gain2;
303 u8 gain4;
304 u8 gain8;
305 } vlOffset;
306 struct {
307 u8 mode;
308 u8 decimation;
309 } compression;
310 struct {
311 u8 frTargeting;
312 u8 targetFR;
313 u8 targetQ;
314 } compressionTarget;
315 struct {
316 u8 yThreshold;
317 u8 uvThreshold;
318 } yuvThreshold;
319 struct {
320 u8 hysteresis;
321 u8 threshMax;
322 u8 smallStep;
323 u8 largeStep;
324 u8 decimationHysteresis;
325 u8 frDiffStepThresh;
326 u8 qDiffStepThresh;
327 u8 decimationThreshMod;
328 } compressionParams;
329 struct {
330 u8 videoSize; /* CIF/QCIF */
331 u8 subSample;
332 u8 yuvOrder;
333 } format;
334 struct { /* Intel QX3 specific data */
335 u8 qx3_detected; /* a QX3 is present */
336 u8 toplight; /* top light lit , R/W */
337 u8 bottomlight; /* bottom light lit, R/W */
338 u8 button; /* snapshot button pressed (R/O) */
339 u8 cradled; /* microscope is in cradle (R/O) */
340 } qx3;
341 struct {
342 u8 colStart; /* skip first 8*colStart pixels */
343 u8 colEnd; /* finish at 8*colEnd pixels */
344 u8 rowStart; /* skip first 4*rowStart lines */
345 u8 rowEnd; /* finish at 4*rowEnd lines */
346 } roi;
347 u8 ecpTiming;
348 u8 streamStartLine;
349};
350
351/* specific webcam descriptor */
352struct sd {
353 struct gspca_dev gspca_dev; /* !! must be the first item */
354 struct cam_params params; /* camera settings */
355
356 atomic_t cam_exposure;
357 atomic_t fps;
358 int exposure_count;
359 u8 exposure_status;
360 u8 mainsFreq; /* 0 = 50hz, 1 = 60hz */
361 u8 first_frame;
362 u8 freq;
363};
364
365/* V4L2 controls supported by the driver */
366static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
367static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
368static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
369static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
370static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val);
371static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val);
372static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
373static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
374static int sd_setcomptarget(struct gspca_dev *gspca_dev, __s32 val);
375static int sd_getcomptarget(struct gspca_dev *gspca_dev, __s32 *val);
376
377static struct ctrl sd_ctrls[] = {
378 {
379 {
380 .id = V4L2_CID_BRIGHTNESS,
381 .type = V4L2_CTRL_TYPE_INTEGER,
382 .name = "Brightness",
383 .minimum = 0,
384 .maximum = 100,
385 .step = 1,
386#define BRIGHTNESS_DEF 50
387 .default_value = BRIGHTNESS_DEF,
388 .flags = 0,
389 },
390 .set = sd_setbrightness,
391 .get = sd_getbrightness,
392 },
393 {
394 {
395 .id = V4L2_CID_CONTRAST,
396 .type = V4L2_CTRL_TYPE_INTEGER,
397 .name = "Contrast",
398 .minimum = 0,
399 .maximum = 96,
400 .step = 8,
401#define CONTRAST_DEF 48
402 .default_value = CONTRAST_DEF,
403 },
404 .set = sd_setcontrast,
405 .get = sd_getcontrast,
406 },
407 {
408 {
409 .id = V4L2_CID_SATURATION,
410 .type = V4L2_CTRL_TYPE_INTEGER,
411 .name = "Saturation",
412 .minimum = 0,
413 .maximum = 100,
414 .step = 1,
415#define SATURATION_DEF 50
416 .default_value = SATURATION_DEF,
417 },
418 .set = sd_setsaturation,
419 .get = sd_getsaturation,
420 },
421 {
422 {
423 .id = V4L2_CID_POWER_LINE_FREQUENCY,
424 .type = V4L2_CTRL_TYPE_MENU,
425 .name = "Light frequency filter",
426 .minimum = 0,
427 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
428 .step = 1,
429#define FREQ_DEF 1
430 .default_value = FREQ_DEF,
431 },
432 .set = sd_setfreq,
433 .get = sd_getfreq,
434 },
435 {
436 {
437#define V4L2_CID_COMP_TARGET V4L2_CID_PRIVATE_BASE
438 .id = V4L2_CID_COMP_TARGET,
439 .type = V4L2_CTRL_TYPE_MENU,
440 .name = "Compression Target",
441 .minimum = 0,
442 .maximum = 1,
443 .step = 1,
444#define COMP_TARGET_DEF CPIA_COMPRESSION_TARGET_QUALITY
445 .default_value = COMP_TARGET_DEF,
446 },
447 .set = sd_setcomptarget,
448 .get = sd_getcomptarget,
449 },
450};
451
452static const struct v4l2_pix_format mode[] = {
453 {160, 120, V4L2_PIX_FMT_CPIA1, V4L2_FIELD_NONE,
454 /* The sizeimage is trial and error, as with low framerates
455 the camera will pad out usb frames, making the image
456 data larger then strictly necessary */
457 .bytesperline = 160,
458 .sizeimage = 65536,
459 .colorspace = V4L2_COLORSPACE_SRGB,
460 .priv = 3},
461 {176, 144, V4L2_PIX_FMT_CPIA1, V4L2_FIELD_NONE,
462 .bytesperline = 172,
463 .sizeimage = 65536,
464 .colorspace = V4L2_COLORSPACE_SRGB,
465 .priv = 2},
466 {320, 240, V4L2_PIX_FMT_CPIA1, V4L2_FIELD_NONE,
467 .bytesperline = 320,
468 .sizeimage = 262144,
469 .colorspace = V4L2_COLORSPACE_SRGB,
470 .priv = 1},
471 {352, 288, V4L2_PIX_FMT_CPIA1, V4L2_FIELD_NONE,
472 .bytesperline = 352,
473 .sizeimage = 262144,
474 .colorspace = V4L2_COLORSPACE_SRGB,
475 .priv = 0},
476};
477
478/**********************************************************************
479 *
480 * General functions
481 *
482 **********************************************************************/
483
484static int cpia_usb_transferCmd(struct gspca_dev *gspca_dev, u8 *command)
485{
486 u8 requesttype;
487 unsigned int pipe;
488 int ret, databytes = command[6] | (command[7] << 8);
489 /* Sometimes we see spurious EPIPE errors */
490 int retries = 3;
491
492 if (command[0] == DATA_IN) {
493 pipe = usb_rcvctrlpipe(gspca_dev->dev, 0);
494 requesttype = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
495 } else if (command[0] == DATA_OUT) {
496 pipe = usb_sndctrlpipe(gspca_dev->dev, 0);
497 requesttype = USB_TYPE_VENDOR | USB_RECIP_DEVICE;
498 } else {
499 PDEBUG(D_ERR, "Unexpected first byte of command: %x",
500 command[0]);
501 return -EINVAL;
502 }
503
504retry:
505 ret = usb_control_msg(gspca_dev->dev, pipe,
506 command[1],
507 requesttype,
508 command[2] | (command[3] << 8),
509 command[4] | (command[5] << 8),
510 gspca_dev->usb_buf, databytes, 1000);
511
512 if (ret < 0)
513 PDEBUG(D_ERR, "usb_control_msg %02x, error %d", command[1],
514 ret);
515
516 if (ret == -EPIPE && retries > 0) {
517 retries--;
518 goto retry;
519 }
520
521 return (ret < 0) ? ret : 0;
522}
523
524/* send an arbitrary command to the camera */
525static int do_command(struct gspca_dev *gspca_dev, u16 command,
526 u8 a, u8 b, u8 c, u8 d)
527{
528 struct sd *sd = (struct sd *) gspca_dev;
529 int ret, datasize;
530 u8 cmd[8];
531
532 switch (command) {
533 case CPIA_COMMAND_GetCPIAVersion:
534 case CPIA_COMMAND_GetPnPID:
535 case CPIA_COMMAND_GetCameraStatus:
536 case CPIA_COMMAND_GetVPVersion:
537 case CPIA_COMMAND_GetColourParams:
538 case CPIA_COMMAND_GetColourBalance:
539 case CPIA_COMMAND_GetExposure:
540 datasize = 8;
541 break;
542 case CPIA_COMMAND_ReadMCPorts:
543 case CPIA_COMMAND_ReadVCRegs:
544 datasize = 4;
545 break;
546 default:
547 datasize = 0;
548 break;
549 }
550
551 cmd[0] = command >> 8;
552 cmd[1] = command & 0xff;
553 cmd[2] = a;
554 cmd[3] = b;
555 cmd[4] = c;
556 cmd[5] = d;
557 cmd[6] = datasize;
558 cmd[7] = 0;
559
560 ret = cpia_usb_transferCmd(gspca_dev, cmd);
561 if (ret)
562 return ret;
563
564 switch (command) {
565 case CPIA_COMMAND_GetCPIAVersion:
566 sd->params.version.firmwareVersion = gspca_dev->usb_buf[0];
567 sd->params.version.firmwareRevision = gspca_dev->usb_buf[1];
568 sd->params.version.vcVersion = gspca_dev->usb_buf[2];
569 sd->params.version.vcRevision = gspca_dev->usb_buf[3];
570 break;
571 case CPIA_COMMAND_GetPnPID:
572 sd->params.pnpID.vendor =
573 gspca_dev->usb_buf[0] | (gspca_dev->usb_buf[1] << 8);
574 sd->params.pnpID.product =
575 gspca_dev->usb_buf[2] | (gspca_dev->usb_buf[3] << 8);
576 sd->params.pnpID.deviceRevision =
577 gspca_dev->usb_buf[4] | (gspca_dev->usb_buf[5] << 8);
578 break;
579 case CPIA_COMMAND_GetCameraStatus:
580 sd->params.status.systemState = gspca_dev->usb_buf[0];
581 sd->params.status.grabState = gspca_dev->usb_buf[1];
582 sd->params.status.streamState = gspca_dev->usb_buf[2];
583 sd->params.status.fatalError = gspca_dev->usb_buf[3];
584 sd->params.status.cmdError = gspca_dev->usb_buf[4];
585 sd->params.status.debugFlags = gspca_dev->usb_buf[5];
586 sd->params.status.vpStatus = gspca_dev->usb_buf[6];
587 sd->params.status.errorCode = gspca_dev->usb_buf[7];
588 break;
589 case CPIA_COMMAND_GetVPVersion:
590 sd->params.vpVersion.vpVersion = gspca_dev->usb_buf[0];
591 sd->params.vpVersion.vpRevision = gspca_dev->usb_buf[1];
592 sd->params.vpVersion.cameraHeadID =
593 gspca_dev->usb_buf[2] | (gspca_dev->usb_buf[3] << 8);
594 break;
595 case CPIA_COMMAND_GetColourParams:
596 sd->params.colourParams.brightness = gspca_dev->usb_buf[0];
597 sd->params.colourParams.contrast = gspca_dev->usb_buf[1];
598 sd->params.colourParams.saturation = gspca_dev->usb_buf[2];
599 break;
600 case CPIA_COMMAND_GetColourBalance:
601 sd->params.colourBalance.redGain = gspca_dev->usb_buf[0];
602 sd->params.colourBalance.greenGain = gspca_dev->usb_buf[1];
603 sd->params.colourBalance.blueGain = gspca_dev->usb_buf[2];
604 break;
605 case CPIA_COMMAND_GetExposure:
606 sd->params.exposure.gain = gspca_dev->usb_buf[0];
607 sd->params.exposure.fineExp = gspca_dev->usb_buf[1];
608 sd->params.exposure.coarseExpLo = gspca_dev->usb_buf[2];
609 sd->params.exposure.coarseExpHi = gspca_dev->usb_buf[3];
610 sd->params.exposure.redComp = gspca_dev->usb_buf[4];
611 sd->params.exposure.green1Comp = gspca_dev->usb_buf[5];
612 sd->params.exposure.green2Comp = gspca_dev->usb_buf[6];
613 sd->params.exposure.blueComp = gspca_dev->usb_buf[7];
614 break;
615
616 case CPIA_COMMAND_ReadMCPorts:
617 if (!sd->params.qx3.qx3_detected)
618 break;
619 /* test button press */
620 sd->params.qx3.button = ((gspca_dev->usb_buf[1] & 0x02) == 0);
621 if (sd->params.qx3.button) {
622 /* button pressed - unlock the latch */
623 do_command(gspca_dev, CPIA_COMMAND_WriteMCPort,
624 3, 0xDF, 0xDF, 0);
625 do_command(gspca_dev, CPIA_COMMAND_WriteMCPort,
626 3, 0xFF, 0xFF, 0);
627 }
628
629 /* test whether microscope is cradled */
630 sd->params.qx3.cradled = ((gspca_dev->usb_buf[2] & 0x40) == 0);
631 break;
632 }
633
634 return 0;
635}
636
637/* send a command to the camera with an additional data transaction */
638static int do_command_extended(struct gspca_dev *gspca_dev, u16 command,
639 u8 a, u8 b, u8 c, u8 d,
640 u8 e, u8 f, u8 g, u8 h,
641 u8 i, u8 j, u8 k, u8 l)
642{
643 u8 cmd[8];
644
645 cmd[0] = command >> 8;
646 cmd[1] = command & 0xff;
647 cmd[2] = a;
648 cmd[3] = b;
649 cmd[4] = c;
650 cmd[5] = d;
651 cmd[6] = 8;
652 cmd[7] = 0;
653 gspca_dev->usb_buf[0] = e;
654 gspca_dev->usb_buf[1] = f;
655 gspca_dev->usb_buf[2] = g;
656 gspca_dev->usb_buf[3] = h;
657 gspca_dev->usb_buf[4] = i;
658 gspca_dev->usb_buf[5] = j;
659 gspca_dev->usb_buf[6] = k;
660 gspca_dev->usb_buf[7] = l;
661
662 return cpia_usb_transferCmd(gspca_dev, cmd);
663}
664
665/* find_over_exposure
666 * Finds a suitable value of OverExposure for use with SetFlickerCtrl
667 * Some calculation is required because this value changes with the brightness
668 * set with SetColourParameters
669 *
670 * Parameters: Brightness - last brightness value set with SetColourParameters
671 *
672 * Returns: OverExposure value to use with SetFlickerCtrl
673 */
674#define FLICKER_MAX_EXPOSURE 250
675#define FLICKER_ALLOWABLE_OVER_EXPOSURE 146
676#define FLICKER_BRIGHTNESS_CONSTANT 59
677static int find_over_exposure(int brightness)
678{
679 int MaxAllowableOverExposure, OverExposure;
680
681 MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness -
682 FLICKER_BRIGHTNESS_CONSTANT;
683
684 if (MaxAllowableOverExposure < FLICKER_ALLOWABLE_OVER_EXPOSURE)
685 OverExposure = MaxAllowableOverExposure;
686 else
687 OverExposure = FLICKER_ALLOWABLE_OVER_EXPOSURE;
688
689 return OverExposure;
690}
691#undef FLICKER_MAX_EXPOSURE
692#undef FLICKER_ALLOWABLE_OVER_EXPOSURE
693#undef FLICKER_BRIGHTNESS_CONSTANT
694
695/* initialise cam_data structure */
696static void reset_camera_params(struct gspca_dev *gspca_dev)
697{
698 struct sd *sd = (struct sd *) gspca_dev;
699 struct cam_params *params = &sd->params;
700
701 /* The following parameter values are the defaults from
702 * "Software Developer's Guide for CPiA Cameras". Any changes
703 * to the defaults are noted in comments. */
704 params->colourParams.brightness = BRIGHTNESS_DEF;
705 params->colourParams.contrast = CONTRAST_DEF;
706 params->colourParams.saturation = SATURATION_DEF;
707 params->exposure.gainMode = 4;
708 params->exposure.expMode = 2; /* AEC */
709 params->exposure.compMode = 1;
710 params->exposure.centreWeight = 1;
711 params->exposure.gain = 0;
712 params->exposure.fineExp = 0;
713 params->exposure.coarseExpLo = 185;
714 params->exposure.coarseExpHi = 0;
715 params->exposure.redComp = COMP_RED;
716 params->exposure.green1Comp = COMP_GREEN1;
717 params->exposure.green2Comp = COMP_GREEN2;
718 params->exposure.blueComp = COMP_BLUE;
719 params->colourBalance.balanceMode = 2; /* ACB */
720 params->colourBalance.redGain = 32;
721 params->colourBalance.greenGain = 6;
722 params->colourBalance.blueGain = 92;
723 params->apcor.gain1 = 0x18;
724 params->apcor.gain2 = 0x16;
725 params->apcor.gain4 = 0x24;
726 params->apcor.gain8 = 0x34;
727 params->flickerControl.flickerMode = 0;
728 params->flickerControl.disabled = 1;
729
730 params->flickerControl.coarseJump =
731 flicker_jumps[sd->mainsFreq]
732 [params->sensorFps.baserate]
733 [params->sensorFps.divisor];
734 params->flickerControl.allowableOverExposure =
735 find_over_exposure(params->colourParams.brightness);
736 params->vlOffset.gain1 = 20;
737 params->vlOffset.gain2 = 24;
738 params->vlOffset.gain4 = 26;
739 params->vlOffset.gain8 = 26;
740 params->compressionParams.hysteresis = 3;
741 params->compressionParams.threshMax = 11;
742 params->compressionParams.smallStep = 1;
743 params->compressionParams.largeStep = 3;
744 params->compressionParams.decimationHysteresis = 2;
745 params->compressionParams.frDiffStepThresh = 5;
746 params->compressionParams.qDiffStepThresh = 3;
747 params->compressionParams.decimationThreshMod = 2;
748 /* End of default values from Software Developer's Guide */
749
750 /* Set Sensor FPS to 15fps. This seems better than 30fps
751 * for indoor lighting. */
752 params->sensorFps.divisor = 1;
753 params->sensorFps.baserate = 1;
754
755 params->yuvThreshold.yThreshold = 6; /* From windows driver */
756 params->yuvThreshold.uvThreshold = 6; /* From windows driver */
757
758 params->format.subSample = SUBSAMPLE_420;
759 params->format.yuvOrder = YUVORDER_YUYV;
760
761 params->compression.mode = CPIA_COMPRESSION_AUTO;
762 params->compression.decimation = NO_DECIMATION;
763
764 params->compressionTarget.frTargeting = COMP_TARGET_DEF;
765 params->compressionTarget.targetFR = 15; /* From windows driver */
766 params->compressionTarget.targetQ = 5; /* From windows driver */
767
768 params->qx3.qx3_detected = 0;
769 params->qx3.toplight = 0;
770 params->qx3.bottomlight = 0;
771 params->qx3.button = 0;
772 params->qx3.cradled = 0;
773}
774
775static void printstatus(struct cam_params *params)
776{
777 PDEBUG(D_PROBE, "status: %02x %02x %02x %02x %02x %02x %02x %02x",
778 params->status.systemState, params->status.grabState,
779 params->status.streamState, params->status.fatalError,
780 params->status.cmdError, params->status.debugFlags,
781 params->status.vpStatus, params->status.errorCode);
782}
783
784static int goto_low_power(struct gspca_dev *gspca_dev)
785{
786 struct sd *sd = (struct sd *) gspca_dev;
787 int ret;
788
789 ret = do_command(gspca_dev, CPIA_COMMAND_GotoLoPower, 0, 0, 0, 0);
790 if (ret)
791 return ret;
792
793 do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0);
794 if (ret)
795 return ret;
796
797 if (sd->params.status.systemState != LO_POWER_STATE) {
798 if (sd->params.status.systemState != WARM_BOOT_STATE) {
799 PDEBUG(D_ERR,
800 "unexpected state after lo power cmd: %02x",
801 sd->params.status.systemState);
802 printstatus(&sd->params);
803 }
804 return -EIO;
805 }
806
807 PDEBUG(D_CONF, "camera now in LOW power state");
808 return 0;
809}
810
811static int goto_high_power(struct gspca_dev *gspca_dev)
812{
813 struct sd *sd = (struct sd *) gspca_dev;
814 int ret;
815
816 ret = do_command(gspca_dev, CPIA_COMMAND_GotoHiPower, 0, 0, 0, 0);
817 if (ret)
818 return ret;
819
820 msleep_interruptible(40); /* windows driver does it too */
821
822 if (signal_pending(current))
823 return -EINTR;
824
825 do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0);
826 if (ret)
827 return ret;
828
829 if (sd->params.status.systemState != HI_POWER_STATE) {
830 PDEBUG(D_ERR, "unexpected state after hi power cmd: %02x",
831 sd->params.status.systemState);
832 printstatus(&sd->params);
833 return -EIO;
834 }
835
836 PDEBUG(D_CONF, "camera now in HIGH power state");
837 return 0;
838}
839
840static int get_version_information(struct gspca_dev *gspca_dev)
841{
842 int ret;
843
844 /* GetCPIAVersion */
845 ret = do_command(gspca_dev, CPIA_COMMAND_GetCPIAVersion, 0, 0, 0, 0);
846 if (ret)
847 return ret;
848
849 /* GetPnPID */
850 return do_command(gspca_dev, CPIA_COMMAND_GetPnPID, 0, 0, 0, 0);
851}
852
853static int save_camera_state(struct gspca_dev *gspca_dev)
854{
855 int ret;
856
857 ret = do_command(gspca_dev, CPIA_COMMAND_GetColourBalance, 0, 0, 0, 0);
858 if (ret)
859 return ret;
860
861 return do_command(gspca_dev, CPIA_COMMAND_GetExposure, 0, 0, 0, 0);
862}
863
864int command_setformat(struct gspca_dev *gspca_dev)
865{
866 struct sd *sd = (struct sd *) gspca_dev;
867 int ret;
868
869 ret = do_command(gspca_dev, CPIA_COMMAND_SetFormat,
870 sd->params.format.videoSize,
871 sd->params.format.subSample,
872 sd->params.format.yuvOrder, 0);
873 if (ret)
874 return ret;
875
876 return do_command(gspca_dev, CPIA_COMMAND_SetROI,
877 sd->params.roi.colStart, sd->params.roi.colEnd,
878 sd->params.roi.rowStart, sd->params.roi.rowEnd);
879}
880
881int command_setcolourparams(struct gspca_dev *gspca_dev)
882{
883 struct sd *sd = (struct sd *) gspca_dev;
884 return do_command(gspca_dev, CPIA_COMMAND_SetColourParams,
885 sd->params.colourParams.brightness,
886 sd->params.colourParams.contrast,
887 sd->params.colourParams.saturation, 0);
888}
889
890int command_setapcor(struct gspca_dev *gspca_dev)
891{
892 struct sd *sd = (struct sd *) gspca_dev;
893 return do_command(gspca_dev, CPIA_COMMAND_SetApcor,
894 sd->params.apcor.gain1,
895 sd->params.apcor.gain2,
896 sd->params.apcor.gain4,
897 sd->params.apcor.gain8);
898}
899
900int command_setvloffset(struct gspca_dev *gspca_dev)
901{
902 struct sd *sd = (struct sd *) gspca_dev;
903 return do_command(gspca_dev, CPIA_COMMAND_SetVLOffset,
904 sd->params.vlOffset.gain1,
905 sd->params.vlOffset.gain2,
906 sd->params.vlOffset.gain4,
907 sd->params.vlOffset.gain8);
908}
909
910int command_setexposure(struct gspca_dev *gspca_dev)
911{
912 struct sd *sd = (struct sd *) gspca_dev;
913 int ret;
914
915 ret = do_command_extended(gspca_dev, CPIA_COMMAND_SetExposure,
916 sd->params.exposure.gainMode,
917 1,
918 sd->params.exposure.compMode,
919 sd->params.exposure.centreWeight,
920 sd->params.exposure.gain,
921 sd->params.exposure.fineExp,
922 sd->params.exposure.coarseExpLo,
923 sd->params.exposure.coarseExpHi,
924 sd->params.exposure.redComp,
925 sd->params.exposure.green1Comp,
926 sd->params.exposure.green2Comp,
927 sd->params.exposure.blueComp);
928 if (ret)
929 return ret;
930
931 if (sd->params.exposure.expMode != 1) {
932 ret = do_command_extended(gspca_dev, CPIA_COMMAND_SetExposure,
933 0,
934 sd->params.exposure.expMode,
935 0, 0,
936 sd->params.exposure.gain,
937 sd->params.exposure.fineExp,
938 sd->params.exposure.coarseExpLo,
939 sd->params.exposure.coarseExpHi,
940 0, 0, 0, 0);
941 }
942
943 return ret;
944}
945
946int command_setcolourbalance(struct gspca_dev *gspca_dev)
947{
948 struct sd *sd = (struct sd *) gspca_dev;
949
950 if (sd->params.colourBalance.balanceMode == 1) {
951 int ret;
952
953 ret = do_command(gspca_dev, CPIA_COMMAND_SetColourBalance,
954 1,
955 sd->params.colourBalance.redGain,
956 sd->params.colourBalance.greenGain,
957 sd->params.colourBalance.blueGain);
958 if (ret)
959 return ret;
960
961 return do_command(gspca_dev, CPIA_COMMAND_SetColourBalance,
962 3, 0, 0, 0);
963 }
964 if (sd->params.colourBalance.balanceMode == 2) {
965 return do_command(gspca_dev, CPIA_COMMAND_SetColourBalance,
966 2, 0, 0, 0);
967 }
968 if (sd->params.colourBalance.balanceMode == 3) {
969 return do_command(gspca_dev, CPIA_COMMAND_SetColourBalance,
970 3, 0, 0, 0);
971 }
972
973 return -EINVAL;
974}
975
976int command_setcompressiontarget(struct gspca_dev *gspca_dev)
977{
978 struct sd *sd = (struct sd *) gspca_dev;
979
980 return do_command(gspca_dev, CPIA_COMMAND_SetCompressionTarget,
981 sd->params.compressionTarget.frTargeting,
982 sd->params.compressionTarget.targetFR,
983 sd->params.compressionTarget.targetQ, 0);
984}
985
986int command_setyuvtresh(struct gspca_dev *gspca_dev)
987{
988 struct sd *sd = (struct sd *) gspca_dev;
989
990 return do_command(gspca_dev, CPIA_COMMAND_SetYUVThresh,
991 sd->params.yuvThreshold.yThreshold,
992 sd->params.yuvThreshold.uvThreshold, 0, 0);
993}
994
995int command_setcompressionparams(struct gspca_dev *gspca_dev)
996{
997 struct sd *sd = (struct sd *) gspca_dev;
998
999 return do_command_extended(gspca_dev,
1000 CPIA_COMMAND_SetCompressionParams,
1001 0, 0, 0, 0,
1002 sd->params.compressionParams.hysteresis,
1003 sd->params.compressionParams.threshMax,
1004 sd->params.compressionParams.smallStep,
1005 sd->params.compressionParams.largeStep,
1006 sd->params.compressionParams.decimationHysteresis,
1007 sd->params.compressionParams.frDiffStepThresh,
1008 sd->params.compressionParams.qDiffStepThresh,
1009 sd->params.compressionParams.decimationThreshMod);
1010}
1011
1012int command_setcompression(struct gspca_dev *gspca_dev)
1013{
1014 struct sd *sd = (struct sd *) gspca_dev;
1015
1016 return do_command(gspca_dev, CPIA_COMMAND_SetCompression,
1017 sd->params.compression.mode,
1018 sd->params.compression.decimation, 0, 0);
1019}
1020
1021int command_setsensorfps(struct gspca_dev *gspca_dev)
1022{
1023 struct sd *sd = (struct sd *) gspca_dev;
1024
1025 return do_command(gspca_dev, CPIA_COMMAND_SetSensorFPS,
1026 sd->params.sensorFps.divisor,
1027 sd->params.sensorFps.baserate, 0, 0);
1028}
1029
1030int command_setflickerctrl(struct gspca_dev *gspca_dev)
1031{
1032 struct sd *sd = (struct sd *) gspca_dev;
1033
1034 return do_command(gspca_dev, CPIA_COMMAND_SetFlickerCtrl,
1035 sd->params.flickerControl.flickerMode,
1036 sd->params.flickerControl.coarseJump,
1037 sd->params.flickerControl.allowableOverExposure,
1038 0);
1039}
1040
1041int command_setecptiming(struct gspca_dev *gspca_dev)
1042{
1043 struct sd *sd = (struct sd *) gspca_dev;
1044
1045 return do_command(gspca_dev, CPIA_COMMAND_SetECPTiming,
1046 sd->params.ecpTiming, 0, 0, 0);
1047}
1048
1049int command_pause(struct gspca_dev *gspca_dev)
1050{
1051 return do_command(gspca_dev, CPIA_COMMAND_EndStreamCap, 0, 0, 0, 0);
1052}
1053
1054int command_resume(struct gspca_dev *gspca_dev)
1055{
1056 struct sd *sd = (struct sd *) gspca_dev;
1057
1058 return do_command(gspca_dev, CPIA_COMMAND_InitStreamCap,
1059 0, sd->params.streamStartLine, 0, 0);
1060}
1061
1062int command_setlights(struct gspca_dev *gspca_dev)
1063{
1064 struct sd *sd = (struct sd *) gspca_dev;
1065 int ret, p1, p2;
1066
1067 if (!sd->params.qx3.qx3_detected)
1068 return 0;
1069
1070 p1 = (sd->params.qx3.bottomlight == 0) << 1;
1071 p2 = (sd->params.qx3.toplight == 0) << 3;
1072
1073 ret = do_command(gspca_dev, CPIA_COMMAND_WriteVCReg,
1074 0x90, 0x8F, 0x50, 0);
1075 if (ret)
1076 return ret;
1077
1078 return do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, 2, 0,
1079 p1 | p2 | 0xE0, 0);
1080}
1081
1082static int set_flicker(struct gspca_dev *gspca_dev, int on, int apply)
1083{
1084 /* Everything in here is from the Windows driver */
1085/* define for compgain calculation */
1086#if 0
1087#define COMPGAIN(base, curexp, newexp) \
1088 (u8) ((((float) base - 128.0) * ((float) curexp / (float) newexp)) + 128.5)
1089#define EXP_FROM_COMP(basecomp, curcomp, curexp) \
1090 (u16)((float)curexp * (float)(u8)(curcomp + 128) / \
1091 (float)(u8)(basecomp - 128))
1092#else
1093 /* equivalent functions without floating point math */
1094#define COMPGAIN(base, curexp, newexp) \
1095 (u8)(128 + (((u32)(2*(base-128)*curexp + newexp)) / (2 * newexp)))
1096#define EXP_FROM_COMP(basecomp, curcomp, curexp) \
1097 (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128)))
1098#endif
1099
1100 struct sd *sd = (struct sd *) gspca_dev;
1101 int currentexp = sd->params.exposure.coarseExpLo +
1102 sd->params.exposure.coarseExpHi * 256;
1103 int ret, startexp;
1104
1105 if (on) {
1106 int cj = sd->params.flickerControl.coarseJump;
1107 sd->params.flickerControl.flickerMode = 1;
1108 sd->params.flickerControl.disabled = 0;
1109 if (sd->params.exposure.expMode != 2) {
1110 sd->params.exposure.expMode = 2;
1111 sd->exposure_status = EXPOSURE_NORMAL;
1112 }
1113 currentexp = currentexp << sd->params.exposure.gain;
1114 sd->params.exposure.gain = 0;
1115 /* round down current exposure to nearest value */
1116 startexp = (currentexp + ROUND_UP_EXP_FOR_FLICKER) / cj;
1117 if (startexp < 1)
1118 startexp = 1;
1119 startexp = (startexp * cj) - 1;
1120 if (FIRMWARE_VERSION(1, 2))
1121 while (startexp > MAX_EXP_102)
1122 startexp -= cj;
1123 else
1124 while (startexp > MAX_EXP)
1125 startexp -= cj;
1126 sd->params.exposure.coarseExpLo = startexp & 0xff;
1127 sd->params.exposure.coarseExpHi = startexp >> 8;
1128 if (currentexp > startexp) {
1129 if (currentexp > (2 * startexp))
1130 currentexp = 2 * startexp;
1131 sd->params.exposure.redComp =
1132 COMPGAIN(COMP_RED, currentexp, startexp);
1133 sd->params.exposure.green1Comp =
1134 COMPGAIN(COMP_GREEN1, currentexp, startexp);
1135 sd->params.exposure.green2Comp =
1136 COMPGAIN(COMP_GREEN2, currentexp, startexp);
1137 sd->params.exposure.blueComp =
1138 COMPGAIN(COMP_BLUE, currentexp, startexp);
1139 } else {
1140 sd->params.exposure.redComp = COMP_RED;
1141 sd->params.exposure.green1Comp = COMP_GREEN1;
1142 sd->params.exposure.green2Comp = COMP_GREEN2;
1143 sd->params.exposure.blueComp = COMP_BLUE;
1144 }
1145 if (FIRMWARE_VERSION(1, 2))
1146 sd->params.exposure.compMode = 0;
1147 else
1148 sd->params.exposure.compMode = 1;
1149
1150 sd->params.apcor.gain1 = 0x18;
1151 sd->params.apcor.gain2 = 0x18;
1152 sd->params.apcor.gain4 = 0x16;
1153 sd->params.apcor.gain8 = 0x14;
1154 } else {
1155 sd->params.flickerControl.flickerMode = 0;
1156 sd->params.flickerControl.disabled = 1;
1157 /* Average equivalent coarse for each comp channel */
1158 startexp = EXP_FROM_COMP(COMP_RED,
1159 sd->params.exposure.redComp, currentexp);
1160 startexp += EXP_FROM_COMP(COMP_GREEN1,
1161 sd->params.exposure.green1Comp, currentexp);
1162 startexp += EXP_FROM_COMP(COMP_GREEN2,
1163 sd->params.exposure.green2Comp, currentexp);
1164 startexp += EXP_FROM_COMP(COMP_BLUE,
1165 sd->params.exposure.blueComp, currentexp);
1166 startexp = startexp >> 2;
1167 while (startexp > MAX_EXP && sd->params.exposure.gain <
1168 sd->params.exposure.gainMode - 1) {
1169 startexp = startexp >> 1;
1170 ++sd->params.exposure.gain;
1171 }
1172 if (FIRMWARE_VERSION(1, 2) && startexp > MAX_EXP_102)
1173 startexp = MAX_EXP_102;
1174 if (startexp > MAX_EXP)
1175 startexp = MAX_EXP;
1176 sd->params.exposure.coarseExpLo = startexp & 0xff;
1177 sd->params.exposure.coarseExpHi = startexp >> 8;
1178 sd->params.exposure.redComp = COMP_RED;
1179 sd->params.exposure.green1Comp = COMP_GREEN1;
1180 sd->params.exposure.green2Comp = COMP_GREEN2;
1181 sd->params.exposure.blueComp = COMP_BLUE;
1182 sd->params.exposure.compMode = 1;
1183 sd->params.apcor.gain1 = 0x18;
1184 sd->params.apcor.gain2 = 0x16;
1185 sd->params.apcor.gain4 = 0x24;
1186 sd->params.apcor.gain8 = 0x34;
1187 }
1188 sd->params.vlOffset.gain1 = 20;
1189 sd->params.vlOffset.gain2 = 24;
1190 sd->params.vlOffset.gain4 = 26;
1191 sd->params.vlOffset.gain8 = 26;
1192
1193 if (apply) {
1194 ret = command_setexposure(gspca_dev);
1195 if (ret)
1196 return ret;
1197
1198 ret = command_setapcor(gspca_dev);
1199 if (ret)
1200 return ret;
1201
1202 ret = command_setvloffset(gspca_dev);
1203 if (ret)
1204 return ret;
1205
1206 ret = command_setflickerctrl(gspca_dev);
1207 if (ret)
1208 return ret;
1209 }
1210
1211 return 0;
1212#undef EXP_FROM_COMP
1213#undef COMPGAIN
1214}
1215
1216/* monitor the exposure and adjust the sensor frame rate if needed */
1217static void monitor_exposure(struct gspca_dev *gspca_dev)
1218{
1219 struct sd *sd = (struct sd *) gspca_dev;
1220 u8 exp_acc, bcomp, gain, coarseL, cmd[8];
1221 int ret, light_exp, dark_exp, very_dark_exp;
1222 int old_exposure, new_exposure, framerate;
1223 int setfps = 0, setexp = 0, setflicker = 0;
1224
1225 /* get necessary stats and register settings from camera */
1226 /* do_command can't handle this, so do it ourselves */
1227 cmd[0] = CPIA_COMMAND_ReadVPRegs >> 8;
1228 cmd[1] = CPIA_COMMAND_ReadVPRegs & 0xff;
1229 cmd[2] = 30;
1230 cmd[3] = 4;
1231 cmd[4] = 9;
1232 cmd[5] = 8;
1233 cmd[6] = 8;
1234 cmd[7] = 0;
1235 ret = cpia_usb_transferCmd(gspca_dev, cmd);
1236 if (ret) {
1237 PDEBUG(D_ERR, "ReadVPRegs(30,4,9,8) - failed: %d", ret);
1238 return;
1239 }
1240 exp_acc = gspca_dev->usb_buf[0];
1241 bcomp = gspca_dev->usb_buf[1];
1242 gain = gspca_dev->usb_buf[2];
1243 coarseL = gspca_dev->usb_buf[3];
1244
1245 light_exp = sd->params.colourParams.brightness +
1246 TC - 50 + EXP_ACC_LIGHT;
1247 if (light_exp > 255)
1248 light_exp = 255;
1249 dark_exp = sd->params.colourParams.brightness +
1250 TC - 50 - EXP_ACC_DARK;
1251 if (dark_exp < 0)
1252 dark_exp = 0;
1253 very_dark_exp = dark_exp / 2;
1254
1255 old_exposure = sd->params.exposure.coarseExpHi * 256 +
1256 sd->params.exposure.coarseExpLo;
1257
1258 if (!sd->params.flickerControl.disabled) {
1259 /* Flicker control on */
1260 int max_comp = FIRMWARE_VERSION(1, 2) ? MAX_COMP :
1261 HIGH_COMP_102;
1262 bcomp += 128; /* decode */
1263 if (bcomp >= max_comp && exp_acc < dark_exp) {
1264 /* dark */
1265 if (exp_acc < very_dark_exp) {
1266 /* very dark */
1267 if (sd->exposure_status == EXPOSURE_VERY_DARK)
1268 ++sd->exposure_count;
1269 else {
1270 sd->exposure_status =
1271 EXPOSURE_VERY_DARK;
1272 sd->exposure_count = 1;
1273 }
1274 } else {
1275 /* just dark */
1276 if (sd->exposure_status == EXPOSURE_DARK)
1277 ++sd->exposure_count;
1278 else {
1279 sd->exposure_status = EXPOSURE_DARK;
1280 sd->exposure_count = 1;
1281 }
1282 }
1283 } else if (old_exposure <= LOW_EXP || exp_acc > light_exp) {
1284 /* light */
1285 if (old_exposure <= VERY_LOW_EXP) {
1286 /* very light */
1287 if (sd->exposure_status == EXPOSURE_VERY_LIGHT)
1288 ++sd->exposure_count;
1289 else {
1290 sd->exposure_status =
1291 EXPOSURE_VERY_LIGHT;
1292 sd->exposure_count = 1;
1293 }
1294 } else {
1295 /* just light */
1296 if (sd->exposure_status == EXPOSURE_LIGHT)
1297 ++sd->exposure_count;
1298 else {
1299 sd->exposure_status = EXPOSURE_LIGHT;
1300 sd->exposure_count = 1;
1301 }
1302 }
1303 } else {
1304 /* not dark or light */
1305 sd->exposure_status = EXPOSURE_NORMAL;
1306 }
1307 } else {
1308 /* Flicker control off */
1309 if (old_exposure >= MAX_EXP && exp_acc < dark_exp) {
1310 /* dark */
1311 if (exp_acc < very_dark_exp) {
1312 /* very dark */
1313 if (sd->exposure_status == EXPOSURE_VERY_DARK)
1314 ++sd->exposure_count;
1315 else {
1316 sd->exposure_status =
1317 EXPOSURE_VERY_DARK;
1318 sd->exposure_count = 1;
1319 }
1320 } else {
1321 /* just dark */
1322 if (sd->exposure_status == EXPOSURE_DARK)
1323 ++sd->exposure_count;
1324 else {
1325 sd->exposure_status = EXPOSURE_DARK;
1326 sd->exposure_count = 1;
1327 }
1328 }
1329 } else if (old_exposure <= LOW_EXP || exp_acc > light_exp) {
1330 /* light */
1331 if (old_exposure <= VERY_LOW_EXP) {
1332 /* very light */
1333 if (sd->exposure_status == EXPOSURE_VERY_LIGHT)
1334 ++sd->exposure_count;
1335 else {
1336 sd->exposure_status =
1337 EXPOSURE_VERY_LIGHT;
1338 sd->exposure_count = 1;
1339 }
1340 } else {
1341 /* just light */
1342 if (sd->exposure_status == EXPOSURE_LIGHT)
1343 ++sd->exposure_count;
1344 else {
1345 sd->exposure_status = EXPOSURE_LIGHT;
1346 sd->exposure_count = 1;
1347 }
1348 }
1349 } else {
1350 /* not dark or light */
1351 sd->exposure_status = EXPOSURE_NORMAL;
1352 }
1353 }
1354
1355 framerate = atomic_read(&sd->fps);
1356 if (framerate > 30 || framerate < 1)
1357 framerate = 1;
1358
1359 if (!sd->params.flickerControl.disabled) {
1360 /* Flicker control on */
1361 if ((sd->exposure_status == EXPOSURE_VERY_DARK ||
1362 sd->exposure_status == EXPOSURE_DARK) &&
1363 sd->exposure_count >= DARK_TIME * framerate &&
1364 sd->params.sensorFps.divisor < 3) {
1365
1366 /* dark for too long */
1367 ++sd->params.sensorFps.divisor;
1368 setfps = 1;
1369
1370 sd->params.flickerControl.coarseJump =
1371 flicker_jumps[sd->mainsFreq]
1372 [sd->params.sensorFps.baserate]
1373 [sd->params.sensorFps.divisor];
1374 setflicker = 1;
1375
1376 new_exposure = sd->params.flickerControl.coarseJump-1;
1377 while (new_exposure < old_exposure / 2)
1378 new_exposure +=
1379 sd->params.flickerControl.coarseJump;
1380 sd->params.exposure.coarseExpLo = new_exposure & 0xff;
1381 sd->params.exposure.coarseExpHi = new_exposure >> 8;
1382 setexp = 1;
1383 sd->exposure_status = EXPOSURE_NORMAL;
1384 PDEBUG(D_CONF, "Automatically decreasing sensor_fps");
1385
1386 } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT ||
1387 sd->exposure_status == EXPOSURE_LIGHT) &&
1388 sd->exposure_count >= LIGHT_TIME * framerate &&
1389 sd->params.sensorFps.divisor > 0) {
1390
1391 /* light for too long */
1392 int max_exp = FIRMWARE_VERSION(1, 2) ? MAX_EXP_102 :
1393 MAX_EXP;
1394 --sd->params.sensorFps.divisor;
1395 setfps = 1;
1396
1397 sd->params.flickerControl.coarseJump =
1398 flicker_jumps[sd->mainsFreq]
1399 [sd->params.sensorFps.baserate]
1400 [sd->params.sensorFps.divisor];
1401 setflicker = 1;
1402
1403 new_exposure = sd->params.flickerControl.coarseJump-1;
1404 while (new_exposure < 2 * old_exposure &&
1405 new_exposure +
1406 sd->params.flickerControl.coarseJump < max_exp)
1407 new_exposure +=
1408 sd->params.flickerControl.coarseJump;
1409 sd->params.exposure.coarseExpLo = new_exposure & 0xff;
1410 sd->params.exposure.coarseExpHi = new_exposure >> 8;
1411 setexp = 1;
1412 sd->exposure_status = EXPOSURE_NORMAL;
1413 PDEBUG(D_CONF, "Automatically increasing sensor_fps");
1414 }
1415 } else {
1416 /* Flicker control off */
1417 if ((sd->exposure_status == EXPOSURE_VERY_DARK ||
1418 sd->exposure_status == EXPOSURE_DARK) &&
1419 sd->exposure_count >= DARK_TIME * framerate &&
1420 sd->params.sensorFps.divisor < 3) {
1421
1422 /* dark for too long */
1423 ++sd->params.sensorFps.divisor;
1424 setfps = 1;
1425
1426 if (sd->params.exposure.gain > 0) {
1427 --sd->params.exposure.gain;
1428 setexp = 1;
1429 }
1430 sd->exposure_status = EXPOSURE_NORMAL;
1431 PDEBUG(D_CONF, "Automatically decreasing sensor_fps");
1432
1433 } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT ||
1434 sd->exposure_status == EXPOSURE_LIGHT) &&
1435 sd->exposure_count >= LIGHT_TIME * framerate &&
1436 sd->params.sensorFps.divisor > 0) {
1437
1438 /* light for too long */
1439 --sd->params.sensorFps.divisor;
1440 setfps = 1;
1441
1442 if (sd->params.exposure.gain <
1443 sd->params.exposure.gainMode - 1) {
1444 ++sd->params.exposure.gain;
1445 setexp = 1;
1446 }
1447 sd->exposure_status = EXPOSURE_NORMAL;
1448 PDEBUG(D_CONF, "Automatically increasing sensor_fps");
1449 }
1450 }
1451
1452 if (setexp)
1453 command_setexposure(gspca_dev);
1454
1455 if (setfps)
1456 command_setsensorfps(gspca_dev);
1457
1458 if (setflicker)
1459 command_setflickerctrl(gspca_dev);
1460}
1461
1462/*-----------------------------------------------------------------*/
1463/* if flicker is switched off, this function switches it back on.It checks,
1464 however, that conditions are suitable before restarting it.
1465 This should only be called for firmware version 1.2.
1466
1467 It also adjust the colour balance when an exposure step is detected - as
1468 long as flicker is running
1469*/
1470static void restart_flicker(struct gspca_dev *gspca_dev)
1471{
1472 struct sd *sd = (struct sd *) gspca_dev;
1473 int cam_exposure, old_exp;
1474
1475 if (!FIRMWARE_VERSION(1, 2))
1476 return;
1477
1478 cam_exposure = atomic_read(&sd->cam_exposure);
1479
1480 if (sd->params.flickerControl.flickerMode == 0 ||
1481 cam_exposure == 0)
1482 return;
1483
1484 old_exp = sd->params.exposure.coarseExpLo +
1485 sd->params.exposure.coarseExpHi*256;
1486 /*
1487 see how far away camera exposure is from a valid
1488 flicker exposure value
1489 */
1490 cam_exposure %= sd->params.flickerControl.coarseJump;
1491 if (!sd->params.flickerControl.disabled &&
1492 cam_exposure <= sd->params.flickerControl.coarseJump - 3) {
1493 /* Flicker control auto-disabled */
1494 sd->params.flickerControl.disabled = 1;
1495 }
1496
1497 if (sd->params.flickerControl.disabled &&
1498 old_exp > sd->params.flickerControl.coarseJump +
1499 ROUND_UP_EXP_FOR_FLICKER) {
1500 /* exposure is now high enough to switch
1501 flicker control back on */
1502 set_flicker(gspca_dev, 1, 1);
1503 }
1504}
1505
1506/* this function is called at probe time */
1507static int sd_config(struct gspca_dev *gspca_dev,
1508 const struct usb_device_id *id)
1509{
1510 struct cam *cam;
1511
1512 reset_camera_params(gspca_dev);
1513
1514 PDEBUG(D_PROBE, "cpia CPiA camera detected (vid/pid 0x%04X:0x%04X)",
1515 id->idVendor, id->idProduct);
1516
1517 cam = &gspca_dev->cam;
1518 cam->cam_mode = mode;
1519 cam->nmodes = ARRAY_SIZE(mode);
1520
1521 sd_setfreq(gspca_dev, FREQ_DEF);
1522
1523 return 0;
1524}
1525
1526/* -- start the camera -- */
1527static int sd_start(struct gspca_dev *gspca_dev)
1528{
1529 struct sd *sd = (struct sd *) gspca_dev;
1530 int priv, ret;
1531
1532 /* Start the camera in low power mode */
1533 if (goto_low_power(gspca_dev)) {
1534 if (sd->params.status.systemState != WARM_BOOT_STATE) {
1535 PDEBUG(D_ERR, "unexpected systemstate: %02x",
1536 sd->params.status.systemState);
1537 printstatus(&sd->params);
1538 return -ENODEV;
1539 }
1540
1541 /* FIXME: this is just dirty trial and error */
1542 ret = goto_high_power(gspca_dev);
1543 if (ret)
1544 return ret;
1545
1546 ret = do_command(gspca_dev, CPIA_COMMAND_DiscardFrame,
1547 0, 0, 0, 0);
1548 if (ret)
1549 return ret;
1550
1551 ret = goto_low_power(gspca_dev);
1552 if (ret)
1553 return ret;
1554 }
1555
1556 /* procedure described in developer's guide p3-28 */
1557
1558 /* Check the firmware version. */
1559 sd->params.version.firmwareVersion = 0;
1560 get_version_information(gspca_dev);
1561 if (sd->params.version.firmwareVersion != 1) {
1562 PDEBUG(D_ERR, "only firmware version 1 is supported (got: %d)",
1563 sd->params.version.firmwareVersion);
1564 return -ENODEV;
1565 }
1566
1567 /* A bug in firmware 1-02 limits gainMode to 2 */
1568 if (sd->params.version.firmwareRevision <= 2 &&
1569 sd->params.exposure.gainMode > 2) {
1570 sd->params.exposure.gainMode = 2;
1571 }
1572
1573 /* set QX3 detected flag */
1574 sd->params.qx3.qx3_detected = (sd->params.pnpID.vendor == 0x0813 &&
1575 sd->params.pnpID.product == 0x0001);
1576
1577 /* The fatal error checking should be done after
1578 * the camera powers up (developer's guide p 3-38) */
1579
1580 /* Set streamState before transition to high power to avoid bug
1581 * in firmware 1-02 */
1582 ret = do_command(gspca_dev, CPIA_COMMAND_ModifyCameraStatus,
1583 STREAMSTATE, 0, STREAM_NOT_READY, 0);
1584 if (ret)
1585 return ret;
1586
1587 /* GotoHiPower */
1588 ret = goto_high_power(gspca_dev);
1589 if (ret)
1590 return ret;
1591
1592 /* Check the camera status */
1593 ret = do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0);
1594 if (ret)
1595 return ret;
1596
1597 if (sd->params.status.fatalError) {
1598 PDEBUG(D_ERR, "fatal_error: %04x, vp_status: %04x",
1599 sd->params.status.fatalError,
1600 sd->params.status.vpStatus);
1601 return -EIO;
1602 }
1603
1604 /* VPVersion can't be retrieved before the camera is in HiPower,
1605 * so get it here instead of in get_version_information. */
1606 ret = do_command(gspca_dev, CPIA_COMMAND_GetVPVersion, 0, 0, 0, 0);
1607 if (ret)
1608 return ret;
1609
1610 /* Determine video mode settings */
1611 sd->params.streamStartLine = 120;
1612
1613 priv = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1614 if (priv & 0x01) { /* crop */
1615 sd->params.roi.colStart = 2;
1616 sd->params.roi.rowStart = 6;
1617 } else {
1618 sd->params.roi.colStart = 0;
1619 sd->params.roi.rowStart = 0;
1620 }
1621
1622 if (priv & 0x02) { /* quarter */
1623 sd->params.format.videoSize = VIDEOSIZE_QCIF;
1624 sd->params.roi.colStart /= 2;
1625 sd->params.roi.rowStart /= 2;
1626 sd->params.streamStartLine /= 2;
1627 } else
1628 sd->params.format.videoSize = VIDEOSIZE_CIF;
1629
1630 sd->params.roi.colEnd = sd->params.roi.colStart +
1631 (gspca_dev->width >> 3);
1632 sd->params.roi.rowEnd = sd->params.roi.rowStart +
1633 (gspca_dev->height >> 2);
1634
1635 /* And now set the camera to a known state */
1636 ret = do_command(gspca_dev, CPIA_COMMAND_SetGrabMode,
1637 CPIA_GRAB_CONTINEOUS, 0, 0, 0);
1638 if (ret)
1639 return ret;
1640 /* We start with compression disabled, as we need one uncompressed
1641 frame to handle later compressed frames */
1642 ret = do_command(gspca_dev, CPIA_COMMAND_SetCompression,
1643 CPIA_COMPRESSION_NONE,
1644 NO_DECIMATION, 0, 0);
1645 if (ret)
1646 return ret;
1647 ret = command_setcompressiontarget(gspca_dev);
1648 if (ret)
1649 return ret;
1650 ret = command_setcolourparams(gspca_dev);
1651 if (ret)
1652 return ret;
1653 ret = command_setformat(gspca_dev);
1654 if (ret)
1655 return ret;
1656 ret = command_setyuvtresh(gspca_dev);
1657 if (ret)
1658 return ret;
1659 ret = command_setecptiming(gspca_dev);
1660 if (ret)
1661 return ret;
1662 ret = command_setcompressionparams(gspca_dev);
1663 if (ret)
1664 return ret;
1665 ret = command_setexposure(gspca_dev);
1666 if (ret)
1667 return ret;
1668 ret = command_setcolourbalance(gspca_dev);
1669 if (ret)
1670 return ret;
1671 ret = command_setsensorfps(gspca_dev);
1672 if (ret)
1673 return ret;
1674 ret = command_setapcor(gspca_dev);
1675 if (ret)
1676 return ret;
1677 ret = command_setflickerctrl(gspca_dev);
1678 if (ret)
1679 return ret;
1680 ret = command_setvloffset(gspca_dev);
1681 if (ret)
1682 return ret;
1683
1684 /* Start stream */
1685 ret = command_resume(gspca_dev);
1686 if (ret)
1687 return ret;
1688
1689 /* Wait 6 frames before turning compression on for the sensor to get
1690 all settings and AEC/ACB to settle */
1691 sd->first_frame = 6;
1692 sd->exposure_status = EXPOSURE_NORMAL;
1693 sd->exposure_count = 0;
1694 atomic_set(&sd->cam_exposure, 0);
1695 atomic_set(&sd->fps, 0);
1696
1697 return 0;
1698}
1699
1700static void sd_stopN(struct gspca_dev *gspca_dev)
1701{
1702 command_pause(gspca_dev);
1703
1704 /* save camera state for later open (developers guide ch 3.5.3) */
1705 save_camera_state(gspca_dev);
1706
1707 /* GotoLoPower */
1708 goto_low_power(gspca_dev);
1709
1710 /* Update the camera status */
1711 do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0);
1712}
1713
1714/* this function is called at probe and resume time */
1715static int sd_init(struct gspca_dev *gspca_dev)
1716{
1717 struct sd *sd = (struct sd *) gspca_dev;
1718 int ret;
1719
1720 /* Start / Stop the camera to make sure we are talking to
1721 a supported camera, and to get some information from it
1722 to print. */
1723 ret = sd_start(gspca_dev);
1724 if (ret)
1725 return ret;
1726
1727 sd_stopN(gspca_dev);
1728
1729 PDEBUG(D_PROBE, "CPIA Version: %d.%02d (%d.%d)",
1730 sd->params.version.firmwareVersion,
1731 sd->params.version.firmwareRevision,
1732 sd->params.version.vcVersion,
1733 sd->params.version.vcRevision);
1734 PDEBUG(D_PROBE, "CPIA PnP-ID: %04x:%04x:%04x",
1735 sd->params.pnpID.vendor, sd->params.pnpID.product,
1736 sd->params.pnpID.deviceRevision);
1737 PDEBUG(D_PROBE, "VP-Version: %d.%d %04x",
1738 sd->params.vpVersion.vpVersion,
1739 sd->params.vpVersion.vpRevision,
1740 sd->params.vpVersion.cameraHeadID);
1741
1742 return 0;
1743}
1744
1745static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1746 u8 *data,
1747 int len)
1748{
1749 struct sd *sd = (struct sd *) gspca_dev;
1750
1751 /* Check for SOF */
1752 if (len >= 64 &&
1753 data[0] == MAGIC_0 && data[1] == MAGIC_1 &&
1754 data[16] == sd->params.format.videoSize &&
1755 data[17] == sd->params.format.subSample &&
1756 data[18] == sd->params.format.yuvOrder &&
1757 data[24] == sd->params.roi.colStart &&
1758 data[25] == sd->params.roi.colEnd &&
1759 data[26] == sd->params.roi.rowStart &&
1760 data[27] == sd->params.roi.rowEnd) {
1761 struct gspca_frame *frame = gspca_get_i_frame(gspca_dev);
1762
1763 atomic_set(&sd->cam_exposure, data[39] * 2);
1764 atomic_set(&sd->fps, data[41]);
1765
1766 if (frame == NULL) {
1767 gspca_dev->last_packet_type = DISCARD_PACKET;
1768 return;
1769 }
1770
1771 /* Check for proper EOF for last frame */
1772 if ((frame->data_end - frame->data) > 4 &&
1773 frame->data_end[-4] == 0xff &&
1774 frame->data_end[-3] == 0xff &&
1775 frame->data_end[-2] == 0xff &&
1776 frame->data_end[-1] == 0xff)
1777 gspca_frame_add(gspca_dev, LAST_PACKET,
1778 NULL, 0);
1779
1780 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
1781 return;
1782 }
1783
1784 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1785}
1786
1787static void sd_dq_callback(struct gspca_dev *gspca_dev)
1788{
1789 struct sd *sd = (struct sd *) gspca_dev;
1790
1791 /* Set the normal compression settings once we have captured a
1792 few uncompressed frames (and AEC has hopefully settled) */
1793 if (sd->first_frame) {
1794 sd->first_frame--;
1795 if (sd->first_frame == 0)
1796 command_setcompression(gspca_dev);
1797 }
1798
1799 /* Switch flicker control back on if it got turned off */
1800 restart_flicker(gspca_dev);
1801
1802 /* If AEC is enabled, monitor the exposure and
1803 adjust the sensor frame rate if needed */
1804 if (sd->params.exposure.expMode == 2)
1805 monitor_exposure(gspca_dev);
1806
1807 /* Update our knowledge of the camera state */
1808 do_command(gspca_dev, CPIA_COMMAND_GetExposure, 0, 0, 0, 0);
1809 if (sd->params.qx3.qx3_detected)
1810 do_command(gspca_dev, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0);
1811}
1812
1813static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1814{
1815 struct sd *sd = (struct sd *) gspca_dev;
1816 int ret;
1817
1818 sd->params.colourParams.brightness = val;
1819 sd->params.flickerControl.allowableOverExposure =
1820 find_over_exposure(sd->params.colourParams.brightness);
1821 if (gspca_dev->streaming) {
1822 ret = command_setcolourparams(gspca_dev);
1823 if (ret)
1824 return ret;
1825 return command_setflickerctrl(gspca_dev);
1826 }
1827 return 0;
1828}
1829
1830static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1831{
1832 struct sd *sd = (struct sd *) gspca_dev;
1833
1834 *val = sd->params.colourParams.brightness;
1835 return 0;
1836}
1837
1838static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1839{
1840 struct sd *sd = (struct sd *) gspca_dev;
1841
1842 sd->params.colourParams.contrast = val;
1843 if (gspca_dev->streaming)
1844 return command_setcolourparams(gspca_dev);
1845
1846 return 0;
1847}
1848
1849static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1850{
1851 struct sd *sd = (struct sd *) gspca_dev;
1852
1853 *val = sd->params.colourParams.contrast;
1854 return 0;
1855}
1856
1857static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val)
1858{
1859 struct sd *sd = (struct sd *) gspca_dev;
1860
1861 sd->params.colourParams.saturation = val;
1862 if (gspca_dev->streaming)
1863 return command_setcolourparams(gspca_dev);
1864
1865 return 0;
1866}
1867
1868static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val)
1869{
1870 struct sd *sd = (struct sd *) gspca_dev;
1871
1872 *val = sd->params.colourParams.saturation;
1873 return 0;
1874}
1875
1876static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
1877{
1878 struct sd *sd = (struct sd *) gspca_dev;
1879 int on;
1880
1881 switch (val) {
1882 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1883 on = 0;
1884 break;
1885 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1886 on = 1;
1887 sd->mainsFreq = 0;
1888 break;
1889 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
1890 on = 1;
1891 sd->mainsFreq = 1;
1892 break;
1893 default:
1894 return -EINVAL;
1895 }
1896
1897 sd->freq = val;
1898 sd->params.flickerControl.coarseJump =
1899 flicker_jumps[sd->mainsFreq]
1900 [sd->params.sensorFps.baserate]
1901 [sd->params.sensorFps.divisor];
1902
1903 return set_flicker(gspca_dev, on, gspca_dev->streaming);
1904}
1905
1906static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
1907{
1908 struct sd *sd = (struct sd *) gspca_dev;
1909
1910 *val = sd->freq;
1911 return 0;
1912}
1913
1914static int sd_setcomptarget(struct gspca_dev *gspca_dev, __s32 val)
1915{
1916 struct sd *sd = (struct sd *) gspca_dev;
1917
1918 sd->params.compressionTarget.frTargeting = val;
1919 if (gspca_dev->streaming)
1920 return command_setcompressiontarget(gspca_dev);
1921
1922 return 0;
1923}
1924
1925static int sd_getcomptarget(struct gspca_dev *gspca_dev, __s32 *val)
1926{
1927 struct sd *sd = (struct sd *) gspca_dev;
1928
1929 *val = sd->params.compressionTarget.frTargeting;
1930 return 0;
1931}
1932
1933static int sd_querymenu(struct gspca_dev *gspca_dev,
1934 struct v4l2_querymenu *menu)
1935{
1936 switch (menu->id) {
1937 case V4L2_CID_POWER_LINE_FREQUENCY:
1938 switch (menu->index) {
1939 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1940 strcpy((char *) menu->name, "NoFliker");
1941 return 0;
1942 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1943 strcpy((char *) menu->name, "50 Hz");
1944 return 0;
1945 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
1946 strcpy((char *) menu->name, "60 Hz");
1947 return 0;
1948 }
1949 break;
1950 case V4L2_CID_COMP_TARGET:
1951 switch (menu->index) {
1952 case CPIA_COMPRESSION_TARGET_QUALITY:
1953 strcpy((char *) menu->name, "Quality");
1954 return 0;
1955 case CPIA_COMPRESSION_TARGET_FRAMERATE:
1956 strcpy((char *) menu->name, "Framerate");
1957 return 0;
1958 }
1959 break;
1960 }
1961 return -EINVAL;
1962}
1963
1964/* sub-driver description */
1965static const struct sd_desc sd_desc = {
1966 .name = MODULE_NAME,
1967 .ctrls = sd_ctrls,
1968 .nctrls = ARRAY_SIZE(sd_ctrls),
1969 .config = sd_config,
1970 .init = sd_init,
1971 .start = sd_start,
1972 .stopN = sd_stopN,
1973 .dq_callback = sd_dq_callback,
1974 .pkt_scan = sd_pkt_scan,
1975 .querymenu = sd_querymenu,
1976};
1977
1978/* -- module initialisation -- */
1979static const __devinitdata struct usb_device_id device_table[] = {
1980 {USB_DEVICE(0x0553, 0x0002)},
1981 {USB_DEVICE(0x0813, 0x0001)},
1982 {}
1983};
1984MODULE_DEVICE_TABLE(usb, device_table);
1985
1986/* -- device connect -- */
1987static int sd_probe(struct usb_interface *intf,
1988 const struct usb_device_id *id)
1989{
1990 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1991 THIS_MODULE);
1992}
1993
1994static struct usb_driver sd_driver = {
1995 .name = MODULE_NAME,
1996 .id_table = device_table,
1997 .probe = sd_probe,
1998 .disconnect = gspca_disconnect,
1999#ifdef CONFIG_PM
2000 .suspend = gspca_suspend,
2001 .resume = gspca_resume,
2002#endif
2003};
2004
2005/* -- module insert / remove -- */
2006static int __init sd_mod_init(void)
2007{
2008 int ret;
2009 ret = usb_register(&sd_driver);
2010 if (ret < 0)
2011 return ret;
2012 PDEBUG(D_PROBE, "registered");
2013 return 0;
2014}
2015static void __exit sd_mod_exit(void)
2016{
2017 usb_deregister(&sd_driver);
2018 PDEBUG(D_PROBE, "deregistered");
2019}
2020
2021module_init(sd_mod_init);
2022module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/etoms.c b/drivers/media/video/gspca/etoms.c
index fdf4c0ec5e7a..ecd4d743d2bc 100644
--- a/drivers/media/video/gspca/etoms.c
+++ b/drivers/media/video/gspca/etoms.c
@@ -52,7 +52,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
52static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); 52static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
53static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); 53static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
54 54
55static struct ctrl sd_ctrls[] = { 55static const struct ctrl sd_ctrls[] = {
56 { 56 {
57 { 57 {
58 .id = V4L2_CID_BRIGHTNESS, 58 .id = V4L2_CID_BRIGHTNESS,
@@ -851,7 +851,7 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
851} 851}
852 852
853/* sub-driver description */ 853/* sub-driver description */
854static struct sd_desc sd_desc = { 854static const struct sd_desc sd_desc = {
855 .name = MODULE_NAME, 855 .name = MODULE_NAME,
856 .ctrls = sd_ctrls, 856 .ctrls = sd_ctrls,
857 .nctrls = ARRAY_SIZE(sd_ctrls), 857 .nctrls = ARRAY_SIZE(sd_ctrls),
diff --git a/drivers/media/video/gspca/gl860/gl860.c b/drivers/media/video/gspca/gl860/gl860.c
index 4878c8f66543..9e42476c0eaf 100644
--- a/drivers/media/video/gspca/gl860/gl860.c
+++ b/drivers/media/video/gspca/gl860/gl860.c
@@ -161,7 +161,7 @@ static int gl860_build_control_table(struct gspca_dev *gspca_dev)
161 161
162/*==================== sud-driver structure initialisation =================*/ 162/*==================== sud-driver structure initialisation =================*/
163 163
164static struct sd_desc sd_desc_mi1320 = { 164static const struct sd_desc sd_desc_mi1320 = {
165 .name = MODULE_NAME, 165 .name = MODULE_NAME,
166 .ctrls = sd_ctrls_mi1320, 166 .ctrls = sd_ctrls_mi1320,
167 .nctrls = GL860_NCTRLS, 167 .nctrls = GL860_NCTRLS,
@@ -174,7 +174,7 @@ static struct sd_desc sd_desc_mi1320 = {
174 .dq_callback = sd_callback, 174 .dq_callback = sd_callback,
175}; 175};
176 176
177static struct sd_desc sd_desc_mi2020 = { 177static const struct sd_desc sd_desc_mi2020 = {
178 .name = MODULE_NAME, 178 .name = MODULE_NAME,
179 .ctrls = sd_ctrls_mi2020, 179 .ctrls = sd_ctrls_mi2020,
180 .nctrls = GL860_NCTRLS, 180 .nctrls = GL860_NCTRLS,
@@ -187,7 +187,7 @@ static struct sd_desc sd_desc_mi2020 = {
187 .dq_callback = sd_callback, 187 .dq_callback = sd_callback,
188}; 188};
189 189
190static struct sd_desc sd_desc_mi2020b = { 190static const struct sd_desc sd_desc_mi2020b = {
191 .name = MODULE_NAME, 191 .name = MODULE_NAME,
192 .ctrls = sd_ctrls_mi2020b, 192 .ctrls = sd_ctrls_mi2020b,
193 .nctrls = GL860_NCTRLS, 193 .nctrls = GL860_NCTRLS,
@@ -200,7 +200,7 @@ static struct sd_desc sd_desc_mi2020b = {
200 .dq_callback = sd_callback, 200 .dq_callback = sd_callback,
201}; 201};
202 202
203static struct sd_desc sd_desc_ov2640 = { 203static const struct sd_desc sd_desc_ov2640 = {
204 .name = MODULE_NAME, 204 .name = MODULE_NAME,
205 .ctrls = sd_ctrls_ov2640, 205 .ctrls = sd_ctrls_ov2640,
206 .nctrls = GL860_NCTRLS, 206 .nctrls = GL860_NCTRLS,
@@ -213,7 +213,7 @@ static struct sd_desc sd_desc_ov2640 = {
213 .dq_callback = sd_callback, 213 .dq_callback = sd_callback,
214}; 214};
215 215
216static struct sd_desc sd_desc_ov9655 = { 216static const struct sd_desc sd_desc_ov9655 = {
217 .name = MODULE_NAME, 217 .name = MODULE_NAME,
218 .ctrls = sd_ctrls_ov9655, 218 .ctrls = sd_ctrls_ov9655,
219 .nctrls = GL860_NCTRLS, 219 .nctrls = GL860_NCTRLS,
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index bd6214d4ab3b..222af479150b 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -3,6 +3,9 @@
3 * 3 *
4 * Copyright (C) 2008-2009 Jean-Francois Moine (http://moinejf.free.fr) 4 * Copyright (C) 2008-2009 Jean-Francois Moine (http://moinejf.free.fr)
5 * 5 *
6 * Camera button input handling by Márton Németh
7 * Copyright (C) 2009-2010 Márton Németh <nm127@freemail.hu>
8 *
6 * This program is free software; you can redistribute it and/or modify it 9 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the 10 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your 11 * Free Software Foundation; either version 2 of the License, or (at your
@@ -37,6 +40,11 @@
37 40
38#include "gspca.h" 41#include "gspca.h"
39 42
43#ifdef CONFIG_INPUT
44#include <linux/input.h>
45#include <linux/usb/input.h>
46#endif
47
40/* global values */ 48/* global values */
41#define DEF_NURBS 3 /* default number of URBs */ 49#define DEF_NURBS 3 /* default number of URBs */
42#if DEF_NURBS > MAX_NURBS 50#if DEF_NURBS > MAX_NURBS
@@ -47,7 +55,7 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
47MODULE_DESCRIPTION("GSPCA USB Camera Driver"); 55MODULE_DESCRIPTION("GSPCA USB Camera Driver");
48MODULE_LICENSE("GPL"); 56MODULE_LICENSE("GPL");
49 57
50#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 8, 0) 58#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 9, 0)
51 59
52#ifdef GSPCA_DEBUG 60#ifdef GSPCA_DEBUG
53int gspca_debug = D_ERR | D_PROBE; 61int gspca_debug = D_ERR | D_PROBE;
@@ -104,15 +112,185 @@ static const struct vm_operations_struct gspca_vm_ops = {
104 .close = gspca_vm_close, 112 .close = gspca_vm_close,
105}; 113};
106 114
115/*
116 * Input and interrupt endpoint handling functions
117 */
118#ifdef CONFIG_INPUT
119static void int_irq(struct urb *urb)
120{
121 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
122 int ret;
123
124 ret = urb->status;
125 switch (ret) {
126 case 0:
127 if (gspca_dev->sd_desc->int_pkt_scan(gspca_dev,
128 urb->transfer_buffer, urb->actual_length) < 0) {
129 PDEBUG(D_ERR, "Unknown packet received");
130 }
131 break;
132
133 case -ENOENT:
134 case -ECONNRESET:
135 case -ENODEV:
136 case -ESHUTDOWN:
137 /* Stop is requested either by software or hardware is gone,
138 * keep the ret value non-zero and don't resubmit later.
139 */
140 break;
141
142 default:
143 PDEBUG(D_ERR, "URB error %i, resubmitting", urb->status);
144 urb->status = 0;
145 ret = 0;
146 }
147
148 if (ret == 0) {
149 ret = usb_submit_urb(urb, GFP_ATOMIC);
150 if (ret < 0)
151 PDEBUG(D_ERR, "Resubmit URB failed with error %i", ret);
152 }
153}
154
155static int gspca_input_connect(struct gspca_dev *dev)
156{
157 struct input_dev *input_dev;
158 int err = 0;
159
160 dev->input_dev = NULL;
161 if (dev->sd_desc->int_pkt_scan || dev->sd_desc->other_input) {
162 input_dev = input_allocate_device();
163 if (!input_dev)
164 return -ENOMEM;
165
166 usb_make_path(dev->dev, dev->phys, sizeof(dev->phys));
167 strlcat(dev->phys, "/input0", sizeof(dev->phys));
168
169 input_dev->name = dev->sd_desc->name;
170 input_dev->phys = dev->phys;
171
172 usb_to_input_id(dev->dev, &input_dev->id);
173
174 input_dev->evbit[0] = BIT_MASK(EV_KEY);
175 input_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA);
176 input_dev->dev.parent = &dev->dev->dev;
177
178 err = input_register_device(input_dev);
179 if (err) {
180 PDEBUG(D_ERR, "Input device registration failed "
181 "with error %i", err);
182 input_dev->dev.parent = NULL;
183 input_free_device(input_dev);
184 } else {
185 dev->input_dev = input_dev;
186 }
187 }
188
189 return err;
190}
191
192static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
193 struct usb_endpoint_descriptor *ep)
194{
195 unsigned int buffer_len;
196 int interval;
197 struct urb *urb;
198 struct usb_device *dev;
199 void *buffer = NULL;
200 int ret = -EINVAL;
201
202 buffer_len = ep->wMaxPacketSize;
203 interval = ep->bInterval;
204 PDEBUG(D_PROBE, "found int in endpoint: 0x%x, "
205 "buffer_len=%u, interval=%u",
206 ep->bEndpointAddress, buffer_len, interval);
207
208 dev = gspca_dev->dev;
209
210 urb = usb_alloc_urb(0, GFP_KERNEL);
211 if (!urb) {
212 ret = -ENOMEM;
213 goto error;
214 }
215
216 buffer = usb_buffer_alloc(dev, ep->wMaxPacketSize,
217 GFP_KERNEL, &urb->transfer_dma);
218 if (!buffer) {
219 ret = -ENOMEM;
220 goto error_buffer;
221 }
222 usb_fill_int_urb(urb, dev,
223 usb_rcvintpipe(dev, ep->bEndpointAddress),
224 buffer, buffer_len,
225 int_irq, (void *)gspca_dev, interval);
226 gspca_dev->int_urb = urb;
227 ret = usb_submit_urb(urb, GFP_KERNEL);
228 if (ret < 0) {
229 PDEBUG(D_ERR, "submit URB failed with error %i", ret);
230 goto error_submit;
231 }
232 return ret;
233
234error_submit:
235 usb_buffer_free(dev,
236 urb->transfer_buffer_length,
237 urb->transfer_buffer,
238 urb->transfer_dma);
239error_buffer:
240 usb_free_urb(urb);
241error:
242 return ret;
243}
244
245static void gspca_input_create_urb(struct gspca_dev *gspca_dev)
246{
247 struct usb_interface *intf;
248 struct usb_host_interface *intf_desc;
249 struct usb_endpoint_descriptor *ep;
250 int i;
251
252 if (gspca_dev->sd_desc->int_pkt_scan) {
253 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
254 intf_desc = intf->cur_altsetting;
255 for (i = 0; i < intf_desc->desc.bNumEndpoints; i++) {
256 ep = &intf_desc->endpoint[i].desc;
257 if (usb_endpoint_dir_in(ep) &&
258 usb_endpoint_xfer_int(ep)) {
259
260 alloc_and_submit_int_urb(gspca_dev, ep);
261 break;
262 }
263 }
264 }
265}
266
267static void gspca_input_destroy_urb(struct gspca_dev *gspca_dev)
268{
269 struct urb *urb;
270
271 urb = gspca_dev->int_urb;
272 if (urb) {
273 gspca_dev->int_urb = NULL;
274 usb_kill_urb(urb);
275 usb_buffer_free(gspca_dev->dev,
276 urb->transfer_buffer_length,
277 urb->transfer_buffer,
278 urb->transfer_dma);
279 usb_free_urb(urb);
280 }
281}
282#else
283#define gspca_input_connect(gspca_dev) 0
284#define gspca_input_create_urb(gspca_dev)
285#define gspca_input_destroy_urb(gspca_dev)
286#endif
287
107/* get the current input frame buffer */ 288/* get the current input frame buffer */
108struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev) 289struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev)
109{ 290{
110 struct gspca_frame *frame; 291 struct gspca_frame *frame;
111 int i;
112 292
113 i = gspca_dev->fr_i; 293 frame = gspca_dev->cur_frame;
114 i = gspca_dev->fr_queue[i];
115 frame = &gspca_dev->frame[i];
116 if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS) 294 if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS)
117 != V4L2_BUF_FLAG_QUEUED) 295 != V4L2_BUF_FLAG_QUEUED)
118 return NULL; 296 return NULL;
@@ -486,11 +664,13 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
486 i, ep->desc.bEndpointAddress); 664 i, ep->desc.bEndpointAddress);
487 gspca_dev->alt = i; /* memorize the current alt setting */ 665 gspca_dev->alt = i; /* memorize the current alt setting */
488 if (gspca_dev->nbalt > 1) { 666 if (gspca_dev->nbalt > 1) {
667 gspca_input_destroy_urb(gspca_dev);
489 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i); 668 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i);
490 if (ret < 0) { 669 if (ret < 0) {
491 err("set alt %d err %d", i, ret); 670 err("set alt %d err %d", i, ret);
492 return NULL; 671 ep = NULL;
493 } 672 }
673 gspca_input_create_urb(gspca_dev);
494 } 674 }
495 return ep; 675 return ep;
496} 676}
@@ -534,26 +714,22 @@ static int create_urbs(struct gspca_dev *gspca_dev,
534 nurbs = 1; 714 nurbs = 1;
535 } 715 }
536 716
537 gspca_dev->nurbs = nurbs;
538 for (n = 0; n < nurbs; n++) { 717 for (n = 0; n < nurbs; n++) {
539 urb = usb_alloc_urb(npkt, GFP_KERNEL); 718 urb = usb_alloc_urb(npkt, GFP_KERNEL);
540 if (!urb) { 719 if (!urb) {
541 err("usb_alloc_urb failed"); 720 err("usb_alloc_urb failed");
542 destroy_urbs(gspca_dev);
543 return -ENOMEM; 721 return -ENOMEM;
544 } 722 }
723 gspca_dev->urb[n] = urb;
545 urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev, 724 urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev,
546 bsize, 725 bsize,
547 GFP_KERNEL, 726 GFP_KERNEL,
548 &urb->transfer_dma); 727 &urb->transfer_dma);
549 728
550 if (urb->transfer_buffer == NULL) { 729 if (urb->transfer_buffer == NULL) {
551 usb_free_urb(urb); 730 err("usb_buffer_alloc failed");
552 err("usb_buffer_urb failed");
553 destroy_urbs(gspca_dev);
554 return -ENOMEM; 731 return -ENOMEM;
555 } 732 }
556 gspca_dev->urb[n] = urb;
557 urb->dev = gspca_dev->dev; 733 urb->dev = gspca_dev->dev;
558 urb->context = gspca_dev; 734 urb->context = gspca_dev;
559 urb->transfer_buffer_length = bsize; 735 urb->transfer_buffer_length = bsize;
@@ -585,6 +761,7 @@ static int create_urbs(struct gspca_dev *gspca_dev,
585static int gspca_init_transfer(struct gspca_dev *gspca_dev) 761static int gspca_init_transfer(struct gspca_dev *gspca_dev)
586{ 762{
587 struct usb_host_endpoint *ep; 763 struct usb_host_endpoint *ep;
764 struct urb *urb;
588 int n, ret; 765 int n, ret;
589 766
590 if (mutex_lock_interruptible(&gspca_dev->usb_lock)) 767 if (mutex_lock_interruptible(&gspca_dev->usb_lock))
@@ -595,6 +772,8 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
595 goto out; 772 goto out;
596 } 773 }
597 774
775 gspca_dev->usb_err = 0;
776
598 /* set the higher alternate setting and 777 /* set the higher alternate setting and
599 * loop until urb submit succeeds */ 778 * loop until urb submit succeeds */
600 if (gspca_dev->cam.reverse_alts) 779 if (gspca_dev->cam.reverse_alts)
@@ -613,10 +792,15 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
613 goto out; 792 goto out;
614 } 793 }
615 for (;;) { 794 for (;;) {
616 PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt); 795 if (!gspca_dev->cam.no_urb_create) {
617 ret = create_urbs(gspca_dev, ep); 796 PDEBUG(D_STREAM, "init transfer alt %d",
618 if (ret < 0) 797 gspca_dev->alt);
619 goto out; 798 ret = create_urbs(gspca_dev, ep);
799 if (ret < 0) {
800 destroy_urbs(gspca_dev);
801 goto out;
802 }
803 }
620 804
621 /* clear the bulk endpoint */ 805 /* clear the bulk endpoint */
622 if (gspca_dev->cam.bulk) 806 if (gspca_dev->cam.bulk)
@@ -636,8 +820,11 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
636 break; 820 break;
637 821
638 /* submit the URBs */ 822 /* submit the URBs */
639 for (n = 0; n < gspca_dev->nurbs; n++) { 823 for (n = 0; n < MAX_NURBS; n++) {
640 ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL); 824 urb = gspca_dev->urb[n];
825 if (urb == NULL)
826 break;
827 ret = usb_submit_urb(urb, GFP_KERNEL);
641 if (ret < 0) 828 if (ret < 0)
642 break; 829 break;
643 } 830 }
@@ -694,7 +881,9 @@ static void gspca_stream_off(struct gspca_dev *gspca_dev)
694 if (gspca_dev->sd_desc->stopN) 881 if (gspca_dev->sd_desc->stopN)
695 gspca_dev->sd_desc->stopN(gspca_dev); 882 gspca_dev->sd_desc->stopN(gspca_dev);
696 destroy_urbs(gspca_dev); 883 destroy_urbs(gspca_dev);
884 gspca_input_destroy_urb(gspca_dev);
697 gspca_set_alt0(gspca_dev); 885 gspca_set_alt0(gspca_dev);
886 gspca_input_create_urb(gspca_dev);
698 } 887 }
699 888
700 /* always call stop0 to free the subdriver's resources */ 889 /* always call stop0 to free the subdriver's resources */
@@ -2060,11 +2249,12 @@ int gspca_dev_probe(struct usb_interface *intf,
2060 PDEBUG(D_ERR, "Too many config"); 2249 PDEBUG(D_ERR, "Too many config");
2061 return -ENODEV; 2250 return -ENODEV;
2062 } 2251 }
2252
2253 /* the USB video interface must be the first one */
2063 interface = &intf->cur_altsetting->desc; 2254 interface = &intf->cur_altsetting->desc;
2064 if (interface->bInterfaceNumber > 0) { 2255 if (dev->config->desc.bNumInterfaces != 1 &&
2065 PDEBUG(D_ERR, "intf != 0"); 2256 interface->bInterfaceNumber != 0)
2066 return -ENODEV; 2257 return -ENODEV;
2067 }
2068 2258
2069 /* create the device */ 2259 /* create the device */
2070 if (dev_size < sizeof *gspca_dev) 2260 if (dev_size < sizeof *gspca_dev)
@@ -2096,6 +2286,10 @@ int gspca_dev_probe(struct usb_interface *intf,
2096 goto out; 2286 goto out;
2097 gspca_set_default_mode(gspca_dev); 2287 gspca_set_default_mode(gspca_dev);
2098 2288
2289 ret = gspca_input_connect(gspca_dev);
2290 if (ret)
2291 goto out;
2292
2099 mutex_init(&gspca_dev->usb_lock); 2293 mutex_init(&gspca_dev->usb_lock);
2100 mutex_init(&gspca_dev->read_lock); 2294 mutex_init(&gspca_dev->read_lock);
2101 mutex_init(&gspca_dev->queue_lock); 2295 mutex_init(&gspca_dev->queue_lock);
@@ -2116,8 +2310,15 @@ int gspca_dev_probe(struct usb_interface *intf,
2116 2310
2117 usb_set_intfdata(intf, gspca_dev); 2311 usb_set_intfdata(intf, gspca_dev);
2118 PDEBUG(D_PROBE, "%s created", video_device_node_name(&gspca_dev->vdev)); 2312 PDEBUG(D_PROBE, "%s created", video_device_node_name(&gspca_dev->vdev));
2313
2314 gspca_input_create_urb(gspca_dev);
2315
2119 return 0; 2316 return 0;
2120out: 2317out:
2318#ifdef CONFIG_INPUT
2319 if (gspca_dev->input_dev)
2320 input_unregister_device(gspca_dev->input_dev);
2321#endif
2121 kfree(gspca_dev->usb_buf); 2322 kfree(gspca_dev->usb_buf);
2122 kfree(gspca_dev); 2323 kfree(gspca_dev);
2123 return ret; 2324 return ret;
@@ -2133,6 +2334,9 @@ EXPORT_SYMBOL(gspca_dev_probe);
2133void gspca_disconnect(struct usb_interface *intf) 2334void gspca_disconnect(struct usb_interface *intf)
2134{ 2335{
2135 struct gspca_dev *gspca_dev = usb_get_intfdata(intf); 2336 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
2337#ifdef CONFIG_INPUT
2338 struct input_dev *input_dev;
2339#endif
2136 2340
2137 PDEBUG(D_PROBE, "%s disconnect", 2341 PDEBUG(D_PROBE, "%s disconnect",
2138 video_device_node_name(&gspca_dev->vdev)); 2342 video_device_node_name(&gspca_dev->vdev));
@@ -2144,6 +2348,15 @@ void gspca_disconnect(struct usb_interface *intf)
2144 wake_up_interruptible(&gspca_dev->wq); 2348 wake_up_interruptible(&gspca_dev->wq);
2145 } 2349 }
2146 2350
2351#ifdef CONFIG_INPUT
2352 gspca_input_destroy_urb(gspca_dev);
2353 input_dev = gspca_dev->input_dev;
2354 if (input_dev) {
2355 gspca_dev->input_dev = NULL;
2356 input_unregister_device(input_dev);
2357 }
2358#endif
2359
2147 /* the device is freed at exit of this function */ 2360 /* the device is freed at exit of this function */
2148 gspca_dev->dev = NULL; 2361 gspca_dev->dev = NULL;
2149 mutex_unlock(&gspca_dev->usb_lock); 2362 mutex_unlock(&gspca_dev->usb_lock);
@@ -2169,6 +2382,7 @@ int gspca_suspend(struct usb_interface *intf, pm_message_t message)
2169 if (gspca_dev->sd_desc->stopN) 2382 if (gspca_dev->sd_desc->stopN)
2170 gspca_dev->sd_desc->stopN(gspca_dev); 2383 gspca_dev->sd_desc->stopN(gspca_dev);
2171 destroy_urbs(gspca_dev); 2384 destroy_urbs(gspca_dev);
2385 gspca_input_destroy_urb(gspca_dev);
2172 gspca_set_alt0(gspca_dev); 2386 gspca_set_alt0(gspca_dev);
2173 if (gspca_dev->sd_desc->stop0) 2387 if (gspca_dev->sd_desc->stop0)
2174 gspca_dev->sd_desc->stop0(gspca_dev); 2388 gspca_dev->sd_desc->stop0(gspca_dev);
@@ -2182,6 +2396,7 @@ int gspca_resume(struct usb_interface *intf)
2182 2396
2183 gspca_dev->frozen = 0; 2397 gspca_dev->frozen = 0;
2184 gspca_dev->sd_desc->init(gspca_dev); 2398 gspca_dev->sd_desc->init(gspca_dev);
2399 gspca_input_create_urb(gspca_dev);
2185 if (gspca_dev->streaming) 2400 if (gspca_dev->streaming)
2186 return gspca_init_transfer(gspca_dev); 2401 return gspca_init_transfer(gspca_dev);
2187 return 0; 2402 return 0;
@@ -2205,6 +2420,8 @@ int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum,
2205 int retval = 0; 2420 int retval = 0;
2206 2421
2207 for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { 2422 for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) {
2423 if (gspca_dev->ctrl_dis & (1 << i))
2424 continue;
2208 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_GAIN) 2425 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_GAIN)
2209 gain_ctrl = &gspca_dev->sd_desc->ctrls[i]; 2426 gain_ctrl = &gspca_dev->sd_desc->ctrls[i];
2210 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_EXPOSURE) 2427 if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_EXPOSURE)
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index 59c7941da999..02c696a22be0 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -48,26 +48,27 @@ extern int gspca_debug;
48 48
49/* used to list framerates supported by a camera mode (resolution) */ 49/* used to list framerates supported by a camera mode (resolution) */
50struct framerates { 50struct framerates {
51 int *rates; 51 const u8 *rates;
52 int nrates; 52 int nrates;
53}; 53};
54 54
55/* device information - set at probe time */ 55/* device information - set at probe time */
56struct cam { 56struct cam {
57 int bulk_size; /* buffer size when image transfer by bulk */
58 const struct v4l2_pix_format *cam_mode; /* size nmodes */ 57 const struct v4l2_pix_format *cam_mode; /* size nmodes */
59 char nmodes;
60 const struct framerates *mode_framerates; /* must have size nmode, 58 const struct framerates *mode_framerates; /* must have size nmode,
61 * just like cam_mode */ 59 * just like cam_mode */
62 __u8 bulk_nurbs; /* number of URBs in bulk mode 60 u32 bulk_size; /* buffer size when image transfer by bulk */
61 u32 input_flags; /* value for ENUM_INPUT status flags */
62 u8 nmodes; /* size of cam_mode */
63 u8 no_urb_create; /* don't create transfer URBs */
64 u8 bulk_nurbs; /* number of URBs in bulk mode
63 * - cannot be > MAX_NURBS 65 * - cannot be > MAX_NURBS
64 * - when 0 and bulk_size != 0 means 66 * - when 0 and bulk_size != 0 means
65 * 1 URB and submit done by subdriver */ 67 * 1 URB and submit done by subdriver */
66 u8 bulk; /* image transfer by 0:isoc / 1:bulk */ 68 u8 bulk; /* image transfer by 0:isoc / 1:bulk */
67 u8 npkt; /* number of packets in an ISOC message 69 u8 npkt; /* number of packets in an ISOC message
68 * 0 is the default value: 32 packets */ 70 * 0 is the default value: 32 packets */
69 u32 input_flags; /* value for ENUM_INPUT status flags */ 71 u8 reverse_alts; /* Alt settings are in high to low order */
70 char reverse_alts; /* Alt settings are in high to low order */
71}; 72};
72 73
73struct gspca_dev; 74struct gspca_dev;
@@ -90,6 +91,9 @@ typedef int (*cam_qmnu_op) (struct gspca_dev *,
90typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev, 91typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
91 u8 *data, 92 u8 *data,
92 int len); 93 int len);
94typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev,
95 u8 *data,
96 int len);
93 97
94struct ctrl { 98struct ctrl {
95 struct v4l2_queryctrl qctrl; 99 struct v4l2_queryctrl qctrl;
@@ -125,6 +129,12 @@ struct sd_desc {
125 cam_reg_op get_register; 129 cam_reg_op get_register;
126#endif 130#endif
127 cam_ident_op get_chip_ident; 131 cam_ident_op get_chip_ident;
132#ifdef CONFIG_INPUT
133 cam_int_pkt_op int_pkt_scan;
134 /* other_input makes the gspca core create gspca_dev->input even when
135 int_pkt_scan is NULL, for cams with non interrupt driven buttons */
136 u8 other_input;
137#endif
128}; 138};
129 139
130/* packet types when moving from iso buf to frame buf */ 140/* packet types when moving from iso buf to frame buf */
@@ -147,6 +157,10 @@ struct gspca_dev {
147 struct module *module; /* subdriver handling the device */ 157 struct module *module; /* subdriver handling the device */
148 struct usb_device *dev; 158 struct usb_device *dev;
149 struct file *capt_file; /* file doing video capture */ 159 struct file *capt_file; /* file doing video capture */
160#ifdef CONFIG_INPUT
161 struct input_dev *input_dev;
162 char phys[64]; /* physical device path */
163#endif
150 164
151 struct cam cam; /* device information */ 165 struct cam cam; /* device information */
152 const struct sd_desc *sd_desc; /* subdriver description */ 166 const struct sd_desc *sd_desc; /* subdriver description */
@@ -156,6 +170,9 @@ struct gspca_dev {
156#define USB_BUF_SZ 64 170#define USB_BUF_SZ 64
157 __u8 *usb_buf; /* buffer for USB exchanges */ 171 __u8 *usb_buf; /* buffer for USB exchanges */
158 struct urb *urb[MAX_NURBS]; 172 struct urb *urb[MAX_NURBS];
173#ifdef CONFIG_INPUT
174 struct urb *int_urb;
175#endif
159 176
160 __u8 *frbuf; /* buffer for nframes */ 177 __u8 *frbuf; /* buffer for nframes */
161 struct gspca_frame frame[GSPCA_MAX_FRAMES]; 178 struct gspca_frame frame[GSPCA_MAX_FRAMES];
@@ -187,7 +204,6 @@ struct gspca_dev {
187 char users; /* number of opens */ 204 char users; /* number of opens */
188 char present; /* device connected */ 205 char present; /* device connected */
189 char nbufread; /* number of buffers for read() */ 206 char nbufread; /* number of buffers for read() */
190 char nurbs; /* number of allocated URBs */
191 char memory; /* memory type (V4L2_MEMORY_xxx) */ 207 char memory; /* memory type (V4L2_MEMORY_xxx) */
192 __u8 iface; /* USB interface number */ 208 __u8 iface; /* USB interface number */
193 __u8 alt; /* USB alternate setting */ 209 __u8 alt; /* USB alternate setting */
diff --git a/drivers/media/video/gspca/m5602/m5602_mt9m111.c b/drivers/media/video/gspca/m5602/m5602_mt9m111.c
index 8d071dff6944..c0722fa64606 100644
--- a/drivers/media/video/gspca/m5602/m5602_mt9m111.c
+++ b/drivers/media/video/gspca/m5602/m5602_mt9m111.c
@@ -48,7 +48,7 @@ static struct v4l2_pix_format mt9m111_modes[] = {
48 } 48 }
49}; 49};
50 50
51const static struct ctrl mt9m111_ctrls[] = { 51static const struct ctrl mt9m111_ctrls[] = {
52#define VFLIP_IDX 0 52#define VFLIP_IDX 0
53 { 53 {
54 { 54 {
@@ -171,7 +171,7 @@ int mt9m111_probe(struct sd *sd)
171 return -ENODEV; 171 return -ENODEV;
172 } 172 }
173 173
174 info("Probing for a mt9m111 sensor"); 174 PDEBUG(D_PROBE, "Probing for a mt9m111 sensor");
175 175
176 /* Do the preinit */ 176 /* Do the preinit */
177 for (i = 0; i < ARRAY_SIZE(preinit_mt9m111); i++) { 177 for (i = 0; i < ARRAY_SIZE(preinit_mt9m111); i++) {
diff --git a/drivers/media/video/gspca/m5602/m5602_ov7660.c b/drivers/media/video/gspca/m5602/m5602_ov7660.c
index 2a28b74cb3f9..62c1cbf06666 100644
--- a/drivers/media/video/gspca/m5602/m5602_ov7660.c
+++ b/drivers/media/video/gspca/m5602/m5602_ov7660.c
@@ -33,7 +33,7 @@ static int ov7660_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
33static int ov7660_get_vflip(struct gspca_dev *gspca_dev, __s32 *val); 33static int ov7660_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
34static int ov7660_set_vflip(struct gspca_dev *gspca_dev, __s32 val); 34static int ov7660_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
35 35
36const static struct ctrl ov7660_ctrls[] = { 36static const struct ctrl ov7660_ctrls[] = {
37#define GAIN_IDX 1 37#define GAIN_IDX 1
38 { 38 {
39 { 39 {
diff --git a/drivers/media/video/gspca/m5602/m5602_ov7660.h b/drivers/media/video/gspca/m5602/m5602_ov7660.h
index f5588ebe667c..4d9dcf29da2e 100644
--- a/drivers/media/video/gspca/m5602/m5602_ov7660.h
+++ b/drivers/media/video/gspca/m5602/m5602_ov7660.h
@@ -94,7 +94,7 @@ int ov7660_start(struct sd *sd);
94int ov7660_stop(struct sd *sd); 94int ov7660_stop(struct sd *sd);
95void ov7660_disconnect(struct sd *sd); 95void ov7660_disconnect(struct sd *sd);
96 96
97const static struct m5602_sensor ov7660 = { 97static const struct m5602_sensor ov7660 = {
98 .name = "ov7660", 98 .name = "ov7660",
99 .i2c_slave_id = 0x42, 99 .i2c_slave_id = 0x42,
100 .i2c_regW = 1, 100 .i2c_regW = 1,
diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.c b/drivers/media/video/gspca/m5602/m5602_ov9650.c
index 923cdd5f7a6b..069ba0044f8b 100644
--- a/drivers/media/video/gspca/m5602/m5602_ov9650.c
+++ b/drivers/media/video/gspca/m5602/m5602_ov9650.c
@@ -307,7 +307,7 @@ int ov9650_probe(struct sd *sd)
307 return -ENODEV; 307 return -ENODEV;
308 } 308 }
309 309
310 info("Probing for an ov9650 sensor"); 310 PDEBUG(D_PROBE, "Probing for an ov9650 sensor");
311 311
312 /* Run the pre-init before probing the sensor */ 312 /* Run the pre-init before probing the sensor */
313 for (i = 0; i < ARRAY_SIZE(preinit_ov9650) && !err; i++) { 313 for (i = 0; i < ARRAY_SIZE(preinit_ov9650) && !err; i++) {
diff --git a/drivers/media/video/gspca/m5602/m5602_po1030.c b/drivers/media/video/gspca/m5602/m5602_po1030.c
index 8d74d8065b79..925b87d66f40 100644
--- a/drivers/media/video/gspca/m5602/m5602_po1030.c
+++ b/drivers/media/video/gspca/m5602/m5602_po1030.c
@@ -205,7 +205,7 @@ int po1030_probe(struct sd *sd)
205 return -ENODEV; 205 return -ENODEV;
206 } 206 }
207 207
208 info("Probing for a po1030 sensor"); 208 PDEBUG(D_PROBE, "Probing for a po1030 sensor");
209 209
210 /* Run the pre-init to actually probe the unit */ 210 /* Run the pre-init to actually probe the unit */
211 for (i = 0; i < ARRAY_SIZE(preinit_po1030); i++) { 211 for (i = 0; i < ARRAY_SIZE(preinit_po1030); i++) {
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k4aa.c b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
index 1b536f7d30cf..da0a38c78708 100644
--- a/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
+++ b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
@@ -248,7 +248,7 @@ int s5k4aa_probe(struct sd *sd)
248 return -ENODEV; 248 return -ENODEV;
249 } 249 }
250 250
251 info("Probing for a s5k4aa sensor"); 251 PDEBUG(D_PROBE, "Probing for a s5k4aa sensor");
252 252
253 /* Preinit the sensor */ 253 /* Preinit the sensor */
254 for (i = 0; i < ARRAY_SIZE(preinit_s5k4aa) && !err; i++) { 254 for (i = 0; i < ARRAY_SIZE(preinit_s5k4aa) && !err; i++) {
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.c b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
index 6b89f33a4ce0..fbd91545497a 100644
--- a/drivers/media/video/gspca/m5602/m5602_s5k83a.c
+++ b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
@@ -143,7 +143,7 @@ int s5k83a_probe(struct sd *sd)
143 return -ENODEV; 143 return -ENODEV;
144 } 144 }
145 145
146 info("Probing for a s5k83a sensor"); 146 PDEBUG(D_PROBE, "Probing for a s5k83a sensor");
147 147
148 /* Preinit the sensor */ 148 /* Preinit the sensor */
149 for (i = 0; i < ARRAY_SIZE(preinit_s5k83a) && !err; i++) { 149 for (i = 0; i < ARRAY_SIZE(preinit_s5k83a) && !err; i++) {
diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c
index 9cf8d68c71bf..3d9229e22b25 100644
--- a/drivers/media/video/gspca/mars.c
+++ b/drivers/media/video/gspca/mars.c
@@ -54,7 +54,7 @@ static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
54static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); 54static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
55static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); 55static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
56 56
57static struct ctrl sd_ctrls[] = { 57static const struct ctrl sd_ctrls[] = {
58 { 58 {
59 { 59 {
60 .id = V4L2_CID_BRIGHTNESS, 60 .id = V4L2_CID_BRIGHTNESS,
diff --git a/drivers/media/video/gspca/mr97310a.c b/drivers/media/video/gspca/mr97310a.c
index 9154870e07d2..33744e724eaa 100644
--- a/drivers/media/video/gspca/mr97310a.c
+++ b/drivers/media/video/gspca/mr97310a.c
@@ -57,6 +57,14 @@
57#define MR97310A_GAIN_MAX 31 57#define MR97310A_GAIN_MAX 31
58#define MR97310A_GAIN_DEFAULT 25 58#define MR97310A_GAIN_DEFAULT 25
59 59
60#define MR97310A_CONTRAST_MIN 0
61#define MR97310A_CONTRAST_MAX 31
62#define MR97310A_CONTRAST_DEFAULT 23
63
64#define MR97310A_CS_GAIN_MIN 0
65#define MR97310A_CS_GAIN_MAX 0x7ff
66#define MR97310A_CS_GAIN_DEFAULT 0x110
67
60#define MR97310A_MIN_CLOCKDIV_MIN 3 68#define MR97310A_MIN_CLOCKDIV_MIN 3
61#define MR97310A_MIN_CLOCKDIV_MAX 8 69#define MR97310A_MIN_CLOCKDIV_MAX 8
62#define MR97310A_MIN_CLOCKDIV_DEFAULT 3 70#define MR97310A_MIN_CLOCKDIV_DEFAULT 3
@@ -82,7 +90,8 @@ struct sd {
82 90
83 int brightness; 91 int brightness;
84 u16 exposure; 92 u16 exposure;
85 u8 gain; 93 u32 gain;
94 u8 contrast;
86 u8 min_clockdiv; 95 u8 min_clockdiv;
87}; 96};
88 97
@@ -98,6 +107,8 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
98static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 107static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
99static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); 108static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
100static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); 109static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
110static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
111static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
101static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); 112static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
102static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); 113static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
103static int sd_setmin_clockdiv(struct gspca_dev *gspca_dev, __s32 val); 114static int sd_setmin_clockdiv(struct gspca_dev *gspca_dev, __s32 val);
@@ -105,11 +116,13 @@ static int sd_getmin_clockdiv(struct gspca_dev *gspca_dev, __s32 *val);
105static void setbrightness(struct gspca_dev *gspca_dev); 116static void setbrightness(struct gspca_dev *gspca_dev);
106static void setexposure(struct gspca_dev *gspca_dev); 117static void setexposure(struct gspca_dev *gspca_dev);
107static void setgain(struct gspca_dev *gspca_dev); 118static void setgain(struct gspca_dev *gspca_dev);
119static void setcontrast(struct gspca_dev *gspca_dev);
108 120
109/* V4L2 controls supported by the driver */ 121/* V4L2 controls supported by the driver */
110static struct ctrl sd_ctrls[] = { 122static const struct ctrl sd_ctrls[] = {
111/* Separate brightness control description for Argus QuickClix as it has 123/* Separate brightness control description for Argus QuickClix as it has
112 different limits from the other mr97310a cameras */ 124 * different limits from the other mr97310a cameras, and separate gain
125 * control for Sakar CyberPix camera. */
113 { 126 {
114#define NORM_BRIGHTNESS_IDX 0 127#define NORM_BRIGHTNESS_IDX 0
115 { 128 {
@@ -171,7 +184,37 @@ static struct ctrl sd_ctrls[] = {
171 .get = sd_getgain, 184 .get = sd_getgain,
172 }, 185 },
173 { 186 {
174#define MIN_CLOCKDIV_IDX 4 187#define SAKAR_CS_GAIN_IDX 4
188 {
189 .id = V4L2_CID_GAIN,
190 .type = V4L2_CTRL_TYPE_INTEGER,
191 .name = "Gain",
192 .minimum = MR97310A_CS_GAIN_MIN,
193 .maximum = MR97310A_CS_GAIN_MAX,
194 .step = 1,
195 .default_value = MR97310A_CS_GAIN_DEFAULT,
196 .flags = 0,
197 },
198 .set = sd_setgain,
199 .get = sd_getgain,
200 },
201 {
202#define CONTRAST_IDX 5
203 {
204 .id = V4L2_CID_CONTRAST,
205 .type = V4L2_CTRL_TYPE_INTEGER,
206 .name = "Contrast",
207 .minimum = MR97310A_CONTRAST_MIN,
208 .maximum = MR97310A_CONTRAST_MAX,
209 .step = 1,
210 .default_value = MR97310A_CONTRAST_DEFAULT,
211 .flags = 0,
212 },
213 .set = sd_setcontrast,
214 .get = sd_getcontrast,
215 },
216 {
217#define MIN_CLOCKDIV_IDX 6
175 { 218 {
176 .id = V4L2_CID_PRIVATE_BASE, 219 .id = V4L2_CID_PRIVATE_BASE,
177 .type = V4L2_CTRL_TYPE_INTEGER, 220 .type = V4L2_CTRL_TYPE_INTEGER,
@@ -327,7 +370,6 @@ static int zero_the_pointer(struct gspca_dev *gspca_dev)
327 if (err_code < 0) 370 if (err_code < 0)
328 return err_code; 371 return err_code;
329 372
330 err_code = mr_write(gspca_dev, 1);
331 data[0] = 0x19; 373 data[0] = 0x19;
332 data[1] = 0x51; 374 data[1] = 0x51;
333 err_code = mr_write(gspca_dev, 2); 375 err_code = mr_write(gspca_dev, 2);
@@ -437,6 +479,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
437{ 479{
438 struct sd *sd = (struct sd *) gspca_dev; 480 struct sd *sd = (struct sd *) gspca_dev;
439 struct cam *cam; 481 struct cam *cam;
482 int gain_default = MR97310A_GAIN_DEFAULT;
440 int err_code; 483 int err_code;
441 484
442 cam = &gspca_dev->cam; 485 cam = &gspca_dev->cam;
@@ -460,12 +503,14 @@ static int sd_config(struct gspca_dev *gspca_dev,
460 if (err_code < 0) 503 if (err_code < 0)
461 return err_code; 504 return err_code;
462 505
506 /* Now, the query for sensor type. */
507 err_code = cam_get_response16(gspca_dev, 0x07, 1);
508 if (err_code < 0)
509 return err_code;
510
463 if (id->idProduct == 0x0110 || id->idProduct == 0x010e) { 511 if (id->idProduct == 0x0110 || id->idProduct == 0x010e) {
464 sd->cam_type = CAM_TYPE_CIF; 512 sd->cam_type = CAM_TYPE_CIF;
465 cam->nmodes--; 513 cam->nmodes--;
466 err_code = cam_get_response16(gspca_dev, 0x06, 1);
467 if (err_code < 0)
468 return err_code;
469 /* 514 /*
470 * All but one of the known CIF cameras share the same USB ID, 515 * All but one of the known CIF cameras share the same USB ID,
471 * but two different init routines are in use, and the control 516 * but two different init routines are in use, and the control
@@ -473,12 +518,12 @@ static int sd_config(struct gspca_dev *gspca_dev,
473 * of the two known varieties is connected! 518 * of the two known varieties is connected!
474 * 519 *
475 * A list of known CIF cameras follows. They all report either 520 * A list of known CIF cameras follows. They all report either
476 * 0002 for type 0 or 0003 for type 1. 521 * 0200 for type 0 or 0300 for type 1.
477 * If you have another to report, please do 522 * If you have another to report, please do
478 * 523 *
479 * Name sd->sensor_type reported by 524 * Name sd->sensor_type reported by
480 * 525 *
481 * Sakar Spy-shot 0 T. Kilgore 526 * Sakar 56379 Spy-shot 0 T. Kilgore
482 * Innovage 0 T. Kilgore 527 * Innovage 0 T. Kilgore
483 * Vivitar Mini 0 H. De Goede 528 * Vivitar Mini 0 H. De Goede
484 * Vivitar Mini 0 E. Rodriguez 529 * Vivitar Mini 0 E. Rodriguez
@@ -487,7 +532,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
487 * Philips dig. keych. 1 T. Kilgore 532 * Philips dig. keych. 1 T. Kilgore
488 * Trust Spyc@m 100 1 A. Jacobs 533 * Trust Spyc@m 100 1 A. Jacobs
489 */ 534 */
490 switch (gspca_dev->usb_buf[1]) { 535 switch (gspca_dev->usb_buf[0]) {
491 case 2: 536 case 2:
492 sd->sensor_type = 0; 537 sd->sensor_type = 0;
493 break; 538 break;
@@ -504,20 +549,19 @@ static int sd_config(struct gspca_dev *gspca_dev,
504 } else { 549 } else {
505 sd->cam_type = CAM_TYPE_VGA; 550 sd->cam_type = CAM_TYPE_VGA;
506 551
507 err_code = cam_get_response16(gspca_dev, 0x07, 1);
508 if (err_code < 0)
509 return err_code;
510
511 /* 552 /*
512 * Here is a table of the responses to the previous command 553 * Here is a table of the responses to the query for sensor
513 * from the known MR97310A VGA cameras. 554 * type, from the known MR97310A VGA cameras. Six different
555 * cameras of which five share the same USB ID.
514 * 556 *
515 * Name gspca_dev->usb_buf[] sd->sensor_type 557 * Name gspca_dev->usb_buf[] sd->sensor_type
516 * sd->do_lcd_stop 558 * sd->do_lcd_stop
517 * Aiptek Pencam VGA+ 0300 0 1 559 * Aiptek Pencam VGA+ 0300 0 1
518 * ION digital 0350 0 1 560 * ION digital 0300 0 1
519 * Argus DC-1620 0450 1 0 561 * Argus DC-1620 0450 1 0
520 * Argus QuickClix 0420 1 1 562 * Argus QuickClix 0420 1 1
563 * Sakar 77379 Digital 0350 0 1
564 * Sakar 1638x CyberPix 0120 0 2
521 * 565 *
522 * Based upon these results, we assume default settings 566 * Based upon these results, we assume default settings
523 * and then correct as necessary, as follows. 567 * and then correct as necessary, as follows.
@@ -527,10 +571,12 @@ static int sd_config(struct gspca_dev *gspca_dev,
527 sd->sensor_type = 1; 571 sd->sensor_type = 1;
528 sd->do_lcd_stop = 0; 572 sd->do_lcd_stop = 0;
529 sd->adj_colors = 0; 573 sd->adj_colors = 0;
530 if ((gspca_dev->usb_buf[0] != 0x03) && 574 if (gspca_dev->usb_buf[0] == 0x01) {
575 sd->sensor_type = 2;
576 } else if ((gspca_dev->usb_buf[0] != 0x03) &&
531 (gspca_dev->usb_buf[0] != 0x04)) { 577 (gspca_dev->usb_buf[0] != 0x04)) {
532 PDEBUG(D_ERR, "Unknown VGA Sensor id Byte 0: %02x", 578 PDEBUG(D_ERR, "Unknown VGA Sensor id Byte 0: %02x",
533 gspca_dev->usb_buf[1]); 579 gspca_dev->usb_buf[0]);
534 PDEBUG(D_ERR, "Defaults assumed, may not work"); 580 PDEBUG(D_ERR, "Defaults assumed, may not work");
535 PDEBUG(D_ERR, "Please report this"); 581 PDEBUG(D_ERR, "Please report this");
536 } 582 }
@@ -560,7 +606,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
560 PDEBUG(D_PROBE, "MR97310A VGA camera detected, sensor: %d", 606 PDEBUG(D_PROBE, "MR97310A VGA camera detected, sensor: %d",
561 sd->sensor_type); 607 sd->sensor_type);
562 } 608 }
563 /* Stop streaming as we've started it to probe the sensor type. */ 609 /* Stop streaming as we've started it only to probe the sensor type. */
564 sd_stopN(gspca_dev); 610 sd_stopN(gspca_dev);
565 611
566 if (force_sensor_type != -1) { 612 if (force_sensor_type != -1) {
@@ -574,9 +620,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
574 /* No brightness for sensor_type 0 */ 620 /* No brightness for sensor_type 0 */
575 if (sd->sensor_type == 0) 621 if (sd->sensor_type == 0)
576 gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) | 622 gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) |
577 (1 << ARGUS_QC_BRIGHTNESS_IDX); 623 (1 << ARGUS_QC_BRIGHTNESS_IDX) |
624 (1 << CONTRAST_IDX) |
625 (1 << SAKAR_CS_GAIN_IDX);
578 else 626 else
579 gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX) | 627 gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX) |
628 (1 << CONTRAST_IDX) |
629 (1 << SAKAR_CS_GAIN_IDX) |
580 (1 << MIN_CLOCKDIV_IDX); 630 (1 << MIN_CLOCKDIV_IDX);
581 } else { 631 } else {
582 /* All controls need to be disabled if VGA sensor_type is 0 */ 632 /* All controls need to be disabled if VGA sensor_type is 0 */
@@ -585,17 +635,30 @@ static int sd_config(struct gspca_dev *gspca_dev,
585 (1 << ARGUS_QC_BRIGHTNESS_IDX) | 635 (1 << ARGUS_QC_BRIGHTNESS_IDX) |
586 (1 << EXPOSURE_IDX) | 636 (1 << EXPOSURE_IDX) |
587 (1 << GAIN_IDX) | 637 (1 << GAIN_IDX) |
638 (1 << CONTRAST_IDX) |
639 (1 << SAKAR_CS_GAIN_IDX) |
588 (1 << MIN_CLOCKDIV_IDX); 640 (1 << MIN_CLOCKDIV_IDX);
589 else if (sd->do_lcd_stop) 641 else if (sd->sensor_type == 2) {
642 gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) |
643 (1 << ARGUS_QC_BRIGHTNESS_IDX) |
644 (1 << GAIN_IDX) |
645 (1 << MIN_CLOCKDIV_IDX);
646 gain_default = MR97310A_CS_GAIN_DEFAULT;
647 } else if (sd->do_lcd_stop)
590 /* Argus QuickClix has different brightness limits */ 648 /* Argus QuickClix has different brightness limits */
591 gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX); 649 gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) |
650 (1 << CONTRAST_IDX) |
651 (1 << SAKAR_CS_GAIN_IDX);
592 else 652 else
593 gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX); 653 gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX) |
654 (1 << CONTRAST_IDX) |
655 (1 << SAKAR_CS_GAIN_IDX);
594 } 656 }
595 657
596 sd->brightness = MR97310A_BRIGHTNESS_DEFAULT; 658 sd->brightness = MR97310A_BRIGHTNESS_DEFAULT;
597 sd->exposure = MR97310A_EXPOSURE_DEFAULT; 659 sd->exposure = MR97310A_EXPOSURE_DEFAULT;
598 sd->gain = MR97310A_GAIN_DEFAULT; 660 sd->gain = gain_default;
661 sd->contrast = MR97310A_CONTRAST_DEFAULT;
599 sd->min_clockdiv = MR97310A_MIN_CLOCKDIV_DEFAULT; 662 sd->min_clockdiv = MR97310A_MIN_CLOCKDIV_DEFAULT;
600 663
601 return 0; 664 return 0;
@@ -697,6 +760,12 @@ static int start_cif_cam(struct gspca_dev *gspca_dev)
697 {0x13, 0x00, {0x01}, 1}, 760 {0x13, 0x00, {0x01}, 1},
698 {0, 0, {0}, 0} 761 {0, 0, {0}, 0}
699 }; 762 };
763 /* Without this command the cam won't work with USB-UHCI */
764 gspca_dev->usb_buf[0] = 0x0a;
765 gspca_dev->usb_buf[1] = 0x00;
766 err_code = mr_write(gspca_dev, 2);
767 if (err_code < 0)
768 return err_code;
700 err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data, 769 err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data,
701 ARRAY_SIZE(cif_sensor1_init_data)); 770 ARRAY_SIZE(cif_sensor1_init_data));
702 } 771 }
@@ -717,6 +786,10 @@ static int start_vga_cam(struct gspca_dev *gspca_dev)
717 data[5] = 0x00; 786 data[5] = 0x00;
718 data[10] = 0x91; 787 data[10] = 0x91;
719 } 788 }
789 if (sd->sensor_type == 2) {
790 data[5] = 0x00;
791 data[10] = 0x18;
792 }
720 793
721 switch (gspca_dev->width) { 794 switch (gspca_dev->width) {
722 case 160: 795 case 160:
@@ -731,6 +804,10 @@ static int start_vga_cam(struct gspca_dev *gspca_dev)
731 data[4] = 0x78; /* reg 3, V size/4 */ 804 data[4] = 0x78; /* reg 3, V size/4 */
732 data[6] = 0x04; /* reg 5, H start */ 805 data[6] = 0x04; /* reg 5, H start */
733 data[8] = 0x03; /* reg 7, V start */ 806 data[8] = 0x03; /* reg 7, V start */
807 if (sd->sensor_type == 2) {
808 data[6] = 2;
809 data[8] = 1;
810 }
734 if (sd->do_lcd_stop) 811 if (sd->do_lcd_stop)
735 data[8] = 0x04; /* Bayer tile shifted */ 812 data[8] = 0x04; /* Bayer tile shifted */
736 break; 813 break;
@@ -753,7 +830,6 @@ static int start_vga_cam(struct gspca_dev *gspca_dev)
753 return err_code; 830 return err_code;
754 831
755 if (!sd->sensor_type) { 832 if (!sd->sensor_type) {
756 /* The only known sensor_type 0 cam is the Argus DC-1620 */
757 const struct sensor_w_data vga_sensor0_init_data[] = { 833 const struct sensor_w_data vga_sensor0_init_data[] = {
758 {0x01, 0x00, {0x0c, 0x00, 0x04}, 3}, 834 {0x01, 0x00, {0x0c, 0x00, 0x04}, 3},
759 {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4}, 835 {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4},
@@ -764,7 +840,7 @@ static int start_vga_cam(struct gspca_dev *gspca_dev)
764 }; 840 };
765 err_code = sensor_write_regs(gspca_dev, vga_sensor0_init_data, 841 err_code = sensor_write_regs(gspca_dev, vga_sensor0_init_data,
766 ARRAY_SIZE(vga_sensor0_init_data)); 842 ARRAY_SIZE(vga_sensor0_init_data));
767 } else { /* sd->sensor_type = 1 */ 843 } else if (sd->sensor_type == 1) {
768 const struct sensor_w_data color_adj[] = { 844 const struct sensor_w_data color_adj[] = {
769 {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00, 845 {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00,
770 /* adjusted blue, green, red gain correct 846 /* adjusted blue, green, red gain correct
@@ -802,6 +878,48 @@ static int start_vga_cam(struct gspca_dev *gspca_dev)
802 878
803 err_code = sensor_write_regs(gspca_dev, vga_sensor1_init_data, 879 err_code = sensor_write_regs(gspca_dev, vga_sensor1_init_data,
804 ARRAY_SIZE(vga_sensor1_init_data)); 880 ARRAY_SIZE(vga_sensor1_init_data));
881 } else { /* sensor type == 2 */
882 const struct sensor_w_data vga_sensor2_init_data[] = {
883
884 {0x01, 0x00, {0x48}, 1},
885 {0x02, 0x00, {0x22}, 1},
886 /* Reg 3 msb and 4 is lsb of the exposure setting*/
887 {0x05, 0x00, {0x10}, 1},
888 {0x06, 0x00, {0x00}, 1},
889 {0x07, 0x00, {0x00}, 1},
890 {0x08, 0x00, {0x00}, 1},
891 {0x09, 0x00, {0x00}, 1},
892 /* The following are used in the gain control
893 * which is BTW completely borked in the OEM driver
894 * The values for each color go from 0 to 0x7ff
895 *{0x0a, 0x00, {0x01}, 1}, green1 gain msb
896 *{0x0b, 0x00, {0x10}, 1}, green1 gain lsb
897 *{0x0c, 0x00, {0x01}, 1}, red gain msb
898 *{0x0d, 0x00, {0x10}, 1}, red gain lsb
899 *{0x0e, 0x00, {0x01}, 1}, blue gain msb
900 *{0x0f, 0x00, {0x10}, 1}, blue gain lsb
901 *{0x10, 0x00, {0x01}, 1}, green2 gain msb
902 *{0x11, 0x00, {0x10}, 1}, green2 gain lsb
903 */
904 {0x12, 0x00, {0x00}, 1},
905 {0x13, 0x00, {0x04}, 1}, /* weird effect on colors */
906 {0x14, 0x00, {0x00}, 1},
907 {0x15, 0x00, {0x06}, 1},
908 {0x16, 0x00, {0x01}, 1},
909 {0x17, 0x00, {0xe2}, 1}, /* vertical alignment */
910 {0x18, 0x00, {0x02}, 1},
911 {0x19, 0x00, {0x82}, 1}, /* don't mess with */
912 {0x1a, 0x00, {0x00}, 1},
913 {0x1b, 0x00, {0x20}, 1},
914 /* {0x1c, 0x00, {0x17}, 1}, contrast control */
915 {0x1d, 0x00, {0x80}, 1}, /* moving causes a mess */
916 {0x1e, 0x00, {0x08}, 1}, /* moving jams the camera */
917 {0x1f, 0x00, {0x0c}, 1},
918 {0x20, 0x00, {0x00}, 1},
919 {0, 0, {0}, 0}
920 };
921 err_code = sensor_write_regs(gspca_dev, vga_sensor2_init_data,
922 ARRAY_SIZE(vga_sensor2_init_data));
805 } 923 }
806 return err_code; 924 return err_code;
807} 925}
@@ -834,6 +952,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
834 return err_code; 952 return err_code;
835 953
836 setbrightness(gspca_dev); 954 setbrightness(gspca_dev);
955 setcontrast(gspca_dev);
837 setexposure(gspca_dev); 956 setexposure(gspca_dev);
838 setgain(gspca_dev); 957 setgain(gspca_dev);
839 958
@@ -893,7 +1012,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
893static void setexposure(struct gspca_dev *gspca_dev) 1012static void setexposure(struct gspca_dev *gspca_dev)
894{ 1013{
895 struct sd *sd = (struct sd *) gspca_dev; 1014 struct sd *sd = (struct sd *) gspca_dev;
896 int exposure; 1015 int exposure = MR97310A_EXPOSURE_DEFAULT;
897 u8 buf[2]; 1016 u8 buf[2];
898 1017
899 if (gspca_dev->ctrl_dis & (1 << EXPOSURE_IDX)) 1018 if (gspca_dev->ctrl_dis & (1 << EXPOSURE_IDX))
@@ -905,6 +1024,11 @@ static void setexposure(struct gspca_dev *gspca_dev)
905 exposure = (sd->exposure * 9267) / 10000 + 300; 1024 exposure = (sd->exposure * 9267) / 10000 + 300;
906 sensor_write1(gspca_dev, 3, exposure >> 4); 1025 sensor_write1(gspca_dev, 3, exposure >> 4);
907 sensor_write1(gspca_dev, 4, exposure & 0x0f); 1026 sensor_write1(gspca_dev, 4, exposure & 0x0f);
1027 } else if (sd->sensor_type == 2) {
1028 exposure = sd->exposure;
1029 exposure >>= 3;
1030 sensor_write1(gspca_dev, 3, exposure >> 8);
1031 sensor_write1(gspca_dev, 4, exposure & 0xff);
908 } else { 1032 } else {
909 /* We have both a clock divider and an exposure register. 1033 /* We have both a clock divider and an exposure register.
910 We first calculate the clock divider, as that determines 1034 We first calculate the clock divider, as that determines
@@ -943,17 +1067,34 @@ static void setexposure(struct gspca_dev *gspca_dev)
943static void setgain(struct gspca_dev *gspca_dev) 1067static void setgain(struct gspca_dev *gspca_dev)
944{ 1068{
945 struct sd *sd = (struct sd *) gspca_dev; 1069 struct sd *sd = (struct sd *) gspca_dev;
1070 u8 gainreg;
946 1071
947 if (gspca_dev->ctrl_dis & (1 << GAIN_IDX)) 1072 if ((gspca_dev->ctrl_dis & (1 << GAIN_IDX)) &&
1073 (gspca_dev->ctrl_dis & (1 << SAKAR_CS_GAIN_IDX)))
948 return; 1074 return;
949 1075
950 if (sd->cam_type == CAM_TYPE_CIF && sd->sensor_type == 1) { 1076 if (sd->cam_type == CAM_TYPE_CIF && sd->sensor_type == 1)
951 sensor_write1(gspca_dev, 0x0e, sd->gain); 1077 sensor_write1(gspca_dev, 0x0e, sd->gain);
952 } else { 1078 else if (sd->cam_type == CAM_TYPE_VGA && sd->sensor_type == 2)
1079 for (gainreg = 0x0a; gainreg < 0x11; gainreg += 2) {
1080 sensor_write1(gspca_dev, gainreg, sd->gain >> 8);
1081 sensor_write1(gspca_dev, gainreg + 1, sd->gain & 0xff);
1082 }
1083 else
953 sensor_write1(gspca_dev, 0x10, sd->gain); 1084 sensor_write1(gspca_dev, 0x10, sd->gain);
954 }
955} 1085}
956 1086
1087static void setcontrast(struct gspca_dev *gspca_dev)
1088{
1089 struct sd *sd = (struct sd *) gspca_dev;
1090
1091 if (gspca_dev->ctrl_dis & (1 << CONTRAST_IDX))
1092 return;
1093
1094 sensor_write1(gspca_dev, 0x1c, sd->contrast);
1095}
1096
1097
957static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 1098static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
958{ 1099{
959 struct sd *sd = (struct sd *) gspca_dev; 1100 struct sd *sd = (struct sd *) gspca_dev;
@@ -1008,6 +1149,25 @@ static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1008 return 0; 1149 return 0;
1009} 1150}
1010 1151
1152static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1153{
1154 struct sd *sd = (struct sd *) gspca_dev;
1155
1156 sd->contrast = val;
1157 if (gspca_dev->streaming)
1158 setcontrast(gspca_dev);
1159 return 0;
1160}
1161
1162
1163static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1164{
1165 struct sd *sd = (struct sd *) gspca_dev;
1166
1167 *val = sd->contrast;
1168 return 0;
1169}
1170
1011static int sd_setmin_clockdiv(struct gspca_dev *gspca_dev, __s32 val) 1171static int sd_setmin_clockdiv(struct gspca_dev *gspca_dev, __s32 val)
1012{ 1172{
1013 struct sd *sd = (struct sd *) gspca_dev; 1173 struct sd *sd = (struct sd *) gspca_dev;
diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c
index b4f965731244..bc4ced6c013b 100644
--- a/drivers/media/video/gspca/ov519.c
+++ b/drivers/media/video/gspca/ov519.c
@@ -38,6 +38,7 @@
38 */ 38 */
39#define MODULE_NAME "ov519" 39#define MODULE_NAME "ov519"
40 40
41#include <linux/input.h>
41#include "gspca.h" 42#include "gspca.h"
42 43
43MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); 44MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
@@ -70,6 +71,9 @@ struct sd {
70 char invert_led; 71 char invert_led;
71#define BRIDGE_INVERT_LED 8 72#define BRIDGE_INVERT_LED 8
72 73
74 char snapshot_pressed;
75 char snapshot_needs_reset;
76
73 /* Determined by sensor type */ 77 /* Determined by sensor type */
74 __u8 sif; 78 __u8 sif;
75 79
@@ -99,10 +103,12 @@ struct sd {
99#define SEN_OV66308AF 5 103#define SEN_OV66308AF 5
100#define SEN_OV7610 6 104#define SEN_OV7610 6
101#define SEN_OV7620 7 105#define SEN_OV7620 7
102#define SEN_OV7640 8 106#define SEN_OV7620AE 8
103#define SEN_OV7670 9 107#define SEN_OV7640 9
104#define SEN_OV76BE 10 108#define SEN_OV7648 10
105#define SEN_OV8610 11 109#define SEN_OV7670 11
110#define SEN_OV76BE 12
111#define SEN_OV8610 13
106 112
107 u8 sensor_addr; 113 u8 sensor_addr;
108 int sensor_width; 114 int sensor_width;
@@ -139,6 +145,7 @@ static void setautobrightness(struct sd *sd);
139static void setfreq(struct sd *sd); 145static void setfreq(struct sd *sd);
140 146
141static const struct ctrl sd_ctrls[] = { 147static const struct ctrl sd_ctrls[] = {
148#define BRIGHTNESS_IDX 0
142 { 149 {
143 { 150 {
144 .id = V4L2_CID_BRIGHTNESS, 151 .id = V4L2_CID_BRIGHTNESS,
@@ -153,6 +160,7 @@ static const struct ctrl sd_ctrls[] = {
153 .set = sd_setbrightness, 160 .set = sd_setbrightness,
154 .get = sd_getbrightness, 161 .get = sd_getbrightness,
155 }, 162 },
163#define CONTRAST_IDX 1
156 { 164 {
157 { 165 {
158 .id = V4L2_CID_CONTRAST, 166 .id = V4L2_CID_CONTRAST,
@@ -167,6 +175,7 @@ static const struct ctrl sd_ctrls[] = {
167 .set = sd_setcontrast, 175 .set = sd_setcontrast,
168 .get = sd_getcontrast, 176 .get = sd_getcontrast,
169 }, 177 },
178#define COLOR_IDX 2
170 { 179 {
171 { 180 {
172 .id = V4L2_CID_SATURATION, 181 .id = V4L2_CID_SATURATION,
@@ -2554,7 +2563,7 @@ static int ov7xx0_configure(struct sd *sd)
2554 /* I don't know what's different about the 76BE yet. */ 2563 /* I don't know what's different about the 76BE yet. */
2555 if (i2c_r(sd, 0x15) & 1) { 2564 if (i2c_r(sd, 0x15) & 1) {
2556 PDEBUG(D_PROBE, "Sensor is an OV7620AE"); 2565 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
2557 sd->sensor = SEN_OV7620; 2566 sd->sensor = SEN_OV7620AE;
2558 } else { 2567 } else {
2559 PDEBUG(D_PROBE, "Sensor is an OV76BE"); 2568 PDEBUG(D_PROBE, "Sensor is an OV76BE");
2560 sd->sensor = SEN_OV76BE; 2569 sd->sensor = SEN_OV76BE;
@@ -2588,7 +2597,7 @@ static int ov7xx0_configure(struct sd *sd)
2588 break; 2597 break;
2589 case 0x48: 2598 case 0x48:
2590 PDEBUG(D_PROBE, "Sensor is an OV7648"); 2599 PDEBUG(D_PROBE, "Sensor is an OV7648");
2591 sd->sensor = SEN_OV7640; /* FIXME */ 2600 sd->sensor = SEN_OV7648;
2592 break; 2601 break;
2593 default: 2602 default:
2594 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low); 2603 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
@@ -2680,6 +2689,36 @@ static void ov51x_led_control(struct sd *sd, int on)
2680 } 2689 }
2681} 2690}
2682 2691
2692static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
2693{
2694 struct sd *sd = (struct sd *) gspca_dev;
2695
2696 if (!sd->snapshot_needs_reset)
2697 return;
2698
2699 /* Note it is important that we clear sd->snapshot_needs_reset,
2700 before actually clearing the snapshot state in the bridge
2701 otherwise we might race with the pkt_scan interrupt handler */
2702 sd->snapshot_needs_reset = 0;
2703
2704 switch (sd->bridge) {
2705 case BRIDGE_OV511:
2706 case BRIDGE_OV511PLUS:
2707 reg_w(sd, R51x_SYS_SNAP, 0x02);
2708 reg_w(sd, R51x_SYS_SNAP, 0x00);
2709 break;
2710 case BRIDGE_OV518:
2711 case BRIDGE_OV518PLUS:
2712 reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */
2713 reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */
2714 break;
2715 case BRIDGE_OV519:
2716 reg_w(sd, R51x_SYS_RESET, 0x40);
2717 reg_w(sd, R51x_SYS_RESET, 0x00);
2718 break;
2719 }
2720}
2721
2683static int ov51x_upload_quan_tables(struct sd *sd) 2722static int ov51x_upload_quan_tables(struct sd *sd)
2684{ 2723{
2685 const unsigned char yQuanTable511[] = { 2724 const unsigned char yQuanTable511[] = {
@@ -3115,7 +3154,11 @@ static int sd_config(struct gspca_dev *gspca_dev,
3115 (1 << OV7670_FREQ_IDX); 3154 (1 << OV7670_FREQ_IDX);
3116 } 3155 }
3117 sd->quality = QUALITY_DEF; 3156 sd->quality = QUALITY_DEF;
3118 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670) 3157 if (sd->sensor == SEN_OV7640 ||
3158 sd->sensor == SEN_OV7648)
3159 gspca_dev->ctrl_dis |= (1 << AUTOBRIGHT_IDX) |
3160 (1 << CONTRAST_IDX);
3161 if (sd->sensor == SEN_OV7670)
3119 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX; 3162 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX;
3120 /* OV8610 Frequency filter control should work but needs testing */ 3163 /* OV8610 Frequency filter control should work but needs testing */
3121 if (sd->sensor == SEN_OV8610) 3164 if (sd->sensor == SEN_OV8610)
@@ -3169,10 +3212,12 @@ static int sd_init(struct gspca_dev *gspca_dev)
3169 return -EIO; 3212 return -EIO;
3170 break; 3213 break;
3171 case SEN_OV7620: 3214 case SEN_OV7620:
3215 case SEN_OV7620AE:
3172 if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620))) 3216 if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
3173 return -EIO; 3217 return -EIO;
3174 break; 3218 break;
3175 case SEN_OV7640: 3219 case SEN_OV7640:
3220 case SEN_OV7648:
3176 if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640))) 3221 if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
3177 return -EIO; 3222 return -EIO;
3178 break; 3223 break;
@@ -3246,7 +3291,9 @@ static int ov511_mode_init_regs(struct sd *sd)
3246 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed 3291 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
3247 for more sensors we need to do this for them too */ 3292 for more sensors we need to do this for them too */
3248 case SEN_OV7620: 3293 case SEN_OV7620:
3294 case SEN_OV7620AE:
3249 case SEN_OV7640: 3295 case SEN_OV7640:
3296 case SEN_OV7648:
3250 case SEN_OV76BE: 3297 case SEN_OV76BE:
3251 if (sd->gspca_dev.width == 320) 3298 if (sd->gspca_dev.width == 320)
3252 interlaced = 1; 3299 interlaced = 1;
@@ -3377,7 +3424,7 @@ static int ov518_mode_init_regs(struct sd *sd)
3377 3424
3378 if (sd->bridge == BRIDGE_OV518PLUS) { 3425 if (sd->bridge == BRIDGE_OV518PLUS) {
3379 switch (sd->sensor) { 3426 switch (sd->sensor) {
3380 case SEN_OV7620: 3427 case SEN_OV7620AE:
3381 if (sd->gspca_dev.width == 320) { 3428 if (sd->gspca_dev.width == 320) {
3382 reg_w(sd, 0x20, 0x00); 3429 reg_w(sd, 0x20, 0x00);
3383 reg_w(sd, 0x21, 0x19); 3430 reg_w(sd, 0x21, 0x19);
@@ -3386,6 +3433,10 @@ static int ov518_mode_init_regs(struct sd *sd)
3386 reg_w(sd, 0x21, 0x1f); 3433 reg_w(sd, 0x21, 0x1f);
3387 } 3434 }
3388 break; 3435 break;
3436 case SEN_OV7620:
3437 reg_w(sd, 0x20, 0x00);
3438 reg_w(sd, 0x21, 0x19);
3439 break;
3389 default: 3440 default:
3390 reg_w(sd, 0x21, 0x19); 3441 reg_w(sd, 0x21, 0x19);
3391 } 3442 }
@@ -3488,7 +3539,8 @@ static int ov519_mode_init_regs(struct sd *sd)
3488 if (write_regvals(sd, mode_init_519, 3539 if (write_regvals(sd, mode_init_519,
3489 ARRAY_SIZE(mode_init_519))) 3540 ARRAY_SIZE(mode_init_519)))
3490 return -EIO; 3541 return -EIO;
3491 if (sd->sensor == SEN_OV7640) { 3542 if (sd->sensor == SEN_OV7640 ||
3543 sd->sensor == SEN_OV7648) {
3492 /* Select 8-bit input mode */ 3544 /* Select 8-bit input mode */
3493 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10); 3545 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
3494 } 3546 }
@@ -3503,6 +3555,9 @@ static int ov519_mode_init_regs(struct sd *sd)
3503 if (sd->sensor == SEN_OV7670 && 3555 if (sd->sensor == SEN_OV7670 &&
3504 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv) 3556 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3505 reg_w(sd, OV519_R12_X_OFFSETL, 0x04); 3557 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
3558 else if (sd->sensor == SEN_OV7648 &&
3559 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3560 reg_w(sd, OV519_R12_X_OFFSETL, 0x01);
3506 else 3561 else
3507 reg_w(sd, OV519_R12_X_OFFSETL, 0x00); 3562 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
3508 reg_w(sd, OV519_R13_X_OFFSETH, 0x00); 3563 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
@@ -3520,6 +3575,7 @@ static int ov519_mode_init_regs(struct sd *sd)
3520 sd->clockdiv = 0; 3575 sd->clockdiv = 0;
3521 switch (sd->sensor) { 3576 switch (sd->sensor) {
3522 case SEN_OV7640: 3577 case SEN_OV7640:
3578 case SEN_OV7648:
3523 switch (sd->frame_rate) { 3579 switch (sd->frame_rate) {
3524 default: 3580 default:
3525/* case 30: */ 3581/* case 30: */
@@ -3649,6 +3705,7 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3649 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ 3705 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3650 break; 3706 break;
3651 case SEN_OV7620: 3707 case SEN_OV7620:
3708 case SEN_OV7620AE:
3652 case SEN_OV76BE: 3709 case SEN_OV76BE:
3653 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); 3710 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3654 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); 3711 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
@@ -3663,13 +3720,16 @@ static int mode_init_ov_sensor_regs(struct sd *sd)
3663 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e); 3720 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
3664 break; 3721 break;
3665 case SEN_OV7640: 3722 case SEN_OV7640:
3723 case SEN_OV7648:
3666 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); 3724 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3667 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); 3725 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3668/* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */ 3726 /* Setting this undocumented bit in qvga mode removes a very
3669/* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */ 3727 annoying vertical shaking of the image */
3670/* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */ 3728 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3671/* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */ 3729 /* Unknown */
3672/* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */ 3730 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3731 /* Allow higher automatic gain (to allow higher framerates) */
3732 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
3673 i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */ 3733 i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */
3674 break; 3734 break;
3675 case SEN_OV7670: 3735 case SEN_OV7670:
@@ -3795,11 +3855,13 @@ static int set_ov_sensor_window(struct sd *sd)
3795 } 3855 }
3796 break; 3856 break;
3797 case SEN_OV7620: 3857 case SEN_OV7620:
3858 case SEN_OV7620AE:
3798 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */ 3859 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
3799 hwebase = 0x2f; 3860 hwebase = 0x2f;
3800 vwsbase = vwebase = 0x05; 3861 vwsbase = vwebase = 0x05;
3801 break; 3862 break;
3802 case SEN_OV7640: 3863 case SEN_OV7640:
3864 case SEN_OV7648:
3803 hwsbase = 0x1a; 3865 hwsbase = 0x1a;
3804 hwebase = 0x1a; 3866 hwebase = 0x1a;
3805 vwsbase = vwebase = 0x03; 3867 vwsbase = vwebase = 0x03;
@@ -3893,6 +3955,12 @@ static int sd_start(struct gspca_dev *gspca_dev)
3893 setautobrightness(sd); 3955 setautobrightness(sd);
3894 setfreq(sd); 3956 setfreq(sd);
3895 3957
3958 /* Force clear snapshot state in case the snapshot button was
3959 pressed while we weren't streaming */
3960 sd->snapshot_needs_reset = 1;
3961 sd_reset_snapshot(gspca_dev);
3962 sd->snapshot_pressed = 0;
3963
3896 ret = ov51x_restart(sd); 3964 ret = ov51x_restart(sd);
3897 if (ret < 0) 3965 if (ret < 0)
3898 goto out; 3966 goto out;
@@ -3919,6 +3987,34 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
3919 w9968cf_stop0(sd); 3987 w9968cf_stop0(sd);
3920} 3988}
3921 3989
3990static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
3991{
3992 struct sd *sd = (struct sd *) gspca_dev;
3993
3994 if (sd->snapshot_pressed != state) {
3995#ifdef CONFIG_INPUT
3996 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
3997 input_sync(gspca_dev->input_dev);
3998#endif
3999 if (state)
4000 sd->snapshot_needs_reset = 1;
4001
4002 sd->snapshot_pressed = state;
4003 } else {
4004 /* On the ov511 / ov519 we need to reset the button state
4005 multiple times, as resetting does not work as long as the
4006 button stays pressed */
4007 switch (sd->bridge) {
4008 case BRIDGE_OV511:
4009 case BRIDGE_OV511PLUS:
4010 case BRIDGE_OV519:
4011 if (state)
4012 sd->snapshot_needs_reset = 1;
4013 break;
4014 }
4015 }
4016}
4017
3922static void ov511_pkt_scan(struct gspca_dev *gspca_dev, 4018static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
3923 u8 *in, /* isoc packet */ 4019 u8 *in, /* isoc packet */
3924 int len) /* iso packet length */ 4020 int len) /* iso packet length */
@@ -3940,6 +4036,7 @@ static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
3940 */ 4036 */
3941 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) && 4037 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
3942 (in[8] & 0x08)) { 4038 (in[8] & 0x08)) {
4039 ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
3943 if (in[8] & 0x80) { 4040 if (in[8] & 0x80) {
3944 /* Frame end */ 4041 /* Frame end */
3945 if ((in[9] + 1) * 8 != gspca_dev->width || 4042 if ((in[9] + 1) * 8 != gspca_dev->width ||
@@ -3977,6 +4074,7 @@ static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
3977 /* A false positive here is likely, until OVT gives me 4074 /* A false positive here is likely, until OVT gives me
3978 * the definitive SOF/EOF format */ 4075 * the definitive SOF/EOF format */
3979 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) { 4076 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
4077 ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1);
3980 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); 4078 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
3981 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); 4079 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
3982 sd->packet_nr = 0; 4080 sd->packet_nr = 0;
@@ -4024,6 +4122,9 @@ static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
4024 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) { 4122 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
4025 switch (data[3]) { 4123 switch (data[3]) {
4026 case 0x50: /* start of frame */ 4124 case 0x50: /* start of frame */
4125 /* Don't check the button state here, as the state
4126 usually (always ?) changes at EOF and checking it
4127 here leads to unnecessary snapshot state resets. */
4027#define HDRSZ 16 4128#define HDRSZ 16
4028 data += HDRSZ; 4129 data += HDRSZ;
4029 len -= HDRSZ; 4130 len -= HDRSZ;
@@ -4035,6 +4136,7 @@ static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
4035 gspca_dev->last_packet_type = DISCARD_PACKET; 4136 gspca_dev->last_packet_type = DISCARD_PACKET;
4036 return; 4137 return;
4037 case 0x51: /* end of frame */ 4138 case 0x51: /* end of frame */
4139 ov51x_handle_button(gspca_dev, data[11] & 1);
4038 if (data[9] != 0) 4140 if (data[9] != 0)
4039 gspca_dev->last_packet_type = DISCARD_PACKET; 4141 gspca_dev->last_packet_type = DISCARD_PACKET;
4040 gspca_frame_add(gspca_dev, LAST_PACKET, 4142 gspca_frame_add(gspca_dev, LAST_PACKET,
@@ -4103,9 +4205,11 @@ static void setbrightness(struct gspca_dev *gspca_dev)
4103 case SEN_OV6630: 4205 case SEN_OV6630:
4104 case SEN_OV66308AF: 4206 case SEN_OV66308AF:
4105 case SEN_OV7640: 4207 case SEN_OV7640:
4208 case SEN_OV7648:
4106 i2c_w(sd, OV7610_REG_BRT, val); 4209 i2c_w(sd, OV7610_REG_BRT, val);
4107 break; 4210 break;
4108 case SEN_OV7620: 4211 case SEN_OV7620:
4212 case SEN_OV7620AE:
4109 /* 7620 doesn't like manual changes when in auto mode */ 4213 /* 7620 doesn't like manual changes when in auto mode */
4110 if (!sd->autobrightness) 4214 if (!sd->autobrightness)
4111 i2c_w(sd, OV7610_REG_BRT, val); 4215 i2c_w(sd, OV7610_REG_BRT, val);
@@ -4142,7 +4246,8 @@ static void setcontrast(struct gspca_dev *gspca_dev)
4142 i2c_w(sd, 0x64, ctab[val >> 5]); 4246 i2c_w(sd, 0x64, ctab[val >> 5]);
4143 break; 4247 break;
4144 } 4248 }
4145 case SEN_OV7620: { 4249 case SEN_OV7620:
4250 case SEN_OV7620AE: {
4146 static const __u8 ctab[] = { 4251 static const __u8 ctab[] = {
4147 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57, 4252 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
4148 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff 4253 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
@@ -4152,10 +4257,6 @@ static void setcontrast(struct gspca_dev *gspca_dev)
4152 i2c_w(sd, 0x64, ctab[val >> 4]); 4257 i2c_w(sd, 0x64, ctab[val >> 4]);
4153 break; 4258 break;
4154 } 4259 }
4155 case SEN_OV7640:
4156 /* Use gain control instead. */
4157 i2c_w(sd, OV7610_REG_GAIN, val >> 2);
4158 break;
4159 case SEN_OV7670: 4260 case SEN_OV7670:
4160 /* check that this isn't just the same as ov7610 */ 4261 /* check that this isn't just the same as ov7610 */
4161 i2c_w(sd, OV7670_REG_CONTRAS, val >> 1); 4262 i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
@@ -4179,6 +4280,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
4179 i2c_w(sd, OV7610_REG_SAT, val); 4280 i2c_w(sd, OV7610_REG_SAT, val);
4180 break; 4281 break;
4181 case SEN_OV7620: 4282 case SEN_OV7620:
4283 case SEN_OV7620AE:
4182 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */ 4284 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
4183/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e); 4285/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
4184 if (rc < 0) 4286 if (rc < 0)
@@ -4186,6 +4288,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
4186 i2c_w(sd, OV7610_REG_SAT, val); 4288 i2c_w(sd, OV7610_REG_SAT, val);
4187 break; 4289 break;
4188 case SEN_OV7640: 4290 case SEN_OV7640:
4291 case SEN_OV7648:
4189 i2c_w(sd, OV7610_REG_SAT, val & 0xf0); 4292 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
4190 break; 4293 break;
4191 case SEN_OV7670: 4294 case SEN_OV7670:
@@ -4198,7 +4301,8 @@ static void setcolors(struct gspca_dev *gspca_dev)
4198 4301
4199static void setautobrightness(struct sd *sd) 4302static void setautobrightness(struct sd *sd)
4200{ 4303{
4201 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670 || 4304 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7648 ||
4305 sd->sensor == SEN_OV7670 ||
4202 sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610) 4306 sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
4203 return; 4307 return;
4204 4308
@@ -4475,9 +4579,13 @@ static const struct sd_desc sd_desc = {
4475 .stopN = sd_stopN, 4579 .stopN = sd_stopN,
4476 .stop0 = sd_stop0, 4580 .stop0 = sd_stop0,
4477 .pkt_scan = sd_pkt_scan, 4581 .pkt_scan = sd_pkt_scan,
4582 .dq_callback = sd_reset_snapshot,
4478 .querymenu = sd_querymenu, 4583 .querymenu = sd_querymenu,
4479 .get_jcomp = sd_get_jcomp, 4584 .get_jcomp = sd_get_jcomp,
4480 .set_jcomp = sd_set_jcomp, 4585 .set_jcomp = sd_set_jcomp,
4586#ifdef CONFIG_INPUT
4587 .other_input = 1,
4588#endif
4481}; 4589};
4482 4590
4483/* -- module initialisation -- */ 4591/* -- module initialisation -- */
@@ -4494,7 +4602,8 @@ static const __devinitdata struct usb_device_id device_table[] = {
4494 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, 4602 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
4495 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 }, 4603 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
4496 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 }, 4604 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
4497 {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 }, 4605 {USB_DEVICE(0x054c, 0x0155),
4606 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
4498 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 }, 4607 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
4499 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 }, 4608 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
4500 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 }, 4609 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c
index 0a6b8f07a69d..957e05e2d08f 100644
--- a/drivers/media/video/gspca/ov534.c
+++ b/drivers/media/video/gspca/ov534.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * ov534 gspca driver 2 * ov534-ov772x gspca driver
3 * 3 *
4 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it> 4 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
5 * Copyright (C) 2008 Jim Paris <jim@jtan.com> 5 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
@@ -68,12 +68,7 @@ struct sd {
68 s8 sharpness; 68 s8 sharpness;
69 u8 hflip; 69 u8 hflip;
70 u8 vflip; 70 u8 vflip;
71 u8 satur;
72 u8 lightfreq;
73 71
74 u8 sensor;
75#define SENSOR_OV772X 0
76#define SENSOR_OV965X 1
77}; 72};
78 73
79/* V4L2 controls supported by the driver */ 74/* V4L2 controls supported by the driver */
@@ -101,12 +96,8 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
101static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 96static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
102static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); 97static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
103static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); 98static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
104static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val);
105static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val);
106static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
107static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
108 99
109static struct ctrl sd_ctrls_ov772x[] = { 100static const struct ctrl sd_ctrls[] = {
110 { /* 0 */ 101 { /* 0 */
111 { 102 {
112 .id = V4L2_CID_BRIGHTNESS, 103 .id = V4L2_CID_BRIGHTNESS,
@@ -115,8 +106,8 @@ static struct ctrl sd_ctrls_ov772x[] = {
115 .minimum = 0, 106 .minimum = 0,
116 .maximum = 255, 107 .maximum = 255,
117 .step = 1, 108 .step = 1,
118#define BRIGHTNESS_77_DEF 20 109#define BRIGHTNESS_DEF 20
119 .default_value = BRIGHTNESS_77_DEF, 110 .default_value = BRIGHTNESS_DEF,
120 }, 111 },
121 .set = sd_setbrightness, 112 .set = sd_setbrightness,
122 .get = sd_getbrightness, 113 .get = sd_getbrightness,
@@ -129,8 +120,8 @@ static struct ctrl sd_ctrls_ov772x[] = {
129 .minimum = 0, 120 .minimum = 0,
130 .maximum = 255, 121 .maximum = 255,
131 .step = 1, 122 .step = 1,
132#define CONTRAST_77_DEF 37 123#define CONTRAST_DEF 37
133 .default_value = CONTRAST_77_DEF, 124 .default_value = CONTRAST_DEF,
134 }, 125 },
135 .set = sd_setcontrast, 126 .set = sd_setcontrast,
136 .get = sd_getcontrast, 127 .get = sd_getcontrast,
@@ -157,8 +148,8 @@ static struct ctrl sd_ctrls_ov772x[] = {
157 .minimum = 0, 148 .minimum = 0,
158 .maximum = 255, 149 .maximum = 255,
159 .step = 1, 150 .step = 1,
160#define EXPO_77_DEF 120 151#define EXPO_DEF 120
161 .default_value = EXPO_77_DEF, 152 .default_value = EXPO_DEF,
162 }, 153 },
163 .set = sd_setexposure, 154 .set = sd_setexposure,
164 .get = sd_getexposure, 155 .get = sd_getexposure,
@@ -213,13 +204,13 @@ static struct ctrl sd_ctrls_ov772x[] = {
213 .minimum = 0, 204 .minimum = 0,
214 .maximum = 1, 205 .maximum = 1,
215 .step = 1, 206 .step = 1,
216#define AUTOGAIN_77_DEF 0 207#define AUTOGAIN_DEF 0
217 .default_value = AUTOGAIN_77_DEF, 208 .default_value = AUTOGAIN_DEF,
218 }, 209 },
219 .set = sd_setautogain, 210 .set = sd_setautogain,
220 .get = sd_getautogain, 211 .get = sd_getautogain,
221 }, 212 },
222#define AWB_77_IDX 8 213#define AWB_IDX 8
223 { /* 8 */ 214 { /* 8 */
224 { 215 {
225 .id = V4L2_CID_AUTO_WHITE_BALANCE, 216 .id = V4L2_CID_AUTO_WHITE_BALANCE,
@@ -242,8 +233,8 @@ static struct ctrl sd_ctrls_ov772x[] = {
242 .minimum = 0, 233 .minimum = 0,
243 .maximum = 63, 234 .maximum = 63,
244 .step = 1, 235 .step = 1,
245#define SHARPNESS_77_DEF 0 236#define SHARPNESS_DEF 0
246 .default_value = SHARPNESS_77_DEF, 237 .default_value = SHARPNESS_DEF,
247 }, 238 },
248 .set = sd_setsharpness, 239 .set = sd_setsharpness,
249 .get = sd_getsharpness, 240 .get = sd_getsharpness,
@@ -277,107 +268,6 @@ static struct ctrl sd_ctrls_ov772x[] = {
277 .get = sd_getvflip, 268 .get = sd_getvflip,
278 }, 269 },
279}; 270};
280static struct ctrl sd_ctrls_ov965x[] = {
281 { /* 0 */
282 {
283 .id = V4L2_CID_BRIGHTNESS,
284 .type = V4L2_CTRL_TYPE_INTEGER,
285 .name = "Brightness",
286 .minimum = 0,
287 .maximum = 15,
288 .step = 1,
289#define BRIGHTNESS_96_DEF 7
290 .default_value = BRIGHTNESS_96_DEF,
291 },
292 .set = sd_setbrightness,
293 .get = sd_getbrightness,
294 },
295 { /* 1 */
296 {
297 .id = V4L2_CID_CONTRAST,
298 .type = V4L2_CTRL_TYPE_INTEGER,
299 .name = "Contrast",
300 .minimum = 0,
301 .maximum = 15,
302 .step = 1,
303#define CONTRAST_96_DEF 3
304 .default_value = CONTRAST_96_DEF,
305 },
306 .set = sd_setcontrast,
307 .get = sd_getcontrast,
308 },
309 { /* 2 */
310 {
311 .id = V4L2_CID_AUTOGAIN,
312 .type = V4L2_CTRL_TYPE_BOOLEAN,
313 .name = "Autogain",
314 .minimum = 0,
315 .maximum = 1,
316 .step = 1,
317#define AUTOGAIN_96_DEF 1
318 .default_value = AUTOGAIN_96_DEF,
319 },
320 .set = sd_setautogain,
321 .get = sd_getautogain,
322 },
323#define EXPO_96_IDX 3
324 { /* 3 */
325 {
326 .id = V4L2_CID_EXPOSURE,
327 .type = V4L2_CTRL_TYPE_INTEGER,
328 .name = "Exposure",
329 .minimum = 0,
330 .maximum = 3,
331 .step = 1,
332#define EXPO_96_DEF 0
333 .default_value = EXPO_96_DEF,
334 },
335 .set = sd_setexposure,
336 .get = sd_getexposure,
337 },
338 { /* 4 */
339 {
340 .id = V4L2_CID_SHARPNESS,
341 .type = V4L2_CTRL_TYPE_INTEGER,
342 .name = "Sharpness",
343 .minimum = -1, /* -1 = auto */
344 .maximum = 4,
345 .step = 1,
346#define SHARPNESS_96_DEF -1
347 .default_value = SHARPNESS_96_DEF,
348 },
349 .set = sd_setsharpness,
350 .get = sd_getsharpness,
351 },
352 { /* 5 */
353 {
354 .id = V4L2_CID_SATURATION,
355 .type = V4L2_CTRL_TYPE_INTEGER,
356 .name = "Saturation",
357 .minimum = 0,
358 .maximum = 4,
359 .step = 1,
360#define SATUR_DEF 2
361 .default_value = SATUR_DEF,
362 },
363 .set = sd_setsatur,
364 .get = sd_getsatur,
365 },
366 {
367 {
368 .id = V4L2_CID_POWER_LINE_FREQUENCY,
369 .type = V4L2_CTRL_TYPE_MENU,
370 .name = "Light frequency filter",
371 .minimum = 0,
372 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
373 .step = 1,
374#define FREQ_DEF 0
375 .default_value = FREQ_DEF,
376 },
377 .set = sd_setfreq,
378 .get = sd_getfreq,
379 },
380};
381 271
382static const struct v4l2_pix_format ov772x_mode[] = { 272static const struct v4l2_pix_format ov772x_mode[] = {
383 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 273 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
@@ -392,35 +282,21 @@ static const struct v4l2_pix_format ov772x_mode[] = {
392 .priv = 0}, 282 .priv = 0},
393}; 283};
394 284
395static const struct v4l2_pix_format ov965x_mode[] = { 285static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
396 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 286static const u8 vga_rates[] = {60, 50, 40, 30, 15};
397 .bytesperline = 320, 287
398 .sizeimage = 320 * 240 * 3 / 8 + 590, 288static const struct framerates ov772x_framerates[] = {
399 .colorspace = V4L2_COLORSPACE_JPEG, 289 { /* 320x240 */
400 .priv = 4}, 290 .rates = qvga_rates,
401 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 291 .nrates = ARRAY_SIZE(qvga_rates),
402 .bytesperline = 640, 292 },
403 .sizeimage = 640 * 480 * 3 / 8 + 590, 293 { /* 640x480 */
404 .colorspace = V4L2_COLORSPACE_JPEG, 294 .rates = vga_rates,
405 .priv = 3}, 295 .nrates = ARRAY_SIZE(vga_rates),
406 {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 296 },
407 .bytesperline = 800,
408 .sizeimage = 800 * 600 * 3 / 8 + 590,
409 .colorspace = V4L2_COLORSPACE_JPEG,
410 .priv = 2},
411 {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
412 .bytesperline = 1024,
413 .sizeimage = 1024 * 768 * 3 / 8 + 590,
414 .colorspace = V4L2_COLORSPACE_JPEG,
415 .priv = 1},
416 {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
417 .bytesperline = 1280,
418 .sizeimage = 1280 * 1024 * 3 / 8 + 590,
419 .colorspace = V4L2_COLORSPACE_JPEG,
420 .priv = 0},
421}; 297};
422 298
423static const u8 bridge_init_ov772x[][2] = { 299static const u8 bridge_init[][2] = {
424 { 0xc2, 0x0c }, 300 { 0xc2, 0x0c },
425 { 0x88, 0xf8 }, 301 { 0x88, 0xf8 },
426 { 0xc3, 0x69 }, 302 { 0xc3, 0x69 },
@@ -478,7 +354,7 @@ static const u8 bridge_init_ov772x[][2] = {
478 { 0xc1, 0x3c }, 354 { 0xc1, 0x3c },
479 { 0xc2, 0x0c }, 355 { 0xc2, 0x0c },
480}; 356};
481static const u8 sensor_init_ov772x[][2] = { 357static const u8 sensor_init[][2] = {
482 { 0x12, 0x80 }, 358 { 0x12, 0x80 },
483 { 0x11, 0x01 }, 359 { 0x11, 0x01 },
484/*fixme: better have a delay?*/ 360/*fixme: better have a delay?*/
@@ -571,7 +447,7 @@ static const u8 sensor_init_ov772x[][2] = {
571 { 0x8e, 0x00 }, /* De-noise threshold */ 447 { 0x8e, 0x00 }, /* De-noise threshold */
572 { 0x0c, 0xd0 } 448 { 0x0c, 0xd0 }
573}; 449};
574static const u8 bridge_start_ov772x_vga[][2] = { 450static const u8 bridge_start_vga[][2] = {
575 {0x1c, 0x00}, 451 {0x1c, 0x00},
576 {0x1d, 0x40}, 452 {0x1d, 0x40},
577 {0x1d, 0x02}, 453 {0x1d, 0x02},
@@ -582,7 +458,7 @@ static const u8 bridge_start_ov772x_vga[][2] = {
582 {0xc0, 0x50}, 458 {0xc0, 0x50},
583 {0xc1, 0x3c}, 459 {0xc1, 0x3c},
584}; 460};
585static const u8 sensor_start_ov772x_vga[][2] = { 461static const u8 sensor_start_vga[][2] = {
586 {0x12, 0x00}, 462 {0x12, 0x00},
587 {0x17, 0x26}, 463 {0x17, 0x26},
588 {0x18, 0xa0}, 464 {0x18, 0xa0},
@@ -592,7 +468,7 @@ static const u8 sensor_start_ov772x_vga[][2] = {
592 {0x2c, 0xf0}, 468 {0x2c, 0xf0},
593 {0x65, 0x20}, 469 {0x65, 0x20},
594}; 470};
595static const u8 bridge_start_ov772x_qvga[][2] = { 471static const u8 bridge_start_qvga[][2] = {
596 {0x1c, 0x00}, 472 {0x1c, 0x00},
597 {0x1d, 0x40}, 473 {0x1d, 0x40},
598 {0x1d, 0x02}, 474 {0x1d, 0x02},
@@ -603,7 +479,7 @@ static const u8 bridge_start_ov772x_qvga[][2] = {
603 {0xc0, 0x28}, 479 {0xc0, 0x28},
604 {0xc1, 0x1e}, 480 {0xc1, 0x1e},
605}; 481};
606static const u8 sensor_start_ov772x_qvga[][2] = { 482static const u8 sensor_start_qvga[][2] = {
607 {0x12, 0x40}, 483 {0x12, 0x40},
608 {0x17, 0x3f}, 484 {0x17, 0x3f},
609 {0x18, 0x50}, 485 {0x18, 0x50},
@@ -614,571 +490,6 @@ static const u8 sensor_start_ov772x_qvga[][2] = {
614 {0x65, 0x2f}, 490 {0x65, 0x2f},
615}; 491};
616 492
617static const u8 bridge_init_ov965x[][2] = {
618 {0x88, 0xf8},
619 {0x89, 0xff},
620 {0x76, 0x03},
621 {0x92, 0x03},
622 {0x95, 0x10},
623 {0xe2, 0x00},
624 {0xe7, 0x3e},
625 {0x8d, 0x1c},
626 {0x8e, 0x00},
627 {0x8f, 0x00},
628 {0x1f, 0x00},
629 {0xc3, 0xf9},
630 {0x89, 0xff},
631 {0x88, 0xf8},
632 {0x76, 0x03},
633 {0x92, 0x01},
634 {0x93, 0x18},
635 {0x1c, 0x0a},
636 {0x1d, 0x48},
637 {0xc0, 0x50},
638 {0xc1, 0x3c},
639 {0x34, 0x05},
640 {0xc2, 0x0c},
641 {0xc3, 0xf9},
642 {0x34, 0x05},
643 {0xe7, 0x2e},
644 {0x31, 0xf9},
645 {0x35, 0x02},
646 {0xd9, 0x10},
647 {0x25, 0x42},
648 {0x94, 0x11},
649};
650
651static const u8 sensor_init_ov965x[][2] = {
652 {0x12, 0x80}, /* com7 - SSCB reset */
653 {0x00, 0x00}, /* gain */
654 {0x01, 0x80}, /* blue */
655 {0x02, 0x80}, /* red */
656 {0x03, 0x1b}, /* vref */
657 {0x04, 0x03}, /* com1 - exposure low bits */
658 {0x0b, 0x57}, /* ver */
659 {0x0e, 0x61}, /* com5 */
660 {0x0f, 0x42}, /* com6 */
661 {0x11, 0x00}, /* clkrc */
662 {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
663 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
664 {0x14, 0x28}, /* com9 */
665 {0x16, 0x24}, /* reg16 */
666 {0x17, 0x1d}, /* hstart*/
667 {0x18, 0xbd}, /* hstop */
668 {0x19, 0x01}, /* vstrt */
669 {0x1a, 0x81}, /* vstop*/
670 {0x1e, 0x04}, /* mvfp */
671 {0x24, 0x3c}, /* aew */
672 {0x25, 0x36}, /* aeb */
673 {0x26, 0x71}, /* vpt */
674 {0x27, 0x08}, /* bbias */
675 {0x28, 0x08}, /* gbbias */
676 {0x29, 0x15}, /* gr com */
677 {0x2a, 0x00}, /* exhch */
678 {0x2b, 0x00}, /* exhcl */
679 {0x2c, 0x08}, /* rbias */
680 {0x32, 0xff}, /* href */
681 {0x33, 0x00}, /* chlf */
682 {0x34, 0x3f}, /* aref1 */
683 {0x35, 0x00}, /* aref2 */
684 {0x36, 0xf8}, /* aref3 */
685 {0x38, 0x72}, /* adc2 */
686 {0x39, 0x57}, /* aref4 */
687 {0x3a, 0x80}, /* tslb - yuyv */
688 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
689 {0x3d, 0x99}, /* com13 */
690 {0x3f, 0xc1}, /* edge */
691 {0x40, 0xc0}, /* com15 */
692 {0x41, 0x40}, /* com16 */
693 {0x42, 0xc0}, /* com17 */
694 {0x43, 0x0a}, /* rsvd */
695 {0x44, 0xf0},
696 {0x45, 0x46},
697 {0x46, 0x62},
698 {0x47, 0x2a},
699 {0x48, 0x3c},
700 {0x4a, 0xfc},
701 {0x4b, 0xfc},
702 {0x4c, 0x7f},
703 {0x4d, 0x7f},
704 {0x4e, 0x7f},
705 {0x4f, 0x98}, /* matrix */
706 {0x50, 0x98},
707 {0x51, 0x00},
708 {0x52, 0x28},
709 {0x53, 0x70},
710 {0x54, 0x98},
711 {0x58, 0x1a}, /* matrix coef sign */
712 {0x59, 0x85}, /* AWB control */
713 {0x5a, 0xa9},
714 {0x5b, 0x64},
715 {0x5c, 0x84},
716 {0x5d, 0x53},
717 {0x5e, 0x0e},
718 {0x5f, 0xf0}, /* AWB blue limit */
719 {0x60, 0xf0}, /* AWB red limit */
720 {0x61, 0xf0}, /* AWB green limit */
721 {0x62, 0x00}, /* lcc1 */
722 {0x63, 0x00}, /* lcc2 */
723 {0x64, 0x02}, /* lcc3 */
724 {0x65, 0x16}, /* lcc4 */
725 {0x66, 0x01}, /* lcc5 */
726 {0x69, 0x02}, /* hv */
727 {0x6b, 0x5a}, /* dbvl */
728 {0x6c, 0x04},
729 {0x6d, 0x55},
730 {0x6e, 0x00},
731 {0x6f, 0x9d},
732 {0x70, 0x21}, /* dnsth */
733 {0x71, 0x78},
734 {0x72, 0x00}, /* poidx */
735 {0x73, 0x01}, /* pckdv */
736 {0x74, 0x3a}, /* xindx */
737 {0x75, 0x35}, /* yindx */
738 {0x76, 0x01},
739 {0x77, 0x02},
740 {0x7a, 0x12}, /* gamma curve */
741 {0x7b, 0x08},
742 {0x7c, 0x16},
743 {0x7d, 0x30},
744 {0x7e, 0x5e},
745 {0x7f, 0x72},
746 {0x80, 0x82},
747 {0x81, 0x8e},
748 {0x82, 0x9a},
749 {0x83, 0xa4},
750 {0x84, 0xac},
751 {0x85, 0xb8},
752 {0x86, 0xc3},
753 {0x87, 0xd6},
754 {0x88, 0xe6},
755 {0x89, 0xf2},
756 {0x8a, 0x03},
757 {0x8c, 0x89}, /* com19 */
758 {0x14, 0x28}, /* com9 */
759 {0x90, 0x7d},
760 {0x91, 0x7b},
761 {0x9d, 0x03}, /* lcc6 */
762 {0x9e, 0x04}, /* lcc7 */
763 {0x9f, 0x7a},
764 {0xa0, 0x79},
765 {0xa1, 0x40}, /* aechm */
766 {0xa4, 0x50}, /* com21 */
767 {0xa5, 0x68}, /* com26 */
768 {0xa6, 0x4a}, /* AWB green */
769 {0xa8, 0xc1}, /* refa8 */
770 {0xa9, 0xef}, /* refa9 */
771 {0xaa, 0x92},
772 {0xab, 0x04},
773 {0xac, 0x80}, /* black level control */
774 {0xad, 0x80},
775 {0xae, 0x80},
776 {0xaf, 0x80},
777 {0xb2, 0xf2},
778 {0xb3, 0x20},
779 {0xb4, 0x20}, /* ctrlb4 */
780 {0xb5, 0x00},
781 {0xb6, 0xaf},
782 {0xbb, 0xae},
783 {0xbc, 0x7f}, /* ADC channel offsets */
784 {0xdb, 0x7f},
785 {0xbe, 0x7f},
786 {0xbf, 0x7f},
787 {0xc0, 0xe2},
788 {0xc1, 0xc0},
789 {0xc2, 0x01},
790 {0xc3, 0x4e},
791 {0xc6, 0x85},
792 {0xc7, 0x80}, /* com24 */
793 {0xc9, 0xe0},
794 {0xca, 0xe8},
795 {0xcb, 0xf0},
796 {0xcc, 0xd8},
797 {0xcd, 0xf1},
798 {0x4f, 0x98}, /* matrix */
799 {0x50, 0x98},
800 {0x51, 0x00},
801 {0x52, 0x28},
802 {0x53, 0x70},
803 {0x54, 0x98},
804 {0x58, 0x1a},
805 {0xff, 0x41}, /* read 41, write ff 00 */
806 {0x41, 0x40}, /* com16 */
807
808 {0xc5, 0x03}, /* 60 Hz banding filter */
809 {0x6a, 0x02}, /* 50 Hz banding filter */
810
811 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
812 {0x36, 0xfa}, /* aref3 */
813 {0x69, 0x0a}, /* hv */
814 {0x8c, 0x89}, /* com22 */
815 {0x14, 0x28}, /* com9 */
816 {0x3e, 0x0c},
817 {0x41, 0x40}, /* com16 */
818 {0x72, 0x00},
819 {0x73, 0x00},
820 {0x74, 0x3a},
821 {0x75, 0x35},
822 {0x76, 0x01},
823 {0xc7, 0x80},
824 {0x03, 0x12}, /* vref */
825 {0x17, 0x16}, /* hstart */
826 {0x18, 0x02}, /* hstop */
827 {0x19, 0x01}, /* vstrt */
828 {0x1a, 0x3d}, /* vstop */
829 {0x32, 0xff}, /* href */
830 {0xc0, 0xaa},
831};
832
833static const u8 bridge_init_ov965x_2[][2] = {
834 {0x94, 0xaa},
835 {0xf1, 0x60},
836 {0xe5, 0x04},
837 {0xc0, 0x50},
838 {0xc1, 0x3c},
839 {0x8c, 0x00},
840 {0x8d, 0x1c},
841 {0x34, 0x05},
842
843 {0xc2, 0x0c},
844 {0xc3, 0xf9},
845 {0xda, 0x01},
846 {0x50, 0x00},
847 {0x51, 0xa0},
848 {0x52, 0x3c},
849 {0x53, 0x00},
850 {0x54, 0x00},
851 {0x55, 0x00},
852 {0x57, 0x00},
853 {0x5c, 0x00},
854 {0x5a, 0xa0},
855 {0x5b, 0x78},
856 {0x35, 0x02},
857 {0xd9, 0x10},
858 {0x94, 0x11},
859};
860
861static const u8 sensor_init_ov965x_2[][2] = {
862 {0x3b, 0xc4},
863 {0x1e, 0x04}, /* mvfp */
864 {0x13, 0xe0}, /* com8 */
865 {0x00, 0x00}, /* gain */
866 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
867 {0x11, 0x03}, /* clkrc */
868 {0x6b, 0x5a}, /* dblv */
869 {0x6a, 0x05},
870 {0xc5, 0x07},
871 {0xa2, 0x4b},
872 {0xa3, 0x3e},
873 {0x2d, 0x00},
874 {0xff, 0x42}, /* read 42, write ff 00 */
875 {0x42, 0xc0}, /* com17 */
876 {0x2d, 0x00},
877 {0xff, 0x42}, /* read 42, write ff 00 */
878 {0x42, 0xc1}, /* com17 */
879/* sharpness */
880 {0x3f, 0x01},
881 {0xff, 0x42}, /* read 42, write ff 00 */
882 {0x42, 0xc1}, /* com17 */
883/* saturation */
884 {0x4f, 0x98}, /* matrix */
885 {0x50, 0x98},
886 {0x51, 0x00},
887 {0x52, 0x28},
888 {0x53, 0x70},
889 {0x54, 0x98},
890 {0x58, 0x1a},
891 {0xff, 0x41}, /* read 41, write ff 00 */
892 {0x41, 0x40}, /* com16 */
893/* contrast */
894 {0x56, 0x40},
895/* brightness */
896 {0x55, 0x8f},
897/* expo */
898 {0x10, 0x25}, /* aech - exposure high bits */
899 {0xff, 0x13}, /* read 13, write ff 00 */
900 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
901};
902
903static const u8 sensor_start_ov965x_1_vga[][2] = { /* same for qvga */
904 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
905 {0x36, 0xfa}, /* aref3 */
906 {0x69, 0x0a}, /* hv */
907 {0x8c, 0x89}, /* com22 */
908 {0x14, 0x28}, /* com9 */
909 {0x3e, 0x0c}, /* com14 */
910 {0x41, 0x40}, /* com16 */
911 {0x72, 0x00},
912 {0x73, 0x00},
913 {0x74, 0x3a},
914 {0x75, 0x35},
915 {0x76, 0x01},
916 {0xc7, 0x80}, /* com24 */
917 {0x03, 0x12}, /* vref */
918 {0x17, 0x16}, /* hstart */
919 {0x18, 0x02}, /* hstop */
920 {0x19, 0x01}, /* vstrt */
921 {0x1a, 0x3d}, /* vstop */
922 {0x32, 0xff}, /* href */
923 {0xc0, 0xaa},
924};
925
926static const u8 sensor_start_ov965x_1_svga[][2] = {
927 {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
928 {0x36, 0xf8}, /* aref3 */
929 {0x69, 0x02}, /* hv */
930 {0x8c, 0x0d}, /* com22 */
931 {0x3e, 0x0c}, /* com14 */
932 {0x41, 0x40}, /* com16 */
933 {0x72, 0x00},
934 {0x73, 0x01},
935 {0x74, 0x3a},
936 {0x75, 0x35},
937 {0x76, 0x01},
938 {0xc7, 0x80}, /* com24 */
939 {0x03, 0x1b}, /* vref */
940 {0x17, 0x1d}, /* hstart */
941 {0x18, 0xbd}, /* hstop */
942 {0x19, 0x01}, /* vstrt */
943 {0x1a, 0x81}, /* vstop */
944 {0x32, 0xff}, /* href */
945 {0xc0, 0xe2},
946};
947
948static const u8 sensor_start_ov965x_1_xga[][2] = {
949 {0x12, 0x02}, /* com7 */
950 {0x36, 0xf8}, /* aref3 */
951 {0x69, 0x02}, /* hv */
952 {0x8c, 0x89}, /* com22 */
953 {0x14, 0x28}, /* com9 */
954 {0x3e, 0x0c}, /* com14 */
955 {0x41, 0x40}, /* com16 */
956 {0x72, 0x00},
957 {0x73, 0x01},
958 {0x74, 0x3a},
959 {0x75, 0x35},
960 {0x76, 0x01},
961 {0xc7, 0x80}, /* com24 */
962 {0x03, 0x1b}, /* vref */
963 {0x17, 0x1d}, /* hstart */
964 {0x18, 0xbd}, /* hstop */
965 {0x19, 0x01}, /* vstrt */
966 {0x1a, 0x81}, /* vstop */
967 {0x32, 0xff}, /* href */
968 {0xc0, 0xe2},
969};
970
971static const u8 sensor_start_ov965x_1_sxga[][2] = {
972 {0x12, 0x02}, /* com7 */
973 {0x36, 0xf8}, /* aref3 */
974 {0x69, 0x02}, /* hv */
975 {0x8c, 0x89}, /* com22 */
976 {0x14, 0x28}, /* com9 */
977 {0x3e, 0x0c}, /* com14 */
978 {0x41, 0x40}, /* com16 */
979 {0x72, 0x00},
980 {0x73, 0x01},
981 {0x74, 0x3a},
982 {0x75, 0x35},
983 {0x76, 0x01},
984 {0xc7, 0x80}, /* com24 */
985 {0x03, 0x1b}, /* vref */
986 {0x17, 0x1d}, /* hstart */
987 {0x18, 0x02}, /* hstop */
988 {0x19, 0x01}, /* vstrt */
989 {0x1a, 0x81}, /* vstop */
990 {0x32, 0xff}, /* href */
991 {0xc0, 0xe2},
992};
993
994static const u8 bridge_start_ov965x_qvga[][2] = {
995 {0x94, 0xaa},
996 {0xf1, 0x60},
997 {0xe5, 0x04},
998 {0xc0, 0x50},
999 {0xc1, 0x3c},
1000 {0x8c, 0x00},
1001 {0x8d, 0x1c},
1002 {0x34, 0x05},
1003
1004 {0xc2, 0x4c},
1005 {0xc3, 0xf9},
1006 {0xda, 0x00},
1007 {0x50, 0x00},
1008 {0x51, 0xa0},
1009 {0x52, 0x78},
1010 {0x53, 0x00},
1011 {0x54, 0x00},
1012 {0x55, 0x00},
1013 {0x57, 0x00},
1014 {0x5c, 0x00},
1015 {0x5a, 0x50},
1016 {0x5b, 0x3c},
1017 {0x35, 0x02},
1018 {0xd9, 0x10},
1019 {0x94, 0x11},
1020};
1021
1022static const u8 bridge_start_ov965x_vga[][2] = {
1023 {0x94, 0xaa},
1024 {0xf1, 0x60},
1025 {0xe5, 0x04},
1026 {0xc0, 0x50},
1027 {0xc1, 0x3c},
1028 {0x8c, 0x00},
1029 {0x8d, 0x1c},
1030 {0x34, 0x05},
1031 {0xc2, 0x0c},
1032 {0xc3, 0xf9},
1033 {0xda, 0x01},
1034 {0x50, 0x00},
1035 {0x51, 0xa0},
1036 {0x52, 0x3c},
1037 {0x53, 0x00},
1038 {0x54, 0x00},
1039 {0x55, 0x00},
1040 {0x57, 0x00},
1041 {0x5c, 0x00},
1042 {0x5a, 0xa0},
1043 {0x5b, 0x78},
1044 {0x35, 0x02},
1045 {0xd9, 0x10},
1046 {0x94, 0x11},
1047};
1048
1049static const u8 bridge_start_ov965x_svga[][2] = {
1050 {0x94, 0xaa},
1051 {0xf1, 0x60},
1052 {0xe5, 0x04},
1053 {0xc0, 0xa0},
1054 {0xc1, 0x80},
1055 {0x8c, 0x00},
1056 {0x8d, 0x1c},
1057 {0x34, 0x05},
1058 {0xc2, 0x4c},
1059 {0xc3, 0xf9},
1060 {0x50, 0x00},
1061 {0x51, 0x40},
1062 {0x52, 0x00},
1063 {0x53, 0x00},
1064 {0x54, 0x00},
1065 {0x55, 0x88},
1066 {0x57, 0x00},
1067 {0x5c, 0x00},
1068 {0x5a, 0xc8},
1069 {0x5b, 0x96},
1070 {0x35, 0x02},
1071 {0xd9, 0x10},
1072 {0xda, 0x00},
1073 {0x94, 0x11},
1074};
1075
1076static const u8 bridge_start_ov965x_xga[][2] = {
1077 {0x94, 0xaa},
1078 {0xf1, 0x60},
1079 {0xe5, 0x04},
1080 {0xc0, 0xa0},
1081 {0xc1, 0x80},
1082 {0x8c, 0x00},
1083 {0x8d, 0x1c},
1084 {0x34, 0x05},
1085 {0xc2, 0x4c},
1086 {0xc3, 0xf9},
1087 {0x50, 0x00},
1088 {0x51, 0x40},
1089 {0x52, 0x00},
1090 {0x53, 0x00},
1091 {0x54, 0x00},
1092 {0x55, 0x88},
1093 {0x57, 0x00},
1094 {0x5c, 0x01},
1095 {0x5a, 0x00},
1096 {0x5b, 0xc0},
1097 {0x35, 0x02},
1098 {0xd9, 0x10},
1099 {0xda, 0x01},
1100 {0x94, 0x11},
1101};
1102
1103static const u8 bridge_start_ov965x_sxga[][2] = {
1104 {0x94, 0xaa},
1105 {0xf1, 0x60},
1106 {0xe5, 0x04},
1107 {0xc0, 0xa0},
1108 {0xc1, 0x80},
1109 {0x8c, 0x00},
1110 {0x8d, 0x1c},
1111 {0x34, 0x05},
1112 {0xc2, 0x0c},
1113 {0xc3, 0xf9},
1114 {0xda, 0x00},
1115 {0x35, 0x02},
1116 {0xd9, 0x10},
1117 {0x94, 0x11},
1118};
1119
1120static const u8 sensor_start_ov965x_2_qvga[][2] = {
1121 {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
1122 {0x1e, 0x04}, /* mvfp */
1123 {0x13, 0xe0}, /* com8 */
1124 {0x00, 0x00},
1125 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
1126 {0x11, 0x01}, /* clkrc */
1127 {0x6b, 0x5a}, /* dblv */
1128 {0x6a, 0x02}, /* 50 Hz banding filter */
1129 {0xc5, 0x03}, /* 60 Hz banding filter */
1130 {0xa2, 0x96}, /* bd50 */
1131 {0xa3, 0x7d}, /* bd60 */
1132
1133 {0xff, 0x13}, /* read 13, write ff 00 */
1134 {0x13, 0xe7},
1135 {0x3a, 0x80}, /* tslb - yuyv */
1136};
1137
1138static const u8 sensor_start_ov965x_2_vga[][2] = {
1139 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
1140 {0x1e, 0x04}, /* mvfp */
1141 {0x13, 0xe0}, /* com8 */
1142 {0x00, 0x00},
1143 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
1144 {0x11, 0x03}, /* clkrc */
1145 {0x6b, 0x5a}, /* dblv */
1146 {0x6a, 0x05}, /* 50 Hz banding filter */
1147 {0xc5, 0x07}, /* 60 Hz banding filter */
1148 {0xa2, 0x4b}, /* bd50 */
1149 {0xa3, 0x3e}, /* bd60 */
1150
1151 {0x2d, 0x00}, /* advfl */
1152};
1153
1154static const u8 sensor_start_ov965x_2_svga[][2] = { /* same for xga */
1155 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
1156 {0x1e, 0x04}, /* mvfp */
1157 {0x13, 0xe0}, /* com8 */
1158 {0x00, 0x00},
1159 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
1160 {0x11, 0x01}, /* clkrc */
1161 {0x6b, 0x5a}, /* dblv */
1162 {0x6a, 0x0c}, /* 50 Hz banding filter */
1163 {0xc5, 0x0f}, /* 60 Hz banding filter */
1164 {0xa2, 0x4e}, /* bd50 */
1165 {0xa3, 0x41}, /* bd60 */
1166};
1167
1168static const u8 sensor_start_ov965x_2_sxga[][2] = {
1169 {0x13, 0xe0}, /* com8 */
1170 {0x00, 0x00},
1171 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
1172 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
1173 {0x1e, 0x04}, /* mvfp */
1174 {0x11, 0x01}, /* clkrc */
1175 {0x6b, 0x5a}, /* dblv */
1176 {0x6a, 0x0c}, /* 50 Hz banding filter */
1177 {0xc5, 0x0f}, /* 60 Hz banding filter */
1178 {0xa2, 0x4e}, /* bd50 */
1179 {0xa3, 0x41}, /* bd60 */
1180};
1181
1182static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) 493static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
1183{ 494{
1184 struct usb_device *udev = gspca_dev->dev; 495 struct usb_device *udev = gspca_dev->dev;
@@ -1360,14 +671,14 @@ static void set_frame_rate(struct gspca_dev *gspca_dev)
1360 PDEBUG(D_PROBE, "frame_rate: %d", r->fps); 671 PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
1361} 672}
1362 673
1363static void setbrightness_77(struct gspca_dev *gspca_dev) 674static void setbrightness(struct gspca_dev *gspca_dev)
1364{ 675{
1365 struct sd *sd = (struct sd *) gspca_dev; 676 struct sd *sd = (struct sd *) gspca_dev;
1366 677
1367 sccb_reg_write(gspca_dev, 0x9B, sd->brightness); 678 sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
1368} 679}
1369 680
1370static void setcontrast_77(struct gspca_dev *gspca_dev) 681static void setcontrast(struct gspca_dev *gspca_dev)
1371{ 682{
1372 struct sd *sd = (struct sd *) gspca_dev; 683 struct sd *sd = (struct sd *) gspca_dev;
1373 684
@@ -1401,7 +712,7 @@ static void setgain(struct gspca_dev *gspca_dev)
1401 sccb_reg_write(gspca_dev, 0x00, val); 712 sccb_reg_write(gspca_dev, 0x00, val);
1402} 713}
1403 714
1404static void setexposure_77(struct gspca_dev *gspca_dev) 715static void setexposure(struct gspca_dev *gspca_dev)
1405{ 716{
1406 struct sd *sd = (struct sd *) gspca_dev; 717 struct sd *sd = (struct sd *) gspca_dev;
1407 u8 val; 718 u8 val;
@@ -1432,7 +743,7 @@ static void sethue(struct gspca_dev *gspca_dev)
1432 sccb_reg_write(gspca_dev, 0x01, sd->hue); 743 sccb_reg_write(gspca_dev, 0x01, sd->hue);
1433} 744}
1434 745
1435static void setautogain_77(struct gspca_dev *gspca_dev) 746static void setautogain(struct gspca_dev *gspca_dev)
1436{ 747{
1437 struct sd *sd = (struct sd *) gspca_dev; 748 struct sd *sd = (struct sd *) gspca_dev;
1438 749
@@ -1457,7 +768,7 @@ static void setawb(struct gspca_dev *gspca_dev)
1457 sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */ 768 sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */
1458} 769}
1459 770
1460static void setsharpness_77(struct gspca_dev *gspca_dev) 771static void setsharpness(struct gspca_dev *gspca_dev)
1461{ 772{
1462 struct sd *sd = (struct sd *) gspca_dev; 773 struct sd *sd = (struct sd *) gspca_dev;
1463 u8 val; 774 u8 val;
@@ -1491,132 +802,6 @@ static void setvflip(struct gspca_dev *gspca_dev)
1491 sccb_reg_read(gspca_dev, 0x0c) & 0x7f); 802 sccb_reg_read(gspca_dev, 0x0c) & 0x7f);
1492} 803}
1493 804
1494/* ov965x specific controls */
1495static void setbrightness_96(struct gspca_dev *gspca_dev)
1496{
1497 struct sd *sd = (struct sd *) gspca_dev;
1498 u8 val;
1499
1500 val = sd->brightness;
1501 if (val < 8)
1502 val = 15 - val; /* f .. 8 */
1503 else
1504 val = val - 8; /* 0 .. 7 */
1505 sccb_reg_write(gspca_dev, 0x55, /* brtn - brightness adjustment */
1506 0x0f | (val << 4));
1507}
1508
1509static void setcontrast_96(struct gspca_dev *gspca_dev)
1510{
1511 struct sd *sd = (struct sd *) gspca_dev;
1512
1513 sccb_reg_write(gspca_dev, 0x56, /* cnst1 - contrast 1 ctrl coeff */
1514 sd->contrast << 4);
1515}
1516
1517static void setexposure_96(struct gspca_dev *gspca_dev)
1518{
1519 struct sd *sd = (struct sd *) gspca_dev;
1520 u8 val;
1521 static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
1522
1523 sccb_reg_write(gspca_dev, 0x10, /* aec[9:2] */
1524 expo[sd->exposure]);
1525 val = sccb_reg_read(gspca_dev, 0x13); /* com8 */
1526 sccb_reg_write(gspca_dev, 0xff, 0x00);
1527 sccb_reg_write(gspca_dev, 0x13, val);
1528 val = sccb_reg_read(gspca_dev, 0xa1); /* aech */
1529 sccb_reg_write(gspca_dev, 0xff, 0x00);
1530 sccb_reg_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */
1531}
1532
1533static void setsharpness_96(struct gspca_dev *gspca_dev)
1534{
1535 struct sd *sd = (struct sd *) gspca_dev;
1536 s8 val;
1537
1538 val = sd->sharpness;
1539 if (val < 0) { /* auto */
1540 val = sccb_reg_read(gspca_dev, 0x42); /* com17 */
1541 sccb_reg_write(gspca_dev, 0xff, 0x00);
1542 sccb_reg_write(gspca_dev, 0x42, val | 0x40);
1543 /* Edge enhancement strength auto adjust */
1544 return;
1545 }
1546 if (val != 0)
1547 val = 1 << (val - 1);
1548 sccb_reg_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */
1549 val);
1550 val = sccb_reg_read(gspca_dev, 0x42); /* com17 */
1551 sccb_reg_write(gspca_dev, 0xff, 0x00);
1552 sccb_reg_write(gspca_dev, 0x42, val & 0xbf);
1553}
1554
1555static void setautogain_96(struct gspca_dev *gspca_dev)
1556{
1557 struct sd *sd = (struct sd *) gspca_dev;
1558 u8 val;
1559
1560/*fixme: should adjust agc/awb/aec by different controls */
1561 val = sd->autogain;
1562 val = sccb_reg_read(gspca_dev, 0x13); /* com8 */
1563 sccb_reg_write(gspca_dev, 0xff, 0x00);
1564 if (sd->autogain)
1565 val |= 0x05; /* agc & aec */
1566 else
1567 val &= 0xfa;
1568 sccb_reg_write(gspca_dev, 0x13, val);
1569}
1570
1571static void setsatur(struct gspca_dev *gspca_dev)
1572{
1573 struct sd *sd = (struct sd *) gspca_dev;
1574 u8 val1, val2, val3;
1575 static const u8 matrix[5][2] = {
1576 {0x14, 0x38},
1577 {0x1e, 0x54},
1578 {0x28, 0x70},
1579 {0x32, 0x8c},
1580 {0x48, 0x90}
1581 };
1582
1583 val1 = matrix[sd->satur][0];
1584 val2 = matrix[sd->satur][1];
1585 val3 = val1 + val2;
1586 sccb_reg_write(gspca_dev, 0x4f, val3); /* matrix coeff */
1587 sccb_reg_write(gspca_dev, 0x50, val3);
1588 sccb_reg_write(gspca_dev, 0x51, 0x00);
1589 sccb_reg_write(gspca_dev, 0x52, val1);
1590 sccb_reg_write(gspca_dev, 0x53, val2);
1591 sccb_reg_write(gspca_dev, 0x54, val3);
1592 sccb_reg_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */
1593 val1 = sccb_reg_read(gspca_dev, 0x41); /* com16 */
1594 sccb_reg_write(gspca_dev, 0xff, 0x00);
1595 sccb_reg_write(gspca_dev, 0x41, val1);
1596}
1597
1598static void setfreq(struct gspca_dev *gspca_dev)
1599{
1600 struct sd *sd = (struct sd *) gspca_dev;
1601 u8 val;
1602
1603 val = sccb_reg_read(gspca_dev, 0x13); /* com8 */
1604 sccb_reg_write(gspca_dev, 0xff, 0x00);
1605 if (sd->lightfreq == 0) {
1606 sccb_reg_write(gspca_dev, 0x13, val & 0xdf);
1607 return;
1608 }
1609 sccb_reg_write(gspca_dev, 0x13, val | 0x20);
1610
1611 val = sccb_reg_read(gspca_dev, 0x42); /* com17 */
1612 sccb_reg_write(gspca_dev, 0xff, 0x00);
1613 if (sd->lightfreq == 1)
1614 val |= 0x01;
1615 else
1616 val &= 0xfe;
1617 sccb_reg_write(gspca_dev, 0x42, val);
1618}
1619
1620/* this function is called at probe time */ 805/* this function is called at probe time */
1621static int sd_config(struct gspca_dev *gspca_dev, 806static int sd_config(struct gspca_dev *gspca_dev,
1622 const struct usb_device_id *id) 807 const struct usb_device_id *id)
@@ -1624,77 +809,50 @@ static int sd_config(struct gspca_dev *gspca_dev,
1624 struct sd *sd = (struct sd *) gspca_dev; 809 struct sd *sd = (struct sd *) gspca_dev;
1625 struct cam *cam; 810 struct cam *cam;
1626 811
1627 sd->sensor = id->driver_info;
1628
1629 cam = &gspca_dev->cam; 812 cam = &gspca_dev->cam;
1630 813
1631 if (sd->sensor == SENSOR_OV772X) { 814 cam->cam_mode = ov772x_mode;
1632 cam->cam_mode = ov772x_mode; 815 cam->nmodes = ARRAY_SIZE(ov772x_mode);
1633 cam->nmodes = ARRAY_SIZE(ov772x_mode); 816 cam->mode_framerates = ov772x_framerates;
1634 817
1635 cam->bulk = 1; 818 cam->bulk = 1;
1636 cam->bulk_size = 16384; 819 cam->bulk_size = 16384;
1637 cam->bulk_nurbs = 2; 820 cam->bulk_nurbs = 2;
1638 } else { /* ov965x */
1639 cam->cam_mode = ov965x_mode;
1640 cam->nmodes = ARRAY_SIZE(ov965x_mode);
1641 }
1642 821
1643 sd->frame_rate = 30; 822 sd->frame_rate = 30;
1644 823
1645 if (sd->sensor == SENSOR_OV772X) { 824 sd->brightness = BRIGHTNESS_DEF;
1646 sd->brightness = BRIGHTNESS_77_DEF; 825 sd->contrast = CONTRAST_DEF;
1647 sd->contrast = CONTRAST_77_DEF; 826 sd->gain = GAIN_DEF;
1648 sd->gain = GAIN_DEF; 827 sd->exposure = EXPO_DEF;
1649 sd->exposure = EXPO_77_DEF; 828 sd->redblc = RED_BALANCE_DEF;
1650 sd->redblc = RED_BALANCE_DEF; 829 sd->blueblc = BLUE_BALANCE_DEF;
1651 sd->blueblc = BLUE_BALANCE_DEF; 830 sd->hue = HUE_DEF;
1652 sd->hue = HUE_DEF; 831#if AUTOGAIN_DEF != 0
1653#if AUTOGAIN_77_DEF != 0 832 sd->autogain = AUTOGAIN_DEF;
1654 sd->autogain = AUTOGAIN_77_DEF;
1655#else 833#else
1656 gspca_dev->ctrl_inac |= (1 << AWB_77_IDX); 834 gspca_dev->ctrl_inac |= (1 << AWB_IDX);
1657#endif 835#endif
1658#if AWB_DEF != 0 836#if AWB_DEF != 0
1659 sd->awb = AWB_DEF 837 sd->awb = AWB_DEF
1660#endif 838#endif
1661#if SHARPNESS_77_DEF != 0 839#if SHARPNESS_DEF != 0
1662 sd->sharpness = SHARPNESS_77_DEF; 840 sd->sharpness = SHARPNESS_DEF;
1663#endif 841#endif
1664#if HFLIP_DEF != 0 842#if HFLIP_DEF != 0
1665 sd->hflip = HFLIP_DEF; 843 sd->hflip = HFLIP_DEF;
1666#endif 844#endif
1667#if VFLIP_DEF != 0 845#if VFLIP_DEF != 0
1668 sd->vflip = VFLIP_DEF; 846 sd->vflip = VFLIP_DEF;
1669#endif
1670 } else {
1671 sd->brightness = BRIGHTNESS_96_DEF;
1672 sd->contrast = CONTRAST_96_DEF;
1673#if AUTOGAIN_96_DEF != 0
1674 sd->autogain = AUTOGAIN_96_DEF;
1675 gspca_dev->ctrl_inac |= (1 << EXPO_96_IDX);
1676#endif 847#endif
1677#if EXPO_96_DEF != 0 848
1678 sd->exposure = EXPO_96_DEF;
1679#endif
1680#if SHARPNESS_96_DEF != 0
1681 sd->sharpness = SHARPNESS_96_DEF;
1682#endif
1683 sd->satur = SATUR_DEF;
1684 sd->lightfreq = FREQ_DEF;
1685 }
1686 return 0; 849 return 0;
1687} 850}
1688 851
1689/* this function is called at probe and resume time */ 852/* this function is called at probe and resume time */
1690static int sd_init(struct gspca_dev *gspca_dev) 853static int sd_init(struct gspca_dev *gspca_dev)
1691{ 854{
1692 struct sd *sd = (struct sd *) gspca_dev;
1693 u16 sensor_id; 855 u16 sensor_id;
1694 static const u8 sensor_addr[2] = {
1695 0x42, /* 0 SENSOR_OV772X */
1696 0x60, /* 1 SENSOR_OV965X */
1697 };
1698 856
1699 /* reset bridge */ 857 /* reset bridge */
1700 ov534_reg_write(gspca_dev, 0xe7, 0x3a); 858 ov534_reg_write(gspca_dev, 0xe7, 0x3a);
@@ -1702,8 +860,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
1702 msleep(100); 860 msleep(100);
1703 861
1704 /* initialize the sensor address */ 862 /* initialize the sensor address */
1705 ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 863 ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42);
1706 sensor_addr[sd->sensor]);
1707 864
1708 /* reset sensor */ 865 /* reset sensor */
1709 sccb_reg_write(gspca_dev, 0x12, 0x80); 866 sccb_reg_write(gspca_dev, 0x12, 0x80);
@@ -1717,64 +874,46 @@ static int sd_init(struct gspca_dev *gspca_dev)
1717 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id); 874 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
1718 875
1719 /* initialize */ 876 /* initialize */
1720 switch (sd->sensor) { 877 reg_w_array(gspca_dev, bridge_init,
1721 case SENSOR_OV772X: 878 ARRAY_SIZE(bridge_init));
1722 reg_w_array(gspca_dev, bridge_init_ov772x, 879 ov534_set_led(gspca_dev, 1);
1723 ARRAY_SIZE(bridge_init_ov772x)); 880 sccb_w_array(gspca_dev, sensor_init,
1724 ov534_set_led(gspca_dev, 1); 881 ARRAY_SIZE(sensor_init));
1725 sccb_w_array(gspca_dev, sensor_init_ov772x, 882 ov534_reg_write(gspca_dev, 0xe0, 0x09);
1726 ARRAY_SIZE(sensor_init_ov772x)); 883 ov534_set_led(gspca_dev, 0);
1727 ov534_reg_write(gspca_dev, 0xe0, 0x09); 884 set_frame_rate(gspca_dev);
1728 ov534_set_led(gspca_dev, 0);
1729 set_frame_rate(gspca_dev);
1730 break;
1731 default:
1732/* case SENSOR_OV965X: */
1733 reg_w_array(gspca_dev, bridge_init_ov965x,
1734 ARRAY_SIZE(bridge_init_ov965x));
1735 sccb_w_array(gspca_dev, sensor_init_ov965x,
1736 ARRAY_SIZE(sensor_init_ov965x));
1737 reg_w_array(gspca_dev, bridge_init_ov965x_2,
1738 ARRAY_SIZE(bridge_init_ov965x_2));
1739 sccb_w_array(gspca_dev, sensor_init_ov965x_2,
1740 ARRAY_SIZE(sensor_init_ov965x_2));
1741 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1742 ov534_reg_write(gspca_dev, 0xe0, 0x01);
1743 ov534_set_led(gspca_dev, 0);
1744 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1745 }
1746 885
1747 return 0; 886 return 0;
1748} 887}
1749 888
1750static int sd_start_ov772x(struct gspca_dev *gspca_dev) 889static int sd_start(struct gspca_dev *gspca_dev)
1751{ 890{
1752 int mode; 891 int mode;
1753 892
1754 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; 893 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1755 if (mode != 0) { /* 320x240 */ 894 if (mode != 0) { /* 320x240 */
1756 reg_w_array(gspca_dev, bridge_start_ov772x_qvga, 895 reg_w_array(gspca_dev, bridge_start_qvga,
1757 ARRAY_SIZE(bridge_start_ov772x_qvga)); 896 ARRAY_SIZE(bridge_start_qvga));
1758 sccb_w_array(gspca_dev, sensor_start_ov772x_qvga, 897 sccb_w_array(gspca_dev, sensor_start_qvga,
1759 ARRAY_SIZE(sensor_start_ov772x_qvga)); 898 ARRAY_SIZE(sensor_start_qvga));
1760 } else { /* 640x480 */ 899 } else { /* 640x480 */
1761 reg_w_array(gspca_dev, bridge_start_ov772x_vga, 900 reg_w_array(gspca_dev, bridge_start_vga,
1762 ARRAY_SIZE(bridge_start_ov772x_vga)); 901 ARRAY_SIZE(bridge_start_vga));
1763 sccb_w_array(gspca_dev, sensor_start_ov772x_vga, 902 sccb_w_array(gspca_dev, sensor_start_vga,
1764 ARRAY_SIZE(sensor_start_ov772x_vga)); 903 ARRAY_SIZE(sensor_start_vga));
1765 } 904 }
1766 set_frame_rate(gspca_dev); 905 set_frame_rate(gspca_dev);
1767 906
1768 setautogain_77(gspca_dev); 907 setautogain(gspca_dev);
1769 setawb(gspca_dev); 908 setawb(gspca_dev);
1770 setgain(gspca_dev); 909 setgain(gspca_dev);
1771 setredblc(gspca_dev); 910 setredblc(gspca_dev);
1772 setblueblc(gspca_dev); 911 setblueblc(gspca_dev);
1773 sethue(gspca_dev); 912 sethue(gspca_dev);
1774 setexposure_77(gspca_dev); 913 setexposure(gspca_dev);
1775 setbrightness_77(gspca_dev); 914 setbrightness(gspca_dev);
1776 setcontrast_77(gspca_dev); 915 setcontrast(gspca_dev);
1777 setsharpness_77(gspca_dev); 916 setsharpness(gspca_dev);
1778 setvflip(gspca_dev); 917 setvflip(gspca_dev);
1779 sethflip(gspca_dev); 918 sethflip(gspca_dev);
1780 919
@@ -1783,81 +922,12 @@ static int sd_start_ov772x(struct gspca_dev *gspca_dev)
1783 return 0; 922 return 0;
1784} 923}
1785 924
1786static int sd_start_ov965x(struct gspca_dev *gspca_dev) 925static void sd_stopN(struct gspca_dev *gspca_dev)
1787{
1788 int mode;
1789
1790 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1791 switch (mode) {
1792 default:
1793/* case 4: * 320x240 */
1794 sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga,
1795 ARRAY_SIZE(sensor_start_ov965x_1_vga));
1796 reg_w_array(gspca_dev, bridge_start_ov965x_qvga,
1797 ARRAY_SIZE(bridge_start_ov965x_qvga));
1798 sccb_w_array(gspca_dev, sensor_start_ov965x_2_qvga,
1799 ARRAY_SIZE(sensor_start_ov965x_2_qvga));
1800 break;
1801 case 3: /* 640x480 */
1802 sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga,
1803 ARRAY_SIZE(sensor_start_ov965x_1_vga));
1804 reg_w_array(gspca_dev, bridge_start_ov965x_vga,
1805 ARRAY_SIZE(bridge_start_ov965x_vga));
1806 sccb_w_array(gspca_dev, sensor_start_ov965x_2_vga,
1807 ARRAY_SIZE(sensor_start_ov965x_2_vga));
1808 break;
1809 case 2: /* 800x600 */
1810 sccb_w_array(gspca_dev, sensor_start_ov965x_1_svga,
1811 ARRAY_SIZE(sensor_start_ov965x_1_svga));
1812 reg_w_array(gspca_dev, bridge_start_ov965x_svga,
1813 ARRAY_SIZE(bridge_start_ov965x_svga));
1814 sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga,
1815 ARRAY_SIZE(sensor_start_ov965x_2_svga));
1816 break;
1817 case 1: /* 1024x768 */
1818 sccb_w_array(gspca_dev, sensor_start_ov965x_1_xga,
1819 ARRAY_SIZE(sensor_start_ov965x_1_xga));
1820 reg_w_array(gspca_dev, bridge_start_ov965x_xga,
1821 ARRAY_SIZE(bridge_start_ov965x_xga));
1822 sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga,
1823 ARRAY_SIZE(sensor_start_ov965x_2_svga));
1824 break;
1825 case 0: /* 1280x1024 */
1826 sccb_w_array(gspca_dev, sensor_start_ov965x_1_sxga,
1827 ARRAY_SIZE(sensor_start_ov965x_1_sxga));
1828 reg_w_array(gspca_dev, bridge_start_ov965x_sxga,
1829 ARRAY_SIZE(bridge_start_ov965x_sxga));
1830 sccb_w_array(gspca_dev, sensor_start_ov965x_2_sxga,
1831 ARRAY_SIZE(sensor_start_ov965x_2_sxga));
1832 break;
1833 }
1834 setfreq(gspca_dev);
1835 setautogain_96(gspca_dev);
1836 setbrightness_96(gspca_dev);
1837 setcontrast_96(gspca_dev);
1838 setexposure_96(gspca_dev);
1839 setsharpness_96(gspca_dev);
1840 setsatur(gspca_dev);
1841
1842 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1843 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1844 ov534_set_led(gspca_dev, 1);
1845 return 0;
1846}
1847
1848static void sd_stopN_ov772x(struct gspca_dev *gspca_dev)
1849{ 926{
1850 ov534_reg_write(gspca_dev, 0xe0, 0x09); 927 ov534_reg_write(gspca_dev, 0xe0, 0x09);
1851 ov534_set_led(gspca_dev, 0); 928 ov534_set_led(gspca_dev, 0);
1852} 929}
1853 930
1854static void sd_stopN_ov965x(struct gspca_dev *gspca_dev)
1855{
1856 ov534_reg_write(gspca_dev, 0xe0, 0x01);
1857 ov534_set_led(gspca_dev, 0);
1858 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1859}
1860
1861/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ 931/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
1862#define UVC_STREAM_EOH (1 << 7) 932#define UVC_STREAM_EOH (1 << 7)
1863#define UVC_STREAM_ERR (1 << 6) 933#define UVC_STREAM_ERR (1 << 6)
@@ -1875,11 +945,9 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1875 __u32 this_pts; 945 __u32 this_pts;
1876 u16 this_fid; 946 u16 this_fid;
1877 int remaining_len = len; 947 int remaining_len = len;
1878 int payload_len;
1879 948
1880 payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
1881 do { 949 do {
1882 len = min(remaining_len, payload_len); 950 len = min(remaining_len, 2048);
1883 951
1884 /* Payloads are prefixed with a UVC-style header. We 952 /* Payloads are prefixed with a UVC-style header. We
1885 consider a frame to start when the FID toggles, or the PTS 953 consider a frame to start when the FID toggles, or the PTS
@@ -1918,7 +986,17 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1918 data + 12, len - 12); 986 data + 12, len - 12);
1919 /* If this packet is marked as EOF, end the frame */ 987 /* If this packet is marked as EOF, end the frame */
1920 } else if (data[1] & UVC_STREAM_EOF) { 988 } else if (data[1] & UVC_STREAM_EOF) {
989 struct gspca_frame *frame;
990
1921 sd->last_pts = 0; 991 sd->last_pts = 0;
992 frame = gspca_get_i_frame(gspca_dev);
993 if (frame == NULL)
994 goto discard;
995 if (frame->data_end - frame->data + (len - 12) !=
996 gspca_dev->width * gspca_dev->height * 2) {
997 PDEBUG(D_PACK, "wrong sized frame");
998 goto discard;
999 }
1922 gspca_frame_add(gspca_dev, LAST_PACKET, 1000 gspca_frame_add(gspca_dev, LAST_PACKET,
1923 data + 12, len - 12); 1001 data + 12, len - 12);
1924 } else { 1002 } else {
@@ -1965,12 +1043,8 @@ static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1965 struct sd *sd = (struct sd *) gspca_dev; 1043 struct sd *sd = (struct sd *) gspca_dev;
1966 1044
1967 sd->exposure = val; 1045 sd->exposure = val;
1968 if (gspca_dev->streaming) { 1046 if (gspca_dev->streaming)
1969 if (sd->sensor == SENSOR_OV772X) 1047 setexposure(gspca_dev);
1970 setexposure_77(gspca_dev);
1971 else
1972 setexposure_96(gspca_dev);
1973 }
1974 return 0; 1048 return 0;
1975} 1049}
1976 1050
@@ -1987,12 +1061,8 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1987 struct sd *sd = (struct sd *) gspca_dev; 1061 struct sd *sd = (struct sd *) gspca_dev;
1988 1062
1989 sd->brightness = val; 1063 sd->brightness = val;
1990 if (gspca_dev->streaming) { 1064 if (gspca_dev->streaming)
1991 if (sd->sensor == SENSOR_OV772X) 1065 setbrightness(gspca_dev);
1992 setbrightness_77(gspca_dev);
1993 else
1994 setbrightness_96(gspca_dev);
1995 }
1996 return 0; 1066 return 0;
1997} 1067}
1998 1068
@@ -2009,12 +1079,8 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
2009 struct sd *sd = (struct sd *) gspca_dev; 1079 struct sd *sd = (struct sd *) gspca_dev;
2010 1080
2011 sd->contrast = val; 1081 sd->contrast = val;
2012 if (gspca_dev->streaming) { 1082 if (gspca_dev->streaming)
2013 if (sd->sensor == SENSOR_OV772X) 1083 setcontrast(gspca_dev);
2014 setcontrast_77(gspca_dev);
2015 else
2016 setcontrast_96(gspca_dev);
2017 }
2018 return 0; 1084 return 0;
2019} 1085}
2020 1086
@@ -2026,41 +1092,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2026 return 0; 1092 return 0;
2027} 1093}
2028 1094
2029static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val)
2030{
2031 struct sd *sd = (struct sd *) gspca_dev;
2032
2033 sd->satur = val;
2034 if (gspca_dev->streaming)
2035 setsatur(gspca_dev);
2036 return 0;
2037}
2038
2039static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val)
2040{
2041 struct sd *sd = (struct sd *) gspca_dev;
2042
2043 *val = sd->satur;
2044 return 0;
2045}
2046static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
2047{
2048 struct sd *sd = (struct sd *) gspca_dev;
2049
2050 sd->lightfreq = val;
2051 if (gspca_dev->streaming)
2052 setfreq(gspca_dev);
2053 return 0;
2054}
2055
2056static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
2057{
2058 struct sd *sd = (struct sd *) gspca_dev;
2059
2060 *val = sd->lightfreq;
2061 return 0;
2062}
2063
2064static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val) 1095static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val)
2065{ 1096{
2066 struct sd *sd = (struct sd *) gspca_dev; 1097 struct sd *sd = (struct sd *) gspca_dev;
@@ -2122,22 +1153,14 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
2122 sd->autogain = val; 1153 sd->autogain = val;
2123 1154
2124 if (gspca_dev->streaming) { 1155 if (gspca_dev->streaming) {
2125 if (sd->sensor == SENSOR_OV772X) { 1156
2126 1157 /* the auto white balance control works only
2127 /* the auto white balance control works only 1158 * when auto gain is set */
2128 * when auto gain is set */ 1159 if (val)
2129 if (val) 1160 gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
2130 gspca_dev->ctrl_inac &= ~(1 << AWB_77_IDX); 1161 else
2131 else 1162 gspca_dev->ctrl_inac |= (1 << AWB_IDX);
2132 gspca_dev->ctrl_inac |= (1 << AWB_77_IDX); 1163 setautogain(gspca_dev);
2133 setautogain_77(gspca_dev);
2134 } else {
2135 if (val)
2136 gspca_dev->ctrl_inac |= (1 << EXPO_96_IDX);
2137 else
2138 gspca_dev->ctrl_inac &= ~(1 << EXPO_96_IDX);
2139 setautogain_96(gspca_dev);
2140 }
2141 } 1164 }
2142 return 0; 1165 return 0;
2143} 1166}
@@ -2173,12 +1196,8 @@ static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
2173 struct sd *sd = (struct sd *) gspca_dev; 1196 struct sd *sd = (struct sd *) gspca_dev;
2174 1197
2175 sd->sharpness = val; 1198 sd->sharpness = val;
2176 if (gspca_dev->streaming) { 1199 if (gspca_dev->streaming)
2177 if (sd->sensor == SENSOR_OV772X) 1200 setsharpness(gspca_dev);
2178 setsharpness_77(gspca_dev);
2179 else
2180 setsharpness_96(gspca_dev);
2181 }
2182 return 0; 1201 return 0;
2183} 1202}
2184 1203
@@ -2257,7 +1276,7 @@ static int sd_set_streamparm(struct gspca_dev *gspca_dev,
2257 1276
2258 /* Set requested framerate */ 1277 /* Set requested framerate */
2259 sd->frame_rate = tpf->denominator / tpf->numerator; 1278 sd->frame_rate = tpf->denominator / tpf->numerator;
2260 if (gspca_dev->streaming && sd->sensor == SENSOR_OV772X) 1279 if (gspca_dev->streaming)
2261 set_frame_rate(gspca_dev); 1280 set_frame_rate(gspca_dev);
2262 1281
2263 /* Return the actual framerate */ 1282 /* Return the actual framerate */
@@ -2267,57 +1286,23 @@ static int sd_set_streamparm(struct gspca_dev *gspca_dev,
2267 return 0; 1286 return 0;
2268} 1287}
2269 1288
2270static int sd_querymenu(struct gspca_dev *gspca_dev,
2271 struct v4l2_querymenu *menu)
2272{
2273 switch (menu->id) {
2274 case V4L2_CID_POWER_LINE_FREQUENCY:
2275 switch (menu->index) {
2276 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
2277 strcpy((char *) menu->name, "NoFliker");
2278 return 0;
2279 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2280 strcpy((char *) menu->name, "50 Hz");
2281 return 0;
2282 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2283 strcpy((char *) menu->name, "60 Hz");
2284 return 0;
2285 }
2286 break;
2287 }
2288 return -EINVAL;
2289}
2290
2291/* sub-driver description */ 1289/* sub-driver description */
2292static const struct sd_desc sd_desc_ov772x = { 1290static const struct sd_desc sd_desc = {
2293 .name = MODULE_NAME, 1291 .name = MODULE_NAME,
2294 .ctrls = sd_ctrls_ov772x, 1292 .ctrls = sd_ctrls,
2295 .nctrls = ARRAY_SIZE(sd_ctrls_ov772x), 1293 .nctrls = ARRAY_SIZE(sd_ctrls),
2296 .config = sd_config, 1294 .config = sd_config,
2297 .init = sd_init, 1295 .init = sd_init,
2298 .start = sd_start_ov772x, 1296 .start = sd_start,
2299 .stopN = sd_stopN_ov772x, 1297 .stopN = sd_stopN,
2300 .pkt_scan = sd_pkt_scan, 1298 .pkt_scan = sd_pkt_scan,
2301 .get_streamparm = sd_get_streamparm, 1299 .get_streamparm = sd_get_streamparm,
2302 .set_streamparm = sd_set_streamparm, 1300 .set_streamparm = sd_set_streamparm,
2303}; 1301};
2304 1302
2305static const struct sd_desc sd_desc_ov965x = {
2306 .name = MODULE_NAME,
2307 .ctrls = sd_ctrls_ov965x,
2308 .nctrls = ARRAY_SIZE(sd_ctrls_ov965x),
2309 .config = sd_config,
2310 .init = sd_init,
2311 .start = sd_start_ov965x,
2312 .stopN = sd_stopN_ov965x,
2313 .pkt_scan = sd_pkt_scan,
2314 .querymenu = sd_querymenu,
2315};
2316
2317/* -- module initialisation -- */ 1303/* -- module initialisation -- */
2318static const __devinitdata struct usb_device_id device_table[] = { 1304static const __devinitdata struct usb_device_id device_table[] = {
2319 {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X}, 1305 {USB_DEVICE(0x1415, 0x2000)},
2320 {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X},
2321 {} 1306 {}
2322}; 1307};
2323 1308
@@ -2326,11 +1311,7 @@ MODULE_DEVICE_TABLE(usb, device_table);
2326/* -- device connect -- */ 1311/* -- device connect -- */
2327static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id) 1312static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
2328{ 1313{
2329 return gspca_dev_probe(intf, id, 1314 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2330 id->driver_info == SENSOR_OV772X
2331 ? &sd_desc_ov772x
2332 : &sd_desc_ov965x,
2333 sizeof(struct sd),
2334 THIS_MODULE); 1315 THIS_MODULE);
2335} 1316}
2336 1317
diff --git a/drivers/media/video/gspca/ov534_9.c b/drivers/media/video/gspca/ov534_9.c
new file mode 100644
index 000000000000..bbe5a030e3b4
--- /dev/null
+++ b/drivers/media/video/gspca/ov534_9.c
@@ -0,0 +1,1477 @@
1/*
2 * ov534-ov965x gspca driver
3 *
4 * Copyright (C) 2009-2010 Jean-Francois Moine http://moinejf.free.fr
5 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
6 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
7 *
8 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
9 * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
10 * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#define MODULE_NAME "ov534_9"
28
29#include "gspca.h"
30
31#define OV534_REG_ADDRESS 0xf1 /* sensor address */
32#define OV534_REG_SUBADDR 0xf2
33#define OV534_REG_WRITE 0xf3
34#define OV534_REG_READ 0xf4
35#define OV534_REG_OPERATION 0xf5
36#define OV534_REG_STATUS 0xf6
37
38#define OV534_OP_WRITE_3 0x37
39#define OV534_OP_WRITE_2 0x33
40#define OV534_OP_READ_2 0xf9
41
42#define CTRL_TIMEOUT 500
43
44MODULE_AUTHOR("Jean-Francois Moine <moinejf@free.fr>");
45MODULE_DESCRIPTION("GSPCA/OV534_9 USB Camera Driver");
46MODULE_LICENSE("GPL");
47
48/* specific webcam descriptor */
49struct sd {
50 struct gspca_dev gspca_dev; /* !! must be the first item */
51 __u32 last_pts;
52 u8 last_fid;
53
54 u8 brightness;
55 u8 contrast;
56 u8 autogain;
57 u8 exposure;
58 s8 sharpness;
59 u8 satur;
60 u8 freq;
61};
62
63/* V4L2 controls supported by the driver */
64static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
65static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
66static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
67static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
68static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
69static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
70static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
71static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
72static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
73static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
74static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val);
75static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val);
76static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
77static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
78
79static const struct ctrl sd_ctrls[] = {
80 { /* 0 */
81 {
82 .id = V4L2_CID_BRIGHTNESS,
83 .type = V4L2_CTRL_TYPE_INTEGER,
84 .name = "Brightness",
85 .minimum = 0,
86 .maximum = 15,
87 .step = 1,
88#define BRIGHTNESS_DEF 7
89 .default_value = BRIGHTNESS_DEF,
90 },
91 .set = sd_setbrightness,
92 .get = sd_getbrightness,
93 },
94 { /* 1 */
95 {
96 .id = V4L2_CID_CONTRAST,
97 .type = V4L2_CTRL_TYPE_INTEGER,
98 .name = "Contrast",
99 .minimum = 0,
100 .maximum = 15,
101 .step = 1,
102#define CONTRAST_DEF 3
103 .default_value = CONTRAST_DEF,
104 },
105 .set = sd_setcontrast,
106 .get = sd_getcontrast,
107 },
108 { /* 2 */
109 {
110 .id = V4L2_CID_AUTOGAIN,
111 .type = V4L2_CTRL_TYPE_BOOLEAN,
112 .name = "Autogain",
113 .minimum = 0,
114 .maximum = 1,
115 .step = 1,
116#define AUTOGAIN_DEF 1
117 .default_value = AUTOGAIN_DEF,
118 },
119 .set = sd_setautogain,
120 .get = sd_getautogain,
121 },
122#define EXPO_IDX 3
123 { /* 3 */
124 {
125 .id = V4L2_CID_EXPOSURE,
126 .type = V4L2_CTRL_TYPE_INTEGER,
127 .name = "Exposure",
128 .minimum = 0,
129 .maximum = 3,
130 .step = 1,
131#define EXPO_DEF 0
132 .default_value = EXPO_DEF,
133 },
134 .set = sd_setexposure,
135 .get = sd_getexposure,
136 },
137 { /* 4 */
138 {
139 .id = V4L2_CID_SHARPNESS,
140 .type = V4L2_CTRL_TYPE_INTEGER,
141 .name = "Sharpness",
142 .minimum = -1, /* -1 = auto */
143 .maximum = 4,
144 .step = 1,
145#define SHARPNESS_DEF -1
146 .default_value = SHARPNESS_DEF,
147 },
148 .set = sd_setsharpness,
149 .get = sd_getsharpness,
150 },
151 { /* 5 */
152 {
153 .id = V4L2_CID_SATURATION,
154 .type = V4L2_CTRL_TYPE_INTEGER,
155 .name = "Saturation",
156 .minimum = 0,
157 .maximum = 4,
158 .step = 1,
159#define SATUR_DEF 2
160 .default_value = SATUR_DEF,
161 },
162 .set = sd_setsatur,
163 .get = sd_getsatur,
164 },
165 {
166 {
167 .id = V4L2_CID_POWER_LINE_FREQUENCY,
168 .type = V4L2_CTRL_TYPE_MENU,
169 .name = "Light frequency filter",
170 .minimum = 0,
171 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
172 .step = 1,
173#define FREQ_DEF 0
174 .default_value = FREQ_DEF,
175 },
176 .set = sd_setfreq,
177 .get = sd_getfreq,
178 },
179};
180
181static const struct v4l2_pix_format ov965x_mode[] = {
182#define QVGA_MODE 0
183 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
184 .bytesperline = 320,
185 .sizeimage = 320 * 240 * 3 / 8 + 590,
186 .colorspace = V4L2_COLORSPACE_JPEG},
187#define VGA_MODE 1
188 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
189 .bytesperline = 640,
190 .sizeimage = 640 * 480 * 3 / 8 + 590,
191 .colorspace = V4L2_COLORSPACE_JPEG},
192#define SVGA_MODE 2
193 {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
194 .bytesperline = 800,
195 .sizeimage = 800 * 600 * 3 / 8 + 590,
196 .colorspace = V4L2_COLORSPACE_JPEG},
197#define XGA_MODE 3
198 {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
199 .bytesperline = 1024,
200 .sizeimage = 1024 * 768 * 3 / 8 + 590,
201 .colorspace = V4L2_COLORSPACE_JPEG},
202#define SXGA_MODE 4
203 {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
204 .bytesperline = 1280,
205 .sizeimage = 1280 * 1024 * 3 / 8 + 590,
206 .colorspace = V4L2_COLORSPACE_JPEG},
207};
208
209static const u8 bridge_init[][2] = {
210 {0x88, 0xf8},
211 {0x89, 0xff},
212 {0x76, 0x03},
213 {0x92, 0x03},
214 {0x95, 0x10},
215 {0xe2, 0x00},
216 {0xe7, 0x3e},
217 {0x8d, 0x1c},
218 {0x8e, 0x00},
219 {0x8f, 0x00},
220 {0x1f, 0x00},
221 {0xc3, 0xf9},
222 {0x89, 0xff},
223 {0x88, 0xf8},
224 {0x76, 0x03},
225 {0x92, 0x01},
226 {0x93, 0x18},
227 {0x1c, 0x0a},
228 {0x1d, 0x48},
229 {0xc0, 0x50},
230 {0xc1, 0x3c},
231 {0x34, 0x05},
232 {0xc2, 0x0c},
233 {0xc3, 0xf9},
234 {0x34, 0x05},
235 {0xe7, 0x2e},
236 {0x31, 0xf9},
237 {0x35, 0x02},
238 {0xd9, 0x10},
239 {0x25, 0x42},
240 {0x94, 0x11},
241};
242
243static const u8 sensor_init[][2] = {
244 {0x12, 0x80}, /* com7 - SSCB reset */
245 {0x00, 0x00}, /* gain */
246 {0x01, 0x80}, /* blue */
247 {0x02, 0x80}, /* red */
248 {0x03, 0x1b}, /* vref */
249 {0x04, 0x03}, /* com1 - exposure low bits */
250 {0x0b, 0x57}, /* ver */
251 {0x0e, 0x61}, /* com5 */
252 {0x0f, 0x42}, /* com6 */
253 {0x11, 0x00}, /* clkrc */
254 {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
255 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
256 {0x14, 0x28}, /* com9 */
257 {0x16, 0x24}, /* reg16 */
258 {0x17, 0x1d}, /* hstart*/
259 {0x18, 0xbd}, /* hstop */
260 {0x19, 0x01}, /* vstrt */
261 {0x1a, 0x81}, /* vstop*/
262 {0x1e, 0x04}, /* mvfp */
263 {0x24, 0x3c}, /* aew */
264 {0x25, 0x36}, /* aeb */
265 {0x26, 0x71}, /* vpt */
266 {0x27, 0x08}, /* bbias */
267 {0x28, 0x08}, /* gbbias */
268 {0x29, 0x15}, /* gr com */
269 {0x2a, 0x00}, /* exhch */
270 {0x2b, 0x00}, /* exhcl */
271 {0x2c, 0x08}, /* rbias */
272 {0x32, 0xff}, /* href */
273 {0x33, 0x00}, /* chlf */
274 {0x34, 0x3f}, /* aref1 */
275 {0x35, 0x00}, /* aref2 */
276 {0x36, 0xf8}, /* aref3 */
277 {0x38, 0x72}, /* adc2 */
278 {0x39, 0x57}, /* aref4 */
279 {0x3a, 0x80}, /* tslb - yuyv */
280 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
281 {0x3d, 0x99}, /* com13 */
282 {0x3f, 0xc1}, /* edge */
283 {0x40, 0xc0}, /* com15 */
284 {0x41, 0x40}, /* com16 */
285 {0x42, 0xc0}, /* com17 */
286 {0x43, 0x0a}, /* rsvd */
287 {0x44, 0xf0},
288 {0x45, 0x46},
289 {0x46, 0x62},
290 {0x47, 0x2a},
291 {0x48, 0x3c},
292 {0x4a, 0xfc},
293 {0x4b, 0xfc},
294 {0x4c, 0x7f},
295 {0x4d, 0x7f},
296 {0x4e, 0x7f},
297 {0x4f, 0x98}, /* matrix */
298 {0x50, 0x98},
299 {0x51, 0x00},
300 {0x52, 0x28},
301 {0x53, 0x70},
302 {0x54, 0x98},
303 {0x58, 0x1a}, /* matrix coef sign */
304 {0x59, 0x85}, /* AWB control */
305 {0x5a, 0xa9},
306 {0x5b, 0x64},
307 {0x5c, 0x84},
308 {0x5d, 0x53},
309 {0x5e, 0x0e},
310 {0x5f, 0xf0}, /* AWB blue limit */
311 {0x60, 0xf0}, /* AWB red limit */
312 {0x61, 0xf0}, /* AWB green limit */
313 {0x62, 0x00}, /* lcc1 */
314 {0x63, 0x00}, /* lcc2 */
315 {0x64, 0x02}, /* lcc3 */
316 {0x65, 0x16}, /* lcc4 */
317 {0x66, 0x01}, /* lcc5 */
318 {0x69, 0x02}, /* hv */
319 {0x6b, 0x5a}, /* dbvl */
320 {0x6c, 0x04},
321 {0x6d, 0x55},
322 {0x6e, 0x00},
323 {0x6f, 0x9d},
324 {0x70, 0x21}, /* dnsth */
325 {0x71, 0x78},
326 {0x72, 0x00}, /* poidx */
327 {0x73, 0x01}, /* pckdv */
328 {0x74, 0x3a}, /* xindx */
329 {0x75, 0x35}, /* yindx */
330 {0x76, 0x01},
331 {0x77, 0x02},
332 {0x7a, 0x12}, /* gamma curve */
333 {0x7b, 0x08},
334 {0x7c, 0x16},
335 {0x7d, 0x30},
336 {0x7e, 0x5e},
337 {0x7f, 0x72},
338 {0x80, 0x82},
339 {0x81, 0x8e},
340 {0x82, 0x9a},
341 {0x83, 0xa4},
342 {0x84, 0xac},
343 {0x85, 0xb8},
344 {0x86, 0xc3},
345 {0x87, 0xd6},
346 {0x88, 0xe6},
347 {0x89, 0xf2},
348 {0x8a, 0x03},
349 {0x8c, 0x89}, /* com19 */
350 {0x14, 0x28}, /* com9 */
351 {0x90, 0x7d},
352 {0x91, 0x7b},
353 {0x9d, 0x03}, /* lcc6 */
354 {0x9e, 0x04}, /* lcc7 */
355 {0x9f, 0x7a},
356 {0xa0, 0x79},
357 {0xa1, 0x40}, /* aechm */
358 {0xa4, 0x50}, /* com21 */
359 {0xa5, 0x68}, /* com26 */
360 {0xa6, 0x4a}, /* AWB green */
361 {0xa8, 0xc1}, /* refa8 */
362 {0xa9, 0xef}, /* refa9 */
363 {0xaa, 0x92},
364 {0xab, 0x04},
365 {0xac, 0x80}, /* black level control */
366 {0xad, 0x80},
367 {0xae, 0x80},
368 {0xaf, 0x80},
369 {0xb2, 0xf2},
370 {0xb3, 0x20},
371 {0xb4, 0x20}, /* ctrlb4 */
372 {0xb5, 0x00},
373 {0xb6, 0xaf},
374 {0xbb, 0xae},
375 {0xbc, 0x7f}, /* ADC channel offsets */
376 {0xdb, 0x7f},
377 {0xbe, 0x7f},
378 {0xbf, 0x7f},
379 {0xc0, 0xe2},
380 {0xc1, 0xc0},
381 {0xc2, 0x01},
382 {0xc3, 0x4e},
383 {0xc6, 0x85},
384 {0xc7, 0x80}, /* com24 */
385 {0xc9, 0xe0},
386 {0xca, 0xe8},
387 {0xcb, 0xf0},
388 {0xcc, 0xd8},
389 {0xcd, 0xf1},
390 {0x4f, 0x98}, /* matrix */
391 {0x50, 0x98},
392 {0x51, 0x00},
393 {0x52, 0x28},
394 {0x53, 0x70},
395 {0x54, 0x98},
396 {0x58, 0x1a},
397 {0xff, 0x41}, /* read 41, write ff 00 */
398 {0x41, 0x40}, /* com16 */
399
400 {0xc5, 0x03}, /* 60 Hz banding filter */
401 {0x6a, 0x02}, /* 50 Hz banding filter */
402
403 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
404 {0x36, 0xfa}, /* aref3 */
405 {0x69, 0x0a}, /* hv */
406 {0x8c, 0x89}, /* com22 */
407 {0x14, 0x28}, /* com9 */
408 {0x3e, 0x0c},
409 {0x41, 0x40}, /* com16 */
410 {0x72, 0x00},
411 {0x73, 0x00},
412 {0x74, 0x3a},
413 {0x75, 0x35},
414 {0x76, 0x01},
415 {0xc7, 0x80},
416 {0x03, 0x12}, /* vref */
417 {0x17, 0x16}, /* hstart */
418 {0x18, 0x02}, /* hstop */
419 {0x19, 0x01}, /* vstrt */
420 {0x1a, 0x3d}, /* vstop */
421 {0x32, 0xff}, /* href */
422 {0xc0, 0xaa},
423};
424
425static const u8 bridge_init_2[][2] = {
426 {0x94, 0xaa},
427 {0xf1, 0x60},
428 {0xe5, 0x04},
429 {0xc0, 0x50},
430 {0xc1, 0x3c},
431 {0x8c, 0x00},
432 {0x8d, 0x1c},
433 {0x34, 0x05},
434
435 {0xc2, 0x0c},
436 {0xc3, 0xf9},
437 {0xda, 0x01},
438 {0x50, 0x00},
439 {0x51, 0xa0},
440 {0x52, 0x3c},
441 {0x53, 0x00},
442 {0x54, 0x00},
443 {0x55, 0x00},
444 {0x57, 0x00},
445 {0x5c, 0x00},
446 {0x5a, 0xa0},
447 {0x5b, 0x78},
448 {0x35, 0x02},
449 {0xd9, 0x10},
450 {0x94, 0x11},
451};
452
453static const u8 sensor_init_2[][2] = {
454 {0x3b, 0xc4},
455 {0x1e, 0x04}, /* mvfp */
456 {0x13, 0xe0}, /* com8 */
457 {0x00, 0x00}, /* gain */
458 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
459 {0x11, 0x03}, /* clkrc */
460 {0x6b, 0x5a}, /* dblv */
461 {0x6a, 0x05},
462 {0xc5, 0x07},
463 {0xa2, 0x4b},
464 {0xa3, 0x3e},
465 {0x2d, 0x00},
466 {0xff, 0x42}, /* read 42, write ff 00 */
467 {0x42, 0xc0}, /* com17 */
468 {0x2d, 0x00},
469 {0xff, 0x42}, /* read 42, write ff 00 */
470 {0x42, 0xc1}, /* com17 */
471/* sharpness */
472 {0x3f, 0x01},
473 {0xff, 0x42}, /* read 42, write ff 00 */
474 {0x42, 0xc1}, /* com17 */
475/* saturation */
476 {0x4f, 0x98}, /* matrix */
477 {0x50, 0x98},
478 {0x51, 0x00},
479 {0x52, 0x28},
480 {0x53, 0x70},
481 {0x54, 0x98},
482 {0x58, 0x1a},
483 {0xff, 0x41}, /* read 41, write ff 00 */
484 {0x41, 0x40}, /* com16 */
485/* contrast */
486 {0x56, 0x40},
487/* brightness */
488 {0x55, 0x8f},
489/* expo */
490 {0x10, 0x25}, /* aech - exposure high bits */
491 {0xff, 0x13}, /* read 13, write ff 00 */
492 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
493};
494
495static const u8 sensor_start_1_vga[][2] = { /* same for qvga */
496 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
497 {0x36, 0xfa}, /* aref3 */
498 {0x69, 0x0a}, /* hv */
499 {0x8c, 0x89}, /* com22 */
500 {0x14, 0x28}, /* com9 */
501 {0x3e, 0x0c}, /* com14 */
502 {0x41, 0x40}, /* com16 */
503 {0x72, 0x00},
504 {0x73, 0x00},
505 {0x74, 0x3a},
506 {0x75, 0x35},
507 {0x76, 0x01},
508 {0xc7, 0x80}, /* com24 */
509 {0x03, 0x12}, /* vref */
510 {0x17, 0x16}, /* hstart */
511 {0x18, 0x02}, /* hstop */
512 {0x19, 0x01}, /* vstrt */
513 {0x1a, 0x3d}, /* vstop */
514 {0x32, 0xff}, /* href */
515 {0xc0, 0xaa},
516};
517
518static const u8 sensor_start_1_svga[][2] = {
519 {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
520 {0x36, 0xf8}, /* aref3 */
521 {0x69, 0x02}, /* hv */
522 {0x8c, 0x0d}, /* com22 */
523 {0x3e, 0x0c}, /* com14 */
524 {0x41, 0x40}, /* com16 */
525 {0x72, 0x00},
526 {0x73, 0x01},
527 {0x74, 0x3a},
528 {0x75, 0x35},
529 {0x76, 0x01},
530 {0xc7, 0x80}, /* com24 */
531 {0x03, 0x1b}, /* vref */
532 {0x17, 0x1d}, /* hstart */
533 {0x18, 0xbd}, /* hstop */
534 {0x19, 0x01}, /* vstrt */
535 {0x1a, 0x81}, /* vstop */
536 {0x32, 0xff}, /* href */
537 {0xc0, 0xe2},
538};
539
540static const u8 sensor_start_1_xga[][2] = {
541 {0x12, 0x02}, /* com7 */
542 {0x36, 0xf8}, /* aref3 */
543 {0x69, 0x02}, /* hv */
544 {0x8c, 0x89}, /* com22 */
545 {0x14, 0x28}, /* com9 */
546 {0x3e, 0x0c}, /* com14 */
547 {0x41, 0x40}, /* com16 */
548 {0x72, 0x00},
549 {0x73, 0x01},
550 {0x74, 0x3a},
551 {0x75, 0x35},
552 {0x76, 0x01},
553 {0xc7, 0x80}, /* com24 */
554 {0x03, 0x1b}, /* vref */
555 {0x17, 0x1d}, /* hstart */
556 {0x18, 0xbd}, /* hstop */
557 {0x19, 0x01}, /* vstrt */
558 {0x1a, 0x81}, /* vstop */
559 {0x32, 0xff}, /* href */
560 {0xc0, 0xe2},
561};
562
563static const u8 sensor_start_1_sxga[][2] = {
564 {0x12, 0x02}, /* com7 */
565 {0x36, 0xf8}, /* aref3 */
566 {0x69, 0x02}, /* hv */
567 {0x8c, 0x89}, /* com22 */
568 {0x14, 0x28}, /* com9 */
569 {0x3e, 0x0c}, /* com14 */
570 {0x41, 0x40}, /* com16 */
571 {0x72, 0x00},
572 {0x73, 0x01},
573 {0x74, 0x3a},
574 {0x75, 0x35},
575 {0x76, 0x01},
576 {0xc7, 0x80}, /* com24 */
577 {0x03, 0x1b}, /* vref */
578 {0x17, 0x1d}, /* hstart */
579 {0x18, 0x02}, /* hstop */
580 {0x19, 0x01}, /* vstrt */
581 {0x1a, 0x81}, /* vstop */
582 {0x32, 0xff}, /* href */
583 {0xc0, 0xe2},
584};
585
586static const u8 bridge_start_qvga[][2] = {
587 {0x94, 0xaa},
588 {0xf1, 0x60},
589 {0xe5, 0x04},
590 {0xc0, 0x50},
591 {0xc1, 0x3c},
592 {0x8c, 0x00},
593 {0x8d, 0x1c},
594 {0x34, 0x05},
595
596 {0xc2, 0x4c},
597 {0xc3, 0xf9},
598 {0xda, 0x00},
599 {0x50, 0x00},
600 {0x51, 0xa0},
601 {0x52, 0x78},
602 {0x53, 0x00},
603 {0x54, 0x00},
604 {0x55, 0x00},
605 {0x57, 0x00},
606 {0x5c, 0x00},
607 {0x5a, 0x50},
608 {0x5b, 0x3c},
609 {0x35, 0x02},
610 {0xd9, 0x10},
611 {0x94, 0x11},
612};
613
614static const u8 bridge_start_vga[][2] = {
615 {0x94, 0xaa},
616 {0xf1, 0x60},
617 {0xe5, 0x04},
618 {0xc0, 0x50},
619 {0xc1, 0x3c},
620 {0x8c, 0x00},
621 {0x8d, 0x1c},
622 {0x34, 0x05},
623 {0xc2, 0x0c},
624 {0xc3, 0xf9},
625 {0xda, 0x01},
626 {0x50, 0x00},
627 {0x51, 0xa0},
628 {0x52, 0x3c},
629 {0x53, 0x00},
630 {0x54, 0x00},
631 {0x55, 0x00},
632 {0x57, 0x00},
633 {0x5c, 0x00},
634 {0x5a, 0xa0},
635 {0x5b, 0x78},
636 {0x35, 0x02},
637 {0xd9, 0x10},
638 {0x94, 0x11},
639};
640
641static const u8 bridge_start_svga[][2] = {
642 {0x94, 0xaa},
643 {0xf1, 0x60},
644 {0xe5, 0x04},
645 {0xc0, 0xa0},
646 {0xc1, 0x80},
647 {0x8c, 0x00},
648 {0x8d, 0x1c},
649 {0x34, 0x05},
650 {0xc2, 0x4c},
651 {0xc3, 0xf9},
652 {0x50, 0x00},
653 {0x51, 0x40},
654 {0x52, 0x00},
655 {0x53, 0x00},
656 {0x54, 0x00},
657 {0x55, 0x88},
658 {0x57, 0x00},
659 {0x5c, 0x00},
660 {0x5a, 0xc8},
661 {0x5b, 0x96},
662 {0x35, 0x02},
663 {0xd9, 0x10},
664 {0xda, 0x00},
665 {0x94, 0x11},
666};
667
668static const u8 bridge_start_xga[][2] = {
669 {0x94, 0xaa},
670 {0xf1, 0x60},
671 {0xe5, 0x04},
672 {0xc0, 0xa0},
673 {0xc1, 0x80},
674 {0x8c, 0x00},
675 {0x8d, 0x1c},
676 {0x34, 0x05},
677 {0xc2, 0x4c},
678 {0xc3, 0xf9},
679 {0x50, 0x00},
680 {0x51, 0x40},
681 {0x52, 0x00},
682 {0x53, 0x00},
683 {0x54, 0x00},
684 {0x55, 0x88},
685 {0x57, 0x00},
686 {0x5c, 0x01},
687 {0x5a, 0x00},
688 {0x5b, 0xc0},
689 {0x35, 0x02},
690 {0xd9, 0x10},
691 {0xda, 0x01},
692 {0x94, 0x11},
693};
694
695static const u8 bridge_start_sxga[][2] = {
696 {0x94, 0xaa},
697 {0xf1, 0x60},
698 {0xe5, 0x04},
699 {0xc0, 0xa0},
700 {0xc1, 0x80},
701 {0x8c, 0x00},
702 {0x8d, 0x1c},
703 {0x34, 0x05},
704 {0xc2, 0x0c},
705 {0xc3, 0xf9},
706 {0xda, 0x00},
707 {0x35, 0x02},
708 {0xd9, 0x10},
709 {0x94, 0x11},
710};
711
712static const u8 sensor_start_2_qvga[][2] = {
713 {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
714 {0x1e, 0x04}, /* mvfp */
715 {0x13, 0xe0}, /* com8 */
716 {0x00, 0x00},
717 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
718 {0x11, 0x01}, /* clkrc */
719 {0x6b, 0x5a}, /* dblv */
720 {0x6a, 0x02}, /* 50 Hz banding filter */
721 {0xc5, 0x03}, /* 60 Hz banding filter */
722 {0xa2, 0x96}, /* bd50 */
723 {0xa3, 0x7d}, /* bd60 */
724
725 {0xff, 0x13}, /* read 13, write ff 00 */
726 {0x13, 0xe7},
727 {0x3a, 0x80}, /* tslb - yuyv */
728};
729
730static const u8 sensor_start_2_vga[][2] = {
731 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
732 {0x1e, 0x04}, /* mvfp */
733 {0x13, 0xe0}, /* com8 */
734 {0x00, 0x00},
735 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
736 {0x11, 0x03}, /* clkrc */
737 {0x6b, 0x5a}, /* dblv */
738 {0x6a, 0x05}, /* 50 Hz banding filter */
739 {0xc5, 0x07}, /* 60 Hz banding filter */
740 {0xa2, 0x4b}, /* bd50 */
741 {0xa3, 0x3e}, /* bd60 */
742
743 {0x2d, 0x00}, /* advfl */
744};
745
746static const u8 sensor_start_2_svga[][2] = { /* same for xga */
747 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
748 {0x1e, 0x04}, /* mvfp */
749 {0x13, 0xe0}, /* com8 */
750 {0x00, 0x00},
751 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
752 {0x11, 0x01}, /* clkrc */
753 {0x6b, 0x5a}, /* dblv */
754 {0x6a, 0x0c}, /* 50 Hz banding filter */
755 {0xc5, 0x0f}, /* 60 Hz banding filter */
756 {0xa2, 0x4e}, /* bd50 */
757 {0xa3, 0x41}, /* bd60 */
758};
759
760static const u8 sensor_start_2_sxga[][2] = {
761 {0x13, 0xe0}, /* com8 */
762 {0x00, 0x00},
763 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
764 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
765 {0x1e, 0x04}, /* mvfp */
766 {0x11, 0x01}, /* clkrc */
767 {0x6b, 0x5a}, /* dblv */
768 {0x6a, 0x0c}, /* 50 Hz banding filter */
769 {0xc5, 0x0f}, /* 60 Hz banding filter */
770 {0xa2, 0x4e}, /* bd50 */
771 {0xa3, 0x41}, /* bd60 */
772};
773
774static void reg_w_i(struct gspca_dev *gspca_dev, u16 reg, u8 val)
775{
776 struct usb_device *udev = gspca_dev->dev;
777 int ret;
778
779 if (gspca_dev->usb_err < 0)
780 return;
781 gspca_dev->usb_buf[0] = val;
782 ret = usb_control_msg(udev,
783 usb_sndctrlpipe(udev, 0),
784 0x01,
785 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
786 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
787 if (ret < 0) {
788 PDEBUG(D_ERR, "reg_w failed %d", ret);
789 gspca_dev->usb_err = ret;
790 }
791}
792
793static void reg_w(struct gspca_dev *gspca_dev, u16 reg, u8 val)
794{
795 PDEBUG(D_USBO, "reg_w [%04x] = %02x", reg, val);
796 reg_w_i(gspca_dev, reg, val);
797}
798
799static u8 reg_r(struct gspca_dev *gspca_dev, u16 reg)
800{
801 struct usb_device *udev = gspca_dev->dev;
802 int ret;
803
804 if (gspca_dev->usb_err < 0)
805 return 0;
806 ret = usb_control_msg(udev,
807 usb_rcvctrlpipe(udev, 0),
808 0x01,
809 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
810 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
811 PDEBUG(D_USBI, "reg_r [%04x] -> %02x", reg, gspca_dev->usb_buf[0]);
812 if (ret < 0) {
813 PDEBUG(D_ERR, "reg_r err %d", ret);
814 gspca_dev->usb_err = ret;
815 }
816 return gspca_dev->usb_buf[0];
817}
818
819static int sccb_check_status(struct gspca_dev *gspca_dev)
820{
821 u8 data;
822 int i;
823
824 for (i = 0; i < 5; i++) {
825 data = reg_r(gspca_dev, OV534_REG_STATUS);
826
827 switch (data) {
828 case 0x00:
829 return 1;
830 case 0x04:
831 return 0;
832 case 0x03:
833 break;
834 default:
835 PDEBUG(D_USBI|D_USBO,
836 "sccb status 0x%02x, attempt %d/5",
837 data, i + 1);
838 }
839 }
840 return 0;
841}
842
843static void sccb_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
844{
845 PDEBUG(D_USBO, "sccb_write [%02x] = %02x", reg, val);
846 reg_w_i(gspca_dev, OV534_REG_SUBADDR, reg);
847 reg_w_i(gspca_dev, OV534_REG_WRITE, val);
848 reg_w_i(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
849
850 if (!sccb_check_status(gspca_dev))
851 PDEBUG(D_ERR, "sccb_write failed");
852}
853
854static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg)
855{
856 reg_w(gspca_dev, OV534_REG_SUBADDR, reg);
857 reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
858 if (!sccb_check_status(gspca_dev))
859 PDEBUG(D_ERR, "sccb_read failed 1");
860
861 reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
862 if (!sccb_check_status(gspca_dev))
863 PDEBUG(D_ERR, "sccb_read failed 2");
864
865 return reg_r(gspca_dev, OV534_REG_READ);
866}
867
868/* output a bridge sequence (reg - val) */
869static void reg_w_array(struct gspca_dev *gspca_dev,
870 const u8 (*data)[2], int len)
871{
872 while (--len >= 0) {
873 reg_w(gspca_dev, (*data)[0], (*data)[1]);
874 data++;
875 }
876}
877
878/* output a sensor sequence (reg - val) */
879static void sccb_w_array(struct gspca_dev *gspca_dev,
880 const u8 (*data)[2], int len)
881{
882 while (--len >= 0) {
883 if ((*data)[0] != 0xff) {
884 sccb_write(gspca_dev, (*data)[0], (*data)[1]);
885 } else {
886 sccb_read(gspca_dev, (*data)[1]);
887 sccb_write(gspca_dev, 0xff, 0x00);
888 }
889 data++;
890 }
891}
892
893/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
894 * (direction and output)? */
895static void set_led(struct gspca_dev *gspca_dev, int status)
896{
897 u8 data;
898
899 PDEBUG(D_CONF, "led status: %d", status);
900
901 data = reg_r(gspca_dev, 0x21);
902 data |= 0x80;
903 reg_w(gspca_dev, 0x21, data);
904
905 data = reg_r(gspca_dev, 0x23);
906 if (status)
907 data |= 0x80;
908 else
909 data &= ~0x80;
910
911 reg_w(gspca_dev, 0x23, data);
912
913 if (!status) {
914 data = reg_r(gspca_dev, 0x21);
915 data &= ~0x80;
916 reg_w(gspca_dev, 0x21, data);
917 }
918}
919
920static void setbrightness(struct gspca_dev *gspca_dev)
921{
922 struct sd *sd = (struct sd *) gspca_dev;
923 u8 val;
924
925 val = sd->brightness;
926 if (val < 8)
927 val = 15 - val; /* f .. 8 */
928 else
929 val = val - 8; /* 0 .. 7 */
930 sccb_write(gspca_dev, 0x55, /* brtn - brightness adjustment */
931 0x0f | (val << 4));
932}
933
934static void setcontrast(struct gspca_dev *gspca_dev)
935{
936 struct sd *sd = (struct sd *) gspca_dev;
937
938 sccb_write(gspca_dev, 0x56, /* cnst1 - contrast 1 ctrl coeff */
939 sd->contrast << 4);
940}
941
942static void setautogain(struct gspca_dev *gspca_dev)
943{
944 struct sd *sd = (struct sd *) gspca_dev;
945 u8 val;
946
947/*fixme: should adjust agc/awb/aec by different controls */
948 val = sd->autogain;
949 val = sccb_read(gspca_dev, 0x13); /* com8 */
950 sccb_write(gspca_dev, 0xff, 0x00);
951 if (sd->autogain)
952 val |= 0x05; /* agc & aec */
953 else
954 val &= 0xfa;
955 sccb_write(gspca_dev, 0x13, val);
956}
957
958static void setexposure(struct gspca_dev *gspca_dev)
959{
960 struct sd *sd = (struct sd *) gspca_dev;
961 u8 val;
962 static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
963
964 sccb_write(gspca_dev, 0x10, /* aec[9:2] */
965 expo[sd->exposure]);
966
967 val = sccb_read(gspca_dev, 0x13); /* com8 */
968 sccb_write(gspca_dev, 0xff, 0x00);
969 sccb_write(gspca_dev, 0x13, val);
970
971 val = sccb_read(gspca_dev, 0xa1); /* aech */
972 sccb_write(gspca_dev, 0xff, 0x00);
973 sccb_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */
974}
975
976static void setsharpness(struct gspca_dev *gspca_dev)
977{
978 struct sd *sd = (struct sd *) gspca_dev;
979 s8 val;
980
981 val = sd->sharpness;
982 if (val < 0) { /* auto */
983 val = sccb_read(gspca_dev, 0x42); /* com17 */
984 sccb_write(gspca_dev, 0xff, 0x00);
985 sccb_write(gspca_dev, 0x42, val | 0x40);
986 /* Edge enhancement strength auto adjust */
987 return;
988 }
989 if (val != 0)
990 val = 1 << (val - 1);
991 sccb_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */
992 val);
993 val = sccb_read(gspca_dev, 0x42); /* com17 */
994 sccb_write(gspca_dev, 0xff, 0x00);
995 sccb_write(gspca_dev, 0x42, val & 0xbf);
996}
997
998static void setsatur(struct gspca_dev *gspca_dev)
999{
1000 struct sd *sd = (struct sd *) gspca_dev;
1001 u8 val1, val2, val3;
1002 static const u8 matrix[5][2] = {
1003 {0x14, 0x38},
1004 {0x1e, 0x54},
1005 {0x28, 0x70},
1006 {0x32, 0x8c},
1007 {0x48, 0x90}
1008 };
1009
1010 val1 = matrix[sd->satur][0];
1011 val2 = matrix[sd->satur][1];
1012 val3 = val1 + val2;
1013 sccb_write(gspca_dev, 0x4f, val3); /* matrix coeff */
1014 sccb_write(gspca_dev, 0x50, val3);
1015 sccb_write(gspca_dev, 0x51, 0x00);
1016 sccb_write(gspca_dev, 0x52, val1);
1017 sccb_write(gspca_dev, 0x53, val2);
1018 sccb_write(gspca_dev, 0x54, val3);
1019 sccb_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */
1020
1021 val1 = sccb_read(gspca_dev, 0x41); /* com16 */
1022 sccb_write(gspca_dev, 0xff, 0x00);
1023 sccb_write(gspca_dev, 0x41, val1);
1024}
1025
1026static void setfreq(struct gspca_dev *gspca_dev)
1027{
1028 struct sd *sd = (struct sd *) gspca_dev;
1029 u8 val;
1030
1031 val = sccb_read(gspca_dev, 0x13); /* com8 */
1032 sccb_write(gspca_dev, 0xff, 0x00);
1033 if (sd->freq == 0) {
1034 sccb_write(gspca_dev, 0x13, val & 0xdf);
1035 return;
1036 }
1037 sccb_write(gspca_dev, 0x13, val | 0x20);
1038
1039 val = sccb_read(gspca_dev, 0x42); /* com17 */
1040 sccb_write(gspca_dev, 0xff, 0x00);
1041 if (sd->freq == 1)
1042 val |= 0x01;
1043 else
1044 val &= 0xfe;
1045 sccb_write(gspca_dev, 0x42, val);
1046}
1047
1048/* this function is called at probe time */
1049static int sd_config(struct gspca_dev *gspca_dev,
1050 const struct usb_device_id *id)
1051{
1052 struct sd *sd = (struct sd *) gspca_dev;
1053 struct cam *cam;
1054
1055 cam = &gspca_dev->cam;
1056
1057 cam->cam_mode = ov965x_mode;
1058 cam->nmodes = ARRAY_SIZE(ov965x_mode);
1059
1060 sd->brightness = BRIGHTNESS_DEF;
1061 sd->contrast = CONTRAST_DEF;
1062#if AUTOGAIN_DEF != 0
1063 sd->autogain = AUTOGAIN_DEF;
1064 gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
1065#endif
1066#if EXPO_DEF != 0
1067 sd->exposure = EXPO_DEF;
1068#endif
1069#if SHARPNESS_DEF != 0
1070 sd->sharpness = SHARPNESS_DEF;
1071#endif
1072 sd->satur = SATUR_DEF;
1073 sd->freq = FREQ_DEF;
1074
1075 return 0;
1076}
1077
1078/* this function is called at probe and resume time */
1079static int sd_init(struct gspca_dev *gspca_dev)
1080{
1081 u16 sensor_id;
1082
1083 /* reset bridge */
1084 reg_w(gspca_dev, 0xe7, 0x3a);
1085 reg_w(gspca_dev, 0xe0, 0x08);
1086 msleep(100);
1087
1088 /* initialize the sensor address */
1089 reg_w(gspca_dev, OV534_REG_ADDRESS, 0x60);
1090
1091 /* reset sensor */
1092 sccb_write(gspca_dev, 0x12, 0x80);
1093 msleep(10);
1094
1095 /* probe the sensor */
1096 sccb_read(gspca_dev, 0x0a);
1097 sensor_id = sccb_read(gspca_dev, 0x0a) << 8;
1098 sccb_read(gspca_dev, 0x0b);
1099 sensor_id |= sccb_read(gspca_dev, 0x0b);
1100 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
1101
1102 /* initialize */
1103 reg_w_array(gspca_dev, bridge_init,
1104 ARRAY_SIZE(bridge_init));
1105 sccb_w_array(gspca_dev, sensor_init,
1106 ARRAY_SIZE(sensor_init));
1107 reg_w_array(gspca_dev, bridge_init_2,
1108 ARRAY_SIZE(bridge_init_2));
1109 sccb_w_array(gspca_dev, sensor_init_2,
1110 ARRAY_SIZE(sensor_init_2));
1111 reg_w(gspca_dev, 0xe0, 0x00);
1112 reg_w(gspca_dev, 0xe0, 0x01);
1113 set_led(gspca_dev, 0);
1114 reg_w(gspca_dev, 0xe0, 0x00);
1115
1116 return gspca_dev->usb_err;
1117}
1118
1119static int sd_start(struct gspca_dev *gspca_dev)
1120{
1121 switch (gspca_dev->curr_mode) {
1122 case QVGA_MODE: /* 320x240 */
1123 sccb_w_array(gspca_dev, sensor_start_1_vga,
1124 ARRAY_SIZE(sensor_start_1_vga));
1125 reg_w_array(gspca_dev, bridge_start_qvga,
1126 ARRAY_SIZE(bridge_start_qvga));
1127 sccb_w_array(gspca_dev, sensor_start_2_qvga,
1128 ARRAY_SIZE(sensor_start_2_qvga));
1129 break;
1130 case VGA_MODE: /* 640x480 */
1131 sccb_w_array(gspca_dev, sensor_start_1_vga,
1132 ARRAY_SIZE(sensor_start_1_vga));
1133 reg_w_array(gspca_dev, bridge_start_vga,
1134 ARRAY_SIZE(bridge_start_vga));
1135 sccb_w_array(gspca_dev, sensor_start_2_vga,
1136 ARRAY_SIZE(sensor_start_2_vga));
1137 break;
1138 case SVGA_MODE: /* 800x600 */
1139 sccb_w_array(gspca_dev, sensor_start_1_svga,
1140 ARRAY_SIZE(sensor_start_1_svga));
1141 reg_w_array(gspca_dev, bridge_start_svga,
1142 ARRAY_SIZE(bridge_start_svga));
1143 sccb_w_array(gspca_dev, sensor_start_2_svga,
1144 ARRAY_SIZE(sensor_start_2_svga));
1145 break;
1146 case XGA_MODE: /* 1024x768 */
1147 sccb_w_array(gspca_dev, sensor_start_1_xga,
1148 ARRAY_SIZE(sensor_start_1_xga));
1149 reg_w_array(gspca_dev, bridge_start_xga,
1150 ARRAY_SIZE(bridge_start_xga));
1151 sccb_w_array(gspca_dev, sensor_start_2_svga,
1152 ARRAY_SIZE(sensor_start_2_svga));
1153 break;
1154 default:
1155/* case SXGA_MODE: * 1280x1024 */
1156 sccb_w_array(gspca_dev, sensor_start_1_sxga,
1157 ARRAY_SIZE(sensor_start_1_sxga));
1158 reg_w_array(gspca_dev, bridge_start_sxga,
1159 ARRAY_SIZE(bridge_start_sxga));
1160 sccb_w_array(gspca_dev, sensor_start_2_sxga,
1161 ARRAY_SIZE(sensor_start_2_sxga));
1162 break;
1163 }
1164 setfreq(gspca_dev);
1165 setautogain(gspca_dev);
1166 setbrightness(gspca_dev);
1167 setcontrast(gspca_dev);
1168 setexposure(gspca_dev);
1169 setsharpness(gspca_dev);
1170 setsatur(gspca_dev);
1171
1172 reg_w(gspca_dev, 0xe0, 0x00);
1173 reg_w(gspca_dev, 0xe0, 0x00);
1174 set_led(gspca_dev, 1);
1175 return gspca_dev->usb_err;
1176}
1177
1178static void sd_stopN(struct gspca_dev *gspca_dev)
1179{
1180 reg_w(gspca_dev, 0xe0, 0x01);
1181 set_led(gspca_dev, 0);
1182 reg_w(gspca_dev, 0xe0, 0x00);
1183}
1184
1185/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
1186#define UVC_STREAM_EOH (1 << 7)
1187#define UVC_STREAM_ERR (1 << 6)
1188#define UVC_STREAM_STI (1 << 5)
1189#define UVC_STREAM_RES (1 << 4)
1190#define UVC_STREAM_SCR (1 << 3)
1191#define UVC_STREAM_PTS (1 << 2)
1192#define UVC_STREAM_EOF (1 << 1)
1193#define UVC_STREAM_FID (1 << 0)
1194
1195static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1196 u8 *data, int len)
1197{
1198 struct sd *sd = (struct sd *) gspca_dev;
1199 __u32 this_pts;
1200 u8 this_fid;
1201 int remaining_len = len;
1202
1203 do {
1204 len = min(remaining_len, 2040);
1205
1206 /* Payloads are prefixed with a UVC-style header. We
1207 consider a frame to start when the FID toggles, or the PTS
1208 changes. A frame ends when EOF is set, and we've received
1209 the correct number of bytes. */
1210
1211 /* Verify UVC header. Header length is always 12 */
1212 if (data[0] != 12 || len < 12) {
1213 PDEBUG(D_PACK, "bad header");
1214 goto discard;
1215 }
1216
1217 /* Check errors */
1218 if (data[1] & UVC_STREAM_ERR) {
1219 PDEBUG(D_PACK, "payload error");
1220 goto discard;
1221 }
1222
1223 /* Extract PTS and FID */
1224 if (!(data[1] & UVC_STREAM_PTS)) {
1225 PDEBUG(D_PACK, "PTS not present");
1226 goto discard;
1227 }
1228 this_pts = (data[5] << 24) | (data[4] << 16)
1229 | (data[3] << 8) | data[2];
1230 this_fid = data[1] & UVC_STREAM_FID;
1231
1232 /* If PTS or FID has changed, start a new frame. */
1233 if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
1234 if (gspca_dev->last_packet_type == INTER_PACKET)
1235 gspca_frame_add(gspca_dev, LAST_PACKET,
1236 NULL, 0);
1237 sd->last_pts = this_pts;
1238 sd->last_fid = this_fid;
1239 gspca_frame_add(gspca_dev, FIRST_PACKET,
1240 data + 12, len - 12);
1241 /* If this packet is marked as EOF, end the frame */
1242 } else if (data[1] & UVC_STREAM_EOF) {
1243 sd->last_pts = 0;
1244 gspca_frame_add(gspca_dev, LAST_PACKET,
1245 data + 12, len - 12);
1246 } else {
1247
1248 /* Add the data from this payload */
1249 gspca_frame_add(gspca_dev, INTER_PACKET,
1250 data + 12, len - 12);
1251 }
1252
1253 /* Done this payload */
1254 goto scan_next;
1255
1256discard:
1257 /* Discard data until a new frame starts. */
1258 gspca_dev->last_packet_type = DISCARD_PACKET;
1259
1260scan_next:
1261 remaining_len -= len;
1262 data += len;
1263 } while (remaining_len > 0);
1264}
1265
1266/* controls */
1267static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1268{
1269 struct sd *sd = (struct sd *) gspca_dev;
1270
1271 sd->brightness = val;
1272 if (gspca_dev->streaming)
1273 setbrightness(gspca_dev);
1274 return gspca_dev->usb_err;
1275}
1276
1277static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1278{
1279 struct sd *sd = (struct sd *) gspca_dev;
1280
1281 *val = sd->brightness;
1282 return 0;
1283}
1284
1285static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1286{
1287 struct sd *sd = (struct sd *) gspca_dev;
1288
1289 sd->contrast = val;
1290 if (gspca_dev->streaming)
1291 setcontrast(gspca_dev);
1292 return gspca_dev->usb_err;
1293}
1294
1295static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1296{
1297 struct sd *sd = (struct sd *) gspca_dev;
1298
1299 *val = sd->contrast;
1300 return 0;
1301}
1302
1303static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
1304{
1305 struct sd *sd = (struct sd *) gspca_dev;
1306
1307 sd->autogain = val;
1308
1309 if (gspca_dev->streaming) {
1310 if (val)
1311 gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
1312 else
1313 gspca_dev->ctrl_inac &= ~(1 << EXPO_IDX);
1314 setautogain(gspca_dev);
1315 }
1316 return gspca_dev->usb_err;
1317}
1318
1319static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
1320{
1321 struct sd *sd = (struct sd *) gspca_dev;
1322
1323 *val = sd->autogain;
1324 return 0;
1325}
1326
1327static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1328{
1329 struct sd *sd = (struct sd *) gspca_dev;
1330
1331 sd->exposure = val;
1332 if (gspca_dev->streaming)
1333 setexposure(gspca_dev);
1334 return gspca_dev->usb_err;
1335}
1336
1337static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
1338{
1339 struct sd *sd = (struct sd *) gspca_dev;
1340
1341 *val = sd->exposure;
1342 return 0;
1343}
1344
1345static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
1346{
1347 struct sd *sd = (struct sd *) gspca_dev;
1348
1349 sd->sharpness = val;
1350 if (gspca_dev->streaming)
1351 setsharpness(gspca_dev);
1352 return gspca_dev->usb_err;
1353}
1354
1355static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
1356{
1357 struct sd *sd = (struct sd *) gspca_dev;
1358
1359 *val = sd->sharpness;
1360 return 0;
1361}
1362
1363static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val)
1364{
1365 struct sd *sd = (struct sd *) gspca_dev;
1366
1367 sd->satur = val;
1368 if (gspca_dev->streaming)
1369 setsatur(gspca_dev);
1370 return gspca_dev->usb_err;
1371}
1372
1373static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val)
1374{
1375 struct sd *sd = (struct sd *) gspca_dev;
1376
1377 *val = sd->satur;
1378 return 0;
1379}
1380static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
1381{
1382 struct sd *sd = (struct sd *) gspca_dev;
1383
1384 sd->freq = val;
1385 if (gspca_dev->streaming)
1386 setfreq(gspca_dev);
1387 return gspca_dev->usb_err;
1388}
1389
1390static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
1391{
1392 struct sd *sd = (struct sd *) gspca_dev;
1393
1394 *val = sd->freq;
1395 return 0;
1396}
1397
1398static int sd_querymenu(struct gspca_dev *gspca_dev,
1399 struct v4l2_querymenu *menu)
1400{
1401 switch (menu->id) {
1402 case V4L2_CID_POWER_LINE_FREQUENCY:
1403 switch (menu->index) {
1404 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1405 strcpy((char *) menu->name, "NoFliker");
1406 return 0;
1407 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1408 strcpy((char *) menu->name, "50 Hz");
1409 return 0;
1410 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
1411 strcpy((char *) menu->name, "60 Hz");
1412 return 0;
1413 }
1414 break;
1415 }
1416 return -EINVAL;
1417}
1418
1419/* sub-driver description */
1420static const struct sd_desc sd_desc = {
1421 .name = MODULE_NAME,
1422 .ctrls = sd_ctrls,
1423 .nctrls = ARRAY_SIZE(sd_ctrls),
1424 .config = sd_config,
1425 .init = sd_init,
1426 .start = sd_start,
1427 .stopN = sd_stopN,
1428 .pkt_scan = sd_pkt_scan,
1429 .querymenu = sd_querymenu,
1430};
1431
1432/* -- module initialisation -- */
1433static const __devinitdata struct usb_device_id device_table[] = {
1434 {USB_DEVICE(0x06f8, 0x3003)},
1435 {}
1436};
1437
1438MODULE_DEVICE_TABLE(usb, device_table);
1439
1440/* -- device connect -- */
1441static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
1442{
1443 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1444 THIS_MODULE);
1445}
1446
1447static struct usb_driver sd_driver = {
1448 .name = MODULE_NAME,
1449 .id_table = device_table,
1450 .probe = sd_probe,
1451 .disconnect = gspca_disconnect,
1452#ifdef CONFIG_PM
1453 .suspend = gspca_suspend,
1454 .resume = gspca_resume,
1455#endif
1456};
1457
1458/* -- module insert / remove -- */
1459static int __init sd_mod_init(void)
1460{
1461 int ret;
1462
1463 ret = usb_register(&sd_driver);
1464 if (ret < 0)
1465 return ret;
1466 PDEBUG(D_PROBE, "registered");
1467 return 0;
1468}
1469
1470static void __exit sd_mod_exit(void)
1471{
1472 usb_deregister(&sd_driver);
1473 PDEBUG(D_PROBE, "deregistered");
1474}
1475
1476module_init(sd_mod_init);
1477module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c
index 4706a823add0..0c87c3490b1e 100644
--- a/drivers/media/video/gspca/pac207.c
+++ b/drivers/media/video/gspca/pac207.c
@@ -25,6 +25,7 @@
25 25
26#define MODULE_NAME "pac207" 26#define MODULE_NAME "pac207"
27 27
28#include <linux/input.h>
28#include "gspca.h" 29#include "gspca.h"
29 30
30MODULE_AUTHOR("Hans de Goede <hdgoede@redhat.com>"); 31MODULE_AUTHOR("Hans de Goede <hdgoede@redhat.com>");
@@ -77,7 +78,7 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
77static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); 78static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
78static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); 79static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
79 80
80static struct ctrl sd_ctrls[] = { 81static const struct ctrl sd_ctrls[] = {
81#define SD_BRIGHTNESS 0 82#define SD_BRIGHTNESS 0
82 { 83 {
83 { 84 {
@@ -495,6 +496,25 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
495 return 0; 496 return 0;
496} 497}
497 498
499#ifdef CONFIG_INPUT
500static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
501 u8 *data, /* interrupt packet data */
502 int len) /* interrput packet length */
503{
504 int ret = -EINVAL;
505
506 if (len == 2 && data[0] == 0x5a && data[1] == 0x5a) {
507 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
508 input_sync(gspca_dev->input_dev);
509 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
510 input_sync(gspca_dev->input_dev);
511 ret = 0;
512 }
513
514 return ret;
515}
516#endif
517
498/* sub-driver description */ 518/* sub-driver description */
499static const struct sd_desc sd_desc = { 519static const struct sd_desc sd_desc = {
500 .name = MODULE_NAME, 520 .name = MODULE_NAME,
@@ -506,6 +526,9 @@ static const struct sd_desc sd_desc = {
506 .stopN = sd_stopN, 526 .stopN = sd_stopN,
507 .dq_callback = pac207_do_auto_gain, 527 .dq_callback = pac207_do_auto_gain,
508 .pkt_scan = sd_pkt_scan, 528 .pkt_scan = sd_pkt_scan,
529#ifdef CONFIG_INPUT
530 .int_pkt_scan = sd_int_pkt_scan,
531#endif
509}; 532};
510 533
511/* -- module initialisation -- */ 534/* -- module initialisation -- */
diff --git a/drivers/media/video/gspca/pac7302.c b/drivers/media/video/gspca/pac7302.c
index de0b66c4b56e..2a68220d1ada 100644
--- a/drivers/media/video/gspca/pac7302.c
+++ b/drivers/media/video/gspca/pac7302.c
@@ -4,7 +4,9 @@
4 * 4 *
5 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> 5 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
6 * 6 *
7 * Separated from Pixart PAC7311 library by Márton Németh <nm127@freemail.hu> 7 * Separated from Pixart PAC7311 library by Márton Németh
8 * Camera button input handling by Márton Németh <nm127@freemail.hu>
9 * Copyright (C) 2009-2010 Márton Németh <nm127@freemail.hu>
8 * 10 *
9 * 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
10 * 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
@@ -22,33 +24,26 @@
22 */ 24 */
23 25
24/* Some documentation about various registers as determined by trial and error. 26/* Some documentation about various registers as determined by trial and error.
25 When the register addresses differ between the 7202 and the 7311 the 2
26 different addresses are written as 7302addr/7311addr, when one of the 2
27 addresses is a - sign that register description is not valid for the
28 matching IC.
29 27
30 Register page 1: 28 Register page 1:
31 29
32 Address Description 30 Address Description
33 -/0x08 Unknown compressor related, must always be 8 except when not
34 in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 !
35 -/0x1b Auto white balance related, bit 0 is AWB enable (inverted)
36 bits 345 seem to toggle per color gains on/off (inverted)
37 0x78 Global control, bit 6 controls the LED (inverted) 31 0x78 Global control, bit 6 controls the LED (inverted)
38 -/0x80 JPEG compression ratio ? Best not touched
39 32
40 Register page 3/4: 33 Register page 3:
41 34
42 Address Description 35 Address Description
43 0x02 Clock divider 2-63, fps =~ 60 / val. Must be a multiple of 3 on 36 0x02 Clock divider 3-63, fps = 90 / val. Must be a multiple of 3 on
44 the 7302, so one of 3, 6, 9, ..., except when between 6 and 12? 37 the 7302, so one of 3, 6, 9, ..., except when between 6 and 12?
45 -/0x0f Master gain 1-245, low value = high gain 38 0x03 Variable framerate ctrl reg2==3: 0 -> ~30 fps, 255 -> ~22fps
46 0x10/- Master gain 0-31 39 0x04 Another var framerate ctrl reg2==3, reg3==0: 0 -> ~30 fps,
47 -/0x10 Another gain 0-15, limited influence (1-2x gain I guess) 40 63 -> ~27 fps, the 2 msb's must always be 1 !!
41 0x05 Another var framerate ctrl reg2==3, reg3==0, reg4==0xc0:
42 1 -> ~30 fps, 2 -> ~20 fps
43 0x0e Exposure bits 0-7, 0-448, 0 = use full frame time
44 0x0f Exposure bit 8, 0-448, 448 = no exposure at all
45 0x10 Master gain 0-31
48 0x21 Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused 46 0x21 Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused
49 -/0x27 Seems to toggle various gains on / off, Setting bit 7 seems to
50 completely disable the analog amplification block. Set to 0x68
51 for max gain, 0x14 for minimal gain.
52 47
53 The registers are accessed in the following functions: 48 The registers are accessed in the following functions:
54 49
@@ -68,6 +63,7 @@
68 63
69#define MODULE_NAME "pac7302" 64#define MODULE_NAME "pac7302"
70 65
66#include <linux/input.h>
71#include <media/v4l2-chip-ident.h> 67#include <media/v4l2-chip-ident.h>
72#include "gspca.h" 68#include "gspca.h"
73 69
@@ -86,8 +82,8 @@ struct sd {
86 unsigned char red_balance; 82 unsigned char red_balance;
87 unsigned char blue_balance; 83 unsigned char blue_balance;
88 unsigned char gain; 84 unsigned char gain;
89 unsigned char exposure;
90 unsigned char autogain; 85 unsigned char autogain;
86 unsigned short exposure;
91 __u8 hflip; 87 __u8 hflip;
92 __u8 vflip; 88 __u8 vflip;
93 u8 flags; 89 u8 flags;
@@ -124,8 +120,7 @@ static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
124static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); 120static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
125static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); 121static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
126 122
127static struct ctrl sd_ctrls[] = { 123static const struct ctrl sd_ctrls[] = {
128/* This control is pac7302 only */
129 { 124 {
130 { 125 {
131 .id = V4L2_CID_BRIGHTNESS, 126 .id = V4L2_CID_BRIGHTNESS,
@@ -141,7 +136,6 @@ static struct ctrl sd_ctrls[] = {
141 .set = sd_setbrightness, 136 .set = sd_setbrightness,
142 .get = sd_getbrightness, 137 .get = sd_getbrightness,
143 }, 138 },
144/* This control is for both the 7302 and the 7311 */
145 { 139 {
146 { 140 {
147 .id = V4L2_CID_CONTRAST, 141 .id = V4L2_CID_CONTRAST,
@@ -157,7 +151,6 @@ static struct ctrl sd_ctrls[] = {
157 .set = sd_setcontrast, 151 .set = sd_setcontrast,
158 .get = sd_getcontrast, 152 .get = sd_getcontrast,
159 }, 153 },
160/* This control is pac7302 only */
161 { 154 {
162 { 155 {
163 .id = V4L2_CID_SATURATION, 156 .id = V4L2_CID_SATURATION,
@@ -215,7 +208,6 @@ static struct ctrl sd_ctrls[] = {
215 .set = sd_setbluebalance, 208 .set = sd_setbluebalance,
216 .get = sd_getbluebalance, 209 .get = sd_getbluebalance,
217 }, 210 },
218/* All controls below are for both the 7302 and the 7311 */
219 { 211 {
220 { 212 {
221 .id = V4L2_CID_GAIN, 213 .id = V4L2_CID_GAIN,
@@ -238,11 +230,10 @@ static struct ctrl sd_ctrls[] = {
238 .type = V4L2_CTRL_TYPE_INTEGER, 230 .type = V4L2_CTRL_TYPE_INTEGER,
239 .name = "Exposure", 231 .name = "Exposure",
240 .minimum = 0, 232 .minimum = 0,
241#define EXPOSURE_MAX 255 233 .maximum = 1023,
242 .maximum = EXPOSURE_MAX,
243 .step = 1, 234 .step = 1,
244#define EXPOSURE_DEF 16 /* 32 ms / 30 fps */ 235#define EXPOSURE_DEF 66 /* 33 ms / 30 fps */
245#define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */ 236#define EXPOSURE_KNEE 133 /* 66 ms / 15 fps */
246 .default_value = EXPOSURE_DEF, 237 .default_value = EXPOSURE_DEF,
247 }, 238 },
248 .set = sd_setexposure, 239 .set = sd_setexposure,
@@ -301,7 +292,6 @@ static const struct v4l2_pix_format vga_mode[] = {
301}; 292};
302 293
303#define LOAD_PAGE3 255 294#define LOAD_PAGE3 255
304#define LOAD_PAGE4 254
305#define END_OF_SEQUENCE 0 295#define END_OF_SEQUENCE 0
306 296
307/* pac 7302 */ 297/* pac 7302 */
@@ -379,7 +369,7 @@ static const __u8 start_7302[] = {
379#define SKIP 0xaa 369#define SKIP 0xaa
380/* page 3 - the value SKIP says skip the index - see reg_w_page() */ 370/* page 3 - the value SKIP says skip the index - see reg_w_page() */
381static const __u8 page3_7302[] = { 371static const __u8 page3_7302[] = {
382 0x90, 0x40, 0x03, 0x50, 0xc2, 0x01, 0x14, 0x16, 372 0x90, 0x40, 0x03, 0x00, 0xc0, 0x01, 0x14, 0x16,
383 0x14, 0x12, 0x00, 0x00, 0x00, 0x02, 0x33, 0x00, 373 0x14, 0x12, 0x00, 0x00, 0x00, 0x02, 0x33, 0x00,
384 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 374 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
385 0x00, 0x00, 0x00, 0x47, 0x01, 0xb3, 0x01, 0x00, 375 0x00, 0x00, 0x00, 0x47, 0x01, 0xb3, 0x01, 0x00,
@@ -388,7 +378,7 @@ static const __u8 page3_7302[] = {
388 0xa4, 0xb8, 0xe0, 0x2a, 0xf6, 0x00, 0x00, 0x00, 378 0xa4, 0xb8, 0xe0, 0x2a, 0xf6, 0x00, 0x00, 0x00,
389 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 379 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
390 0x00, 0xfc, 0x00, 0xf2, 0x1f, 0x04, 0x00, 0x00, 380 0x00, 0xfc, 0x00, 0xf2, 0x1f, 0x04, 0x00, 0x00,
391 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x10, 0x00, 0x00, 381 SKIP, 0x00, 0x00, 0xc0, 0xc0, 0x10, 0x00, 0x00,
392 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 382 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
393 0x00, 0x40, 0xff, 0x03, 0x19, 0x00, 0x00, 0x00, 383 0x00, 0x40, 0xff, 0x03, 0x19, 0x00, 0x00, 0x00,
394 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 384 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -401,12 +391,14 @@ static const __u8 page3_7302[] = {
401 0x00 391 0x00
402}; 392};
403 393
404static int reg_w_buf(struct gspca_dev *gspca_dev, 394static void reg_w_buf(struct gspca_dev *gspca_dev,
405 __u8 index, 395 __u8 index,
406 const char *buffer, int len) 396 const char *buffer, int len)
407{ 397{
408 int ret; 398 int ret;
409 399
400 if (gspca_dev->usb_err < 0)
401 return;
410 memcpy(gspca_dev->usb_buf, buffer, len); 402 memcpy(gspca_dev->usb_buf, buffer, len);
411 ret = usb_control_msg(gspca_dev->dev, 403 ret = usb_control_msg(gspca_dev->dev,
412 usb_sndctrlpipe(gspca_dev->dev, 0), 404 usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -415,20 +407,23 @@ static int reg_w_buf(struct gspca_dev *gspca_dev,
415 0, /* value */ 407 0, /* value */
416 index, gspca_dev->usb_buf, len, 408 index, gspca_dev->usb_buf, len,
417 500); 409 500);
418 if (ret < 0) 410 if (ret < 0) {
419 PDEBUG(D_ERR, "reg_w_buf(): " 411 PDEBUG(D_ERR, "reg_w_buf(): "
420 "Failed to write registers to index 0x%x, error %i", 412 "Failed to write registers to index 0x%x, error %i",
421 index, ret); 413 index, ret);
422 return ret; 414 gspca_dev->usb_err = ret;
415 }
423} 416}
424 417
425 418
426static int reg_w(struct gspca_dev *gspca_dev, 419static void reg_w(struct gspca_dev *gspca_dev,
427 __u8 index, 420 __u8 index,
428 __u8 value) 421 __u8 value)
429{ 422{
430 int ret; 423 int ret;
431 424
425 if (gspca_dev->usb_err < 0)
426 return;
432 gspca_dev->usb_buf[0] = value; 427 gspca_dev->usb_buf[0] = value;
433 ret = usb_control_msg(gspca_dev->dev, 428 ret = usb_control_msg(gspca_dev->dev,
434 usb_sndctrlpipe(gspca_dev->dev, 0), 429 usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -436,32 +431,32 @@ static int reg_w(struct gspca_dev *gspca_dev,
436 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 431 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
437 0, index, gspca_dev->usb_buf, 1, 432 0, index, gspca_dev->usb_buf, 1,
438 500); 433 500);
439 if (ret < 0) 434 if (ret < 0) {
440 PDEBUG(D_ERR, "reg_w(): " 435 PDEBUG(D_ERR, "reg_w(): "
441 "Failed to write register to index 0x%x, value 0x%x, error %i", 436 "Failed to write register to index 0x%x, value 0x%x, error %i",
442 index, value, ret); 437 index, value, ret);
443 return ret; 438 gspca_dev->usb_err = ret;
439 }
444} 440}
445 441
446static int reg_w_seq(struct gspca_dev *gspca_dev, 442static void reg_w_seq(struct gspca_dev *gspca_dev,
447 const __u8 *seq, int len) 443 const __u8 *seq, int len)
448{ 444{
449 int ret = 0;
450 while (--len >= 0) { 445 while (--len >= 0) {
451 if (0 <= ret) 446 reg_w(gspca_dev, seq[0], seq[1]);
452 ret = reg_w(gspca_dev, seq[0], seq[1]);
453 seq += 2; 447 seq += 2;
454 } 448 }
455 return ret;
456} 449}
457 450
458/* load the beginning of a page */ 451/* load the beginning of a page */
459static int reg_w_page(struct gspca_dev *gspca_dev, 452static void reg_w_page(struct gspca_dev *gspca_dev,
460 const __u8 *page, int len) 453 const __u8 *page, int len)
461{ 454{
462 int index; 455 int index;
463 int ret = 0; 456 int ret = 0;
464 457
458 if (gspca_dev->usb_err < 0)
459 return;
465 for (index = 0; index < len; index++) { 460 for (index = 0; index < len; index++) {
466 if (page[index] == SKIP) /* skip this index */ 461 if (page[index] == SKIP) /* skip this index */
467 continue; 462 continue;
@@ -477,56 +472,47 @@ static int reg_w_page(struct gspca_dev *gspca_dev,
477 "Failed to write register to index 0x%x, " 472 "Failed to write register to index 0x%x, "
478 "value 0x%x, error %i", 473 "value 0x%x, error %i",
479 index, page[index], ret); 474 index, page[index], ret);
475 gspca_dev->usb_err = ret;
480 break; 476 break;
481 } 477 }
482 } 478 }
483 return ret;
484} 479}
485 480
486/* output a variable sequence */ 481/* output a variable sequence */
487static int reg_w_var(struct gspca_dev *gspca_dev, 482static void reg_w_var(struct gspca_dev *gspca_dev,
488 const __u8 *seq, 483 const __u8 *seq,
489 const __u8 *page3, unsigned int page3_len, 484 const __u8 *page3, unsigned int page3_len)
490 const __u8 *page4, unsigned int page4_len)
491{ 485{
492 int index, len; 486 int index, len;
493 int ret = 0;
494 487
495 for (;;) { 488 for (;;) {
496 index = *seq++; 489 index = *seq++;
497 len = *seq++; 490 len = *seq++;
498 switch (len) { 491 switch (len) {
499 case END_OF_SEQUENCE: 492 case END_OF_SEQUENCE:
500 return ret; 493 return;
501 case LOAD_PAGE4:
502 ret = reg_w_page(gspca_dev, page4, page4_len);
503 break;
504 case LOAD_PAGE3: 494 case LOAD_PAGE3:
505 ret = reg_w_page(gspca_dev, page3, page3_len); 495 reg_w_page(gspca_dev, page3, page3_len);
506 break; 496 break;
507 default: 497 default:
508 if (len > USB_BUF_SZ) { 498 if (len > USB_BUF_SZ) {
509 PDEBUG(D_ERR|D_STREAM, 499 PDEBUG(D_ERR|D_STREAM,
510 "Incorrect variable sequence"); 500 "Incorrect variable sequence");
511 return -EINVAL; 501 return;
512 } 502 }
513 while (len > 0) { 503 while (len > 0) {
514 if (len < 8) { 504 if (len < 8) {
515 ret = reg_w_buf(gspca_dev, 505 reg_w_buf(gspca_dev,
516 index, seq, len); 506 index, seq, len);
517 if (ret < 0)
518 return ret;
519 seq += len; 507 seq += len;
520 break; 508 break;
521 } 509 }
522 ret = reg_w_buf(gspca_dev, index, seq, 8); 510 reg_w_buf(gspca_dev, index, seq, 8);
523 seq += 8; 511 seq += 8;
524 index += 8; 512 index += 8;
525 len -= 8; 513 len -= 8;
526 } 514 }
527 } 515 }
528 if (ret < 0)
529 return ret;
530 } 516 }
531 /* not reached */ 517 /* not reached */
532} 518}
@@ -560,11 +546,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
560} 546}
561 547
562/* This function is used by pac7302 only */ 548/* This function is used by pac7302 only */
563static int setbrightcont(struct gspca_dev *gspca_dev) 549static void setbrightcont(struct gspca_dev *gspca_dev)
564{ 550{
565 struct sd *sd = (struct sd *) gspca_dev; 551 struct sd *sd = (struct sd *) gspca_dev;
566 int i, v; 552 int i, v;
567 int ret;
568 static const __u8 max[10] = 553 static const __u8 max[10] =
569 {0x29, 0x33, 0x42, 0x5a, 0x6e, 0x80, 0x9f, 0xbb, 554 {0x29, 0x33, 0x42, 0x5a, 0x6e, 0x80, 0x9f, 0xbb,
570 0xd4, 0xec}; 555 0xd4, 0xec};
@@ -572,7 +557,7 @@ static int setbrightcont(struct gspca_dev *gspca_dev)
572 {0x35, 0x33, 0x33, 0x2f, 0x2a, 0x25, 0x1e, 0x17, 557 {0x35, 0x33, 0x33, 0x2f, 0x2a, 0x25, 0x1e, 0x17,
573 0x11, 0x0b}; 558 0x11, 0x0b};
574 559
575 ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ 560 reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
576 for (i = 0; i < 10; i++) { 561 for (i = 0; i < 10; i++) {
577 v = max[i]; 562 v = max[i];
578 v += (sd->brightness - BRIGHTNESS_MAX) 563 v += (sd->brightness - BRIGHTNESS_MAX)
@@ -582,136 +567,121 @@ static int setbrightcont(struct gspca_dev *gspca_dev)
582 v = 0; 567 v = 0;
583 else if (v > 0xff) 568 else if (v > 0xff)
584 v = 0xff; 569 v = 0xff;
585 if (0 <= ret) 570 reg_w(gspca_dev, 0xa2 + i, v);
586 ret = reg_w(gspca_dev, 0xa2 + i, v);
587 } 571 }
588 if (0 <= ret) 572 reg_w(gspca_dev, 0xdc, 0x01);
589 ret = reg_w(gspca_dev, 0xdc, 0x01);
590 return ret;
591} 573}
592 574
593/* This function is used by pac7302 only */ 575/* This function is used by pac7302 only */
594static int setcolors(struct gspca_dev *gspca_dev) 576static void setcolors(struct gspca_dev *gspca_dev)
595{ 577{
596 struct sd *sd = (struct sd *) gspca_dev; 578 struct sd *sd = (struct sd *) gspca_dev;
597 int i, v; 579 int i, v;
598 int ret;
599 static const int a[9] = 580 static const int a[9] =
600 {217, -212, 0, -101, 170, -67, -38, -315, 355}; 581 {217, -212, 0, -101, 170, -67, -38, -315, 355};
601 static const int b[9] = 582 static const int b[9] =
602 {19, 106, 0, 19, 106, 1, 19, 106, 1}; 583 {19, 106, 0, 19, 106, 1, 19, 106, 1};
603 584
604 ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ 585 reg_w(gspca_dev, 0xff, 0x03); /* page 3 */
605 if (0 <= ret) 586 reg_w(gspca_dev, 0x11, 0x01);
606 ret = reg_w(gspca_dev, 0x11, 0x01); 587 reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
607 if (0 <= ret)
608 ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
609 for (i = 0; i < 9; i++) { 588 for (i = 0; i < 9; i++) {
610 v = a[i] * sd->colors / COLOR_MAX + b[i]; 589 v = a[i] * sd->colors / COLOR_MAX + b[i];
611 if (0 <= ret) 590 reg_w(gspca_dev, 0x0f + 2 * i, (v >> 8) & 0x07);
612 ret = reg_w(gspca_dev, 0x0f + 2 * i, (v >> 8) & 0x07); 591 reg_w(gspca_dev, 0x0f + 2 * i + 1, v);
613 if (0 <= ret)
614 ret = reg_w(gspca_dev, 0x0f + 2 * i + 1, v);
615 } 592 }
616 if (0 <= ret) 593 reg_w(gspca_dev, 0xdc, 0x01);
617 ret = reg_w(gspca_dev, 0xdc, 0x01);
618 PDEBUG(D_CONF|D_STREAM, "color: %i", sd->colors); 594 PDEBUG(D_CONF|D_STREAM, "color: %i", sd->colors);
619 return ret;
620} 595}
621 596
622static int setwhitebalance(struct gspca_dev *gspca_dev) 597static void setwhitebalance(struct gspca_dev *gspca_dev)
623{ 598{
624 struct sd *sd = (struct sd *) gspca_dev; 599 struct sd *sd = (struct sd *) gspca_dev;
625 int ret;
626 600
627 ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ 601 reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
628 if (0 <= ret) 602 reg_w(gspca_dev, 0xc6, sd->white_balance);
629 ret = reg_w(gspca_dev, 0xc6, sd->white_balance);
630 603
631 if (0 <= ret) 604 reg_w(gspca_dev, 0xdc, 0x01);
632 ret = reg_w(gspca_dev, 0xdc, 0x01);
633 PDEBUG(D_CONF|D_STREAM, "white_balance: %i", sd->white_balance); 605 PDEBUG(D_CONF|D_STREAM, "white_balance: %i", sd->white_balance);
634 return ret;
635} 606}
636 607
637static int setredbalance(struct gspca_dev *gspca_dev) 608static void setredbalance(struct gspca_dev *gspca_dev)
638{ 609{
639 struct sd *sd = (struct sd *) gspca_dev; 610 struct sd *sd = (struct sd *) gspca_dev;
640 int ret;
641 611
642 ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ 612 reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
643 if (0 <= ret) 613 reg_w(gspca_dev, 0xc5, sd->red_balance);
644 ret = reg_w(gspca_dev, 0xc5, sd->red_balance);
645 614
646 if (0 <= ret) 615 reg_w(gspca_dev, 0xdc, 0x01);
647 ret = reg_w(gspca_dev, 0xdc, 0x01);
648 PDEBUG(D_CONF|D_STREAM, "red_balance: %i", sd->red_balance); 616 PDEBUG(D_CONF|D_STREAM, "red_balance: %i", sd->red_balance);
649 return ret;
650} 617}
651 618
652static int setbluebalance(struct gspca_dev *gspca_dev) 619static void setbluebalance(struct gspca_dev *gspca_dev)
653{ 620{
654 struct sd *sd = (struct sd *) gspca_dev; 621 struct sd *sd = (struct sd *) gspca_dev;
655 int ret;
656 622
657 ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ 623 reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
658 if (0 <= ret) 624 reg_w(gspca_dev, 0xc7, sd->blue_balance);
659 ret = reg_w(gspca_dev, 0xc7, sd->blue_balance);
660 625
661 if (0 <= ret) 626 reg_w(gspca_dev, 0xdc, 0x01);
662 ret = reg_w(gspca_dev, 0xdc, 0x01);
663 PDEBUG(D_CONF|D_STREAM, "blue_balance: %i", sd->blue_balance); 627 PDEBUG(D_CONF|D_STREAM, "blue_balance: %i", sd->blue_balance);
664 return ret;
665} 628}
666 629
667static int setgain(struct gspca_dev *gspca_dev) 630static void setgain(struct gspca_dev *gspca_dev)
668{ 631{
669 struct sd *sd = (struct sd *) gspca_dev; 632 struct sd *sd = (struct sd *) gspca_dev;
670 int ret;
671 633
672 ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ 634 reg_w(gspca_dev, 0xff, 0x03); /* page 3 */
673 if (0 <= ret) 635 reg_w(gspca_dev, 0x10, sd->gain >> 3);
674 ret = reg_w(gspca_dev, 0x10, sd->gain >> 3);
675 636
676 /* load registers to sensor (Bit 0, auto clear) */ 637 /* load registers to sensor (Bit 0, auto clear) */
677 if (0 <= ret) 638 reg_w(gspca_dev, 0x11, 0x01);
678 ret = reg_w(gspca_dev, 0x11, 0x01);
679 return ret;
680} 639}
681 640
682static int setexposure(struct gspca_dev *gspca_dev) 641static void setexposure(struct gspca_dev *gspca_dev)
683{ 642{
684 struct sd *sd = (struct sd *) gspca_dev; 643 struct sd *sd = (struct sd *) gspca_dev;
685 int ret; 644 __u8 clockdiv;
686 __u8 reg; 645 __u16 exposure;
687 646
688 /* register 2 of frame 3/4 contains the clock divider configuring the 647 /* register 2 of frame 3 contains the clock divider configuring the
689 no fps according to the formula: 60 / reg. sd->exposure is the 648 no fps according to the formula: 90 / reg. sd->exposure is the
690 desired exposure time in ms. */ 649 desired exposure time in 0.5 ms. */
691 reg = 120 * sd->exposure / 1000; 650 clockdiv = (90 * sd->exposure + 1999) / 2000;
692 if (reg < 2) 651
693 reg = 2; 652 /* Note clockdiv = 3 also works, but when running at 30 fps, depending
694 else if (reg > 63) 653 on the scene being recorded, the camera switches to another
695 reg = 63; 654 quantization table for certain JPEG blocks, and we don't know how
696 655 to decompress these blocks. So we cap the framerate at 15 fps */
697 /* On the pac7302 reg2 MUST be a multiple of 3, so round it to 656 if (clockdiv < 6)
698 the nearest multiple of 3, except when between 6 and 12? */ 657 clockdiv = 6;
699 if (reg < 6 || reg > 12) 658 else if (clockdiv > 63)
700 reg = ((reg + 1) / 3) * 3; 659 clockdiv = 63;
701 ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ 660
702 if (0 <= ret) 661 /* reg2 MUST be a multiple of 3, except when between 6 and 12?
703 ret = reg_w(gspca_dev, 0x02, reg); 662 Always round up, otherwise we cannot get the desired frametime
663 using the partial frame time exposure control */
664 if (clockdiv < 6 || clockdiv > 12)
665 clockdiv = ((clockdiv + 2) / 3) * 3;
666
667 /* frame exposure time in ms = 1000 * clockdiv / 90 ->
668 exposure = (sd->exposure / 2) * 448 / (1000 * clockdiv / 90) */
669 exposure = (sd->exposure * 45 * 448) / (1000 * clockdiv);
670 /* 0 = use full frametime, 448 = no exposure, reverse it */
671 exposure = 448 - exposure;
672
673 reg_w(gspca_dev, 0xff, 0x03); /* page 3 */
674 reg_w(gspca_dev, 0x02, clockdiv);
675 reg_w(gspca_dev, 0x0e, exposure & 0xff);
676 reg_w(gspca_dev, 0x0f, exposure >> 8);
704 677
705 /* load registers to sensor (Bit 0, auto clear) */ 678 /* load registers to sensor (Bit 0, auto clear) */
706 if (0 <= ret) 679 reg_w(gspca_dev, 0x11, 0x01);
707 ret = reg_w(gspca_dev, 0x11, 0x01);
708 return ret;
709} 680}
710 681
711static int sethvflip(struct gspca_dev *gspca_dev) 682static void sethvflip(struct gspca_dev *gspca_dev)
712{ 683{
713 struct sd *sd = (struct sd *) gspca_dev; 684 struct sd *sd = (struct sd *) gspca_dev;
714 int ret;
715 u8 data, hflip, vflip; 685 u8 data, hflip, vflip;
716 686
717 hflip = sd->hflip; 687 hflip = sd->hflip;
@@ -721,48 +691,37 @@ static int sethvflip(struct gspca_dev *gspca_dev)
721 if (sd->flags & FL_VFLIP) 691 if (sd->flags & FL_VFLIP)
722 vflip = !vflip; 692 vflip = !vflip;
723 693
724 ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ 694 reg_w(gspca_dev, 0xff, 0x03); /* page 3 */
725 data = (hflip ? 0x08 : 0x00) | (vflip ? 0x04 : 0x00); 695 data = (hflip ? 0x08 : 0x00) | (vflip ? 0x04 : 0x00);
726 if (0 <= ret) 696 reg_w(gspca_dev, 0x21, data);
727 ret = reg_w(gspca_dev, 0x21, data); 697
728 /* load registers to sensor (Bit 0, auto clear) */ 698 /* load registers to sensor (Bit 0, auto clear) */
729 if (0 <= ret) 699 reg_w(gspca_dev, 0x11, 0x01);
730 ret = reg_w(gspca_dev, 0x11, 0x01);
731 return ret;
732} 700}
733 701
734/* this function is called at probe and resume time for pac7302 */ 702/* this function is called at probe and resume time for pac7302 */
735static int sd_init(struct gspca_dev *gspca_dev) 703static int sd_init(struct gspca_dev *gspca_dev)
736{ 704{
737 return reg_w_seq(gspca_dev, init_7302, sizeof(init_7302)/2); 705 reg_w_seq(gspca_dev, init_7302, sizeof(init_7302)/2);
706 return gspca_dev->usb_err;
738} 707}
739 708
740static int sd_start(struct gspca_dev *gspca_dev) 709static int sd_start(struct gspca_dev *gspca_dev)
741{ 710{
742 struct sd *sd = (struct sd *) gspca_dev; 711 struct sd *sd = (struct sd *) gspca_dev;
743 int ret = 0;
744 712
745 sd->sof_read = 0; 713 sd->sof_read = 0;
746 714
747 ret = reg_w_var(gspca_dev, start_7302, 715 reg_w_var(gspca_dev, start_7302,
748 page3_7302, sizeof(page3_7302), 716 page3_7302, sizeof(page3_7302));
749 NULL, 0); 717 setbrightcont(gspca_dev);
750 if (0 <= ret) 718 setcolors(gspca_dev);
751 ret = setbrightcont(gspca_dev); 719 setwhitebalance(gspca_dev);
752 if (0 <= ret) 720 setredbalance(gspca_dev);
753 ret = setcolors(gspca_dev); 721 setbluebalance(gspca_dev);
754 if (0 <= ret) 722 setgain(gspca_dev);
755 ret = setwhitebalance(gspca_dev); 723 setexposure(gspca_dev);
756 if (0 <= ret) 724 sethvflip(gspca_dev);
757 ret = setredbalance(gspca_dev);
758 if (0 <= ret)
759 ret = setbluebalance(gspca_dev);
760 if (0 <= ret)
761 ret = setgain(gspca_dev);
762 if (0 <= ret)
763 ret = setexposure(gspca_dev);
764 if (0 <= ret)
765 ret = sethvflip(gspca_dev);
766 725
767 /* only resolution 640x480 is supported for pac7302 */ 726 /* only resolution 640x480 is supported for pac7302 */
768 727
@@ -771,34 +730,27 @@ static int sd_start(struct gspca_dev *gspca_dev)
771 atomic_set(&sd->avg_lum, -1); 730 atomic_set(&sd->avg_lum, -1);
772 731
773 /* start stream */ 732 /* start stream */
774 if (0 <= ret) 733 reg_w(gspca_dev, 0xff, 0x01);
775 ret = reg_w(gspca_dev, 0xff, 0x01); 734 reg_w(gspca_dev, 0x78, 0x01);
776 if (0 <= ret)
777 ret = reg_w(gspca_dev, 0x78, 0x01);
778 735
779 return ret; 736 return gspca_dev->usb_err;
780} 737}
781 738
782static void sd_stopN(struct gspca_dev *gspca_dev) 739static void sd_stopN(struct gspca_dev *gspca_dev)
783{ 740{
784 int ret;
785 741
786 /* stop stream */ 742 /* stop stream */
787 ret = reg_w(gspca_dev, 0xff, 0x01); 743 reg_w(gspca_dev, 0xff, 0x01);
788 if (0 <= ret) 744 reg_w(gspca_dev, 0x78, 0x00);
789 ret = reg_w(gspca_dev, 0x78, 0x00);
790} 745}
791 746
792/* called on streamoff with alt 0 and on disconnect for pac7302 */ 747/* called on streamoff with alt 0 and on disconnect for pac7302 */
793static void sd_stop0(struct gspca_dev *gspca_dev) 748static void sd_stop0(struct gspca_dev *gspca_dev)
794{ 749{
795 int ret;
796
797 if (!gspca_dev->present) 750 if (!gspca_dev->present)
798 return; 751 return;
799 ret = reg_w(gspca_dev, 0xff, 0x01); 752 reg_w(gspca_dev, 0xff, 0x01);
800 if (0 <= ret) 753 reg_w(gspca_dev, 0x78, 0x40);
801 ret = reg_w(gspca_dev, 0x78, 0x40);
802} 754}
803 755
804/* Include pac common sof detection functions */ 756/* Include pac common sof detection functions */
@@ -808,22 +760,13 @@ static void do_autogain(struct gspca_dev *gspca_dev)
808{ 760{
809 struct sd *sd = (struct sd *) gspca_dev; 761 struct sd *sd = (struct sd *) gspca_dev;
810 int avg_lum = atomic_read(&sd->avg_lum); 762 int avg_lum = atomic_read(&sd->avg_lum);
811 int desired_lum, deadzone; 763 int desired_lum;
764 const int deadzone = 30;
812 765
813 if (avg_lum == -1) 766 if (avg_lum == -1)
814 return; 767 return;
815 768
816 desired_lum = 270 + sd->brightness * 4; 769 desired_lum = 270 + sd->brightness;
817 /* Hack hack, with the 7202 the first exposure step is
818 pretty large, so if we're about to make the first
819 exposure increase make the deadzone large to avoid
820 oscilating */
821 if (desired_lum > avg_lum && sd->gain == GAIN_DEF &&
822 sd->exposure > EXPOSURE_DEF &&
823 sd->exposure < 42)
824 deadzone = 90;
825 else
826 deadzone = 30;
827 770
828 if (sd->autogain_ignore_frames > 0) 771 if (sd->autogain_ignore_frames > 0)
829 sd->autogain_ignore_frames--; 772 sd->autogain_ignore_frames--;
@@ -947,7 +890,7 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
947 sd->brightness = val; 890 sd->brightness = val;
948 if (gspca_dev->streaming) 891 if (gspca_dev->streaming)
949 setbrightcont(gspca_dev); 892 setbrightcont(gspca_dev);
950 return 0; 893 return gspca_dev->usb_err;
951} 894}
952 895
953static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) 896static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
@@ -966,7 +909,7 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
966 if (gspca_dev->streaming) { 909 if (gspca_dev->streaming) {
967 setbrightcont(gspca_dev); 910 setbrightcont(gspca_dev);
968 } 911 }
969 return 0; 912 return gspca_dev->usb_err;
970} 913}
971 914
972static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) 915static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
@@ -984,7 +927,7 @@ static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
984 sd->colors = val; 927 sd->colors = val;
985 if (gspca_dev->streaming) 928 if (gspca_dev->streaming)
986 setcolors(gspca_dev); 929 setcolors(gspca_dev);
987 return 0; 930 return gspca_dev->usb_err;
988} 931}
989 932
990static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) 933static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
@@ -998,14 +941,11 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
998static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val) 941static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val)
999{ 942{
1000 struct sd *sd = (struct sd *) gspca_dev; 943 struct sd *sd = (struct sd *) gspca_dev;
1001 int ret = 0;
1002 944
1003 sd->white_balance = val; 945 sd->white_balance = val;
1004 if (gspca_dev->streaming) 946 if (gspca_dev->streaming)
1005 ret = setwhitebalance(gspca_dev); 947 setwhitebalance(gspca_dev);
1006 if (0 <= ret) 948 return gspca_dev->usb_err;
1007 ret = 0;
1008 return ret;
1009} 949}
1010 950
1011static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val) 951static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val)
@@ -1019,14 +959,11 @@ static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val)
1019static int sd_setredbalance(struct gspca_dev *gspca_dev, __s32 val) 959static int sd_setredbalance(struct gspca_dev *gspca_dev, __s32 val)
1020{ 960{
1021 struct sd *sd = (struct sd *) gspca_dev; 961 struct sd *sd = (struct sd *) gspca_dev;
1022 int ret = 0;
1023 962
1024 sd->red_balance = val; 963 sd->red_balance = val;
1025 if (gspca_dev->streaming) 964 if (gspca_dev->streaming)
1026 ret = setredbalance(gspca_dev); 965 setredbalance(gspca_dev);
1027 if (0 <= ret) 966 return gspca_dev->usb_err;
1028 ret = 0;
1029 return ret;
1030} 967}
1031 968
1032static int sd_getredbalance(struct gspca_dev *gspca_dev, __s32 *val) 969static int sd_getredbalance(struct gspca_dev *gspca_dev, __s32 *val)
@@ -1040,14 +977,11 @@ static int sd_getredbalance(struct gspca_dev *gspca_dev, __s32 *val)
1040static int sd_setbluebalance(struct gspca_dev *gspca_dev, __s32 val) 977static int sd_setbluebalance(struct gspca_dev *gspca_dev, __s32 val)
1041{ 978{
1042 struct sd *sd = (struct sd *) gspca_dev; 979 struct sd *sd = (struct sd *) gspca_dev;
1043 int ret = 0;
1044 980
1045 sd->blue_balance = val; 981 sd->blue_balance = val;
1046 if (gspca_dev->streaming) 982 if (gspca_dev->streaming)
1047 ret = setbluebalance(gspca_dev); 983 setbluebalance(gspca_dev);
1048 if (0 <= ret) 984 return gspca_dev->usb_err;
1049 ret = 0;
1050 return ret;
1051} 985}
1052 986
1053static int sd_getbluebalance(struct gspca_dev *gspca_dev, __s32 *val) 987static int sd_getbluebalance(struct gspca_dev *gspca_dev, __s32 *val)
@@ -1065,7 +999,7 @@ static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
1065 sd->gain = val; 999 sd->gain = val;
1066 if (gspca_dev->streaming) 1000 if (gspca_dev->streaming)
1067 setgain(gspca_dev); 1001 setgain(gspca_dev);
1068 return 0; 1002 return gspca_dev->usb_err;
1069} 1003}
1070 1004
1071static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) 1005static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
@@ -1083,7 +1017,7 @@ static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1083 sd->exposure = val; 1017 sd->exposure = val;
1084 if (gspca_dev->streaming) 1018 if (gspca_dev->streaming)
1085 setexposure(gspca_dev); 1019 setexposure(gspca_dev);
1086 return 0; 1020 return gspca_dev->usb_err;
1087} 1021}
1088 1022
1089static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) 1023static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
@@ -1114,7 +1048,7 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
1114 } 1048 }
1115 } 1049 }
1116 1050
1117 return 0; 1051 return gspca_dev->usb_err;
1118} 1052}
1119 1053
1120static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) 1054static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
@@ -1132,7 +1066,7 @@ static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
1132 sd->hflip = val; 1066 sd->hflip = val;
1133 if (gspca_dev->streaming) 1067 if (gspca_dev->streaming)
1134 sethvflip(gspca_dev); 1068 sethvflip(gspca_dev);
1135 return 0; 1069 return gspca_dev->usb_err;
1136} 1070}
1137 1071
1138static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) 1072static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
@@ -1150,7 +1084,7 @@ static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
1150 sd->vflip = val; 1084 sd->vflip = val;
1151 if (gspca_dev->streaming) 1085 if (gspca_dev->streaming)
1152 sethvflip(gspca_dev); 1086 sethvflip(gspca_dev);
1153 return 0; 1087 return gspca_dev->usb_err;
1154} 1088}
1155 1089
1156static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) 1090static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
@@ -1165,7 +1099,6 @@ static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
1165static int sd_dbg_s_register(struct gspca_dev *gspca_dev, 1099static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
1166 struct v4l2_dbg_register *reg) 1100 struct v4l2_dbg_register *reg)
1167{ 1101{
1168 int ret = -EINVAL;
1169 __u8 index; 1102 __u8 index;
1170 __u8 value; 1103 __u8 value;
1171 1104
@@ -1185,14 +1118,12 @@ static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
1185 /* Note that there shall be no access to other page 1118 /* Note that there shall be no access to other page
1186 by any other function between the page swith and 1119 by any other function between the page swith and
1187 the actual register write */ 1120 the actual register write */
1188 ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ 1121 reg_w(gspca_dev, 0xff, 0x00); /* page 0 */
1189 if (0 <= ret) 1122 reg_w(gspca_dev, index, value);
1190 ret = reg_w(gspca_dev, index, value);
1191 1123
1192 if (0 <= ret) 1124 reg_w(gspca_dev, 0xdc, 0x01);
1193 ret = reg_w(gspca_dev, 0xdc, 0x01);
1194 } 1125 }
1195 return ret; 1126 return gspca_dev->usb_err;
1196} 1127}
1197 1128
1198static int sd_chip_ident(struct gspca_dev *gspca_dev, 1129static int sd_chip_ident(struct gspca_dev *gspca_dev,
@@ -1210,8 +1141,39 @@ static int sd_chip_ident(struct gspca_dev *gspca_dev,
1210} 1141}
1211#endif 1142#endif
1212 1143
1144#ifdef CONFIG_INPUT
1145static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
1146 u8 *data, /* interrupt packet data */
1147 int len) /* interrput packet length */
1148{
1149 int ret = -EINVAL;
1150 u8 data0, data1;
1151
1152 if (len == 2) {
1153 data0 = data[0];
1154 data1 = data[1];
1155 if ((data0 == 0x00 && data1 == 0x11) ||
1156 (data0 == 0x22 && data1 == 0x33) ||
1157 (data0 == 0x44 && data1 == 0x55) ||
1158 (data0 == 0x66 && data1 == 0x77) ||
1159 (data0 == 0x88 && data1 == 0x99) ||
1160 (data0 == 0xaa && data1 == 0xbb) ||
1161 (data0 == 0xcc && data1 == 0xdd) ||
1162 (data0 == 0xee && data1 == 0xff)) {
1163 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
1164 input_sync(gspca_dev->input_dev);
1165 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
1166 input_sync(gspca_dev->input_dev);
1167 ret = 0;
1168 }
1169 }
1170
1171 return ret;
1172}
1173#endif
1174
1213/* sub-driver description for pac7302 */ 1175/* sub-driver description for pac7302 */
1214static struct sd_desc sd_desc = { 1176static const struct sd_desc sd_desc = {
1215 .name = MODULE_NAME, 1177 .name = MODULE_NAME,
1216 .ctrls = sd_ctrls, 1178 .ctrls = sd_ctrls,
1217 .nctrls = ARRAY_SIZE(sd_ctrls), 1179 .nctrls = ARRAY_SIZE(sd_ctrls),
@@ -1226,6 +1188,9 @@ static struct sd_desc sd_desc = {
1226 .set_register = sd_dbg_s_register, 1188 .set_register = sd_dbg_s_register,
1227 .get_chip_ident = sd_chip_ident, 1189 .get_chip_ident = sd_chip_ident,
1228#endif 1190#endif
1191#ifdef CONFIG_INPUT
1192 .int_pkt_scan = sd_int_pkt_scan,
1193#endif
1229}; 1194};
1230 1195
1231/* -- module initialisation -- */ 1196/* -- module initialisation -- */
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index 42cfcdfd8f4f..44fed9686729 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -51,6 +51,7 @@
51 51
52#define MODULE_NAME "pac7311" 52#define MODULE_NAME "pac7311"
53 53
54#include <linux/input.h>
54#include "gspca.h" 55#include "gspca.h"
55 56
56MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li"); 57MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li");
@@ -88,7 +89,7 @@ static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
88static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); 89static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
89static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); 90static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
90 91
91static struct ctrl sd_ctrls[] = { 92static const struct ctrl sd_ctrls[] = {
92/* This control is for both the 7302 and the 7311 */ 93/* This control is for both the 7302 and the 7311 */
93 { 94 {
94 { 95 {
@@ -200,7 +201,6 @@ static const struct v4l2_pix_format vga_mode[] = {
200 .priv = 0}, 201 .priv = 0},
201}; 202};
202 203
203#define LOAD_PAGE3 255
204#define LOAD_PAGE4 254 204#define LOAD_PAGE4 254
205#define END_OF_SEQUENCE 0 205#define END_OF_SEQUENCE 0
206 206
@@ -259,12 +259,14 @@ static const __u8 page4_7311[] = {
259 0x23, 0x28, 0x04, 0x11, 0x00, 0x00 259 0x23, 0x28, 0x04, 0x11, 0x00, 0x00
260}; 260};
261 261
262static int reg_w_buf(struct gspca_dev *gspca_dev, 262static void reg_w_buf(struct gspca_dev *gspca_dev,
263 __u8 index, 263 __u8 index,
264 const char *buffer, int len) 264 const char *buffer, int len)
265{ 265{
266 int ret; 266 int ret;
267 267
268 if (gspca_dev->usb_err < 0)
269 return;
268 memcpy(gspca_dev->usb_buf, buffer, len); 270 memcpy(gspca_dev->usb_buf, buffer, len);
269 ret = usb_control_msg(gspca_dev->dev, 271 ret = usb_control_msg(gspca_dev->dev,
270 usb_sndctrlpipe(gspca_dev->dev, 0), 272 usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -273,20 +275,23 @@ static int reg_w_buf(struct gspca_dev *gspca_dev,
273 0, /* value */ 275 0, /* value */
274 index, gspca_dev->usb_buf, len, 276 index, gspca_dev->usb_buf, len,
275 500); 277 500);
276 if (ret < 0) 278 if (ret < 0) {
277 PDEBUG(D_ERR, "reg_w_buf(): " 279 PDEBUG(D_ERR, "reg_w_buf(): "
278 "Failed to write registers to index 0x%x, error %i", 280 "Failed to write registers to index 0x%x, error %i",
279 index, ret); 281 index, ret);
280 return ret; 282 gspca_dev->usb_err = ret;
283 }
281} 284}
282 285
283 286
284static int reg_w(struct gspca_dev *gspca_dev, 287static void reg_w(struct gspca_dev *gspca_dev,
285 __u8 index, 288 __u8 index,
286 __u8 value) 289 __u8 value)
287{ 290{
288 int ret; 291 int ret;
289 292
293 if (gspca_dev->usb_err < 0)
294 return;
290 gspca_dev->usb_buf[0] = value; 295 gspca_dev->usb_buf[0] = value;
291 ret = usb_control_msg(gspca_dev->dev, 296 ret = usb_control_msg(gspca_dev->dev,
292 usb_sndctrlpipe(gspca_dev->dev, 0), 297 usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -294,32 +299,32 @@ static int reg_w(struct gspca_dev *gspca_dev,
294 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 299 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
295 0, index, gspca_dev->usb_buf, 1, 300 0, index, gspca_dev->usb_buf, 1,
296 500); 301 500);
297 if (ret < 0) 302 if (ret < 0) {
298 PDEBUG(D_ERR, "reg_w(): " 303 PDEBUG(D_ERR, "reg_w(): "
299 "Failed to write register to index 0x%x, value 0x%x, error %i", 304 "Failed to write register to index 0x%x, value 0x%x, error %i",
300 index, value, ret); 305 index, value, ret);
301 return ret; 306 gspca_dev->usb_err = ret;
307 }
302} 308}
303 309
304static int reg_w_seq(struct gspca_dev *gspca_dev, 310static void reg_w_seq(struct gspca_dev *gspca_dev,
305 const __u8 *seq, int len) 311 const __u8 *seq, int len)
306{ 312{
307 int ret = 0;
308 while (--len >= 0) { 313 while (--len >= 0) {
309 if (0 <= ret) 314 reg_w(gspca_dev, seq[0], seq[1]);
310 ret = reg_w(gspca_dev, seq[0], seq[1]);
311 seq += 2; 315 seq += 2;
312 } 316 }
313 return ret;
314} 317}
315 318
316/* load the beginning of a page */ 319/* load the beginning of a page */
317static int reg_w_page(struct gspca_dev *gspca_dev, 320static void reg_w_page(struct gspca_dev *gspca_dev,
318 const __u8 *page, int len) 321 const __u8 *page, int len)
319{ 322{
320 int index; 323 int index;
321 int ret = 0; 324 int ret = 0;
322 325
326 if (gspca_dev->usb_err < 0)
327 return;
323 for (index = 0; index < len; index++) { 328 for (index = 0; index < len; index++) {
324 if (page[index] == SKIP) /* skip this index */ 329 if (page[index] == SKIP) /* skip this index */
325 continue; 330 continue;
@@ -335,56 +340,47 @@ static int reg_w_page(struct gspca_dev *gspca_dev,
335 "Failed to write register to index 0x%x, " 340 "Failed to write register to index 0x%x, "
336 "value 0x%x, error %i", 341 "value 0x%x, error %i",
337 index, page[index], ret); 342 index, page[index], ret);
343 gspca_dev->usb_err = ret;
338 break; 344 break;
339 } 345 }
340 } 346 }
341 return ret;
342} 347}
343 348
344/* output a variable sequence */ 349/* output a variable sequence */
345static int reg_w_var(struct gspca_dev *gspca_dev, 350static void reg_w_var(struct gspca_dev *gspca_dev,
346 const __u8 *seq, 351 const __u8 *seq,
347 const __u8 *page3, unsigned int page3_len,
348 const __u8 *page4, unsigned int page4_len) 352 const __u8 *page4, unsigned int page4_len)
349{ 353{
350 int index, len; 354 int index, len;
351 int ret = 0;
352 355
353 for (;;) { 356 for (;;) {
354 index = *seq++; 357 index = *seq++;
355 len = *seq++; 358 len = *seq++;
356 switch (len) { 359 switch (len) {
357 case END_OF_SEQUENCE: 360 case END_OF_SEQUENCE:
358 return ret; 361 return;
359 case LOAD_PAGE4: 362 case LOAD_PAGE4:
360 ret = reg_w_page(gspca_dev, page4, page4_len); 363 reg_w_page(gspca_dev, page4, page4_len);
361 break;
362 case LOAD_PAGE3:
363 ret = reg_w_page(gspca_dev, page3, page3_len);
364 break; 364 break;
365 default: 365 default:
366 if (len > USB_BUF_SZ) { 366 if (len > USB_BUF_SZ) {
367 PDEBUG(D_ERR|D_STREAM, 367 PDEBUG(D_ERR|D_STREAM,
368 "Incorrect variable sequence"); 368 "Incorrect variable sequence");
369 return -EINVAL; 369 return;
370 } 370 }
371 while (len > 0) { 371 while (len > 0) {
372 if (len < 8) { 372 if (len < 8) {
373 ret = reg_w_buf(gspca_dev, 373 reg_w_buf(gspca_dev,
374 index, seq, len); 374 index, seq, len);
375 if (ret < 0)
376 return ret;
377 seq += len; 375 seq += len;
378 break; 376 break;
379 } 377 }
380 ret = reg_w_buf(gspca_dev, index, seq, 8); 378 reg_w_buf(gspca_dev, index, seq, 8);
381 seq += 8; 379 seq += 8;
382 index += 8; 380 index += 8;
383 len -= 8; 381 len -= 8;
384 } 382 }
385 } 383 }
386 if (ret < 0)
387 return ret;
388 } 384 }
389 /* not reached */ 385 /* not reached */
390} 386}
@@ -412,46 +408,36 @@ static int sd_config(struct gspca_dev *gspca_dev,
412} 408}
413 409
414/* This function is used by pac7311 only */ 410/* This function is used by pac7311 only */
415static int setcontrast(struct gspca_dev *gspca_dev) 411static void setcontrast(struct gspca_dev *gspca_dev)
416{ 412{
417 struct sd *sd = (struct sd *) gspca_dev; 413 struct sd *sd = (struct sd *) gspca_dev;
418 int ret;
419 414
420 ret = reg_w(gspca_dev, 0xff, 0x04); 415 reg_w(gspca_dev, 0xff, 0x04);
421 if (0 <= ret) 416 reg_w(gspca_dev, 0x10, sd->contrast >> 4);
422 ret = reg_w(gspca_dev, 0x10, sd->contrast >> 4);
423 /* load registers to sensor (Bit 0, auto clear) */ 417 /* load registers to sensor (Bit 0, auto clear) */
424 if (0 <= ret) 418 reg_w(gspca_dev, 0x11, 0x01);
425 ret = reg_w(gspca_dev, 0x11, 0x01);
426 return ret;
427} 419}
428 420
429static int setgain(struct gspca_dev *gspca_dev) 421static void setgain(struct gspca_dev *gspca_dev)
430{ 422{
431 struct sd *sd = (struct sd *) gspca_dev; 423 struct sd *sd = (struct sd *) gspca_dev;
432 int gain = GAIN_MAX - sd->gain; 424 int gain = GAIN_MAX - sd->gain;
433 int ret;
434 425
435 if (gain < 1) 426 if (gain < 1)
436 gain = 1; 427 gain = 1;
437 else if (gain > 245) 428 else if (gain > 245)
438 gain = 245; 429 gain = 245;
439 ret = reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ 430 reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
440 if (0 <= ret) 431 reg_w(gspca_dev, 0x0e, 0x00);
441 ret = reg_w(gspca_dev, 0x0e, 0x00); 432 reg_w(gspca_dev, 0x0f, gain);
442 if (0 <= ret)
443 ret = reg_w(gspca_dev, 0x0f, gain);
444 433
445 /* load registers to sensor (Bit 0, auto clear) */ 434 /* load registers to sensor (Bit 0, auto clear) */
446 if (0 <= ret) 435 reg_w(gspca_dev, 0x11, 0x01);
447 ret = reg_w(gspca_dev, 0x11, 0x01);
448 return ret;
449} 436}
450 437
451static int setexposure(struct gspca_dev *gspca_dev) 438static void setexposure(struct gspca_dev *gspca_dev)
452{ 439{
453 struct sd *sd = (struct sd *) gspca_dev; 440 struct sd *sd = (struct sd *) gspca_dev;
454 int ret;
455 __u8 reg; 441 __u8 reg;
456 442
457 /* register 2 of frame 3/4 contains the clock divider configuring the 443 /* register 2 of frame 3/4 contains the clock divider configuring the
@@ -463,94 +449,72 @@ static int setexposure(struct gspca_dev *gspca_dev)
463 else if (reg > 63) 449 else if (reg > 63)
464 reg = 63; 450 reg = 63;
465 451
466 ret = reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ 452 reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
467 if (0 <= ret) 453 reg_w(gspca_dev, 0x02, reg);
468 ret = reg_w(gspca_dev, 0x02, reg); 454
469 /* Page 1 register 8 must always be 0x08 except when not in 455 /* Page 1 register 8 must always be 0x08 except when not in
470 640x480 mode and Page3/4 reg 2 <= 3 then it must be 9 */ 456 640x480 mode and Page3/4 reg 2 <= 3 then it must be 9 */
471 if (0 <= ret) 457 reg_w(gspca_dev, 0xff, 0x01);
472 ret = reg_w(gspca_dev, 0xff, 0x01);
473 if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv && 458 if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv &&
474 reg <= 3) { 459 reg <= 3) {
475 if (0 <= ret) 460 reg_w(gspca_dev, 0x08, 0x09);
476 ret = reg_w(gspca_dev, 0x08, 0x09);
477 } else { 461 } else {
478 if (0 <= ret) 462 reg_w(gspca_dev, 0x08, 0x08);
479 ret = reg_w(gspca_dev, 0x08, 0x08);
480 } 463 }
481 464
482 /* load registers to sensor (Bit 0, auto clear) */ 465 /* load registers to sensor (Bit 0, auto clear) */
483 if (0 <= ret) 466 reg_w(gspca_dev, 0x11, 0x01);
484 ret = reg_w(gspca_dev, 0x11, 0x01);
485 return ret;
486} 467}
487 468
488static int sethvflip(struct gspca_dev *gspca_dev) 469static void sethvflip(struct gspca_dev *gspca_dev)
489{ 470{
490 struct sd *sd = (struct sd *) gspca_dev; 471 struct sd *sd = (struct sd *) gspca_dev;
491 int ret;
492 __u8 data; 472 __u8 data;
493 473
494 ret = reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ 474 reg_w(gspca_dev, 0xff, 0x04); /* page 4 */
495 data = (sd->hflip ? 0x04 : 0x00) | (sd->vflip ? 0x08 : 0x00); 475 data = (sd->hflip ? 0x04 : 0x00) | (sd->vflip ? 0x08 : 0x00);
496 if (0 <= ret) 476 reg_w(gspca_dev, 0x21, data);
497 ret = reg_w(gspca_dev, 0x21, data); 477
498 /* load registers to sensor (Bit 0, auto clear) */ 478 /* load registers to sensor (Bit 0, auto clear) */
499 if (0 <= ret) 479 reg_w(gspca_dev, 0x11, 0x01);
500 ret = reg_w(gspca_dev, 0x11, 0x01);
501 return ret;
502} 480}
503 481
504/* this function is called at probe and resume time for pac7311 */ 482/* this function is called at probe and resume time for pac7311 */
505static int sd_init(struct gspca_dev *gspca_dev) 483static int sd_init(struct gspca_dev *gspca_dev)
506{ 484{
507 return reg_w_seq(gspca_dev, init_7311, sizeof(init_7311)/2); 485 reg_w_seq(gspca_dev, init_7311, sizeof(init_7311)/2);
486 return gspca_dev->usb_err;
508} 487}
509 488
510static int sd_start(struct gspca_dev *gspca_dev) 489static int sd_start(struct gspca_dev *gspca_dev)
511{ 490{
512 struct sd *sd = (struct sd *) gspca_dev; 491 struct sd *sd = (struct sd *) gspca_dev;
513 int ret;
514 492
515 sd->sof_read = 0; 493 sd->sof_read = 0;
516 494
517 ret = reg_w_var(gspca_dev, start_7311, 495 reg_w_var(gspca_dev, start_7311,
518 NULL, 0,
519 page4_7311, sizeof(page4_7311)); 496 page4_7311, sizeof(page4_7311));
520 if (0 <= ret) 497 setcontrast(gspca_dev);
521 ret = setcontrast(gspca_dev); 498 setgain(gspca_dev);
522 if (0 <= ret) 499 setexposure(gspca_dev);
523 ret = setgain(gspca_dev); 500 sethvflip(gspca_dev);
524 if (0 <= ret)
525 ret = setexposure(gspca_dev);
526 if (0 <= ret)
527 ret = sethvflip(gspca_dev);
528 501
529 /* set correct resolution */ 502 /* set correct resolution */
530 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { 503 switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) {
531 case 2: /* 160x120 pac7311 */ 504 case 2: /* 160x120 pac7311 */
532 if (0 <= ret) 505 reg_w(gspca_dev, 0xff, 0x01);
533 ret = reg_w(gspca_dev, 0xff, 0x01); 506 reg_w(gspca_dev, 0x17, 0x20);
534 if (0 <= ret) 507 reg_w(gspca_dev, 0x87, 0x10);
535 ret = reg_w(gspca_dev, 0x17, 0x20);
536 if (0 <= ret)
537 ret = reg_w(gspca_dev, 0x87, 0x10);
538 break; 508 break;
539 case 1: /* 320x240 pac7311 */ 509 case 1: /* 320x240 pac7311 */
540 if (0 <= ret) 510 reg_w(gspca_dev, 0xff, 0x01);
541 ret = reg_w(gspca_dev, 0xff, 0x01); 511 reg_w(gspca_dev, 0x17, 0x30);
542 if (0 <= ret) 512 reg_w(gspca_dev, 0x87, 0x11);
543 ret = reg_w(gspca_dev, 0x17, 0x30);
544 if (0 <= ret)
545 ret = reg_w(gspca_dev, 0x87, 0x11);
546 break; 513 break;
547 case 0: /* 640x480 */ 514 case 0: /* 640x480 */
548 if (0 <= ret) 515 reg_w(gspca_dev, 0xff, 0x01);
549 ret = reg_w(gspca_dev, 0xff, 0x01); 516 reg_w(gspca_dev, 0x17, 0x00);
550 if (0 <= ret) 517 reg_w(gspca_dev, 0x87, 0x12);
551 ret = reg_w(gspca_dev, 0x17, 0x00);
552 if (0 <= ret)
553 ret = reg_w(gspca_dev, 0x87, 0x12);
554 break; 518 break;
555 } 519 }
556 520
@@ -559,37 +523,24 @@ static int sd_start(struct gspca_dev *gspca_dev)
559 atomic_set(&sd->avg_lum, -1); 523 atomic_set(&sd->avg_lum, -1);
560 524
561 /* start stream */ 525 /* start stream */
562 if (0 <= ret) 526 reg_w(gspca_dev, 0xff, 0x01);
563 ret = reg_w(gspca_dev, 0xff, 0x01); 527 reg_w(gspca_dev, 0x78, 0x05);
564 if (0 <= ret)
565 ret = reg_w(gspca_dev, 0x78, 0x05);
566 528
567 return ret; 529 return gspca_dev->usb_err;
568} 530}
569 531
570static void sd_stopN(struct gspca_dev *gspca_dev) 532static void sd_stopN(struct gspca_dev *gspca_dev)
571{ 533{
572 int ret; 534 reg_w(gspca_dev, 0xff, 0x04);
573 535 reg_w(gspca_dev, 0x27, 0x80);
574 ret = reg_w(gspca_dev, 0xff, 0x04); 536 reg_w(gspca_dev, 0x28, 0xca);
575 if (0 <= ret) 537 reg_w(gspca_dev, 0x29, 0x53);
576 ret = reg_w(gspca_dev, 0x27, 0x80); 538 reg_w(gspca_dev, 0x2a, 0x0e);
577 if (0 <= ret) 539 reg_w(gspca_dev, 0xff, 0x01);
578 ret = reg_w(gspca_dev, 0x28, 0xca); 540 reg_w(gspca_dev, 0x3e, 0x20);
579 if (0 <= ret) 541 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
580 ret = reg_w(gspca_dev, 0x29, 0x53); 542 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
581 if (0 <= ret) 543 reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
582 ret = reg_w(gspca_dev, 0x2a, 0x0e);
583 if (0 <= ret)
584 ret = reg_w(gspca_dev, 0xff, 0x01);
585 if (0 <= ret)
586 ret = reg_w(gspca_dev, 0x3e, 0x20);
587 if (0 <= ret)
588 ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
589 if (0 <= ret)
590 ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
591 if (0 <= ret)
592 ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */
593} 544}
594 545
595/* called on streamoff with alt 0 and on disconnect for 7311 */ 546/* called on streamoff with alt 0 and on disconnect for 7311 */
@@ -734,7 +685,7 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
734 if (gspca_dev->streaming) { 685 if (gspca_dev->streaming) {
735 setcontrast(gspca_dev); 686 setcontrast(gspca_dev);
736 } 687 }
737 return 0; 688 return gspca_dev->usb_err;
738} 689}
739 690
740static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) 691static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
@@ -752,7 +703,7 @@ static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
752 sd->gain = val; 703 sd->gain = val;
753 if (gspca_dev->streaming) 704 if (gspca_dev->streaming)
754 setgain(gspca_dev); 705 setgain(gspca_dev);
755 return 0; 706 return gspca_dev->usb_err;
756} 707}
757 708
758static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) 709static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
@@ -770,7 +721,7 @@ static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
770 sd->exposure = val; 721 sd->exposure = val;
771 if (gspca_dev->streaming) 722 if (gspca_dev->streaming)
772 setexposure(gspca_dev); 723 setexposure(gspca_dev);
773 return 0; 724 return gspca_dev->usb_err;
774} 725}
775 726
776static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) 727static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
@@ -801,7 +752,7 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
801 } 752 }
802 } 753 }
803 754
804 return 0; 755 return gspca_dev->usb_err;
805} 756}
806 757
807static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) 758static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
@@ -819,7 +770,7 @@ static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
819 sd->hflip = val; 770 sd->hflip = val;
820 if (gspca_dev->streaming) 771 if (gspca_dev->streaming)
821 sethvflip(gspca_dev); 772 sethvflip(gspca_dev);
822 return 0; 773 return gspca_dev->usb_err;
823} 774}
824 775
825static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) 776static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
@@ -837,7 +788,7 @@ static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
837 sd->vflip = val; 788 sd->vflip = val;
838 if (gspca_dev->streaming) 789 if (gspca_dev->streaming)
839 sethvflip(gspca_dev); 790 sethvflip(gspca_dev);
840 return 0; 791 return gspca_dev->usb_err;
841} 792}
842 793
843static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) 794static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
@@ -848,8 +799,39 @@ static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
848 return 0; 799 return 0;
849} 800}
850 801
802#ifdef CONFIG_INPUT
803static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
804 u8 *data, /* interrupt packet data */
805 int len) /* interrupt packet length */
806{
807 int ret = -EINVAL;
808 u8 data0, data1;
809
810 if (len == 2) {
811 data0 = data[0];
812 data1 = data[1];
813 if ((data0 == 0x00 && data1 == 0x11) ||
814 (data0 == 0x22 && data1 == 0x33) ||
815 (data0 == 0x44 && data1 == 0x55) ||
816 (data0 == 0x66 && data1 == 0x77) ||
817 (data0 == 0x88 && data1 == 0x99) ||
818 (data0 == 0xaa && data1 == 0xbb) ||
819 (data0 == 0xcc && data1 == 0xdd) ||
820 (data0 == 0xee && data1 == 0xff)) {
821 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
822 input_sync(gspca_dev->input_dev);
823 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
824 input_sync(gspca_dev->input_dev);
825 ret = 0;
826 }
827 }
828
829 return ret;
830}
831#endif
832
851/* sub-driver description for pac7311 */ 833/* sub-driver description for pac7311 */
852static struct sd_desc sd_desc = { 834static const struct sd_desc sd_desc = {
853 .name = MODULE_NAME, 835 .name = MODULE_NAME,
854 .ctrls = sd_ctrls, 836 .ctrls = sd_ctrls,
855 .nctrls = ARRAY_SIZE(sd_ctrls), 837 .nctrls = ARRAY_SIZE(sd_ctrls),
@@ -860,6 +842,9 @@ static struct sd_desc sd_desc = {
860 .stop0 = sd_stop0, 842 .stop0 = sd_stop0,
861 .pkt_scan = sd_pkt_scan, 843 .pkt_scan = sd_pkt_scan,
862 .dq_callback = do_autogain, 844 .dq_callback = do_autogain,
845#ifdef CONFIG_INPUT
846 .int_pkt_scan = sd_int_pkt_scan,
847#endif
863}; 848};
864 849
865/* -- module initialisation -- */ 850/* -- module initialisation -- */
diff --git a/drivers/media/video/gspca/pac_common.h b/drivers/media/video/gspca/pac_common.h
index 20f67d9b8c06..8462a7c1a338 100644
--- a/drivers/media/video/gspca/pac_common.h
+++ b/drivers/media/video/gspca/pac_common.h
@@ -24,11 +24,10 @@
24 */ 24 */
25 25
26/* We calculate the autogain at the end of the transfer of a frame, at this 26/* We calculate the autogain at the end of the transfer of a frame, at this
27 moment a frame with the old settings is being transmitted, and a frame is 27 moment a frame with the old settings is being captured and transmitted. So
28 being captured with the old settings. So if we adjust the autogain we must 28 if we adjust the gain or exposure we must ignore atleast the next frame for
29 ignore atleast the 2 next frames for the new settings to come into effect 29 the new settings to come into effect before doing any other adjustments. */
30 before doing any other adjustments */ 30#define PAC_AUTOGAIN_IGNORE_FRAMES 2
31#define PAC_AUTOGAIN_IGNORE_FRAMES 3
32 31
33static const unsigned char pac_sof_marker[5] = 32static const unsigned char pac_sof_marker[5] =
34 { 0xff, 0xff, 0x00, 0xff, 0x96 }; 33 { 0xff, 0xff, 0x00, 0xff, 0x96 };
diff --git a/drivers/media/video/gspca/sn9c2028.c b/drivers/media/video/gspca/sn9c2028.c
new file mode 100644
index 000000000000..dda5fd4aa69e
--- /dev/null
+++ b/drivers/media/video/gspca/sn9c2028.c
@@ -0,0 +1,757 @@
1/*
2 * SN9C2028 library
3 *
4 * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn.edu>
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 * 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#define MODULE_NAME "sn9c2028"
22
23#include "gspca.h"
24
25MODULE_AUTHOR("Theodore Kilgore");
26MODULE_DESCRIPTION("Sonix SN9C2028 USB Camera Driver");
27MODULE_LICENSE("GPL");
28
29/* specific webcam descriptor */
30struct sd {
31 struct gspca_dev gspca_dev; /* !! must be the first item */
32 u8 sof_read;
33 u16 model;
34};
35
36struct init_command {
37 unsigned char instruction[6];
38 unsigned char to_read; /* length to read. 0 means no reply requested */
39};
40
41/* V4L2 controls supported by the driver */
42static struct ctrl sd_ctrls[] = {
43};
44
45/* How to change the resolution of any of the VGA cams is unknown */
46static const struct v4l2_pix_format vga_mode[] = {
47 {640, 480, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
48 .bytesperline = 640,
49 .sizeimage = 640 * 480 * 3 / 4,
50 .colorspace = V4L2_COLORSPACE_SRGB,
51 .priv = 0},
52};
53
54/* No way to change the resolution of the CIF cams is known */
55static const struct v4l2_pix_format cif_mode[] = {
56 {352, 288, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE,
57 .bytesperline = 352,
58 .sizeimage = 352 * 288 * 3 / 4,
59 .colorspace = V4L2_COLORSPACE_SRGB,
60 .priv = 0},
61};
62
63/* the bytes to write are in gspca_dev->usb_buf */
64static int sn9c2028_command(struct gspca_dev *gspca_dev, u8 *command)
65{
66 int rc;
67
68 PDEBUG(D_USBO, "sending command %02x%02x%02x%02x%02x%02x", command[0],
69 command[1], command[2], command[3], command[4], command[5]);
70
71 memcpy(gspca_dev->usb_buf, command, 6);
72 rc = usb_control_msg(gspca_dev->dev,
73 usb_sndctrlpipe(gspca_dev->dev, 0),
74 USB_REQ_GET_CONFIGURATION,
75 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
76 2, 0, gspca_dev->usb_buf, 6, 500);
77 if (rc < 0) {
78 PDEBUG(D_ERR, "command write [%02x] error %d",
79 gspca_dev->usb_buf[0], rc);
80 return rc;
81 }
82
83 return 0;
84}
85
86static int sn9c2028_read1(struct gspca_dev *gspca_dev)
87{
88 int rc;
89
90 rc = usb_control_msg(gspca_dev->dev,
91 usb_rcvctrlpipe(gspca_dev->dev, 0),
92 USB_REQ_GET_STATUS,
93 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
94 1, 0, gspca_dev->usb_buf, 1, 500);
95 if (rc != 1) {
96 PDEBUG(D_ERR, "read1 error %d", rc);
97 return (rc < 0) ? rc : -EIO;
98 }
99 PDEBUG(D_USBI, "read1 response %02x", gspca_dev->usb_buf[0]);
100 return gspca_dev->usb_buf[0];
101}
102
103static int sn9c2028_read4(struct gspca_dev *gspca_dev, u8 *reading)
104{
105 int rc;
106 rc = usb_control_msg(gspca_dev->dev,
107 usb_rcvctrlpipe(gspca_dev->dev, 0),
108 USB_REQ_GET_STATUS,
109 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
110 4, 0, gspca_dev->usb_buf, 4, 500);
111 if (rc != 4) {
112 PDEBUG(D_ERR, "read4 error %d", rc);
113 return (rc < 0) ? rc : -EIO;
114 }
115 memcpy(reading, gspca_dev->usb_buf, 4);
116 PDEBUG(D_USBI, "read4 response %02x%02x%02x%02x", reading[0],
117 reading[1], reading[2], reading[3]);
118 return rc;
119}
120
121static int sn9c2028_long_command(struct gspca_dev *gspca_dev, u8 *command)
122{
123 int i, status;
124 __u8 reading[4];
125
126 status = sn9c2028_command(gspca_dev, command);
127 if (status < 0)
128 return status;
129
130 status = -1;
131 for (i = 0; i < 256 && status < 2; i++)
132 status = sn9c2028_read1(gspca_dev);
133 if (status != 2) {
134 PDEBUG(D_ERR, "long command status read error %d", status);
135 return (status < 0) ? status : -EIO;
136 }
137
138 memset(reading, 0, 4);
139 status = sn9c2028_read4(gspca_dev, reading);
140 if (status < 0)
141 return status;
142
143 /* in general, the first byte of the response is the first byte of
144 * the command, or'ed with 8 */
145 status = sn9c2028_read1(gspca_dev);
146 if (status < 0)
147 return status;
148
149 return 0;
150}
151
152static int sn9c2028_short_command(struct gspca_dev *gspca_dev, u8 *command)
153{
154 int err_code;
155
156 err_code = sn9c2028_command(gspca_dev, command);
157 if (err_code < 0)
158 return err_code;
159
160 err_code = sn9c2028_read1(gspca_dev);
161 if (err_code < 0)
162 return err_code;
163
164 return 0;
165}
166
167/* this function is called at probe time */
168static int sd_config(struct gspca_dev *gspca_dev,
169 const struct usb_device_id *id)
170{
171 struct sd *sd = (struct sd *) gspca_dev;
172 struct cam *cam = &gspca_dev->cam;
173
174 PDEBUG(D_PROBE, "SN9C2028 camera detected (vid/pid 0x%04X:0x%04X)",
175 id->idVendor, id->idProduct);
176
177 sd->model = id->idProduct;
178
179 switch (sd->model) {
180 case 0x7005:
181 PDEBUG(D_PROBE, "Genius Smart 300 camera");
182 break;
183 case 0x8000:
184 PDEBUG(D_PROBE, "DC31VC");
185 break;
186 case 0x8001:
187 PDEBUG(D_PROBE, "Spy camera");
188 break;
189 case 0x8003:
190 PDEBUG(D_PROBE, "CIF camera");
191 break;
192 case 0x8008:
193 PDEBUG(D_PROBE, "Mini-Shotz ms-350 camera");
194 break;
195 case 0x800a:
196 PDEBUG(D_PROBE, "Vivitar 3350b type camera");
197 cam->input_flags = V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
198 break;
199 }
200
201 switch (sd->model) {
202 case 0x8000:
203 case 0x8001:
204 case 0x8003:
205 cam->cam_mode = cif_mode;
206 cam->nmodes = ARRAY_SIZE(cif_mode);
207 break;
208 default:
209 cam->cam_mode = vga_mode;
210 cam->nmodes = ARRAY_SIZE(vga_mode);
211 }
212 return 0;
213}
214
215/* this function is called at probe and resume time */
216static int sd_init(struct gspca_dev *gspca_dev)
217{
218 int status = -1;
219
220 sn9c2028_read1(gspca_dev);
221 sn9c2028_read1(gspca_dev);
222 status = sn9c2028_read1(gspca_dev);
223
224 return (status < 0) ? status : 0;
225}
226
227static int run_start_commands(struct gspca_dev *gspca_dev,
228 struct init_command *cam_commands, int n)
229{
230 int i, err_code = -1;
231
232 for (i = 0; i < n; i++) {
233 switch (cam_commands[i].to_read) {
234 case 4:
235 err_code = sn9c2028_long_command(gspca_dev,
236 cam_commands[i].instruction);
237 break;
238 case 1:
239 err_code = sn9c2028_short_command(gspca_dev,
240 cam_commands[i].instruction);
241 break;
242 case 0:
243 err_code = sn9c2028_command(gspca_dev,
244 cam_commands[i].instruction);
245 break;
246 }
247 if (err_code < 0)
248 return err_code;
249 }
250 return 0;
251}
252
253static int start_spy_cam(struct gspca_dev *gspca_dev)
254{
255 struct init_command spy_start_commands[] = {
256 {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
257 {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
258 {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
259 {{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4},
260 {{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4},
261 {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
262 {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, /* width 352 */
263 {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, /* height 288 */
264 /* {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4}, */
265 {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4},
266 {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* red gain ?*/
267 /* {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4}, */
268 {{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4},
269 /* {{0x13, 0x29, 0x01, 0x0c, 0x00, 0x00}, 4}, */
270 {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
271 {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
272 /* {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, */
273 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
274 {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
275 /* {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4}, */
276 {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
277 {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
278 {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
279 {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
280 {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
281 {{0x11, 0x02, 0x06, 0x00, 0x00, 0x00}, 4},
282 {{0x11, 0x03, 0x13, 0x00, 0x00, 0x00}, 4}, /*don't mess with*/
283 /*{{0x11, 0x04, 0x06, 0x00, 0x00, 0x00}, 4}, observed */
284 {{0x11, 0x04, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */
285 /*{{0x11, 0x05, 0x65, 0x00, 0x00, 0x00}, 4}, observed */
286 {{0x11, 0x05, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */
287 {{0x11, 0x06, 0xb1, 0x00, 0x00, 0x00}, 4}, /* observed */
288 {{0x11, 0x07, 0x00, 0x00, 0x00, 0x00}, 4},
289 /*{{0x11, 0x08, 0x06, 0x00, 0x00, 0x00}, 4}, observed */
290 {{0x11, 0x08, 0x0b, 0x00, 0x00, 0x00}, 4},
291 {{0x11, 0x09, 0x01, 0x00, 0x00, 0x00}, 4},
292 {{0x11, 0x0a, 0x01, 0x00, 0x00, 0x00}, 4},
293 {{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4},
294 {{0x11, 0x0c, 0x01, 0x00, 0x00, 0x00}, 4},
295 {{0x11, 0x0d, 0x00, 0x00, 0x00, 0x00}, 4},
296 {{0x11, 0x0e, 0x04, 0x00, 0x00, 0x00}, 4},
297 /* {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4}, */
298 /* brightness or gain. 0 is default. 4 is good
299 * indoors at night with incandescent lighting */
300 {{0x11, 0x0f, 0x04, 0x00, 0x00, 0x00}, 4},
301 {{0x11, 0x10, 0x06, 0x00, 0x00, 0x00}, 4}, /*hstart or hoffs*/
302 {{0x11, 0x11, 0x06, 0x00, 0x00, 0x00}, 4},
303 {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
304 {{0x11, 0x14, 0x02, 0x00, 0x00, 0x00}, 4},
305 {{0x11, 0x13, 0x01, 0x00, 0x00, 0x00}, 4},
306 /* {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1}, observed */
307 {{0x1b, 0x02, 0x11, 0x00, 0x00, 0x00}, 1}, /* brighter */
308 /* {{0x1b, 0x13, 0x01, 0x00, 0x00, 0x00}, 1}, observed */
309 {{0x1b, 0x13, 0x11, 0x00, 0x00, 0x00}, 1},
310 {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}, /* compresses */
311 /* Camera should start to capture now. */
312 };
313
314 return run_start_commands(gspca_dev, spy_start_commands,
315 ARRAY_SIZE(spy_start_commands));
316}
317
318static int start_cif_cam(struct gspca_dev *gspca_dev)
319{
320 struct init_command cif_start_commands[] = {
321 {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
322 /* The entire sequence below seems redundant */
323 /* {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
324 {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
325 {{0x13, 0x22, 0x01, 0x06, 0x00, 0x00}, 4},
326 {{0x13, 0x23, 0x01, 0x02, 0x00, 0x00}, 4},
327 {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
328 {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, width?
329 {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, height?
330 {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample?
331 {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4},
332 {{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4},
333 {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
334 {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
335 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
336 {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
337 {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
338 {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
339 {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
340 {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
341 {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},*/
342 {{0x1b, 0x21, 0x00, 0x00, 0x00, 0x00}, 1},
343 {{0x1b, 0x17, 0x00, 0x00, 0x00, 0x00}, 1},
344 {{0x1b, 0x19, 0x00, 0x00, 0x00, 0x00}, 1},
345 {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1},
346 {{0x1b, 0x03, 0x5a, 0x00, 0x00, 0x00}, 1},
347 {{0x1b, 0x04, 0x27, 0x00, 0x00, 0x00}, 1},
348 {{0x1b, 0x05, 0x01, 0x00, 0x00, 0x00}, 1},
349 {{0x1b, 0x12, 0x14, 0x00, 0x00, 0x00}, 1},
350 {{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1},
351 {{0x1b, 0x14, 0x00, 0x00, 0x00, 0x00}, 1},
352 {{0x1b, 0x15, 0x00, 0x00, 0x00, 0x00}, 1},
353 {{0x1b, 0x16, 0x00, 0x00, 0x00, 0x00}, 1},
354 {{0x1b, 0x77, 0xa2, 0x00, 0x00, 0x00}, 1},
355 {{0x1b, 0x06, 0x0f, 0x00, 0x00, 0x00}, 1},
356 {{0x1b, 0x07, 0x14, 0x00, 0x00, 0x00}, 1},
357 {{0x1b, 0x08, 0x0f, 0x00, 0x00, 0x00}, 1},
358 {{0x1b, 0x09, 0x10, 0x00, 0x00, 0x00}, 1},
359 {{0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00}, 1},
360 {{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1},
361 {{0x1b, 0x12, 0x07, 0x00, 0x00, 0x00}, 1},
362 {{0x1b, 0x10, 0x1f, 0x00, 0x00, 0x00}, 1},
363 {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
364 {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 1}, /* width/8 */
365 {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 1}, /* height/8 */
366 /* {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample?
367 * {{0x13, 0x28, 0x01, 0x1e, 0x00, 0x00}, 4}, does nothing
368 * {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4}, */
369 /* {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
370 * causes subsampling
371 * but not a change in the resolution setting! */
372 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
373 {{0x13, 0x2d, 0x01, 0x01, 0x00, 0x00}, 4},
374 {{0x13, 0x2e, 0x01, 0x08, 0x00, 0x00}, 4},
375 {{0x13, 0x2f, 0x01, 0x06, 0x00, 0x00}, 4},
376 {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4},
377 {{0x1b, 0x04, 0x6d, 0x00, 0x00, 0x00}, 1},
378 {{0x1b, 0x05, 0x03, 0x00, 0x00, 0x00}, 1},
379 {{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1},
380 {{0x1b, 0x0e, 0x01, 0x00, 0x00, 0x00}, 1},
381 {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
382 {{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1},
383 {{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1},
384 {{0x1b, 0x10, 0x0f, 0x00, 0x00, 0x00}, 1},
385 {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1},
386 {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
387 {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1},/* use compression */
388 /* Camera should start to capture now. */
389 };
390
391 return run_start_commands(gspca_dev, cif_start_commands,
392 ARRAY_SIZE(cif_start_commands));
393}
394
395static int start_ms350_cam(struct gspca_dev *gspca_dev)
396{
397 struct init_command ms350_start_commands[] = {
398 {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
399 {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
400 {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
401 {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
402 {{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4},
403 {{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4},
404 {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
405 {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
406 {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
407 {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4},
408 {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4},
409 {{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4},
410 {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
411 {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
412 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
413 {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
414 {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
415 {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
416 {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
417 {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
418 {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
419 {{0x11, 0x00, 0x01, 0x00, 0x00, 0x00}, 4},
420 {{0x11, 0x01, 0x70, 0x00, 0x00, 0x00}, 4},
421 {{0x11, 0x02, 0x05, 0x00, 0x00, 0x00}, 4},
422 {{0x11, 0x03, 0x5d, 0x00, 0x00, 0x00}, 4},
423 {{0x11, 0x04, 0x07, 0x00, 0x00, 0x00}, 4},
424 {{0x11, 0x05, 0x25, 0x00, 0x00, 0x00}, 4},
425 {{0x11, 0x06, 0x00, 0x00, 0x00, 0x00}, 4},
426 {{0x11, 0x07, 0x09, 0x00, 0x00, 0x00}, 4},
427 {{0x11, 0x08, 0x01, 0x00, 0x00, 0x00}, 4},
428 {{0x11, 0x09, 0x00, 0x00, 0x00, 0x00}, 4},
429 {{0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, 4},
430 {{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4},
431 {{0x11, 0x0c, 0x00, 0x00, 0x00, 0x00}, 4},
432 {{0x11, 0x0d, 0x0c, 0x00, 0x00, 0x00}, 4},
433 {{0x11, 0x0e, 0x01, 0x00, 0x00, 0x00}, 4},
434 {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4},
435 {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
436 {{0x11, 0x11, 0x00, 0x00, 0x00, 0x00}, 4},
437 {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
438 {{0x11, 0x13, 0x63, 0x00, 0x00, 0x00}, 4},
439 {{0x11, 0x15, 0x70, 0x00, 0x00, 0x00}, 4},
440 {{0x11, 0x18, 0x00, 0x00, 0x00, 0x00}, 4},
441 {{0x11, 0x11, 0x01, 0x00, 0x00, 0x00}, 4},
442 {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* width */
443 {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* height */
444 {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* vstart? */
445 {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4},
446 {{0x13, 0x29, 0x01, 0x40, 0x00, 0x00}, 4}, /* hstart? */
447 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
448 {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
449 {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
450 {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
451 {{0x1b, 0x02, 0x05, 0x00, 0x00, 0x00}, 1},
452 {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1},
453 {{0x20, 0x18, 0x00, 0x00, 0x00, 0x00}, 1},
454 {{0x1b, 0x02, 0x0a, 0x00, 0x00, 0x00}, 1},
455 {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 0},
456 /* Camera should start to capture now. */
457 };
458
459 return run_start_commands(gspca_dev, ms350_start_commands,
460 ARRAY_SIZE(ms350_start_commands));
461}
462
463static int start_genius_cam(struct gspca_dev *gspca_dev)
464{
465 struct init_command genius_start_commands[] = {
466 {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
467 {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
468 {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4},
469 {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4},
470 {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4},
471 /* "preliminary" width and height settings */
472 {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
473 {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
474 {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4},
475 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
476 {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4},
477 {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4},
478 {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4},
479 {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
480 {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
481 {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
482 {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
483 {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
484 {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4},
485 {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
486 {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4},
487 {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
488 {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4},
489 {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4},
490 {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4},
491 {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
492 {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4},
493 {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
494 {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4},
495 {{0x11, 0x25, 0x00, 0x00, 0x00, 0x00}, 4},
496 {{0x11, 0x26, 0x02, 0x00, 0x00, 0x00}, 4},
497 {{0x11, 0x27, 0x88, 0x00, 0x00, 0x00}, 4},
498 {{0x11, 0x30, 0x38, 0x00, 0x00, 0x00}, 4},
499 {{0x11, 0x31, 0x2a, 0x00, 0x00, 0x00}, 4},
500 {{0x11, 0x32, 0x2a, 0x00, 0x00, 0x00}, 4},
501 {{0x11, 0x33, 0x2a, 0x00, 0x00, 0x00}, 4},
502 {{0x11, 0x34, 0x02, 0x00, 0x00, 0x00}, 4},
503 {{0x11, 0x5b, 0x0a, 0x00, 0x00, 0x00}, 4},
504 {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* real width */
505 {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* real height */
506 {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4},
507 {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
508 {{0x13, 0x29, 0x01, 0x62, 0x00, 0x00}, 4},
509 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
510 {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
511 {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
512 {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
513 {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4},
514 {{0x11, 0x21, 0x2a, 0x00, 0x00, 0x00}, 4},
515 {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4},
516 {{0x11, 0x23, 0x28, 0x00, 0x00, 0x00}, 4},
517 {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4},
518 {{0x11, 0x11, 0x04, 0x00, 0x00, 0x00}, 4},
519 {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4},
520 {{0x11, 0x13, 0x03, 0x00, 0x00, 0x00}, 4},
521 {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4},
522 {{0x11, 0x15, 0xe0, 0x00, 0x00, 0x00}, 4},
523 {{0x11, 0x16, 0x02, 0x00, 0x00, 0x00}, 4},
524 {{0x11, 0x17, 0x80, 0x00, 0x00, 0x00}, 4},
525 {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
526 {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1},
527 {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 0}
528 /* Camera should start to capture now. */
529 };
530
531 return run_start_commands(gspca_dev, genius_start_commands,
532 ARRAY_SIZE(genius_start_commands));
533}
534
535static int start_vivitar_cam(struct gspca_dev *gspca_dev)
536{
537 struct init_command vivitar_start_commands[] = {
538 {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4},
539 {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4},
540 {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4},
541 {{0x13, 0x22, 0x01, 0x01, 0x00, 0x00}, 4},
542 {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4},
543 {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4},
544 {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
545 {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
546 {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4},
547 {{0x13, 0x28, 0x01, 0x0a, 0x00, 0x00}, 4},
548 /*
549 * Above is changed from OEM 0x0b. Fixes Bayer tiling.
550 * Presumably gives a vertical shift of one row.
551 */
552 {{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4},
553 /* Above seems to do horizontal shift. */
554 {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4},
555 {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4},
556 {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4},
557 {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4},
558 {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4},
559 {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4},
560 /* Above three commands seem to relate to brightness. */
561 {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4},
562 {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4},
563 {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},
564 {{0x1b, 0x12, 0x80, 0x00, 0x00, 0x00}, 1},
565 {{0x1b, 0x01, 0x77, 0x00, 0x00, 0x00}, 1},
566 {{0x1b, 0x02, 0x3a, 0x00, 0x00, 0x00}, 1},
567 {{0x1b, 0x12, 0x78, 0x00, 0x00, 0x00}, 1},
568 {{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1},
569 {{0x1b, 0x14, 0x80, 0x00, 0x00, 0x00}, 1},
570 {{0x1b, 0x15, 0x34, 0x00, 0x00, 0x00}, 1},
571 {{0x1b, 0x1b, 0x04, 0x00, 0x00, 0x00}, 1},
572 {{0x1b, 0x20, 0x44, 0x00, 0x00, 0x00}, 1},
573 {{0x1b, 0x23, 0xee, 0x00, 0x00, 0x00}, 1},
574 {{0x1b, 0x26, 0xa0, 0x00, 0x00, 0x00}, 1},
575 {{0x1b, 0x27, 0x9a, 0x00, 0x00, 0x00}, 1},
576 {{0x1b, 0x28, 0xa0, 0x00, 0x00, 0x00}, 1},
577 {{0x1b, 0x29, 0x30, 0x00, 0x00, 0x00}, 1},
578 {{0x1b, 0x2a, 0x80, 0x00, 0x00, 0x00}, 1},
579 {{0x1b, 0x2b, 0x00, 0x00, 0x00, 0x00}, 1},
580 {{0x1b, 0x2f, 0x3d, 0x00, 0x00, 0x00}, 1},
581 {{0x1b, 0x30, 0x24, 0x00, 0x00, 0x00}, 1},
582 {{0x1b, 0x32, 0x86, 0x00, 0x00, 0x00}, 1},
583 {{0x1b, 0x60, 0xa9, 0x00, 0x00, 0x00}, 1},
584 {{0x1b, 0x61, 0x42, 0x00, 0x00, 0x00}, 1},
585 {{0x1b, 0x65, 0x00, 0x00, 0x00, 0x00}, 1},
586 {{0x1b, 0x69, 0x38, 0x00, 0x00, 0x00}, 1},
587 {{0x1b, 0x6f, 0x88, 0x00, 0x00, 0x00}, 1},
588 {{0x1b, 0x70, 0x0b, 0x00, 0x00, 0x00}, 1},
589 {{0x1b, 0x71, 0x00, 0x00, 0x00, 0x00}, 1},
590 {{0x1b, 0x74, 0x21, 0x00, 0x00, 0x00}, 1},
591 {{0x1b, 0x75, 0x86, 0x00, 0x00, 0x00}, 1},
592 {{0x1b, 0x76, 0x00, 0x00, 0x00, 0x00}, 1},
593 {{0x1b, 0x7d, 0xf3, 0x00, 0x00, 0x00}, 1},
594 {{0x1b, 0x17, 0x1c, 0x00, 0x00, 0x00}, 1},
595 {{0x1b, 0x18, 0xc0, 0x00, 0x00, 0x00}, 1},
596 {{0x1b, 0x19, 0x05, 0x00, 0x00, 0x00}, 1},
597 {{0x1b, 0x1a, 0xf6, 0x00, 0x00, 0x00}, 1},
598 /* {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4},
599 {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4},
600 {{0x13, 0x28, 0x01, 0x0b, 0x00, 0x00}, 4}, */
601 {{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1},
602 {{0x1b, 0x10, 0x26, 0x00, 0x00, 0x00}, 1},
603 {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
604 {{0x1b, 0x76, 0x03, 0x00, 0x00, 0x00}, 1},
605 {{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1},
606 {{0x1b, 0x00, 0x3f, 0x00, 0x00, 0x00}, 1},
607 /* Above is brightness; OEM driver setting is 0x10 */
608 {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4},
609 {{0x20, 0x29, 0x30, 0x00, 0x00, 0x00}, 1},
610 {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}
611 };
612
613 return run_start_commands(gspca_dev, vivitar_start_commands,
614 ARRAY_SIZE(vivitar_start_commands));
615}
616
617static int sd_start(struct gspca_dev *gspca_dev)
618{
619 struct sd *sd = (struct sd *) gspca_dev;
620 int err_code;
621
622 sd->sof_read = 0;
623
624 switch (sd->model) {
625 case 0x7005:
626 err_code = start_genius_cam(gspca_dev);
627 break;
628 case 0x8001:
629 err_code = start_spy_cam(gspca_dev);
630 break;
631 case 0x8003:
632 err_code = start_cif_cam(gspca_dev);
633 break;
634 case 0x8008:
635 err_code = start_ms350_cam(gspca_dev);
636 break;
637 case 0x800a:
638 err_code = start_vivitar_cam(gspca_dev);
639 break;
640 default:
641 PDEBUG(D_ERR, "Starting unknown camera, please report this");
642 return -ENXIO;
643 }
644
645 return err_code;
646}
647
648static void sd_stopN(struct gspca_dev *gspca_dev)
649{
650 int result;
651 __u8 data[6];
652
653 result = sn9c2028_read1(gspca_dev);
654 if (result < 0)
655 PDEBUG(D_ERR, "Camera Stop read failed");
656
657 memset(data, 0, 6);
658 data[0] = 0x14;
659 result = sn9c2028_command(gspca_dev, data);
660 if (result < 0)
661 PDEBUG(D_ERR, "Camera Stop command failed");
662}
663
664/* Include sn9c2028 sof detection functions */
665#include "sn9c2028.h"
666
667static void sd_pkt_scan(struct gspca_dev *gspca_dev,
668 __u8 *data, /* isoc packet */
669 int len) /* iso packet length */
670{
671 unsigned char *sof;
672
673 sof = sn9c2028_find_sof(gspca_dev, data, len);
674 if (sof) {
675 int n;
676
677 /* finish decoding current frame */
678 n = sof - data;
679 if (n > sizeof sn9c2028_sof_marker)
680 n -= sizeof sn9c2028_sof_marker;
681 else
682 n = 0;
683 gspca_frame_add(gspca_dev, LAST_PACKET, data, n);
684 /* Start next frame. */
685 gspca_frame_add(gspca_dev, FIRST_PACKET,
686 sn9c2028_sof_marker, sizeof sn9c2028_sof_marker);
687 len -= sof - data;
688 data = sof;
689 }
690 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
691}
692
693/* sub-driver description */
694static const struct sd_desc sd_desc = {
695 .name = MODULE_NAME,
696 .ctrls = sd_ctrls,
697 .nctrls = ARRAY_SIZE(sd_ctrls),
698 .config = sd_config,
699 .init = sd_init,
700 .start = sd_start,
701 .stopN = sd_stopN,
702 .pkt_scan = sd_pkt_scan,
703};
704
705/* -- module initialisation -- */
706static const __devinitdata struct usb_device_id device_table[] = {
707 {USB_DEVICE(0x0458, 0x7005)}, /* Genius Smart 300, version 2 */
708 /* The Genius Smart is untested. I can't find an owner ! */
709 /* {USB_DEVICE(0x0c45, 0x8000)}, DC31VC, Don't know this camera */
710 {USB_DEVICE(0x0c45, 0x8001)}, /* Wild Planet digital spy cam */
711 {USB_DEVICE(0x0c45, 0x8003)}, /* Several small CIF cameras */
712 /* {USB_DEVICE(0x0c45, 0x8006)}, Unknown VGA camera */
713 {USB_DEVICE(0x0c45, 0x8008)}, /* Mini-Shotz ms-350 */
714 {USB_DEVICE(0x0c45, 0x800a)}, /* Vivicam 3350B */
715 {}
716};
717MODULE_DEVICE_TABLE(usb, device_table);
718
719/* -- device connect -- */
720static int sd_probe(struct usb_interface *intf,
721 const struct usb_device_id *id)
722{
723 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
724 THIS_MODULE);
725}
726
727static struct usb_driver sd_driver = {
728 .name = MODULE_NAME,
729 .id_table = device_table,
730 .probe = sd_probe,
731 .disconnect = gspca_disconnect,
732#ifdef CONFIG_PM
733 .suspend = gspca_suspend,
734 .resume = gspca_resume,
735#endif
736};
737
738/* -- module insert / remove -- */
739static int __init sd_mod_init(void)
740{
741 int ret;
742
743 ret = usb_register(&sd_driver);
744 if (ret < 0)
745 return ret;
746 PDEBUG(D_PROBE, "registered");
747 return 0;
748}
749
750static void __exit sd_mod_exit(void)
751{
752 usb_deregister(&sd_driver);
753 PDEBUG(D_PROBE, "deregistered");
754}
755
756module_init(sd_mod_init);
757module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/sn9c2028.h b/drivers/media/video/gspca/sn9c2028.h
new file mode 100644
index 000000000000..8fd1d3e05665
--- /dev/null
+++ b/drivers/media/video/gspca/sn9c2028.h
@@ -0,0 +1,51 @@
1/*
2 * SN9C2028 common functions
3 *
4 * Copyright (C) 2009 Theodore Kilgore <kilgota@auburn,edu>
5 *
6 * Based closely upon the file gspca/pac_common.h
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24static const unsigned char sn9c2028_sof_marker[5] =
25 { 0xff, 0xff, 0x00, 0xc4, 0xc4 };
26
27static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev,
28 unsigned char *m, int len)
29{
30 struct sd *sd = (struct sd *) gspca_dev;
31 int i;
32
33 /* Search for the SOF marker (fixed part) in the header */
34 for (i = 0; i < len; i++) {
35 if (m[i] == sn9c2028_sof_marker[sd->sof_read]) {
36 sd->sof_read++;
37 if (sd->sof_read == sizeof(sn9c2028_sof_marker)) {
38 PDEBUG(D_FRAM,
39 "SOF found, bytes to analyze: %u."
40 " Frame starts at byte #%u",
41 len, i + 1);
42 sd->sof_read = 0;
43 return m + i + 1;
44 }
45 } else {
46 sd->sof_read = 0;
47 }
48 }
49
50 return NULL;
51}
diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c
index 0ca1c06652b1..4a1bc08f82b9 100644
--- a/drivers/media/video/gspca/sn9c20x.c
+++ b/drivers/media/video/gspca/sn9c20x.c
@@ -129,7 +129,7 @@ static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val);
129static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val); 129static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val);
130static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val); 130static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val);
131 131
132static struct ctrl sd_ctrls[] = { 132static const struct ctrl sd_ctrls[] = {
133 { 133 {
134#define BRIGHTNESS_IDX 0 134#define BRIGHTNESS_IDX 0
135 { 135 {
@@ -1506,36 +1506,36 @@ static int set_cmatrix(struct gspca_dev *gspca_dev)
1506 struct sd *sd = (struct sd *) gspca_dev; 1506 struct sd *sd = (struct sd *) gspca_dev;
1507 s32 hue_coord, hue_index = 180 + sd->hue; 1507 s32 hue_coord, hue_index = 180 + sd->hue;
1508 u8 cmatrix[21]; 1508 u8 cmatrix[21];
1509 memset(cmatrix, 0, 21);
1510 1509
1510 memset(cmatrix, 0, sizeof cmatrix);
1511 cmatrix[2] = (sd->contrast * 0x25 / 0x100) + 0x26; 1511 cmatrix[2] = (sd->contrast * 0x25 / 0x100) + 0x26;
1512 cmatrix[0] = 0x13 + (cmatrix[2] - 0x26) * 0x13 / 0x25; 1512 cmatrix[0] = 0x13 + (cmatrix[2] - 0x26) * 0x13 / 0x25;
1513 cmatrix[4] = 0x07 + (cmatrix[2] - 0x26) * 0x07 / 0x25; 1513 cmatrix[4] = 0x07 + (cmatrix[2] - 0x26) * 0x07 / 0x25;
1514 cmatrix[18] = sd->brightness - 0x80; 1514 cmatrix[18] = sd->brightness - 0x80;
1515 1515
1516 hue_coord = (hsv_red_x[hue_index] * sd->saturation) >> 8; 1516 hue_coord = (hsv_red_x[hue_index] * sd->saturation) >> 8;
1517 cmatrix[6] = (unsigned char)(hue_coord & 0xff); 1517 cmatrix[6] = hue_coord;
1518 cmatrix[7] = (unsigned char)((hue_coord >> 8) & 0x0f); 1518 cmatrix[7] = (hue_coord >> 8) & 0x0f;
1519 1519
1520 hue_coord = (hsv_red_y[hue_index] * sd->saturation) >> 8; 1520 hue_coord = (hsv_red_y[hue_index] * sd->saturation) >> 8;
1521 cmatrix[8] = (unsigned char)(hue_coord & 0xff); 1521 cmatrix[8] = hue_coord;
1522 cmatrix[9] = (unsigned char)((hue_coord >> 8) & 0x0f); 1522 cmatrix[9] = (hue_coord >> 8) & 0x0f;
1523 1523
1524 hue_coord = (hsv_green_x[hue_index] * sd->saturation) >> 8; 1524 hue_coord = (hsv_green_x[hue_index] * sd->saturation) >> 8;
1525 cmatrix[10] = (unsigned char)(hue_coord & 0xff); 1525 cmatrix[10] = hue_coord;
1526 cmatrix[11] = (unsigned char)((hue_coord >> 8) & 0x0f); 1526 cmatrix[11] = (hue_coord >> 8) & 0x0f;
1527 1527
1528 hue_coord = (hsv_green_y[hue_index] * sd->saturation) >> 8; 1528 hue_coord = (hsv_green_y[hue_index] * sd->saturation) >> 8;
1529 cmatrix[12] = (unsigned char)(hue_coord & 0xff); 1529 cmatrix[12] = hue_coord;
1530 cmatrix[13] = (unsigned char)((hue_coord >> 8) & 0x0f); 1530 cmatrix[13] = (hue_coord >> 8) & 0x0f;
1531 1531
1532 hue_coord = (hsv_blue_x[hue_index] * sd->saturation) >> 8; 1532 hue_coord = (hsv_blue_x[hue_index] * sd->saturation) >> 8;
1533 cmatrix[14] = (unsigned char)(hue_coord & 0xff); 1533 cmatrix[14] = hue_coord;
1534 cmatrix[15] = (unsigned char)((hue_coord >> 8) & 0x0f); 1534 cmatrix[15] = (hue_coord >> 8) & 0x0f;
1535 1535
1536 hue_coord = (hsv_blue_y[hue_index] * sd->saturation) >> 8; 1536 hue_coord = (hsv_blue_y[hue_index] * sd->saturation) >> 8;
1537 cmatrix[16] = (unsigned char)(hue_coord & 0xff); 1537 cmatrix[16] = hue_coord;
1538 cmatrix[17] = (unsigned char)((hue_coord >> 8) & 0x0f); 1538 cmatrix[17] = (hue_coord >> 8) & 0x0f;
1539 1539
1540 return reg_w(gspca_dev, 0x10e1, cmatrix, 21); 1540 return reg_w(gspca_dev, 0x10e1, cmatrix, 21);
1541} 1541}
@@ -2015,6 +2015,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
2015 default: 2015 default:
2016 cam->cam_mode = vga_mode; 2016 cam->cam_mode = vga_mode;
2017 cam->nmodes = ARRAY_SIZE(vga_mode); 2017 cam->nmodes = ARRAY_SIZE(vga_mode);
2018 break;
2018 } 2019 }
2019 2020
2020 sd->old_step = 0; 2021 sd->old_step = 0;
@@ -2319,7 +2320,7 @@ static void do_autogain(struct gspca_dev *gspca_dev, u16 avg_lum)
2319 } 2320 }
2320 } 2321 }
2321 if (avg_lum > MAX_AVG_LUM) { 2322 if (avg_lum > MAX_AVG_LUM) {
2322 if (sd->gain >= 1) { 2323 if (sd->gain > 0) {
2323 sd->gain--; 2324 sd->gain--;
2324 set_gain(gspca_dev); 2325 set_gain(gspca_dev);
2325 } 2326 }
@@ -2347,7 +2348,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2347{ 2348{
2348 struct sd *sd = (struct sd *) gspca_dev; 2349 struct sd *sd = (struct sd *) gspca_dev;
2349 int avg_lum; 2350 int avg_lum;
2350 static unsigned char frame_header[] = 2351 static u8 frame_header[] =
2351 {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96}; 2352 {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96};
2352 if (len == 64 && memcmp(data, frame_header, 6) == 0) { 2353 if (len == 64 && memcmp(data, frame_header, 6) == 0) {
2353 avg_lum = ((data[35] >> 2) & 3) | 2354 avg_lum = ((data[35] >> 2) & 3) |
diff --git a/drivers/media/video/gspca/sonixb.c b/drivers/media/video/gspca/sonixb.c
index ddff2b5ee5c2..785eeb4c2014 100644
--- a/drivers/media/video/gspca/sonixb.c
+++ b/drivers/media/video/gspca/sonixb.c
@@ -42,6 +42,7 @@ Reg Use
42 42
43#define MODULE_NAME "sonixb" 43#define MODULE_NAME "sonixb"
44 44
45#include <linux/input.h>
45#include "gspca.h" 46#include "gspca.h"
46 47
47MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 48MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
@@ -53,9 +54,11 @@ struct sd {
53 struct gspca_dev gspca_dev; /* !! must be the first item */ 54 struct gspca_dev gspca_dev; /* !! must be the first item */
54 atomic_t avg_lum; 55 atomic_t avg_lum;
55 int prev_avg_lum; 56 int prev_avg_lum;
57 int exp_too_low_cnt;
58 int exp_too_high_cnt;
56 59
60 unsigned short exposure;
57 unsigned char gain; 61 unsigned char gain;
58 unsigned char exposure;
59 unsigned char brightness; 62 unsigned char brightness;
60 unsigned char autogain; 63 unsigned char autogain;
61 unsigned char autogain_ignore_frames; 64 unsigned char autogain_ignore_frames;
@@ -73,8 +76,9 @@ struct sd {
73#define SENSOR_OV7630 2 76#define SENSOR_OV7630 2
74#define SENSOR_PAS106 3 77#define SENSOR_PAS106 3
75#define SENSOR_PAS202 4 78#define SENSOR_PAS202 4
76#define SENSOR_TAS5110 5 79#define SENSOR_TAS5110C 5
77#define SENSOR_TAS5130CXX 6 80#define SENSOR_TAS5110D 6
81#define SENSOR_TAS5130CXX 7
78 __u8 reg11; 82 __u8 reg11;
79}; 83};
80 84
@@ -95,13 +99,15 @@ struct sensor_data {
95/* sensor_data flags */ 99/* sensor_data flags */
96#define F_GAIN 0x01 /* has gain */ 100#define F_GAIN 0x01 /* has gain */
97#define F_SIF 0x02 /* sif or vga */ 101#define F_SIF 0x02 /* sif or vga */
102#define F_COARSE_EXPO 0x04 /* exposure control is coarse */
98 103
99/* priv field of struct v4l2_pix_format flags (do not use low nibble!) */ 104/* priv field of struct v4l2_pix_format flags (do not use low nibble!) */
100#define MODE_RAW 0x10 /* raw bayer mode */ 105#define MODE_RAW 0x10 /* raw bayer mode */
101#define MODE_REDUCED_SIF 0x20 /* vga mode (320x240 / 160x120) on sif cam */ 106#define MODE_REDUCED_SIF 0x20 /* vga mode (320x240 / 160x120) on sif cam */
102 107
103/* ctrl_dis helper macros */ 108/* ctrl_dis helper macros */
104#define NO_EXPO ((1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX)) 109#define NO_EXPO ((1 << EXPOSURE_IDX) | (1 << COARSE_EXPOSURE_IDX) | \
110 (1 << AUTOGAIN_IDX))
105#define NO_FREQ (1 << FREQ_IDX) 111#define NO_FREQ (1 << FREQ_IDX)
106#define NO_BRIGHTNESS (1 << BRIGHTNESS_IDX) 112#define NO_BRIGHTNESS (1 << BRIGHTNESS_IDX)
107 113
@@ -127,11 +133,10 @@ struct sensor_data {
127} 133}
128 134
129/* We calculate the autogain at the end of the transfer of a frame, at this 135/* We calculate the autogain at the end of the transfer of a frame, at this
130 moment a frame with the old settings is being transmitted, and a frame is 136 moment a frame with the old settings is being captured and transmitted. So
131 being captured with the old settings. So if we adjust the autogain we must 137 if we adjust the gain or exposure we must ignore atleast the next frame for
132 ignore atleast the 2 next frames for the new settings to come into effect 138 the new settings to come into effect before doing any other adjustments. */
133 before doing any other adjustments */ 139#define AUTOGAIN_IGNORE_FRAMES 1
134#define AUTOGAIN_IGNORE_FRAMES 3
135 140
136/* V4L2 controls supported by the driver */ 141/* V4L2 controls supported by the driver */
137static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 142static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
@@ -145,7 +150,7 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
145static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); 150static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
146static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); 151static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
147 152
148static struct ctrl sd_ctrls[] = { 153static const struct ctrl sd_ctrls[] = {
149#define BRIGHTNESS_IDX 0 154#define BRIGHTNESS_IDX 0
150 { 155 {
151 { 156 {
@@ -171,7 +176,7 @@ static struct ctrl sd_ctrls[] = {
171 .maximum = 255, 176 .maximum = 255,
172 .step = 1, 177 .step = 1,
173#define GAIN_DEF 127 178#define GAIN_DEF 127
174#define GAIN_KNEE 200 179#define GAIN_KNEE 230
175 .default_value = GAIN_DEF, 180 .default_value = GAIN_DEF,
176 }, 181 },
177 .set = sd_setgain, 182 .set = sd_setgain,
@@ -183,10 +188,10 @@ static struct ctrl sd_ctrls[] = {
183 .id = V4L2_CID_EXPOSURE, 188 .id = V4L2_CID_EXPOSURE,
184 .type = V4L2_CTRL_TYPE_INTEGER, 189 .type = V4L2_CTRL_TYPE_INTEGER,
185 .name = "Exposure", 190 .name = "Exposure",
186#define EXPOSURE_DEF 16 /* 32 ms / 30 fps */ 191#define EXPOSURE_DEF 66 /* 33 ms / 30 fps (except on PASXXX) */
187#define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */ 192#define EXPOSURE_KNEE 200 /* 100 ms / 10 fps (except on PASXXX) */
188 .minimum = 0, 193 .minimum = 0,
189 .maximum = 255, 194 .maximum = 1023,
190 .step = 1, 195 .step = 1,
191 .default_value = EXPOSURE_DEF, 196 .default_value = EXPOSURE_DEF,
192 .flags = 0, 197 .flags = 0,
@@ -194,7 +199,23 @@ static struct ctrl sd_ctrls[] = {
194 .set = sd_setexposure, 199 .set = sd_setexposure,
195 .get = sd_getexposure, 200 .get = sd_getexposure,
196 }, 201 },
197#define AUTOGAIN_IDX 3 202#define COARSE_EXPOSURE_IDX 3
203 {
204 {
205 .id = V4L2_CID_EXPOSURE,
206 .type = V4L2_CTRL_TYPE_INTEGER,
207 .name = "Exposure",
208#define COARSE_EXPOSURE_DEF 2 /* 30 fps */
209 .minimum = 2,
210 .maximum = 15,
211 .step = 1,
212 .default_value = COARSE_EXPOSURE_DEF,
213 .flags = 0,
214 },
215 .set = sd_setexposure,
216 .get = sd_getexposure,
217 },
218#define AUTOGAIN_IDX 4
198 { 219 {
199 { 220 {
200 .id = V4L2_CID_AUTOGAIN, 221 .id = V4L2_CID_AUTOGAIN,
@@ -210,7 +231,7 @@ static struct ctrl sd_ctrls[] = {
210 .set = sd_setautogain, 231 .set = sd_setautogain,
211 .get = sd_getautogain, 232 .get = sd_getautogain,
212 }, 233 },
213#define FREQ_IDX 4 234#define FREQ_IDX 5
214 { 235 {
215 { 236 {
216 .id = V4L2_CID_POWER_LINE_FREQUENCY, 237 .id = V4L2_CID_POWER_LINE_FREQUENCY,
@@ -219,7 +240,7 @@ static struct ctrl sd_ctrls[] = {
219 .minimum = 0, 240 .minimum = 0,
220 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ 241 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
221 .step = 1, 242 .step = 1,
222#define FREQ_DEF 1 243#define FREQ_DEF 0
223 .default_value = FREQ_DEF, 244 .default_value = FREQ_DEF,
224 }, 245 },
225 .set = sd_setfreq, 246 .set = sd_setfreq,
@@ -345,7 +366,7 @@ static const __u8 initOv7630[] = {
345}; 366};
346static const __u8 initOv7630_3[] = { 367static const __u8 initOv7630_3[] = {
347 0x44, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 0x80, /* r01 .. r08 */ 368 0x44, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 0x80, /* r01 .. r08 */
348 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, /* r09 .. r10 */ 369 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */
349 0x00, 0x02, 0x01, 0x0a, /* r11 .. r14 */ 370 0x00, 0x02, 0x01, 0x0a, /* r11 .. r14 */
350 0x28, 0x1e, /* H & V sizes r15 .. r16 */ 371 0x28, 0x1e, /* H & V sizes r15 .. r16 */
351 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */ 372 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */
@@ -387,6 +408,30 @@ static const __u8 initPas106[] = {
387 0x18, 0x10, 0x02, 0x02, 0x09, 0x07 408 0x18, 0x10, 0x02, 0x02, 0x09, 0x07
388}; 409};
389/* compression 0x86 mckinit1 0x2b */ 410/* compression 0x86 mckinit1 0x2b */
411
412/* "Known" PAS106B registers:
413 0x02 clock divider
414 0x03 Variable framerate bits 4-11
415 0x04 Var framerate bits 0-3, one must leave the 4 msb's at 0 !!
416 The variable framerate control must never be set lower then 300,
417 which sets the framerate at 90 / reg02, otherwise vsync is lost.
418 0x05 Shutter Time Line Offset, this can be used as an exposure control:
419 0 = use full frame time, 255 = no exposure at all
420 Note this may never be larger then "var-framerate control" / 2 - 2.
421 When var-framerate control is < 514, no exposure is reached at the max
422 allowed value for the framerate control value, rather then at 255.
423 0x06 Shutter Time Pixel Offset, like reg05 this influences exposure, but
424 only a very little bit, leave at 0xcd
425 0x07 offset sign bit (bit0 1 > negative offset)
426 0x08 offset
427 0x09 Blue Gain
428 0x0a Green1 Gain
429 0x0b Green2 Gain
430 0x0c Red Gain
431 0x0e Global gain
432 0x13 Write 1 to commit settings to sensor
433*/
434
390static const __u8 pas106_sensor_init[][8] = { 435static const __u8 pas106_sensor_init[][8] = {
391 /* Pixel Clock Divider 6 */ 436 /* Pixel Clock Divider 6 */
392 { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 }, 437 { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 },
@@ -433,37 +478,55 @@ static const __u8 initPas202[] = {
433 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 478 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00,
434 0x00, 0x00, 479 0x00, 0x00,
435 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a, 480 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a,
436 0x28, 0x1e, 0x28, 0x89, 0x20, 481 0x28, 0x1e, 0x20, 0x89, 0x20,
437 0x00, 0x00, 0x02, 0x03, 0x0f, 0x0c 482 0x00, 0x00, 0x02, 0x03, 0x0f, 0x0c
438}; 483};
484
485/* "Known" PAS202BCB registers:
486 0x02 clock divider
487 0x04 Variable framerate bits 6-11 (*)
488 0x05 Var framerate bits 0-5, one must leave the 2 msb's at 0 !!
489 0x07 Blue Gain
490 0x08 Green Gain
491 0x09 Red Gain
492 0x0b offset sign bit (bit0 1 > negative offset)
493 0x0c offset
494 0x0e Unknown image is slightly brighter when bit 0 is 0, if reg0f is 0 too,
495 leave at 1 otherwise we get a jump in our exposure control
496 0x0f Exposure 0-255, 0 = use full frame time, 255 = no exposure at all
497 0x10 Master gain 0 - 31
498 0x11 write 1 to apply changes
499 (*) The variable framerate control must never be set lower then 500
500 which sets the framerate at 30 / reg02, otherwise vsync is lost.
501*/
439static const __u8 pas202_sensor_init[][8] = { 502static const __u8 pas202_sensor_init[][8] = {
440 {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10}, 503 /* Set the clock divider to 4 -> 30 / 4 = 7.5 fps, we would like
504 to set it lower, but for some reason the bridge starts missing
505 vsync's then */
506 {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10},
441 {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10}, 507 {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10},
442 {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10}, 508 {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10},
443 {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x00, 0x32, 0x10}, 509 {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x01, 0x32, 0x10},
444 {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10}, 510 {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10},
445 {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10}, 511 {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10},
446 {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10}, 512 {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10},
447 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10}, 513 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
448 {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10}, 514 {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10},
449 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10}, 515 {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10},
450 {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x10},
451 {0xb0, 0x40, 0x0e, 0x00, 0x3d, 0x00, 0x63, 0x10},
452
453 {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16},
454 {0xa0, 0x40, 0x10, 0x08, 0x3d, 0x00, 0x63, 0x15},
455 {0xa0, 0x40, 0x02, 0x04, 0x3d, 0x00, 0x63, 0x16},
456 {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16},
457 {0xb0, 0x40, 0x0e, 0x00, 0x31, 0x00, 0x63, 0x16},
458 {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16},
459 {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15},
460 {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16},
461}; 516};
462 517
463static const __u8 initTas5110[] = { 518static const __u8 initTas5110c[] = {
464 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, 519 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
465 0x00, 0x00, 520 0x00, 0x00,
466 0x00, 0x01, 0x00, 0x45, 0x09, 0x0a, 521 0x00, 0x00, 0x00, 0x45, 0x09, 0x0a,
522 0x16, 0x12, 0x60, 0x86, 0x2b,
523 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07
524};
525/* Same as above, except a different hstart */
526static const __u8 initTas5110d[] = {
527 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
528 0x00, 0x00,
529 0x00, 0x00, 0x00, 0x41, 0x09, 0x0a,
467 0x16, 0x12, 0x60, 0x86, 0x2b, 530 0x16, 0x12, 0x60, 0x86, 0x2b,
468 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07 531 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07
469}; 532};
@@ -476,7 +539,7 @@ static const __u8 tas5110_sensor_init[][8] = {
476static const __u8 initTas5130[] = { 539static const __u8 initTas5130[] = {
477 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, 540 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00,
478 0x00, 0x00, 541 0x00, 0x00,
479 0x00, 0x01, 0x00, 0x68, 0x0c, 0x0a, 542 0x00, 0x00, 0x00, 0x68, 0x0c, 0x0a,
480 0x28, 0x1e, 0x60, COMP, MCK_INIT, 543 0x28, 0x1e, 0x60, COMP, MCK_INIT,
481 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c 544 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c
482}; 545};
@@ -493,12 +556,14 @@ SENS(initHv7131, NULL, hv7131_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, 0),
493SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60), 556SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60),
494SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3, 557SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3,
495 F_GAIN, 0, 0x21), 558 F_GAIN, 0, 0x21),
496SENS(initPas106, NULL, pas106_sensor_init, NULL, NULL, F_SIF, NO_EXPO|NO_FREQ, 559SENS(initPas106, NULL, pas106_sensor_init, NULL, NULL, F_GAIN|F_SIF, NO_FREQ,
497 0), 560 0),
498SENS(initPas202, initPas202, pas202_sensor_init, NULL, NULL, 0, 561SENS(initPas202, initPas202, pas202_sensor_init, NULL, NULL, F_GAIN,
499 NO_EXPO|NO_FREQ, 0), 562 NO_FREQ, 0),
500SENS(initTas5110, NULL, tas5110_sensor_init, NULL, NULL, F_GAIN|F_SIF, 563SENS(initTas5110c, NULL, tas5110_sensor_init, NULL, NULL,
501 NO_BRIGHTNESS|NO_FREQ, 0), 564 F_GAIN|F_SIF|F_COARSE_EXPO, NO_BRIGHTNESS|NO_FREQ, 0),
565SENS(initTas5110d, NULL, tas5110_sensor_init, NULL, NULL,
566 F_GAIN|F_SIF|F_COARSE_EXPO, NO_BRIGHTNESS|NO_FREQ, 0),
502SENS(initTas5130, NULL, tas5130_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, 567SENS(initTas5130, NULL, tas5130_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ,
503 0), 568 0),
504}; 569};
@@ -587,42 +652,28 @@ static void setbrightness(struct gspca_dev *gspca_dev)
587 goto err; 652 goto err;
588 break; 653 break;
589 } 654 }
590 case SENSOR_PAS106: { 655 case SENSOR_PAS106:
591 __u8 i2c1[] =
592 {0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14};
593
594 i2c1[3] = sd->brightness >> 3;
595 i2c1[2] = 0x0e;
596 if (i2c_w(gspca_dev, i2c1) < 0)
597 goto err;
598 i2c1[3] = 0x01;
599 i2c1[2] = 0x13;
600 if (i2c_w(gspca_dev, i2c1) < 0)
601 goto err;
602 break;
603 }
604 case SENSOR_PAS202: { 656 case SENSOR_PAS202: {
605 /* __u8 i2cpexpo1[] = 657 __u8 i2cpbright[] =
606 {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x16}; */ 658 {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16};
607 __u8 i2cpexpo[] = 659 __u8 i2cpdoit[] =
608 {0xb0, 0x40, 0x0e, 0x01, 0xab, 0x00, 0x63, 0x16}; 660 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
609 __u8 i2cp202[] = 661
610 {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15}; 662 /* PAS106 uses reg 7 and 8 instead of b and c */
611 static __u8 i2cpdoit[] = 663 if (sd->sensor == SENSOR_PAS106) {
612 {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16}; 664 i2cpbright[2] = 7;
613 665 i2cpdoit[2] = 0x13;
614 /* change reg 0x10 */ 666 }
615 i2cpexpo[4] = 0xff - sd->brightness; 667
616/* if(i2c_w(gspca_dev,i2cpexpo1) < 0) 668 if (sd->brightness < 127) {
617 goto err; */ 669 /* change reg 0x0b, signreg */
618/* if(i2c_w(gspca_dev,i2cpdoit) < 0) 670 i2cpbright[3] = 0x01;
619 goto err; */ 671 /* set reg 0x0c, offset */
620 if (i2c_w(gspca_dev, i2cpexpo) < 0) 672 i2cpbright[4] = 127 - sd->brightness;
621 goto err; 673 } else
622 if (i2c_w(gspca_dev, i2cpdoit) < 0) 674 i2cpbright[4] = sd->brightness - 127;
623 goto err; 675
624 i2cp202[3] = sd->brightness >> 3; 676 if (i2c_w(gspca_dev, i2cpbright) < 0)
625 if (i2c_w(gspca_dev, i2cp202) < 0)
626 goto err; 677 goto err;
627 if (i2c_w(gspca_dev, i2cpdoit) < 0) 678 if (i2c_w(gspca_dev, i2cpdoit) < 0)
628 goto err; 679 goto err;
@@ -652,7 +703,8 @@ static void setsensorgain(struct gspca_dev *gspca_dev)
652 703
653 switch (sd->sensor) { 704 switch (sd->sensor) {
654 705
655 case SENSOR_TAS5110: { 706 case SENSOR_TAS5110C:
707 case SENSOR_TAS5110D: {
656 __u8 i2c[] = 708 __u8 i2c[] =
657 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}; 709 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10};
658 710
@@ -674,6 +726,37 @@ static void setsensorgain(struct gspca_dev *gspca_dev)
674 goto err; 726 goto err;
675 break; 727 break;
676 } 728 }
729 case SENSOR_PAS106:
730 case SENSOR_PAS202: {
731 __u8 i2cpgain[] =
732 {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15};
733 __u8 i2cpcolorgain[] =
734 {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15};
735 __u8 i2cpdoit[] =
736 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
737
738 /* PAS106 uses different regs (and has split green gains) */
739 if (sd->sensor == SENSOR_PAS106) {
740 i2cpgain[2] = 0x0e;
741 i2cpcolorgain[0] = 0xd0;
742 i2cpcolorgain[2] = 0x09;
743 i2cpdoit[2] = 0x13;
744 }
745
746 i2cpgain[3] = sd->gain >> 3;
747 i2cpcolorgain[3] = sd->gain >> 4;
748 i2cpcolorgain[4] = sd->gain >> 4;
749 i2cpcolorgain[5] = sd->gain >> 4;
750 i2cpcolorgain[6] = sd->gain >> 4;
751
752 if (i2c_w(gspca_dev, i2cpgain) < 0)
753 goto err;
754 if (i2c_w(gspca_dev, i2cpcolorgain) < 0)
755 goto err;
756 if (i2c_w(gspca_dev, i2cpdoit) < 0)
757 goto err;
758 break;
759 }
677 } 760 }
678 return; 761 return;
679err: 762err:
@@ -684,19 +767,21 @@ static void setgain(struct gspca_dev *gspca_dev)
684{ 767{
685 struct sd *sd = (struct sd *) gspca_dev; 768 struct sd *sd = (struct sd *) gspca_dev;
686 __u8 gain; 769 __u8 gain;
687 __u8 rgb_value; 770 __u8 buf[2] = { 0, 0 };
771
772 if (sensor_data[sd->sensor].flags & F_GAIN) {
773 /* Use the sensor gain to do the actual gain */
774 setsensorgain(gspca_dev);
775 return;
776 }
688 777
689 gain = sd->gain >> 4; 778 gain = sd->gain >> 4;
690 779
691 /* red and blue gain */ 780 /* red and blue gain */
692 rgb_value = gain << 4 | gain; 781 buf[0] = gain << 4 | gain;
693 reg_w(gspca_dev, 0x10, &rgb_value, 1);
694 /* green gain */ 782 /* green gain */
695 rgb_value = gain; 783 buf[1] = gain;
696 reg_w(gspca_dev, 0x11, &rgb_value, 1); 784 reg_w(gspca_dev, 0x10, buf, 2);
697
698 if (sensor_data[sd->sensor].flags & F_GAIN)
699 setsensorgain(gspca_dev);
700} 785}
701 786
702static void setexposure(struct gspca_dev *gspca_dev) 787static void setexposure(struct gspca_dev *gspca_dev)
@@ -704,17 +789,12 @@ static void setexposure(struct gspca_dev *gspca_dev)
704 struct sd *sd = (struct sd *) gspca_dev; 789 struct sd *sd = (struct sd *) gspca_dev;
705 790
706 switch (sd->sensor) { 791 switch (sd->sensor) {
707 case SENSOR_TAS5110: { 792 case SENSOR_TAS5110C:
708 __u8 reg; 793 case SENSOR_TAS5110D: {
709
710 /* register 19's high nibble contains the sn9c10x clock divider 794 /* register 19's high nibble contains the sn9c10x clock divider
711 The high nibble configures the no fps according to the 795 The high nibble configures the no fps according to the
712 formula: 60 / high_nibble. With a maximum of 30 fps */ 796 formula: 60 / high_nibble. With a maximum of 30 fps */
713 reg = 120 * sd->exposure / 1000; 797 __u8 reg = sd->exposure;
714 if (reg < 2)
715 reg = 2;
716 else if (reg > 15)
717 reg = 15;
718 reg = (reg << 4) | 0x0b; 798 reg = (reg << 4) | 0x0b;
719 reg_w(gspca_dev, 0x19, &reg, 1); 799 reg_w(gspca_dev, 0x19, &reg, 1);
720 break; 800 break;
@@ -750,20 +830,21 @@ static void setexposure(struct gspca_dev *gspca_dev)
750 } else 830 } else
751 reg10_max = 0x41; 831 reg10_max = 0x41;
752 832
753 reg11 = (60 * sd->exposure + 999) / 1000; 833 reg11 = (15 * sd->exposure + 999) / 1000;
754 if (reg11 < 1) 834 if (reg11 < 1)
755 reg11 = 1; 835 reg11 = 1;
756 else if (reg11 > 16) 836 else if (reg11 > 16)
757 reg11 = 16; 837 reg11 = 16;
758 838
759 /* In 640x480, if the reg11 has less than 3, the image is 839 /* In 640x480, if the reg11 has less than 4, the image is
760 unstable (not enough bandwidth). */ 840 unstable (the bridge goes into a higher compression mode
761 if (gspca_dev->width == 640 && reg11 < 3) 841 which we have not reverse engineered yet). */
762 reg11 = 3; 842 if (gspca_dev->width == 640 && reg11 < 4)
843 reg11 = 4;
763 844
764 /* frame exposure time in ms = 1000 * reg11 / 30 -> 845 /* frame exposure time in ms = 1000 * reg11 / 30 ->
765 reg10 = sd->exposure * 2 * reg10_max / (1000 * reg11 / 30) */ 846 reg10 = (sd->exposure / 2) * reg10_max / (1000 * reg11 / 30) */
766 reg10 = (sd->exposure * 60 * reg10_max) / (1000 * reg11); 847 reg10 = (sd->exposure * 15 * reg10_max) / (1000 * reg11);
767 848
768 /* Don't allow this to get below 10 when using autogain, the 849 /* Don't allow this to get below 10 when using autogain, the
769 steps become very large (relatively) when below 10 causing 850 steps become very large (relatively) when below 10 causing
@@ -786,10 +867,85 @@ static void setexposure(struct gspca_dev *gspca_dev)
786 if (i2c_w(gspca_dev, i2c) == 0) 867 if (i2c_w(gspca_dev, i2c) == 0)
787 sd->reg11 = reg11; 868 sd->reg11 = reg11;
788 else 869 else
789 PDEBUG(D_ERR, "i2c error exposure"); 870 goto err;
871 break;
872 }
873 case SENSOR_PAS202: {
874 __u8 i2cpframerate[] =
875 {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16};
876 __u8 i2cpexpo[] =
877 {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16};
878 const __u8 i2cpdoit[] =
879 {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16};
880 int framerate_ctrl;
881
882 /* The exposure knee for the autogain algorithm is 200
883 (100 ms / 10 fps on other sensors), for values below this
884 use the control for setting the partial frame expose time,
885 above that use variable framerate. This way we run at max
886 framerate (640x480@7.5 fps, 320x240@10fps) until the knee
887 is reached. Using the variable framerate control above 200
888 is better then playing around with both clockdiv + partial
889 frame exposure times (like we are doing with the ov chips),
890 as that sometimes leads to jumps in the exposure control,
891 which are bad for auto exposure. */
892 if (sd->exposure < 200) {
893 i2cpexpo[3] = 255 - (sd->exposure * 255) / 200;
894 framerate_ctrl = 500;
895 } else {
896 /* The PAS202's exposure control goes from 0 - 4095,
897 but anything below 500 causes vsync issues, so scale
898 our 200-1023 to 500-4095 */
899 framerate_ctrl = (sd->exposure - 200) * 1000 / 229 +
900 500;
901 }
902
903 i2cpframerate[3] = framerate_ctrl >> 6;
904 i2cpframerate[4] = framerate_ctrl & 0x3f;
905 if (i2c_w(gspca_dev, i2cpframerate) < 0)
906 goto err;
907 if (i2c_w(gspca_dev, i2cpexpo) < 0)
908 goto err;
909 if (i2c_w(gspca_dev, i2cpdoit) < 0)
910 goto err;
911 break;
912 }
913 case SENSOR_PAS106: {
914 __u8 i2cpframerate[] =
915 {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14};
916 __u8 i2cpexpo[] =
917 {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14};
918 const __u8 i2cpdoit[] =
919 {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14};
920 int framerate_ctrl;
921
922 /* For values below 150 use partial frame exposure, above
923 that use framerate ctrl */
924 if (sd->exposure < 150) {
925 i2cpexpo[3] = 150 - sd->exposure;
926 framerate_ctrl = 300;
927 } else {
928 /* The PAS106's exposure control goes from 0 - 4095,
929 but anything below 300 causes vsync issues, so scale
930 our 150-1023 to 300-4095 */
931 framerate_ctrl = (sd->exposure - 150) * 1000 / 230 +
932 300;
933 }
934
935 i2cpframerate[3] = framerate_ctrl >> 4;
936 i2cpframerate[4] = framerate_ctrl & 0x0f;
937 if (i2c_w(gspca_dev, i2cpframerate) < 0)
938 goto err;
939 if (i2c_w(gspca_dev, i2cpexpo) < 0)
940 goto err;
941 if (i2c_w(gspca_dev, i2cpdoit) < 0)
942 goto err;
790 break; 943 break;
791 } 944 }
792 } 945 }
946 return;
947err:
948 PDEBUG(D_ERR, "i2c error exposure");
793} 949}
794 950
795static void setfreq(struct gspca_dev *gspca_dev) 951static void setfreq(struct gspca_dev *gspca_dev)
@@ -823,30 +979,43 @@ static void setfreq(struct gspca_dev *gspca_dev)
823 } 979 }
824} 980}
825 981
982#include "coarse_expo_autogain.h"
983
826static void do_autogain(struct gspca_dev *gspca_dev) 984static void do_autogain(struct gspca_dev *gspca_dev)
827{ 985{
828 int deadzone, desired_avg_lum; 986 int deadzone, desired_avg_lum, result;
829 struct sd *sd = (struct sd *) gspca_dev; 987 struct sd *sd = (struct sd *) gspca_dev;
830 int avg_lum = atomic_read(&sd->avg_lum); 988 int avg_lum = atomic_read(&sd->avg_lum);
831 989
832 if (avg_lum == -1) 990 if (avg_lum == -1 || !sd->autogain)
833 return; 991 return;
834 992
993 if (sd->autogain_ignore_frames > 0) {
994 sd->autogain_ignore_frames--;
995 return;
996 }
997
835 /* SIF / VGA sensors have a different autoexposure area and thus 998 /* SIF / VGA sensors have a different autoexposure area and thus
836 different avg_lum values for the same picture brightness */ 999 different avg_lum values for the same picture brightness */
837 if (sensor_data[sd->sensor].flags & F_SIF) { 1000 if (sensor_data[sd->sensor].flags & F_SIF) {
838 deadzone = 1000; 1001 deadzone = 500;
839 desired_avg_lum = 7000; 1002 /* SIF sensors tend to overexpose, so keep this small */
1003 desired_avg_lum = 5000;
840 } else { 1004 } else {
841 deadzone = 3000; 1005 deadzone = 1500;
842 desired_avg_lum = 23000; 1006 desired_avg_lum = 18000;
843 } 1007 }
844 1008
845 if (sd->autogain_ignore_frames > 0) 1009 if (sensor_data[sd->sensor].flags & F_COARSE_EXPO)
846 sd->autogain_ignore_frames--; 1010 result = gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum,
847 else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, 1011 sd->brightness * desired_avg_lum / 127,
848 sd->brightness * desired_avg_lum / 127, 1012 deadzone);
849 deadzone, GAIN_KNEE, EXPOSURE_KNEE)) { 1013 else
1014 result = gspca_auto_gain_n_exposure(gspca_dev, avg_lum,
1015 sd->brightness * desired_avg_lum / 127,
1016 deadzone, GAIN_KNEE, EXPOSURE_KNEE);
1017
1018 if (result) {
850 PDEBUG(D_FRAM, "autogain: gain changed: gain: %d expo: %d", 1019 PDEBUG(D_FRAM, "autogain: gain changed: gain: %d expo: %d",
851 (int)sd->gain, (int)sd->exposure); 1020 (int)sd->gain, (int)sd->exposure);
852 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; 1021 sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES;
@@ -881,7 +1050,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
881 1050
882 sd->brightness = BRIGHTNESS_DEF; 1051 sd->brightness = BRIGHTNESS_DEF;
883 sd->gain = GAIN_DEF; 1052 sd->gain = GAIN_DEF;
884 sd->exposure = EXPOSURE_DEF; 1053 if (sensor_data[sd->sensor].flags & F_COARSE_EXPO) {
1054 sd->exposure = COARSE_EXPOSURE_DEF;
1055 gspca_dev->ctrl_dis |= (1 << EXPOSURE_IDX);
1056 } else {
1057 sd->exposure = EXPOSURE_DEF;
1058 gspca_dev->ctrl_dis |= (1 << COARSE_EXPOSURE_IDX);
1059 }
885 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX)) 1060 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
886 sd->autogain = 0; /* Disable do_autogain callback */ 1061 sd->autogain = 0; /* Disable do_autogain callback */
887 else 1062 else
@@ -917,9 +1092,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
917 reg12_19[6] = sn9c10x[0x18 - 1] | (mode << 4); 1092 reg12_19[6] = sn9c10x[0x18 - 1] | (mode << 4);
918 /* Special cases where reg 17 and or 19 value depends on mode */ 1093 /* Special cases where reg 17 and or 19 value depends on mode */
919 switch (sd->sensor) { 1094 switch (sd->sensor) {
920 case SENSOR_PAS202:
921 reg12_19[5] = mode ? 0x24 : 0x20;
922 break;
923 case SENSOR_TAS5130CXX: 1095 case SENSOR_TAS5130CXX:
924 /* probably not mode specific at all most likely the upper 1096 /* probably not mode specific at all most likely the upper
925 nibble of 0x19 is exposure (clock divider) just as with 1097 nibble of 0x19 is exposure (clock divider) just as with
@@ -955,6 +1127,16 @@ static int sd_start(struct gspca_dev *gspca_dev)
955 sensor_data[sd->sensor].sensor_bridge_init_size[ 1127 sensor_data[sd->sensor].sensor_bridge_init_size[
956 sd->bridge]); 1128 sd->bridge]);
957 1129
1130 /* Mode specific sensor setup */
1131 switch (sd->sensor) {
1132 case SENSOR_PAS202: {
1133 const __u8 i2cpclockdiv[] =
1134 {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10};
1135 /* clockdiv from 4 to 3 (7.5 -> 10 fps) when in low res mode */
1136 if (mode)
1137 i2c_w(gspca_dev, i2cpclockdiv);
1138 }
1139 }
958 /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */ 1140 /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */
959 reg_w(gspca_dev, 0x15, &reg12_19[3], 2); 1141 reg_w(gspca_dev, 0x15, &reg12_19[3], 2);
960 /* compression register */ 1142 /* compression register */
@@ -985,6 +1167,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
985 1167
986 sd->frames_to_drop = 0; 1168 sd->frames_to_drop = 0;
987 sd->autogain_ignore_frames = 0; 1169 sd->autogain_ignore_frames = 0;
1170 sd->exp_too_high_cnt = 0;
1171 sd->exp_too_low_cnt = 0;
988 atomic_set(&sd->avg_lum, -1); 1172 atomic_set(&sd->avg_lum, -1);
989 return 0; 1173 return 0;
990} 1174}
@@ -1143,11 +1327,14 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
1143 struct sd *sd = (struct sd *) gspca_dev; 1327 struct sd *sd = (struct sd *) gspca_dev;
1144 1328
1145 sd->autogain = val; 1329 sd->autogain = val;
1330 sd->exp_too_high_cnt = 0;
1331 sd->exp_too_low_cnt = 0;
1332
1146 /* when switching to autogain set defaults to make sure 1333 /* when switching to autogain set defaults to make sure
1147 we are on a valid point of the autogain gain / 1334 we are on a valid point of the autogain gain /
1148 exposure knee graph, and give this change time to 1335 exposure knee graph, and give this change time to
1149 take effect before doing autogain. */ 1336 take effect before doing autogain. */
1150 if (sd->autogain) { 1337 if (sd->autogain && !(sensor_data[sd->sensor].flags & F_COARSE_EXPO)) {
1151 sd->exposure = EXPOSURE_DEF; 1338 sd->exposure = EXPOSURE_DEF;
1152 sd->gain = GAIN_DEF; 1339 sd->gain = GAIN_DEF;
1153 if (gspca_dev->streaming) { 1340 if (gspca_dev->streaming) {
@@ -1207,6 +1394,25 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
1207 return -EINVAL; 1394 return -EINVAL;
1208} 1395}
1209 1396
1397#ifdef CONFIG_INPUT
1398static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
1399 u8 *data, /* interrupt packet data */
1400 int len) /* interrupt packet length */
1401{
1402 int ret = -EINVAL;
1403
1404 if (len == 1 && data[0] == 1) {
1405 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
1406 input_sync(gspca_dev->input_dev);
1407 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
1408 input_sync(gspca_dev->input_dev);
1409 ret = 0;
1410 }
1411
1412 return ret;
1413}
1414#endif
1415
1210/* sub-driver description */ 1416/* sub-driver description */
1211static const struct sd_desc sd_desc = { 1417static const struct sd_desc sd_desc = {
1212 .name = MODULE_NAME, 1418 .name = MODULE_NAME,
@@ -1219,6 +1425,9 @@ static const struct sd_desc sd_desc = {
1219 .pkt_scan = sd_pkt_scan, 1425 .pkt_scan = sd_pkt_scan,
1220 .querymenu = sd_querymenu, 1426 .querymenu = sd_querymenu,
1221 .dq_callback = do_autogain, 1427 .dq_callback = do_autogain,
1428#ifdef CONFIG_INPUT
1429 .int_pkt_scan = sd_int_pkt_scan,
1430#endif
1222}; 1431};
1223 1432
1224/* -- module initialisation -- */ 1433/* -- module initialisation -- */
@@ -1227,21 +1436,21 @@ static const struct sd_desc sd_desc = {
1227 1436
1228 1437
1229static const struct usb_device_id device_table[] __devinitconst = { 1438static const struct usb_device_id device_table[] __devinitconst = {
1230 {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110, 102)}, /* TAS5110C1B */ 1439 {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */
1231 {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110, 101)}, /* TAS5110C1B */ 1440 {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */
1232#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 1441#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1233 {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110, 101)}, /* TAS5110D */ 1442 {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */
1443#endif
1234 {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)}, 1444 {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)},
1235 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)}, 1445 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)},
1236#endif
1237 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)}, 1446 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)},
1238#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 1447#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1239 {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)}, 1448 {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)},
1240 {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)}, 1449 {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)},
1241 {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)}, 1450 {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)},
1451#endif
1242 {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)}, 1452 {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)},
1243 {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)}, 1453 {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)},
1244#endif
1245 {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)}, 1454 {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)},
1246 {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)}, 1455 {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)},
1247#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 1456#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index 0bd36a00dd2a..83d5773d4629 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -21,6 +21,7 @@
21 21
22#define MODULE_NAME "sonixj" 22#define MODULE_NAME "sonixj"
23 23
24#include <linux/input.h>
24#include "gspca.h" 25#include "gspca.h"
25#include "jpeg.h" 26#include "jpeg.h"
26 27
@@ -45,6 +46,7 @@ struct sd {
45 u8 red; 46 u8 red;
46 u8 gamma; 47 u8 gamma;
47 u8 vflip; /* ov7630/ov7648 only */ 48 u8 vflip; /* ov7630/ov7648 only */
49 u8 sharpness;
48 u8 infrared; /* mt9v111 only */ 50 u8 infrared; /* mt9v111 only */
49 u8 freq; /* ov76xx only */ 51 u8 freq; /* ov76xx only */
50 u8 quality; /* image quality */ 52 u8 quality; /* image quality */
@@ -64,16 +66,17 @@ struct sd {
64#define BRIDGE_SN9C110 2 66#define BRIDGE_SN9C110 2
65#define BRIDGE_SN9C120 3 67#define BRIDGE_SN9C120 3
66 u8 sensor; /* Type of image sensor chip */ 68 u8 sensor; /* Type of image sensor chip */
67#define SENSOR_HV7131R 0 69#define SENSOR_ADCM1700 0
68#define SENSOR_MI0360 1 70#define SENSOR_HV7131R 1
69#define SENSOR_MO4000 2 71#define SENSOR_MI0360 2
70#define SENSOR_MT9V111 3 72#define SENSOR_MO4000 3
71#define SENSOR_OM6802 4 73#define SENSOR_MT9V111 4
72#define SENSOR_OV7630 5 74#define SENSOR_OM6802 5
73#define SENSOR_OV7648 6 75#define SENSOR_OV7630 6
74#define SENSOR_OV7660 7 76#define SENSOR_OV7648 7
75#define SENSOR_PO1030 8 77#define SENSOR_OV7660 8
76#define SENSOR_SP80708 9 78#define SENSOR_PO1030 9
79#define SENSOR_SP80708 10
77 u8 i2c_addr; 80 u8 i2c_addr;
78 81
79 u8 *jpeg_hdr; 82 u8 *jpeg_hdr;
@@ -96,12 +99,14 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
96static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); 99static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
97static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); 100static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
98static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); 101static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
102static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
103static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
99static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val); 104static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
100static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val); 105static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
101static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); 106static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
102static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); 107static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
103 108
104static struct ctrl sd_ctrls[] = { 109static const struct ctrl sd_ctrls[] = {
105#define BRIGHTNESS_IDX 0 110#define BRIGHTNESS_IDX 0
106 { 111 {
107 { 112 {
@@ -225,8 +230,23 @@ static struct ctrl sd_ctrls[] = {
225 .set = sd_setvflip, 230 .set = sd_setvflip,
226 .get = sd_getvflip, 231 .get = sd_getvflip,
227 }, 232 },
233#define SHARPNESS_IDX 8
234 {
235 {
236 .id = V4L2_CID_SHARPNESS,
237 .type = V4L2_CTRL_TYPE_INTEGER,
238 .name = "Sharpness",
239 .minimum = 0,
240 .maximum = 255,
241 .step = 1,
242#define SHARPNESS_DEF 90
243 .default_value = SHARPNESS_DEF,
244 },
245 .set = sd_setsharpness,
246 .get = sd_getsharpness,
247 },
228/* mt9v111 only */ 248/* mt9v111 only */
229#define INFRARED_IDX 8 249#define INFRARED_IDX 9
230 { 250 {
231 { 251 {
232 .id = V4L2_CID_INFRARED, 252 .id = V4L2_CID_INFRARED,
@@ -242,7 +262,7 @@ static struct ctrl sd_ctrls[] = {
242 .get = sd_getinfrared, 262 .get = sd_getinfrared,
243 }, 263 },
244/* ov7630/ov7648/ov7660 only */ 264/* ov7630/ov7648/ov7660 only */
245#define FREQ_IDX 9 265#define FREQ_IDX 10
246 { 266 {
247 { 267 {
248 .id = V4L2_CID_POWER_LINE_FREQUENCY, 268 .id = V4L2_CID_POWER_LINE_FREQUENCY,
@@ -261,28 +281,37 @@ static struct ctrl sd_ctrls[] = {
261 281
262/* table of the disabled controls */ 282/* table of the disabled controls */
263static __u32 ctrl_dis[] = { 283static __u32 ctrl_dis[] = {
284 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX) |
285 (1 << AUTOGAIN_IDX), /* SENSOR_ADCM1700 0 */
286 (1 << INFRARED_IDX) | (1 << FREQ_IDX),
287 /* SENSOR_HV7131R 1 */
264 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), 288 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
265 /* SENSOR_HV7131R 0 */ 289 /* SENSOR_MI0360 2 */
266 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), 290 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
267 /* SENSOR_MI0360 1 */ 291 /* SENSOR_MO4000 3 */
268 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
269 /* SENSOR_MO4000 2 */
270 (1 << VFLIP_IDX) | (1 << FREQ_IDX), 292 (1 << VFLIP_IDX) | (1 << FREQ_IDX),
271 /* SENSOR_MT9V111 3 */ 293 /* SENSOR_MT9V111 4 */
272 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), 294 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
273 /* SENSOR_OM6802 4 */ 295 /* SENSOR_OM6802 5 */
274 (1 << INFRARED_IDX), 296 (1 << INFRARED_IDX),
275 /* SENSOR_OV7630 5 */ 297 /* SENSOR_OV7630 6 */
276 (1 << INFRARED_IDX), 298 (1 << INFRARED_IDX),
277 /* SENSOR_OV7648 6 */ 299 /* SENSOR_OV7648 7 */
278 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX), 300 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
279 /* SENSOR_OV7660 7 */ 301 /* SENSOR_OV7660 8 */
280 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | 302 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
281 (1 << FREQ_IDX), /* SENSOR_PO1030 8 */ 303 (1 << FREQ_IDX), /* SENSOR_PO1030 9 */
282 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | 304 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
283 (1 << FREQ_IDX), /* SENSOR_SP80708 9 */ 305 (1 << FREQ_IDX), /* SENSOR_SP80708 10 */
284}; 306};
285 307
308static const struct v4l2_pix_format cif_mode[] = {
309 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
310 .bytesperline = 352,
311 .sizeimage = 352 * 288 * 4 / 8 + 590,
312 .colorspace = V4L2_COLORSPACE_JPEG,
313 .priv = 0},
314};
286static const struct v4l2_pix_format vga_mode[] = { 315static const struct v4l2_pix_format vga_mode[] = {
287 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 316 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
288 .bytesperline = 160, 317 .bytesperline = 160,
@@ -302,6 +331,17 @@ static const struct v4l2_pix_format vga_mode[] = {
302 .priv = 0}, 331 .priv = 0},
303}; 332};
304 333
334static const u8 sn_adcm1700[0x1c] = {
335/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
336 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
337/* reg8 reg9 rega regb regc regd rege regf */
338 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
339/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
340 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
341/* reg18 reg19 reg1a reg1b */
342 0x06, 0x00, 0x00, 0x00
343};
344
305/*Data from sn9c102p+hv7131r */ 345/*Data from sn9c102p+hv7131r */
306static const u8 sn_hv7131[0x1c] = { 346static const u8 sn_hv7131[0x1c] = {
307/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ 347/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
@@ -415,6 +455,7 @@ static const u8 sn_sp80708[0x1c] = {
415 455
416/* sequence specific to the sensors - !! index = SENSOR_xxx */ 456/* sequence specific to the sensors - !! index = SENSOR_xxx */
417static const u8 *sn_tb[] = { 457static const u8 *sn_tb[] = {
458 sn_adcm1700,
418 sn_hv7131, 459 sn_hv7131,
419 sn_mi0360, 460 sn_mi0360,
420 sn_mo4000, 461 sn_mo4000,
@@ -432,6 +473,11 @@ static const u8 gamma_def[17] = {
432 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99, 473 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
433 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff 474 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
434}; 475};
476/* gamma for sensor ADCM1700 */
477static const u8 gamma_spec_0[17] = {
478 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
479 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
480};
435/* gamma for sensors HV7131R and MT9V111 */ 481/* gamma for sensors HV7131R and MT9V111 */
436static const u8 gamma_spec_1[17] = { 482static const u8 gamma_spec_1[17] = {
437 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d, 483 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
@@ -450,6 +496,42 @@ static const u8 reg84[] = {
450 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */ 496 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
451 0x00, 0x00, 0x00 /* YUV offsets */ 497 0x00, 0x00, 0x00 /* YUV offsets */
452}; 498};
499static const u8 adcm1700_sensor_init[][8] = {
500 {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
501 {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
502 {0xdd, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
503 {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
504 {0xdd, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
505 {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
506 {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
507 {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
508 {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
509 {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
510 {0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
511 {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
512 {0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
513 {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
514 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
515 {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
516 {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
517 {}
518};
519static const u8 adcm1700_sensor_param1[][8] = {
520 {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
521 {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
522
523 {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
524 {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
525 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
526 {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
527 {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
528
529 {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
530 {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
531 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
532 {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
533 {}
534};
453static const u8 hv7131r_sensor_init[][8] = { 535static const u8 hv7131r_sensor_init[][8] = {
454 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10}, 536 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
455 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10}, 537 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
@@ -986,17 +1068,18 @@ static const u8 sp80708_sensor_param1[][8] = {
986 {} 1068 {}
987}; 1069};
988 1070
989static const u8 (*sensor_init[10])[8] = { 1071static const u8 (*sensor_init[11])[8] = {
990 hv7131r_sensor_init, /* HV7131R 0 */ 1072 adcm1700_sensor_init, /* ADCM1700 0 */
991 mi0360_sensor_init, /* MI0360 1 */ 1073 hv7131r_sensor_init, /* HV7131R 1 */
992 mo4000_sensor_init, /* MO4000 2 */ 1074 mi0360_sensor_init, /* MI0360 2 */
993 mt9v111_sensor_init, /* MT9V111 3 */ 1075 mo4000_sensor_init, /* MO4000 3 */
994 om6802_sensor_init, /* OM6802 4 */ 1076 mt9v111_sensor_init, /* MT9V111 4 */
995 ov7630_sensor_init, /* OV7630 5 */ 1077 om6802_sensor_init, /* OM6802 5 */
996 ov7648_sensor_init, /* OV7648 6 */ 1078 ov7630_sensor_init, /* OV7630 6 */
997 ov7660_sensor_init, /* OV7660 7 */ 1079 ov7648_sensor_init, /* OV7648 7 */
998 po1030_sensor_init, /* PO1030 8 */ 1080 ov7660_sensor_init, /* OV7660 8 */
999 sp80708_sensor_init, /* SP80708 9 */ 1081 po1030_sensor_init, /* PO1030 9 */
1082 sp80708_sensor_init, /* SP80708 10 */
1000}; 1083};
1001 1084
1002/* read <len> bytes to gspca_dev->usb_buf */ 1085/* read <len> bytes to gspca_dev->usb_buf */
@@ -1064,6 +1147,7 @@ static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
1064 1147
1065 PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val); 1148 PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
1066 switch (sd->sensor) { 1149 switch (sd->sensor) {
1150 case SENSOR_ADCM1700:
1067 case SENSOR_OM6802: /* i2c command = a0 (100 kHz) */ 1151 case SENSOR_OM6802: /* i2c command = a0 (100 kHz) */
1068 gspca_dev->usb_buf[0] = 0x80 | (2 << 4); 1152 gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
1069 break; 1153 break;
@@ -1110,6 +1194,7 @@ static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
1110 u8 mode[8]; 1194 u8 mode[8];
1111 1195
1112 switch (sd->sensor) { 1196 switch (sd->sensor) {
1197 case SENSOR_ADCM1700:
1113 case SENSOR_OM6802: /* i2c command = 90 (100 kHz) */ 1198 case SENSOR_OM6802: /* i2c command = 90 (100 kHz) */
1114 mode[0] = 0x80 | 0x10; 1199 mode[0] = 0x80 | 0x10;
1115 break; 1200 break;
@@ -1260,7 +1345,8 @@ static void bridge_init(struct gspca_dev *gspca_dev,
1260 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20}; 1345 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
1261 static const u8 regd4[] = {0x60, 0x00, 0x00}; 1346 static const u8 regd4[] = {0x60, 0x00, 0x00};
1262 1347
1263 reg_w1(gspca_dev, 0xf1, 0x00); 1348 /* sensor clock already enabled in sd_init */
1349 /* reg_w1(gspca_dev, 0xf1, 0x00); */
1264 reg_w1(gspca_dev, 0x01, sn9c1xx[1]); 1350 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1265 1351
1266 /* configure gpio */ 1352 /* configure gpio */
@@ -1284,6 +1370,12 @@ static void bridge_init(struct gspca_dev *gspca_dev,
1284 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f); 1370 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
1285 1371
1286 switch (sd->sensor) { 1372 switch (sd->sensor) {
1373 case SENSOR_ADCM1700:
1374 reg_w1(gspca_dev, 0x01, 0x43);
1375 reg_w1(gspca_dev, 0x17, 0x62);
1376 reg_w1(gspca_dev, 0x01, 0x42);
1377 reg_w1(gspca_dev, 0x01, 0x42);
1378 break;
1287 case SENSOR_MT9V111: 1379 case SENSOR_MT9V111:
1288 reg_w1(gspca_dev, 0x01, 0x61); 1380 reg_w1(gspca_dev, 0x01, 0x61);
1289 reg_w1(gspca_dev, 0x17, 0x61); 1381 reg_w1(gspca_dev, 0x17, 0x61);
@@ -1357,14 +1449,19 @@ static int sd_config(struct gspca_dev *gspca_dev,
1357 struct sd *sd = (struct sd *) gspca_dev; 1449 struct sd *sd = (struct sd *) gspca_dev;
1358 struct cam *cam; 1450 struct cam *cam;
1359 1451
1360 cam = &gspca_dev->cam;
1361 cam->cam_mode = vga_mode;
1362 cam->nmodes = ARRAY_SIZE(vga_mode);
1363 cam->npkt = 24; /* 24 packets per ISOC message */
1364
1365 sd->bridge = id->driver_info >> 16; 1452 sd->bridge = id->driver_info >> 16;
1366 sd->sensor = id->driver_info; 1453 sd->sensor = id->driver_info;
1367 1454
1455 cam = &gspca_dev->cam;
1456 if (sd->sensor == SENSOR_ADCM1700) {
1457 cam->cam_mode = cif_mode;
1458 cam->nmodes = ARRAY_SIZE(cif_mode);
1459 } else {
1460 cam->cam_mode = vga_mode;
1461 cam->nmodes = ARRAY_SIZE(vga_mode);
1462 }
1463 cam->npkt = 24; /* 24 packets per ISOC message */
1464
1368 sd->brightness = BRIGHTNESS_DEF; 1465 sd->brightness = BRIGHTNESS_DEF;
1369 sd->contrast = CONTRAST_DEF; 1466 sd->contrast = CONTRAST_DEF;
1370 sd->colors = COLOR_DEF; 1467 sd->colors = COLOR_DEF;
@@ -1374,6 +1471,14 @@ static int sd_config(struct gspca_dev *gspca_dev,
1374 sd->autogain = AUTOGAIN_DEF; 1471 sd->autogain = AUTOGAIN_DEF;
1375 sd->ag_cnt = -1; 1472 sd->ag_cnt = -1;
1376 sd->vflip = VFLIP_DEF; 1473 sd->vflip = VFLIP_DEF;
1474 switch (sd->sensor) {
1475 case SENSOR_OM6802:
1476 sd->sharpness = 0x10;
1477 break;
1478 default:
1479 sd->sharpness = SHARPNESS_DEF;
1480 break;
1481 }
1377 sd->infrared = INFRARED_DEF; 1482 sd->infrared = INFRARED_DEF;
1378 sd->freq = FREQ_DEF; 1483 sd->freq = FREQ_DEF;
1379 sd->quality = QUALITY_DEF; 1484 sd->quality = QUALITY_DEF;
@@ -1433,7 +1538,9 @@ static int sd_init(struct gspca_dev *gspca_dev)
1433 break; 1538 break;
1434 } 1539 }
1435 1540
1436 reg_w1(gspca_dev, 0xf1, 0x01); 1541 /* Note we do not disable the sensor clock here (power saving mode),
1542 as that also disables the button on the cam. */
1543 reg_w1(gspca_dev, 0xf1, 0x00);
1437 1544
1438 /* set the i2c address */ 1545 /* set the i2c address */
1439 sn9c1xx = sn_tb[sd->sensor]; 1546 sn9c1xx = sn_tb[sd->sensor];
@@ -1543,6 +1650,10 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1543 1650
1544 k2 = ((int) sd->brightness - 0x8000) >> 10; 1651 k2 = ((int) sd->brightness - 0x8000) >> 10;
1545 switch (sd->sensor) { 1652 switch (sd->sensor) {
1653 case SENSOR_ADCM1700:
1654 if (k2 > 0x1f)
1655 k2 = 0; /* only positive Y offset */
1656 break;
1546 case SENSOR_HV7131R: 1657 case SENSOR_HV7131R:
1547 expo = sd->brightness << 4; 1658 expo = sd->brightness << 4;
1548 if (expo > 0x002dc6c0) 1659 if (expo > 0x002dc6c0)
@@ -1625,6 +1736,9 @@ static void setgamma(struct gspca_dev *gspca_dev)
1625 }; 1736 };
1626 1737
1627 switch (sd->sensor) { 1738 switch (sd->sensor) {
1739 case SENSOR_ADCM1700:
1740 gamma_base = gamma_spec_0;
1741 break;
1628 case SENSOR_HV7131R: 1742 case SENSOR_HV7131R:
1629 case SENSOR_MT9V111: 1743 case SENSOR_MT9V111:
1630 gamma_base = gamma_spec_1; 1744 gamma_base = gamma_spec_1;
@@ -1670,23 +1784,39 @@ static void setautogain(struct gspca_dev *gspca_dev)
1670 sd->ag_cnt = -1; 1784 sd->ag_cnt = -1;
1671} 1785}
1672 1786
1673/* ov7630/ov7648 only */ 1787/* hv7131r/ov7630/ov7648 only */
1674static void setvflip(struct sd *sd) 1788static void setvflip(struct sd *sd)
1675{ 1789{
1676 u8 comn; 1790 u8 comn;
1677 1791
1678 if (sd->gspca_dev.ctrl_dis & (1 << VFLIP_IDX)) 1792 if (sd->gspca_dev.ctrl_dis & (1 << VFLIP_IDX))
1679 return; 1793 return;
1680 if (sd->sensor == SENSOR_OV7630) { 1794 switch (sd->sensor) {
1795 case SENSOR_HV7131R:
1796 comn = 0x18; /* clkdiv = 1, ablcen = 1 */
1797 if (sd->vflip)
1798 comn |= 0x01;
1799 i2c_w1(&sd->gspca_dev, 0x01, comn); /* sctra */
1800 break;
1801 case SENSOR_OV7630:
1681 comn = 0x02; 1802 comn = 0x02;
1682 if (!sd->vflip) 1803 if (!sd->vflip)
1683 comn |= 0x80; 1804 comn |= 0x80;
1684 } else { 1805 i2c_w1(&sd->gspca_dev, 0x75, comn);
1806 break;
1807 default:
1808/* case SENSOR_OV7648: */
1685 comn = 0x06; 1809 comn = 0x06;
1686 if (sd->vflip) 1810 if (sd->vflip)
1687 comn |= 0x80; 1811 comn |= 0x80;
1812 i2c_w1(&sd->gspca_dev, 0x75, comn);
1813 break;
1688 } 1814 }
1689 i2c_w1(&sd->gspca_dev, 0x75, comn); 1815}
1816
1817static void setsharpness(struct sd *sd)
1818{
1819 reg_w1(&sd->gspca_dev, 0x99, sd->sharpness);
1690} 1820}
1691 1821
1692static void setinfrared(struct sd *sd) 1822static void setinfrared(struct sd *sd)
@@ -1804,6 +1934,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
1804 int mode; 1934 int mode;
1805 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f }; 1935 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
1806 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec }; 1936 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
1937 static const u8 CA_adcm1700[] =
1938 { 0x14, 0xec, 0x0a, 0xf6 };
1807 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */ 1939 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
1808 static const u8 CE_ov76xx[] = 1940 static const u8 CE_ov76xx[] =
1809 { 0x32, 0xdd, 0x32, 0xdd }; 1941 { 0x32, 0xdd, 0x32, 0xdd };
@@ -1824,6 +1956,9 @@ static int sd_start(struct gspca_dev *gspca_dev)
1824 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]); 1956 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
1825 1957
1826 switch (sd->sensor) { 1958 switch (sd->sensor) {
1959 case SENSOR_ADCM1700:
1960 reg2 = 0x60;
1961 break;
1827 case SENSOR_OM6802: 1962 case SENSOR_OM6802:
1828 reg2 = 0x71; 1963 reg2 = 0x71;
1829 break; 1964 break;
@@ -1842,17 +1977,28 @@ static int sd_start(struct gspca_dev *gspca_dev)
1842 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]); 1977 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
1843 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]); 1978 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
1844 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]); 1979 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1845 reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */ 1980 if (sd->sensor == SENSOR_ADCM1700) {
1846 reg_w1(gspca_dev, 0xd3, 0x50); 1981 reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
1982 reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
1983 } else {
1984 reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
1985 reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
1986 }
1847 reg_w1(gspca_dev, 0xc6, 0x00); 1987 reg_w1(gspca_dev, 0xc6, 0x00);
1848 reg_w1(gspca_dev, 0xc7, 0x00); 1988 reg_w1(gspca_dev, 0xc7, 0x00);
1849 reg_w1(gspca_dev, 0xc8, 0x50); 1989 if (sd->sensor == SENSOR_ADCM1700) {
1850 reg_w1(gspca_dev, 0xc9, 0x3c); 1990 reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
1991 reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
1992 } else {
1993 reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
1994 reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
1995 }
1851 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]); 1996 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1852 switch (sd->sensor) { 1997 switch (sd->sensor) {
1853 case SENSOR_MT9V111: 1998 case SENSOR_MT9V111:
1854 reg17 = 0xe0; 1999 reg17 = 0xe0;
1855 break; 2000 break;
2001 case SENSOR_ADCM1700:
1856 case SENSOR_OV7630: 2002 case SENSOR_OV7630:
1857 reg17 = 0xe2; 2003 reg17 = 0xe2;
1858 break; 2004 break;
@@ -1870,44 +2016,39 @@ static int sd_start(struct gspca_dev *gspca_dev)
1870 break; 2016 break;
1871 } 2017 }
1872 reg_w1(gspca_dev, 0x17, reg17); 2018 reg_w1(gspca_dev, 0x17, reg17);
1873/* set reg1 was here */ 2019
1874 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */ 2020 reg_w1(gspca_dev, 0x05, 0x00); /* red */
1875 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */ 2021 reg_w1(gspca_dev, 0x07, 0x00); /* green */
1876 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */ 2022 reg_w1(gspca_dev, 0x06, 0x00); /* blue */
1877 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]); 2023 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
1878 2024
1879 setgamma(gspca_dev); 2025 setgamma(gspca_dev);
1880 2026
2027/*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
1881 for (i = 0; i < 8; i++) 2028 for (i = 0; i < 8; i++)
1882 reg_w(gspca_dev, 0x84, reg84, sizeof reg84); 2029 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1883 switch (sd->sensor) { 2030 switch (sd->sensor) {
2031 case SENSOR_ADCM1700:
2032 case SENSOR_OV7660:
2033 case SENSOR_SP80708:
2034 reg_w1(gspca_dev, 0x9a, 0x05);
2035 break;
1884 case SENSOR_MT9V111: 2036 case SENSOR_MT9V111:
1885 reg_w1(gspca_dev, 0x9a, 0x07); 2037 reg_w1(gspca_dev, 0x9a, 0x07);
1886 reg_w1(gspca_dev, 0x99, 0x59);
1887 break;
1888 case SENSOR_OM6802:
1889 reg_w1(gspca_dev, 0x9a, 0x08);
1890 reg_w1(gspca_dev, 0x99, 0x10);
1891 break; 2038 break;
1892 case SENSOR_OV7648: 2039 case SENSOR_OV7648:
1893 reg_w1(gspca_dev, 0x9a, 0x0a); 2040 reg_w1(gspca_dev, 0x9a, 0x0a);
1894 reg_w1(gspca_dev, 0x99, 0x60);
1895 break;
1896 case SENSOR_OV7660:
1897 case SENSOR_SP80708:
1898 reg_w1(gspca_dev, 0x9a, 0x05);
1899 reg_w1(gspca_dev, 0x99, 0x59);
1900 break; 2041 break;
1901 default: 2042 default:
1902 reg_w1(gspca_dev, 0x9a, 0x08); 2043 reg_w1(gspca_dev, 0x9a, 0x08);
1903 reg_w1(gspca_dev, 0x99, 0x59);
1904 break; 2044 break;
1905 } 2045 }
2046 setsharpness(sd);
1906 2047
1907 reg_w(gspca_dev, 0x84, reg84, sizeof reg84); 2048 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1908 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */ 2049 reg_w1(gspca_dev, 0x05, 0x20); /* red */
1909 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */ 2050 reg_w1(gspca_dev, 0x07, 0x20); /* green */
1910 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */ 2051 reg_w1(gspca_dev, 0x06, 0x20); /* blue */
1911 2052
1912 init = NULL; 2053 init = NULL;
1913 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; 2054 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
@@ -1917,6 +2058,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
1917 reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */ 2058 reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
1918 reg17 = 0x61; /* 0x:20: enable sensor clock */ 2059 reg17 = 0x61; /* 0x:20: enable sensor clock */
1919 switch (sd->sensor) { 2060 switch (sd->sensor) {
2061 case SENSOR_ADCM1700:
2062 init = adcm1700_sensor_param1;
2063 reg1 = 0x46;
2064 reg17 = 0xe2;
2065 break;
1920 case SENSOR_MO4000: 2066 case SENSOR_MO4000:
1921 if (mode) { 2067 if (mode) {
1922/* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */ 2068/* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
@@ -1940,7 +2086,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
1940 reg17 = 0x64; /* 640 MCKSIZE */ 2086 reg17 = 0x64; /* 640 MCKSIZE */
1941 break; 2087 break;
1942 case SENSOR_OV7630: 2088 case SENSOR_OV7630:
1943 setvflip(sd);
1944 reg17 = 0xe2; 2089 reg17 = 0xe2;
1945 reg1 = 0x44; 2090 reg1 = 0x44;
1946 break; 2091 break;
@@ -1986,8 +2131,12 @@ static int sd_start(struct gspca_dev *gspca_dev)
1986 } 2131 }
1987 2132
1988 reg_w(gspca_dev, 0xc0, C0, 6); 2133 reg_w(gspca_dev, 0xc0, C0, 6);
1989 reg_w(gspca_dev, 0xca, CA, 4); 2134 if (sd->sensor == SENSOR_ADCM1700)
2135 reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
2136 else
2137 reg_w(gspca_dev, 0xca, CA, 4);
1990 switch (sd->sensor) { 2138 switch (sd->sensor) {
2139 case SENSOR_ADCM1700:
1991 case SENSOR_OV7630: 2140 case SENSOR_OV7630:
1992 case SENSOR_OV7648: 2141 case SENSOR_OV7648:
1993 case SENSOR_OV7660: 2142 case SENSOR_OV7660:
@@ -2008,11 +2157,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
2008 reg_w1(gspca_dev, 0x17, reg17); 2157 reg_w1(gspca_dev, 0x17, reg17);
2009 reg_w1(gspca_dev, 0x01, reg1); 2158 reg_w1(gspca_dev, 0x01, reg1);
2010 2159
2011 switch (sd->sensor) { 2160 setvflip(sd);
2012 case SENSOR_OV7630:
2013 setvflip(sd);
2014 break;
2015 }
2016 setbrightness(gspca_dev); 2161 setbrightness(gspca_dev);
2017 setcontrast(gspca_dev); 2162 setcontrast(gspca_dev);
2018 setautogain(gspca_dev); 2163 setautogain(gspca_dev);
@@ -2056,7 +2201,8 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
2056 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]); 2201 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
2057 reg_w1(gspca_dev, 0x01, sn9c1xx[1]); 2202 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
2058 reg_w1(gspca_dev, 0x01, data); 2203 reg_w1(gspca_dev, 0x01, data);
2059 reg_w1(gspca_dev, 0xf1, 0x00); 2204 /* Don't disable sensor clock as that disables the button on the cam */
2205 /* reg_w1(gspca_dev, 0xf1, 0x01); */
2060} 2206}
2061 2207
2062static void sd_stop0(struct gspca_dev *gspca_dev) 2208static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -2288,6 +2434,24 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
2288 return 0; 2434 return 0;
2289} 2435}
2290 2436
2437static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
2438{
2439 struct sd *sd = (struct sd *) gspca_dev;
2440
2441 sd->sharpness = val;
2442 if (gspca_dev->streaming)
2443 setsharpness(sd);
2444 return 0;
2445}
2446
2447static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
2448{
2449 struct sd *sd = (struct sd *) gspca_dev;
2450
2451 *val = sd->sharpness;
2452 return 0;
2453}
2454
2291static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) 2455static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2292{ 2456{
2293 struct sd *sd = (struct sd *) gspca_dev; 2457 struct sd *sd = (struct sd *) gspca_dev;
@@ -2391,6 +2555,25 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
2391 return -EINVAL; 2555 return -EINVAL;
2392} 2556}
2393 2557
2558#ifdef CONFIG_INPUT
2559static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
2560 u8 *data, /* interrupt packet data */
2561 int len) /* interrupt packet length */
2562{
2563 int ret = -EINVAL;
2564
2565 if (len == 1 && data[0] == 1) {
2566 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
2567 input_sync(gspca_dev->input_dev);
2568 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
2569 input_sync(gspca_dev->input_dev);
2570 ret = 0;
2571 }
2572
2573 return ret;
2574}
2575#endif
2576
2394/* sub-driver description */ 2577/* sub-driver description */
2395static const struct sd_desc sd_desc = { 2578static const struct sd_desc sd_desc = {
2396 .name = MODULE_NAME, 2579 .name = MODULE_NAME,
@@ -2406,6 +2589,9 @@ static const struct sd_desc sd_desc = {
2406 .get_jcomp = sd_get_jcomp, 2589 .get_jcomp = sd_get_jcomp,
2407 .set_jcomp = sd_set_jcomp, 2590 .set_jcomp = sd_set_jcomp,
2408 .querymenu = sd_querymenu, 2591 .querymenu = sd_querymenu,
2592#ifdef CONFIG_INPUT
2593 .int_pkt_scan = sd_int_pkt_scan,
2594#endif
2409}; 2595};
2410 2596
2411/* -- module initialisation -- */ 2597/* -- module initialisation -- */
@@ -2472,6 +2658,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
2472/* {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, *sn9c120b*/ 2658/* {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, *sn9c120b*/
2473 {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/ 2659 {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
2474 {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/ 2660 {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
2661 {USB_DEVICE(0x0c45, 0x614a), BS(SN9C120, ADCM1700)}, /*sn9c120b*/
2475 {} 2662 {}
2476}; 2663};
2477MODULE_DEVICE_TABLE(usb, device_table); 2664MODULE_DEVICE_TABLE(usb, device_table);
diff --git a/drivers/media/video/gspca/spca500.c b/drivers/media/video/gspca/spca500.c
index fe46868a87f2..b866c73c97db 100644
--- a/drivers/media/video/gspca/spca500.c
+++ b/drivers/media/video/gspca/spca500.c
@@ -68,7 +68,7 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
68static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); 68static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
69static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); 69static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
70 70
71static struct ctrl sd_ctrls[] = { 71static const struct ctrl sd_ctrls[] = {
72 { 72 {
73 { 73 {
74 .id = V4L2_CID_BRIGHTNESS, 74 .id = V4L2_CID_BRIGHTNESS,
@@ -1047,7 +1047,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev,
1047} 1047}
1048 1048
1049/* sub-driver description */ 1049/* sub-driver description */
1050static struct sd_desc sd_desc = { 1050static const struct sd_desc sd_desc = {
1051 .name = MODULE_NAME, 1051 .name = MODULE_NAME,
1052 .ctrls = sd_ctrls, 1052 .ctrls = sd_ctrls,
1053 .nctrls = ARRAY_SIZE(sd_ctrls), 1053 .nctrls = ARRAY_SIZE(sd_ctrls),
diff --git a/drivers/media/video/gspca/spca501.c b/drivers/media/video/gspca/spca501.c
index 6761a3048a98..c99333933e32 100644
--- a/drivers/media/video/gspca/spca501.c
+++ b/drivers/media/video/gspca/spca501.c
@@ -59,7 +59,7 @@ static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
59static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val); 59static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
60static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val); 60static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
61 61
62static struct ctrl sd_ctrls[] = { 62static const struct ctrl sd_ctrls[] = {
63#define MY_BRIGHTNESS 0 63#define MY_BRIGHTNESS 0
64 { 64 {
65 { 65 {
diff --git a/drivers/media/video/gspca/spca505.c b/drivers/media/video/gspca/spca505.c
index 0f9232ff1281..c576eed73abe 100644
--- a/drivers/media/video/gspca/spca505.c
+++ b/drivers/media/video/gspca/spca505.c
@@ -42,7 +42,7 @@ struct sd {
42static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 42static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
43static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 43static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
44 44
45static struct ctrl sd_ctrls[] = { 45static const struct ctrl sd_ctrls[] = {
46 { 46 {
47 { 47 {
48 .id = V4L2_CID_BRIGHTNESS, 48 .id = V4L2_CID_BRIGHTNESS,
diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c
index 39257e4e074f..89fec4c500af 100644
--- a/drivers/media/video/gspca/spca506.c
+++ b/drivers/media/video/gspca/spca506.c
@@ -51,7 +51,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
51static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val); 51static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
52static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val); 52static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
53 53
54static struct ctrl sd_ctrls[] = { 54static const struct ctrl sd_ctrls[] = {
55#define SD_BRIGHTNESS 0 55#define SD_BRIGHTNESS 0
56 { 56 {
57 { 57 {
@@ -673,7 +673,7 @@ static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
673} 673}
674 674
675/* sub-driver description */ 675/* sub-driver description */
676static struct sd_desc sd_desc = { 676static const struct sd_desc sd_desc = {
677 .name = MODULE_NAME, 677 .name = MODULE_NAME,
678 .ctrls = sd_ctrls, 678 .ctrls = sd_ctrls,
679 .nctrls = ARRAY_SIZE(sd_ctrls), 679 .nctrls = ARRAY_SIZE(sd_ctrls),
diff --git a/drivers/media/video/gspca/spca508.c b/drivers/media/video/gspca/spca508.c
index 4d8e6cf75d55..15b2eef8a3f6 100644
--- a/drivers/media/video/gspca/spca508.c
+++ b/drivers/media/video/gspca/spca508.c
@@ -45,7 +45,7 @@ struct sd {
45static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 45static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
46static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 46static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
47 47
48static struct ctrl sd_ctrls[] = { 48static const struct ctrl sd_ctrls[] = {
49 { 49 {
50 { 50 {
51 .id = V4L2_CID_BRIGHTNESS, 51 .id = V4L2_CID_BRIGHTNESS,
diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c
index 58c2f0039af1..dc7f2b0fbc79 100644
--- a/drivers/media/video/gspca/spca561.c
+++ b/drivers/media/video/gspca/spca561.c
@@ -922,7 +922,7 @@ static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
922} 922}
923 923
924/* control tables */ 924/* control tables */
925static struct ctrl sd_ctrls_12a[] = { 925static const struct ctrl sd_ctrls_12a[] = {
926 { 926 {
927 { 927 {
928 .id = V4L2_CID_HUE, 928 .id = V4L2_CID_HUE,
@@ -964,7 +964,7 @@ static struct ctrl sd_ctrls_12a[] = {
964 }, 964 },
965}; 965};
966 966
967static struct ctrl sd_ctrls_72a[] = { 967static const struct ctrl sd_ctrls_72a[] = {
968 { 968 {
969 { 969 {
970 .id = V4L2_CID_HUE, 970 .id = V4L2_CID_HUE,
diff --git a/drivers/media/video/gspca/sq905c.c b/drivers/media/video/gspca/sq905c.c
index d70b156872d6..e64662052992 100644
--- a/drivers/media/video/gspca/sq905c.c
+++ b/drivers/media/video/gspca/sq905c.c
@@ -47,6 +47,7 @@ MODULE_LICENSE("GPL");
47 47
48/* Commands. These go in the "value" slot. */ 48/* Commands. These go in the "value" slot. */
49#define SQ905C_CLEAR 0xa0 /* clear everything */ 49#define SQ905C_CLEAR 0xa0 /* clear everything */
50#define SQ905C_GET_ID 0x14f4 /* Read version number */
50#define SQ905C_CAPTURE_LOW 0xa040 /* Starts capture at 160x120 */ 51#define SQ905C_CAPTURE_LOW 0xa040 /* Starts capture at 160x120 */
51#define SQ905C_CAPTURE_MED 0x1440 /* Starts capture at 320x240 */ 52#define SQ905C_CAPTURE_MED 0x1440 /* Starts capture at 320x240 */
52#define SQ905C_CAPTURE_HI 0x2840 /* Starts capture at 320x240 */ 53#define SQ905C_CAPTURE_HI 0x2840 /* Starts capture at 320x240 */
@@ -101,6 +102,26 @@ static int sq905c_command(struct gspca_dev *gspca_dev, u16 command, u16 index)
101 return 0; 102 return 0;
102} 103}
103 104
105static int sq905c_read(struct gspca_dev *gspca_dev, u16 command, u16 index,
106 int size)
107{
108 int ret;
109
110 ret = usb_control_msg(gspca_dev->dev,
111 usb_rcvctrlpipe(gspca_dev->dev, 0),
112 USB_REQ_SYNCH_FRAME, /* request */
113 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
114 command, index, gspca_dev->usb_buf, size,
115 SQ905C_CMD_TIMEOUT);
116 if (ret < 0) {
117 PDEBUG(D_ERR, "%s: usb_control_msg failed (%d)",
118 __func__, ret);
119 return ret;
120 }
121
122 return 0;
123}
124
104/* This function is called as a workqueue function and runs whenever the camera 125/* This function is called as a workqueue function and runs whenever the camera
105 * is streaming data. Because it is a workqueue function it is allowed to sleep 126 * is streaming data. Because it is a workqueue function it is allowed to sleep
106 * so we can use synchronous USB calls. To avoid possible collisions with other 127 * so we can use synchronous USB calls. To avoid possible collisions with other
@@ -183,13 +204,34 @@ static int sd_config(struct gspca_dev *gspca_dev,
183{ 204{
184 struct cam *cam = &gspca_dev->cam; 205 struct cam *cam = &gspca_dev->cam;
185 struct sd *dev = (struct sd *) gspca_dev; 206 struct sd *dev = (struct sd *) gspca_dev;
207 int ret;
186 208
187 PDEBUG(D_PROBE, 209 PDEBUG(D_PROBE,
188 "SQ9050 camera detected" 210 "SQ9050 camera detected"
189 " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); 211 " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
212
213 ret = sq905c_command(gspca_dev, SQ905C_GET_ID, 0);
214 if (ret < 0) {
215 PDEBUG(D_ERR, "Get version command failed");
216 return ret;
217 }
218
219 ret = sq905c_read(gspca_dev, 0xf5, 0, 20);
220 if (ret < 0) {
221 PDEBUG(D_ERR, "Reading version command failed");
222 return ret;
223 }
224 /* Note we leave out the usb id and the manufacturing date */
225 PDEBUG(D_PROBE,
226 "SQ9050 ID string: %02x - %02x %02x %02x %02x %02x %02x",
227 gspca_dev->usb_buf[3],
228 gspca_dev->usb_buf[14], gspca_dev->usb_buf[15],
229 gspca_dev->usb_buf[16], gspca_dev->usb_buf[17],
230 gspca_dev->usb_buf[18], gspca_dev->usb_buf[19]);
231
190 cam->cam_mode = sq905c_mode; 232 cam->cam_mode = sq905c_mode;
191 cam->nmodes = 2; 233 cam->nmodes = 2;
192 if (id->idProduct == 0x9050) 234 if (gspca_dev->usb_buf[15] == 0)
193 cam->nmodes = 1; 235 cam->nmodes = 1;
194 /* We don't use the buffer gspca allocates so make it small. */ 236 /* We don't use the buffer gspca allocates so make it small. */
195 cam->bulk_size = 32; 237 cam->bulk_size = 32;
@@ -258,6 +300,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
258static const __devinitdata struct usb_device_id device_table[] = { 300static const __devinitdata struct usb_device_id device_table[] = {
259 {USB_DEVICE(0x2770, 0x905c)}, 301 {USB_DEVICE(0x2770, 0x905c)},
260 {USB_DEVICE(0x2770, 0x9050)}, 302 {USB_DEVICE(0x2770, 0x9050)},
303 {USB_DEVICE(0x2770, 0x9052)},
261 {USB_DEVICE(0x2770, 0x913d)}, 304 {USB_DEVICE(0x2770, 0x913d)},
262 {} 305 {}
263}; 306};
diff --git a/drivers/media/video/gspca/stk014.c b/drivers/media/video/gspca/stk014.c
index 2e2935532d99..0fb534210a2c 100644
--- a/drivers/media/video/gspca/stk014.c
+++ b/drivers/media/video/gspca/stk014.c
@@ -53,7 +53,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
53static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); 53static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
54static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); 54static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
55 55
56static struct ctrl sd_ctrls[] = { 56static const struct ctrl sd_ctrls[] = {
57 { 57 {
58 { 58 {
59 .id = V4L2_CID_BRIGHTNESS, 59 .id = V4L2_CID_BRIGHTNESS,
diff --git a/drivers/media/video/gspca/stv0680.c b/drivers/media/video/gspca/stv0680.c
index 2a69d7ccb50d..e50dd7693f74 100644
--- a/drivers/media/video/gspca/stv0680.c
+++ b/drivers/media/video/gspca/stv0680.c
@@ -45,7 +45,7 @@ struct sd {
45}; 45};
46 46
47/* V4L2 controls supported by the driver */ 47/* V4L2 controls supported by the driver */
48static struct ctrl sd_ctrls[] = { 48static const struct ctrl sd_ctrls[] = {
49}; 49};
50 50
51static int stv_sndctrl(struct gspca_dev *gspca_dev, int set, u8 req, u16 val, 51static int stv_sndctrl(struct gspca_dev *gspca_dev, int set, u8 req, u16 val,
@@ -53,24 +53,28 @@ static int stv_sndctrl(struct gspca_dev *gspca_dev, int set, u8 req, u16 val,
53{ 53{
54 int ret = -1; 54 int ret = -1;
55 u8 req_type = 0; 55 u8 req_type = 0;
56 unsigned int pipe = 0;
56 57
57 switch (set) { 58 switch (set) {
58 case 0: /* 0xc1 */ 59 case 0: /* 0xc1 */
59 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; 60 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
61 pipe = usb_rcvctrlpipe(gspca_dev->dev, 0);
60 break; 62 break;
61 case 1: /* 0x41 */ 63 case 1: /* 0x41 */
62 req_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; 64 req_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
65 pipe = usb_sndctrlpipe(gspca_dev->dev, 0);
63 break; 66 break;
64 case 2: /* 0x80 */ 67 case 2: /* 0x80 */
65 req_type = USB_DIR_IN | USB_RECIP_DEVICE; 68 req_type = USB_DIR_IN | USB_RECIP_DEVICE;
69 pipe = usb_rcvctrlpipe(gspca_dev->dev, 0);
66 break; 70 break;
67 case 3: /* 0x40 */ 71 case 3: /* 0x40 */
68 req_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; 72 req_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
73 pipe = usb_sndctrlpipe(gspca_dev->dev, 0);
69 break; 74 break;
70 } 75 }
71 76
72 ret = usb_control_msg(gspca_dev->dev, 77 ret = usb_control_msg(gspca_dev->dev, pipe,
73 usb_rcvctrlpipe(gspca_dev->dev, 0),
74 req, req_type, 78 req, req_type,
75 val, 0, gspca_dev->usb_buf, size, 500); 79 val, 0, gspca_dev->usb_buf, size, 500);
76 80
@@ -138,6 +142,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
138 struct sd *sd = (struct sd *) gspca_dev; 142 struct sd *sd = (struct sd *) gspca_dev;
139 struct cam *cam = &gspca_dev->cam; 143 struct cam *cam = &gspca_dev->cam;
140 144
145 /* Give the camera some time to settle, otherwise initalization will
146 fail on hotplug, and yes it really needs a full second. */
147 msleep(1000);
148
141 /* ping camera to be sure STV0680 is present */ 149 /* ping camera to be sure STV0680 is present */
142 if (stv_sndctrl(gspca_dev, 0, 0x88, 0x5678, 0x02) != 0x02 || 150 if (stv_sndctrl(gspca_dev, 0, 0x88, 0x5678, 0x02) != 0x02 ||
143 gspca_dev->usb_buf[0] != 0x56 || gspca_dev->usb_buf[1] != 0x78) { 151 gspca_dev->usb_buf[0] != 0x56 || gspca_dev->usb_buf[1] != 0x78) {
@@ -169,6 +177,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
169 PDEBUG(D_PROBE, "Camera supports CIF mode"); 177 PDEBUG(D_PROBE, "Camera supports CIF mode");
170 if (gspca_dev->usb_buf[7] & 0x02) 178 if (gspca_dev->usb_buf[7] & 0x02)
171 PDEBUG(D_PROBE, "Camera supports VGA mode"); 179 PDEBUG(D_PROBE, "Camera supports VGA mode");
180 if (gspca_dev->usb_buf[7] & 0x04)
181 PDEBUG(D_PROBE, "Camera supports QCIF mode");
172 if (gspca_dev->usb_buf[7] & 0x08) 182 if (gspca_dev->usb_buf[7] & 0x08)
173 PDEBUG(D_PROBE, "Camera supports QVGA mode"); 183 PDEBUG(D_PROBE, "Camera supports QVGA mode");
174 184
diff --git a/drivers/media/video/gspca/stv06xx/stv06xx.c b/drivers/media/video/gspca/stv06xx/stv06xx.c
index 5d0241bb1611..af73da34c83f 100644
--- a/drivers/media/video/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/video/gspca/stv06xx/stv06xx.c
@@ -27,6 +27,7 @@
27 * P/N 861040-0000: Sensor ST VV6410 ASIC STV0610 - QuickCam Web 27 * P/N 861040-0000: Sensor ST VV6410 ASIC STV0610 - QuickCam Web
28 */ 28 */
29 29
30#include <linux/input.h>
30#include "stv06xx_sensor.h" 31#include "stv06xx_sensor.h"
31 32
32MODULE_AUTHOR("Erik Andrén"); 33MODULE_AUTHOR("Erik Andrén");
@@ -219,6 +220,7 @@ static void stv06xx_dump_bridge(struct sd *sd)
219 info("Read 0x%x from address 0x%x", data, i); 220 info("Read 0x%x from address 0x%x", data, i);
220 } 221 }
221 222
223 info("Testing stv06xx bridge registers for writability");
222 for (i = 0x1400; i < 0x160f; i++) { 224 for (i = 0x1400; i < 0x160f; i++) {
223 stv06xx_read_bridge(sd, i, &data); 225 stv06xx_read_bridge(sd, i, &data);
224 buf = data; 226 buf = data;
@@ -229,7 +231,7 @@ static void stv06xx_dump_bridge(struct sd *sd)
229 info("Register 0x%x is read/write", i); 231 info("Register 0x%x is read/write", i);
230 else if (data != buf) 232 else if (data != buf)
231 info("Register 0x%x is read/write," 233 info("Register 0x%x is read/write,"
232 "but only partially", i); 234 " but only partially", i);
233 else 235 else
234 info("Register 0x%x is read-only", i); 236 info("Register 0x%x is read-only", i);
235 237
@@ -426,6 +428,29 @@ frame_data:
426 } 428 }
427} 429}
428 430
431#ifdef CONFIG_INPUT
432static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
433 u8 *data, /* interrupt packet data */
434 int len) /* interrupt packet length */
435{
436 int ret = -EINVAL;
437
438 if (len == 1 && data[0] == 0x80) {
439 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
440 input_sync(gspca_dev->input_dev);
441 ret = 0;
442 }
443
444 if (len == 1 && data[0] == 0x88) {
445 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
446 input_sync(gspca_dev->input_dev);
447 ret = 0;
448 }
449
450 return ret;
451}
452#endif
453
429static int stv06xx_config(struct gspca_dev *gspca_dev, 454static int stv06xx_config(struct gspca_dev *gspca_dev,
430 const struct usb_device_id *id); 455 const struct usb_device_id *id);
431 456
@@ -436,7 +461,10 @@ static const struct sd_desc sd_desc = {
436 .init = stv06xx_init, 461 .init = stv06xx_init,
437 .start = stv06xx_start, 462 .start = stv06xx_start,
438 .stopN = stv06xx_stopN, 463 .stopN = stv06xx_stopN,
439 .pkt_scan = stv06xx_pkt_scan 464 .pkt_scan = stv06xx_pkt_scan,
465#ifdef CONFIG_INPUT
466 .int_pkt_scan = sd_int_pkt_scan,
467#endif
440}; 468};
441 469
442/* This function is called at probe time */ 470/* This function is called at probe time */
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index 306b7d75b4aa..0c786e00ebcf 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -67,7 +67,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
67static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); 67static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
68static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); 68static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
69 69
70static struct ctrl sd_ctrls[] = { 70static const struct ctrl sd_ctrls[] = {
71 { 71 {
72 { 72 {
73 .id = V4L2_CID_BRIGHTNESS, 73 .id = V4L2_CID_BRIGHTNESS,
@@ -267,142 +267,6 @@ static const struct cmd spca504A_clicksmart420_open_data[] = {
267 {0x06, 0x0000, 0x0000}, 267 {0x06, 0x0000, 0x0000},
268 {0x00, 0x0004, 0x2880}, 268 {0x00, 0x0004, 0x2880},
269 {0x00, 0x0001, 0x2881}, 269 {0x00, 0x0001, 0x2881},
270/* look like setting a qTable */
271 {0x00, 0x0006, 0x2800},
272 {0x00, 0x0004, 0x2801},
273 {0x00, 0x0004, 0x2802},
274 {0x00, 0x0006, 0x2803},
275 {0x00, 0x000a, 0x2804},
276 {0x00, 0x0010, 0x2805},
277 {0x00, 0x0014, 0x2806},
278 {0x00, 0x0018, 0x2807},
279 {0x00, 0x0005, 0x2808},
280 {0x00, 0x0005, 0x2809},
281 {0x00, 0x0006, 0x280a},
282 {0x00, 0x0008, 0x280b},
283 {0x00, 0x000a, 0x280c},
284 {0x00, 0x0017, 0x280d},
285 {0x00, 0x0018, 0x280e},
286 {0x00, 0x0016, 0x280f},
287
288 {0x00, 0x0006, 0x2810},
289 {0x00, 0x0005, 0x2811},
290 {0x00, 0x0006, 0x2812},
291 {0x00, 0x000a, 0x2813},
292 {0x00, 0x0010, 0x2814},
293 {0x00, 0x0017, 0x2815},
294 {0x00, 0x001c, 0x2816},
295 {0x00, 0x0016, 0x2817},
296 {0x00, 0x0006, 0x2818},
297 {0x00, 0x0007, 0x2819},
298 {0x00, 0x0009, 0x281a},
299 {0x00, 0x000c, 0x281b},
300 {0x00, 0x0014, 0x281c},
301 {0x00, 0x0023, 0x281d},
302 {0x00, 0x0020, 0x281e},
303 {0x00, 0x0019, 0x281f},
304
305 {0x00, 0x0007, 0x2820},
306 {0x00, 0x0009, 0x2821},
307 {0x00, 0x000f, 0x2822},
308 {0x00, 0x0016, 0x2823},
309 {0x00, 0x001b, 0x2824},
310 {0x00, 0x002c, 0x2825},
311 {0x00, 0x0029, 0x2826},
312 {0x00, 0x001f, 0x2827},
313 {0x00, 0x000a, 0x2828},
314 {0x00, 0x000e, 0x2829},
315 {0x00, 0x0016, 0x282a},
316 {0x00, 0x001a, 0x282b},
317 {0x00, 0x0020, 0x282c},
318 {0x00, 0x002a, 0x282d},
319 {0x00, 0x002d, 0x282e},
320 {0x00, 0x0025, 0x282f},
321
322 {0x00, 0x0014, 0x2830},
323 {0x00, 0x001a, 0x2831},
324 {0x00, 0x001f, 0x2832},
325 {0x00, 0x0023, 0x2833},
326 {0x00, 0x0029, 0x2834},
327 {0x00, 0x0030, 0x2835},
328 {0x00, 0x0030, 0x2836},
329 {0x00, 0x0028, 0x2837},
330 {0x00, 0x001d, 0x2838},
331 {0x00, 0x0025, 0x2839},
332 {0x00, 0x0026, 0x283a},
333 {0x00, 0x0027, 0x283b},
334 {0x00, 0x002d, 0x283c},
335 {0x00, 0x0028, 0x283d},
336 {0x00, 0x0029, 0x283e},
337 {0x00, 0x0028, 0x283f},
338
339 {0x00, 0x0007, 0x2840},
340 {0x00, 0x0007, 0x2841},
341 {0x00, 0x000a, 0x2842},
342 {0x00, 0x0013, 0x2843},
343 {0x00, 0x0028, 0x2844},
344 {0x00, 0x0028, 0x2845},
345 {0x00, 0x0028, 0x2846},
346 {0x00, 0x0028, 0x2847},
347 {0x00, 0x0007, 0x2848},
348 {0x00, 0x0008, 0x2849},
349 {0x00, 0x000a, 0x284a},
350 {0x00, 0x001a, 0x284b},
351 {0x00, 0x0028, 0x284c},
352 {0x00, 0x0028, 0x284d},
353 {0x00, 0x0028, 0x284e},
354 {0x00, 0x0028, 0x284f},
355
356 {0x00, 0x000a, 0x2850},
357 {0x00, 0x000a, 0x2851},
358 {0x00, 0x0016, 0x2852},
359 {0x00, 0x0028, 0x2853},
360 {0x00, 0x0028, 0x2854},
361 {0x00, 0x0028, 0x2855},
362 {0x00, 0x0028, 0x2856},
363 {0x00, 0x0028, 0x2857},
364 {0x00, 0x0013, 0x2858},
365 {0x00, 0x001a, 0x2859},
366 {0x00, 0x0028, 0x285a},
367 {0x00, 0x0028, 0x285b},
368 {0x00, 0x0028, 0x285c},
369 {0x00, 0x0028, 0x285d},
370 {0x00, 0x0028, 0x285e},
371 {0x00, 0x0028, 0x285f},
372
373 {0x00, 0x0028, 0x2860},
374 {0x00, 0x0028, 0x2861},
375 {0x00, 0x0028, 0x2862},
376 {0x00, 0x0028, 0x2863},
377 {0x00, 0x0028, 0x2864},
378 {0x00, 0x0028, 0x2865},
379 {0x00, 0x0028, 0x2866},
380 {0x00, 0x0028, 0x2867},
381 {0x00, 0x0028, 0x2868},
382 {0x00, 0x0028, 0x2869},
383 {0x00, 0x0028, 0x286a},
384 {0x00, 0x0028, 0x286b},
385 {0x00, 0x0028, 0x286c},
386 {0x00, 0x0028, 0x286d},
387 {0x00, 0x0028, 0x286e},
388 {0x00, 0x0028, 0x286f},
389
390 {0x00, 0x0028, 0x2870},
391 {0x00, 0x0028, 0x2871},
392 {0x00, 0x0028, 0x2872},
393 {0x00, 0x0028, 0x2873},
394 {0x00, 0x0028, 0x2874},
395 {0x00, 0x0028, 0x2875},
396 {0x00, 0x0028, 0x2876},
397 {0x00, 0x0028, 0x2877},
398 {0x00, 0x0028, 0x2878},
399 {0x00, 0x0028, 0x2879},
400 {0x00, 0x0028, 0x287a},
401 {0x00, 0x0028, 0x287b},
402 {0x00, 0x0028, 0x287c},
403 {0x00, 0x0028, 0x287d},
404 {0x00, 0x0028, 0x287e},
405 {0x00, 0x0028, 0x287f},
406 270
407 {0xa0, 0x0000, 0x0503}, 271 {0xa0, 0x0000, 0x0503},
408}; 272};
@@ -622,6 +486,20 @@ static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
622 PDEBUG(D_FRAM, "after wait 0x%04x", notdone); 486 PDEBUG(D_FRAM, "after wait 0x%04x", notdone);
623} 487}
624 488
489static void spca504_read_info(struct gspca_dev *gspca_dev)
490{
491 int i;
492 u8 info[6];
493
494 for (i = 0; i < 6; i++)
495 info[i] = reg_r_1(gspca_dev, i);
496 PDEBUG(D_STREAM,
497 "Read info: %d %d %d %d %d %d."
498 " Should be 1,0,2,2,0,0",
499 info[0], info[1], info[2],
500 info[3], info[4], info[5]);
501}
502
625static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev, 503static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
626 u8 req, 504 u8 req,
627 u16 idx, u16 val, u16 endcode, u8 count) 505 u16 idx, u16 val, u16 endcode, u8 count)
@@ -881,8 +759,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
881static int sd_init(struct gspca_dev *gspca_dev) 759static int sd_init(struct gspca_dev *gspca_dev)
882{ 760{
883 struct sd *sd = (struct sd *) gspca_dev; 761 struct sd *sd = (struct sd *) gspca_dev;
884 int i;
885 u8 info[6];
886 762
887 switch (sd->bridge) { 763 switch (sd->bridge) {
888 case BRIDGE_SPCA504B: 764 case BRIDGE_SPCA504B:
@@ -924,15 +800,8 @@ static int sd_init(struct gspca_dev *gspca_dev)
924/* case BRIDGE_SPCA504: */ 800/* case BRIDGE_SPCA504: */
925 PDEBUG(D_STREAM, "Opening SPCA504"); 801 PDEBUG(D_STREAM, "Opening SPCA504");
926 if (sd->subtype == AiptekMiniPenCam13) { 802 if (sd->subtype == AiptekMiniPenCam13) {
927 /*****************************/ 803 spca504_read_info(gspca_dev);
928 for (i = 0; i < 6; i++) 804
929 info[i] = reg_r_1(gspca_dev, i);
930 PDEBUG(D_STREAM,
931 "Read info: %d %d %d %d %d %d."
932 " Should be 1,0,2,2,0,0",
933 info[0], info[1], info[2],
934 info[3], info[4], info[5]);
935 /* spca504a aiptek */
936 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */ 805 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
937 spca504A_acknowledged_command(gspca_dev, 0x24, 806 spca504A_acknowledged_command(gspca_dev, 0x24,
938 8, 3, 0x9e, 1); 807 8, 3, 0x9e, 1);
@@ -971,8 +840,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
971{ 840{
972 struct sd *sd = (struct sd *) gspca_dev; 841 struct sd *sd = (struct sd *) gspca_dev;
973 int enable; 842 int enable;
974 int i;
975 u8 info[6];
976 843
977 /* create the JPEG header */ 844 /* create the JPEG header */
978 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); 845 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
@@ -1008,14 +875,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
1008 break; 875 break;
1009 case BRIDGE_SPCA504: 876 case BRIDGE_SPCA504:
1010 if (sd->subtype == AiptekMiniPenCam13) { 877 if (sd->subtype == AiptekMiniPenCam13) {
1011 for (i = 0; i < 6; i++) 878 spca504_read_info(gspca_dev);
1012 info[i] = reg_r_1(gspca_dev, i); 879
1013 PDEBUG(D_STREAM,
1014 "Read info: %d %d %d %d %d %d."
1015 " Should be 1,0,2,2,0,0",
1016 info[0], info[1], info[2],
1017 info[3], info[4], info[5]);
1018 /* spca504a aiptek */
1019 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */ 880 /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */
1020 spca504A_acknowledged_command(gspca_dev, 0x24, 881 spca504A_acknowledged_command(gspca_dev, 0x24,
1021 8, 3, 0x9e, 1); 882 8, 3, 0x9e, 1);
@@ -1026,13 +887,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
1026 0, 0, 0x9d, 1); 887 0, 0, 0x9d, 1);
1027 } else { 888 } else {
1028 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); 889 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
1029 for (i = 0; i < 6; i++) 890 spca504_read_info(gspca_dev);
1030 info[i] = reg_r_1(gspca_dev, i);
1031 PDEBUG(D_STREAM,
1032 "Read info: %d %d %d %d %d %d."
1033 " Should be 1,0,2,2,0,0",
1034 info[0], info[1], info[2],
1035 info[3], info[4], info[5]);
1036 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); 891 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
1037 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 892 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
1038 } 893 }
@@ -1336,6 +1191,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
1336 {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)}, 1191 {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)},
1337 {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)}, 1192 {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)},
1338 {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)}, 1193 {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)},
1194 {USB_DEVICE(0x052b, 0x1507), BS(SPCA533, MegapixV4)},
1339 {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)}, 1195 {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)},
1340 {USB_DEVICE(0x052b, 0x1803), BS(SPCA533, MegaImageVI)}, 1196 {USB_DEVICE(0x052b, 0x1803), BS(SPCA533, MegaImageVI)},
1341 {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)}, 1197 {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)},
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index 55ef6a744427..668a7536af90 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -52,6 +52,7 @@ struct sd {
52#define SENSOR_OM6802 0 52#define SENSOR_OM6802 0
53#define SENSOR_OTHER 1 53#define SENSOR_OTHER 1
54#define SENSOR_TAS5130A 2 54#define SENSOR_TAS5130A 2
55#define SENSOR_LT168G 3 /* must verify if this is the actual model */
55}; 56};
56 57
57/* V4L2 controls supported by the driver */ 58/* V4L2 controls supported by the driver */
@@ -78,7 +79,7 @@ static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val);
78static int sd_querymenu(struct gspca_dev *gspca_dev, 79static int sd_querymenu(struct gspca_dev *gspca_dev,
79 struct v4l2_querymenu *menu); 80 struct v4l2_querymenu *menu);
80 81
81static struct ctrl sd_ctrls[] = { 82static const struct ctrl sd_ctrls[] = {
82 { 83 {
83 { 84 {
84 .id = V4L2_CID_BRIGHTNESS, 85 .id = V4L2_CID_BRIGHTNESS,
@@ -306,6 +307,17 @@ static const u8 n4_tas5130a[] = {
306 0xbe, 0x36, 0xbf, 0xff, 0xc2, 0x88, 0xc5, 0xc8, 307 0xbe, 0x36, 0xbf, 0xff, 0xc2, 0x88, 0xc5, 0xc8,
307 0xc6, 0xda 308 0xc6, 0xda
308}; 309};
310static const u8 n4_lt168g[] = {
311 0x66, 0x01, 0x7f, 0x00, 0x80, 0x7c, 0x81, 0x28,
312 0x83, 0x44, 0x84, 0x20, 0x86, 0x20, 0x8a, 0x70,
313 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xa0, 0x8e, 0xb3,
314 0x8f, 0x24, 0xa1, 0xb0, 0xa2, 0x38, 0xa5, 0x20,
315 0xa6, 0x4a, 0xa8, 0xe8, 0xaf, 0x38, 0xb0, 0x68,
316 0xb1, 0x44, 0xb2, 0x88, 0xbb, 0x86, 0xbd, 0x40,
317 0xbe, 0x26, 0xc1, 0x05, 0xc2, 0x88, 0xc5, 0xc0,
318 0xda, 0x8e, 0xdb, 0xca, 0xdc, 0xa8, 0xdd, 0x8c,
319 0xde, 0x44, 0xdf, 0x0c, 0xe9, 0x80
320};
309 321
310static const struct additional_sensor_data sensor_data[] = { 322static const struct additional_sensor_data sensor_data[] = {
311 { /* 0: OM6802 */ 323 { /* 0: OM6802 */
@@ -380,6 +392,23 @@ static const struct additional_sensor_data sensor_data[] = {
380 .stream = 392 .stream =
381 {0x0b, 0x04, 0x0a, 0x40}, 393 {0x0b, 0x04, 0x0a, 0x40},
382 }, 394 },
395 { /* 3: LT168G */
396 .n3 = {0x61, 0xc2, 0x65, 0x68, 0x60, 0x00},
397 .n4 = n4_lt168g,
398 .n4sz = sizeof n4_lt168g,
399 .reg80 = 0x7c,
400 .reg8e = 0xb3,
401 .nset8 = {0xa8, 0xf0, 0xc6, 0xba, 0xc0, 0x00},
402 .data1 = {0xc0, 0x38, 0x08, 0x10, 0xc0, 0x30, 0x10, 0x40,
403 0xb0, 0xf4},
404 .data2 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
405 0xff},
406 .data3 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6,
407 0xff},
408 .data4 = {0x66, 0x41, 0xa8, 0xf0},
409 .data5 = {0x0c, 0x03, 0xab, 0x4b, 0x81, 0x2b},
410 .stream = {0x0b, 0x04, 0x0a, 0x28},
411 },
383}; 412};
384 413
385#define MAX_EFFECTS 7 414#define MAX_EFFECTS 7
@@ -716,6 +745,10 @@ static int sd_init(struct gspca_dev *gspca_dev)
716 PDEBUG(D_PROBE, "sensor tas5130a"); 745 PDEBUG(D_PROBE, "sensor tas5130a");
717 sd->sensor = SENSOR_TAS5130A; 746 sd->sensor = SENSOR_TAS5130A;
718 break; 747 break;
748 case 0x0802:
749 PDEBUG(D_PROBE, "sensor lt168g");
750 sd->sensor = SENSOR_LT168G;
751 break;
719 case 0x0803: 752 case 0x0803:
720 PDEBUG(D_PROBE, "sensor 'other'"); 753 PDEBUG(D_PROBE, "sensor 'other'");
721 sd->sensor = SENSOR_OTHER; 754 sd->sensor = SENSOR_OTHER;
@@ -758,6 +791,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
758 reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3); 791 reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3);
759 reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz); 792 reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz);
760 793
794 if (sd->sensor == SENSOR_LT168G) {
795 test_byte = reg_r(gspca_dev, 0x80);
796 PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80,
797 test_byte);
798 reg_w(gspca_dev, 0x6c80);
799 }
800
761 reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1); 801 reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
762 reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2); 802 reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
763 reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3); 803 reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
@@ -782,6 +822,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
782 reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8); 822 reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8);
783 reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream); 823 reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream);
784 824
825 if (sd->sensor == SENSOR_LT168G) {
826 test_byte = reg_r(gspca_dev, 0x80);
827 PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80,
828 test_byte);
829 reg_w(gspca_dev, 0x6c80);
830 }
831
785 reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1); 832 reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1);
786 reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2); 833 reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2);
787 reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3); 834 reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3);
@@ -888,6 +935,8 @@ static int sd_start(struct gspca_dev *gspca_dev)
888 case SENSOR_OM6802: 935 case SENSOR_OM6802:
889 om6802_sensor_init(gspca_dev); 936 om6802_sensor_init(gspca_dev);
890 break; 937 break;
938 case SENSOR_LT168G:
939 break;
891 case SENSOR_OTHER: 940 case SENSOR_OTHER:
892 break; 941 break;
893 default: 942 default:
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index b74a3b6489c7..c7b6eb1e04d5 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -39,7 +39,7 @@ struct sd {
39static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); 39static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
40static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); 40static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
41 41
42static struct ctrl sd_ctrls[] = { 42static const struct ctrl sd_ctrls[] = {
43 { 43 {
44 { 44 {
45 .id = V4L2_CID_BRIGHTNESS, 45 .id = V4L2_CID_BRIGHTNESS,
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index 71921c878424..4989f9afb46e 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -32,10 +32,13 @@ MODULE_LICENSE("GPL");
32struct sd { 32struct sd {
33 struct gspca_dev gspca_dev; /* !! must be the first item */ 33 struct gspca_dev gspca_dev; /* !! must be the first item */
34 34
35 u8 brightness;
36 u8 contrast;
37 u8 colors;
35 u8 hflip; 38 u8 hflip;
36 u8 vflip; 39 u8 vflip;
37 u8 lightfreq; 40 u8 lightfreq;
38 u8 sharpness; 41 s8 sharpness;
39 42
40 u8 image_offset; 43 u8 image_offset;
41 44
@@ -52,6 +55,7 @@ struct sd {
52#define SENSOR_OV7670 6 55#define SENSOR_OV7670 6
53#define SENSOR_PO1200 7 56#define SENSOR_PO1200 7
54#define SENSOR_PO3130NC 8 57#define SENSOR_PO3130NC 8
58#define SENSOR_POxxxx 9
55 u8 flags; 59 u8 flags;
56#define FL_SAMSUNG 0x01 /* SamsungQ1 (2 sensors) */ 60#define FL_SAMSUNG 0x01 /* SamsungQ1 (2 sensors) */
57#define FL_HFLIP 0x02 /* mirrored by default */ 61#define FL_HFLIP 0x02 /* mirrored by default */
@@ -59,6 +63,12 @@ struct sd {
59}; 63};
60 64
61/* V4L2 controls supported by the driver */ 65/* V4L2 controls supported by the driver */
66static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
67static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
68static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
69static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
70static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
71static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
62static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); 72static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
63static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val); 73static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
64static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); 74static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
@@ -68,9 +78,54 @@ static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
68static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); 78static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
69static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); 79static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
70 80
71static struct ctrl sd_ctrls[] = { 81static const struct ctrl sd_ctrls[] = {
82#define BRIGHTNESS_IDX 0
83 {
84 {
85 .id = V4L2_CID_BRIGHTNESS,
86 .type = V4L2_CTRL_TYPE_INTEGER,
87 .name = "Brightness",
88 .minimum = 0,
89 .maximum = 255,
90 .step = 1,
91#define BRIGHTNESS_DEF 128
92 .default_value = BRIGHTNESS_DEF,
93 },
94 .set = sd_setbrightness,
95 .get = sd_getbrightness,
96 },
97#define CONTRAST_IDX 1
98 {
99 {
100 .id = V4L2_CID_CONTRAST,
101 .type = V4L2_CTRL_TYPE_INTEGER,
102 .name = "Contrast",
103 .minimum = 0,
104 .maximum = 255,
105 .step = 1,
106#define CONTRAST_DEF 127
107 .default_value = CONTRAST_DEF,
108 },
109 .set = sd_setcontrast,
110 .get = sd_getcontrast,
111 },
112#define COLORS_IDX 2
113 {
114 {
115 .id = V4L2_CID_SATURATION,
116 .type = V4L2_CTRL_TYPE_INTEGER,
117 .name = "Saturation",
118 .minimum = 1,
119 .maximum = 127,
120 .step = 1,
121#define COLOR_DEF 63
122 .default_value = COLOR_DEF,
123 },
124 .set = sd_setcolors,
125 .get = sd_getcolors,
126 },
72/* next 2 controls work with some sensors only */ 127/* next 2 controls work with some sensors only */
73#define HFLIP_IDX 0 128#define HFLIP_IDX 3
74 { 129 {
75 { 130 {
76 .id = V4L2_CID_HFLIP, 131 .id = V4L2_CID_HFLIP,
@@ -85,7 +140,7 @@ static struct ctrl sd_ctrls[] = {
85 .set = sd_sethflip, 140 .set = sd_sethflip,
86 .get = sd_gethflip, 141 .get = sd_gethflip,
87 }, 142 },
88#define VFLIP_IDX 1 143#define VFLIP_IDX 4
89 { 144 {
90 { 145 {
91 .id = V4L2_CID_VFLIP, 146 .id = V4L2_CID_VFLIP,
@@ -100,7 +155,7 @@ static struct ctrl sd_ctrls[] = {
100 .set = sd_setvflip, 155 .set = sd_setvflip,
101 .get = sd_getvflip, 156 .get = sd_getvflip,
102 }, 157 },
103#define LIGHTFREQ_IDX 2 158#define LIGHTFREQ_IDX 5
104 { 159 {
105 { 160 {
106 .id = V4L2_CID_POWER_LINE_FREQUENCY, 161 .id = V4L2_CID_POWER_LINE_FREQUENCY,
@@ -115,17 +170,16 @@ static struct ctrl sd_ctrls[] = {
115 .set = sd_setfreq, 170 .set = sd_setfreq,
116 .get = sd_getfreq, 171 .get = sd_getfreq,
117 }, 172 },
118/* po1200 only */ 173#define SHARPNESS_IDX 6
119#define SHARPNESS_IDX 3
120 { 174 {
121 { 175 {
122 .id = V4L2_CID_SHARPNESS, 176 .id = V4L2_CID_SHARPNESS,
123 .type = V4L2_CTRL_TYPE_INTEGER, 177 .type = V4L2_CTRL_TYPE_INTEGER,
124 .name = "Sharpness", 178 .name = "Sharpness",
125 .minimum = 0, 179 .minimum = -1,
126 .maximum = 2, 180 .maximum = 2,
127 .step = 1, 181 .step = 1,
128#define SHARPNESS_DEF 1 182#define SHARPNESS_DEF -1
129 .default_value = SHARPNESS_DEF, 183 .default_value = SHARPNESS_DEF,
130 }, 184 },
131 .set = sd_setsharpness, 185 .set = sd_setsharpness,
@@ -133,6 +187,42 @@ static struct ctrl sd_ctrls[] = {
133 }, 187 },
134}; 188};
135 189
190/* table of the disabled controls */
191static u32 ctrl_dis[] = {
192/* SENSOR_HV7131R 0 */
193 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
194 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
195 | (1 << SHARPNESS_IDX),
196/* SENSOR_MI0360 1 */
197 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
198 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
199 | (1 << SHARPNESS_IDX),
200/* SENSOR_MI1310_SOC 2 */
201 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
202 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX),
203/* SENSOR_MI1320 3 */
204 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
205 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX),
206/* SENSOR_MI1320_SOC 4 */
207 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
208 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX),
209/* SENSOR_OV7660 5 */
210 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
211 | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX),
212/* SENSOR_OV7670 6 */
213 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
214 | (1 << SHARPNESS_IDX),
215/* SENSOR_PO1200 7 */
216 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
217 | (1 << LIGHTFREQ_IDX),
218/* SENSOR_PO3130NC 8 */
219 (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX)
220 | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX)
221 | (1 << SHARPNESS_IDX),
222/* SENSOR_POxxxx 9 */
223 (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX),
224};
225
136static const struct v4l2_pix_format vc0321_mode[] = { 226static const struct v4l2_pix_format vc0321_mode[] = {
137 {320, 240, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE, 227 {320, 240, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE,
138 .bytesperline = 320, 228 .bytesperline = 320,
@@ -215,7 +305,7 @@ static const u8 mi0360_initVGA_JPG[][4] = {
215 {0xb3, 0x15, 0x00, 0xcc}, 305 {0xb3, 0x15, 0x00, 0xcc},
216 {0xb3, 0x16, 0x02, 0xcc}, 306 {0xb3, 0x16, 0x02, 0xcc},
217 {0xb3, 0x17, 0x7f, 0xcc}, 307 {0xb3, 0x17, 0x7f, 0xcc},
218 {0xb3, 0x35, 0xdd, 0xcc}, 308 {0xb3, 0x35, 0xdd, 0xcc}, /* i2c add: 5d */
219 {0xb3, 0x34, 0x02, 0xcc}, 309 {0xb3, 0x34, 0x02, 0xcc},
220 {0xb3, 0x00, 0x25, 0xcc}, 310 {0xb3, 0x00, 0x25, 0xcc},
221 {0xbc, 0x00, 0x71, 0xcc}, 311 {0xbc, 0x00, 0x71, 0xcc},
@@ -435,7 +525,7 @@ static const u8 mi1310_socinitVGA_JPG[][4] = {
435 {0xb3, 0x08, 0x01, 0xcc}, 525 {0xb3, 0x08, 0x01, 0xcc},
436 {0xb3, 0x09, 0x0c, 0xcc}, 526 {0xb3, 0x09, 0x0c, 0xcc},
437 {0xb3, 0x34, 0x02, 0xcc}, 527 {0xb3, 0x34, 0x02, 0xcc},
438 {0xb3, 0x35, 0xdd, 0xcc}, 528 {0xb3, 0x35, 0xdd, 0xcc}, /* i2c add: 5d */
439 {0xb3, 0x02, 0x00, 0xcc}, 529 {0xb3, 0x02, 0x00, 0xcc},
440 {0xb3, 0x03, 0x0a, 0xcc}, 530 {0xb3, 0x03, 0x0a, 0xcc},
441 {0xb3, 0x04, 0x05, 0xcc}, 531 {0xb3, 0x04, 0x05, 0xcc},
@@ -860,7 +950,8 @@ static const u8 mi1320_initVGA_data[][4] = {
860 {0xb0, 0x16, 0x03, 0xcc}, {0xb3, 0x05, 0x00, 0xcc}, 950 {0xb0, 0x16, 0x03, 0xcc}, {0xb3, 0x05, 0x00, 0xcc},
861 {0xb3, 0x06, 0x00, 0xcc}, {0xb3, 0x08, 0x01, 0xcc}, 951 {0xb3, 0x06, 0x00, 0xcc}, {0xb3, 0x08, 0x01, 0xcc},
862 {0xb3, 0x09, 0x0c, 0xcc}, {0xb3, 0x34, 0x02, 0xcc}, 952 {0xb3, 0x09, 0x0c, 0xcc}, {0xb3, 0x34, 0x02, 0xcc},
863 {0xb3, 0x35, 0xc8, 0xcc}, {0xb3, 0x02, 0x00, 0xcc}, 953 {0xb3, 0x35, 0xc8, 0xcc}, /* i2c add: 48 */
954 {0xb3, 0x02, 0x00, 0xcc},
864 {0xb3, 0x03, 0x0a, 0xcc}, {0xb3, 0x04, 0x05, 0xcc}, 955 {0xb3, 0x03, 0x0a, 0xcc}, {0xb3, 0x04, 0x05, 0xcc},
865 {0xb3, 0x20, 0x00, 0xcc}, {0xb3, 0x21, 0x00, 0xcc}, 956 {0xb3, 0x20, 0x00, 0xcc}, {0xb3, 0x21, 0x00, 0xcc},
866 {0xb3, 0x22, 0x03, 0xcc}, {0xb3, 0x23, 0xc0, 0xcc}, 957 {0xb3, 0x22, 0x03, 0xcc}, {0xb3, 0x23, 0xc0, 0xcc},
@@ -901,7 +992,8 @@ static const u8 mi1320_initVGA_data[][4] = {
901 {0xc3, 0x01, 0x03, 0xbb}, {0xc4, 0x00, 0x04, 0xbb}, 992 {0xc3, 0x01, 0x03, 0xbb}, {0xc4, 0x00, 0x04, 0xbb},
902 {0xf0, 0x00, 0x00, 0xbb}, {0x05, 0x01, 0x13, 0xbb}, 993 {0xf0, 0x00, 0x00, 0xbb}, {0x05, 0x01, 0x13, 0xbb},
903 {0x06, 0x00, 0x11, 0xbb}, {0x07, 0x00, 0x85, 0xbb}, 994 {0x06, 0x00, 0x11, 0xbb}, {0x07, 0x00, 0x85, 0xbb},
904 {0x08, 0x00, 0x27, 0xbb}, {0x20, 0x01, 0x03, 0xbb}, 995 {0x08, 0x00, 0x27, 0xbb},
996 {0x20, 0x01, 0x00, 0xbb}, /* h/v flips - was 03 */
905 {0x21, 0x80, 0x00, 0xbb}, {0x22, 0x0d, 0x0f, 0xbb}, 997 {0x21, 0x80, 0x00, 0xbb}, {0x22, 0x0d, 0x0f, 0xbb},
906 {0x24, 0x80, 0x00, 0xbb}, {0x59, 0x00, 0xff, 0xbb}, 998 {0x24, 0x80, 0x00, 0xbb}, {0x59, 0x00, 0xff, 0xbb},
907 {0xf0, 0x00, 0x02, 0xbb}, {0x39, 0x03, 0x0d, 0xbb}, 999 {0xf0, 0x00, 0x02, 0xbb}, {0x39, 0x03, 0x0d, 0xbb},
@@ -1012,7 +1104,7 @@ static const u8 mi1320_soc_InitVGA[][4] = {
1012 {0xb3, 0x08, 0x01, 0xcc}, 1104 {0xb3, 0x08, 0x01, 0xcc},
1013 {0xb3, 0x09, 0x0c, 0xcc}, 1105 {0xb3, 0x09, 0x0c, 0xcc},
1014 {0xb3, 0x34, 0x02, 0xcc}, 1106 {0xb3, 0x34, 0x02, 0xcc},
1015 {0xb3, 0x35, 0xc8, 0xcc}, 1107 {0xb3, 0x35, 0xc8, 0xcc}, /* i2c add: 48 */
1016 {0xb3, 0x02, 0x00, 0xcc}, 1108 {0xb3, 0x02, 0x00, 0xcc},
1017 {0xb3, 0x03, 0x0a, 0xcc}, 1109 {0xb3, 0x03, 0x0a, 0xcc},
1018 {0xb3, 0x04, 0x05, 0xcc}, 1110 {0xb3, 0x04, 0x05, 0xcc},
@@ -1359,7 +1451,8 @@ static const u8 po3130_initVGA_data[][4] = {
1359 {0xb3, 0x23, 0xe8, 0xcc}, {0xb8, 0x08, 0xe8, 0xcc}, 1451 {0xb3, 0x23, 0xe8, 0xcc}, {0xb8, 0x08, 0xe8, 0xcc},
1360 {0xb3, 0x14, 0x00, 0xcc}, {0xb3, 0x15, 0x00, 0xcc}, 1452 {0xb3, 0x14, 0x00, 0xcc}, {0xb3, 0x15, 0x00, 0xcc},
1361 {0xb3, 0x16, 0x02, 0xcc}, {0xb3, 0x17, 0x7f, 0xcc}, 1453 {0xb3, 0x16, 0x02, 0xcc}, {0xb3, 0x17, 0x7f, 0xcc},
1362 {0xb3, 0x34, 0x01, 0xcc}, {0xb3, 0x35, 0xf6, 0xcc}, 1454 {0xb3, 0x34, 0x01, 0xcc},
1455 {0xb3, 0x35, 0xf6, 0xcc}, /* i2c add: 76 */
1363 {0xb3, 0x00, 0x27, 0xcc}, {0xbc, 0x00, 0x71, 0xcc}, 1456 {0xb3, 0x00, 0x27, 0xcc}, {0xbc, 0x00, 0x71, 0xcc},
1364 {0xb8, 0x00, 0x21, 0xcc}, {0xb8, 0x27, 0x20, 0xcc}, 1457 {0xb8, 0x00, 0x21, 0xcc}, {0xb8, 0x27, 0x20, 0xcc},
1365 {0xb8, 0x01, 0x79, 0xcc}, {0xb8, 0x81, 0x09, 0xcc}, 1458 {0xb8, 0x01, 0x79, 0xcc}, {0xb8, 0x81, 0x09, 0xcc},
@@ -1561,7 +1654,7 @@ static const u8 hv7131r_initVGA_data[][4] = {
1561 {0xb3, 0x16, 0x02, 0xcc}, 1654 {0xb3, 0x16, 0x02, 0xcc},
1562 {0xb3, 0x17, 0x7f, 0xcc}, 1655 {0xb3, 0x17, 0x7f, 0xcc},
1563 {0xb3, 0x34, 0x01, 0xcc}, 1656 {0xb3, 0x34, 0x01, 0xcc},
1564 {0xb3, 0x35, 0x91, 0xcc}, 1657 {0xb3, 0x35, 0x91, 0xcc}, /* i2c add: 11 */
1565 {0xb3, 0x00, 0x27, 0xcc}, 1658 {0xb3, 0x00, 0x27, 0xcc},
1566 {0xbc, 0x00, 0x73, 0xcc}, 1659 {0xbc, 0x00, 0x73, 0xcc},
1567 {0xb8, 0x00, 0x23, 0xcc}, 1660 {0xb8, 0x00, 0x23, 0xcc},
@@ -1747,7 +1840,8 @@ static const u8 ov7660_initVGA_data[][4] = {
1747 {0xb3, 0x23, 0xe0, 0xcc}, {0xb3, 0x1d, 0x01, 0xcc}, 1840 {0xb3, 0x23, 0xe0, 0xcc}, {0xb3, 0x1d, 0x01, 0xcc},
1748 {0xb3, 0x1f, 0x02, 0xcc}, 1841 {0xb3, 0x1f, 0x02, 0xcc},
1749 {0xb3, 0x34, 0x01, 0xcc}, 1842 {0xb3, 0x34, 0x01, 0xcc},
1750 {0xb3, 0x35, 0xa1, 0xcc}, {0xb3, 0x00, 0x26, 0xcc}, 1843 {0xb3, 0x35, 0xa1, 0xcc}, /* i2c add: 21 */
1844 {0xb3, 0x00, 0x26, 0xcc},
1751 {0xb8, 0x00, 0x33, 0xcc}, /* 13 */ 1845 {0xb8, 0x00, 0x33, 0xcc}, /* 13 */
1752 {0xb8, 0x01, 0x7d, 0xcc}, 1846 {0xb8, 0x01, 0x7d, 0xcc},
1753 {0xbc, 0x00, 0x73, 0xcc}, {0xb8, 0x81, 0x09, 0xcc}, 1847 {0xbc, 0x00, 0x73, 0xcc}, {0xb8, 0x81, 0x09, 0xcc},
@@ -1883,7 +1977,8 @@ static const u8 ov7670_initVGA_JPG[][4] = {
1883 {0x00, 0x00, 0x10, 0xdd}, 1977 {0x00, 0x00, 0x10, 0xdd},
1884 {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x10, 0xdd}, 1978 {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x10, 0xdd},
1885 {0xb3, 0x00, 0x66, 0xcc}, {0xb3, 0x00, 0x67, 0xcc}, 1979 {0xb3, 0x00, 0x66, 0xcc}, {0xb3, 0x00, 0x67, 0xcc},
1886 {0xb3, 0x35, 0xa1, 0xcc}, {0xb3, 0x34, 0x01, 0xcc}, 1980 {0xb3, 0x35, 0xa1, 0xcc}, /* i2c add: 21 */
1981 {0xb3, 0x34, 0x01, 0xcc},
1887 {0xb3, 0x05, 0x01, 0xcc}, {0xb3, 0x06, 0x01, 0xcc}, 1982 {0xb3, 0x05, 0x01, 0xcc}, {0xb3, 0x06, 0x01, 0xcc},
1888 {0xb3, 0x08, 0x01, 0xcc}, {0xb3, 0x09, 0x0c, 0xcc}, 1983 {0xb3, 0x08, 0x01, 0xcc}, {0xb3, 0x09, 0x0c, 0xcc},
1889 {0xb3, 0x02, 0x02, 0xcc}, {0xb3, 0x03, 0x1f, 0xcc}, 1984 {0xb3, 0x02, 0x02, 0xcc}, {0xb3, 0x03, 0x1f, 0xcc},
@@ -2181,7 +2276,7 @@ static const u8 po1200_initVGA_data[][4] = {
2181 {0xb0, 0x54, 0x13, 0xcc}, 2276 {0xb0, 0x54, 0x13, 0xcc},
2182 {0xb3, 0x00, 0x67, 0xcc}, 2277 {0xb3, 0x00, 0x67, 0xcc},
2183 {0xb3, 0x34, 0x01, 0xcc}, 2278 {0xb3, 0x34, 0x01, 0xcc},
2184 {0xb3, 0x35, 0xdc, 0xcc}, 2279 {0xb3, 0x35, 0xdc, 0xcc}, /* i2c add: 5c */
2185 {0x00, 0x03, 0x00, 0xaa}, 2280 {0x00, 0x03, 0x00, 0xaa},
2186 {0x00, 0x12, 0x05, 0xaa}, 2281 {0x00, 0x12, 0x05, 0xaa},
2187 {0x00, 0x13, 0x02, 0xaa}, 2282 {0x00, 0x13, 0x02, 0xaa},
@@ -2408,6 +2503,251 @@ static const u8 po1200_initVGA_data[][4] = {
2408 {0x00, 0xb6, 0x39, 0xaa}, 2503 {0x00, 0xb6, 0x39, 0xaa},
2409 {0x00, 0xb7, 0x24, 0xaa}, 2504 {0x00, 0xb7, 0x24, 0xaa},
2410/*write 89 0400 1415*/ 2505/*write 89 0400 1415*/
2506 {}
2507};
2508
2509static const u8 poxxxx_init_common[][4] = {
2510 {0xb3, 0x00, 0x04, 0xcc},
2511 {0x00, 0x00, 0x10, 0xdd},
2512 {0xb3, 0x00, 0x64, 0xcc},
2513 {0x00, 0x00, 0x10, 0xdd},
2514 {0xb3, 0x00, 0x65, 0xcc},
2515 {0x00, 0x00, 0x10, 0xdd},
2516 {0xb3, 0x00, 0x67, 0xcc},
2517 {0xb0, 0x03, 0x09, 0xcc},
2518 {0xb3, 0x05, 0x00, 0xcc},
2519 {0xb3, 0x06, 0x00, 0xcc},
2520 {0xb3, 0x5c, 0x01, 0xcc},
2521 {0xb3, 0x08, 0x01, 0xcc},
2522 {0xb3, 0x09, 0x0c, 0xcc},
2523 {0xb3, 0x34, 0x01, 0xcc},
2524 {0xb3, 0x35, 0xf6, 0xcc}, /* i2c add: 76 */
2525 {0xb3, 0x02, 0xb0, 0xcc},
2526 {0xb3, 0x03, 0x18, 0xcc},
2527 {0xb3, 0x04, 0x15, 0xcc},
2528 {0xb3, 0x20, 0x00, 0xcc},
2529 {0xb3, 0x21, 0x00, 0xcc},
2530 {0xb3, 0x22, 0x04, 0xcc},
2531 {0xb3, 0x23, 0x00, 0xcc},
2532 {0xb3, 0x14, 0x00, 0xcc},
2533 {0xb3, 0x15, 0x00, 0xcc},
2534 {0xb3, 0x16, 0x04, 0xcc},
2535 {0xb3, 0x17, 0xff, 0xcc},
2536 {0xb3, 0x2c, 0x03, 0xcc},
2537 {0xb3, 0x2d, 0x56, 0xcc},
2538 {0xb3, 0x2e, 0x02, 0xcc},
2539 {0xb3, 0x2f, 0x0a, 0xcc},
2540 {0xb3, 0x40, 0x00, 0xcc},
2541 {0xb3, 0x41, 0x34, 0xcc},
2542 {0xb3, 0x42, 0x01, 0xcc},
2543 {0xb3, 0x43, 0xe0, 0xcc},
2544 {0xbc, 0x00, 0x71, 0xcc},
2545 {0xbc, 0x01, 0x01, 0xcc},
2546 {0xb3, 0x01, 0x41, 0xcc},
2547 {0xb3, 0x4d, 0x00, 0xcc},
2548 {0x00, 0x0b, 0x2a, 0xaa},
2549 {0x00, 0x0e, 0x03, 0xaa},
2550 {0x00, 0x0f, 0xea, 0xaa},
2551 {0x00, 0x12, 0x08, 0xaa},
2552 {0x00, 0x1e, 0x06, 0xaa},
2553 {0x00, 0x21, 0x00, 0xaa},
2554 {0x00, 0x31, 0x1f, 0xaa},
2555 {0x00, 0x33, 0x38, 0xaa},
2556 {0x00, 0x36, 0xc0, 0xaa},
2557 {0x00, 0x37, 0xc8, 0xaa},
2558 {0x00, 0x3b, 0x36, 0xaa},
2559 {0x00, 0x4b, 0xfe, 0xaa},
2560 {0x00, 0x4d, 0x2e, 0xaa},
2561 {0x00, 0x51, 0x1c, 0xaa},
2562 {0x00, 0x52, 0x01, 0xaa},
2563 {0x00, 0x55, 0x0a, 0xaa},
2564 {0x00, 0x56, 0x0a, 0xaa},
2565 {0x00, 0x57, 0x07, 0xaa},
2566 {0x00, 0x58, 0x07, 0xaa},
2567 {0x00, 0x59, 0x04, 0xaa},
2568 {0x00, 0x70, 0x68, 0xaa},
2569 {0x00, 0x71, 0x04, 0xaa},
2570 {0x00, 0x72, 0x10, 0xaa},
2571 {0x00, 0x80, 0x71, 0xaa},
2572 {0x00, 0x81, 0x08, 0xaa},
2573 {0x00, 0x82, 0x00, 0xaa},
2574 {0x00, 0x83, 0x55, 0xaa},
2575 {0x00, 0x84, 0x06, 0xaa},
2576 {0x00, 0x85, 0x06, 0xaa},
2577 {0x00, 0x8b, 0x25, 0xaa},
2578 {0x00, 0x8c, 0x00, 0xaa},
2579 {0x00, 0x8d, 0x86, 0xaa},
2580 {0x00, 0x8e, 0x82, 0xaa},
2581 {0x00, 0x8f, 0x2d, 0xaa},
2582 {0x00, 0x90, 0x8b, 0xaa},
2583 {0x00, 0x91, 0x81, 0xaa},
2584 {0x00, 0x92, 0x81, 0xaa},
2585 {0x00, 0x93, 0x23, 0xaa},
2586 {0x00, 0xa3, 0x2a, 0xaa},
2587 {0x00, 0xa4, 0x03, 0xaa},
2588 {0x00, 0xa5, 0xea, 0xaa},
2589 {0x00, 0xb0, 0x68, 0xaa},
2590 {0x00, 0xbc, 0x04, 0xaa},
2591 {0x00, 0xbe, 0x3b, 0xaa},
2592 {0x00, 0x4e, 0x40, 0xaa},
2593 {0x00, 0x06, 0x04, 0xaa},
2594 {0x00, 0x07, 0x03, 0xaa},
2595 {0x00, 0xcd, 0x18, 0xaa},
2596 {0x00, 0x28, 0x03, 0xaa},
2597 {0x00, 0x29, 0xef, 0xaa},
2598/* reinit on alt 2 (qvga) or alt7 (vga) */
2599 {0xb3, 0x05, 0x00, 0xcc},
2600 {0xb3, 0x06, 0x00, 0xcc},
2601 {0xb8, 0x00, 0x01, 0xcc},
2602
2603 {0x00, 0x1d, 0x85, 0xaa},
2604 {0x00, 0x1e, 0xc6, 0xaa},
2605 {0x00, 0x00, 0x40, 0xdd},
2606 {0x00, 0x1d, 0x05, 0xaa},
2607
2608 {0x00, 0xd6, 0x22, 0xaa}, /* gamma 0 */
2609 {0x00, 0x73, 0x00, 0xaa},
2610 {0x00, 0x74, 0x0a, 0xaa},
2611 {0x00, 0x75, 0x16, 0xaa},
2612 {0x00, 0x76, 0x25, 0xaa},
2613 {0x00, 0x77, 0x34, 0xaa},
2614 {0x00, 0x78, 0x49, 0xaa},
2615 {0x00, 0x79, 0x5a, 0xaa},
2616 {0x00, 0x7a, 0x7f, 0xaa},
2617 {0x00, 0x7b, 0x9b, 0xaa},
2618 {0x00, 0x7c, 0xba, 0xaa},
2619 {0x00, 0x7d, 0xd4, 0xaa},
2620 {0x00, 0x7e, 0xea, 0xaa},
2621
2622 {0x00, 0xd6, 0x62, 0xaa}, /* gamma 1 */
2623 {0x00, 0x73, 0x00, 0xaa},
2624 {0x00, 0x74, 0x0a, 0xaa},
2625 {0x00, 0x75, 0x16, 0xaa},
2626 {0x00, 0x76, 0x25, 0xaa},
2627 {0x00, 0x77, 0x34, 0xaa},
2628 {0x00, 0x78, 0x49, 0xaa},
2629 {0x00, 0x79, 0x5a, 0xaa},
2630 {0x00, 0x7a, 0x7f, 0xaa},
2631 {0x00, 0x7b, 0x9b, 0xaa},
2632 {0x00, 0x7c, 0xba, 0xaa},
2633 {0x00, 0x7d, 0xd4, 0xaa},
2634 {0x00, 0x7e, 0xea, 0xaa},
2635
2636 {0x00, 0xd6, 0xa2, 0xaa}, /* gamma 2 */
2637 {0x00, 0x73, 0x00, 0xaa},
2638 {0x00, 0x74, 0x0a, 0xaa},
2639 {0x00, 0x75, 0x16, 0xaa},
2640 {0x00, 0x76, 0x25, 0xaa},
2641 {0x00, 0x77, 0x34, 0xaa},
2642 {0x00, 0x78, 0x49, 0xaa},
2643 {0x00, 0x79, 0x5a, 0xaa},
2644 {0x00, 0x7a, 0x7f, 0xaa},
2645 {0x00, 0x7b, 0x9b, 0xaa},
2646 {0x00, 0x7c, 0xba, 0xaa},
2647 {0x00, 0x7d, 0xd4, 0xaa},
2648 {0x00, 0x7e, 0xea, 0xaa},
2649
2650 {0x00, 0xaa, 0xff, 0xaa}, /* back light comp */
2651 {0x00, 0xc4, 0x03, 0xaa},
2652 {0x00, 0xc5, 0x19, 0xaa},
2653 {0x00, 0xc6, 0x03, 0xaa},
2654 {0x00, 0xc7, 0x91, 0xaa},
2655 {0x00, 0xc8, 0x01, 0xaa},
2656 {0x00, 0xc9, 0xdd, 0xaa},
2657 {0x00, 0xca, 0x02, 0xaa},
2658 {0x00, 0xcb, 0x37, 0xaa},
2659
2660/* read d1 */
2661 {0x00, 0xd1, 0x3c, 0xaa},
2662 {0x00, 0xb8, 0x28, 0xaa},
2663 {0x00, 0xb9, 0x1e, 0xaa},
2664 {0x00, 0xb6, 0x14, 0xaa},
2665 {0x00, 0xb7, 0x0f, 0xaa},
2666 {0x00, 0x5c, 0x10, 0xaa},
2667 {0x00, 0x5d, 0x18, 0xaa},
2668 {0x00, 0x5e, 0x24, 0xaa},
2669 {0x00, 0x5f, 0x24, 0xaa},
2670 {0x00, 0x86, 0x1a, 0xaa},
2671 {0x00, 0x60, 0x00, 0xaa},
2672 {0x00, 0x61, 0x1b, 0xaa},
2673 {0x00, 0x62, 0x30, 0xaa},
2674 {0x00, 0x63, 0x40, 0xaa},
2675 {0x00, 0x87, 0x1a, 0xaa},
2676 {0x00, 0x64, 0x00, 0xaa},
2677 {0x00, 0x65, 0x08, 0xaa},
2678 {0x00, 0x66, 0x10, 0xaa},
2679 {0x00, 0x67, 0x20, 0xaa},
2680 {0x00, 0x88, 0x10, 0xaa},
2681 {0x00, 0x68, 0x00, 0xaa},
2682 {0x00, 0x69, 0x08, 0xaa},
2683 {0x00, 0x6a, 0x0f, 0xaa},
2684 {0x00, 0x6b, 0x0f, 0xaa},
2685 {0x00, 0x89, 0x07, 0xaa},
2686 {0x00, 0xd5, 0x4c, 0xaa},
2687 {0x00, 0x0a, 0x00, 0xaa},
2688 {0x00, 0x0b, 0x2a, 0xaa},
2689 {0x00, 0x0e, 0x03, 0xaa},
2690 {0x00, 0x0f, 0xea, 0xaa},
2691 {0x00, 0xa2, 0x00, 0xaa},
2692 {0x00, 0xa3, 0x2a, 0xaa},
2693 {0x00, 0xa4, 0x03, 0xaa},
2694 {0x00, 0xa5, 0xea, 0xaa},
2695 {}
2696};
2697static const u8 poxxxx_initVGA[][4] = {
2698 {0x00, 0x20, 0x11, 0xaa},
2699 {0x00, 0x33, 0x38, 0xaa},
2700 {0x00, 0xbb, 0x0d, 0xaa},
2701 {0xb3, 0x22, 0x01, 0xcc},
2702 {0xb3, 0x23, 0xe0, 0xcc},
2703 {0xb3, 0x16, 0x02, 0xcc},
2704 {0xb3, 0x17, 0x7f, 0xcc},
2705 {0xb3, 0x02, 0xb0, 0xcc},
2706 {0xb3, 0x06, 0x00, 0xcc},
2707 {0xb3, 0x5c, 0x01, 0xcc},
2708 {0x00, 0x04, 0x06, 0xaa},
2709 {0x00, 0x05, 0x3f, 0xaa},
2710 {0x00, 0x04, 0x00, 0xdd}, /* delay 1s */
2711 {}
2712};
2713static const u8 poxxxx_initQVGA[][4] = {
2714 {0x00, 0x20, 0x33, 0xaa},
2715 {0x00, 0x33, 0x38, 0xaa},
2716 {0x00, 0xbb, 0x0d, 0xaa},
2717 {0xb3, 0x22, 0x00, 0xcc},
2718 {0xb3, 0x23, 0xf0, 0xcc},
2719 {0xb3, 0x16, 0x01, 0xcc},
2720 {0xb3, 0x17, 0x3f, 0xcc},
2721 {0xb3, 0x02, 0xb0, 0xcc},
2722 {0xb3, 0x06, 0x01, 0xcc},
2723 {0xb3, 0x5c, 0x00, 0xcc},
2724 {0x00, 0x04, 0x06, 0xaa},
2725 {0x00, 0x05, 0x3f, 0xaa},
2726 {0x00, 0x04, 0x00, 0xdd}, /* delay 1s */
2727 {}
2728};
2729static const u8 poxxxx_init_end_1[][4] = {
2730 {0x00, 0x47, 0x25, 0xaa},
2731 {0x00, 0x48, 0x80, 0xaa},
2732 {0x00, 0x49, 0x1f, 0xaa},
2733 {0x00, 0x4a, 0x40, 0xaa},
2734 {0x00, 0x44, 0x40, 0xaa},
2735 {0x00, 0xab, 0x4a, 0xaa},
2736 {0x00, 0xb1, 0x00, 0xaa},
2737 {0x00, 0xb2, 0x04, 0xaa},
2738 {0x00, 0xb3, 0x08, 0xaa},
2739 {0x00, 0xb4, 0x0b, 0xaa},
2740 {0x00, 0xb5, 0x0d, 0xaa},
2741 {0x00, 0x59, 0x7e, 0xaa}, /* sharpness */
2742 {0x00, 0x16, 0x00, 0xaa}, /* white balance */
2743 {0x00, 0x18, 0x00, 0xaa},
2744 {}
2745};
2746static const u8 poxxxx_init_end_2[][4] = {
2747 {0x00, 0x1d, 0x85, 0xaa},
2748 {0x00, 0x1e, 0x06, 0xaa},
2749 {0x00, 0x1d, 0x05, 0xaa},
2750 {}
2411}; 2751};
2412 2752
2413struct sensor_info { 2753struct sensor_info {
@@ -2420,33 +2760,89 @@ struct sensor_info {
2420 u8 op; 2760 u8 op;
2421}; 2761};
2422 2762
2423static const struct sensor_info sensor_info_data[] = { 2763/* probe values */
2424/* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */ 2764static const struct sensor_info vc0321_probe_data[] = {
2765/* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */
2766/* 0 OV9640 */
2425 {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, 2767 {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05},
2768/* 1 ICM108T (may respond on IdAdd == 0x83 - tested in vc032x_probe_sensor) */
2426 {-1, 0x80 | 0x20, 0x82, 0x0000, 0x24, 0x25, 0x01}, 2769 {-1, 0x80 | 0x20, 0x82, 0x0000, 0x24, 0x25, 0x01},
2427/* (tested in vc032x_probe_sensor) */ 2770/* 2 PO2130 (may detect PO3130NC - tested in vc032x_probe_sensor)*/
2428/* {-1, 0x80 | 0x20, 0x83, 0x0000, 0x24, 0x25, 0x01}, */ 2771 {-1, 0x80 | 0x76, 0x00, 0x0000, 0x24, 0x25, 0x01},
2429 {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, 2772/* 3 MI1310 */
2773 {-1, 0x80 | 0x5d, 0x00, 0x0000, 0x24, 0x25, 0x01},
2774/* 4 MI360 - tested in vc032x_probe_sensor */
2775/* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */
2776/* 5 7131R */
2777 {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01},
2778/* 6 OV7649 */
2779 {-1, 0x80 | 0x21, 0x0a, 0x0000, 0x21, 0x20, 0x05},
2780/* 7 PAS302BCW */
2781 {-1, 0x80 | 0x40, 0x00, 0x0000, 0x20, 0x22, 0x05},
2782/* 8 OV7660 */
2783 {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05},
2784/* 9 PO3130NC - (tested in vc032x_probe_sensor) */
2785/* {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, */
2786/* 10 PO1030KC */
2787 {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01},
2788/* 11 MI1310_SOC */
2430 {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01}, 2789 {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01},
2431/* (tested in vc032x_probe_sensor) */ 2790/* 12 OV9650 */
2791 {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05},
2792/* 13 S5K532 */
2793 {-1, 0x80 | 0x11, 0x39, 0x0000, 0x24, 0x25, 0x01},
2794/* 14 MI360_SOC - ??? */
2795/* 15 PO1200N */
2796 {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01},
2797/* 16 PO3030K */
2798 {-1, 0x80 | 0x18, 0x00, 0x0000, 0x24, 0x25, 0x01},
2799/* 17 PO2030 */
2800 {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01},
2801/* ?? */
2802 {-1, 0x80 | 0x56, 0x01, 0x0000, 0x64, 0x67, 0x01},
2803 {SENSOR_MI1320, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x65, 0x01},
2804};
2805static const struct sensor_info vc0323_probe_data[] = {
2806/* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */
2807/* 0 OV9640 */
2808 {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05},
2809/* 1 ICM108T (may respond on IdAdd == 0x83 - tested in vc032x_probe_sensor) */
2810 {-1, 0x80 | 0x20, 0x82, 0x0000, 0x24, 0x25, 0x01},
2811/* 2 PO2130 (may detect PO3130NC - tested in vc032x_probe_sensor)*/
2812 {-1, 0x80 | 0x76, 0x00, 0x0000, 0x24, 0x25, 0x01},
2813/* 3 MI1310 */
2814 {-1, 0x80 | 0x5d, 0x00, 0x0000, 0x24, 0x25, 0x01},
2815/* 4 MI360 - tested in vc032x_probe_sensor */
2432/* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */ 2816/* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */
2817/* 5 7131R */
2433 {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01}, 2818 {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01},
2819/* 6 OV7649 */
2434 {-1, 0x80 | 0x21, 0x0a, 0x0000, 0x21, 0x20, 0x05}, 2820 {-1, 0x80 | 0x21, 0x0a, 0x0000, 0x21, 0x20, 0x05},
2821/* 7 PAS302BCW */
2435 {-1, 0x80 | 0x40, 0x00, 0x0000, 0x20, 0x22, 0x05}, 2822 {-1, 0x80 | 0x40, 0x00, 0x0000, 0x20, 0x22, 0x05},
2823/* 8 OV7660 */
2436 {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05}, 2824 {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05},
2437/* {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x0000, 0x24, 0x25, 0x01}, */ 2825/* 9 PO3130NC - (tested in vc032x_probe_sensor) */
2826/* {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, */
2827/* 10 PO1030KC */
2438 {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01}, 2828 {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01},
2439/* {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x0000, 0x24, 0x25, 0x01}, */ 2829/* 11 MI1310_SOC */
2440/* {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, */ 2830 {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01},
2831/* 12 OV9650 */
2832 {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05},
2833/* 13 S5K532 */
2441 {-1, 0x80 | 0x11, 0x39, 0x0000, 0x24, 0x25, 0x01}, 2834 {-1, 0x80 | 0x11, 0x39, 0x0000, 0x24, 0x25, 0x01},
2835/* 14 MI360_SOC - ??? */
2836/* 15 PO1200N */
2442 {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01}, 2837 {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01},
2838/* 16 ?? */
2443 {-1, 0x80 | 0x2d, 0x00, 0x0000, 0x65, 0x67, 0x01}, 2839 {-1, 0x80 | 0x2d, 0x00, 0x0000, 0x65, 0x67, 0x01},
2840/* 17 PO2030 */
2444 {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01}, 2841 {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01},
2842/* ?? */
2445 {-1, 0x80 | 0x56, 0x01, 0x0000, 0x64, 0x67, 0x01}, 2843 {-1, 0x80 | 0x56, 0x01, 0x0000, 0x64, 0x67, 0x01},
2446 {SENSOR_MI1320_SOC, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x67, 0x01}, 2844 {SENSOR_MI1320_SOC, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x67, 0x01},
2447/*fixme: previously detected?*/ 2845/*fixme: not in the ms-win probe - may be found before? */
2448 {SENSOR_MI1320, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x65, 0x01},
2449/*fixme: not in the ms-win probe - may be found before?*/
2450 {SENSOR_OV7670, 0x80 | 0x21, 0x0a, 0x7673, 0x66, 0x67, 0x05}, 2846 {SENSOR_OV7670, 0x80 | 0x21, 0x0a, 0x7673, 0x66, 0x67, 0x05},
2451}; 2847};
2452 2848
@@ -2520,7 +2916,7 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
2520{ 2916{
2521 struct sd *sd = (struct sd *) gspca_dev; 2917 struct sd *sd = (struct sd *) gspca_dev;
2522 struct usb_device *dev = gspca_dev->dev; 2918 struct usb_device *dev = gspca_dev->dev;
2523 int i; 2919 int i, n;
2524 u16 value; 2920 u16 value;
2525 const struct sensor_info *ptsensor_info; 2921 const struct sensor_info *ptsensor_info;
2526 2922
@@ -2531,9 +2927,16 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
2531 } 2927 }
2532 2928
2533 reg_r(gspca_dev, 0xa1, 0xbfcf, 1); 2929 reg_r(gspca_dev, 0xa1, 0xbfcf, 1);
2534 PDEBUG(D_PROBE, "check sensor header %02x", gspca_dev->usb_buf[0]); 2930 PDEBUG(D_PROBE, "vc032%d check sensor header %02x",
2535 for (i = 0; i < ARRAY_SIZE(sensor_info_data); i++) { 2931 sd->bridge == BRIDGE_VC0321 ? 1 : 3, gspca_dev->usb_buf[0]);
2536 ptsensor_info = &sensor_info_data[i]; 2932 if (sd->bridge == BRIDGE_VC0321) {
2933 ptsensor_info = vc0321_probe_data;
2934 n = ARRAY_SIZE(vc0321_probe_data);
2935 } else {
2936 ptsensor_info = vc0323_probe_data;
2937 n = ARRAY_SIZE(vc0323_probe_data);
2938 }
2939 for (i = 0; i < n; i++) {
2537 reg_w(dev, 0xa0, 0x02, 0xb334); 2940 reg_w(dev, 0xa0, 0x02, 0xb334);
2538 reg_w(dev, 0xa0, ptsensor_info->m1, 0xb300); 2941 reg_w(dev, 0xa0, ptsensor_info->m1, 0xb300);
2539 reg_w(dev, 0xa0, ptsensor_info->m2, 0xb300); 2942 reg_w(dev, 0xa0, ptsensor_info->m2, 0xb300);
@@ -2551,13 +2954,15 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
2551 return ptsensor_info->sensorId; 2954 return ptsensor_info->sensorId;
2552 2955
2553 switch (value) { 2956 switch (value) {
2957 case 0x3130:
2958 return SENSOR_PO3130NC;
2554 case 0x7673: 2959 case 0x7673:
2555 return SENSOR_OV7670; 2960 return SENSOR_OV7670;
2556 case 0x8243: 2961 case 0x8243:
2557 return SENSOR_MI0360; 2962 return SENSOR_MI0360;
2558 } 2963 }
2559/*fixme: should return here*/
2560 } 2964 }
2965 ptsensor_info++;
2561 } 2966 }
2562 return -1; 2967 return -1;
2563} 2968}
@@ -2619,7 +3024,7 @@ static void usb_exchange(struct gspca_dev *gspca_dev,
2619 i2c_write(gspca_dev, data[i][0], &data[i][1], 2); 3024 i2c_write(gspca_dev, data[i][0], &data[i][1], 2);
2620 break; 3025 break;
2621 case 0xdd: 3026 case 0xdd:
2622 msleep(data[i][2] + 10); 3027 msleep(data[i][1] * 256 + data[i][2] + 10);
2623 break; 3028 break;
2624 } 3029 }
2625 i++; 3030 i++;
@@ -2646,12 +3051,17 @@ static int sd_config(struct gspca_dev *gspca_dev,
2646 64, /* OV7670 6 */ 3051 64, /* OV7670 6 */
2647 128, /* PO1200 7 */ 3052 128, /* PO1200 7 */
2648 128, /* PO3130NC 8 */ 3053 128, /* PO3130NC 8 */
3054 128, /* POxxxx 9 */
2649 }; 3055 };
2650 3056
2651 cam = &gspca_dev->cam; 3057 cam = &gspca_dev->cam;
2652 sd->bridge = id->driver_info >> 8; 3058 sd->bridge = id->driver_info >> 8;
2653 sd->flags = id->driver_info & 0xff; 3059 sd->flags = id->driver_info & 0xff;
2654 sensor = vc032x_probe_sensor(gspca_dev); 3060 if (id->idVendor == 0x046d &&
3061 (id->idProduct == 0x0892 || id->idProduct == 0x0896))
3062 sensor = SENSOR_POxxxx;
3063 else
3064 sensor = vc032x_probe_sensor(gspca_dev);
2655 switch (sensor) { 3065 switch (sensor) {
2656 case -1: 3066 case -1:
2657 PDEBUG(D_PROBE, "Unknown sensor..."); 3067 PDEBUG(D_PROBE, "Unknown sensor...");
@@ -2684,6 +3094,9 @@ static int sd_config(struct gspca_dev *gspca_dev,
2684 case SENSOR_PO3130NC: 3094 case SENSOR_PO3130NC:
2685 PDEBUG(D_PROBE, "Find Sensor PO3130NC"); 3095 PDEBUG(D_PROBE, "Find Sensor PO3130NC");
2686 break; 3096 break;
3097 case SENSOR_POxxxx:
3098 PDEBUG(D_PROBE, "Sensor POxxxx");
3099 break;
2687 } 3100 }
2688 sd->sensor = sensor; 3101 sd->sensor = sensor;
2689 3102
@@ -2712,28 +3125,19 @@ static int sd_config(struct gspca_dev *gspca_dev,
2712 } 3125 }
2713 cam->npkt = npkt[sd->sensor]; 3126 cam->npkt = npkt[sd->sensor];
2714 3127
3128 sd->brightness = BRIGHTNESS_DEF;
3129 sd->contrast = CONTRAST_DEF;
3130 sd->colors = COLOR_DEF;
2715 sd->hflip = HFLIP_DEF; 3131 sd->hflip = HFLIP_DEF;
2716 sd->vflip = VFLIP_DEF; 3132 sd->vflip = VFLIP_DEF;
2717 if (sd->sensor == SENSOR_OV7670)
2718 sd->flags |= FL_HFLIP | FL_VFLIP;
2719 sd->lightfreq = FREQ_DEF; 3133 sd->lightfreq = FREQ_DEF;
2720 if (sd->sensor != SENSOR_OV7670)
2721 gspca_dev->ctrl_dis = (1 << LIGHTFREQ_IDX);
2722 switch (sd->sensor) {
2723 case SENSOR_MI1310_SOC:
2724 case SENSOR_MI1320_SOC:
2725 case SENSOR_OV7660:
2726 case SENSOR_OV7670:
2727 case SENSOR_PO1200:
2728 break;
2729 default:
2730 gspca_dev->ctrl_dis = (1 << HFLIP_IDX)
2731 | (1 << VFLIP_IDX);
2732 break;
2733 }
2734
2735 sd->sharpness = SHARPNESS_DEF; 3134 sd->sharpness = SHARPNESS_DEF;
2736 3135
3136 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
3137
3138 if (sd->sensor == SENSOR_OV7670)
3139 sd->flags |= FL_HFLIP | FL_VFLIP;
3140
2737 if (sd->bridge == BRIDGE_VC0321) { 3141 if (sd->bridge == BRIDGE_VC0321) {
2738 reg_r(gspca_dev, 0x8a, 0, 3); 3142 reg_r(gspca_dev, 0x8a, 0, 3);
2739 reg_w(dev, 0x87, 0x00, 0x0f0f); 3143 reg_w(dev, 0x87, 0x00, 0x0f0f);
@@ -2747,10 +3151,55 @@ static int sd_config(struct gspca_dev *gspca_dev,
2747/* this function is called at probe and resume time */ 3151/* this function is called at probe and resume time */
2748static int sd_init(struct gspca_dev *gspca_dev) 3152static int sd_init(struct gspca_dev *gspca_dev)
2749{ 3153{
3154 struct sd *sd = (struct sd *) gspca_dev;
3155
3156 if (sd->sensor == SENSOR_POxxxx) {
3157 reg_r(gspca_dev, 0xa1, 0xb300, 1);
3158 if (gspca_dev->usb_buf[0] != 0) {
3159 reg_w(gspca_dev->dev, 0xa0, 0x26, 0xb300);
3160 reg_w(gspca_dev->dev, 0xa0, 0x04, 0xb300);
3161 reg_w(gspca_dev->dev, 0xa0, 0x00, 0xb300);
3162 }
3163 }
2750 return 0; 3164 return 0;
2751} 3165}
2752 3166
2753/* some sensors only */ 3167static void setbrightness(struct gspca_dev *gspca_dev)
3168{
3169 struct sd *sd = (struct sd *) gspca_dev;
3170 u8 data;
3171
3172 if (gspca_dev->ctrl_dis & (1 << BRIGHTNESS_IDX))
3173 return;
3174 data = sd->brightness;
3175 if (data >= 0x80)
3176 data &= 0x7f;
3177 else
3178 data = 0xff ^ data;
3179 i2c_write(gspca_dev, 0x98, &data, 1);
3180}
3181
3182static void setcontrast(struct gspca_dev *gspca_dev)
3183{
3184 struct sd *sd = (struct sd *) gspca_dev;
3185
3186 if (gspca_dev->ctrl_dis & (1 << CONTRAST_IDX))
3187 return;
3188 i2c_write(gspca_dev, 0x99, &sd->contrast, 1);
3189}
3190
3191static void setcolors(struct gspca_dev *gspca_dev)
3192{
3193 struct sd *sd = (struct sd *) gspca_dev;
3194 u8 data;
3195
3196 if (gspca_dev->ctrl_dis & (1 << COLORS_IDX))
3197 return;
3198 data = sd->colors - (sd->colors >> 3) - 1;
3199 i2c_write(gspca_dev, 0x94, &data, 1);
3200 i2c_write(gspca_dev, 0x95, &sd->colors, 1);
3201}
3202
2754static void sethvflip(struct gspca_dev *gspca_dev) 3203static void sethvflip(struct gspca_dev *gspca_dev)
2755{ 3204{
2756 struct sd *sd = (struct sd *) gspca_dev; 3205 struct sd *sd = (struct sd *) gspca_dev;
@@ -2764,6 +3213,7 @@ static void sethvflip(struct gspca_dev *gspca_dev)
2764 vflip = !vflip; 3213 vflip = !vflip;
2765 switch (sd->sensor) { 3214 switch (sd->sensor) {
2766 case SENSOR_MI1310_SOC: 3215 case SENSOR_MI1310_SOC:
3216 case SENSOR_MI1320:
2767 case SENSOR_MI1320_SOC: 3217 case SENSOR_MI1320_SOC:
2768 data[0] = data[1] = 0; /* select page 0 */ 3218 data[0] = data[1] = 0; /* select page 0 */
2769 i2c_write(gspca_dev, 0xf0, data, 2); 3219 i2c_write(gspca_dev, 0xf0, data, 2);
@@ -2801,18 +3251,29 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
2801 usb_exchange(gspca_dev, ov7660_freq_tb[sd->lightfreq]); 3251 usb_exchange(gspca_dev, ov7660_freq_tb[sd->lightfreq]);
2802} 3252}
2803 3253
2804/* po1200 only */
2805static void setsharpness(struct gspca_dev *gspca_dev) 3254static void setsharpness(struct gspca_dev *gspca_dev)
2806{ 3255{
2807 struct sd *sd = (struct sd *) gspca_dev; 3256 struct sd *sd = (struct sd *) gspca_dev;
2808 u8 data; 3257 u8 data;
2809 3258
2810 if (sd->sensor != SENSOR_PO1200) 3259 switch (sd->sensor) {
2811 return; 3260 case SENSOR_PO1200:
2812 data = 0; 3261 data = 0;
2813 i2c_write(gspca_dev, 0x03, &data, 1); 3262 i2c_write(gspca_dev, 0x03, &data, 1);
2814 data = 0xb5 + sd->sharpness * 3; 3263 if (sd->sharpness < 0)
2815 i2c_write(gspca_dev, 0x61, &data, 1); 3264 data = 0x6a;
3265 else
3266 data = 0xb5 + sd->sharpness * 3;
3267 i2c_write(gspca_dev, 0x61, &data, 1);
3268 break;
3269 case SENSOR_POxxxx:
3270 if (sd->sharpness < 0)
3271 data = 0x7e; /* def = max */
3272 else
3273 data = 0x60 + sd->sharpness * 0x0f;
3274 i2c_write(gspca_dev, 0x59, &data, 1);
3275 break;
3276 }
2816} 3277}
2817 3278
2818static int sd_start(struct gspca_dev *gspca_dev) 3279static int sd_start(struct gspca_dev *gspca_dev)
@@ -2922,12 +3383,27 @@ static int sd_start(struct gspca_dev *gspca_dev)
2922 usb_exchange(gspca_dev, init); 3383 usb_exchange(gspca_dev, init);
2923 init = po3130_rundata; 3384 init = po3130_rundata;
2924 break; 3385 break;
2925 default: 3386 case SENSOR_PO1200:
2926/* case SENSOR_PO1200: */
2927 GammaT = po1200_gamma; 3387 GammaT = po1200_gamma;
2928 MatrixT = po1200_matrix; 3388 MatrixT = po1200_matrix;
2929 init = po1200_initVGA_data; 3389 init = po1200_initVGA_data;
2930 break; 3390 break;
3391 default:
3392/* case SENSOR_POxxxx: */
3393 usb_exchange(gspca_dev, poxxxx_init_common);
3394 if (mode)
3395 init = poxxxx_initQVGA;
3396 else
3397 init = poxxxx_initVGA;
3398 usb_exchange(gspca_dev, init);
3399 reg_r(gspca_dev, 0x8c, 0x0000, 3);
3400 reg_w(gspca_dev->dev, 0xa0,
3401 gspca_dev->usb_buf[2] & 1 ? 0 : 1,
3402 0xb35c);
3403 msleep(300);
3404/*fixme: i2c read 04 and 05*/
3405 init = poxxxx_init_end_1;
3406 break;
2931 } 3407 }
2932 usb_exchange(gspca_dev, init); 3408 usb_exchange(gspca_dev, init);
2933 if (GammaT && MatrixT) { 3409 if (GammaT && MatrixT) {
@@ -2936,7 +3412,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
2936 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb86c); 3412 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb86c);
2937 put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c); 3413 put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c);
2938 3414
2939 /* set the led on 0x0892 0x0896 */
2940 switch (sd->sensor) { 3415 switch (sd->sensor) {
2941 case SENSOR_PO1200: 3416 case SENSOR_PO1200:
2942 case SENSOR_HV7131R: 3417 case SENSOR_HV7131R:
@@ -2945,16 +3420,22 @@ static int sd_start(struct gspca_dev *gspca_dev)
2945 case SENSOR_MI1310_SOC: 3420 case SENSOR_MI1310_SOC:
2946 reg_w(gspca_dev->dev, 0x89, 0x058c, 0x0000); 3421 reg_w(gspca_dev->dev, 0x89, 0x058c, 0x0000);
2947 break; 3422 break;
2948 default:
2949 if (!(sd->flags & FL_SAMSUNG))
2950 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff);
2951 break;
2952 } 3423 }
2953 msleep(100); 3424 msleep(100);
2954 setsharpness(gspca_dev); 3425 setsharpness(gspca_dev);
2955 sethvflip(gspca_dev); 3426 sethvflip(gspca_dev);
2956 setlightfreq(gspca_dev); 3427 setlightfreq(gspca_dev);
2957 } 3428 }
3429 if (sd->sensor == SENSOR_POxxxx) {
3430 setcolors(gspca_dev);
3431 setbrightness(gspca_dev);
3432 setcontrast(gspca_dev);
3433
3434 /* led on */
3435 msleep(80);
3436 reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff);
3437 usb_exchange(gspca_dev, poxxxx_init_end_2);
3438 }
2958 return 0; 3439 return 0;
2959} 3440}
2960 3441
@@ -2963,10 +3444,17 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
2963 struct usb_device *dev = gspca_dev->dev; 3444 struct usb_device *dev = gspca_dev->dev;
2964 struct sd *sd = (struct sd *) gspca_dev; 3445 struct sd *sd = (struct sd *) gspca_dev;
2965 3446
2966 if (sd->sensor == SENSOR_MI1310_SOC) 3447 switch (sd->sensor) {
3448 case SENSOR_MI1310_SOC:
2967 reg_w(dev, 0x89, 0x058c, 0x00ff); 3449 reg_w(dev, 0x89, 0x058c, 0x00ff);
2968 else if (!(sd->flags & FL_SAMSUNG)) 3450 break;
2969 reg_w(dev, 0x89, 0xffff, 0xffff); 3451 case SENSOR_POxxxx:
3452 return;
3453 default:
3454 if (!(sd->flags & FL_SAMSUNG))
3455 reg_w(dev, 0x89, 0xffff, 0xffff);
3456 break;
3457 }
2970 reg_w(dev, 0xa0, 0x01, 0xb301); 3458 reg_w(dev, 0xa0, 0x01, 0xb301);
2971 reg_w(dev, 0xa0, 0x09, 0xb003); 3459 reg_w(dev, 0xa0, 0x09, 0xb003);
2972} 3460}
@@ -2984,6 +3472,12 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
2984 reg_w(dev, 0x89, 0x058c, 0x00ff); 3472 reg_w(dev, 0x89, 0x058c, 0x00ff);
2985 else if (!(sd->flags & FL_SAMSUNG)) 3473 else if (!(sd->flags & FL_SAMSUNG))
2986 reg_w(dev, 0x89, 0xffff, 0xffff); 3474 reg_w(dev, 0x89, 0xffff, 0xffff);
3475
3476 if (sd->sensor == SENSOR_POxxxx) {
3477 reg_w(dev, 0xa0, 0x26, 0xb300);
3478 reg_w(dev, 0xa0, 0x04, 0xb300);
3479 reg_w(dev, 0xa0, 0x00, 0xb300);
3480 }
2987} 3481}
2988 3482
2989static void sd_pkt_scan(struct gspca_dev *gspca_dev, 3483static void sd_pkt_scan(struct gspca_dev *gspca_dev,
@@ -3020,6 +3514,60 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
3020 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 3514 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
3021} 3515}
3022 3516
3517static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
3518{
3519 struct sd *sd = (struct sd *) gspca_dev;
3520
3521 sd->brightness = val;
3522 if (gspca_dev->streaming)
3523 setbrightness(gspca_dev);
3524 return 0;
3525}
3526
3527static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
3528{
3529 struct sd *sd = (struct sd *) gspca_dev;
3530
3531 *val = sd->brightness;
3532 return 0;
3533}
3534
3535static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
3536{
3537 struct sd *sd = (struct sd *) gspca_dev;
3538
3539 sd->contrast = val;
3540 if (gspca_dev->streaming)
3541 setcontrast(gspca_dev);
3542 return 0;
3543}
3544
3545static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
3546{
3547 struct sd *sd = (struct sd *) gspca_dev;
3548
3549 *val = sd->contrast;
3550 return 0;
3551}
3552
3553static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
3554{
3555 struct sd *sd = (struct sd *) gspca_dev;
3556
3557 sd->colors = val;
3558 if (gspca_dev->streaming)
3559 setcolors(gspca_dev);
3560 return 0;
3561}
3562
3563static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
3564{
3565 struct sd *sd = (struct sd *) gspca_dev;
3566
3567 *val = sd->colors;
3568 return 0;
3569}
3570
3023static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) 3571static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
3024{ 3572{
3025 struct sd *sd = (struct sd *) gspca_dev; 3573 struct sd *sd = (struct sd *) gspca_dev;
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index 1a800fc1c00e..50986da3d912 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -1,9 +1,8 @@
1/* 1/*
2 * Z-Star/Vimicro zc301/zc302p/vc30x library 2 * Z-Star/Vimicro zc301/zc302p/vc30x library
3 * Copyright (C) 2004 2005 2006 Michel Xhaard
4 * mxhaard@magic.fr
5 * 3 *
6 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> 4 * Copyright (C) 2009-2010 Jean-Francois Moine <http://moinejf.free.fr>
5 * Copyright (C) 2004 2005 2006 Michel Xhaard mxhaard@magic.fr
7 * 6 *
8 * 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
9 * 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
@@ -22,10 +21,11 @@
22 21
23#define MODULE_NAME "zc3xx" 22#define MODULE_NAME "zc3xx"
24 23
24#include <linux/input.h>
25#include "gspca.h" 25#include "gspca.h"
26#include "jpeg.h" 26#include "jpeg.h"
27 27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, " 28MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>, "
29 "Serge A. Suchkov <Serge.A.S@tochka.ru>"); 29 "Serge A. Suchkov <Serge.A.S@tochka.ru>");
30MODULE_DESCRIPTION("GSPCA ZC03xx/VC3xx USB Camera Driver"); 30MODULE_DESCRIPTION("GSPCA ZC03xx/VC3xx USB Camera Driver");
31MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
@@ -39,18 +39,18 @@ static int force_sensor = -1;
39struct sd { 39struct sd {
40 struct gspca_dev gspca_dev; /* !! must be the first item */ 40 struct gspca_dev gspca_dev; /* !! must be the first item */
41 41
42 __u8 brightness; 42 u8 brightness;
43 __u8 contrast; 43 u8 contrast;
44 __u8 gamma; 44 u8 gamma;
45 __u8 autogain; 45 u8 autogain;
46 __u8 lightfreq; 46 u8 lightfreq;
47 __u8 sharpness; 47 u8 sharpness;
48 u8 quality; /* image quality */ 48 u8 quality; /* image quality */
49#define QUALITY_MIN 40 49#define QUALITY_MIN 40
50#define QUALITY_MAX 60 50#define QUALITY_MAX 60
51#define QUALITY_DEF 50 51#define QUALITY_DEF 50
52 52
53 signed char sensor; /* Type of image sensor chip */ 53 u8 sensor; /* Type of image sensor chip */
54/* !! values used in different tables */ 54/* !! values used in different tables */
55#define SENSOR_ADCM2700 0 55#define SENSOR_ADCM2700 0
56#define SENSOR_CS2102 1 56#define SENSOR_CS2102 1
@@ -92,9 +92,8 @@ static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
92static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); 92static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
93static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); 93static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
94 94
95static struct ctrl sd_ctrls[] = { 95static const struct ctrl sd_ctrls[] = {
96#define BRIGHTNESS_IDX 0 96#define BRIGHTNESS_IDX 0
97#define SD_BRIGHTNESS 0
98 { 97 {
99 { 98 {
100 .id = V4L2_CID_BRIGHTNESS, 99 .id = V4L2_CID_BRIGHTNESS,
@@ -103,26 +102,26 @@ static struct ctrl sd_ctrls[] = {
103 .minimum = 0, 102 .minimum = 0,
104 .maximum = 255, 103 .maximum = 255,
105 .step = 1, 104 .step = 1,
106 .default_value = 128, 105#define BRIGHTNESS_DEF 128
106 .default_value = BRIGHTNESS_DEF,
107 }, 107 },
108 .set = sd_setbrightness, 108 .set = sd_setbrightness,
109 .get = sd_getbrightness, 109 .get = sd_getbrightness,
110 }, 110 },
111#define SD_CONTRAST 1
112 { 111 {
113 { 112 {
114 .id = V4L2_CID_CONTRAST, 113 .id = V4L2_CID_CONTRAST,
115 .type = V4L2_CTRL_TYPE_INTEGER, 114 .type = V4L2_CTRL_TYPE_INTEGER,
116 .name = "Contrast", 115 .name = "Contrast",
117 .minimum = 0, 116 .minimum = 0,
118 .maximum = 256, 117 .maximum = 255,
119 .step = 1, 118 .step = 1,
120 .default_value = 128, 119#define CONTRAST_DEF 128
120 .default_value = CONTRAST_DEF,
121 }, 121 },
122 .set = sd_setcontrast, 122 .set = sd_setcontrast,
123 .get = sd_getcontrast, 123 .get = sd_getcontrast,
124 }, 124 },
125#define SD_GAMMA 2
126 { 125 {
127 { 126 {
128 .id = V4L2_CID_GAMMA, 127 .id = V4L2_CID_GAMMA,
@@ -136,7 +135,6 @@ static struct ctrl sd_ctrls[] = {
136 .set = sd_setgamma, 135 .set = sd_setgamma,
137 .get = sd_getgamma, 136 .get = sd_getgamma,
138 }, 137 },
139#define SD_AUTOGAIN 3
140 { 138 {
141 { 139 {
142 .id = V4L2_CID_AUTOGAIN, 140 .id = V4L2_CID_AUTOGAIN,
@@ -145,13 +143,13 @@ static struct ctrl sd_ctrls[] = {
145 .minimum = 0, 143 .minimum = 0,
146 .maximum = 1, 144 .maximum = 1,
147 .step = 1, 145 .step = 1,
148 .default_value = 1, 146#define AUTOGAIN_DEF 1
147 .default_value = AUTOGAIN_DEF,
149 }, 148 },
150 .set = sd_setautogain, 149 .set = sd_setautogain,
151 .get = sd_getautogain, 150 .get = sd_getautogain,
152 }, 151 },
153#define LIGHTFREQ_IDX 4 152#define LIGHTFREQ_IDX 4
154#define SD_FREQ 4
155 { 153 {
156 { 154 {
157 .id = V4L2_CID_POWER_LINE_FREQUENCY, 155 .id = V4L2_CID_POWER_LINE_FREQUENCY,
@@ -160,12 +158,12 @@ static struct ctrl sd_ctrls[] = {
160 .minimum = 0, 158 .minimum = 0,
161 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ 159 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
162 .step = 1, 160 .step = 1,
163 .default_value = 1, 161#define FREQ_DEF 0
162 .default_value = FREQ_DEF,
164 }, 163 },
165 .set = sd_setfreq, 164 .set = sd_setfreq,
166 .get = sd_getfreq, 165 .get = sd_getfreq,
167 }, 166 },
168#define SD_SHARPNESS 5
169 { 167 {
170 { 168 {
171 .id = V4L2_CID_SHARPNESS, 169 .id = V4L2_CID_SHARPNESS,
@@ -174,7 +172,8 @@ static struct ctrl sd_ctrls[] = {
174 .minimum = 0, 172 .minimum = 0,
175 .maximum = 3, 173 .maximum = 3,
176 .step = 1, 174 .step = 1,
177 .default_value = 2, 175#define SHARPNESS_DEF 2
176 .default_value = SHARPNESS_DEF,
178 }, 177 },
179 .set = sd_setsharpness, 178 .set = sd_setsharpness,
180 .get = sd_getsharpness, 179 .get = sd_getsharpness,
@@ -194,6 +193,19 @@ static const struct v4l2_pix_format vga_mode[] = {
194 .priv = 0}, 193 .priv = 0},
195}; 194};
196 195
196static const struct v4l2_pix_format broken_vga_mode[] = {
197 {320, 232, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
198 .bytesperline = 320,
199 .sizeimage = 320 * 232 * 4 / 8 + 590,
200 .colorspace = V4L2_COLORSPACE_JPEG,
201 .priv = 1},
202 {640, 472, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
203 .bytesperline = 640,
204 .sizeimage = 640 * 472 * 3 / 8 + 590,
205 .colorspace = V4L2_COLORSPACE_JPEG,
206 .priv = 0},
207};
208
197static const struct v4l2_pix_format sif_mode[] = { 209static const struct v4l2_pix_format sif_mode[] = {
198 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, 210 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
199 .bytesperline = 176, 211 .bytesperline = 176,
@@ -209,9 +221,9 @@ static const struct v4l2_pix_format sif_mode[] = {
209 221
210/* usb exchanges */ 222/* usb exchanges */
211struct usb_action { 223struct usb_action {
212 __u8 req; 224 u8 req;
213 __u8 val; 225 u8 val;
214 __u16 idx; 226 u16 idx;
215}; 227};
216 228
217static const struct usb_action adcm2700_Initial[] = { 229static const struct usb_action adcm2700_Initial[] = {
@@ -421,7 +433,7 @@ static const struct usb_action adcm2700_NoFliker[] = {
421 {0xaa, 0xfe, 0x0010}, /* 00,fe,10,aa */ 433 {0xaa, 0xfe, 0x0010}, /* 00,fe,10,aa */
422 {} 434 {}
423}; 435};
424static const struct usb_action cs2102_Initial[] = { /* 320x240 */ 436static const struct usb_action cs2102_InitialScale[] = { /* 320x240 */
425 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 437 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
426 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, 438 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
427 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, 439 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT},
@@ -473,7 +485,7 @@ static const struct usb_action cs2102_Initial[] = { /* 320x240 */
473 {} 485 {}
474}; 486};
475 487
476static const struct usb_action cs2102_InitialScale[] = { /* 640x480 */ 488static const struct usb_action cs2102_Initial[] = { /* 640x480 */
477 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 489 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
478 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, 490 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
479 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, 491 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT},
@@ -524,7 +536,7 @@ static const struct usb_action cs2102_InitialScale[] = { /* 640x480 */
524 {0xa0, 0x00, 0x01ad}, 536 {0xa0, 0x00, 0x01ad},
525 {} 537 {}
526}; 538};
527static const struct usb_action cs2102_50HZ[] = { 539static const struct usb_action cs2102_50HZScale[] = {
528 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 540 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
529 {0xaa, 0x23, 0x0001}, 541 {0xaa, 0x23, 0x0001},
530 {0xaa, 0x24, 0x005f}, 542 {0xaa, 0x24, 0x005f},
@@ -546,7 +558,7 @@ static const struct usb_action cs2102_50HZ[] = {
546 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, 558 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
547 {} 559 {}
548}; 560};
549static const struct usb_action cs2102_50HZScale[] = { 561static const struct usb_action cs2102_50HZ[] = {
550 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 562 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
551 {0xaa, 0x23, 0x0000}, 563 {0xaa, 0x23, 0x0000},
552 {0xaa, 0x24, 0x00af}, 564 {0xaa, 0x24, 0x00af},
@@ -568,7 +580,7 @@ static const struct usb_action cs2102_50HZScale[] = {
568 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, 580 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
569 {} 581 {}
570}; 582};
571static const struct usb_action cs2102_60HZ[] = { 583static const struct usb_action cs2102_60HZScale[] = {
572 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 584 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
573 {0xaa, 0x23, 0x0001}, 585 {0xaa, 0x23, 0x0001},
574 {0xaa, 0x24, 0x0055}, 586 {0xaa, 0x24, 0x0055},
@@ -590,7 +602,7 @@ static const struct usb_action cs2102_60HZ[] = {
590 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, 602 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
591 {} 603 {}
592}; 604};
593static const struct usb_action cs2102_60HZScale[] = { 605static const struct usb_action cs2102_60HZ[] = {
594 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 606 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
595 {0xaa, 0x23, 0x0000}, 607 {0xaa, 0x23, 0x0000},
596 {0xaa, 0x24, 0x00aa}, 608 {0xaa, 0x24, 0x00aa},
@@ -612,7 +624,7 @@ static const struct usb_action cs2102_60HZScale[] = {
612 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, 624 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
613 {} 625 {}
614}; 626};
615static const struct usb_action cs2102_NoFliker[] = { 627static const struct usb_action cs2102_NoFlikerScale[] = {
616 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 628 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
617 {0xaa, 0x23, 0x0001}, 629 {0xaa, 0x23, 0x0001},
618 {0xaa, 0x24, 0x005f}, 630 {0xaa, 0x24, 0x005f},
@@ -634,7 +646,7 @@ static const struct usb_action cs2102_NoFliker[] = {
634 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, 646 {0xa0, 0xff, ZC3XX_R020_HSYNC_3},
635 {} 647 {}
636}; 648};
637static const struct usb_action cs2102_NoFlikerScale[] = { 649static const struct usb_action cs2102_NoFliker[] = {
638 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, 650 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
639 {0xaa, 0x23, 0x0000}, 651 {0xaa, 0x23, 0x0000},
640 {0xaa, 0x24, 0x00af}, 652 {0xaa, 0x24, 0x00af},
@@ -658,7 +670,7 @@ static const struct usb_action cs2102_NoFlikerScale[] = {
658}; 670};
659 671
660/* CS2102_KOCOM */ 672/* CS2102_KOCOM */
661static const struct usb_action cs2102K_Initial[] = { 673static const struct usb_action cs2102K_InitialScale[] = {
662 {0xa0, 0x11, ZC3XX_R002_CLOCKSELECT}, 674 {0xa0, 0x11, ZC3XX_R002_CLOCKSELECT},
663 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 675 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
664 {0xa0, 0x08, ZC3XX_R010_CMOSSENSORSELECT}, 676 {0xa0, 0x08, ZC3XX_R010_CMOSSENSORSELECT},
@@ -917,7 +929,7 @@ static const struct usb_action cs2102K_Initial[] = {
917 {} 929 {}
918}; 930};
919 931
920static const struct usb_action cs2102K_InitialScale[] = { 932static const struct usb_action cs2102K_Initial[] = {
921 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 933 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
922 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, 934 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
923 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 935 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
@@ -1495,7 +1507,7 @@ static const struct usb_action gc0305_NoFliker[] = {
1495 {} 1507 {}
1496}; 1508};
1497 1509
1498static const struct usb_action hdcs2020xb_Initial[] = { 1510static const struct usb_action hdcs2020b_InitialScale[] = {
1499 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 1511 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
1500 {0xa0, 0x11, ZC3XX_R002_CLOCKSELECT}, 1512 {0xa0, 0x11, ZC3XX_R002_CLOCKSELECT},
1501 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* qtable 0x05 */ 1513 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* qtable 0x05 */
@@ -1627,7 +1639,7 @@ static const struct usb_action hdcs2020xb_Initial[] = {
1627 {0xa0, 0x40, ZC3XX_R118_BGAIN}, 1639 {0xa0, 0x40, ZC3XX_R118_BGAIN},
1628 {} 1640 {}
1629}; 1641};
1630static const struct usb_action hdcs2020xb_InitialScale[] = { 1642static const struct usb_action hdcs2020b_Initial[] = {
1631 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 1643 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
1632 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, 1644 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
1633 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 1645 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
@@ -1819,7 +1831,7 @@ static const struct usb_action hdcs2020b_NoFliker[] = {
1819 {} 1831 {}
1820}; 1832};
1821 1833
1822static const struct usb_action hv7131bxx_Initial[] = { /* 320x240 */ 1834static const struct usb_action hv7131b_InitialScale[] = { /* 320x240 */
1823 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 1835 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
1824 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, 1836 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
1825 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, 1837 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT},
@@ -1866,7 +1878,7 @@ static const struct usb_action hv7131bxx_Initial[] = { /* 320x240 */
1866 {} 1878 {}
1867}; 1879};
1868 1880
1869static const struct usb_action hv7131bxx_InitialScale[] = { /* 640x480*/ 1881static const struct usb_action hv7131b_Initial[] = { /* 640x480*/
1870 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 1882 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
1871 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, 1883 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
1872 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, 1884 {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT},
@@ -2063,7 +2075,7 @@ static const struct usb_action hv7131b_NoFlikerScale[] = { /* 320x240 */
2063 {} 2075 {}
2064}; 2076};
2065 2077
2066static const struct usb_action hv7131cxx_Initial[] = { 2078static const struct usb_action hv7131r_InitialScale[] = {
2067 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 2079 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
2068 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, 2080 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
2069 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, 2081 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT},
@@ -2157,7 +2169,7 @@ static const struct usb_action hv7131cxx_Initial[] = {
2157 {} 2169 {}
2158}; 2170};
2159 2171
2160static const struct usb_action hv7131cxx_InitialScale[] = { 2172static const struct usb_action hv7131r_Initial[] = {
2161 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 2173 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
2162 2174
2163 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* diff */ 2175 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* diff */
@@ -2259,7 +2271,7 @@ static const struct usb_action hv7131cxx_InitialScale[] = {
2259 {} 2271 {}
2260}; 2272};
2261 2273
2262static const struct usb_action icm105axx_Initial[] = { 2274static const struct usb_action icm105a_InitialScale[] = {
2263 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 2275 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
2264 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, 2276 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
2265 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 2277 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
@@ -2436,7 +2448,7 @@ static const struct usb_action icm105axx_Initial[] = {
2436 {} 2448 {}
2437}; 2449};
2438 2450
2439static const struct usb_action icm105axx_InitialScale[] = { 2451static const struct usb_action icm105a_Initial[] = {
2440 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 2452 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
2441 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, 2453 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
2442 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 2454 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
@@ -2615,7 +2627,7 @@ static const struct usb_action icm105axx_InitialScale[] = {
2615 {0xa0, 0x40, ZC3XX_R118_BGAIN}, 2627 {0xa0, 0x40, ZC3XX_R118_BGAIN},
2616 {} 2628 {}
2617}; 2629};
2618static const struct usb_action icm105a_50HZ[] = { 2630static const struct usb_action icm105a_50HZScale[] = {
2619 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2631 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2620 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ 2632 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */
2621 {0xaa, 0x0c, 0x0020}, /* 00,0c,20,aa */ 2633 {0xaa, 0x0c, 0x0020}, /* 00,0c,20,aa */
@@ -2646,7 +2658,7 @@ static const struct usb_action icm105a_50HZ[] = {
2646 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */ 2658 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */
2647 {} 2659 {}
2648}; 2660};
2649static const struct usb_action icm105a_50HZScale[] = { 2661static const struct usb_action icm105a_50HZ[] = {
2650 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2662 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2651 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ 2663 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */
2652 {0xaa, 0x0c, 0x008c}, /* 00,0c,8c,aa */ 2664 {0xaa, 0x0c, 0x008c}, /* 00,0c,8c,aa */
@@ -2679,7 +2691,7 @@ static const struct usb_action icm105a_50HZScale[] = {
2679 {0xa0, 0xc0, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,c0,cc */ 2691 {0xa0, 0xc0, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,c0,cc */
2680 {} 2692 {}
2681}; 2693};
2682static const struct usb_action icm105a_60HZ[] = { 2694static const struct usb_action icm105a_60HZScale[] = {
2683 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2695 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2684 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ 2696 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */
2685 {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */ 2697 {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */
@@ -2710,7 +2722,7 @@ static const struct usb_action icm105a_60HZ[] = {
2710 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */ 2722 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */
2711 {} 2723 {}
2712}; 2724};
2713static const struct usb_action icm105a_60HZScale[] = { 2725static const struct usb_action icm105a_60HZ[] = {
2714 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2726 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2715 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ 2727 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */
2716 {0xaa, 0x0c, 0x0008}, /* 00,0c,08,aa */ 2728 {0xaa, 0x0c, 0x0008}, /* 00,0c,08,aa */
@@ -2743,7 +2755,7 @@ static const struct usb_action icm105a_60HZScale[] = {
2743 {0xa0, 0xc0, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,c0,cc */ 2755 {0xa0, 0xc0, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,c0,cc */
2744 {} 2756 {}
2745}; 2757};
2746static const struct usb_action icm105a_NoFliker[] = { 2758static const struct usb_action icm105a_NoFlikerScale[] = {
2747 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2759 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2748 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ 2760 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */
2749 {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */ 2761 {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */
@@ -2774,7 +2786,7 @@ static const struct usb_action icm105a_NoFliker[] = {
2774 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */ 2786 {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */
2775 {} 2787 {}
2776}; 2788};
2777static const struct usb_action icm105a_NoFlikerScale[] = { 2789static const struct usb_action icm105a_NoFliker[] = {
2778 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2790 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2779 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ 2791 {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */
2780 {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */ 2792 {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */
@@ -2808,7 +2820,7 @@ static const struct usb_action icm105a_NoFlikerScale[] = {
2808 {} 2820 {}
2809}; 2821};
2810 2822
2811static const struct usb_action MC501CB_InitialScale[] = { 2823static const struct usb_action mc501cb_Initial[] = {
2812 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ 2824 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
2813 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* 00,02,00,cc */ 2825 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* 00,02,00,cc */
2814 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ 2826 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
@@ -2928,7 +2940,7 @@ static const struct usb_action MC501CB_InitialScale[] = {
2928 {} 2940 {}
2929}; 2941};
2930 2942
2931static const struct usb_action MC501CB_Initial[] = { /* 320x240 */ 2943static const struct usb_action mc501cb_InitialScale[] = { /* 320x240 */
2932 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ 2944 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
2933 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */ 2945 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */
2934 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ 2946 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
@@ -3047,7 +3059,7 @@ static const struct usb_action MC501CB_Initial[] = { /* 320x240 */
3047 {} 3059 {}
3048}; 3060};
3049 3061
3050static const struct usb_action MC501CB_50HZ[] = { 3062static const struct usb_action mc501cb_50HZScale[] = {
3051 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ 3063 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */
3052 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ 3064 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */
3053 {0xaa, 0x36, 0x001d}, /* 00,36,1D,aa */ 3065 {0xaa, 0x36, 0x001d}, /* 00,36,1D,aa */
@@ -3064,7 +3076,7 @@ static const struct usb_action MC501CB_50HZ[] = {
3064 {} 3076 {}
3065}; 3077};
3066 3078
3067static const struct usb_action MC501CB_50HZScale[] = { 3079static const struct usb_action mc501cb_50HZ[] = {
3068 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ 3080 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */
3069 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ 3081 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */
3070 {0xaa, 0x36, 0x003a}, /* 00,36,3A,aa */ 3082 {0xaa, 0x36, 0x003a}, /* 00,36,3A,aa */
@@ -3081,7 +3093,7 @@ static const struct usb_action MC501CB_50HZScale[] = {
3081 {} 3093 {}
3082}; 3094};
3083 3095
3084static const struct usb_action MC501CB_60HZ[] = { 3096static const struct usb_action mc501cb_60HZScale[] = {
3085 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ 3097 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */
3086 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ 3098 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */
3087 {0xaa, 0x36, 0x0018}, /* 00,36,18,aa */ 3099 {0xaa, 0x36, 0x0018}, /* 00,36,18,aa */
@@ -3098,7 +3110,7 @@ static const struct usb_action MC501CB_60HZ[] = {
3098 {} 3110 {}
3099}; 3111};
3100 3112
3101static const struct usb_action MC501CB_60HZScale[] = { 3113static const struct usb_action mc501cb_60HZ[] = {
3102 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ 3114 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */
3103 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ 3115 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */
3104 {0xaa, 0x36, 0x0030}, /* 00,36,30,aa */ 3116 {0xaa, 0x36, 0x0030}, /* 00,36,30,aa */
@@ -3115,7 +3127,7 @@ static const struct usb_action MC501CB_60HZScale[] = {
3115 {} 3127 {}
3116}; 3128};
3117 3129
3118static const struct usb_action MC501CB_NoFliker[] = { 3130static const struct usb_action mc501cb_NoFlikerScale[] = {
3119 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ 3131 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */
3120 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ 3132 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */
3121 {0xaa, 0x36, 0x0018}, /* 00,36,18,aa */ 3133 {0xaa, 0x36, 0x0018}, /* 00,36,18,aa */
@@ -3132,7 +3144,7 @@ static const struct usb_action MC501CB_NoFliker[] = {
3132 {} 3144 {}
3133}; 3145};
3134 3146
3135static const struct usb_action MC501CB_NoFlikerScale[] = { 3147static const struct usb_action mc501cb_NoFliker[] = {
3136 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ 3148 {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */
3137 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ 3149 {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */
3138 {0xaa, 0x36, 0x0030}, /* 00,36,30,aa */ 3150 {0xaa, 0x36, 0x0030}, /* 00,36,30,aa */
@@ -3144,8 +3156,8 @@ static const struct usb_action MC501CB_NoFlikerScale[] = {
3144 {} 3156 {}
3145}; 3157};
3146 3158
3147/* from zs211.inf - HKR,%OV7620%,Initial - 640x480 */ 3159/* from zs211.inf */
3148static const struct usb_action OV7620_mode0[] = { 3160static const struct usb_action ov7620_Initial[] = { /* 640x480 */
3149 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ 3161 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
3150 {0xa0, 0x40, ZC3XX_R002_CLOCKSELECT}, /* 00,02,40,cc */ 3162 {0xa0, 0x40, ZC3XX_R002_CLOCKSELECT}, /* 00,02,40,cc */
3151 {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ 3163 {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */
@@ -3214,9 +3226,7 @@ static const struct usb_action OV7620_mode0[] = {
3214 {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,50,cc */ 3226 {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,50,cc */
3215 {} 3227 {}
3216}; 3228};
3217 3229static const struct usb_action ov7620_InitialScale[] = { /* 320x240 */
3218/* from zs211.inf - HKR,%OV7620%,InitialScale - 320x240 */
3219static const struct usb_action OV7620_mode1[] = {
3220 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ 3230 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
3221 {0xa0, 0x50, ZC3XX_R002_CLOCKSELECT}, /* 00,02,50,cc */ 3231 {0xa0, 0x50, ZC3XX_R002_CLOCKSELECT}, /* 00,02,50,cc */
3222 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ 3232 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */
@@ -3287,9 +3297,7 @@ static const struct usb_action OV7620_mode1[] = {
3287 {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,50,cc */ 3297 {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,50,cc */
3288 {} 3298 {}
3289}; 3299};
3290 3300static const struct usb_action ov7620_50HZ[] = {
3291/* from zs211.inf - HKR,%OV7620%\AE,50HZ */
3292static const struct usb_action OV7620_50HZ[] = {
3293 {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */ 3301 {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */
3294 {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */ 3302 {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */
3295 {0xaa, 0x2b, 0x0096}, /* 00,2b,96,aa */ 3303 {0xaa, 0x2b, 0x0096}, /* 00,2b,96,aa */
@@ -3307,9 +3315,7 @@ static const struct usb_action OV7620_50HZ[] = {
3307 if mode0 (640x480) */ 3315 if mode0 (640x480) */
3308 {} 3316 {}
3309}; 3317};
3310 3318static const struct usb_action ov7620_60HZ[] = {
3311/* from zs211.inf - HKR,%OV7620%\AE,60HZ */
3312static const struct usb_action OV7620_60HZ[] = {
3313 {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */ 3319 {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */
3314 /* (bug in zs211.inf) */ 3320 /* (bug in zs211.inf) */
3315 {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */ 3321 {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */
@@ -3331,9 +3337,7 @@ static const struct usb_action OV7620_60HZ[] = {
3331 {0xa1, 0x01, 0x0037}, */ 3337 {0xa1, 0x01, 0x0037}, */
3332 {} 3338 {}
3333}; 3339};
3334 3340static const struct usb_action ov7620_NoFliker[] = {
3335/* from zs211.inf - HKR,%OV7620%\AE,NoFliker */
3336static const struct usb_action OV7620_NoFliker[] = {
3337 {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */ 3341 {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */
3338 /* (bug in zs211.inf) */ 3342 /* (bug in zs211.inf) */
3339 {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */ 3343 {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */
@@ -3354,7 +3358,7 @@ static const struct usb_action OV7620_NoFliker[] = {
3354 {} 3358 {}
3355}; 3359};
3356 3360
3357static const struct usb_action ov7630c_Initial[] = { 3361static const struct usb_action ov7630c_InitialScale[] = {
3358 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 3362 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
3359 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, 3363 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT},
3360 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 3364 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
@@ -3511,7 +3515,7 @@ static const struct usb_action ov7630c_Initial[] = {
3511 {} 3515 {}
3512}; 3516};
3513 3517
3514static const struct usb_action ov7630c_InitialScale[] = { 3518static const struct usb_action ov7630c_Initial[] = {
3515 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 3519 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
3516 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, 3520 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT},
3517 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 3521 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
@@ -3682,7 +3686,7 @@ static const struct usb_action pas106b_Initial_com[] = {
3682 {} 3686 {}
3683}; 3687};
3684 3688
3685static const struct usb_action pas106b_Initial[] = { /* 176x144 */ 3689static const struct usb_action pas106b_InitialScale[] = { /* 176x144 */
3686/* JPEG control */ 3690/* JPEG control */
3687 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 3691 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
3688/* Sream and Sensor specific */ 3692/* Sream and Sensor specific */
@@ -3800,7 +3804,7 @@ static const struct usb_action pas106b_Initial[] = { /* 176x144 */
3800 {} 3804 {}
3801}; 3805};
3802 3806
3803static const struct usb_action pas106b_InitialScale[] = { /* 352x288 */ 3807static const struct usb_action pas106b_Initial[] = { /* 352x288 */
3804/* JPEG control */ 3808/* JPEG control */
3805 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, 3809 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
3806/* Sream and Sensor specific */ 3810/* Sream and Sensor specific */
@@ -3972,10 +3976,10 @@ static const struct usb_action pas106b_NoFliker[] = {
3972 {} 3976 {}
3973}; 3977};
3974 3978
3975/* from usbvm31b.inf */ 3979/* from lvWIMv.inf 046d:08a2/:08aa 2007/06/03 */
3976static const struct usb_action pas202b_Initial[] = { /* 640x480 */ 3980static const struct usb_action pas202b_Initial[] = { /* 640x480 */
3977 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ 3981 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
3978 {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ 3982 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
3979 {0xa0, 0x0e, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0e,cc */ 3983 {0xa0, 0x0e, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0e,cc */
3980 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* 00,02,00,cc */ 3984 {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* 00,02,00,cc */
3981 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */ 3985 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */
@@ -4000,7 +4004,7 @@ static const struct usb_action pas202b_Initial[] = { /* 640x480 */
4000 {0xaa, 0x09, 0x0006}, /* 00,09,06,aa */ 4004 {0xaa, 0x09, 0x0006}, /* 00,09,06,aa */
4001 {0xaa, 0x0a, 0x0001}, /* 00,0a,01,aa */ 4005 {0xaa, 0x0a, 0x0001}, /* 00,0a,01,aa */
4002 {0xaa, 0x0b, 0x0001}, /* 00,0b,01,aa */ 4006 {0xaa, 0x0b, 0x0001}, /* 00,0b,01,aa */
4003 {0xaa, 0x0c, 0x0008}, /* 00,0c,08,aa */ 4007 {0xaa, 0x0c, 0x0006},
4004 {0xaa, 0x0d, 0x0000}, /* 00,0d,00,aa */ 4008 {0xaa, 0x0d, 0x0000}, /* 00,0d,00,aa */
4005 {0xaa, 0x10, 0x0000}, /* 00,10,00,aa */ 4009 {0xaa, 0x10, 0x0000}, /* 00,10,00,aa */
4006 {0xaa, 0x12, 0x0005}, /* 00,12,05,aa */ 4010 {0xaa, 0x12, 0x0005}, /* 00,12,05,aa */
@@ -4019,13 +4023,13 @@ static const struct usb_action pas202b_Initial[] = { /* 640x480 */
4019}; 4023};
4020static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */ 4024static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */
4021 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ 4025 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
4022 {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ 4026 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4023 {0xa0, 0x0e, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0e,cc */ 4027 {0xa0, 0x0e, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0e,cc */
4024 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */ 4028 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */
4025 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */ 4029 {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */
4026 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, /* 00,04,80,cc */ 4030 {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, /* 00,04,80,cc */
4027 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, /* 00,05,01,cc */ 4031 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, /* 00,05,01,cc */
4028 {0xa0, 0xd0, ZC3XX_R006_FRAMEHEIGHTLOW}, /* 00,06,d0,cc */ 4032 {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW},
4029 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* 00,01,01,cc */ 4033 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* 00,01,01,cc */
4030 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,03,cc */ 4034 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,03,cc */
4031 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,01,cc */ 4035 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,01,cc */
@@ -4035,7 +4039,7 @@ static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */
4035 {0xa0, 0x08, ZC3XX_R11A_FIRSTYLOW}, /* 01,1a,08,cc */ 4039 {0xa0, 0x08, ZC3XX_R11A_FIRSTYLOW}, /* 01,1a,08,cc */
4036 {0xa0, 0x02, ZC3XX_R11C_FIRSTXLOW}, /* 01,1c,02,cc */ 4040 {0xa0, 0x02, ZC3XX_R11C_FIRSTXLOW}, /* 01,1c,02,cc */
4037 {0xa0, 0x01, ZC3XX_R09B_WINHEIGHTHIGH}, /* 00,9b,01,cc */ 4041 {0xa0, 0x01, ZC3XX_R09B_WINHEIGHTHIGH}, /* 00,9b,01,cc */
4038 {0xa0, 0xd8, ZC3XX_R09C_WINHEIGHTLOW}, /* 00,9c,d8,cc */ 4042 {0xa0, 0xe8, ZC3XX_R09C_WINHEIGHTLOW},
4039 {0xa0, 0x02, ZC3XX_R09D_WINWIDTHHIGH}, /* 00,9d,02,cc */ 4043 {0xa0, 0x02, ZC3XX_R09D_WINWIDTHHIGH}, /* 00,9d,02,cc */
4040 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW}, /* 00,9e,88,cc */ 4044 {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW}, /* 00,9e,88,cc */
4041 {0xaa, 0x02, 0x0002}, /* 00,02,02,aa */ 4045 {0xaa, 0x02, 0x0002}, /* 00,02,02,aa */
@@ -4044,7 +4048,7 @@ static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */
4044 {0xaa, 0x09, 0x0006}, /* 00,09,06,aa */ 4048 {0xaa, 0x09, 0x0006}, /* 00,09,06,aa */
4045 {0xaa, 0x0a, 0x0001}, /* 00,0a,01,aa */ 4049 {0xaa, 0x0a, 0x0001}, /* 00,0a,01,aa */
4046 {0xaa, 0x0b, 0x0001}, /* 00,0b,01,aa */ 4050 {0xaa, 0x0b, 0x0001}, /* 00,0b,01,aa */
4047 {0xaa, 0x0c, 0x0008}, /* 00,0c,08,aa */ 4051 {0xaa, 0x0c, 0x0006},
4048 {0xaa, 0x0d, 0x0000}, /* 00,0d,00,aa */ 4052 {0xaa, 0x0d, 0x0000}, /* 00,0d,00,aa */
4049 {0xaa, 0x10, 0x0000}, /* 00,10,00,aa */ 4053 {0xaa, 0x10, 0x0000}, /* 00,10,00,aa */
4050 {0xaa, 0x12, 0x0005}, /* 00,12,05,aa */ 4054 {0xaa, 0x12, 0x0005}, /* 00,12,05,aa */
@@ -4059,6 +4063,8 @@ static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */
4059 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* 02,50,08,cc */ 4063 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* 02,50,08,cc */
4060 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* 03,01,08,cc */ 4064 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* 03,01,08,cc */
4061 {0xa0, 0x70, ZC3XX_R18D_YTARGET}, /* 01,8d,70,cc */ 4065 {0xa0, 0x70, ZC3XX_R18D_YTARGET}, /* 01,8d,70,cc */
4066 {0xa0, 0xff, ZC3XX_R097_WINYSTARTHIGH},
4067 {0xa0, 0xfe, ZC3XX_R098_WINYSTARTLOW},
4062 {} 4068 {}
4063}; 4069};
4064static const struct usb_action pas202b_50HZ[] = { 4070static const struct usb_action pas202b_50HZ[] = {
@@ -4066,22 +4072,22 @@ static const struct usb_action pas202b_50HZ[] = {
4066 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ 4072 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */
4067 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ 4073 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */
4068 {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ 4074 {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */
4069 {0xaa, 0x21, 0x0068}, /* 00,21,68,aa */ 4075 {0xaa, 0x21, 0x001b},
4070 {0xaa, 0x03, 0x0044}, /* 00,03,44,aa */ 4076 {0xaa, 0x03, 0x0044}, /* 00,03,44,aa */
4071 {0xaa, 0x04, 0x0009}, /* 00,04,09,aa */ 4077 {0xaa, 0x04, 0x0008},
4072 {0xaa, 0x05, 0x0028}, /* 00,05,28,aa */ 4078 {0xaa, 0x05, 0x001b},
4073 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ 4079 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */
4074 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ 4080 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */
4075 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,14,cc */ 4081 {0xa0, 0x1c, ZC3XX_R1A9_DIGITALLIMITDIFF},
4076 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */ 4082 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */
4077 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 4083 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
4078 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,07,cc */ 4084 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID},
4079 {0xa0, 0xd2, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,d2,cc */ 4085 {0xa0, 0x1b, ZC3XX_R192_EXPOSURELIMITLOW},
4080 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ 4086 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */
4081 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ 4087 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */
4082 {0xa0, 0x4d, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,4d,cc */ 4088 {0xa0, 0x4d, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,4d,cc */
4083 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ 4089 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4084 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ 4090 {0xa0, 0x1b, ZC3XX_R18F_AEUNFREEZE},
4085 {0xa0, 0x44, ZC3XX_R01D_HSYNC_0}, /* 00,1d,44,cc */ 4091 {0xa0, 0x44, ZC3XX_R01D_HSYNC_0}, /* 00,1d,44,cc */
4086 {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */ 4092 {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */
4087 {0xa0, 0xad, ZC3XX_R01F_HSYNC_2}, /* 00,1f,ad,cc */ 4093 {0xa0, 0xad, ZC3XX_R01F_HSYNC_2}, /* 00,1f,ad,cc */
@@ -4094,23 +4100,23 @@ static const struct usb_action pas202b_50HZScale[] = {
4094 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 4100 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
4095 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ 4101 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */
4096 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ 4102 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */
4097 {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ 4103 {0xaa, 0x20, 0x0004},
4098 {0xaa, 0x21, 0x006c}, /* 00,21,6c,aa */ 4104 {0xaa, 0x21, 0x003d},
4099 {0xaa, 0x03, 0x0041}, /* 00,03,41,aa */ 4105 {0xaa, 0x03, 0x0041}, /* 00,03,41,aa */
4100 {0xaa, 0x04, 0x0009}, /* 00,04,09,aa */ 4106 {0xaa, 0x04, 0x0010},
4101 {0xaa, 0x05, 0x002c}, /* 00,05,2c,aa */ 4107 {0xaa, 0x05, 0x003d},
4102 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ 4108 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */
4103 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ 4109 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */
4104 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,14,cc */ 4110 {0xa0, 0x1c, ZC3XX_R1A9_DIGITALLIMITDIFF},
4105 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */ 4111 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */
4106 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 4112 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
4107 {0xa0, 0x0f, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,0f,cc */ 4113 {0xa0, 0x04, ZC3XX_R191_EXPOSURELIMITMID},
4108 {0xa0, 0xbe, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,be,cc */ 4114 {0xa0, 0x3d, ZC3XX_R192_EXPOSURELIMITLOW},
4109 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ 4115 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */
4110 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ 4116 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */
4111 {0xa0, 0x9b, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,9b,cc */ 4117 {0xa0, 0x9b, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,9b,cc */
4112 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ 4118 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4113 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ 4119 {0xa0, 0x1b, ZC3XX_R18F_AEUNFREEZE},
4114 {0xa0, 0x41, ZC3XX_R01D_HSYNC_0}, /* 00,1d,41,cc */ 4120 {0xa0, 0x41, ZC3XX_R01D_HSYNC_0}, /* 00,1d,41,cc */
4115 {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */ 4121 {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */
4116 {0xa0, 0xad, ZC3XX_R01F_HSYNC_2}, /* 00,1f,ad,cc */ 4122 {0xa0, 0xad, ZC3XX_R01F_HSYNC_2}, /* 00,1f,ad,cc */
@@ -4130,16 +4136,16 @@ static const struct usb_action pas202b_60HZ[] = {
4130 {0xaa, 0x05, 0x0000}, /* 00,05,00,aa */ 4136 {0xaa, 0x05, 0x0000}, /* 00,05,00,aa */
4131 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ 4137 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */
4132 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ 4138 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */
4133 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,14,cc */ 4139 {0xa0, 0x1c, ZC3XX_R1A9_DIGITALLIMITDIFF},
4134 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */ 4140 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */
4135 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 4141 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
4136 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,07,cc */ 4142 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID},
4137 {0xa0, 0xc0, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,c0,cc */ 4143 {0xa0, 0x00, ZC3XX_R192_EXPOSURELIMITLOW},
4138 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ 4144 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */
4139 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ 4145 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */
4140 {0xa0, 0x40, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,40,cc */ 4146 {0xa0, 0x40, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,40,cc */
4141 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ 4147 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4142 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ 4148 {0xa0, 0x1b, ZC3XX_R18F_AEUNFREEZE},
4143 {0xa0, 0x45, ZC3XX_R01D_HSYNC_0}, /* 00,1d,45,cc */ 4149 {0xa0, 0x45, ZC3XX_R01D_HSYNC_0}, /* 00,1d,45,cc */
4144 {0xa0, 0x8e, ZC3XX_R01E_HSYNC_1}, /* 00,1e,8e,cc */ 4150 {0xa0, 0x8e, ZC3XX_R01E_HSYNC_1}, /* 00,1e,8e,cc */
4145 {0xa0, 0xc1, ZC3XX_R01F_HSYNC_2}, /* 00,1f,c1,cc */ 4151 {0xa0, 0xc1, ZC3XX_R01F_HSYNC_2}, /* 00,1f,c1,cc */
@@ -4152,23 +4158,23 @@ static const struct usb_action pas202b_60HZScale[] = {
4152 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 4158 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
4153 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ 4159 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */
4154 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ 4160 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */
4155 {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ 4161 {0xaa, 0x20, 0x0004},
4156 {0xaa, 0x21, 0x0004}, /* 00,21,04,aa */ 4162 {0xaa, 0x21, 0x0008},
4157 {0xaa, 0x03, 0x0042}, /* 00,03,42,aa */ 4163 {0xaa, 0x03, 0x0042}, /* 00,03,42,aa */
4158 {0xaa, 0x04, 0x0008}, /* 00,04,08,aa */ 4164 {0xaa, 0x04, 0x0010},
4159 {0xaa, 0x05, 0x0004}, /* 00,05,04,aa */ 4165 {0xaa, 0x05, 0x0008},
4160 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ 4166 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */
4161 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ 4167 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */
4162 {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,14,cc */ 4168 {0xa0, 0x1c, ZC3XX_R1A9_DIGITALLIMITDIFF},
4163 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */ 4169 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */
4164 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 4170 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
4165 {0xa0, 0x0f, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,0f,cc */ 4171 {0xa0, 0x04, ZC3XX_R191_EXPOSURELIMITMID},
4166 {0xa0, 0x9f, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,9f,cc */ 4172 {0xa0, 0x08, ZC3XX_R192_EXPOSURELIMITLOW},
4167 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ 4173 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */
4168 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ 4174 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */
4169 {0xa0, 0x81, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,81,cc */ 4175 {0xa0, 0x81, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,81,cc */
4170 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ 4176 {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE},
4171 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ 4177 {0xa0, 0x1b, ZC3XX_R18F_AEUNFREEZE},
4172 {0xa0, 0x42, ZC3XX_R01D_HSYNC_0}, /* 00,1d,42,cc */ 4178 {0xa0, 0x42, ZC3XX_R01D_HSYNC_0}, /* 00,1d,42,cc */
4173 {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */ 4179 {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */
4174 {0xa0, 0xaf, ZC3XX_R01F_HSYNC_2}, /* 00,1f,af,cc */ 4180 {0xa0, 0xaf, ZC3XX_R01F_HSYNC_2}, /* 00,1f,af,cc */
@@ -4182,22 +4188,22 @@ static const struct usb_action pas202b_NoFliker[] = {
4182 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ 4188 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */
4183 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ 4189 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */
4184 {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ 4190 {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */
4185 {0xaa, 0x21, 0x0020}, /* 00,21,20,aa */ 4191 {0xaa, 0x21, 0x0006},
4186 {0xaa, 0x03, 0x0040}, /* 00,03,40,aa */ 4192 {0xaa, 0x03, 0x0040}, /* 00,03,40,aa */
4187 {0xaa, 0x04, 0x0008}, /* 00,04,08,aa */ 4193 {0xaa, 0x04, 0x0008}, /* 00,04,08,aa */
4188 {0xaa, 0x05, 0x0020}, /* 00,05,20,aa */ 4194 {0xaa, 0x05, 0x0006},
4189 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ 4195 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */
4190 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ 4196 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */
4191 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 4197 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
4192 {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,07,cc */ 4198 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID},
4193 {0xa0, 0xf0, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,f0,cc */ 4199 {0xa0, 0x06, ZC3XX_R192_EXPOSURELIMITLOW},
4194 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ 4200 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */
4195 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ 4201 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */
4196 {0xa0, 0x02, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,02,cc */ 4202 {0xa0, 0x01, ZC3XX_R197_ANTIFLICKERLOW},
4197 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ 4203 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */
4198 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ 4204 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */
4199 {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,00,cc */ 4205 {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,00,cc */
4200 {0xa0, 0x00, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,00,cc */ 4206 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP},
4201 {0xa0, 0x40, ZC3XX_R01D_HSYNC_0}, /* 00,1d,40,cc */ 4207 {0xa0, 0x40, ZC3XX_R01D_HSYNC_0}, /* 00,1d,40,cc */
4202 {0xa0, 0x60, ZC3XX_R01E_HSYNC_1}, /* 00,1e,60,cc */ 4208 {0xa0, 0x60, ZC3XX_R01E_HSYNC_1}, /* 00,1e,60,cc */
4203 {0xa0, 0x90, ZC3XX_R01F_HSYNC_2}, /* 00,1f,90,cc */ 4209 {0xa0, 0x90, ZC3XX_R01F_HSYNC_2}, /* 00,1f,90,cc */
@@ -4210,23 +4216,23 @@ static const struct usb_action pas202b_NoFlikerScale[] = {
4210 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 4216 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
4211 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ 4217 {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */
4212 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ 4218 {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */
4213 {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ 4219 {0xaa, 0x20, 0x0004},
4214 {0xaa, 0x21, 0x0010}, /* 00,21,10,aa */ 4220 {0xaa, 0x21, 0x000c},
4215 {0xaa, 0x03, 0x0040}, /* 00,03,40,aa */ 4221 {0xaa, 0x03, 0x0040}, /* 00,03,40,aa */
4216 {0xaa, 0x04, 0x0008}, /* 00,04,08,aa */ 4222 {0xaa, 0x04, 0x0010},
4217 {0xaa, 0x05, 0x0010}, /* 00,05,10,aa */ 4223 {0xaa, 0x05, 0x000c},
4218 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ 4224 {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */
4219 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ 4225 {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */
4220 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 4226 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
4221 {0xa0, 0x0f, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,0f,cc */ 4227 {0xa0, 0x04, ZC3XX_R191_EXPOSURELIMITMID},
4222 {0xa0, 0xf0, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,f0,cc */ 4228 {0xa0, 0x0c, ZC3XX_R192_EXPOSURELIMITLOW},
4223 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ 4229 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */
4224 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ 4230 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */
4225 {0xa0, 0x02, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,02,cc */ 4231 {0xa0, 0x02, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,02,cc */
4226 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ 4232 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */
4227 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ 4233 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */
4228 {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,00,cc */ 4234 {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,00,cc */
4229 {0xa0, 0x00, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,00,cc */ 4235 {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP},
4230 {0xa0, 0x40, ZC3XX_R01D_HSYNC_0}, /* 00,1d,40,cc */ 4236 {0xa0, 0x40, ZC3XX_R01D_HSYNC_0}, /* 00,1d,40,cc */
4231 {0xa0, 0x60, ZC3XX_R01E_HSYNC_1}, /* 00,1e,60,cc */ 4237 {0xa0, 0x60, ZC3XX_R01E_HSYNC_1}, /* 00,1e,60,cc */
4232 {0xa0, 0x90, ZC3XX_R01F_HSYNC_2}, /* 00,1f,90,cc */ 4238 {0xa0, 0x90, ZC3XX_R01F_HSYNC_2}, /* 00,1f,90,cc */
@@ -4713,8 +4719,8 @@ static const struct usb_action pb0330_NoFlikerScale[] = {
4713 {} 4719 {}
4714}; 4720};
4715 4721
4716/* from oem9.inf - HKR,%PO2030%,Initial - 640x480 - (close to CS2102) */ 4722/* from oem9.inf */
4717static const struct usb_action PO2030_mode0[] = { 4723static const struct usb_action po2030_Initial[] = { /* 640x480 */
4718 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ 4724 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
4719 {0xa0, 0x04, ZC3XX_R002_CLOCKSELECT}, /* 00,02,04,cc */ 4725 {0xa0, 0x04, ZC3XX_R002_CLOCKSELECT}, /* 00,02,04,cc */
4720 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ 4726 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
@@ -4790,8 +4796,8 @@ static const struct usb_action PO2030_mode0[] = {
4790 {} 4796 {}
4791}; 4797};
4792 4798
4793/* from oem9.inf - HKR,%PO2030%,InitialScale - 320x240 */ 4799/* from oem9.inf */
4794static const struct usb_action PO2030_mode1[] = { 4800static const struct usb_action po2030_InitialScale[] = { /* 320x240 */
4795 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ 4801 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */
4796 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */ 4802 {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */
4797 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ 4803 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */
@@ -4867,7 +4873,7 @@ static const struct usb_action PO2030_mode1[] = {
4867 {} 4873 {}
4868}; 4874};
4869 4875
4870static const struct usb_action PO2030_50HZ[] = { 4876static const struct usb_action po2030_50HZ[] = {
4871 {0xaa, 0x8d, 0x0008}, /* 00,8d,08,aa */ 4877 {0xaa, 0x8d, 0x0008}, /* 00,8d,08,aa */
4872 {0xaa, 0x1a, 0x0001}, /* 00,1a,01,aa */ 4878 {0xaa, 0x1a, 0x0001}, /* 00,1a,01,aa */
4873 {0xaa, 0x1b, 0x000a}, /* 00,1b,0a,aa */ 4879 {0xaa, 0x1b, 0x000a}, /* 00,1b,0a,aa */
@@ -4889,7 +4895,7 @@ static const struct usb_action PO2030_50HZ[] = {
4889 {} 4895 {}
4890}; 4896};
4891 4897
4892static const struct usb_action PO2030_60HZ[] = { 4898static const struct usb_action po2030_60HZ[] = {
4893 {0xaa, 0x8d, 0x0008}, /* 00,8d,08,aa */ 4899 {0xaa, 0x8d, 0x0008}, /* 00,8d,08,aa */
4894 {0xaa, 0x1a, 0x0000}, /* 00,1a,00,aa */ 4900 {0xaa, 0x1a, 0x0000}, /* 00,1a,00,aa */
4895 {0xaa, 0x1b, 0x00de}, /* 00,1b,de,aa */ 4901 {0xaa, 0x1b, 0x00de}, /* 00,1b,de,aa */
@@ -4912,7 +4918,7 @@ static const struct usb_action PO2030_60HZ[] = {
4912 {} 4918 {}
4913}; 4919};
4914 4920
4915static const struct usb_action PO2030_NoFliker[] = { 4921static const struct usb_action po2030_NoFliker[] = {
4916 {0xa0, 0x02, ZC3XX_R180_AUTOCORRECTENABLE}, /* 01,80,02,cc */ 4922 {0xa0, 0x02, ZC3XX_R180_AUTOCORRECTENABLE}, /* 01,80,02,cc */
4917 {0xaa, 0x8d, 0x000d}, /* 00,8d,0d,aa */ 4923 {0xaa, 0x8d, 0x000d}, /* 00,8d,0d,aa */
4918 {0xaa, 0x1a, 0x0000}, /* 00,1a,00,aa */ 4924 {0xaa, 0x1a, 0x0000}, /* 00,1a,00,aa */
@@ -4924,7 +4930,7 @@ static const struct usb_action PO2030_NoFliker[] = {
4924}; 4930};
4925 4931
4926/* TEST */ 4932/* TEST */
4927static const struct usb_action tas5130CK_Initial[] = { 4933static const struct usb_action tas5130cK_InitialScale[] = {
4928 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 4934 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
4929 {0xa0, 0x01, 0x003b}, 4935 {0xa0, 0x01, 0x003b},
4930 {0xa0, 0x0e, 0x003a}, 4936 {0xa0, 0x0e, 0x003a},
@@ -5127,7 +5133,7 @@ static const struct usb_action tas5130CK_Initial[] = {
5127 {} 5133 {}
5128}; 5134};
5129 5135
5130static const struct usb_action tas5130CK_InitialScale[] = { 5136static const struct usb_action tas5130cK_Initial[] = {
5131 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, 5137 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL},
5132 {0xa0, 0x01, 0x003b}, 5138 {0xa0, 0x01, 0x003b},
5133 {0xa0, 0x0e, 0x003a}, 5139 {0xa0, 0x0e, 0x003a},
@@ -5560,7 +5566,7 @@ static const struct usb_action tas5130cxx_NoFlikerScale[] = {
5560 {} 5566 {}
5561}; 5567};
5562 5568
5563static const struct usb_action tas5130c_vf0250_Initial[] = { 5569static const struct usb_action tas5130c_vf0250_InitialScale[] = {
5564 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */ 5570 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */
5565 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */ 5571 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */
5566 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */ 5572 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */
@@ -5627,7 +5633,7 @@ static const struct usb_action tas5130c_vf0250_Initial[] = {
5627 {} 5633 {}
5628}; 5634};
5629 5635
5630static const struct usb_action tas5130c_vf0250_InitialScale[] = { 5636static const struct usb_action tas5130c_vf0250_Initial[] = {
5631 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */ 5637 {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */
5632 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */ 5638 {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */
5633 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */ 5639 {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */
@@ -5692,8 +5698,7 @@ static const struct usb_action tas5130c_vf0250_InitialScale[] = {
5692 {0xa0, 0x65, ZC3XX_R118_BGAIN}, /* 01,18,65,cc */ 5698 {0xa0, 0x65, ZC3XX_R118_BGAIN}, /* 01,18,65,cc */
5693 {} 5699 {}
5694}; 5700};
5695/* "50HZ" light frequency banding filter */ 5701static const struct usb_action tas5130c_vf0250_50HZScale[] = {
5696static const struct usb_action tas5130c_vf0250_50HZ[] = {
5697 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5702 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5698 {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */ 5703 {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */
5699 {0xaa, 0x84, 0x00aa}, /* 00,84,aa,aa */ 5704 {0xaa, 0x84, 0x00aa}, /* 00,84,aa,aa */
@@ -5717,8 +5722,7 @@ static const struct usb_action tas5130c_vf0250_50HZ[] = {
5717 {} 5722 {}
5718}; 5723};
5719 5724
5720/* "50HZScale" light frequency banding filter */ 5725static const struct usb_action tas5130c_vf0250_50HZ[] = {
5721static const struct usb_action tas5130c_vf0250_50HZScale[] = {
5722 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5726 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5723 {0xaa, 0x83, 0x0003}, /* 00,83,03,aa */ 5727 {0xaa, 0x83, 0x0003}, /* 00,83,03,aa */
5724 {0xaa, 0x84, 0x0054}, /* 00,84,54,aa */ 5728 {0xaa, 0x84, 0x0054}, /* 00,84,54,aa */
@@ -5742,8 +5746,7 @@ static const struct usb_action tas5130c_vf0250_50HZScale[] = {
5742 {} 5746 {}
5743}; 5747};
5744 5748
5745/* "60HZ" light frequency banding filter */ 5749static const struct usb_action tas5130c_vf0250_60HZScale[] = {
5746static const struct usb_action tas5130c_vf0250_60HZ[] = {
5747 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5750 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5748 {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */ 5751 {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */
5749 {0xaa, 0x84, 0x0062}, /* 00,84,62,aa */ 5752 {0xaa, 0x84, 0x0062}, /* 00,84,62,aa */
@@ -5767,8 +5770,7 @@ static const struct usb_action tas5130c_vf0250_60HZ[] = {
5767 {} 5770 {}
5768}; 5771};
5769 5772
5770/* "60HZScale" light frequency banding ilter */ 5773static const struct usb_action tas5130c_vf0250_60HZ[] = {
5771static const struct usb_action tas5130c_vf0250_60HZScale[] = {
5772 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5774 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5773 {0xaa, 0x83, 0x0002}, /* 00,83,02,aa */ 5775 {0xaa, 0x83, 0x0002}, /* 00,83,02,aa */
5774 {0xaa, 0x84, 0x00c4}, /* 00,84,c4,aa */ 5776 {0xaa, 0x84, 0x00c4}, /* 00,84,c4,aa */
@@ -5792,8 +5794,7 @@ static const struct usb_action tas5130c_vf0250_60HZScale[] = {
5792 {} 5794 {}
5793}; 5795};
5794 5796
5795/* "NoFliker" light frequency banding flter */ 5797static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = {
5796static const struct usb_action tas5130c_vf0250_NoFliker[] = {
5797 {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */ 5798 {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */
5798 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5799 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5799 {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */ 5800 {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */
@@ -5815,8 +5816,7 @@ static const struct usb_action tas5130c_vf0250_NoFliker[] = {
5815 {} 5816 {}
5816}; 5817};
5817 5818
5818/* "NoFlikerScale" light frequency banding filter */ 5819static const struct usb_action tas5130c_vf0250_NoFliker[] = {
5819static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = {
5820 {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */ 5820 {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */
5821 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ 5821 {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */
5822 {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */ 5822 {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */
@@ -5839,7 +5839,7 @@ static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = {
5839}; 5839};
5840 5840
5841static u8 reg_r_i(struct gspca_dev *gspca_dev, 5841static u8 reg_r_i(struct gspca_dev *gspca_dev,
5842 __u16 index) 5842 u16 index)
5843{ 5843{
5844 usb_control_msg(gspca_dev->dev, 5844 usb_control_msg(gspca_dev->dev,
5845 usb_rcvctrlpipe(gspca_dev->dev, 0), 5845 usb_rcvctrlpipe(gspca_dev->dev, 0),
@@ -5852,7 +5852,7 @@ static u8 reg_r_i(struct gspca_dev *gspca_dev,
5852} 5852}
5853 5853
5854static u8 reg_r(struct gspca_dev *gspca_dev, 5854static u8 reg_r(struct gspca_dev *gspca_dev,
5855 __u16 index) 5855 u16 index)
5856{ 5856{
5857 u8 ret; 5857 u8 ret;
5858 5858
@@ -5862,8 +5862,8 @@ static u8 reg_r(struct gspca_dev *gspca_dev,
5862} 5862}
5863 5863
5864static void reg_w_i(struct usb_device *dev, 5864static void reg_w_i(struct usb_device *dev,
5865 __u8 value, 5865 u8 value,
5866 __u16 index) 5866 u16 index)
5867{ 5867{
5868 usb_control_msg(dev, 5868 usb_control_msg(dev,
5869 usb_sndctrlpipe(dev, 0), 5869 usb_sndctrlpipe(dev, 0),
@@ -5874,18 +5874,18 @@ static void reg_w_i(struct usb_device *dev,
5874} 5874}
5875 5875
5876static void reg_w(struct usb_device *dev, 5876static void reg_w(struct usb_device *dev,
5877 __u8 value, 5877 u8 value,
5878 __u16 index) 5878 u16 index)
5879{ 5879{
5880 PDEBUG(D_USBO, "reg w [%04x] = %02x", index, value); 5880 PDEBUG(D_USBO, "reg w [%04x] = %02x", index, value);
5881 reg_w_i(dev, value, index); 5881 reg_w_i(dev, value, index);
5882} 5882}
5883 5883
5884static __u16 i2c_read(struct gspca_dev *gspca_dev, 5884static u16 i2c_read(struct gspca_dev *gspca_dev,
5885 __u8 reg) 5885 u8 reg)
5886{ 5886{
5887 __u8 retbyte; 5887 u8 retbyte;
5888 __u16 retval; 5888 u16 retval;
5889 5889
5890 reg_w_i(gspca_dev->dev, reg, 0x0092); 5890 reg_w_i(gspca_dev->dev, reg, 0x0092);
5891 reg_w_i(gspca_dev->dev, 0x02, 0x0090); /* <- read command */ 5891 reg_w_i(gspca_dev->dev, 0x02, 0x0090); /* <- read command */
@@ -5900,12 +5900,12 @@ static __u16 i2c_read(struct gspca_dev *gspca_dev,
5900 return retval; 5900 return retval;
5901} 5901}
5902 5902
5903static __u8 i2c_write(struct gspca_dev *gspca_dev, 5903static u8 i2c_write(struct gspca_dev *gspca_dev,
5904 __u8 reg, 5904 u8 reg,
5905 __u8 valL, 5905 u8 valL,
5906 __u8 valH) 5906 u8 valH)
5907{ 5907{
5908 __u8 retbyte; 5908 u8 retbyte;
5909 5909
5910 reg_w_i(gspca_dev->dev, reg, 0x92); 5910 reg_w_i(gspca_dev->dev, reg, 0x92);
5911 reg_w_i(gspca_dev->dev, valL, 0x93); 5911 reg_w_i(gspca_dev->dev, valL, 0x93);
@@ -5957,24 +5957,24 @@ static void setmatrix(struct gspca_dev *gspca_dev)
5957{ 5957{
5958 struct sd *sd = (struct sd *) gspca_dev; 5958 struct sd *sd = (struct sd *) gspca_dev;
5959 int i; 5959 int i;
5960 const __u8 *matrix; 5960 const u8 *matrix;
5961 static const u8 adcm2700_matrix[9] = 5961 static const u8 adcm2700_matrix[9] =
5962/* {0x66, 0xed, 0xed, 0xed, 0x66, 0xed, 0xed, 0xed, 0x66}; */ 5962/* {0x66, 0xed, 0xed, 0xed, 0x66, 0xed, 0xed, 0xed, 0x66}; */
5963/*ms-win*/ 5963/*ms-win*/
5964 {0x74, 0xed, 0xed, 0xed, 0x74, 0xed, 0xed, 0xed, 0x74}; 5964 {0x74, 0xed, 0xed, 0xed, 0x74, 0xed, 0xed, 0xed, 0x74};
5965 static const __u8 gc0305_matrix[9] = 5965 static const u8 gc0305_matrix[9] =
5966 {0x50, 0xf8, 0xf8, 0xf8, 0x50, 0xf8, 0xf8, 0xf8, 0x50}; 5966 {0x50, 0xf8, 0xf8, 0xf8, 0x50, 0xf8, 0xf8, 0xf8, 0x50};
5967 static const __u8 ov7620_matrix[9] = 5967 static const u8 ov7620_matrix[9] =
5968 {0x58, 0xf4, 0xf4, 0xf4, 0x58, 0xf4, 0xf4, 0xf4, 0x58}; 5968 {0x58, 0xf4, 0xf4, 0xf4, 0x58, 0xf4, 0xf4, 0xf4, 0x58};
5969 static const __u8 pas202b_matrix[9] = 5969 static const u8 pas202b_matrix[9] =
5970 {0x4c, 0xf5, 0xff, 0xf9, 0x51, 0xf5, 0xfb, 0xed, 0x5f}; 5970 {0x4c, 0xf5, 0xff, 0xf9, 0x51, 0xf5, 0xfb, 0xed, 0x5f};
5971 static const __u8 po2030_matrix[9] = 5971 static const u8 po2030_matrix[9] =
5972 {0x60, 0xf0, 0xf0, 0xf0, 0x60, 0xf0, 0xf0, 0xf0, 0x60}; 5972 {0x60, 0xf0, 0xf0, 0xf0, 0x60, 0xf0, 0xf0, 0xf0, 0x60};
5973 static const u8 tas5130c_matrix[9] = 5973 static const u8 tas5130c_matrix[9] =
5974 {0x68, 0xec, 0xec, 0xec, 0x68, 0xec, 0xec, 0xec, 0x68}; 5974 {0x68, 0xec, 0xec, 0xec, 0x68, 0xec, 0xec, 0xec, 0x68};
5975 static const __u8 vf0250_matrix[9] = 5975 static const u8 vf0250_matrix[9] =
5976 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b}; 5976 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b};
5977 static const __u8 *matrix_tb[SENSOR_MAX] = { 5977 static const u8 *matrix_tb[SENSOR_MAX] = {
5978 adcm2700_matrix, /* SENSOR_ADCM2700 0 */ 5978 adcm2700_matrix, /* SENSOR_ADCM2700 0 */
5979 ov7620_matrix, /* SENSOR_CS2102 1 */ 5979 ov7620_matrix, /* SENSOR_CS2102 1 */
5980 NULL, /* SENSOR_CS2102K 2 */ 5980 NULL, /* SENSOR_CS2102K 2 */
@@ -6006,11 +6006,12 @@ static void setmatrix(struct gspca_dev *gspca_dev)
6006static void setbrightness(struct gspca_dev *gspca_dev) 6006static void setbrightness(struct gspca_dev *gspca_dev)
6007{ 6007{
6008 struct sd *sd = (struct sd *) gspca_dev; 6008 struct sd *sd = (struct sd *) gspca_dev;
6009 __u8 brightness; 6009 u8 brightness;
6010 6010
6011 switch (sd->sensor) { 6011 switch (sd->sensor) {
6012 case SENSOR_GC0305: 6012 case SENSOR_GC0305:
6013 case SENSOR_OV7620: 6013 case SENSOR_OV7620:
6014 case SENSOR_PAS202B:
6014 case SENSOR_PO2030: 6015 case SENSOR_PO2030:
6015 return; 6016 return;
6016 } 6017 }
@@ -6034,7 +6035,7 @@ static void setsharpness(struct gspca_dev *gspca_dev)
6034 struct sd *sd = (struct sd *) gspca_dev; 6035 struct sd *sd = (struct sd *) gspca_dev;
6035 struct usb_device *dev = gspca_dev->dev; 6036 struct usb_device *dev = gspca_dev->dev;
6036 int sharpness; 6037 int sharpness;
6037 static const __u8 sharpness_tb[][2] = { 6038 static const u8 sharpness_tb[][2] = {
6038 {0x02, 0x03}, 6039 {0x02, 0x03},
6039 {0x04, 0x07}, 6040 {0x04, 0x07},
6040 {0x08, 0x0f}, 6041 {0x08, 0x0f},
@@ -6053,118 +6054,69 @@ static void setcontrast(struct gspca_dev *gspca_dev)
6053{ 6054{
6054 struct sd *sd = (struct sd *) gspca_dev; 6055 struct sd *sd = (struct sd *) gspca_dev;
6055 struct usb_device *dev = gspca_dev->dev; 6056 struct usb_device *dev = gspca_dev->dev;
6056 const __u8 *Tgamma, *Tgradient; 6057 const u8 *Tgamma;
6057 int g, i, k; 6058 int g, i, k, adj, gp;
6058 static const __u8 kgamma_tb[16] = /* delta for contrast */ 6059 u8 gr[16];
6060 static const u8 delta_tb[16] = /* delta for contrast */
6059 {0x15, 0x0d, 0x0a, 0x09, 0x08, 0x08, 0x08, 0x08, 6061 {0x15, 0x0d, 0x0a, 0x09, 0x08, 0x08, 0x08, 0x08,
6060 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08}; 6062 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08};
6061 static const __u8 kgrad_tb[16] = 6063 static const u8 gamma_tb[6][16] = {
6062 {0x1b, 0x06, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00,
6063 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x04};
6064 static const __u8 Tgamma_1[16] =
6065 {0x00, 0x00, 0x03, 0x0d, 0x1b, 0x2e, 0x45, 0x5f, 6064 {0x00, 0x00, 0x03, 0x0d, 0x1b, 0x2e, 0x45, 0x5f,
6066 0x79, 0x93, 0xab, 0xc1, 0xd4, 0xe5, 0xf3, 0xff}; 6065 0x79, 0x93, 0xab, 0xc1, 0xd4, 0xe5, 0xf3, 0xff},
6067 static const __u8 Tgradient_1[16] =
6068 {0x00, 0x01, 0x05, 0x0b, 0x10, 0x15, 0x18, 0x1a,
6069 0x1a, 0x18, 0x16, 0x14, 0x12, 0x0f, 0x0d, 0x06};
6070 static const __u8 Tgamma_2[16] =
6071 {0x01, 0x0c, 0x1f, 0x3a, 0x53, 0x6d, 0x85, 0x9c, 6066 {0x01, 0x0c, 0x1f, 0x3a, 0x53, 0x6d, 0x85, 0x9c,
6072 0xb0, 0xc2, 0xd1, 0xde, 0xe9, 0xf2, 0xf9, 0xff}; 6067 0xb0, 0xc2, 0xd1, 0xde, 0xe9, 0xf2, 0xf9, 0xff},
6073 static const __u8 Tgradient_2[16] =
6074 {0x05, 0x0f, 0x16, 0x1a, 0x19, 0x19, 0x17, 0x15,
6075 0x12, 0x10, 0x0e, 0x0b, 0x09, 0x08, 0x06, 0x03};
6076 static const __u8 Tgamma_3[16] =
6077 {0x04, 0x16, 0x30, 0x4e, 0x68, 0x81, 0x98, 0xac, 6068 {0x04, 0x16, 0x30, 0x4e, 0x68, 0x81, 0x98, 0xac,
6078 0xbe, 0xcd, 0xda, 0xe4, 0xed, 0xf5, 0xfb, 0xff}; 6069 0xbe, 0xcd, 0xda, 0xe4, 0xed, 0xf5, 0xfb, 0xff},
6079 static const __u8 Tgradient_3[16] =
6080 {0x0c, 0x16, 0x1b, 0x1c, 0x19, 0x18, 0x15, 0x12,
6081 0x10, 0x0d, 0x0b, 0x09, 0x08, 0x06, 0x05, 0x03};
6082 static const __u8 Tgamma_4[16] =
6083 {0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, 6070 {0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8,
6084 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff}; 6071 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff},
6085 static const __u8 Tgradient_4[16] =
6086 {0x26, 0x22, 0x20, 0x1c, 0x16, 0x13, 0x10, 0x0d,
6087 0x0b, 0x09, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02};
6088 static const __u8 Tgamma_5[16] =
6089 {0x20, 0x4b, 0x6e, 0x8d, 0xa3, 0xb5, 0xc5, 0xd2, 6072 {0x20, 0x4b, 0x6e, 0x8d, 0xa3, 0xb5, 0xc5, 0xd2,
6090 0xdc, 0xe5, 0xec, 0xf2, 0xf6, 0xfa, 0xfd, 0xff}; 6073 0xdc, 0xe5, 0xec, 0xf2, 0xf6, 0xfa, 0xfd, 0xff},
6091 static const __u8 Tgradient_5[16] =
6092 {0x37, 0x26, 0x20, 0x1a, 0x14, 0x10, 0x0e, 0x0b,
6093 0x09, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x02};
6094 static const __u8 Tgamma_6[16] = /* ?? was gamma 5 */
6095 {0x24, 0x44, 0x64, 0x84, 0x9d, 0xb2, 0xc4, 0xd3, 6074 {0x24, 0x44, 0x64, 0x84, 0x9d, 0xb2, 0xc4, 0xd3,
6096 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}; 6075 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff},
6097 static const __u8 Tgradient_6[16] =
6098 {0x18, 0x20, 0x20, 0x1c, 0x16, 0x13, 0x10, 0x0e,
6099 0x0b, 0x09, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01};
6100 static const __u8 *gamma_tb[] = {
6101 NULL, Tgamma_1, Tgamma_2,
6102 Tgamma_3, Tgamma_4, Tgamma_5, Tgamma_6
6103 }; 6076 };
6104 static const __u8 *gradient_tb[] = {
6105 NULL, Tgradient_1, Tgradient_2,
6106 Tgradient_3, Tgradient_4, Tgradient_5, Tgradient_6
6107 };
6108#ifdef GSPCA_DEBUG
6109 __u8 v[16];
6110#endif
6111 6077
6112 Tgamma = gamma_tb[sd->gamma]; 6078 Tgamma = gamma_tb[sd->gamma - 1];
6113 Tgradient = gradient_tb[sd->gamma];
6114 6079
6115 k = (sd->contrast - 128) /* -128 / 128 */ 6080 k = ((int) sd->contrast - 128); /* -128 / 128 */
6116 * Tgamma[0]; 6081 adj = 0;
6117 PDEBUG(D_CONF, "gamma:%d contrast:%d gamma coeff: %d/128", 6082 gp = 0;
6118 sd->gamma, sd->contrast, k);
6119 for (i = 0; i < 16; i++) { 6083 for (i = 0; i < 16; i++) {
6120 g = Tgamma[i] + kgamma_tb[i] * k / 128; 6084 g = Tgamma[i] - delta_tb[i] * k / 128 - adj / 2;
6121 if (g > 0xff) 6085 if (g > 0xff)
6122 g = 0xff; 6086 g = 0xff;
6123 else if (g <= 0) 6087 else if (g <= 0)
6124 g = 1; 6088 g = 1;
6125 reg_w(dev, g, 0x0120 + i); /* gamma */ 6089 reg_w(dev, g, 0x0120 + i); /* gamma */
6126#ifdef GSPCA_DEBUG 6090 if (k > 0)
6127 if (gspca_debug & D_CONF) 6091 adj--;
6128 v[i] = g; 6092 else
6129#endif 6093 adj++;
6130 } 6094
6131 PDEBUG(D_CONF, "tb: %02x %02x %02x %02x %02x %02x %02x %02x", 6095 if (i != 0) {
6132 v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); 6096 if (gp == 0)
6133 PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", 6097 gr[i - 1] = 0;
6134 v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]);
6135 for (i = 0; i < 16; i++) {
6136 g = Tgradient[i] - kgrad_tb[i] * k / 128;
6137 if (g > 0xff)
6138 g = 0xff;
6139 else if (g <= 0) {
6140 if (i != 15)
6141 g = 0;
6142 else 6098 else
6143 g = 1; 6099 gr[i - 1] = g - gp;
6144 } 6100 }
6145 reg_w(dev, g, 0x0130 + i); /* gradient */ 6101 gp = g;
6146#ifdef GSPCA_DEBUG
6147 if (gspca_debug & D_CONF)
6148 v[i] = g;
6149#endif
6150 } 6102 }
6151 PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", 6103 gr[15] = gr[14] / 2;
6152 v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); 6104 for (i = 0; i < 16; i++)
6153 PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", 6105 reg_w(dev, gr[i], 0x0130 + i); /* gradient */
6154 v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]);
6155} 6106}
6156 6107
6157static void setquality(struct gspca_dev *gspca_dev) 6108static void setquality(struct gspca_dev *gspca_dev)
6158{ 6109{
6159 struct sd *sd = (struct sd *) gspca_dev; 6110 struct sd *sd = (struct sd *) gspca_dev;
6160 struct usb_device *dev = gspca_dev->dev; 6111 struct usb_device *dev = gspca_dev->dev;
6161 __u8 frxt; 6112 u8 frxt;
6162 6113
6163 switch (sd->sensor) { 6114 switch (sd->sensor) {
6164 case SENSOR_ADCM2700: 6115 case SENSOR_ADCM2700:
6165 case SENSOR_GC0305: 6116 case SENSOR_GC0305:
6166 case SENSOR_HV7131B: 6117 case SENSOR_HV7131B:
6167 case SENSOR_OV7620: 6118 case SENSOR_OV7620:
6119 case SENSOR_PAS202B:
6168 case SENSOR_PO2030: 6120 case SENSOR_PO2030:
6169 return; 6121 return;
6170 } 6122 }
@@ -6218,9 +6170,9 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6218 hdcs2020b_50HZ, hdcs2020b_50HZ, 6170 hdcs2020b_50HZ, hdcs2020b_50HZ,
6219 hdcs2020b_60HZ, hdcs2020b_60HZ}, 6171 hdcs2020b_60HZ, hdcs2020b_60HZ},
6220/* SENSOR_HV7131B 5 */ 6172/* SENSOR_HV7131B 5 */
6221 {hv7131b_NoFlikerScale, hv7131b_NoFliker, 6173 {hv7131b_NoFliker, hv7131b_NoFlikerScale,
6222 hv7131b_50HZScale, hv7131b_50HZ, 6174 hv7131b_50HZ, hv7131b_50HZScale,
6223 hv7131b_60HZScale, hv7131b_60HZ}, 6175 hv7131b_60HZ, hv7131b_60HZScale},
6224/* SENSOR_HV7131C 6 */ 6176/* SENSOR_HV7131C 6 */
6225 {NULL, NULL, 6177 {NULL, NULL,
6226 NULL, NULL, 6178 NULL, NULL,
@@ -6230,17 +6182,17 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6230 icm105a_50HZ, icm105a_50HZScale, 6182 icm105a_50HZ, icm105a_50HZScale,
6231 icm105a_60HZ, icm105a_60HZScale}, 6183 icm105a_60HZ, icm105a_60HZScale},
6232/* SENSOR_MC501CB 8 */ 6184/* SENSOR_MC501CB 8 */
6233 {MC501CB_NoFliker, MC501CB_NoFlikerScale, 6185 {mc501cb_NoFliker, mc501cb_NoFlikerScale,
6234 MC501CB_50HZ, MC501CB_50HZScale, 6186 mc501cb_50HZ, mc501cb_50HZScale,
6235 MC501CB_60HZ, MC501CB_60HZScale}, 6187 mc501cb_60HZ, mc501cb_60HZScale},
6236/* SENSOR_MI0360SOC 9 */ 6188/* SENSOR_MI0360SOC 9 */
6237 {mi360soc_AENoFlikerScale, mi360soc_AENoFliker, 6189 {mi360soc_AENoFliker, mi360soc_AENoFlikerScale,
6238 mi360soc_AE50HZScale, mi360soc_AE50HZ, 6190 mi360soc_AE50HZ, mi360soc_AE50HZScale,
6239 mi360soc_AE60HZScale, mi360soc_AE60HZ}, 6191 mi360soc_AE60HZ, mi360soc_AE60HZScale},
6240/* SENSOR_OV7620 10 */ 6192/* SENSOR_OV7620 10 */
6241 {OV7620_NoFliker, OV7620_NoFliker, 6193 {ov7620_NoFliker, ov7620_NoFliker,
6242 OV7620_50HZ, OV7620_50HZ, 6194 ov7620_50HZ, ov7620_50HZ,
6243 OV7620_60HZ, OV7620_60HZ}, 6195 ov7620_60HZ, ov7620_60HZ},
6244/* SENSOR_OV7630C 11 */ 6196/* SENSOR_OV7630C 11 */
6245 {NULL, NULL, 6197 {NULL, NULL,
6246 NULL, NULL, 6198 NULL, NULL,
@@ -6258,17 +6210,17 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6258 pb0330_50HZScale, pb0330_50HZ, 6210 pb0330_50HZScale, pb0330_50HZ,
6259 pb0330_60HZScale, pb0330_60HZ}, 6211 pb0330_60HZScale, pb0330_60HZ},
6260/* SENSOR_PO2030 15 */ 6212/* SENSOR_PO2030 15 */
6261 {PO2030_NoFliker, PO2030_NoFliker, 6213 {po2030_NoFliker, po2030_NoFliker,
6262 PO2030_50HZ, PO2030_50HZ, 6214 po2030_50HZ, po2030_50HZ,
6263 PO2030_60HZ, PO2030_60HZ}, 6215 po2030_60HZ, po2030_60HZ},
6264/* SENSOR_TAS5130CK 16 */ 6216/* SENSOR_TAS5130CK 16 */
6265 {tas5130cxx_NoFlikerScale, tas5130cxx_NoFliker, 6217 {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale,
6266 tas5130cxx_50HZScale, tas5130cxx_50HZ, 6218 tas5130cxx_50HZ, tas5130cxx_50HZScale,
6267 tas5130cxx_60HZScale, tas5130cxx_60HZ}, 6219 tas5130cxx_60HZ, tas5130cxx_60HZScale},
6268/* SENSOR_TAS5130CXX 17 */ 6220/* SENSOR_TAS5130CXX 17 */
6269 {tas5130cxx_NoFlikerScale, tas5130cxx_NoFliker, 6221 {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale,
6270 tas5130cxx_50HZScale, tas5130cxx_50HZ, 6222 tas5130cxx_50HZ, tas5130cxx_50HZScale,
6271 tas5130cxx_60HZScale, tas5130cxx_60HZ}, 6223 tas5130cxx_60HZ, tas5130cxx_60HZScale},
6272/* SENSOR_TAS5130C_VF0250 18 */ 6224/* SENSOR_TAS5130C_VF0250 18 */
6273 {tas5130c_vf0250_NoFliker, tas5130c_vf0250_NoFlikerScale, 6225 {tas5130c_vf0250_NoFliker, tas5130c_vf0250_NoFlikerScale,
6274 tas5130c_vf0250_50HZ, tas5130c_vf0250_50HZScale, 6226 tas5130c_vf0250_50HZ, tas5130c_vf0250_50HZScale,
@@ -6277,9 +6229,9 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6277 6229
6278 i = sd->lightfreq * 2; 6230 i = sd->lightfreq * 2;
6279 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 6231 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
6280 if (!mode) 6232 if (mode)
6281 i++; /* 640x480 */ 6233 i++; /* 320x240 */
6282 zc3_freq = freq_tb[(int) sd->sensor][i]; 6234 zc3_freq = freq_tb[sd->sensor][i];
6283 if (zc3_freq != NULL) { 6235 if (zc3_freq != NULL) {
6284 usb_exchange(gspca_dev, zc3_freq); 6236 usb_exchange(gspca_dev, zc3_freq);
6285 switch (sd->sensor) { 6237 switch (sd->sensor) {
@@ -6297,6 +6249,9 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6297 reg_w(gspca_dev->dev, 0x44, 0x0002); 6249 reg_w(gspca_dev->dev, 0x44, 0x0002);
6298 } 6250 }
6299 break; 6251 break;
6252 case SENSOR_PAS202B:
6253 reg_w(gspca_dev->dev, 0x00, 0x01a7);
6254 break;
6300 } 6255 }
6301 } 6256 }
6302 return 0; 6257 return 0;
@@ -6305,7 +6260,7 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
6305static void setautogain(struct gspca_dev *gspca_dev) 6260static void setautogain(struct gspca_dev *gspca_dev)
6306{ 6261{
6307 struct sd *sd = (struct sd *) gspca_dev; 6262 struct sd *sd = (struct sd *) gspca_dev;
6308 __u8 autoval; 6263 u8 autoval;
6309 6264
6310 if (sd->autogain) 6265 if (sd->autogain)
6311 autoval = 0x42; 6266 autoval = 0x42;
@@ -6333,6 +6288,12 @@ static void send_unknown(struct usb_device *dev, int sensor)
6333 reg_w(dev, 0x02, 0x003b); 6288 reg_w(dev, 0x02, 0x003b);
6334 reg_w(dev, 0x00, 0x0038); 6289 reg_w(dev, 0x00, 0x0038);
6335 break; 6290 break;
6291 case SENSOR_PAS202B:
6292 reg_w(dev, 0x03, 0x003b);
6293 reg_w(dev, 0x0c, 0x003a);
6294 reg_w(dev, 0x0b, 0x0039);
6295 reg_w(dev, 0x0b, 0x0038);
6296 break;
6336 } 6297 }
6337} 6298}
6338 6299
@@ -6349,7 +6310,7 @@ static void start_2wr_probe(struct usb_device *dev, int sensor)
6349 6310
6350static int sif_probe(struct gspca_dev *gspca_dev) 6311static int sif_probe(struct gspca_dev *gspca_dev)
6351{ 6312{
6352 __u16 checkword; 6313 u16 checkword;
6353 6314
6354 start_2wr_probe(gspca_dev->dev, 0x0f); /* PAS106 */ 6315 start_2wr_probe(gspca_dev->dev, 0x0f); /* PAS106 */
6355 reg_w(gspca_dev->dev, 0x08, 0x008d); 6316 reg_w(gspca_dev->dev, 0x08, 0x008d);
@@ -6392,6 +6353,7 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6392 } 6353 }
6393 6354
6394 start_2wr_probe(dev, 0x08); /* HDCS2020 */ 6355 start_2wr_probe(dev, 0x08); /* HDCS2020 */
6356 i2c_write(gspca_dev, 0x1c, 0x00, 0x00);
6395 i2c_write(gspca_dev, 0x15, 0xaa, 0x00); 6357 i2c_write(gspca_dev, 0x15, 0xaa, 0x00);
6396 retword = i2c_read(gspca_dev, 0x15); 6358 retword = i2c_read(gspca_dev, 0x15);
6397 if (retword != 0) 6359 if (retword != 0)
@@ -6420,8 +6382,10 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6420 i2c_write(gspca_dev, 0x03, 0xaa, 0x00); 6382 i2c_write(gspca_dev, 0x03, 0xaa, 0x00);
6421 msleep(50); 6383 msleep(50);
6422 retword = i2c_read(gspca_dev, 0x03); 6384 retword = i2c_read(gspca_dev, 0x03);
6423 if (retword != 0) 6385 if (retword != 0) {
6386 send_unknown(dev, SENSOR_PAS202B);
6424 return 0x0e; /* PAS202BCB */ 6387 return 0x0e; /* PAS202BCB */
6388 }
6425 6389
6426 start_2wr_probe(dev, 0x02); /* TAS5130C */ 6390 start_2wr_probe(dev, 0x02); /* TAS5130C */
6427 i2c_write(gspca_dev, 0x01, 0xaa, 0x00); 6391 i2c_write(gspca_dev, 0x01, 0xaa, 0x00);
@@ -6457,8 +6421,8 @@ ov_check:
6457} 6421}
6458 6422
6459struct sensor_by_chipset_revision { 6423struct sensor_by_chipset_revision {
6460 __u16 revision; 6424 u16 revision;
6461 __u8 internal_sensor_id; 6425 u8 internal_sensor_id;
6462}; 6426};
6463static const struct sensor_by_chipset_revision chipset_revision_sensor[] = { 6427static const struct sensor_by_chipset_revision chipset_revision_sensor[] = {
6464 {0xc000, 0x12}, /* TAS5130C */ 6428 {0xc000, 0x12}, /* TAS5130C */
@@ -6467,6 +6431,7 @@ static const struct sensor_by_chipset_revision chipset_revision_sensor[] = {
6467 {0x8001, 0x13}, 6431 {0x8001, 0x13},
6468 {0x8000, 0x14}, /* CS2102K */ 6432 {0x8000, 0x14}, /* CS2102K */
6469 {0x8400, 0x15}, /* TAS5130K */ 6433 {0x8400, 0x15}, /* TAS5130K */
6434 {0xe400, 0x15},
6470}; 6435};
6471 6436
6472static int vga_3wr_probe(struct gspca_dev *gspca_dev) 6437static int vga_3wr_probe(struct gspca_dev *gspca_dev)
@@ -6474,7 +6439,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6474 struct sd *sd = (struct sd *) gspca_dev; 6439 struct sd *sd = (struct sd *) gspca_dev;
6475 struct usb_device *dev = gspca_dev->dev; 6440 struct usb_device *dev = gspca_dev->dev;
6476 int i; 6441 int i;
6477 __u8 retbyte; 6442 u8 retbyte;
6478 u16 retword; 6443 u16 retword;
6479 6444
6480/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/ 6445/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/
@@ -6622,8 +6587,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
6622 struct sd *sd = (struct sd *) gspca_dev; 6587 struct sd *sd = (struct sd *) gspca_dev;
6623 struct cam *cam; 6588 struct cam *cam;
6624 int sensor; 6589 int sensor;
6625 int vga = 1; /* 1: vga, 0: sif */ 6590 static const u8 gamma[SENSOR_MAX] = {
6626 static const __u8 gamma[SENSOR_MAX] = {
6627 4, /* SENSOR_ADCM2700 0 */ 6591 4, /* SENSOR_ADCM2700 0 */
6628 4, /* SENSOR_CS2102 1 */ 6592 4, /* SENSOR_CS2102 1 */
6629 5, /* SENSOR_CS2102K 2 */ 6593 5, /* SENSOR_CS2102K 2 */
@@ -6644,9 +6608,30 @@ static int sd_config(struct gspca_dev *gspca_dev,
6644 3, /* SENSOR_TAS5130CXX 17 */ 6608 3, /* SENSOR_TAS5130CXX 17 */
6645 3, /* SENSOR_TAS5130C_VF0250 18 */ 6609 3, /* SENSOR_TAS5130C_VF0250 18 */
6646 }; 6610 };
6611 static const u8 mode_tb[SENSOR_MAX] = {
6612 2, /* SENSOR_ADCM2700 0 */
6613 1, /* SENSOR_CS2102 1 */
6614 1, /* SENSOR_CS2102K 2 */
6615 1, /* SENSOR_GC0305 3 */
6616 1, /* SENSOR_HDCS2020b 4 */
6617 1, /* SENSOR_HV7131B 5 */
6618 1, /* SENSOR_HV7131C 6 */
6619 1, /* SENSOR_ICM105A 7 */
6620 2, /* SENSOR_MC501CB 8 */
6621 1, /* SENSOR_MI0360SOC 9 */
6622 2, /* SENSOR_OV7620 10 */
6623 1, /* SENSOR_OV7630C 11 */
6624 0, /* SENSOR_PAS106 12 */
6625 1, /* SENSOR_PAS202B 13 */
6626 1, /* SENSOR_PB0330 14 */
6627 1, /* SENSOR_PO2030 15 */
6628 1, /* SENSOR_TAS5130CK 16 */
6629 1, /* SENSOR_TAS5130CXX 17 */
6630 1, /* SENSOR_TAS5130C_VF0250 18 */
6631 };
6647 6632
6648 /* define some sensors from the vendor/product */ 6633 /* define some sensors from the vendor/product */
6649 sd->sharpness = 2; 6634 sd->sharpness = SHARPNESS_DEF;
6650 sd->sensor = id->driver_info; 6635 sd->sensor = id->driver_info;
6651 sensor = zcxx_probeSensor(gspca_dev); 6636 sensor = zcxx_probeSensor(gspca_dev);
6652 if (sensor >= 0) 6637 if (sensor >= 0)
@@ -6671,8 +6656,21 @@ static int sd_config(struct gspca_dev *gspca_dev,
6671 } 6656 }
6672 break; 6657 break;
6673 case 0: 6658 case 0:
6674 PDEBUG(D_PROBE, "Find Sensor HV7131B"); 6659 /* check the sensor type */
6675 sd->sensor = SENSOR_HV7131B; 6660 sensor = i2c_read(gspca_dev, 0x00);
6661 PDEBUG(D_PROBE, "Sensor hv7131 type %d", sensor);
6662 switch (sensor) {
6663 case 0: /* hv7131b */
6664 case 1: /* hv7131e */
6665 PDEBUG(D_PROBE, "Find Sensor HV7131B");
6666 sd->sensor = SENSOR_HV7131B;
6667 break;
6668 default:
6669/* case 2: * hv7131r */
6670 PDEBUG(D_PROBE, "Find Sensor HV7131R(c)");
6671 sd->sensor = SENSOR_HV7131C;
6672 break;
6673 }
6676 break; 6674 break;
6677 case 0x02: 6675 case 0x02:
6678 PDEBUG(D_PROBE, "Sensor TAS5130C"); 6676 PDEBUG(D_PROBE, "Sensor TAS5130C");
@@ -6699,12 +6697,11 @@ static int sd_config(struct gspca_dev *gspca_dev,
6699 case 0x0e: 6697 case 0x0e:
6700 PDEBUG(D_PROBE, "Find Sensor PAS202B"); 6698 PDEBUG(D_PROBE, "Find Sensor PAS202B");
6701 sd->sensor = SENSOR_PAS202B; 6699 sd->sensor = SENSOR_PAS202B;
6702 sd->sharpness = 1; 6700/* sd->sharpness = 1; */
6703 break; 6701 break;
6704 case 0x0f: 6702 case 0x0f:
6705 PDEBUG(D_PROBE, "Find Sensor PAS106"); 6703 PDEBUG(D_PROBE, "Find Sensor PAS106");
6706 sd->sensor = SENSOR_PAS106; 6704 sd->sensor = SENSOR_PAS106;
6707 vga = 0; /* SIF */
6708 break; 6705 break;
6709 case 0x10: 6706 case 0x10:
6710 case 0x12: 6707 case 0x12:
@@ -6770,31 +6767,38 @@ static int sd_config(struct gspca_dev *gspca_dev,
6770 if (sensor < 0x20) { 6767 if (sensor < 0x20) {
6771 if (sensor == -1 || sensor == 0x10 || sensor == 0x12) 6768 if (sensor == -1 || sensor == 0x10 || sensor == 0x12)
6772 reg_w(gspca_dev->dev, 0x02, 0x0010); 6769 reg_w(gspca_dev->dev, 0x02, 0x0010);
6773 else
6774 reg_w(gspca_dev->dev, sensor & 0x0f, 0x0010);
6775 reg_r(gspca_dev, 0x0010); 6770 reg_r(gspca_dev, 0x0010);
6776 } 6771 }
6777 6772
6778 cam = &gspca_dev->cam; 6773 cam = &gspca_dev->cam;
6779/*fixme:test*/ 6774/*fixme:test*/
6780 gspca_dev->nbalt--; 6775 gspca_dev->nbalt--;
6781 if (vga) { 6776 switch (mode_tb[sd->sensor]) {
6782 cam->cam_mode = vga_mode; 6777 case 0:
6783 cam->nmodes = ARRAY_SIZE(vga_mode);
6784 } else {
6785 cam->cam_mode = sif_mode; 6778 cam->cam_mode = sif_mode;
6786 cam->nmodes = ARRAY_SIZE(sif_mode); 6779 cam->nmodes = ARRAY_SIZE(sif_mode);
6780 break;
6781 case 1:
6782 cam->cam_mode = vga_mode;
6783 cam->nmodes = ARRAY_SIZE(vga_mode);
6784 break;
6785 default:
6786/* case 2: */
6787 cam->cam_mode = broken_vga_mode;
6788 cam->nmodes = ARRAY_SIZE(broken_vga_mode);
6789 break;
6787 } 6790 }
6788 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 6791 sd->brightness = BRIGHTNESS_DEF;
6789 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 6792 sd->contrast = CONTRAST_DEF;
6790 sd->gamma = gamma[(int) sd->sensor]; 6793 sd->gamma = gamma[sd->sensor];
6791 sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value; 6794 sd->autogain = AUTOGAIN_DEF;
6792 sd->lightfreq = sd_ctrls[SD_FREQ].qctrl.default_value; 6795 sd->lightfreq = FREQ_DEF;
6793 sd->quality = QUALITY_DEF; 6796 sd->quality = QUALITY_DEF;
6794 6797
6795 switch (sd->sensor) { 6798 switch (sd->sensor) {
6796 case SENSOR_GC0305: 6799 case SENSOR_GC0305:
6797 case SENSOR_OV7620: 6800 case SENSOR_OV7620:
6801 case SENSOR_PAS202B:
6798 case SENSOR_PO2030: 6802 case SENSOR_PO2030:
6799 gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX); 6803 gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX);
6800 break; 6804 break;
@@ -6805,14 +6809,13 @@ static int sd_config(struct gspca_dev *gspca_dev,
6805 break; 6809 break;
6806 } 6810 }
6807 6811
6808 /* switch the led off */
6809 reg_w(gspca_dev->dev, 0x01, 0x0000);
6810 return 0; 6812 return 0;
6811} 6813}
6812 6814
6813/* this function is called at probe and resume time */ 6815/* this function is called at probe and resume time */
6814static int sd_init(struct gspca_dev *gspca_dev) 6816static int sd_init(struct gspca_dev *gspca_dev)
6815{ 6817{
6818 /* switch off the led */
6816 reg_w(gspca_dev->dev, 0x01, 0x0000); 6819 reg_w(gspca_dev->dev, 0x01, 0x0000);
6817 return 0; 6820 return 0;
6818} 6821}
@@ -6821,28 +6824,27 @@ static int sd_start(struct gspca_dev *gspca_dev)
6821{ 6824{
6822 struct sd *sd = (struct sd *) gspca_dev; 6825 struct sd *sd = (struct sd *) gspca_dev;
6823 struct usb_device *dev = gspca_dev->dev; 6826 struct usb_device *dev = gspca_dev->dev;
6824 const struct usb_action *zc3_init;
6825 int mode; 6827 int mode;
6826 static const struct usb_action *init_tb[SENSOR_MAX][2] = { 6828 static const struct usb_action *init_tb[SENSOR_MAX][2] = {
6827 {adcm2700_Initial, adcm2700_InitialScale}, /* 0 */ 6829 {adcm2700_Initial, adcm2700_InitialScale}, /* 0 */
6828 {cs2102_InitialScale, cs2102_Initial}, /* 1 */ 6830 {cs2102_Initial, cs2102_InitialScale}, /* 1 */
6829 {cs2102K_InitialScale, cs2102K_Initial}, /* 2 */ 6831 {cs2102K_Initial, cs2102K_InitialScale}, /* 2 */
6830 {gc0305_Initial, gc0305_InitialScale}, /* 3 */ 6832 {gc0305_Initial, gc0305_InitialScale}, /* 3 */
6831 {hdcs2020xb_InitialScale, hdcs2020xb_Initial}, /* 4 */ 6833 {hdcs2020b_Initial, hdcs2020b_InitialScale}, /* 4 */
6832 {hv7131bxx_InitialScale, hv7131bxx_Initial}, /* 5 */ 6834 {hv7131b_Initial, hv7131b_InitialScale}, /* 5 */
6833 {hv7131cxx_InitialScale, hv7131cxx_Initial}, /* 6 */ 6835 {hv7131r_Initial, hv7131r_InitialScale}, /* 6 */
6834 {icm105axx_InitialScale, icm105axx_Initial}, /* 7 */ 6836 {icm105a_Initial, icm105a_InitialScale}, /* 7 */
6835 {MC501CB_InitialScale, MC501CB_Initial}, /* 8 */ 6837 {mc501cb_Initial, mc501cb_InitialScale}, /* 8 */
6836 {mi0360soc_Initial, mi0360soc_InitialScale}, /* 9 */ 6838 {mi0360soc_Initial, mi0360soc_InitialScale}, /* 9 */
6837 {OV7620_mode0, OV7620_mode1}, /* 10 */ 6839 {ov7620_Initial, ov7620_InitialScale}, /* 10 */
6838 {ov7630c_InitialScale, ov7630c_Initial}, /* 11 */ 6840 {ov7630c_Initial, ov7630c_InitialScale}, /* 11 */
6839 {pas106b_InitialScale, pas106b_Initial}, /* 12 */ 6841 {pas106b_Initial, pas106b_InitialScale}, /* 12 */
6840 {pas202b_Initial, pas202b_InitialScale}, /* 13 */ 6842 {pas202b_Initial, pas202b_InitialScale}, /* 13 */
6841 {pb0330_Initial, pb0330_InitialScale}, /* 14 */ 6843 {pb0330_Initial, pb0330_InitialScale}, /* 14 */
6842 {PO2030_mode0, PO2030_mode1}, /* 15 */ 6844 {po2030_Initial, po2030_InitialScale}, /* 15 */
6843 {tas5130CK_InitialScale, tas5130CK_Initial}, /* 16 */ 6845 {tas5130cK_Initial, tas5130cK_InitialScale}, /* 16 */
6844 {tas5130cxx_Initial, tas5130cxx_InitialScale}, /* 17 */ 6846 {tas5130cxx_Initial, tas5130cxx_InitialScale}, /* 17 */
6845 {tas5130c_vf0250_InitialScale, tas5130c_vf0250_Initial}, 6847 {tas5130c_vf0250_Initial, tas5130c_vf0250_InitialScale},
6846 /* 18 */ 6848 /* 18 */
6847 }; 6849 };
6848 6850
@@ -6854,8 +6856,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
6854 0x21); /* JPEG 422 */ 6856 0x21); /* JPEG 422 */
6855 jpeg_set_qual(sd->jpeg_hdr, sd->quality); 6857 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
6856 6858
6857 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 6859 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
6858 zc3_init = init_tb[(int) sd->sensor][mode];
6859 switch (sd->sensor) { 6860 switch (sd->sensor) {
6860 case SENSOR_HV7131C: 6861 case SENSOR_HV7131C:
6861 zcxx_probeSensor(gspca_dev); 6862 zcxx_probeSensor(gspca_dev);
@@ -6864,7 +6865,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
6864 usb_exchange(gspca_dev, pas106b_Initial_com); 6865 usb_exchange(gspca_dev, pas106b_Initial_com);
6865 break; 6866 break;
6866 } 6867 }
6867 usb_exchange(gspca_dev, zc3_init); 6868 usb_exchange(gspca_dev, init_tb[sd->sensor][mode]);
6868 6869
6869 switch (sd->sensor) { 6870 switch (sd->sensor) {
6870 case SENSOR_ADCM2700: 6871 case SENSOR_ADCM2700:
@@ -6883,6 +6884,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
6883 reg_w(dev, 0x02, 0x003b); 6884 reg_w(dev, 0x02, 0x003b);
6884 reg_w(dev, 0x00, 0x0038); 6885 reg_w(dev, 0x00, 0x0038);
6885 break; 6886 break;
6887 case SENSOR_PAS202B:
6888 reg_w(dev, 0x03, 0x003b);
6889 reg_w(dev, 0x0c, 0x003a);
6890 reg_w(dev, 0x0b, 0x0039);
6891 break;
6886 } 6892 }
6887 6893
6888 setmatrix(gspca_dev); 6894 setmatrix(gspca_dev);
@@ -6961,13 +6967,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
6961 switch (sd->sensor) { 6967 switch (sd->sensor) {
6962 case SENSOR_PO2030: 6968 case SENSOR_PO2030:
6963 msleep(50); 6969 msleep(50);
6964 reg_r(gspca_dev, 0x0008);
6965 reg_r(gspca_dev, 0x0007);
6966 /*fall thru*/
6967 case SENSOR_PAS202B:
6968 reg_w(dev, 0x00, 0x0007); /* (from win traces) */ 6970 reg_w(dev, 0x00, 0x0007); /* (from win traces) */
6969 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING); 6971 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING);
6970 break; 6972 break;
6973 case SENSOR_PAS202B:
6974 reg_w(dev, 0x32, 0x0007); /* (from win traces) */
6975 reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING);
6976 break;
6971 } 6977 }
6972 return 0; 6978 return 0;
6973} 6979}
@@ -7165,6 +7171,22 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev,
7165 return 0; 7171 return 0;
7166} 7172}
7167 7173
7174#ifdef CONFIG_INPUT
7175static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
7176 u8 *data, /* interrupt packet data */
7177 int len) /* interrput packet length */
7178{
7179 if (len == 8 && data[4] == 1) {
7180 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
7181 input_sync(gspca_dev->input_dev);
7182 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
7183 input_sync(gspca_dev->input_dev);
7184 }
7185
7186 return 0;
7187}
7188#endif
7189
7168static const struct sd_desc sd_desc = { 7190static const struct sd_desc sd_desc = {
7169 .name = MODULE_NAME, 7191 .name = MODULE_NAME,
7170 .ctrls = sd_ctrls, 7192 .ctrls = sd_ctrls,
@@ -7177,6 +7199,9 @@ static const struct sd_desc sd_desc = {
7177 .querymenu = sd_querymenu, 7199 .querymenu = sd_querymenu,
7178 .get_jcomp = sd_get_jcomp, 7200 .get_jcomp = sd_get_jcomp,
7179 .set_jcomp = sd_set_jcomp, 7201 .set_jcomp = sd_set_jcomp,
7202#ifdef CONFIG_INPUT
7203 .int_pkt_scan = sd_int_pkt_scan,
7204#endif
7180}; 7205};
7181 7206
7182static const __devinitdata struct usb_device_id device_table[] = { 7207static const __devinitdata struct usb_device_id device_table[] = {
diff --git a/drivers/media/video/hdpvr/hdpvr-core.c b/drivers/media/video/hdpvr/hdpvr-core.c
index 51f393d03a46..2fc9865fd486 100644
--- a/drivers/media/video/hdpvr/hdpvr-core.c
+++ b/drivers/media/video/hdpvr/hdpvr-core.c
@@ -39,12 +39,12 @@ int hdpvr_debug;
39module_param(hdpvr_debug, int, S_IRUGO|S_IWUSR); 39module_param(hdpvr_debug, int, S_IRUGO|S_IWUSR);
40MODULE_PARM_DESC(hdpvr_debug, "enable debugging output"); 40MODULE_PARM_DESC(hdpvr_debug, "enable debugging output");
41 41
42uint default_video_input = HDPVR_VIDEO_INPUTS; 42static uint default_video_input = HDPVR_VIDEO_INPUTS;
43module_param(default_video_input, uint, S_IRUGO|S_IWUSR); 43module_param(default_video_input, uint, S_IRUGO|S_IWUSR);
44MODULE_PARM_DESC(default_video_input, "default video input: 0=Component / " 44MODULE_PARM_DESC(default_video_input, "default video input: 0=Component / "
45 "1=S-Video / 2=Composite"); 45 "1=S-Video / 2=Composite");
46 46
47uint default_audio_input = HDPVR_AUDIO_INPUTS; 47static uint default_audio_input = HDPVR_AUDIO_INPUTS;
48module_param(default_audio_input, uint, S_IRUGO|S_IWUSR); 48module_param(default_audio_input, uint, S_IRUGO|S_IWUSR);
49MODULE_PARM_DESC(default_audio_input, "default audio input: 0=RCA back / " 49MODULE_PARM_DESC(default_audio_input, "default audio input: 0=RCA back / "
50 "1=RCA front / 2=S/PDIF"); 50 "1=RCA front / 2=S/PDIF");
@@ -59,6 +59,7 @@ static struct usb_device_id hdpvr_table[] = {
59 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID) }, 59 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID) },
60 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID1) }, 60 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID1) },
61 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID2) }, 61 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID2) },
62 { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID3) },
62 { } /* Terminating entry */ 63 { } /* Terminating entry */
63}; 64};
64MODULE_DEVICE_TABLE(usb, hdpvr_table); 65MODULE_DEVICE_TABLE(usb, hdpvr_table);
diff --git a/drivers/media/video/hdpvr/hdpvr-video.c b/drivers/media/video/hdpvr/hdpvr-video.c
index fdd782039e9d..196f82de48f0 100644
--- a/drivers/media/video/hdpvr/hdpvr-video.c
+++ b/drivers/media/video/hdpvr/hdpvr-video.c
@@ -302,7 +302,8 @@ static int hdpvr_start_streaming(struct hdpvr_device *dev)
302/* function expects dev->io_mutex to be hold by caller */ 302/* function expects dev->io_mutex to be hold by caller */
303static int hdpvr_stop_streaming(struct hdpvr_device *dev) 303static int hdpvr_stop_streaming(struct hdpvr_device *dev)
304{ 304{
305 uint actual_length, c = 0; 305 int actual_length;
306 uint c = 0;
306 u8 *buf; 307 u8 *buf;
307 308
308 if (dev->status == STATUS_IDLE) 309 if (dev->status == STATUS_IDLE)
@@ -572,7 +573,7 @@ static int vidioc_querycap(struct file *file, void *priv,
572 struct hdpvr_device *dev = video_drvdata(file); 573 struct hdpvr_device *dev = video_drvdata(file);
573 574
574 strcpy(cap->driver, "hdpvr"); 575 strcpy(cap->driver, "hdpvr");
575 strcpy(cap->card, "Haupauge HD PVR"); 576 strcpy(cap->card, "Hauppauge HD PVR");
576 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); 577 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
577 cap->version = HDPVR_VERSION; 578 cap->version = HDPVR_VERSION;
578 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 579 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
diff --git a/drivers/media/video/hdpvr/hdpvr.h b/drivers/media/video/hdpvr/hdpvr.h
index 1edd8759121e..49ae25d83d10 100644
--- a/drivers/media/video/hdpvr/hdpvr.h
+++ b/drivers/media/video/hdpvr/hdpvr.h
@@ -30,6 +30,7 @@
30#define HD_PVR_PRODUCT_ID 0x4900 30#define HD_PVR_PRODUCT_ID 0x4900
31#define HD_PVR_PRODUCT_ID1 0x4901 31#define HD_PVR_PRODUCT_ID1 0x4901
32#define HD_PVR_PRODUCT_ID2 0x4902 32#define HD_PVR_PRODUCT_ID2 0x4902
33#define HD_PVR_PRODUCT_ID3 0x4982
33 34
34#define UNSET (-1U) 35#define UNSET (-1U)
35 36
diff --git a/drivers/media/video/hexium_gemini.c b/drivers/media/video/hexium_gemini.c
index 60d992ee2589..e620a3a92f25 100644
--- a/drivers/media/video/hexium_gemini.c
+++ b/drivers/media/video/hexium_gemini.c
@@ -352,9 +352,13 @@ static struct saa7146_ext_vv vv_data;
352static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info) 352static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
353{ 353{
354 struct hexium *hexium = (struct hexium *) dev->ext_priv; 354 struct hexium *hexium = (struct hexium *) dev->ext_priv;
355 int ret;
355 356
356 DEB_EE((".\n")); 357 DEB_EE((".\n"));
357 358
359 ret = saa7146_vv_devinit(dev);
360 if (ret)
361 return ret;
358 hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL); 362 hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL);
359 if (NULL == hexium) { 363 if (NULL == hexium) {
360 printk("hexium_gemini: not enough kernel memory in hexium_attach().\n"); 364 printk("hexium_gemini: not enough kernel memory in hexium_attach().\n");
@@ -400,9 +404,10 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
400 vv_data.ops.vidioc_enum_input = vidioc_enum_input; 404 vv_data.ops.vidioc_enum_input = vidioc_enum_input;
401 vv_data.ops.vidioc_g_input = vidioc_g_input; 405 vv_data.ops.vidioc_g_input = vidioc_g_input;
402 vv_data.ops.vidioc_s_input = vidioc_s_input; 406 vv_data.ops.vidioc_s_input = vidioc_s_input;
403 if (0 != saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_GRABBER)) { 407 ret = saa7146_register_device(&hexium->video_dev, dev, "hexium gemini", VFL_TYPE_GRABBER);
408 if (ret < 0) {
404 printk("hexium_gemini: cannot register capture v4l2 device. skipping.\n"); 409 printk("hexium_gemini: cannot register capture v4l2 device. skipping.\n");
405 return -1; 410 return ret;
406 } 411 }
407 412
408 printk("hexium_gemini: found 'hexium gemini' frame grabber-%d.\n", hexium_num); 413 printk("hexium_gemini: found 'hexium gemini' frame grabber-%d.\n", hexium_num);
diff --git a/drivers/media/video/hexium_orion.c b/drivers/media/video/hexium_orion.c
index 938a1f8f880a..fe596a1c12a8 100644
--- a/drivers/media/video/hexium_orion.c
+++ b/drivers/media/video/hexium_orion.c
@@ -216,6 +216,10 @@ static int hexium_probe(struct saa7146_dev *dev)
216 return -EFAULT; 216 return -EFAULT;
217 } 217 }
218 218
219 err = saa7146_vv_devinit(dev);
220 if (err)
221 return err;
222
219 hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL); 223 hexium = kzalloc(sizeof(struct hexium), GFP_KERNEL);
220 if (NULL == hexium) { 224 if (NULL == hexium) {
221 printk("hexium_orion: hexium_probe: not enough kernel memory.\n"); 225 printk("hexium_orion: hexium_probe: not enough kernel memory.\n");
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index b86e35386cee..da18d698e7f2 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -299,7 +299,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
299{ 299{
300 struct ir_scancode_table *ir_codes = NULL; 300 struct ir_scancode_table *ir_codes = NULL;
301 const char *name = NULL; 301 const char *name = NULL;
302 int ir_type = 0; 302 u64 ir_type = 0;
303 struct IR_i2c *ir; 303 struct IR_i2c *ir;
304 struct input_dev *input_dev; 304 struct input_dev *input_dev;
305 struct i2c_adapter *adap = client->adapter; 305 struct i2c_adapter *adap = client->adapter;
@@ -331,6 +331,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
331 ir_codes = &ir_codes_pv951_table; 331 ir_codes = &ir_codes_pv951_table;
332 break; 332 break;
333 case 0x18: 333 case 0x18:
334 case 0x1f:
334 case 0x1a: 335 case 0x1a:
335 name = "Hauppauge"; 336 name = "Hauppauge";
336 ir->get_key = get_key_haup; 337 ir->get_key = get_key_haup;
@@ -446,7 +447,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
446 input_dev->name = ir->name; 447 input_dev->name = ir->name;
447 input_dev->phys = ir->phys; 448 input_dev->phys = ir->phys;
448 449
449 err = ir_input_register(ir->input, ir->ir_codes); 450 err = ir_input_register(ir->input, ir->ir_codes, NULL);
450 if (err) 451 if (err)
451 goto err_out_free; 452 goto err_out_free;
452 453
diff --git a/drivers/media/video/ivtv/ivtv-cards.c b/drivers/media/video/ivtv/ivtv-cards.c
index 79d0fe4990d6..ca1fd3227a93 100644
--- a/drivers/media/video/ivtv/ivtv-cards.c
+++ b/drivers/media/video/ivtv/ivtv-cards.c
@@ -1210,6 +1210,53 @@ static const struct ivtv_card ivtv_card_buffalo = {
1210 .i2c = &ivtv_i2c_std, 1210 .i2c = &ivtv_i2c_std,
1211}; 1211};
1212 1212
1213/* ------------------------------------------------------------------------- */
1214/* Sony Kikyou */
1215
1216static const struct ivtv_card_pci_info ivtv_pci_kikyou[] = {
1217 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_SONY, 0x813d },
1218 { 0, 0, 0 }
1219};
1220
1221static const struct ivtv_card ivtv_card_kikyou = {
1222 .type = IVTV_CARD_KIKYOU,
1223 .name = "Sony VAIO Giga Pocket (ENX Kikyou)",
1224 .v4l2_capabilities = IVTV_CAP_ENCODER,
1225 .hw_video = IVTV_HW_SAA7115,
1226 .hw_audio = IVTV_HW_GPIO,
1227 .hw_audio_ctrl = IVTV_HW_GPIO,
1228 .hw_all = IVTV_HW_GPIO | IVTV_HW_SAA7115 | IVTV_HW_TUNER,
1229 .video_inputs = {
1230 { IVTV_CARD_INPUT_VID_TUNER, 0, IVTV_SAA71XX_COMPOSITE1 },
1231 { IVTV_CARD_INPUT_COMPOSITE1, 1, IVTV_SAA71XX_COMPOSITE1 },
1232 { IVTV_CARD_INPUT_SVIDEO1, 1, IVTV_SAA71XX_SVIDEO1 },
1233 },
1234 .audio_inputs = {
1235 { IVTV_CARD_INPUT_AUD_TUNER, IVTV_GPIO_TUNER },
1236 { IVTV_CARD_INPUT_LINE_IN1, IVTV_GPIO_LINE_IN },
1237 { IVTV_CARD_INPUT_LINE_IN2, IVTV_GPIO_LINE_IN },
1238 },
1239 .gpio_init = { .direction = 0x03e1, .initial_value = 0x0320 },
1240 .gpio_audio_input = { .mask = 0x0060,
1241 .tuner = 0x0020,
1242 .linein = 0x0000,
1243 .radio = 0x0060 },
1244 .gpio_audio_mute = { .mask = 0x0000,
1245 .mute = 0x0000 }, /* 0x200? Disable for now. */
1246 .gpio_audio_mode = { .mask = 0x0080,
1247 .mono = 0x0000,
1248 .stereo = 0x0000, /* SAP */
1249 .lang1 = 0x0080,
1250 .lang2 = 0x0000,
1251 .both = 0x0080 },
1252 .tuners = {
1253 { .std = V4L2_STD_ALL, .tuner = TUNER_SONY_BTF_PXN01Z },
1254 },
1255 .pci_list = ivtv_pci_kikyou,
1256 .i2c = &ivtv_i2c_std,
1257};
1258
1259
1213static const struct ivtv_card *ivtv_card_list[] = { 1260static const struct ivtv_card *ivtv_card_list[] = {
1214 &ivtv_card_pvr250, 1261 &ivtv_card_pvr250,
1215 &ivtv_card_pvr350, 1262 &ivtv_card_pvr350,
@@ -1238,6 +1285,7 @@ static const struct ivtv_card *ivtv_card_list[] = {
1238 &ivtv_card_aver_m104, 1285 &ivtv_card_aver_m104,
1239 &ivtv_card_buffalo, 1286 &ivtv_card_buffalo,
1240 &ivtv_card_aver_ultra1500mce, 1287 &ivtv_card_aver_ultra1500mce,
1288 &ivtv_card_kikyou,
1241 1289
1242 /* Variations of standard cards but with the same PCI IDs. 1290 /* Variations of standard cards but with the same PCI IDs.
1243 These cards must come last in this list. */ 1291 These cards must come last in this list. */
diff --git a/drivers/media/video/ivtv/ivtv-cards.h b/drivers/media/video/ivtv/ivtv-cards.h
index 6148827ec885..78eca992e1fd 100644
--- a/drivers/media/video/ivtv/ivtv-cards.h
+++ b/drivers/media/video/ivtv/ivtv-cards.h
@@ -51,7 +51,8 @@
51#define IVTV_CARD_AVER_M104 24 /* AverMedia M104 miniPCI card */ 51#define IVTV_CARD_AVER_M104 24 /* AverMedia M104 miniPCI card */
52#define IVTV_CARD_BUFFALO_MV5L 25 /* Buffalo PC-MV5L/PCI card */ 52#define IVTV_CARD_BUFFALO_MV5L 25 /* Buffalo PC-MV5L/PCI card */
53#define IVTV_CARD_AVER_ULTRA1500MCE 26 /* AVerMedia UltraTV 1500 MCE */ 53#define IVTV_CARD_AVER_ULTRA1500MCE 26 /* AVerMedia UltraTV 1500 MCE */
54#define IVTV_CARD_LAST 26 54#define IVTV_CARD_KIKYOU 27 /* Sony VAIO Giga Pocket (ENX Kikyou) */
55#define IVTV_CARD_LAST 27
55 56
56/* Variants of existing cards but with the same PCI IDs. The driver 57/* Variants of existing cards but with the same PCI IDs. The driver
57 detects these based on other device information. 58 detects these based on other device information.
@@ -86,6 +87,7 @@
86#define IVTV_PCI_ID_MELCO 0x1154 87#define IVTV_PCI_ID_MELCO 0x1154
87#define IVTV_PCI_ID_GOTVIEW1 0xffac 88#define IVTV_PCI_ID_GOTVIEW1 0xffac
88#define IVTV_PCI_ID_GOTVIEW2 0xffad 89#define IVTV_PCI_ID_GOTVIEW2 0xffad
90#define IVTV_PCI_ID_SONY 0x104d
89 91
90/* hardware flags, no gaps allowed */ 92/* hardware flags, no gaps allowed */
91#define IVTV_HW_CX25840 (1 << 0) 93#define IVTV_HW_CX25840 (1 << 0)
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 347c3344f56d..9a250548be4d 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -193,6 +193,7 @@ MODULE_PARM_DESC(cardtype,
193 "\t\t\t25 = AverMedia M104 (not yet working)\n" 193 "\t\t\t25 = AverMedia M104 (not yet working)\n"
194 "\t\t\t26 = Buffalo PC-MV5L/PCI\n" 194 "\t\t\t26 = Buffalo PC-MV5L/PCI\n"
195 "\t\t\t27 = AVerMedia UltraTV 1500 MCE\n" 195 "\t\t\t27 = AVerMedia UltraTV 1500 MCE\n"
196 "\t\t\t28 = Sony VAIO Giga Pocket (ENX Kikyou)\n"
196 "\t\t\t 0 = Autodetect (default)\n" 197 "\t\t\t 0 = Autodetect (default)\n"
197 "\t\t\t-1 = Ignore this card\n\t\t"); 198 "\t\t\t-1 = Ignore this card\n\t\t");
198MODULE_PARM_DESC(pal, "Set PAL standard: BGH, DK, I, M, N, Nc, 60"); 199MODULE_PARM_DESC(pal, "Set PAL standard: BGH, DK, I, M, N, Nc, 60");
diff --git a/drivers/media/video/ivtv/ivtv-firmware.c b/drivers/media/video/ivtv/ivtv-firmware.c
index c1b7ec475c27..a71e8ba306b0 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.c
+++ b/drivers/media/video/ivtv/ivtv-firmware.c
@@ -258,7 +258,7 @@ void ivtv_init_mpeg_decoder(struct ivtv *itv)
258 IVTV_ERR("ivtv_init_mpeg_decoder failed to start playback\n"); 258 IVTV_ERR("ivtv_init_mpeg_decoder failed to start playback\n");
259 return; 259 return;
260 } 260 }
261 ivtv_api_get_data(&itv->dec_mbox, IVTV_MBOX_DMA, data); 261 ivtv_api_get_data(&itv->dec_mbox, IVTV_MBOX_DMA, 2, data);
262 mem_offset = itv->dec_mem + data[1]; 262 mem_offset = itv->dec_mem + data[1];
263 263
264 if ((readbytes = load_fw_direct(IVTV_DECODE_INIT_MPEG_FILENAME, 264 if ((readbytes = load_fw_direct(IVTV_DECODE_INIT_MPEG_FILENAME,
diff --git a/drivers/media/video/ivtv/ivtv-irq.c b/drivers/media/video/ivtv/ivtv-irq.c
index cd9db0bf33bf..12d36ca91d53 100644
--- a/drivers/media/video/ivtv/ivtv-irq.c
+++ b/drivers/media/video/ivtv/ivtv-irq.c
@@ -562,7 +562,7 @@ static void ivtv_irq_enc_dma_complete(struct ivtv *itv)
562 u32 data[CX2341X_MBOX_MAX_DATA]; 562 u32 data[CX2341X_MBOX_MAX_DATA];
563 struct ivtv_stream *s; 563 struct ivtv_stream *s;
564 564
565 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data); 565 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, 2, data);
566 IVTV_DEBUG_HI_IRQ("ENC DMA COMPLETE %x %d (%d)\n", data[0], data[1], itv->cur_dma_stream); 566 IVTV_DEBUG_HI_IRQ("ENC DMA COMPLETE %x %d (%d)\n", data[0], data[1], itv->cur_dma_stream);
567 567
568 del_timer(&itv->dma_timer); 568 del_timer(&itv->dma_timer);
@@ -638,7 +638,7 @@ static void ivtv_irq_dma_err(struct ivtv *itv)
638 u32 data[CX2341X_MBOX_MAX_DATA]; 638 u32 data[CX2341X_MBOX_MAX_DATA];
639 639
640 del_timer(&itv->dma_timer); 640 del_timer(&itv->dma_timer);
641 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data); 641 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, 2, data);
642 IVTV_DEBUG_WARN("DMA ERROR %08x %08x %08x %d\n", data[0], data[1], 642 IVTV_DEBUG_WARN("DMA ERROR %08x %08x %08x %d\n", data[0], data[1],
643 read_reg(IVTV_REG_DMASTATUS), itv->cur_dma_stream); 643 read_reg(IVTV_REG_DMASTATUS), itv->cur_dma_stream);
644 write_reg(read_reg(IVTV_REG_DMASTATUS) & 3, IVTV_REG_DMASTATUS); 644 write_reg(read_reg(IVTV_REG_DMASTATUS) & 3, IVTV_REG_DMASTATUS);
@@ -669,7 +669,7 @@ static void ivtv_irq_enc_start_cap(struct ivtv *itv)
669 struct ivtv_stream *s; 669 struct ivtv_stream *s;
670 670
671 /* Get DMA destination and size arguments from card */ 671 /* Get DMA destination and size arguments from card */
672 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA, data); 672 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA, 7, data);
673 IVTV_DEBUG_HI_IRQ("ENC START CAP %d: %08x %08x\n", data[0], data[1], data[2]); 673 IVTV_DEBUG_HI_IRQ("ENC START CAP %d: %08x %08x\n", data[0], data[1], data[2]);
674 674
675 if (data[0] > 2 || data[1] == 0 || data[2] == 0) { 675 if (data[0] > 2 || data[1] == 0 || data[2] == 0) {
@@ -713,9 +713,9 @@ static void ivtv_irq_dec_data_req(struct ivtv *itv)
713 struct ivtv_stream *s; 713 struct ivtv_stream *s;
714 714
715 /* YUV or MPG */ 715 /* YUV or MPG */
716 ivtv_api_get_data(&itv->dec_mbox, IVTV_MBOX_DMA, data);
717 716
718 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)) { 717 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)) {
718 ivtv_api_get_data(&itv->dec_mbox, IVTV_MBOX_DMA, 2, data);
719 itv->dma_data_req_size = 719 itv->dma_data_req_size =
720 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31); 720 1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
721 itv->dma_data_req_offset = data[1]; 721 itv->dma_data_req_offset = data[1];
@@ -724,6 +724,7 @@ static void ivtv_irq_dec_data_req(struct ivtv *itv)
724 s = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV]; 724 s = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV];
725 } 725 }
726 else { 726 else {
727 ivtv_api_get_data(&itv->dec_mbox, IVTV_MBOX_DMA, 3, data);
727 itv->dma_data_req_size = min_t(u32, data[2], 0x10000); 728 itv->dma_data_req_size = min_t(u32, data[2], 0x10000);
728 itv->dma_data_req_offset = data[1]; 729 itv->dma_data_req_offset = data[1];
729 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG]; 730 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG];
@@ -940,9 +941,10 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
940 ivtv_dma_enc_start(s); 941 ivtv_dma_enc_start(s);
941 break; 942 break;
942 } 943 }
943 if (i == IVTV_MAX_STREAMS && test_and_clear_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags)) { 944
945 if (i == IVTV_MAX_STREAMS &&
946 test_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags))
944 ivtv_udma_start(itv); 947 ivtv_udma_start(itv);
945 }
946 } 948 }
947 949
948 if ((combo & IVTV_IRQ_DMA) && !test_bit(IVTV_F_I_PIO, &itv->i_flags)) { 950 if ((combo & IVTV_IRQ_DMA) && !test_bit(IVTV_F_I_PIO, &itv->i_flags)) {
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.c b/drivers/media/video/ivtv/ivtv-mailbox.c
index 1b5c0ac09a85..84577f6f41a2 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.c
+++ b/drivers/media/video/ivtv/ivtv-mailbox.c
@@ -369,10 +369,11 @@ int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...)
369} 369}
370 370
371/* This one is for stuff that can't sleep.. irq handlers, etc.. */ 371/* This one is for stuff that can't sleep.. irq handlers, etc.. */
372void ivtv_api_get_data(struct ivtv_mailbox_data *mbdata, int mb, u32 data[]) 372void ivtv_api_get_data(struct ivtv_mailbox_data *mbdata, int mb,
373 int argc, u32 data[])
373{ 374{
375 volatile u32 __iomem *p = mbdata->mbox[mb].data;
374 int i; 376 int i;
375 377 for (i = 0; i < argc; i++, p++)
376 for (i = 0; i < CX2341X_MBOX_MAX_DATA; i++) 378 data[i] = readl(p);
377 data[i] = readl(&mbdata->mbox[mb].data[i]);
378} 379}
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.h b/drivers/media/video/ivtv/ivtv-mailbox.h
index 6ef12091e3f3..8247662c928e 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.h
+++ b/drivers/media/video/ivtv/ivtv-mailbox.h
@@ -24,7 +24,8 @@
24#define IVTV_MBOX_DMA_END 8 24#define IVTV_MBOX_DMA_END 8
25#define IVTV_MBOX_DMA 9 25#define IVTV_MBOX_DMA 9
26 26
27void ivtv_api_get_data(struct ivtv_mailbox_data *mbox, int mb, u32 data[]); 27void ivtv_api_get_data(struct ivtv_mailbox_data *mbdata, int mb,
28 int argc, u32 data[]);
28int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[]); 29int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[]);
29int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...); 30int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...);
30int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...); 31int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...);
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index e12c6022373e..1f9387f6ca24 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -577,10 +577,14 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
577 clear_bit(IVTV_F_I_EOS, &itv->i_flags); 577 clear_bit(IVTV_F_I_EOS, &itv->i_flags);
578 578
579 /* Initialize Digitizer for Capture */ 579 /* Initialize Digitizer for Capture */
580 /* Avoid tinny audio problem - ensure audio clocks are going */
581 v4l2_subdev_call(itv->sd_audio, audio, s_stream, 1);
582 /* Avoid unpredictable PCI bus hang - disable video clocks */
580 v4l2_subdev_call(itv->sd_video, video, s_stream, 0); 583 v4l2_subdev_call(itv->sd_video, video, s_stream, 0);
581 ivtv_msleep_timeout(300, 1); 584 ivtv_msleep_timeout(150, 1);
582 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0); 585 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
583 v4l2_subdev_call(itv->sd_video, video, s_stream, 1); 586 v4l2_subdev_call(itv->sd_video, video, s_stream, 1);
587 ivtv_msleep_timeout(150, 1);
584 } 588 }
585 589
586 /* begin_capture */ 590 /* begin_capture */
diff --git a/drivers/media/video/ivtv/ivtv-udma.c b/drivers/media/video/ivtv/ivtv-udma.c
index d07ad6c39024..1daf1dd65bf7 100644
--- a/drivers/media/video/ivtv/ivtv-udma.c
+++ b/drivers/media/video/ivtv/ivtv-udma.c
@@ -213,6 +213,7 @@ void ivtv_udma_start(struct ivtv *itv)
213 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER); 213 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER);
214 set_bit(IVTV_F_I_DMA, &itv->i_flags); 214 set_bit(IVTV_F_I_DMA, &itv->i_flags);
215 set_bit(IVTV_F_I_UDMA, &itv->i_flags); 215 set_bit(IVTV_F_I_UDMA, &itv->i_flags);
216 clear_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags);
216} 217}
217 218
218void ivtv_udma_prepare(struct ivtv *itv) 219void ivtv_udma_prepare(struct ivtv *itv)
diff --git a/drivers/media/video/mt9t112.c b/drivers/media/video/mt9t112.c
index fc4dd6045720..7438f8d775ba 100644
--- a/drivers/media/video/mt9t112.c
+++ b/drivers/media/video/mt9t112.c
@@ -514,7 +514,7 @@ static int mt9t112_init_pll(const struct i2c_client *client)
514 /* poll to verify out of standby. Must Poll this bit */ 514 /* poll to verify out of standby. Must Poll this bit */
515 for (i = 0; i < 100; i++) { 515 for (i = 0; i < 100; i++) {
516 mt9t112_reg_read(data, client, 0x0018); 516 mt9t112_reg_read(data, client, 0x0018);
517 if (0x4000 & data) 517 if (!(0x4000 & data))
518 break; 518 break;
519 519
520 mdelay(10); 520 mdelay(10);
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index 91df7ec91fb6..1a34d2993e94 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -257,19 +257,18 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd,
257static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd) 257static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd)
258{ 258{
259 struct soc_camera_link *icl = to_soc_camera_link(icd); 259 struct soc_camera_link *icl = to_soc_camera_link(icd);
260 unsigned int width_flag; 260 unsigned int flags = SOCAM_MASTER | SOCAM_SLAVE |
261 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
262 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
263 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
264 SOCAM_DATA_ACTIVE_HIGH;
261 265
262 if (icl->query_bus_param) 266 if (icl->query_bus_param)
263 width_flag = icl->query_bus_param(icl) & 267 flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
264 SOCAM_DATAWIDTH_MASK;
265 else 268 else
266 width_flag = SOCAM_DATAWIDTH_10; 269 flags |= SOCAM_DATAWIDTH_10;
267 270
268 return SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | 271 return soc_camera_apply_sensor_flags(icl, flags);
269 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
270 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
271 SOCAM_DATA_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_SLAVE |
272 width_flag;
273} 272}
274 273
275static int mt9v022_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 274static int mt9v022_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index c1fc6dc776f5..9f01f14e4aa2 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -169,7 +169,11 @@ static struct saa7146_extension extension;
169static int mxb_probe(struct saa7146_dev *dev) 169static int mxb_probe(struct saa7146_dev *dev)
170{ 170{
171 struct mxb *mxb = NULL; 171 struct mxb *mxb = NULL;
172 int err;
172 173
174 err = saa7146_vv_devinit(dev);
175 if (err)
176 return err;
173 mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL); 177 mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
174 if (mxb == NULL) { 178 if (mxb == NULL) {
175 DEB_D(("not enough kernel memory.\n")); 179 DEB_D(("not enough kernel memory.\n"));
@@ -294,7 +298,7 @@ static int mxb_init_done(struct saa7146_dev* dev)
294 /* select tuner-output on saa7111a */ 298 /* select tuner-output on saa7111a */
295 i = 0; 299 i = 0;
296 saa7111a_call(mxb, video, s_routing, SAA7115_COMPOSITE0, 300 saa7111a_call(mxb, video, s_routing, SAA7115_COMPOSITE0,
297 SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS, 0); 301 SAA7111_FMT_CCIR, 0);
298 302
299 /* select a tuner type */ 303 /* select a tuner type */
300 tun_setup.mode_mask = T_ANALOG_TV; 304 tun_setup.mode_mask = T_ANALOG_TV;
@@ -518,8 +522,8 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
518 return err; 522 return err;
519 523
520 /* switch video in saa7111a */ 524 /* switch video in saa7111a */
521 if (saa7111a_call(mxb, video, s_routing, i, 0, 0)) 525 if (saa7111a_call(mxb, video, s_routing, i, SAA7111_FMT_CCIR, 0))
522 printk(KERN_ERR "VIDIOC_S_INPUT: could not address saa7111a #1.\n"); 526 printk(KERN_ERR "VIDIOC_S_INPUT: could not address saa7111a.\n");
523 527
524 /* switch the audio-source only if necessary */ 528 /* switch the audio-source only if necessary */
525 if (0 == mxb->cur_mute) 529 if (0 == mxb->cur_mute)
diff --git a/drivers/media/video/ov772x.c b/drivers/media/video/ov772x.c
index 3a45e945a528..7f8ece30c77b 100644
--- a/drivers/media/video/ov772x.c
+++ b/drivers/media/video/ov772x.c
@@ -547,7 +547,6 @@ static const struct v4l2_queryctrl ov772x_controls[] = {
547 }, 547 },
548}; 548};
549 549
550
551/* 550/*
552 * general function 551 * general function
553 */ 552 */
@@ -634,7 +633,12 @@ static unsigned long ov772x_query_bus_param(struct soc_camera_device *icd)
634 struct soc_camera_link *icl = to_soc_camera_link(icd); 633 struct soc_camera_link *icl = to_soc_camera_link(icd);
635 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER | 634 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
636 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH | 635 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
637 SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth; 636 SOCAM_DATA_ACTIVE_HIGH;
637
638 if (priv->info->flags & OV772X_FLAG_8BIT)
639 flags |= SOCAM_DATAWIDTH_8;
640 else
641 flags |= SOCAM_DATAWIDTH_10;
638 642
639 return soc_camera_apply_sensor_flags(icl, flags); 643 return soc_camera_apply_sensor_flags(icl, flags);
640} 644}
@@ -1040,15 +1044,6 @@ static int ov772x_video_probe(struct soc_camera_device *icd,
1040 return -ENODEV; 1044 return -ENODEV;
1041 1045
1042 /* 1046 /*
1043 * ov772x only use 8 or 10 bit bus width
1044 */
1045 if (SOCAM_DATAWIDTH_10 != priv->info->buswidth &&
1046 SOCAM_DATAWIDTH_8 != priv->info->buswidth) {
1047 dev_err(&client->dev, "bus width error\n");
1048 return -ENODEV;
1049 }
1050
1051 /*
1052 * check and show product ID and manufacturer ID 1047 * check and show product ID and manufacturer ID
1053 */ 1048 */
1054 pid = i2c_smbus_read_byte_data(client, PID); 1049 pid = i2c_smbus_read_byte_data(client, PID);
@@ -1130,7 +1125,6 @@ static int ov772x_probe(struct i2c_client *client,
1130 const struct i2c_device_id *did) 1125 const struct i2c_device_id *did)
1131{ 1126{
1132 struct ov772x_priv *priv; 1127 struct ov772x_priv *priv;
1133 struct ov772x_camera_info *info;
1134 struct soc_camera_device *icd = client->dev.platform_data; 1128 struct soc_camera_device *icd = client->dev.platform_data;
1135 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1129 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1136 struct soc_camera_link *icl; 1130 struct soc_camera_link *icl;
@@ -1145,8 +1139,6 @@ static int ov772x_probe(struct i2c_client *client,
1145 if (!icl || !icl->priv) 1139 if (!icl || !icl->priv)
1146 return -EINVAL; 1140 return -EINVAL;
1147 1141
1148 info = icl->priv;
1149
1150 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1142 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1151 dev_err(&adapter->dev, 1143 dev_err(&adapter->dev,
1152 "I2C-Adapter doesn't support " 1144 "I2C-Adapter doesn't support "
@@ -1158,7 +1150,7 @@ static int ov772x_probe(struct i2c_client *client,
1158 if (!priv) 1150 if (!priv)
1159 return -ENOMEM; 1151 return -ENOMEM;
1160 1152
1161 priv->info = info; 1153 priv->info = icl->priv;
1162 1154
1163 v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops); 1155 v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops);
1164 1156
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index de5485f506b1..cb4057bb07a0 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -233,8 +233,9 @@ struct pvr2_hdw {
233 int state_encoder_waitok; /* Encoder pre-wait done */ 233 int state_encoder_waitok; /* Encoder pre-wait done */
234 int state_encoder_runok; /* Encoder has run for >= .25 sec */ 234 int state_encoder_runok; /* Encoder has run for >= .25 sec */
235 int state_decoder_run; /* Decoder is running */ 235 int state_decoder_run; /* Decoder is running */
236 int state_decoder_ready; /* Decoder is stabilized & streamable */
236 int state_usbstream_run; /* FX2 is streaming */ 237 int state_usbstream_run; /* FX2 is streaming */
237 int state_decoder_quiescent; /* Decoder idle for > 50msec */ 238 int state_decoder_quiescent; /* Decoder idle for minimal interval */
238 int state_pipeline_config; /* Pipeline is configured */ 239 int state_pipeline_config; /* Pipeline is configured */
239 int state_pipeline_req; /* Somebody wants to stream */ 240 int state_pipeline_req; /* Somebody wants to stream */
240 int state_pipeline_pause; /* Pipeline must be paused */ 241 int state_pipeline_pause; /* Pipeline must be paused */
@@ -255,9 +256,16 @@ struct pvr2_hdw {
255 void (*state_func)(void *); 256 void (*state_func)(void *);
256 void *state_data; 257 void *state_data;
257 258
258 /* Timer for measuring decoder settling time */ 259 /* Timer for measuring required decoder settling time before we're
260 allowed to fire it up again. */
259 struct timer_list quiescent_timer; 261 struct timer_list quiescent_timer;
260 262
263 /* Timer for measuring decoder stabilization time, which is the
264 amount of time we need to let the decoder run before we can
265 trust its output (otherwise the encoder might see garbage and
266 then fail to start correctly). */
267 struct timer_list decoder_stabilization_timer;
268
261 /* Timer for measuring encoder pre-wait time */ 269 /* Timer for measuring encoder pre-wait time */
262 struct timer_list encoder_wait_timer; 270 struct timer_list encoder_wait_timer;
263 271
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 1bbdab08fe0e..712b300f723f 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -48,11 +48,13 @@
48 before we are allowed to start it running. */ 48 before we are allowed to start it running. */
49#define TIME_MSEC_DECODER_WAIT 50 49#define TIME_MSEC_DECODER_WAIT 50
50 50
51/* This defines a minimum interval that the decoder must be allowed to run
52 before we can safely begin using its streaming output. */
53#define TIME_MSEC_DECODER_STABILIZATION_WAIT 300
54
51/* This defines a minimum interval that the encoder must remain quiet 55/* This defines a minimum interval that the encoder must remain quiet
52 before we are allowed to configure it. I had this originally set to 56 before we are allowed to configure it. */
53 50msec, but Martin Dauskardt <martin.dauskardt@gmx.de> reports that 57#define TIME_MSEC_ENCODER_WAIT 50
54 things work better when it's set to 100msec. */
55#define TIME_MSEC_ENCODER_WAIT 100
56 58
57/* This defines the minimum interval that the encoder must successfully run 59/* This defines the minimum interval that the encoder must successfully run
58 before we consider that the encoder has run at least once since its 60 before we consider that the encoder has run at least once since its
@@ -334,6 +336,7 @@ static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw);
334static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw); 336static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw);
335static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw); 337static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw);
336static void pvr2_hdw_quiescent_timeout(unsigned long); 338static void pvr2_hdw_quiescent_timeout(unsigned long);
339static void pvr2_hdw_decoder_stabilization_timeout(unsigned long);
337static void pvr2_hdw_encoder_wait_timeout(unsigned long); 340static void pvr2_hdw_encoder_wait_timeout(unsigned long);
338static void pvr2_hdw_encoder_run_timeout(unsigned long); 341static void pvr2_hdw_encoder_run_timeout(unsigned long);
339static int pvr2_issue_simple_cmd(struct pvr2_hdw *,u32); 342static int pvr2_issue_simple_cmd(struct pvr2_hdw *,u32);
@@ -1705,6 +1708,7 @@ static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl)
1705 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 stream=%s", 1708 pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 stream=%s",
1706 (enablefl ? "on" : "off")); 1709 (enablefl ? "on" : "off"));
1707 v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_stream, enablefl); 1710 v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_stream, enablefl);
1711 v4l2_device_call_all(&hdw->v4l2_dev, 0, audio, s_stream, enablefl);
1708 if (hdw->decoder_client_id) { 1712 if (hdw->decoder_client_id) {
1709 /* We get here if the encoder has been noticed. Otherwise 1713 /* We get here if the encoder has been noticed. Otherwise
1710 we'll issue a warning to the user (which should 1714 we'll issue a warning to the user (which should
@@ -2461,6 +2465,11 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2461 hdw->quiescent_timer.data = (unsigned long)hdw; 2465 hdw->quiescent_timer.data = (unsigned long)hdw;
2462 hdw->quiescent_timer.function = pvr2_hdw_quiescent_timeout; 2466 hdw->quiescent_timer.function = pvr2_hdw_quiescent_timeout;
2463 2467
2468 init_timer(&hdw->decoder_stabilization_timer);
2469 hdw->decoder_stabilization_timer.data = (unsigned long)hdw;
2470 hdw->decoder_stabilization_timer.function =
2471 pvr2_hdw_decoder_stabilization_timeout;
2472
2464 init_timer(&hdw->encoder_wait_timer); 2473 init_timer(&hdw->encoder_wait_timer);
2465 hdw->encoder_wait_timer.data = (unsigned long)hdw; 2474 hdw->encoder_wait_timer.data = (unsigned long)hdw;
2466 hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout; 2475 hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout;
@@ -2674,6 +2683,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2674 fail: 2683 fail:
2675 if (hdw) { 2684 if (hdw) {
2676 del_timer_sync(&hdw->quiescent_timer); 2685 del_timer_sync(&hdw->quiescent_timer);
2686 del_timer_sync(&hdw->decoder_stabilization_timer);
2677 del_timer_sync(&hdw->encoder_run_timer); 2687 del_timer_sync(&hdw->encoder_run_timer);
2678 del_timer_sync(&hdw->encoder_wait_timer); 2688 del_timer_sync(&hdw->encoder_wait_timer);
2679 if (hdw->workqueue) { 2689 if (hdw->workqueue) {
@@ -2741,6 +2751,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2741 hdw->workqueue = NULL; 2751 hdw->workqueue = NULL;
2742 } 2752 }
2743 del_timer_sync(&hdw->quiescent_timer); 2753 del_timer_sync(&hdw->quiescent_timer);
2754 del_timer_sync(&hdw->decoder_stabilization_timer);
2744 del_timer_sync(&hdw->encoder_run_timer); 2755 del_timer_sync(&hdw->encoder_run_timer);
2745 del_timer_sync(&hdw->encoder_wait_timer); 2756 del_timer_sync(&hdw->encoder_wait_timer);
2746 if (hdw->fw_buffer) { 2757 if (hdw->fw_buffer) {
@@ -4452,7 +4463,7 @@ static int state_check_enable_encoder_run(struct pvr2_hdw *hdw)
4452 4463
4453 switch (hdw->pathway_state) { 4464 switch (hdw->pathway_state) {
4454 case PVR2_PATHWAY_ANALOG: 4465 case PVR2_PATHWAY_ANALOG:
4455 if (hdw->state_decoder_run) { 4466 if (hdw->state_decoder_run && hdw->state_decoder_ready) {
4456 /* In analog mode, if the decoder is running, then 4467 /* In analog mode, if the decoder is running, then
4457 run the encoder. */ 4468 run the encoder. */
4458 return !0; 4469 return !0;
@@ -4519,6 +4530,17 @@ static void pvr2_hdw_quiescent_timeout(unsigned long data)
4519} 4530}
4520 4531
4521 4532
4533/* Timeout function for decoder stabilization timer. */
4534static void pvr2_hdw_decoder_stabilization_timeout(unsigned long data)
4535{
4536 struct pvr2_hdw *hdw = (struct pvr2_hdw *)data;
4537 hdw->state_decoder_ready = !0;
4538 trace_stbit("state_decoder_ready", hdw->state_decoder_ready);
4539 hdw->state_stale = !0;
4540 queue_work(hdw->workqueue, &hdw->workpoll);
4541}
4542
4543
4522/* Timeout function for encoder wait timer. */ 4544/* Timeout function for encoder wait timer. */
4523static void pvr2_hdw_encoder_wait_timeout(unsigned long data) 4545static void pvr2_hdw_encoder_wait_timeout(unsigned long data)
4524{ 4546{
@@ -4557,8 +4579,13 @@ static int state_eval_decoder_run(struct pvr2_hdw *hdw)
4557 } 4579 }
4558 hdw->state_decoder_quiescent = 0; 4580 hdw->state_decoder_quiescent = 0;
4559 hdw->state_decoder_run = 0; 4581 hdw->state_decoder_run = 0;
4560 /* paranoia - solve race if timer just completed */ 4582 /* paranoia - solve race if timer(s) just completed */
4561 del_timer_sync(&hdw->quiescent_timer); 4583 del_timer_sync(&hdw->quiescent_timer);
4584 /* Kill the stabilization timer, in case we're killing the
4585 encoder before the previous stabilization interval has
4586 been properly timed. */
4587 del_timer_sync(&hdw->decoder_stabilization_timer);
4588 hdw->state_decoder_ready = 0;
4562 } else { 4589 } else {
4563 if (!hdw->state_decoder_quiescent) { 4590 if (!hdw->state_decoder_quiescent) {
4564 if (!timer_pending(&hdw->quiescent_timer)) { 4591 if (!timer_pending(&hdw->quiescent_timer)) {
@@ -4596,10 +4623,21 @@ static int state_eval_decoder_run(struct pvr2_hdw *hdw)
4596 if (hdw->flag_decoder_missed) return 0; 4623 if (hdw->flag_decoder_missed) return 0;
4597 if (pvr2_decoder_enable(hdw,!0) < 0) return 0; 4624 if (pvr2_decoder_enable(hdw,!0) < 0) return 0;
4598 hdw->state_decoder_quiescent = 0; 4625 hdw->state_decoder_quiescent = 0;
4626 hdw->state_decoder_ready = 0;
4599 hdw->state_decoder_run = !0; 4627 hdw->state_decoder_run = !0;
4628 if (hdw->decoder_client_id == PVR2_CLIENT_ID_SAA7115) {
4629 hdw->decoder_stabilization_timer.expires =
4630 jiffies +
4631 (HZ * TIME_MSEC_DECODER_STABILIZATION_WAIT /
4632 1000);
4633 add_timer(&hdw->decoder_stabilization_timer);
4634 } else {
4635 hdw->state_decoder_ready = !0;
4636 }
4600 } 4637 }
4601 trace_stbit("state_decoder_quiescent",hdw->state_decoder_quiescent); 4638 trace_stbit("state_decoder_quiescent",hdw->state_decoder_quiescent);
4602 trace_stbit("state_decoder_run",hdw->state_decoder_run); 4639 trace_stbit("state_decoder_run",hdw->state_decoder_run);
4640 trace_stbit("state_decoder_ready", hdw->state_decoder_ready);
4603 return !0; 4641 return !0;
4604} 4642}
4605 4643
@@ -4797,7 +4835,8 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
4797 buf,acnt, 4835 buf,acnt,
4798 "worker:%s%s%s%s%s%s%s", 4836 "worker:%s%s%s%s%s%s%s",
4799 (hdw->state_decoder_run ? 4837 (hdw->state_decoder_run ?
4800 " <decode:run>" : 4838 (hdw->state_decoder_ready ?
4839 "<decode:run>" : " <decode:start>") :
4801 (hdw->state_decoder_quiescent ? 4840 (hdw->state_decoder_quiescent ?
4802 "" : " <decode:stop>")), 4841 "" : " <decode:stop>")),
4803 (hdw->state_decoder_quiescent ? 4842 (hdw->state_decoder_quiescent ?
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.h b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
index 56e70eae20c1..51d3009ab57f 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
@@ -306,6 +306,7 @@ struct pvr2_hdw_debug_info {
306 int state_encoder_ok; 306 int state_encoder_ok;
307 int state_encoder_run; 307 int state_encoder_run;
308 int state_decoder_run; 308 int state_decoder_run;
309 int state_decoder_ready;
309 int state_usbstream_run; 310 int state_usbstream_run;
310 int state_decoder_quiescent; 311 int state_decoder_quiescent;
311 int state_pipeline_config; 312 int state_pipeline_config;
diff --git a/drivers/media/video/pwc/pwc-ctrl.c b/drivers/media/video/pwc/pwc-ctrl.c
index 50b415e07eda..f7f7e04cf485 100644
--- a/drivers/media/video/pwc/pwc-ctrl.c
+++ b/drivers/media/video/pwc/pwc-ctrl.c
@@ -753,7 +753,7 @@ int pwc_set_shutter_speed(struct pwc_device *pdev, int mode, int value)
753 buf[0] = 0xff; /* fixed */ 753 buf[0] = 0xff; /* fixed */
754 754
755 ret = send_control_msg(pdev, 755 ret = send_control_msg(pdev,
756 SET_LUM_CTL, SHUTTER_MODE_FORMATTER, &buf, sizeof(buf)); 756 SET_LUM_CTL, SHUTTER_MODE_FORMATTER, &buf, 1);
757 757
758 if (!mode && ret >= 0) { 758 if (!mode && ret >= 0) {
759 if (value < 0) 759 if (value < 0)
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index 294f860ce2b0..322ac4eecf0a 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -898,18 +898,8 @@ static void recalculate_fifo_timeout(struct pxa_camera_dev *pcdev,
898 898
899static void pxa_camera_activate(struct pxa_camera_dev *pcdev) 899static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
900{ 900{
901 struct pxacamera_platform_data *pdata = pcdev->pdata;
902 struct device *dev = pcdev->soc_host.v4l2_dev.dev;
903 u32 cicr4 = 0; 901 u32 cicr4 = 0;
904 902
905 dev_dbg(dev, "Registered platform device at %p data %p\n",
906 pcdev, pdata);
907
908 if (pdata && pdata->init) {
909 dev_dbg(dev, "%s: Init gpios\n", __func__);
910 pdata->init(dev);
911 }
912
913 /* disable all interrupts */ 903 /* disable all interrupts */
914 __raw_writel(0x3ff, pcdev->base + CICR0); 904 __raw_writel(0x3ff, pcdev->base + CICR0);
915 905
diff --git a/drivers/media/video/rj54n1cb0c.c b/drivers/media/video/rj54n1cb0c.c
index 805226e0d9c1..9277194cd821 100644
--- a/drivers/media/video/rj54n1cb0c.c
+++ b/drivers/media/video/rj54n1cb0c.c
@@ -165,7 +165,7 @@ struct rj54n1_reg_val {
165 u8 val; 165 u8 val;
166}; 166};
167 167
168const static struct rj54n1_reg_val bank_4[] = { 168static const struct rj54n1_reg_val bank_4[] = {
169 {0x417, 0}, 169 {0x417, 0},
170 {0x42c, 0}, 170 {0x42c, 0},
171 {0x42d, 0xf0}, 171 {0x42d, 0xf0},
@@ -186,7 +186,7 @@ const static struct rj54n1_reg_val bank_4[] = {
186 {0x4fe, 2}, 186 {0x4fe, 2},
187}; 187};
188 188
189const static struct rj54n1_reg_val bank_5[] = { 189static const struct rj54n1_reg_val bank_5[] = {
190 {0x514, 0}, 190 {0x514, 0},
191 {0x516, 0}, 191 {0x516, 0},
192 {0x518, 0}, 192 {0x518, 0},
@@ -207,7 +207,7 @@ const static struct rj54n1_reg_val bank_5[] = {
207 {0x5fe, 2}, 207 {0x5fe, 2},
208}; 208};
209 209
210const static struct rj54n1_reg_val bank_7[] = { 210static const struct rj54n1_reg_val bank_7[] = {
211 {0x70a, 0}, 211 {0x70a, 0},
212 {0x714, 0xff}, 212 {0x714, 0xff},
213 {0x715, 0xff}, 213 {0x715, 0xff},
@@ -215,7 +215,7 @@ const static struct rj54n1_reg_val bank_7[] = {
215 {0x7FE, 2}, 215 {0x7FE, 2},
216}; 216};
217 217
218const static struct rj54n1_reg_val bank_8[] = { 218static const struct rj54n1_reg_val bank_8[] = {
219 {0x800, 0x00}, 219 {0x800, 0x00},
220 {0x801, 0x01}, 220 {0x801, 0x01},
221 {0x802, 0x61}, 221 {0x802, 0x61},
@@ -403,12 +403,12 @@ const static struct rj54n1_reg_val bank_8[] = {
403 {0x8FE, 2}, 403 {0x8FE, 2},
404}; 404};
405 405
406const static struct rj54n1_reg_val bank_10[] = { 406static const struct rj54n1_reg_val bank_10[] = {
407 {0x10bf, 0x69} 407 {0x10bf, 0x69}
408}; 408};
409 409
410/* Clock dividers - these are default register values, divider = register + 1 */ 410/* Clock dividers - these are default register values, divider = register + 1 */
411const static struct rj54n1_clock_div clk_div = { 411static const struct rj54n1_clock_div clk_div = {
412 .ratio_tg = 3 /* default: 5 */, 412 .ratio_tg = 3 /* default: 5 */,
413 .ratio_t = 4 /* default: 1 */, 413 .ratio_t = 4 /* default: 1 */,
414 .ratio_r = 4 /* default: 0 */, 414 .ratio_r = 4 /* default: 0 */,
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index 44873a016c2c..c0a7f8a369f4 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -104,6 +104,10 @@ static int saa711x_has_reg(const int id, const u8 reg)
104 if (id == V4L2_IDENT_SAA7111) 104 if (id == V4L2_IDENT_SAA7111)
105 return reg < 0x20 && reg != 0x01 && reg != 0x0f && 105 return reg < 0x20 && reg != 0x01 && reg != 0x0f &&
106 (reg < 0x13 || reg > 0x19) && reg != 0x1d && reg != 0x1e; 106 (reg < 0x13 || reg > 0x19) && reg != 0x1d && reg != 0x1e;
107 if (id == V4L2_IDENT_SAA7111A)
108 return reg < 0x20 && reg != 0x01 && reg != 0x0f &&
109 reg != 0x14 && reg != 0x18 && reg != 0x19 &&
110 reg != 0x1d && reg != 0x1e;
107 111
108 /* common for saa7113/4/5/8 */ 112 /* common for saa7113/4/5/8 */
109 if (unlikely((reg >= 0x3b && reg <= 0x3f) || reg == 0x5c || reg == 0x5f || 113 if (unlikely((reg >= 0x3b && reg <= 0x3f) || reg == 0x5c || reg == 0x5f ||
@@ -954,8 +958,7 @@ static void saa711x_set_v4lstd(struct v4l2_subdev *sd, v4l2_std_id std)
954 011 NTSC N (3.58MHz) PAL M (3.58MHz) 958 011 NTSC N (3.58MHz) PAL M (3.58MHz)
955 100 reserved NTSC-Japan (3.58MHz) 959 100 reserved NTSC-Japan (3.58MHz)
956 */ 960 */
957 if (state->ident == V4L2_IDENT_SAA7111 || 961 if (state->ident <= V4L2_IDENT_SAA7113) {
958 state->ident == V4L2_IDENT_SAA7113) {
959 u8 reg = saa711x_read(sd, R_0E_CHROMA_CNTL_1) & 0x8f; 962 u8 reg = saa711x_read(sd, R_0E_CHROMA_CNTL_1) & 0x8f;
960 963
961 if (std == V4L2_STD_PAL_M) { 964 if (std == V4L2_STD_PAL_M) {
@@ -1232,22 +1235,19 @@ static int saa711x_s_routing(struct v4l2_subdev *sd,
1232 u32 input, u32 output, u32 config) 1235 u32 input, u32 output, u32 config)
1233{ 1236{
1234 struct saa711x_state *state = to_state(sd); 1237 struct saa711x_state *state = to_state(sd);
1235 u8 mask = (state->ident == V4L2_IDENT_SAA7111) ? 0xf8 : 0xf0; 1238 u8 mask = (state->ident <= V4L2_IDENT_SAA7111A) ? 0xf8 : 0xf0;
1236 1239
1237 v4l2_dbg(1, debug, sd, "decoder set input %d output %d\n", 1240 v4l2_dbg(1, debug, sd, "decoder set input %d output %d\n",
1238 input, output); 1241 input, output);
1239 1242
1240 /* saa7111/3 does not have these inputs */ 1243 /* saa7111/3 does not have these inputs */
1241 if ((state->ident == V4L2_IDENT_SAA7113 || 1244 if (state->ident <= V4L2_IDENT_SAA7113 &&
1242 state->ident == V4L2_IDENT_SAA7111) &&
1243 (input == SAA7115_COMPOSITE4 || 1245 (input == SAA7115_COMPOSITE4 ||
1244 input == SAA7115_COMPOSITE5)) { 1246 input == SAA7115_COMPOSITE5)) {
1245 return -EINVAL; 1247 return -EINVAL;
1246 } 1248 }
1247 if (input > SAA7115_SVIDEO3) 1249 if (input > SAA7115_SVIDEO3)
1248 return -EINVAL; 1250 return -EINVAL;
1249 if (output > SAA7115_IPORT_ON)
1250 return -EINVAL;
1251 if (state->input == input && state->output == output) 1251 if (state->input == input && state->output == output)
1252 return 0; 1252 return 0;
1253 v4l2_dbg(1, debug, sd, "now setting %s input %s output\n", 1253 v4l2_dbg(1, debug, sd, "now setting %s input %s output\n",
@@ -1256,7 +1256,7 @@ static int saa711x_s_routing(struct v4l2_subdev *sd,
1256 state->input = input; 1256 state->input = input;
1257 1257
1258 /* saa7111 has slightly different input numbering */ 1258 /* saa7111 has slightly different input numbering */
1259 if (state->ident == V4L2_IDENT_SAA7111) { 1259 if (state->ident <= V4L2_IDENT_SAA7111A) {
1260 if (input >= SAA7115_COMPOSITE4) 1260 if (input >= SAA7115_COMPOSITE4)
1261 input -= 2; 1261 input -= 2;
1262 /* saa7111 specific */ 1262 /* saa7111 specific */
@@ -1292,7 +1292,7 @@ static int saa711x_s_gpio(struct v4l2_subdev *sd, u32 val)
1292{ 1292{
1293 struct saa711x_state *state = to_state(sd); 1293 struct saa711x_state *state = to_state(sd);
1294 1294
1295 if (state->ident != V4L2_IDENT_SAA7111) 1295 if (state->ident > V4L2_IDENT_SAA7111A)
1296 return -EINVAL; 1296 return -EINVAL;
1297 saa711x_write(sd, 0x11, (saa711x_read(sd, 0x11) & 0x7f) | 1297 saa711x_write(sd, 0x11, (saa711x_read(sd, 0x11) & 0x7f) |
1298 (val ? 0x80 : 0)); 1298 (val ? 0x80 : 0));
@@ -1596,6 +1596,10 @@ static int saa711x_probe(struct i2c_client *client,
1596 switch (chip_id) { 1596 switch (chip_id) {
1597 case '1': 1597 case '1':
1598 state->ident = V4L2_IDENT_SAA7111; 1598 state->ident = V4L2_IDENT_SAA7111;
1599 if (saa711x_read(sd, R_00_CHIP_VERSION) & 0xf0) {
1600 v4l_info(client, "saa7111a variant found\n");
1601 state->ident = V4L2_IDENT_SAA7111A;
1602 }
1599 break; 1603 break;
1600 case '3': 1604 case '3':
1601 state->ident = V4L2_IDENT_SAA7113; 1605 state->ident = V4L2_IDENT_SAA7113;
@@ -1612,7 +1616,7 @@ static int saa711x_probe(struct i2c_client *client,
1612 default: 1616 default:
1613 state->ident = V4L2_IDENT_SAA7111; 1617 state->ident = V4L2_IDENT_SAA7111;
1614 v4l2_info(sd, "WARNING: Chip is not known - Falling back to saa7111\n"); 1618 v4l2_info(sd, "WARNING: Chip is not known - Falling back to saa7111\n");
1615 1619 break;
1616 } 1620 }
1617 1621
1618 state->audclk_freq = 48000; 1622 state->audclk_freq = 48000;
@@ -1623,6 +1627,7 @@ static int saa711x_probe(struct i2c_client *client,
1623 state->crystal_freq = SAA7115_FREQ_24_576_MHZ; 1627 state->crystal_freq = SAA7115_FREQ_24_576_MHZ;
1624 switch (state->ident) { 1628 switch (state->ident) {
1625 case V4L2_IDENT_SAA7111: 1629 case V4L2_IDENT_SAA7111:
1630 case V4L2_IDENT_SAA7111A:
1626 saa711x_writeregs(sd, saa7111_init); 1631 saa711x_writeregs(sd, saa7111_init);
1627 break; 1632 break;
1628 case V4L2_IDENT_SAA7113: 1633 case V4L2_IDENT_SAA7113:
@@ -1632,7 +1637,7 @@ static int saa711x_probe(struct i2c_client *client,
1632 state->crystal_freq = SAA7115_FREQ_32_11_MHZ; 1637 state->crystal_freq = SAA7115_FREQ_32_11_MHZ;
1633 saa711x_writeregs(sd, saa7115_init_auto_input); 1638 saa711x_writeregs(sd, saa7115_init_auto_input);
1634 } 1639 }
1635 if (state->ident != V4L2_IDENT_SAA7111) 1640 if (state->ident > V4L2_IDENT_SAA7111A)
1636 saa711x_writeregs(sd, saa7115_init_misc); 1641 saa711x_writeregs(sd, saa7115_init_misc);
1637 saa711x_set_v4lstd(sd, V4L2_STD_NTSC); 1642 saa711x_set_v4lstd(sd, V4L2_STD_NTSC);
1638 1643
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index 2fe7a701b954..250ef84cf5ca 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -181,7 +181,7 @@ static const struct i2c_reg_value saa7127_init_config_common[] = {
181#define SAA7127_60HZ_DAC_CONTROL 0x15 181#define SAA7127_60HZ_DAC_CONTROL 0x15
182static const struct i2c_reg_value saa7127_init_config_60hz[] = { 182static const struct i2c_reg_value saa7127_init_config_60hz[] = {
183 { SAA7127_REG_BURST_START, 0x19 }, 183 { SAA7127_REG_BURST_START, 0x19 },
184 /* BURST_END is also used as a chip ID in saa7127_detect_client */ 184 /* BURST_END is also used as a chip ID in saa7127_probe */
185 { SAA7127_REG_BURST_END, 0x1d }, 185 { SAA7127_REG_BURST_END, 0x1d },
186 { SAA7127_REG_CHROMA_PHASE, 0xa3 }, 186 { SAA7127_REG_CHROMA_PHASE, 0xa3 },
187 { SAA7127_REG_GAINU, 0x98 }, 187 { SAA7127_REG_GAINU, 0x98 },
@@ -200,10 +200,10 @@ static const struct i2c_reg_value saa7127_init_config_60hz[] = {
200 { 0, 0 } 200 { 0, 0 }
201}; 201};
202 202
203#define SAA7127_50HZ_DAC_CONTROL 0x02 203#define SAA7127_50HZ_PAL_DAC_CONTROL 0x02
204static struct i2c_reg_value saa7127_init_config_50hz[] = { 204static struct i2c_reg_value saa7127_init_config_50hz_pal[] = {
205 { SAA7127_REG_BURST_START, 0x21 }, 205 { SAA7127_REG_BURST_START, 0x21 },
206 /* BURST_END is also used as a chip ID in saa7127_detect_client */ 206 /* BURST_END is also used as a chip ID in saa7127_probe */
207 { SAA7127_REG_BURST_END, 0x1d }, 207 { SAA7127_REG_BURST_END, 0x1d },
208 { SAA7127_REG_CHROMA_PHASE, 0x3f }, 208 { SAA7127_REG_CHROMA_PHASE, 0x3f },
209 { SAA7127_REG_GAINU, 0x7d }, 209 { SAA7127_REG_GAINU, 0x7d },
@@ -222,6 +222,28 @@ static struct i2c_reg_value saa7127_init_config_50hz[] = {
222 { 0, 0 } 222 { 0, 0 }
223}; 223};
224 224
225#define SAA7127_50HZ_SECAM_DAC_CONTROL 0x08
226static struct i2c_reg_value saa7127_init_config_50hz_secam[] = {
227 { SAA7127_REG_BURST_START, 0x21 },
228 /* BURST_END is also used as a chip ID in saa7127_probe */
229 { SAA7127_REG_BURST_END, 0x1d },
230 { SAA7127_REG_CHROMA_PHASE, 0x3f },
231 { SAA7127_REG_GAINU, 0x6a },
232 { SAA7127_REG_GAINV, 0x81 },
233 { SAA7127_REG_BLACK_LEVEL, 0x33 },
234 { SAA7127_REG_BLANKING_LEVEL, 0x35 },
235 { SAA7127_REG_VBI_BLANKING, 0x35 },
236 { SAA7127_REG_DAC_CONTROL, 0x08 },
237 { SAA7127_REG_BURST_AMP, 0x2f },
238 { SAA7127_REG_SUBC3, 0xb2 },
239 { SAA7127_REG_SUBC2, 0x3b },
240 { SAA7127_REG_SUBC1, 0xa3 },
241 { SAA7127_REG_SUBC0, 0x28 },
242 { SAA7127_REG_MULTI, 0x90 },
243 { SAA7127_REG_CLOSED_CAPTION, 0x00 },
244 { 0, 0 }
245};
246
225/* 247/*
226 ********************************************************************** 248 **********************************************************************
227 * 249 *
@@ -463,10 +485,21 @@ static int saa7127_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
463 v4l2_dbg(1, debug, sd, "Selecting 60 Hz video Standard\n"); 485 v4l2_dbg(1, debug, sd, "Selecting 60 Hz video Standard\n");
464 inittab = saa7127_init_config_60hz; 486 inittab = saa7127_init_config_60hz;
465 state->reg_61 = SAA7127_60HZ_DAC_CONTROL; 487 state->reg_61 = SAA7127_60HZ_DAC_CONTROL;
488
489 } else if (state->ident == V4L2_IDENT_SAA7129 &&
490 (std & V4L2_STD_SECAM) &&
491 !(std & (V4L2_STD_625_50 & ~V4L2_STD_SECAM))) {
492
493 /* If and only if SECAM, with a SAA712[89] */
494 v4l2_dbg(1, debug, sd,
495 "Selecting 50 Hz SECAM video Standard\n");
496 inittab = saa7127_init_config_50hz_secam;
497 state->reg_61 = SAA7127_50HZ_SECAM_DAC_CONTROL;
498
466 } else { 499 } else {
467 v4l2_dbg(1, debug, sd, "Selecting 50 Hz video Standard\n"); 500 v4l2_dbg(1, debug, sd, "Selecting 50 Hz PAL video Standard\n");
468 inittab = saa7127_init_config_50hz; 501 inittab = saa7127_init_config_50hz_pal;
469 state->reg_61 = SAA7127_50HZ_DAC_CONTROL; 502 state->reg_61 = SAA7127_50HZ_PAL_DAC_CONTROL;
470 } 503 }
471 504
472 /* Write Table */ 505 /* Write Table */
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 03f572708b85..297833fb3b4a 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -4160,7 +4160,7 @@ struct saa7134_board saa7134_boards[] = {
4160 .amux = LINE2, 4160 .amux = LINE2,
4161 }, 4161 },
4162 }, 4162 },
4163 [SAA7134_BOARD_BEHOLD_505RDS] = { 4163 [SAA7134_BOARD_BEHOLD_505RDS_MK5] = {
4164 /* Beholder Intl. Ltd. 2008 */ 4164 /* Beholder Intl. Ltd. 2008 */
4165 /*Dmitry Belimov <d.belimov@gmail.com> */ 4165 /*Dmitry Belimov <d.belimov@gmail.com> */
4166 .name = "Beholder BeholdTV 505 RDS", 4166 .name = "Beholder BeholdTV 505 RDS",
@@ -5320,6 +5320,41 @@ struct saa7134_board saa7134_boards[] = {
5320 .vmux = 8, 5320 .vmux = 8,
5321 } }, 5321 } },
5322 }, 5322 },
5323 [SAA7134_BOARD_BEHOLD_505RDS_MK3] = {
5324 /* Beholder Intl. Ltd. 2008 */
5325 /*Dmitry Belimov <d.belimov@gmail.com> */
5326 .name = "Beholder BeholdTV 505 RDS",
5327 .audio_clock = 0x00200000,
5328 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
5329 .radio_type = UNSET,
5330 .tuner_addr = ADDR_UNSET,
5331 .radio_addr = ADDR_UNSET,
5332 .rds_addr = 0x10,
5333 .tda9887_conf = TDA9887_PRESENT,
5334 .gpiomask = 0x00008000,
5335 .inputs = {{
5336 .name = name_tv,
5337 .vmux = 3,
5338 .amux = LINE2,
5339 .tv = 1,
5340 }, {
5341 .name = name_comp1,
5342 .vmux = 1,
5343 .amux = LINE1,
5344 }, {
5345 .name = name_svideo,
5346 .vmux = 8,
5347 .amux = LINE1,
5348 } },
5349 .mute = {
5350 .name = name_mute,
5351 .amux = LINE1,
5352 },
5353 .radio = {
5354 .name = name_radio,
5355 .amux = LINE2,
5356 },
5357 },
5323 5358
5324}; 5359};
5325 5360
@@ -6235,7 +6270,13 @@ struct pci_device_id saa7134_pci_tbl[] = {
6235 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 6270 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
6236 .subvendor = 0x0000, 6271 .subvendor = 0x0000,
6237 .subdevice = 0x505B, 6272 .subdevice = 0x505B,
6238 .driver_data = SAA7134_BOARD_BEHOLD_505RDS, 6273 .driver_data = SAA7134_BOARD_BEHOLD_505RDS_MK5,
6274 }, {
6275 .vendor = PCI_VENDOR_ID_PHILIPS,
6276 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
6277 .subvendor = 0x0000,
6278 .subdevice = 0x5051,
6279 .driver_data = SAA7134_BOARD_BEHOLD_505RDS_MK3,
6239 },{ 6280 },{
6240 .vendor = PCI_VENDOR_ID_PHILIPS, 6281 .vendor = PCI_VENDOR_ID_PHILIPS,
6241 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 6282 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
@@ -6792,7 +6833,8 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6792 case SAA7134_BOARD_BEHOLD_407FM: 6833 case SAA7134_BOARD_BEHOLD_407FM:
6793 case SAA7134_BOARD_BEHOLD_409: 6834 case SAA7134_BOARD_BEHOLD_409:
6794 case SAA7134_BOARD_BEHOLD_505FM: 6835 case SAA7134_BOARD_BEHOLD_505FM:
6795 case SAA7134_BOARD_BEHOLD_505RDS: 6836 case SAA7134_BOARD_BEHOLD_505RDS_MK5:
6837 case SAA7134_BOARD_BEHOLD_505RDS_MK3:
6796 case SAA7134_BOARD_BEHOLD_507_9FM: 6838 case SAA7134_BOARD_BEHOLD_507_9FM:
6797 case SAA7134_BOARD_BEHOLD_507RDS_MK3: 6839 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
6798 case SAA7134_BOARD_BEHOLD_507RDS_MK5: 6840 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
@@ -6953,8 +6995,8 @@ int saa7134_board_init1(struct saa7134_dev *dev)
6953 break; 6995 break;
6954 case SAA7134_BOARD_VIDEOMATE_S350: 6996 case SAA7134_BOARD_VIDEOMATE_S350:
6955 dev->has_remote = SAA7134_REMOTE_GPIO; 6997 dev->has_remote = SAA7134_REMOTE_GPIO;
6956 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x00008000, 0x00008000); 6998 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x0000C000, 0x0000C000);
6957 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x00008000, 0x00008000); 6999 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0000C000, 0x0000C000);
6958 break; 7000 break;
6959 } 7001 }
6960 return 0; 7002 return 0;
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index f8e985989ca0..9499000f66b6 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -460,7 +460,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
460 int polling = 0; 460 int polling = 0;
461 int rc5_gpio = 0; 461 int rc5_gpio = 0;
462 int nec_gpio = 0; 462 int nec_gpio = 0;
463 int ir_type = IR_TYPE_OTHER; 463 u64 ir_type = IR_TYPE_OTHER;
464 int err; 464 int err;
465 465
466 if (dev->has_remote != SAA7134_REMOTE_GPIO) 466 if (dev->has_remote != SAA7134_REMOTE_GPIO)
@@ -568,7 +568,8 @@ int saa7134_input_init1(struct saa7134_dev *dev)
568 case SAA7134_BOARD_BEHOLD_407FM: 568 case SAA7134_BOARD_BEHOLD_407FM:
569 case SAA7134_BOARD_BEHOLD_409: 569 case SAA7134_BOARD_BEHOLD_409:
570 case SAA7134_BOARD_BEHOLD_505FM: 570 case SAA7134_BOARD_BEHOLD_505FM:
571 case SAA7134_BOARD_BEHOLD_505RDS: 571 case SAA7134_BOARD_BEHOLD_505RDS_MK5:
572 case SAA7134_BOARD_BEHOLD_505RDS_MK3:
572 case SAA7134_BOARD_BEHOLD_507_9FM: 573 case SAA7134_BOARD_BEHOLD_507_9FM:
573 case SAA7134_BOARD_BEHOLD_507RDS_MK3: 574 case SAA7134_BOARD_BEHOLD_507RDS_MK3:
574 case SAA7134_BOARD_BEHOLD_507RDS_MK5: 575 case SAA7134_BOARD_BEHOLD_507RDS_MK5:
@@ -728,7 +729,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
728 dev->remote = ir; 729 dev->remote = ir;
729 saa7134_ir_start(dev, ir); 730 saa7134_ir_start(dev, ir);
730 731
731 err = ir_input_register(ir->dev, ir_codes); 732 err = ir_input_register(ir->dev, ir_codes, NULL);
732 if (err) 733 if (err)
733 goto err_out_stop; 734 goto err_out_stop;
734 735
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index cb732640ac4a..31138d3e51bb 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -205,7 +205,7 @@ static struct saa7134_format formats[] = {
205 205
206#define NORM_525_60 \ 206#define NORM_525_60 \
207 .h_start = 0, \ 207 .h_start = 0, \
208 .h_stop = 703, \ 208 .h_stop = 719, \
209 .video_v_start = 23, \ 209 .video_v_start = 23, \
210 .video_v_stop = 262, \ 210 .video_v_stop = 262, \
211 .vbi_v_start_0 = 10, \ 211 .vbi_v_start_0 = 10, \
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 53b7e0b8a2fb..bf130967ed17 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -282,7 +282,7 @@ struct saa7134_format {
282#define SAA7134_BOARD_HAUPPAUGE_HVR1120 156 282#define SAA7134_BOARD_HAUPPAUGE_HVR1120 156
283#define SAA7134_BOARD_AVERMEDIA_STUDIO_507UA 157 283#define SAA7134_BOARD_AVERMEDIA_STUDIO_507UA 157
284#define SAA7134_BOARD_AVERMEDIA_CARDBUS_501 158 284#define SAA7134_BOARD_AVERMEDIA_CARDBUS_501 158
285#define SAA7134_BOARD_BEHOLD_505RDS 159 285#define SAA7134_BOARD_BEHOLD_505RDS_MK5 159
286#define SAA7134_BOARD_BEHOLD_507RDS_MK3 160 286#define SAA7134_BOARD_BEHOLD_507RDS_MK3 160
287#define SAA7134_BOARD_BEHOLD_507RDS_MK5 161 287#define SAA7134_BOARD_BEHOLD_507RDS_MK5 161
288#define SAA7134_BOARD_BEHOLD_607FM_MK5 162 288#define SAA7134_BOARD_BEHOLD_607FM_MK5 162
@@ -299,6 +299,7 @@ struct saa7134_format {
299#define SAA7134_BOARD_ZOLID_HYBRID_PCI 173 299#define SAA7134_BOARD_ZOLID_HYBRID_PCI 173
300#define SAA7134_BOARD_ASUS_EUROPA_HYBRID 174 300#define SAA7134_BOARD_ASUS_EUROPA_HYBRID 174
301#define SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S 175 301#define SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S 175
302#define SAA7134_BOARD_BEHOLD_505RDS_MK3 176
302 303
303#define SAA7134_MAXBOARDS 32 304#define SAA7134_MAXBOARDS 32
304#define SAA7134_INPUT_MAX 8 305#define SAA7134_INPUT_MAX 8
diff --git a/drivers/media/video/saa7164/saa7164-api.c b/drivers/media/video/saa7164/saa7164-api.c
index 6f094a96ac81..1d487c150340 100644
--- a/drivers/media/video/saa7164/saa7164-api.c
+++ b/drivers/media/video/saa7164/saa7164-api.c
@@ -523,7 +523,7 @@ int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, u32 datalen,
523 } 523 }
524 524
525 reglen = saa7164_i2caddr_to_reglen(bus, addr); 525 reglen = saa7164_i2caddr_to_reglen(bus, addr);
526 if (unitid < 0) { 526 if (reglen < 0) {
527 printk(KERN_ERR 527 printk(KERN_ERR
528 "%s() error, cannot translate regaddr to reglen\n", 528 "%s() error, cannot translate regaddr to reglen\n",
529 __func__); 529 __func__);
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index f09c7140d6b2..fb88c63188f3 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -1748,6 +1748,22 @@ static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q,
1748 icd); 1748 icd);
1749} 1749}
1750 1750
1751static int sh_mobile_ceu_get_parm(struct soc_camera_device *icd,
1752 struct v4l2_streamparm *parm)
1753{
1754 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1755
1756 return v4l2_subdev_call(sd, video, g_parm, parm);
1757}
1758
1759static int sh_mobile_ceu_set_parm(struct soc_camera_device *icd,
1760 struct v4l2_streamparm *parm)
1761{
1762 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1763
1764 return v4l2_subdev_call(sd, video, s_parm, parm);
1765}
1766
1751static int sh_mobile_ceu_get_ctrl(struct soc_camera_device *icd, 1767static int sh_mobile_ceu_get_ctrl(struct soc_camera_device *icd,
1752 struct v4l2_control *ctrl) 1768 struct v4l2_control *ctrl)
1753{ 1769{
@@ -1808,6 +1824,8 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
1808 .try_fmt = sh_mobile_ceu_try_fmt, 1824 .try_fmt = sh_mobile_ceu_try_fmt,
1809 .set_ctrl = sh_mobile_ceu_set_ctrl, 1825 .set_ctrl = sh_mobile_ceu_set_ctrl,
1810 .get_ctrl = sh_mobile_ceu_get_ctrl, 1826 .get_ctrl = sh_mobile_ceu_get_ctrl,
1827 .set_parm = sh_mobile_ceu_set_parm,
1828 .get_parm = sh_mobile_ceu_get_parm,
1811 .reqbufs = sh_mobile_ceu_reqbufs, 1829 .reqbufs = sh_mobile_ceu_reqbufs,
1812 .poll = sh_mobile_ceu_poll, 1830 .poll = sh_mobile_ceu_poll,
1813 .querycap = sh_mobile_ceu_querycap, 1831 .querycap = sh_mobile_ceu_querycap,
diff --git a/drivers/media/video/sn9c102/Kconfig b/drivers/media/video/sn9c102/Kconfig
index f71f272776de..6ebaf2940d06 100644
--- a/drivers/media/video/sn9c102/Kconfig
+++ b/drivers/media/video/sn9c102/Kconfig
@@ -1,7 +1,10 @@
1config USB_SN9C102 1config USB_SN9C102
2 tristate "USB SN9C1xx PC Camera Controller support" 2 tristate "USB SN9C1xx PC Camera Controller support (DEPRECATED)"
3 depends on VIDEO_V4L2 3 depends on VIDEO_V4L2
4 ---help--- 4 ---help---
5 This driver is DEPRECATED please use the gspca sonixb and
6 sonixj modules instead.
7
5 Say Y here if you want support for cameras based on SONiX SN9C101, 8 Say Y here if you want support for cameras based on SONiX SN9C101,
6 SN9C102, SN9C103, SN9C105 and SN9C120 PC Camera Controllers. 9 SN9C102, SN9C103, SN9C105 and SN9C120 PC Camera Controllers.
7 10
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
index 36ee43a9ee95..cc40d6ba9f22 100644
--- a/drivers/media/video/sn9c102/sn9c102_devtable.h
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -45,20 +45,24 @@ static const struct usb_device_id sn9c102_id_table[] = {
45 { SN9C102_USB_DEVICE(0x0c45, 0x6005, BRIDGE_SN9C102), }, 45 { SN9C102_USB_DEVICE(0x0c45, 0x6005, BRIDGE_SN9C102), },
46#endif 46#endif
47 { SN9C102_USB_DEVICE(0x0c45, 0x6007, BRIDGE_SN9C102), }, 47 { SN9C102_USB_DEVICE(0x0c45, 0x6007, BRIDGE_SN9C102), },
48#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
48 { SN9C102_USB_DEVICE(0x0c45, 0x6009, BRIDGE_SN9C102), }, 49 { SN9C102_USB_DEVICE(0x0c45, 0x6009, BRIDGE_SN9C102), },
49 { SN9C102_USB_DEVICE(0x0c45, 0x600d, BRIDGE_SN9C102), }, 50 { SN9C102_USB_DEVICE(0x0c45, 0x600d, BRIDGE_SN9C102), },
50/* { SN9C102_USB_DEVICE(0x0c45, 0x6011, BRIDGE_SN9C102), }, OV6650 */ 51/* { SN9C102_USB_DEVICE(0x0c45, 0x6011, BRIDGE_SN9C102), }, OV6650 */
52#endif
51 { SN9C102_USB_DEVICE(0x0c45, 0x6019, BRIDGE_SN9C102), }, 53 { SN9C102_USB_DEVICE(0x0c45, 0x6019, BRIDGE_SN9C102), },
52 { SN9C102_USB_DEVICE(0x0c45, 0x6024, BRIDGE_SN9C102), }, 54 { SN9C102_USB_DEVICE(0x0c45, 0x6024, BRIDGE_SN9C102), },
53 { SN9C102_USB_DEVICE(0x0c45, 0x6025, BRIDGE_SN9C102), }, 55 { SN9C102_USB_DEVICE(0x0c45, 0x6025, BRIDGE_SN9C102), },
56#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
54 { SN9C102_USB_DEVICE(0x0c45, 0x6028, BRIDGE_SN9C102), }, 57 { SN9C102_USB_DEVICE(0x0c45, 0x6028, BRIDGE_SN9C102), },
55 { SN9C102_USB_DEVICE(0x0c45, 0x6029, BRIDGE_SN9C102), }, 58 { SN9C102_USB_DEVICE(0x0c45, 0x6029, BRIDGE_SN9C102), },
59#endif
56 { SN9C102_USB_DEVICE(0x0c45, 0x602a, BRIDGE_SN9C102), }, 60 { SN9C102_USB_DEVICE(0x0c45, 0x602a, BRIDGE_SN9C102), },
57 { SN9C102_USB_DEVICE(0x0c45, 0x602b, BRIDGE_SN9C102), }, 61 { SN9C102_USB_DEVICE(0x0c45, 0x602b, BRIDGE_SN9C102), },
58#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE 62#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
59 { SN9C102_USB_DEVICE(0x0c45, 0x602c, BRIDGE_SN9C102), }, 63 { SN9C102_USB_DEVICE(0x0c45, 0x602c, BRIDGE_SN9C102), },
60#endif
61/* { SN9C102_USB_DEVICE(0x0c45, 0x602d, BRIDGE_SN9C102), }, HV7131R */ 64/* { SN9C102_USB_DEVICE(0x0c45, 0x602d, BRIDGE_SN9C102), }, HV7131R */
65#endif
62 { SN9C102_USB_DEVICE(0x0c45, 0x602e, BRIDGE_SN9C102), }, 66 { SN9C102_USB_DEVICE(0x0c45, 0x602e, BRIDGE_SN9C102), },
63 { SN9C102_USB_DEVICE(0x0c45, 0x6030, BRIDGE_SN9C102), }, 67 { SN9C102_USB_DEVICE(0x0c45, 0x6030, BRIDGE_SN9C102), },
64 /* SN9C103 */ 68 /* SN9C103 */
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 6b3fbcca7747..80f6bfa2632b 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -781,6 +781,32 @@ static int soc_camera_s_crop(struct file *file, void *fh,
781 return ret; 781 return ret;
782} 782}
783 783
784static int soc_camera_g_parm(struct file *file, void *fh,
785 struct v4l2_streamparm *a)
786{
787 struct soc_camera_file *icf = file->private_data;
788 struct soc_camera_device *icd = icf->icd;
789 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
790
791 if (ici->ops->get_parm)
792 return ici->ops->get_parm(icd, a);
793
794 return -ENOIOCTLCMD;
795}
796
797static int soc_camera_s_parm(struct file *file, void *fh,
798 struct v4l2_streamparm *a)
799{
800 struct soc_camera_file *icf = file->private_data;
801 struct soc_camera_device *icd = icf->icd;
802 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
803
804 if (ici->ops->set_parm)
805 return ici->ops->set_parm(icd, a);
806
807 return -ENOIOCTLCMD;
808}
809
784static int soc_camera_g_chip_ident(struct file *file, void *fh, 810static int soc_camera_g_chip_ident(struct file *file, void *fh,
785 struct v4l2_dbg_chip_ident *id) 811 struct v4l2_dbg_chip_ident *id)
786{ 812{
@@ -846,10 +872,8 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
846 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 872 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
847 struct i2c_adapter *adap = i2c_get_adapter(icl->i2c_adapter_id); 873 struct i2c_adapter *adap = i2c_get_adapter(icl->i2c_adapter_id);
848 struct v4l2_subdev *subdev; 874 struct v4l2_subdev *subdev;
849 int ret;
850 875
851 if (!adap) { 876 if (!adap) {
852 ret = -ENODEV;
853 dev_err(&icd->dev, "Cannot get I2C adapter #%d. No driver?\n", 877 dev_err(&icd->dev, "Cannot get I2C adapter #%d. No driver?\n",
854 icl->i2c_adapter_id); 878 icl->i2c_adapter_id);
855 goto ei2cga; 879 goto ei2cga;
@@ -859,10 +883,8 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
859 883
860 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap, 884 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap,
861 icl->module_name, icl->board_info, NULL); 885 icl->module_name, icl->board_info, NULL);
862 if (!subdev) { 886 if (!subdev)
863 ret = -ENOMEM;
864 goto ei2cnd; 887 goto ei2cnd;
865 }
866 888
867 client = subdev->priv; 889 client = subdev->priv;
868 890
@@ -873,7 +895,7 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
873ei2cnd: 895ei2cnd:
874 i2c_put_adapter(adap); 896 i2c_put_adapter(adap);
875ei2cga: 897ei2cga:
876 return ret; 898 return -ENODEV;
877} 899}
878 900
879static void soc_camera_free_i2c(struct soc_camera_device *icd) 901static void soc_camera_free_i2c(struct soc_camera_device *icd)
@@ -1260,6 +1282,8 @@ static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
1260 .vidioc_cropcap = soc_camera_cropcap, 1282 .vidioc_cropcap = soc_camera_cropcap,
1261 .vidioc_g_crop = soc_camera_g_crop, 1283 .vidioc_g_crop = soc_camera_g_crop,
1262 .vidioc_s_crop = soc_camera_s_crop, 1284 .vidioc_s_crop = soc_camera_s_crop,
1285 .vidioc_g_parm = soc_camera_g_parm,
1286 .vidioc_s_parm = soc_camera_s_parm,
1263 .vidioc_g_chip_ident = soc_camera_g_chip_ident, 1287 .vidioc_g_chip_ident = soc_camera_g_chip_ident,
1264#ifdef CONFIG_VIDEO_ADV_DEBUG 1288#ifdef CONFIG_VIDEO_ADV_DEBUG
1265 .vidioc_g_register = soc_camera_g_register, 1289 .vidioc_g_register = soc_camera_g_register,
diff --git a/drivers/media/video/soc_mediabus.c b/drivers/media/video/soc_mediabus.c
index f8d5c87dc2aa..8b63b6545e76 100644
--- a/drivers/media/video/soc_mediabus.c
+++ b/drivers/media/video/soc_mediabus.c
@@ -24,91 +24,106 @@ static const struct soc_mbus_pixelfmt mbus_fmt[] = {
24 .bits_per_sample = 8, 24 .bits_per_sample = 8,
25 .packing = SOC_MBUS_PACKING_2X8_PADHI, 25 .packing = SOC_MBUS_PACKING_2X8_PADHI,
26 .order = SOC_MBUS_ORDER_LE, 26 .order = SOC_MBUS_ORDER_LE,
27 }, [MBUS_IDX(YVYU8_2X8_LE)] = { 27 },
28 [MBUS_IDX(YVYU8_2X8_LE)] = {
28 .fourcc = V4L2_PIX_FMT_YVYU, 29 .fourcc = V4L2_PIX_FMT_YVYU,
29 .name = "YVYU", 30 .name = "YVYU",
30 .bits_per_sample = 8, 31 .bits_per_sample = 8,
31 .packing = SOC_MBUS_PACKING_2X8_PADHI, 32 .packing = SOC_MBUS_PACKING_2X8_PADHI,
32 .order = SOC_MBUS_ORDER_LE, 33 .order = SOC_MBUS_ORDER_LE,
33 }, [MBUS_IDX(YUYV8_2X8_BE)] = { 34 },
35 [MBUS_IDX(YUYV8_2X8_BE)] = {
34 .fourcc = V4L2_PIX_FMT_UYVY, 36 .fourcc = V4L2_PIX_FMT_UYVY,
35 .name = "UYVY", 37 .name = "UYVY",
36 .bits_per_sample = 8, 38 .bits_per_sample = 8,
37 .packing = SOC_MBUS_PACKING_2X8_PADHI, 39 .packing = SOC_MBUS_PACKING_2X8_PADHI,
38 .order = SOC_MBUS_ORDER_LE, 40 .order = SOC_MBUS_ORDER_LE,
39 }, [MBUS_IDX(YVYU8_2X8_BE)] = { 41 },
42 [MBUS_IDX(YVYU8_2X8_BE)] = {
40 .fourcc = V4L2_PIX_FMT_VYUY, 43 .fourcc = V4L2_PIX_FMT_VYUY,
41 .name = "VYUY", 44 .name = "VYUY",
42 .bits_per_sample = 8, 45 .bits_per_sample = 8,
43 .packing = SOC_MBUS_PACKING_2X8_PADHI, 46 .packing = SOC_MBUS_PACKING_2X8_PADHI,
44 .order = SOC_MBUS_ORDER_LE, 47 .order = SOC_MBUS_ORDER_LE,
45 }, [MBUS_IDX(RGB555_2X8_PADHI_LE)] = { 48 },
49 [MBUS_IDX(RGB555_2X8_PADHI_LE)] = {
46 .fourcc = V4L2_PIX_FMT_RGB555, 50 .fourcc = V4L2_PIX_FMT_RGB555,
47 .name = "RGB555", 51 .name = "RGB555",
48 .bits_per_sample = 8, 52 .bits_per_sample = 8,
49 .packing = SOC_MBUS_PACKING_2X8_PADHI, 53 .packing = SOC_MBUS_PACKING_2X8_PADHI,
50 .order = SOC_MBUS_ORDER_LE, 54 .order = SOC_MBUS_ORDER_LE,
51 }, [MBUS_IDX(RGB555_2X8_PADHI_BE)] = { 55 },
56 [MBUS_IDX(RGB555_2X8_PADHI_BE)] = {
52 .fourcc = V4L2_PIX_FMT_RGB555X, 57 .fourcc = V4L2_PIX_FMT_RGB555X,
53 .name = "RGB555X", 58 .name = "RGB555X",
54 .bits_per_sample = 8, 59 .bits_per_sample = 8,
55 .packing = SOC_MBUS_PACKING_2X8_PADHI, 60 .packing = SOC_MBUS_PACKING_2X8_PADHI,
56 .order = SOC_MBUS_ORDER_LE, 61 .order = SOC_MBUS_ORDER_LE,
57 }, [MBUS_IDX(RGB565_2X8_LE)] = { 62 },
63 [MBUS_IDX(RGB565_2X8_LE)] = {
58 .fourcc = V4L2_PIX_FMT_RGB565, 64 .fourcc = V4L2_PIX_FMT_RGB565,
59 .name = "RGB565", 65 .name = "RGB565",
60 .bits_per_sample = 8, 66 .bits_per_sample = 8,
61 .packing = SOC_MBUS_PACKING_2X8_PADHI, 67 .packing = SOC_MBUS_PACKING_2X8_PADHI,
62 .order = SOC_MBUS_ORDER_LE, 68 .order = SOC_MBUS_ORDER_LE,
63 }, [MBUS_IDX(RGB565_2X8_BE)] = { 69 },
70 [MBUS_IDX(RGB565_2X8_BE)] = {
64 .fourcc = V4L2_PIX_FMT_RGB565X, 71 .fourcc = V4L2_PIX_FMT_RGB565X,
65 .name = "RGB565X", 72 .name = "RGB565X",
66 .bits_per_sample = 8, 73 .bits_per_sample = 8,
67 .packing = SOC_MBUS_PACKING_2X8_PADHI, 74 .packing = SOC_MBUS_PACKING_2X8_PADHI,
68 .order = SOC_MBUS_ORDER_LE, 75 .order = SOC_MBUS_ORDER_LE,
69 }, [MBUS_IDX(SBGGR8_1X8)] = { 76 },
77 [MBUS_IDX(SBGGR8_1X8)] = {
70 .fourcc = V4L2_PIX_FMT_SBGGR8, 78 .fourcc = V4L2_PIX_FMT_SBGGR8,
71 .name = "Bayer 8 BGGR", 79 .name = "Bayer 8 BGGR",
72 .bits_per_sample = 8, 80 .bits_per_sample = 8,
73 .packing = SOC_MBUS_PACKING_NONE, 81 .packing = SOC_MBUS_PACKING_NONE,
74 .order = SOC_MBUS_ORDER_LE, 82 .order = SOC_MBUS_ORDER_LE,
75 }, [MBUS_IDX(SBGGR10_1X10)] = { 83 },
84 [MBUS_IDX(SBGGR10_1X10)] = {
76 .fourcc = V4L2_PIX_FMT_SBGGR10, 85 .fourcc = V4L2_PIX_FMT_SBGGR10,
77 .name = "Bayer 10 BGGR", 86 .name = "Bayer 10 BGGR",
78 .bits_per_sample = 10, 87 .bits_per_sample = 10,
79 .packing = SOC_MBUS_PACKING_EXTEND16, 88 .packing = SOC_MBUS_PACKING_EXTEND16,
80 .order = SOC_MBUS_ORDER_LE, 89 .order = SOC_MBUS_ORDER_LE,
81 }, [MBUS_IDX(GREY8_1X8)] = { 90 },
91 [MBUS_IDX(GREY8_1X8)] = {
82 .fourcc = V4L2_PIX_FMT_GREY, 92 .fourcc = V4L2_PIX_FMT_GREY,
83 .name = "Grey", 93 .name = "Grey",
84 .bits_per_sample = 8, 94 .bits_per_sample = 8,
85 .packing = SOC_MBUS_PACKING_NONE, 95 .packing = SOC_MBUS_PACKING_NONE,
86 .order = SOC_MBUS_ORDER_LE, 96 .order = SOC_MBUS_ORDER_LE,
87 }, [MBUS_IDX(Y10_1X10)] = { 97 },
98 [MBUS_IDX(Y10_1X10)] = {
88 .fourcc = V4L2_PIX_FMT_Y10, 99 .fourcc = V4L2_PIX_FMT_Y10,
89 .name = "Grey 10bit", 100 .name = "Grey 10bit",
90 .bits_per_sample = 10, 101 .bits_per_sample = 10,
91 .packing = SOC_MBUS_PACKING_EXTEND16, 102 .packing = SOC_MBUS_PACKING_EXTEND16,
92 .order = SOC_MBUS_ORDER_LE, 103 .order = SOC_MBUS_ORDER_LE,
93 }, [MBUS_IDX(SBGGR10_2X8_PADHI_LE)] = { 104 },
105 [MBUS_IDX(SBGGR10_2X8_PADHI_LE)] = {
94 .fourcc = V4L2_PIX_FMT_SBGGR10, 106 .fourcc = V4L2_PIX_FMT_SBGGR10,
95 .name = "Bayer 10 BGGR", 107 .name = "Bayer 10 BGGR",
96 .bits_per_sample = 8, 108 .bits_per_sample = 8,
97 .packing = SOC_MBUS_PACKING_2X8_PADHI, 109 .packing = SOC_MBUS_PACKING_2X8_PADHI,
98 .order = SOC_MBUS_ORDER_LE, 110 .order = SOC_MBUS_ORDER_LE,
99 }, [MBUS_IDX(SBGGR10_2X8_PADLO_LE)] = { 111 },
112 [MBUS_IDX(SBGGR10_2X8_PADLO_LE)] = {
100 .fourcc = V4L2_PIX_FMT_SBGGR10, 113 .fourcc = V4L2_PIX_FMT_SBGGR10,
101 .name = "Bayer 10 BGGR", 114 .name = "Bayer 10 BGGR",
102 .bits_per_sample = 8, 115 .bits_per_sample = 8,
103 .packing = SOC_MBUS_PACKING_2X8_PADLO, 116 .packing = SOC_MBUS_PACKING_2X8_PADLO,
104 .order = SOC_MBUS_ORDER_LE, 117 .order = SOC_MBUS_ORDER_LE,
105 }, [MBUS_IDX(SBGGR10_2X8_PADHI_BE)] = { 118 },
119 [MBUS_IDX(SBGGR10_2X8_PADHI_BE)] = {
106 .fourcc = V4L2_PIX_FMT_SBGGR10, 120 .fourcc = V4L2_PIX_FMT_SBGGR10,
107 .name = "Bayer 10 BGGR", 121 .name = "Bayer 10 BGGR",
108 .bits_per_sample = 8, 122 .bits_per_sample = 8,
109 .packing = SOC_MBUS_PACKING_2X8_PADHI, 123 .packing = SOC_MBUS_PACKING_2X8_PADHI,
110 .order = SOC_MBUS_ORDER_BE, 124 .order = SOC_MBUS_ORDER_BE,
111 }, [MBUS_IDX(SBGGR10_2X8_PADLO_BE)] = { 125 },
126 [MBUS_IDX(SBGGR10_2X8_PADLO_BE)] = {
112 .fourcc = V4L2_PIX_FMT_SBGGR10, 127 .fourcc = V4L2_PIX_FMT_SBGGR10,
113 .name = "Bayer 10 BGGR", 128 .name = "Bayer 10 BGGR",
114 .bits_per_sample = 8, 129 .bits_per_sample = 8,
@@ -134,7 +149,8 @@ EXPORT_SYMBOL(soc_mbus_bytes_per_line);
134const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc( 149const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
135 enum v4l2_mbus_pixelcode code) 150 enum v4l2_mbus_pixelcode code)
136{ 151{
137 if ((unsigned int)(code - V4L2_MBUS_FMT_FIXED) > ARRAY_SIZE(mbus_fmt)) 152 if (code - V4L2_MBUS_FMT_FIXED > ARRAY_SIZE(mbus_fmt) ||
153 code <= V4L2_MBUS_FMT_FIXED)
138 return NULL; 154 return NULL;
139 return mbus_fmt + code - V4L2_MBUS_FMT_FIXED - 1; 155 return mbus_fmt + code - V4L2_MBUS_FMT_FIXED - 1;
140} 156}
diff --git a/drivers/media/video/tlg2300/Kconfig b/drivers/media/video/tlg2300/Kconfig
new file mode 100644
index 000000000000..2c29ec659b4e
--- /dev/null
+++ b/drivers/media/video/tlg2300/Kconfig
@@ -0,0 +1,16 @@
1config VIDEO_TLG2300
2 tristate "Telegent TLG2300 USB video capture support"
3 depends on VIDEO_DEV && I2C && INPUT && SND && DVB_CORE
4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM
6 select VIDEO_IR
7 select VIDEOBUF_VMALLOC
8 select SND_PCM
9 select VIDEOBUF_DVB
10
11 ---help---
12 This is a video4linux driver for Telegent tlg2300 based TV cards.
13 The driver supports V4L2, DVB-T and radio.
14
15 To compile this driver as a module, choose M here: the
16 module will be called poseidon
diff --git a/drivers/media/video/tlg2300/Makefile b/drivers/media/video/tlg2300/Makefile
new file mode 100644
index 000000000000..81bb7fdd1e3d
--- /dev/null
+++ b/drivers/media/video/tlg2300/Makefile
@@ -0,0 +1,9 @@
1poseidon-objs := pd-video.o pd-alsa.o pd-dvb.o pd-radio.o pd-main.o
2
3obj-$(CONFIG_VIDEO_TLG2300) += poseidon.o
4
5EXTRA_CFLAGS += -Idrivers/media/video
6EXTRA_CFLAGS += -Idrivers/media/common/tuners
7EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
8EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
9
diff --git a/drivers/media/video/tlg2300/pd-alsa.c b/drivers/media/video/tlg2300/pd-alsa.c
new file mode 100644
index 000000000000..6f42621ad478
--- /dev/null
+++ b/drivers/media/video/tlg2300/pd-alsa.c
@@ -0,0 +1,332 @@
1#include <linux/kernel.h>
2#include <linux/usb.h>
3#include <linux/init.h>
4#include <linux/sound.h>
5#include <linux/spinlock.h>
6#include <linux/soundcard.h>
7#include <linux/slab.h>
8#include <linux/vmalloc.h>
9#include <linux/proc_fs.h>
10#include <linux/module.h>
11#include <sound/core.h>
12#include <sound/pcm.h>
13#include <sound/pcm_params.h>
14#include <sound/info.h>
15#include <sound/initval.h>
16#include <sound/control.h>
17#include <media/v4l2-common.h>
18#include "pd-common.h"
19#include "vendorcmds.h"
20
21static void complete_handler_audio(struct urb *urb);
22#define AUDIO_EP (0x83)
23#define AUDIO_BUF_SIZE (512)
24#define PERIOD_SIZE (1024 * 8)
25#define PERIOD_MIN (4)
26#define PERIOD_MAX PERIOD_MIN
27
28static struct snd_pcm_hardware snd_pd_hw_capture = {
29 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
30 SNDRV_PCM_INFO_MMAP |
31 SNDRV_PCM_INFO_INTERLEAVED |
32 SNDRV_PCM_INFO_MMAP_VALID,
33
34 .formats = SNDRV_PCM_FMTBIT_S16_LE,
35 .rates = SNDRV_PCM_RATE_48000,
36
37 .rate_min = 48000,
38 .rate_max = 48000,
39 .channels_min = 2,
40 .channels_max = 2,
41 .buffer_bytes_max = PERIOD_SIZE * PERIOD_MIN,
42 .period_bytes_min = PERIOD_SIZE,
43 .period_bytes_max = PERIOD_SIZE,
44 .periods_min = PERIOD_MIN,
45 .periods_max = PERIOD_MAX,
46 /*
47 .buffer_bytes_max = 62720 * 8,
48 .period_bytes_min = 64,
49 .period_bytes_max = 12544,
50 .periods_min = 2,
51 .periods_max = 98
52 */
53};
54
55static int snd_pd_capture_open(struct snd_pcm_substream *substream)
56{
57 struct poseidon *p = snd_pcm_substream_chip(substream);
58 struct poseidon_audio *pa = &p->audio;
59 struct snd_pcm_runtime *runtime = substream->runtime;
60
61 if (!p)
62 return -ENODEV;
63 pa->users++;
64 pa->card_close = 0;
65 pa->capture_pcm_substream = substream;
66 runtime->private_data = p;
67
68 runtime->hw = snd_pd_hw_capture;
69 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
70 usb_autopm_get_interface(p->interface);
71 kref_get(&p->kref);
72 return 0;
73}
74
75static int snd_pd_pcm_close(struct snd_pcm_substream *substream)
76{
77 struct poseidon *p = snd_pcm_substream_chip(substream);
78 struct poseidon_audio *pa = &p->audio;
79
80 pa->users--;
81 pa->card_close = 1;
82 usb_autopm_put_interface(p->interface);
83 kref_put(&p->kref, poseidon_delete);
84 return 0;
85}
86
87static int snd_pd_hw_capture_params(struct snd_pcm_substream *substream,
88 struct snd_pcm_hw_params *hw_params)
89{
90 struct snd_pcm_runtime *runtime = substream->runtime;
91 unsigned int size;
92
93 size = params_buffer_bytes(hw_params);
94 if (runtime->dma_area) {
95 if (runtime->dma_bytes > size)
96 return 0;
97 vfree(runtime->dma_area);
98 }
99 runtime->dma_area = vmalloc(size);
100 if (!runtime->dma_area)
101 return -ENOMEM;
102 else
103 runtime->dma_bytes = size;
104 return 0;
105}
106
107static int audio_buf_free(struct poseidon *p)
108{
109 struct poseidon_audio *pa = &p->audio;
110 int i;
111
112 for (i = 0; i < AUDIO_BUFS; i++)
113 if (pa->urb_array[i])
114 usb_kill_urb(pa->urb_array[i]);
115 free_all_urb_generic(pa->urb_array, AUDIO_BUFS);
116 logpm();
117 return 0;
118}
119
120static int snd_pd_hw_capture_free(struct snd_pcm_substream *substream)
121{
122 struct poseidon *p = snd_pcm_substream_chip(substream);
123
124 logpm();
125 audio_buf_free(p);
126 return 0;
127}
128
129static int snd_pd_prepare(struct snd_pcm_substream *substream)
130{
131 return 0;
132}
133
134#define AUDIO_TRAILER_SIZE (16)
135static inline void handle_audio_data(struct urb *urb, int *period_elapsed)
136{
137 struct poseidon_audio *pa = urb->context;
138 struct snd_pcm_runtime *runtime = pa->capture_pcm_substream->runtime;
139
140 int stride = runtime->frame_bits >> 3;
141 int len = urb->actual_length / stride;
142 unsigned char *cp = urb->transfer_buffer;
143 unsigned int oldptr = pa->rcv_position;
144
145 if (urb->actual_length == AUDIO_BUF_SIZE - 4)
146 len -= (AUDIO_TRAILER_SIZE / stride);
147
148 /* do the copy */
149 if (oldptr + len >= runtime->buffer_size) {
150 unsigned int cnt = runtime->buffer_size - oldptr;
151
152 memcpy(runtime->dma_area + oldptr * stride, cp, cnt * stride);
153 memcpy(runtime->dma_area, (cp + cnt * stride),
154 (len * stride - cnt * stride));
155 } else
156 memcpy(runtime->dma_area + oldptr * stride, cp, len * stride);
157
158 /* update the statas */
159 snd_pcm_stream_lock(pa->capture_pcm_substream);
160 pa->rcv_position += len;
161 if (pa->rcv_position >= runtime->buffer_size)
162 pa->rcv_position -= runtime->buffer_size;
163
164 pa->copied_position += (len);
165 if (pa->copied_position >= runtime->period_size) {
166 pa->copied_position -= runtime->period_size;
167 *period_elapsed = 1;
168 }
169 snd_pcm_stream_unlock(pa->capture_pcm_substream);
170}
171
172static void complete_handler_audio(struct urb *urb)
173{
174 struct poseidon_audio *pa = urb->context;
175 struct snd_pcm_substream *substream = pa->capture_pcm_substream;
176 int period_elapsed = 0;
177 int ret;
178
179 if (1 == pa->card_close || pa->capture_stream != STREAM_ON)
180 return;
181
182 if (urb->status != 0) {
183 /*if (urb->status == -ESHUTDOWN)*/
184 return;
185 }
186
187 if (substream) {
188 if (urb->actual_length) {
189 handle_audio_data(urb, &period_elapsed);
190 if (period_elapsed)
191 snd_pcm_period_elapsed(substream);
192 }
193 }
194
195 ret = usb_submit_urb(urb, GFP_ATOMIC);
196 if (ret < 0)
197 log("audio urb failed (errcod = %i)", ret);
198 return;
199}
200
201static int fire_audio_urb(struct poseidon *p)
202{
203 int i, ret = 0;
204 struct poseidon_audio *pa = &p->audio;
205
206 alloc_bulk_urbs_generic(pa->urb_array, AUDIO_BUFS,
207 p->udev, AUDIO_EP,
208 AUDIO_BUF_SIZE, GFP_ATOMIC,
209 complete_handler_audio, pa);
210
211 for (i = 0; i < AUDIO_BUFS; i++) {
212 ret = usb_submit_urb(pa->urb_array[i], GFP_KERNEL);
213 if (ret)
214 log("urb err : %d", ret);
215 }
216 log();
217 return ret;
218}
219
220static int snd_pd_capture_trigger(struct snd_pcm_substream *substream, int cmd)
221{
222 struct poseidon *p = snd_pcm_substream_chip(substream);
223 struct poseidon_audio *pa = &p->audio;
224
225 if (debug_mode)
226 log("cmd %d, audio stat : %d\n", cmd, pa->capture_stream);
227
228 switch (cmd) {
229 case SNDRV_PCM_TRIGGER_RESUME:
230 case SNDRV_PCM_TRIGGER_START:
231 if (pa->capture_stream == STREAM_ON)
232 return 0;
233
234 pa->rcv_position = pa->copied_position = 0;
235 pa->capture_stream = STREAM_ON;
236
237 if (in_hibernation(p))
238 return 0;
239 fire_audio_urb(p);
240 return 0;
241
242 case SNDRV_PCM_TRIGGER_SUSPEND:
243 pa->capture_stream = STREAM_SUSPEND;
244 return 0;
245 case SNDRV_PCM_TRIGGER_STOP:
246 pa->capture_stream = STREAM_OFF;
247 return 0;
248 default:
249 return -EINVAL;
250 }
251}
252
253static snd_pcm_uframes_t
254snd_pd_capture_pointer(struct snd_pcm_substream *substream)
255{
256 struct poseidon *p = snd_pcm_substream_chip(substream);
257 struct poseidon_audio *pa = &p->audio;
258 return pa->rcv_position;
259}
260
261static struct page *snd_pcm_pd_get_page(struct snd_pcm_substream *subs,
262 unsigned long offset)
263{
264 void *pageptr = subs->runtime->dma_area + offset;
265 return vmalloc_to_page(pageptr);
266}
267
268static struct snd_pcm_ops pcm_capture_ops = {
269 .open = snd_pd_capture_open,
270 .close = snd_pd_pcm_close,
271 .ioctl = snd_pcm_lib_ioctl,
272 .hw_params = snd_pd_hw_capture_params,
273 .hw_free = snd_pd_hw_capture_free,
274 .prepare = snd_pd_prepare,
275 .trigger = snd_pd_capture_trigger,
276 .pointer = snd_pd_capture_pointer,
277 .page = snd_pcm_pd_get_page,
278};
279
280#ifdef CONFIG_PM
281int pm_alsa_suspend(struct poseidon *p)
282{
283 logpm(p);
284 audio_buf_free(p);
285 return 0;
286}
287
288int pm_alsa_resume(struct poseidon *p)
289{
290 logpm(p);
291 fire_audio_urb(p);
292 return 0;
293}
294#endif
295
296int poseidon_audio_init(struct poseidon *p)
297{
298 struct poseidon_audio *pa = &p->audio;
299 struct snd_card *card;
300 struct snd_pcm *pcm;
301 int ret;
302
303 ret = snd_card_create(-1, "Telegent", THIS_MODULE, 0, &card);
304 if (ret != 0)
305 return ret;
306
307 ret = snd_pcm_new(card, "poseidon audio", 0, 0, 1, &pcm);
308 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pcm_capture_ops);
309 pcm->info_flags = 0;
310 pcm->private_data = p;
311 strcpy(pcm->name, "poseidon audio capture");
312
313 strcpy(card->driver, "ALSA driver");
314 strcpy(card->shortname, "poseidon Audio");
315 strcpy(card->longname, "poseidon ALSA Audio");
316
317 if (snd_card_register(card)) {
318 snd_card_free(card);
319 return -ENOMEM;
320 }
321 pa->card = card;
322 return 0;
323}
324
325int poseidon_audio_free(struct poseidon *p)
326{
327 struct poseidon_audio *pa = &p->audio;
328
329 if (pa->card)
330 snd_card_free(pa->card);
331 return 0;
332}
diff --git a/drivers/media/video/tlg2300/pd-common.h b/drivers/media/video/tlg2300/pd-common.h
new file mode 100644
index 000000000000..46066bdc73f9
--- /dev/null
+++ b/drivers/media/video/tlg2300/pd-common.h
@@ -0,0 +1,282 @@
1#ifndef PD_COMMON_H
2#define PD_COMMON_H
3
4#include <linux/version.h>
5#include <linux/fs.h>
6#include <linux/wait.h>
7#include <linux/list.h>
8#include <linux/videodev2.h>
9#include <linux/semaphore.h>
10#include <linux/usb.h>
11#include <linux/poll.h>
12#include <media/videobuf-vmalloc.h>
13#include <media/v4l2-device.h>
14
15#include "dvb_frontend.h"
16#include "dvbdev.h"
17#include "dvb_demux.h"
18#include "dmxdev.h"
19
20#define SBUF_NUM 8
21#define MAX_BUFFER_NUM 6
22#define PK_PER_URB 32
23#define ISO_PKT_SIZE 3072
24
25#define POSEIDON_STATE_NONE (0x0000)
26#define POSEIDON_STATE_ANALOG (0x0001)
27#define POSEIDON_STATE_FM (0x0002)
28#define POSEIDON_STATE_DVBT (0x0004)
29#define POSEIDON_STATE_VBI (0x0008)
30#define POSEIDON_STATE_DISCONNECT (0x0080)
31
32#define PM_SUSPEND_DELAY 3
33
34#define V4L_PAL_VBI_LINES 18
35#define V4L_NTSC_VBI_LINES 12
36#define V4L_PAL_VBI_FRAMESIZE (V4L_PAL_VBI_LINES * 1440 * 2)
37#define V4L_NTSC_VBI_FRAMESIZE (V4L_NTSC_VBI_LINES * 1440 * 2)
38
39#define TUNER_FREQ_MIN (45000000)
40#define TUNER_FREQ_MAX (862000000)
41
42struct vbi_data {
43 struct video_device *v_dev;
44 struct video_data *video;
45 struct front_face *front;
46
47 unsigned int copied;
48 unsigned int vbi_size; /* the whole size of two fields */
49 int users;
50};
51
52/*
53 * This is the running context of the video, it is useful for
54 * resume()
55 */
56struct running_context {
57 u32 freq; /* VIDIOC_S_FREQUENCY */
58 int audio_idx; /* VIDIOC_S_TUNER */
59 v4l2_std_id tvnormid; /* VIDIOC_S_STD */
60 int sig_index; /* VIDIOC_S_INPUT */
61 struct v4l2_pix_format pix; /* VIDIOC_S_FMT */
62};
63
64struct video_data {
65 /* v4l2 video device */
66 struct video_device *v_dev;
67
68 /* the working context */
69 struct running_context context;
70
71 /* for data copy */
72 int field_count;
73
74 char *dst;
75 int lines_copied;
76 int prev_left;
77
78 int lines_per_field;
79 int lines_size;
80
81 /* for communication */
82 u8 endpoint_addr;
83 struct urb *urb_array[SBUF_NUM];
84 struct vbi_data *vbi;
85 struct poseidon *pd;
86 struct front_face *front;
87
88 int is_streaming;
89 int users;
90
91 /* for bubble handler */
92 struct work_struct bubble_work;
93};
94
95enum pcm_stream_state {
96 STREAM_OFF,
97 STREAM_ON,
98 STREAM_SUSPEND,
99};
100
101#define AUDIO_BUFS (3)
102#define CAPTURE_STREAM_EN 1
103struct poseidon_audio {
104 struct urb *urb_array[AUDIO_BUFS];
105 unsigned int copied_position;
106 struct snd_pcm_substream *capture_pcm_substream;
107
108 unsigned int rcv_position;
109 struct snd_card *card;
110 int card_close;
111
112 int users;
113 int pm_state;
114 enum pcm_stream_state capture_stream;
115};
116
117struct radio_data {
118 __u32 fm_freq;
119 int users;
120 unsigned int is_radio_streaming;
121 int pre_emphasis;
122 struct video_device *fm_dev;
123};
124
125#define DVB_SBUF_NUM 4
126#define DVB_URB_BUF_SIZE 0x2000
127struct pd_dvb_adapter {
128 struct dvb_adapter dvb_adap;
129 struct dvb_frontend dvb_fe;
130 struct dmxdev dmxdev;
131 struct dvb_demux demux;
132
133 atomic_t users;
134 atomic_t active_feed;
135
136 /* data transfer */
137 s32 is_streaming;
138 struct urb *urb_array[DVB_SBUF_NUM];
139 struct poseidon *pd_device;
140 u8 ep_addr;
141 u8 reserved[3];
142
143 /* data for power resume*/
144 struct dvb_frontend_parameters fe_param;
145
146 /* for channel scanning */
147 int prev_freq;
148 int bandwidth;
149 unsigned long last_jiffies;
150};
151
152struct front_face {
153 /* use this field to distinguish VIDEO and VBI */
154 enum v4l2_buf_type type;
155
156 /* for host */
157 struct videobuf_queue q;
158
159 /* the bridge for host and device */
160 struct videobuf_buffer *curr_frame;
161
162 /* for device */
163 spinlock_t queue_lock;
164 struct list_head active;
165 struct poseidon *pd;
166};
167
168struct poseidon {
169 struct list_head device_list;
170
171 struct mutex lock;
172 struct kref kref;
173
174 /* for V4L2 */
175 struct v4l2_device v4l2_dev;
176
177 /* hardware info */
178 struct usb_device *udev;
179 struct usb_interface *interface;
180 int cur_transfer_mode;
181
182 struct video_data video_data; /* video */
183 struct vbi_data vbi_data; /* vbi */
184 struct poseidon_audio audio; /* audio (alsa) */
185 struct radio_data radio_data; /* FM */
186 struct pd_dvb_adapter dvb_data; /* DVB */
187
188 u32 state;
189 struct file *file_for_stream; /* the active stream*/
190
191#ifdef CONFIG_PM
192 int (*pm_suspend)(struct poseidon *);
193 int (*pm_resume)(struct poseidon *);
194 pm_message_t msg;
195
196 struct work_struct pm_work;
197 u8 portnum;
198#endif
199};
200
201struct poseidon_format {
202 char *name;
203 int fourcc; /* video4linux 2 */
204 int depth; /* bit/pixel */
205 int flags;
206};
207
208struct poseidon_tvnorm {
209 v4l2_std_id v4l2_id;
210 char name[12];
211 u32 tlg_tvnorm;
212};
213
214/* video */
215int pd_video_init(struct poseidon *);
216void pd_video_exit(struct poseidon *);
217int stop_all_video_stream(struct poseidon *);
218
219/* alsa audio */
220int poseidon_audio_init(struct poseidon *);
221int poseidon_audio_free(struct poseidon *);
222#ifdef CONFIG_PM
223int pm_alsa_suspend(struct poseidon *);
224int pm_alsa_resume(struct poseidon *);
225#endif
226
227/* dvb */
228int pd_dvb_usb_device_init(struct poseidon *);
229void pd_dvb_usb_device_exit(struct poseidon *);
230void pd_dvb_usb_device_cleanup(struct poseidon *);
231int pd_dvb_get_adapter_num(struct pd_dvb_adapter *);
232void dvb_stop_streaming(struct pd_dvb_adapter *);
233
234/* FM */
235int poseidon_fm_init(struct poseidon *);
236int poseidon_fm_exit(struct poseidon *);
237struct video_device *vdev_init(struct poseidon *, struct video_device *);
238
239/* vendor command ops */
240int send_set_req(struct poseidon*, u8, s32, s32*);
241int send_get_req(struct poseidon*, u8, s32, void*, s32*, s32);
242s32 set_tuner_mode(struct poseidon*, unsigned char);
243
244/* bulk urb alloc/free */
245int alloc_bulk_urbs_generic(struct urb **urb_array, int num,
246 struct usb_device *udev, u8 ep_addr,
247 int buf_size, gfp_t gfp_flags,
248 usb_complete_t complete_fn, void *context);
249void free_all_urb_generic(struct urb **urb_array, int num);
250
251/* misc */
252void poseidon_delete(struct kref *kref);
253void destroy_video_device(struct video_device **v_dev);
254extern int debug_mode;
255void set_debug_mode(struct video_device *vfd, int debug_mode);
256
257#ifdef CONFIG_PM
258#define in_hibernation(pd) (pd->msg.event == PM_EVENT_FREEZE)
259#else
260#define in_hibernation(pd) (0)
261#endif
262#define get_pm_count(p) (atomic_read(&(p)->interface->pm_usage_cnt))
263
264#define log(a, ...) printk(KERN_DEBUG "\t[ %s : %.3d ] "a"\n", \
265 __func__, __LINE__, ## __VA_ARGS__)
266
267/* for power management */
268#define logpm(pd) do {\
269 if (debug_mode & 0x10)\
270 log();\
271 } while (0)
272
273#define logs(f) do { \
274 if ((debug_mode & 0x4) && \
275 (f)->type == V4L2_BUF_TYPE_VBI_CAPTURE) \
276 log("type : VBI");\
277 \
278 if ((debug_mode & 0x8) && \
279 (f)->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) \
280 log("type : VIDEO");\
281 } while (0)
282#endif
diff --git a/drivers/media/video/tlg2300/pd-dvb.c b/drivers/media/video/tlg2300/pd-dvb.c
new file mode 100644
index 000000000000..4133aee568bf
--- /dev/null
+++ b/drivers/media/video/tlg2300/pd-dvb.c
@@ -0,0 +1,593 @@
1#include "pd-common.h"
2#include <linux/kernel.h>
3#include <linux/usb.h>
4#include <linux/dvb/dmx.h>
5#include <linux/delay.h>
6
7#include "vendorcmds.h"
8#include <linux/sched.h>
9#include <asm/atomic.h>
10
11static void dvb_urb_cleanup(struct pd_dvb_adapter *pd_dvb);
12
13static int dvb_bandwidth[][2] = {
14 { TLG_BW_8, BANDWIDTH_8_MHZ },
15 { TLG_BW_7, BANDWIDTH_7_MHZ },
16 { TLG_BW_6, BANDWIDTH_6_MHZ }
17};
18static int dvb_bandwidth_length = ARRAY_SIZE(dvb_bandwidth);
19
20static s32 dvb_start_streaming(struct pd_dvb_adapter *pd_dvb);
21static int poseidon_check_mode_dvbt(struct poseidon *pd)
22{
23 s32 ret = 0, cmd_status = 0;
24
25 set_current_state(TASK_INTERRUPTIBLE);
26 schedule_timeout(HZ/4);
27
28 ret = usb_set_interface(pd->udev, 0, BULK_ALTERNATE_IFACE);
29 if (ret != 0)
30 return ret;
31
32 ret = set_tuner_mode(pd, TLG_MODE_CAPS_DVB_T);
33 if (ret)
34 return ret;
35
36 /* signal source */
37 ret = send_set_req(pd, SGNL_SRC_SEL, TLG_SIG_SRC_ANTENNA, &cmd_status);
38 if (ret|cmd_status)
39 return ret;
40
41 return 0;
42}
43
44/* acquire :
45 * 1 == open
46 * 0 == release
47 */
48static int poseidon_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
49{
50 struct poseidon *pd = fe->demodulator_priv;
51 struct pd_dvb_adapter *pd_dvb;
52 int ret = 0;
53
54 if (!pd)
55 return -ENODEV;
56
57 pd_dvb = container_of(fe, struct pd_dvb_adapter, dvb_fe);
58 if (acquire) {
59 mutex_lock(&pd->lock);
60 if (pd->state & POSEIDON_STATE_DISCONNECT) {
61 ret = -ENODEV;
62 goto open_out;
63 }
64
65 if (pd->state && !(pd->state & POSEIDON_STATE_DVBT)) {
66 ret = -EBUSY;
67 goto open_out;
68 }
69
70 usb_autopm_get_interface(pd->interface);
71 if (0 == pd->state) {
72 ret = poseidon_check_mode_dvbt(pd);
73 if (ret < 0) {
74 usb_autopm_put_interface(pd->interface);
75 goto open_out;
76 }
77 pd->state |= POSEIDON_STATE_DVBT;
78 pd_dvb->bandwidth = 0;
79 pd_dvb->prev_freq = 0;
80 }
81 atomic_inc(&pd_dvb->users);
82 kref_get(&pd->kref);
83open_out:
84 mutex_unlock(&pd->lock);
85 } else {
86 dvb_stop_streaming(pd_dvb);
87
88 if (atomic_dec_and_test(&pd_dvb->users)) {
89 mutex_lock(&pd->lock);
90 pd->state &= ~POSEIDON_STATE_DVBT;
91 mutex_unlock(&pd->lock);
92 }
93 kref_put(&pd->kref, poseidon_delete);
94 usb_autopm_put_interface(pd->interface);
95 }
96 return ret;
97}
98
99static void poseidon_fe_release(struct dvb_frontend *fe)
100{
101 struct poseidon *pd = fe->demodulator_priv;
102
103#ifdef CONFIG_PM
104 pd->pm_suspend = NULL;
105 pd->pm_resume = NULL;
106#endif
107}
108
109static s32 poseidon_fe_sleep(struct dvb_frontend *fe)
110{
111 return 0;
112}
113
114/*
115 * return true if we can satisfy the conditions, else return false.
116 */
117static bool check_scan_ok(__u32 freq, int bandwidth,
118 struct pd_dvb_adapter *adapter)
119{
120 if (bandwidth < 0)
121 return false;
122
123 if (adapter->prev_freq == freq
124 && adapter->bandwidth == bandwidth) {
125 long nl = jiffies - adapter->last_jiffies;
126 unsigned int msec ;
127
128 msec = jiffies_to_msecs(abs(nl));
129 return msec > 15000 ? true : false;
130 }
131 return true;
132}
133
134/*
135 * Check if the firmware delays too long for an invalid frequency.
136 */
137static int fw_delay_overflow(struct pd_dvb_adapter *adapter)
138{
139 long nl = jiffies - adapter->last_jiffies;
140 unsigned int msec ;
141
142 msec = jiffies_to_msecs(abs(nl));
143 return msec > 800 ? true : false;
144}
145
146static int poseidon_set_fe(struct dvb_frontend *fe,
147 struct dvb_frontend_parameters *fep)
148{
149 s32 ret = 0, cmd_status = 0;
150 s32 i, bandwidth = -1;
151 struct poseidon *pd = fe->demodulator_priv;
152 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
153
154 if (in_hibernation(pd))
155 return -EBUSY;
156
157 mutex_lock(&pd->lock);
158 for (i = 0; i < dvb_bandwidth_length; i++)
159 if (fep->u.ofdm.bandwidth == dvb_bandwidth[i][1])
160 bandwidth = dvb_bandwidth[i][0];
161
162 if (check_scan_ok(fep->frequency, bandwidth, pd_dvb)) {
163 ret = send_set_req(pd, TUNE_FREQ_SELECT,
164 fep->frequency / 1000, &cmd_status);
165 if (ret | cmd_status) {
166 log("error line");
167 goto front_out;
168 }
169
170 ret = send_set_req(pd, DVBT_BANDW_SEL,
171 bandwidth, &cmd_status);
172 if (ret | cmd_status) {
173 log("error line");
174 goto front_out;
175 }
176
177 ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
178 if (ret | cmd_status) {
179 log("error line");
180 goto front_out;
181 }
182
183 /* save the context for future */
184 memcpy(&pd_dvb->fe_param, fep, sizeof(*fep));
185 pd_dvb->bandwidth = bandwidth;
186 pd_dvb->prev_freq = fep->frequency;
187 pd_dvb->last_jiffies = jiffies;
188 }
189front_out:
190 mutex_unlock(&pd->lock);
191 return ret;
192}
193
194#ifdef CONFIG_PM
195static int pm_dvb_suspend(struct poseidon *pd)
196{
197 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
198 dvb_stop_streaming(pd_dvb);
199 dvb_urb_cleanup(pd_dvb);
200 msleep(500);
201 return 0;
202}
203
204static int pm_dvb_resume(struct poseidon *pd)
205{
206 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
207
208 poseidon_check_mode_dvbt(pd);
209 msleep(300);
210 poseidon_set_fe(&pd_dvb->dvb_fe, &pd_dvb->fe_param);
211
212 dvb_start_streaming(pd_dvb);
213 return 0;
214}
215#endif
216
217static s32 poseidon_fe_init(struct dvb_frontend *fe)
218{
219 struct poseidon *pd = fe->demodulator_priv;
220 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
221
222#ifdef CONFIG_PM
223 pd->pm_suspend = pm_dvb_suspend;
224 pd->pm_resume = pm_dvb_resume;
225#endif
226 memset(&pd_dvb->fe_param, 0,
227 sizeof(struct dvb_frontend_parameters));
228 return 0;
229}
230
231static int poseidon_get_fe(struct dvb_frontend *fe,
232 struct dvb_frontend_parameters *fep)
233{
234 struct poseidon *pd = fe->demodulator_priv;
235 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
236
237 memcpy(fep, &pd_dvb->fe_param, sizeof(*fep));
238 return 0;
239}
240
241static int poseidon_fe_get_tune_settings(struct dvb_frontend *fe,
242 struct dvb_frontend_tune_settings *tune)
243{
244 tune->min_delay_ms = 1000;
245 return 0;
246}
247
248static int poseidon_read_status(struct dvb_frontend *fe, fe_status_t *stat)
249{
250 struct poseidon *pd = fe->demodulator_priv;
251 s32 ret = -1, cmd_status;
252 struct tuner_dtv_sig_stat_s status = {};
253
254 if (in_hibernation(pd))
255 return -EBUSY;
256 mutex_lock(&pd->lock);
257
258 ret = send_get_req(pd, TUNER_STATUS, TLG_MODE_DVB_T,
259 &status, &cmd_status, sizeof(status));
260 if (ret | cmd_status) {
261 log("get tuner status error");
262 goto out;
263 }
264
265 if (debug_mode)
266 log("P : %d, L %d, LB :%d", status.sig_present,
267 status.sig_locked, status.sig_lock_busy);
268
269 if (status.sig_lock_busy) {
270 goto out;
271 } else if (status.sig_present || status.sig_locked) {
272 *stat |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER
273 | FE_HAS_SYNC | FE_HAS_VITERBI;
274 } else {
275 if (fw_delay_overflow(&pd->dvb_data))
276 *stat |= FE_TIMEDOUT;
277 }
278out:
279 mutex_unlock(&pd->lock);
280 return ret;
281}
282
283static int poseidon_read_ber(struct dvb_frontend *fe, u32 *ber)
284{
285 struct poseidon *pd = fe->demodulator_priv;
286 struct tuner_ber_rate_s tlg_ber = {};
287 s32 ret = -1, cmd_status;
288
289 mutex_lock(&pd->lock);
290 ret = send_get_req(pd, TUNER_BER_RATE, 0,
291 &tlg_ber, &cmd_status, sizeof(tlg_ber));
292 if (ret | cmd_status)
293 goto out;
294 *ber = tlg_ber.ber_rate;
295out:
296 mutex_unlock(&pd->lock);
297 return ret;
298}
299
300static s32 poseidon_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
301{
302 struct poseidon *pd = fe->demodulator_priv;
303 struct tuner_dtv_sig_stat_s status = {};
304 s32 ret = 0, cmd_status;
305
306 mutex_lock(&pd->lock);
307 ret = send_get_req(pd, TUNER_STATUS, TLG_MODE_DVB_T,
308 &status, &cmd_status, sizeof(status));
309 if (ret | cmd_status)
310 goto out;
311 if ((status.sig_present || status.sig_locked) && !status.sig_strength)
312 *strength = 0xFFFF;
313 else
314 *strength = status.sig_strength;
315out:
316 mutex_unlock(&pd->lock);
317 return ret;
318}
319
320static int poseidon_read_snr(struct dvb_frontend *fe, u16 *snr)
321{
322 return 0;
323}
324
325static int poseidon_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
326{
327 *unc = 0;
328 return 0;
329}
330
331static struct dvb_frontend_ops poseidon_frontend_ops = {
332 .info = {
333 .name = "Poseidon DVB-T",
334 .type = FE_OFDM,
335 .frequency_min = 174000000,
336 .frequency_max = 862000000,
337 .frequency_stepsize = 62500,/* FIXME */
338 .caps = FE_CAN_INVERSION_AUTO |
339 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
340 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
341 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
342 FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
343 FE_CAN_GUARD_INTERVAL_AUTO |
344 FE_CAN_RECOVER |
345 FE_CAN_HIERARCHY_AUTO,
346 },
347
348 .release = poseidon_fe_release,
349
350 .init = poseidon_fe_init,
351 .sleep = poseidon_fe_sleep,
352
353 .set_frontend = poseidon_set_fe,
354 .get_frontend = poseidon_get_fe,
355 .get_tune_settings = poseidon_fe_get_tune_settings,
356
357 .read_status = poseidon_read_status,
358 .read_ber = poseidon_read_ber,
359 .read_signal_strength = poseidon_read_signal_strength,
360 .read_snr = poseidon_read_snr,
361 .read_ucblocks = poseidon_read_unc_blocks,
362
363 .ts_bus_ctrl = poseidon_ts_bus_ctrl,
364};
365
366static void dvb_urb_irq(struct urb *urb)
367{
368 struct pd_dvb_adapter *pd_dvb = urb->context;
369 int len = urb->transfer_buffer_length;
370 struct dvb_demux *demux = &pd_dvb->demux;
371 s32 ret;
372
373 if (!pd_dvb->is_streaming || urb->status) {
374 if (urb->status == -EPROTO)
375 goto resend;
376 return;
377 }
378
379 if (urb->actual_length == len)
380 dvb_dmx_swfilter(demux, urb->transfer_buffer, len);
381 else if (urb->actual_length == len - 4) {
382 int offset;
383 u8 *buf = urb->transfer_buffer;
384
385 /*
386 * The packet size is 512,
387 * last packet contains 456 bytes tsp data
388 */
389 for (offset = 456; offset < len; offset += 512) {
390 if (!strncmp(buf + offset, "DVHS", 4)) {
391 dvb_dmx_swfilter(demux, buf, offset);
392 if (len > offset + 52 + 4) {
393 /*16 bytes trailer + 36 bytes padding */
394 buf += offset + 52;
395 len -= offset + 52 + 4;
396 dvb_dmx_swfilter(demux, buf, len);
397 }
398 break;
399 }
400 }
401 }
402
403resend:
404 ret = usb_submit_urb(urb, GFP_ATOMIC);
405 if (ret)
406 log(" usb_submit_urb failed: error %d", ret);
407}
408
409static int dvb_urb_init(struct pd_dvb_adapter *pd_dvb)
410{
411 if (pd_dvb->urb_array[0])
412 return 0;
413
414 alloc_bulk_urbs_generic(pd_dvb->urb_array, DVB_SBUF_NUM,
415 pd_dvb->pd_device->udev, pd_dvb->ep_addr,
416 DVB_URB_BUF_SIZE, GFP_KERNEL,
417 dvb_urb_irq, pd_dvb);
418 return 0;
419}
420
421static void dvb_urb_cleanup(struct pd_dvb_adapter *pd_dvb)
422{
423 free_all_urb_generic(pd_dvb->urb_array, DVB_SBUF_NUM);
424}
425
426static s32 dvb_start_streaming(struct pd_dvb_adapter *pd_dvb)
427{
428 struct poseidon *pd = pd_dvb->pd_device;
429 int ret = 0;
430
431 if (pd->state & POSEIDON_STATE_DISCONNECT)
432 return -ENODEV;
433
434 mutex_lock(&pd->lock);
435 if (!pd_dvb->is_streaming) {
436 s32 i, cmd_status = 0;
437 /*
438 * Once upon a time, there was a difficult bug lying here.
439 * ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
440 */
441
442 ret = send_set_req(pd, PLAY_SERVICE, 1, &cmd_status);
443 if (ret | cmd_status)
444 goto out;
445
446 ret = dvb_urb_init(pd_dvb);
447 if (ret < 0)
448 goto out;
449
450 pd_dvb->is_streaming = 1;
451 for (i = 0; i < DVB_SBUF_NUM; i++) {
452 ret = usb_submit_urb(pd_dvb->urb_array[i],
453 GFP_KERNEL);
454 if (ret) {
455 log(" submit urb error %d", ret);
456 goto out;
457 }
458 }
459 }
460out:
461 mutex_unlock(&pd->lock);
462 return ret;
463}
464
465void dvb_stop_streaming(struct pd_dvb_adapter *pd_dvb)
466{
467 struct poseidon *pd = pd_dvb->pd_device;
468
469 mutex_lock(&pd->lock);
470 if (pd_dvb->is_streaming) {
471 s32 i, ret, cmd_status = 0;
472
473 pd_dvb->is_streaming = 0;
474
475 for (i = 0; i < DVB_SBUF_NUM; i++)
476 if (pd_dvb->urb_array[i])
477 usb_kill_urb(pd_dvb->urb_array[i]);
478
479 ret = send_set_req(pd, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_STOP,
480 &cmd_status);
481 if (ret | cmd_status)
482 log("error");
483 }
484 mutex_unlock(&pd->lock);
485}
486
487static int pd_start_feed(struct dvb_demux_feed *feed)
488{
489 struct pd_dvb_adapter *pd_dvb = feed->demux->priv;
490 int ret = 0;
491
492 if (!pd_dvb)
493 return -1;
494 if (atomic_inc_return(&pd_dvb->active_feed) == 1)
495 ret = dvb_start_streaming(pd_dvb);
496 return ret;
497}
498
499static int pd_stop_feed(struct dvb_demux_feed *feed)
500{
501 struct pd_dvb_adapter *pd_dvb = feed->demux->priv;
502
503 if (!pd_dvb)
504 return -1;
505 if (atomic_dec_and_test(&pd_dvb->active_feed))
506 dvb_stop_streaming(pd_dvb);
507 return 0;
508}
509
510DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
511int pd_dvb_usb_device_init(struct poseidon *pd)
512{
513 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
514 struct dvb_demux *dvbdemux;
515 int ret = 0;
516
517 pd_dvb->ep_addr = 0x82;
518 atomic_set(&pd_dvb->users, 0);
519 atomic_set(&pd_dvb->active_feed, 0);
520 pd_dvb->pd_device = pd;
521
522 ret = dvb_register_adapter(&pd_dvb->dvb_adap,
523 "Poseidon dvbt adapter",
524 THIS_MODULE,
525 NULL /* for hibernation correctly*/,
526 adapter_nr);
527 if (ret < 0)
528 goto error1;
529
530 /* register frontend */
531 pd_dvb->dvb_fe.demodulator_priv = pd;
532 memcpy(&pd_dvb->dvb_fe.ops, &poseidon_frontend_ops,
533 sizeof(struct dvb_frontend_ops));
534 ret = dvb_register_frontend(&pd_dvb->dvb_adap, &pd_dvb->dvb_fe);
535 if (ret < 0)
536 goto error2;
537
538 /* register demux device */
539 dvbdemux = &pd_dvb->demux;
540 dvbdemux->dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING;
541 dvbdemux->priv = pd_dvb;
542 dvbdemux->feednum = dvbdemux->filternum = 64;
543 dvbdemux->start_feed = pd_start_feed;
544 dvbdemux->stop_feed = pd_stop_feed;
545 dvbdemux->write_to_decoder = NULL;
546
547 ret = dvb_dmx_init(dvbdemux);
548 if (ret < 0)
549 goto error3;
550
551 pd_dvb->dmxdev.filternum = pd_dvb->demux.filternum;
552 pd_dvb->dmxdev.demux = &pd_dvb->demux.dmx;
553 pd_dvb->dmxdev.capabilities = 0;
554
555 ret = dvb_dmxdev_init(&pd_dvb->dmxdev, &pd_dvb->dvb_adap);
556 if (ret < 0)
557 goto error3;
558 return 0;
559
560error3:
561 dvb_unregister_frontend(&pd_dvb->dvb_fe);
562error2:
563 dvb_unregister_adapter(&pd_dvb->dvb_adap);
564error1:
565 return ret;
566}
567
568void pd_dvb_usb_device_exit(struct poseidon *pd)
569{
570 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
571
572 while (atomic_read(&pd_dvb->users) != 0
573 || atomic_read(&pd_dvb->active_feed) != 0) {
574 set_current_state(TASK_INTERRUPTIBLE);
575 schedule_timeout(HZ);
576 }
577 dvb_dmxdev_release(&pd_dvb->dmxdev);
578 dvb_unregister_frontend(&pd_dvb->dvb_fe);
579 dvb_unregister_adapter(&pd_dvb->dvb_adap);
580 pd_dvb_usb_device_cleanup(pd);
581}
582
583void pd_dvb_usb_device_cleanup(struct poseidon *pd)
584{
585 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
586
587 dvb_urb_cleanup(pd_dvb);
588}
589
590int pd_dvb_get_adapter_num(struct pd_dvb_adapter *pd_dvb)
591{
592 return pd_dvb->dvb_adap.num;
593}
diff --git a/drivers/media/video/tlg2300/pd-main.c b/drivers/media/video/tlg2300/pd-main.c
new file mode 100644
index 000000000000..2cf0ebf9f28b
--- /dev/null
+++ b/drivers/media/video/tlg2300/pd-main.c
@@ -0,0 +1,539 @@
1/*
2 * device driver for Telegent tlg2300 based TV cards
3 *
4 * Author :
5 * Kang Yong <kangyong@telegent.com>
6 * Zhang Xiaobing <xbzhang@telegent.com>
7 * Huang Shijie <zyziii@telegent.com> or <shijie8@gmail.com>
8 *
9 * (c) 2009 Telegent Systems
10 * (c) 2010 Telegent Systems
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <linux/version.h>
28#include <linux/kernel.h>
29#include <linux/errno.h>
30#include <linux/init.h>
31#include <linux/slab.h>
32#include <linux/module.h>
33#include <linux/kref.h>
34#include <linux/suspend.h>
35#include <linux/usb/quirks.h>
36#include <linux/ctype.h>
37#include <linux/string.h>
38#include <linux/types.h>
39#include <linux/firmware.h>
40#include <linux/smp_lock.h>
41
42#include "vendorcmds.h"
43#include "pd-common.h"
44
45#define VENDOR_ID 0x1B24
46#define PRODUCT_ID 0x4001
47static struct usb_device_id id_table[] = {
48 { USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ID, PRODUCT_ID, 255, 1, 0) },
49 { USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ID, PRODUCT_ID, 255, 1, 1) },
50 { },
51};
52MODULE_DEVICE_TABLE(usb, id_table);
53
54int debug_mode;
55module_param(debug_mode, int, 0644);
56MODULE_PARM_DESC(debug_mode, "0 = disable, 1 = enable, 2 = verbose");
57
58const char *firmware_name = "tlg2300_firmware.bin";
59struct usb_driver poseidon_driver;
60static LIST_HEAD(pd_device_list);
61
62/*
63 * send set request to USB firmware.
64 */
65s32 send_set_req(struct poseidon *pd, u8 cmdid, s32 param, s32 *cmd_status)
66{
67 s32 ret;
68 s8 data[32] = {};
69 u16 lower_16, upper_16;
70
71 if (pd->state & POSEIDON_STATE_DISCONNECT)
72 return -ENODEV;
73
74 mdelay(30);
75
76 if (param == 0) {
77 upper_16 = lower_16 = 0;
78 } else {
79 /* send 32 bit param as two 16 bit param,little endian */
80 lower_16 = (unsigned short)(param & 0xffff);
81 upper_16 = (unsigned short)((param >> 16) & 0xffff);
82 }
83 ret = usb_control_msg(pd->udev,
84 usb_rcvctrlpipe(pd->udev, 0),
85 REQ_SET_CMD | cmdid,
86 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
87 lower_16,
88 upper_16,
89 &data,
90 sizeof(*cmd_status),
91 USB_CTRL_GET_TIMEOUT);
92
93 if (!ret) {
94 return -ENXIO;
95 } else {
96 /* 1st 4 bytes into cmd_status */
97 memcpy((char *)cmd_status, &(data[0]), sizeof(*cmd_status));
98 }
99 return 0;
100}
101
102/*
103 * send get request to Poseidon firmware.
104 */
105s32 send_get_req(struct poseidon *pd, u8 cmdid, s32 param,
106 void *buf, s32 *cmd_status, s32 datalen)
107{
108 s32 ret;
109 s8 data[128] = {};
110 u16 lower_16, upper_16;
111
112 if (pd->state & POSEIDON_STATE_DISCONNECT)
113 return -ENODEV;
114
115 mdelay(30);
116 if (param == 0) {
117 upper_16 = lower_16 = 0;
118 } else {
119 /*send 32 bit param as two 16 bit param, little endian */
120 lower_16 = (unsigned short)(param & 0xffff);
121 upper_16 = (unsigned short)((param >> 16) & 0xffff);
122 }
123 ret = usb_control_msg(pd->udev,
124 usb_rcvctrlpipe(pd->udev, 0),
125 REQ_GET_CMD | cmdid,
126 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
127 lower_16,
128 upper_16,
129 &data,
130 (datalen + sizeof(*cmd_status)),
131 USB_CTRL_GET_TIMEOUT);
132
133 if (ret < 0) {
134 return -ENXIO;
135 } else {
136 /* 1st 4 bytes into cmd_status, remaining data into cmd_data */
137 memcpy((char *)cmd_status, &data[0], sizeof(*cmd_status));
138 memcpy((char *)buf, &data[sizeof(*cmd_status)], datalen);
139 }
140 return 0;
141}
142
143static int pm_notifier_block(struct notifier_block *nb,
144 unsigned long event, void *dummy)
145{
146 struct poseidon *pd = NULL;
147 struct list_head *node, *next;
148
149 switch (event) {
150 case PM_POST_HIBERNATION:
151 list_for_each_safe(node, next, &pd_device_list) {
152 struct usb_device *udev;
153 struct usb_interface *iface;
154 int rc = 0;
155
156 pd = container_of(node, struct poseidon, device_list);
157 udev = pd->udev;
158 iface = pd->interface;
159
160 /* It will cause the system to reload the firmware */
161 rc = usb_lock_device_for_reset(udev, iface);
162 if (rc >= 0) {
163 usb_reset_device(udev);
164 usb_unlock_device(udev);
165 }
166 }
167 break;
168 default:
169 break;
170 }
171 log("event :%ld\n", event);
172 return 0;
173}
174
175static struct notifier_block pm_notifer = {
176 .notifier_call = pm_notifier_block,
177};
178
179int set_tuner_mode(struct poseidon *pd, unsigned char mode)
180{
181 s32 ret, cmd_status;
182
183 if (pd->state & POSEIDON_STATE_DISCONNECT)
184 return -ENODEV;
185
186 ret = send_set_req(pd, TUNE_MODE_SELECT, mode, &cmd_status);
187 if (ret || cmd_status)
188 return -ENXIO;
189 return 0;
190}
191
192void poseidon_delete(struct kref *kref)
193{
194 struct poseidon *pd = container_of(kref, struct poseidon, kref);
195
196 if (!pd)
197 return;
198 list_del_init(&pd->device_list);
199
200 pd_dvb_usb_device_cleanup(pd);
201 /* clean_audio_data(&pd->audio_data);*/
202
203 if (pd->udev) {
204 usb_put_dev(pd->udev);
205 pd->udev = NULL;
206 }
207 if (pd->interface) {
208 usb_put_intf(pd->interface);
209 pd->interface = NULL;
210 }
211 kfree(pd);
212 log();
213}
214
215static int firmware_download(struct usb_device *udev)
216{
217 int ret = 0, actual_length;
218 const struct firmware *fw = NULL;
219 void *fwbuf = NULL;
220 size_t fwlength = 0, offset;
221 size_t max_packet_size;
222
223 ret = request_firmware(&fw, firmware_name, &udev->dev);
224 if (ret) {
225 log("download err : %d", ret);
226 return ret;
227 }
228
229 fwlength = fw->size;
230
231 fwbuf = kzalloc(fwlength, GFP_KERNEL);
232 if (!fwbuf) {
233 ret = -ENOMEM;
234 goto out;
235 }
236 memcpy(fwbuf, fw->data, fwlength);
237
238 max_packet_size = udev->ep_out[0x1]->desc.wMaxPacketSize;
239 log("\t\t download size : %d", (int)max_packet_size);
240
241 for (offset = 0; offset < fwlength; offset += max_packet_size) {
242 actual_length = 0;
243 ret = usb_bulk_msg(udev,
244 usb_sndbulkpipe(udev, 0x01), /* ep 1 */
245 fwbuf + offset,
246 min(max_packet_size, fwlength - offset),
247 &actual_length,
248 HZ * 10);
249 if (ret)
250 break;
251 }
252 kfree(fwbuf);
253out:
254 release_firmware(fw);
255 return ret;
256}
257
258static inline struct poseidon *get_pd(struct usb_interface *intf)
259{
260 return usb_get_intfdata(intf);
261}
262
263#ifdef CONFIG_PM
264/* one-to-one map : poseidon{} <----> usb_device{}'s port */
265static inline void set_map_flags(struct poseidon *pd, struct usb_device *udev)
266{
267 pd->portnum = udev->portnum;
268}
269
270static inline int get_autopm_ref(struct poseidon *pd)
271{
272 return pd->video_data.users + pd->vbi_data.users + pd->audio.users
273 + atomic_read(&pd->dvb_data.users) + pd->radio_data.users;
274}
275
276/* fixup something for poseidon */
277static inline struct poseidon *fixup(struct poseidon *pd)
278{
279 int count;
280
281 /* old udev and interface have gone, so put back reference . */
282 count = get_autopm_ref(pd);
283 log("count : %d, ref count : %d", count, get_pm_count(pd));
284 while (count--)
285 usb_autopm_put_interface(pd->interface);
286 /*usb_autopm_set_interface(pd->interface); */
287
288 usb_put_dev(pd->udev);
289 usb_put_intf(pd->interface);
290 log("event : %d\n", pd->msg.event);
291 return pd;
292}
293
294static struct poseidon *find_old_poseidon(struct usb_device *udev)
295{
296 struct poseidon *pd;
297
298 list_for_each_entry(pd, &pd_device_list, device_list) {
299 if (pd->portnum == udev->portnum && in_hibernation(pd))
300 return fixup(pd);
301 }
302 return NULL;
303}
304
305/* Is the card working now ? */
306static inline int is_working(struct poseidon *pd)
307{
308 return get_pm_count(pd) > 0;
309}
310
311static int poseidon_suspend(struct usb_interface *intf, pm_message_t msg)
312{
313 struct poseidon *pd = get_pd(intf);
314
315 if (!pd)
316 return 0;
317 if (!is_working(pd)) {
318 if (get_pm_count(pd) <= 0 && !in_hibernation(pd)) {
319 pd->msg.event = PM_EVENT_AUTO_SUSPEND;
320 pd->pm_resume = NULL; /* a good guard */
321 printk(KERN_DEBUG "\n\t+ TLG2300 auto suspend +\n\n");
322 }
323 return 0;
324 }
325 pd->msg = msg; /* save it here */
326 logpm(pd);
327 return pd->pm_suspend ? pd->pm_suspend(pd) : 0;
328}
329
330static int poseidon_resume(struct usb_interface *intf)
331{
332 struct poseidon *pd = get_pd(intf);
333
334 if (!pd)
335 return 0;
336 printk(KERN_DEBUG "\n\t ++ TLG2300 resume ++\n\n");
337
338 if (!is_working(pd)) {
339 if (PM_EVENT_AUTO_SUSPEND == pd->msg.event)
340 pd->msg = PMSG_ON;
341 return 0;
342 }
343 if (in_hibernation(pd)) {
344 logpm(pd);
345 return 0;
346 }
347 logpm(pd);
348 return pd->pm_resume ? pd->pm_resume(pd) : 0;
349}
350
351static void hibernation_resume(struct work_struct *w)
352{
353 struct poseidon *pd = container_of(w, struct poseidon, pm_work);
354 int count;
355
356 pd->msg.event = 0; /* clear it here */
357 pd->state &= ~POSEIDON_STATE_DISCONNECT;
358
359 /* set the new interface's reference */
360 count = get_autopm_ref(pd);
361 while (count--)
362 usb_autopm_get_interface(pd->interface);
363
364 /* resume the context */
365 logpm(pd);
366 if (pd->pm_resume)
367 pd->pm_resume(pd);
368}
369#else /* CONFIG_PM is not enabled: */
370static inline struct poseidon *find_old_poseidon(struct usb_device *udev)
371{
372 return NULL;
373}
374
375static inline void set_map_flags(struct poseidon *pd, struct usb_device *udev)
376{
377}
378#endif
379
380static bool check_firmware(struct usb_device *udev, int *down_firmware)
381{
382 void *buf;
383 int ret;
384 struct cmd_firmware_vers_s *cmd_firm;
385
386 buf = kzalloc(sizeof(*cmd_firm) + sizeof(u32), GFP_KERNEL);
387 if (!buf)
388 return -ENOMEM;
389 ret = usb_control_msg(udev,
390 usb_rcvctrlpipe(udev, 0),
391 REQ_GET_CMD | GET_FW_ID,
392 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
393 0,
394 0,
395 buf,
396 sizeof(*cmd_firm) + sizeof(u32),
397 USB_CTRL_GET_TIMEOUT);
398 kfree(buf);
399
400 if (ret < 0) {
401 *down_firmware = 1;
402 return firmware_download(udev);
403 }
404 return ret;
405}
406
407static int poseidon_probe(struct usb_interface *interface,
408 const struct usb_device_id *id)
409{
410 struct usb_device *udev = interface_to_usbdev(interface);
411 struct poseidon *pd = NULL;
412 int ret = 0;
413 int new_one = 0;
414
415 /* download firmware */
416 check_firmware(udev, &ret);
417 if (ret)
418 return 0;
419
420 /* Do I recovery from the hibernate ? */
421 pd = find_old_poseidon(udev);
422 if (!pd) {
423 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
424 if (!pd)
425 return -ENOMEM;
426 kref_init(&pd->kref);
427 set_map_flags(pd, udev);
428 new_one = 1;
429 }
430
431 pd->udev = usb_get_dev(udev);
432 pd->interface = usb_get_intf(interface);
433 usb_set_intfdata(interface, pd);
434
435 if (new_one) {
436 struct device *dev = &interface->dev;
437
438 logpm(pd);
439 mutex_init(&pd->lock);
440
441 /* register v4l2 device */
442 snprintf(pd->v4l2_dev.name, sizeof(pd->v4l2_dev.name), "%s %s",
443 dev->driver->name, dev_name(dev));
444 ret = v4l2_device_register(NULL, &pd->v4l2_dev);
445
446 /* register devices in directory /dev */
447 ret = pd_video_init(pd);
448 poseidon_audio_init(pd);
449 poseidon_fm_init(pd);
450 pd_dvb_usb_device_init(pd);
451
452 INIT_LIST_HEAD(&pd->device_list);
453 list_add_tail(&pd->device_list, &pd_device_list);
454 }
455
456 device_init_wakeup(&udev->dev, 1);
457#ifdef CONFIG_PM
458 pd->udev->autosuspend_disabled = 0;
459 pd->udev->autosuspend_delay = HZ * PM_SUSPEND_DELAY;
460
461 if (in_hibernation(pd)) {
462 INIT_WORK(&pd->pm_work, hibernation_resume);
463 schedule_work(&pd->pm_work);
464 }
465#endif
466 return 0;
467}
468
469static void poseidon_disconnect(struct usb_interface *interface)
470{
471 struct poseidon *pd = get_pd(interface);
472
473 if (!pd)
474 return;
475 logpm(pd);
476 if (in_hibernation(pd))
477 return;
478
479 mutex_lock(&pd->lock);
480 pd->state |= POSEIDON_STATE_DISCONNECT;
481 mutex_unlock(&pd->lock);
482
483 /* stop urb transferring */
484 stop_all_video_stream(pd);
485 dvb_stop_streaming(&pd->dvb_data);
486
487 /*unregister v4l2 device */
488 v4l2_device_unregister(&pd->v4l2_dev);
489
490 lock_kernel();
491 {
492 pd_dvb_usb_device_exit(pd);
493 poseidon_fm_exit(pd);
494
495 poseidon_audio_free(pd);
496 pd_video_exit(pd);
497 }
498 unlock_kernel();
499
500 usb_set_intfdata(interface, NULL);
501 kref_put(&pd->kref, poseidon_delete);
502}
503
504struct usb_driver poseidon_driver = {
505 .name = "poseidon",
506 .probe = poseidon_probe,
507 .disconnect = poseidon_disconnect,
508 .id_table = id_table,
509#ifdef CONFIG_PM
510 .suspend = poseidon_suspend,
511 .resume = poseidon_resume,
512#endif
513 .supports_autosuspend = 1,
514};
515
516static int __init poseidon_init(void)
517{
518 int ret;
519
520 ret = usb_register(&poseidon_driver);
521 if (ret)
522 return ret;
523 register_pm_notifier(&pm_notifer);
524 return ret;
525}
526
527static void __exit poseidon_exit(void)
528{
529 log();
530 unregister_pm_notifier(&pm_notifer);
531 usb_deregister(&poseidon_driver);
532}
533
534module_init(poseidon_init);
535module_exit(poseidon_exit);
536
537MODULE_AUTHOR("Telegent Systems");
538MODULE_DESCRIPTION("For tlg2300-based USB device ");
539MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tlg2300/pd-radio.c b/drivers/media/video/tlg2300/pd-radio.c
new file mode 100644
index 000000000000..755766b15157
--- /dev/null
+++ b/drivers/media/video/tlg2300/pd-radio.c
@@ -0,0 +1,420 @@
1#include <linux/init.h>
2#include <linux/list.h>
3#include <linux/module.h>
4#include <linux/kernel.h>
5#include <linux/bitmap.h>
6#include <linux/usb.h>
7#include <linux/i2c.h>
8#include <media/v4l2-dev.h>
9#include <linux/version.h>
10#include <linux/mm.h>
11#include <linux/mutex.h>
12#include <media/v4l2-ioctl.h>
13#include <linux/sched.h>
14
15#include "pd-common.h"
16#include "vendorcmds.h"
17
18static int set_frequency(struct poseidon *p, __u32 frequency);
19static int poseidon_fm_close(struct file *filp);
20static int poseidon_fm_open(struct file *filp);
21
22#define TUNER_FREQ_MIN_FM 76000000
23#define TUNER_FREQ_MAX_FM 108000000
24
25#define MAX_PREEMPHASIS (V4L2_PREEMPHASIS_75_uS + 1)
26static int preemphasis[MAX_PREEMPHASIS] = {
27 TLG_TUNE_ASTD_NONE, /* V4L2_PREEMPHASIS_DISABLED */
28 TLG_TUNE_ASTD_FM_EUR, /* V4L2_PREEMPHASIS_50_uS */
29 TLG_TUNE_ASTD_FM_US, /* V4L2_PREEMPHASIS_75_uS */
30};
31
32static int poseidon_check_mode_radio(struct poseidon *p)
33{
34 int ret;
35 u32 status;
36
37 set_current_state(TASK_INTERRUPTIBLE);
38 schedule_timeout(HZ/2);
39 ret = usb_set_interface(p->udev, 0, BULK_ALTERNATE_IFACE);
40 if (ret < 0)
41 goto out;
42
43 ret = set_tuner_mode(p, TLG_MODE_FM_RADIO);
44 if (ret != 0)
45 goto out;
46
47 ret = send_set_req(p, SGNL_SRC_SEL, TLG_SIG_SRC_ANTENNA, &status);
48 ret = send_set_req(p, TUNER_AUD_ANA_STD,
49 p->radio_data.pre_emphasis, &status);
50 ret |= send_set_req(p, TUNER_AUD_MODE,
51 TLG_TUNE_TVAUDIO_MODE_STEREO, &status);
52 ret |= send_set_req(p, AUDIO_SAMPLE_RATE_SEL,
53 ATV_AUDIO_RATE_48K, &status);
54 ret |= send_set_req(p, TUNE_FREQ_SELECT, TUNER_FREQ_MIN_FM, &status);
55out:
56 return ret;
57}
58
59#ifdef CONFIG_PM
60static int pm_fm_suspend(struct poseidon *p)
61{
62 logpm(p);
63 pm_alsa_suspend(p);
64 usb_set_interface(p->udev, 0, 0);
65 msleep(300);
66 return 0;
67}
68
69static int pm_fm_resume(struct poseidon *p)
70{
71 logpm(p);
72 poseidon_check_mode_radio(p);
73 set_frequency(p, p->radio_data.fm_freq);
74 pm_alsa_resume(p);
75 return 0;
76}
77#endif
78
79static int poseidon_fm_open(struct file *filp)
80{
81 struct video_device *vfd = video_devdata(filp);
82 struct poseidon *p = video_get_drvdata(vfd);
83 int ret = 0;
84
85 if (!p)
86 return -1;
87
88 mutex_lock(&p->lock);
89 if (p->state & POSEIDON_STATE_DISCONNECT) {
90 ret = -ENODEV;
91 goto out;
92 }
93
94 if (p->state && !(p->state & POSEIDON_STATE_FM)) {
95 ret = -EBUSY;
96 goto out;
97 }
98
99 usb_autopm_get_interface(p->interface);
100 if (0 == p->state) {
101 /* default pre-emphasis */
102 if (p->radio_data.pre_emphasis == 0)
103 p->radio_data.pre_emphasis = TLG_TUNE_ASTD_FM_EUR;
104 set_debug_mode(vfd, debug_mode);
105
106 ret = poseidon_check_mode_radio(p);
107 if (ret < 0) {
108 usb_autopm_put_interface(p->interface);
109 goto out;
110 }
111 p->state |= POSEIDON_STATE_FM;
112 }
113 p->radio_data.users++;
114 kref_get(&p->kref);
115 filp->private_data = p;
116out:
117 mutex_unlock(&p->lock);
118 return ret;
119}
120
121static int poseidon_fm_close(struct file *filp)
122{
123 struct poseidon *p = filp->private_data;
124 struct radio_data *fm = &p->radio_data;
125 uint32_t status;
126
127 mutex_lock(&p->lock);
128 fm->users--;
129 if (0 == fm->users)
130 p->state &= ~POSEIDON_STATE_FM;
131
132 if (fm->is_radio_streaming && filp == p->file_for_stream) {
133 fm->is_radio_streaming = 0;
134 send_set_req(p, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_STOP, &status);
135 }
136 usb_autopm_put_interface(p->interface);
137 mutex_unlock(&p->lock);
138
139 kref_put(&p->kref, poseidon_delete);
140 filp->private_data = NULL;
141 return 0;
142}
143
144static int vidioc_querycap(struct file *file, void *priv,
145 struct v4l2_capability *v)
146{
147 struct poseidon *p = file->private_data;
148
149 strlcpy(v->driver, "tele-radio", sizeof(v->driver));
150 strlcpy(v->card, "Telegent Poseidon", sizeof(v->card));
151 usb_make_path(p->udev, v->bus_info, sizeof(v->bus_info));
152 v->version = KERNEL_VERSION(0, 0, 1);
153 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
154 return 0;
155}
156
157static const struct v4l2_file_operations poseidon_fm_fops = {
158 .owner = THIS_MODULE,
159 .open = poseidon_fm_open,
160 .release = poseidon_fm_close,
161 .ioctl = video_ioctl2,
162};
163
164int tlg_fm_vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *vt)
165{
166 struct tuner_fm_sig_stat_s fm_stat = {};
167 int ret, status, count = 5;
168 struct poseidon *p = file->private_data;
169
170 if (vt->index != 0)
171 return -EINVAL;
172
173 vt->type = V4L2_TUNER_RADIO;
174 vt->capability = V4L2_TUNER_CAP_STEREO;
175 vt->rangelow = TUNER_FREQ_MIN_FM / 62500;
176 vt->rangehigh = TUNER_FREQ_MAX_FM / 62500;
177 vt->rxsubchans = V4L2_TUNER_SUB_STEREO;
178 vt->audmode = V4L2_TUNER_MODE_STEREO;
179 vt->signal = 0;
180 vt->afc = 0;
181
182 mutex_lock(&p->lock);
183 ret = send_get_req(p, TUNER_STATUS, TLG_MODE_FM_RADIO,
184 &fm_stat, &status, sizeof(fm_stat));
185
186 while (fm_stat.sig_lock_busy && count-- && !ret) {
187 set_current_state(TASK_INTERRUPTIBLE);
188 schedule_timeout(HZ);
189
190 ret = send_get_req(p, TUNER_STATUS, TLG_MODE_FM_RADIO,
191 &fm_stat, &status, sizeof(fm_stat));
192 }
193 mutex_unlock(&p->lock);
194
195 if (ret || status) {
196 vt->signal = 0;
197 } else if ((fm_stat.sig_present || fm_stat.sig_locked)
198 && fm_stat.sig_strength == 0) {
199 vt->signal = 0xffff;
200 } else
201 vt->signal = (fm_stat.sig_strength * 255 / 10) << 8;
202
203 return 0;
204}
205
206int fm_get_freq(struct file *file, void *priv, struct v4l2_frequency *argp)
207{
208 struct poseidon *p = file->private_data;
209
210 argp->frequency = p->radio_data.fm_freq;
211 return 0;
212}
213
214static int set_frequency(struct poseidon *p, __u32 frequency)
215{
216 __u32 freq ;
217 int ret, status;
218
219 mutex_lock(&p->lock);
220
221 ret = send_set_req(p, TUNER_AUD_ANA_STD,
222 p->radio_data.pre_emphasis, &status);
223
224 freq = (frequency * 125) * 500 / 1000;/* kHZ */
225 if (freq < TUNER_FREQ_MIN_FM/1000 || freq > TUNER_FREQ_MAX_FM/1000) {
226 ret = -EINVAL;
227 goto error;
228 }
229
230 ret = send_set_req(p, TUNE_FREQ_SELECT, freq, &status);
231 if (ret < 0)
232 goto error ;
233 ret = send_set_req(p, TAKE_REQUEST, 0, &status);
234
235 set_current_state(TASK_INTERRUPTIBLE);
236 schedule_timeout(HZ/4);
237 if (!p->radio_data.is_radio_streaming) {
238 ret = send_set_req(p, TAKE_REQUEST, 0, &status);
239 ret = send_set_req(p, PLAY_SERVICE,
240 TLG_TUNE_PLAY_SVC_START, &status);
241 p->radio_data.is_radio_streaming = 1;
242 }
243 p->radio_data.fm_freq = frequency;
244error:
245 mutex_unlock(&p->lock);
246 return ret;
247}
248
249int fm_set_freq(struct file *file, void *priv, struct v4l2_frequency *argp)
250{
251 struct poseidon *p = file->private_data;
252
253 p->file_for_stream = file;
254#ifdef CONFIG_PM
255 p->pm_suspend = pm_fm_suspend;
256 p->pm_resume = pm_fm_resume;
257#endif
258 return set_frequency(p, argp->frequency);
259}
260
261int tlg_fm_vidioc_g_ctrl(struct file *file, void *priv,
262 struct v4l2_control *arg)
263{
264 return 0;
265}
266
267int tlg_fm_vidioc_g_exts_ctrl(struct file *file, void *fh,
268 struct v4l2_ext_controls *ctrls)
269{
270 struct poseidon *p = file->private_data;
271 int i;
272
273 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_FM_TX)
274 return -EINVAL;
275
276 for (i = 0; i < ctrls->count; i++) {
277 struct v4l2_ext_control *ctrl = ctrls->controls + i;
278
279 if (ctrl->id != V4L2_CID_TUNE_PREEMPHASIS)
280 continue;
281
282 if (i < MAX_PREEMPHASIS)
283 ctrl->value = p->radio_data.pre_emphasis;
284 }
285 return 0;
286}
287
288int tlg_fm_vidioc_s_exts_ctrl(struct file *file, void *fh,
289 struct v4l2_ext_controls *ctrls)
290{
291 int i;
292
293 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_FM_TX)
294 return -EINVAL;
295
296 for (i = 0; i < ctrls->count; i++) {
297 struct v4l2_ext_control *ctrl = ctrls->controls + i;
298
299 if (ctrl->id != V4L2_CID_TUNE_PREEMPHASIS)
300 continue;
301
302 if (ctrl->value >= 0 && ctrl->value < MAX_PREEMPHASIS) {
303 struct poseidon *p = file->private_data;
304 int pre_emphasis = preemphasis[ctrl->value];
305 u32 status;
306
307 send_set_req(p, TUNER_AUD_ANA_STD,
308 pre_emphasis, &status);
309 p->radio_data.pre_emphasis = pre_emphasis;
310 }
311 }
312 return 0;
313}
314
315int tlg_fm_vidioc_s_ctrl(struct file *file, void *priv,
316 struct v4l2_control *ctrl)
317{
318 return 0;
319}
320
321int tlg_fm_vidioc_queryctrl(struct file *file, void *priv,
322 struct v4l2_queryctrl *ctrl)
323{
324 if (!(ctrl->id & V4L2_CTRL_FLAG_NEXT_CTRL))
325 return -EINVAL;
326
327 ctrl->id &= ~V4L2_CTRL_FLAG_NEXT_CTRL;
328 if (ctrl->id != V4L2_CID_TUNE_PREEMPHASIS) {
329 /* return the next supported control */
330 ctrl->id = V4L2_CID_TUNE_PREEMPHASIS;
331 v4l2_ctrl_query_fill(ctrl, V4L2_PREEMPHASIS_DISABLED,
332 V4L2_PREEMPHASIS_75_uS, 1,
333 V4L2_PREEMPHASIS_50_uS);
334 ctrl->flags = V4L2_CTRL_FLAG_UPDATE;
335 return 0;
336 }
337 return -EINVAL;
338}
339
340int tlg_fm_vidioc_querymenu(struct file *file, void *fh,
341 struct v4l2_querymenu *qmenu)
342{
343 return v4l2_ctrl_query_menu(qmenu, NULL, NULL);
344}
345
346static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *vt)
347{
348 return vt->index > 0 ? -EINVAL : 0;
349}
350static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *va)
351{
352 return (va->index != 0) ? -EINVAL : 0;
353}
354
355static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
356{
357 a->index = 0;
358 a->mode = 0;
359 a->capability = V4L2_AUDCAP_STEREO;
360 strcpy(a->name, "Radio");
361 return 0;
362}
363
364static int vidioc_s_input(struct file *filp, void *priv, u32 i)
365{
366 return (i != 0) ? -EINVAL : 0;
367}
368
369static int vidioc_g_input(struct file *filp, void *priv, u32 *i)
370{
371 return (*i != 0) ? -EINVAL : 0;
372}
373
374static const struct v4l2_ioctl_ops poseidon_fm_ioctl_ops = {
375 .vidioc_querycap = vidioc_querycap,
376 .vidioc_g_audio = vidioc_g_audio,
377 .vidioc_s_audio = vidioc_s_audio,
378 .vidioc_g_input = vidioc_g_input,
379 .vidioc_s_input = vidioc_s_input,
380 .vidioc_queryctrl = tlg_fm_vidioc_queryctrl,
381 .vidioc_querymenu = tlg_fm_vidioc_querymenu,
382 .vidioc_g_ctrl = tlg_fm_vidioc_g_ctrl,
383 .vidioc_s_ctrl = tlg_fm_vidioc_s_ctrl,
384 .vidioc_s_ext_ctrls = tlg_fm_vidioc_s_exts_ctrl,
385 .vidioc_g_ext_ctrls = tlg_fm_vidioc_g_exts_ctrl,
386 .vidioc_s_tuner = vidioc_s_tuner,
387 .vidioc_g_tuner = tlg_fm_vidioc_g_tuner,
388 .vidioc_g_frequency = fm_get_freq,
389 .vidioc_s_frequency = fm_set_freq,
390};
391
392static struct video_device poseidon_fm_template = {
393 .name = "Telegent-Radio",
394 .fops = &poseidon_fm_fops,
395 .minor = -1,
396 .release = video_device_release,
397 .ioctl_ops = &poseidon_fm_ioctl_ops,
398};
399
400int poseidon_fm_init(struct poseidon *p)
401{
402 struct video_device *fm_dev;
403
404 fm_dev = vdev_init(p, &poseidon_fm_template);
405 if (fm_dev == NULL)
406 return -1;
407
408 if (video_register_device(fm_dev, VFL_TYPE_RADIO, -1) < 0) {
409 video_device_release(fm_dev);
410 return -1;
411 }
412 p->radio_data.fm_dev = fm_dev;
413 return 0;
414}
415
416int poseidon_fm_exit(struct poseidon *p)
417{
418 destroy_video_device(&p->radio_data.fm_dev);
419 return 0;
420}
diff --git a/drivers/media/video/tlg2300/pd-video.c b/drivers/media/video/tlg2300/pd-video.c
new file mode 100644
index 000000000000..becfba6a3041
--- /dev/null
+++ b/drivers/media/video/tlg2300/pd-video.c
@@ -0,0 +1,1667 @@
1#include <linux/fs.h>
2#include <linux/vmalloc.h>
3#include <linux/videodev2.h>
4#include <linux/usb.h>
5#include <linux/mm.h>
6#include <linux/sched.h>
7
8#include <media/v4l2-ioctl.h>
9#include <media/v4l2-dev.h>
10
11#include "pd-common.h"
12#include "vendorcmds.h"
13
14static int pm_video_suspend(struct poseidon *pd);
15static int pm_video_resume(struct poseidon *pd);
16static void iso_bubble_handler(struct work_struct *w);
17
18int usb_transfer_mode;
19module_param(usb_transfer_mode, int, 0644);
20MODULE_PARM_DESC(usb_transfer_mode, "0 = Bulk, 1 = Isochronous");
21
22static const struct poseidon_format poseidon_formats[] = {
23 { "YUV 422", V4L2_PIX_FMT_YUYV, 16, 0},
24 { "RGB565", V4L2_PIX_FMT_RGB565, 16, 0},
25};
26
27static const struct poseidon_tvnorm poseidon_tvnorms[] = {
28 { V4L2_STD_PAL_D, "PAL-D", TLG_TUNE_VSTD_PAL_D },
29 { V4L2_STD_PAL_B, "PAL-B", TLG_TUNE_VSTD_PAL_B },
30 { V4L2_STD_PAL_G, "PAL-G", TLG_TUNE_VSTD_PAL_G },
31 { V4L2_STD_PAL_H, "PAL-H", TLG_TUNE_VSTD_PAL_H },
32 { V4L2_STD_PAL_I, "PAL-I", TLG_TUNE_VSTD_PAL_I },
33 { V4L2_STD_PAL_M, "PAL-M", TLG_TUNE_VSTD_PAL_M },
34 { V4L2_STD_PAL_N, "PAL-N", TLG_TUNE_VSTD_PAL_N_COMBO },
35 { V4L2_STD_PAL_Nc, "PAL-Nc", TLG_TUNE_VSTD_PAL_N_COMBO },
36 { V4L2_STD_NTSC_M, "NTSC-M", TLG_TUNE_VSTD_NTSC_M },
37 { V4L2_STD_NTSC_M_JP, "NTSC-JP", TLG_TUNE_VSTD_NTSC_M_J },
38 { V4L2_STD_SECAM_B, "SECAM-B", TLG_TUNE_VSTD_SECAM_B },
39 { V4L2_STD_SECAM_D, "SECAM-D", TLG_TUNE_VSTD_SECAM_D },
40 { V4L2_STD_SECAM_G, "SECAM-G", TLG_TUNE_VSTD_SECAM_G },
41 { V4L2_STD_SECAM_H, "SECAM-H", TLG_TUNE_VSTD_SECAM_H },
42 { V4L2_STD_SECAM_K, "SECAM-K", TLG_TUNE_VSTD_SECAM_K },
43 { V4L2_STD_SECAM_K1, "SECAM-K1", TLG_TUNE_VSTD_SECAM_K1 },
44 { V4L2_STD_SECAM_L, "SECAM-L", TLG_TUNE_VSTD_SECAM_L },
45 { V4L2_STD_SECAM_LC, "SECAM-LC", TLG_TUNE_VSTD_SECAM_L1 },
46};
47static const unsigned int POSEIDON_TVNORMS = ARRAY_SIZE(poseidon_tvnorms);
48
49struct pd_audio_mode {
50 u32 tlg_audio_mode;
51 u32 v4l2_audio_sub;
52 u32 v4l2_audio_mode;
53};
54
55static const struct pd_audio_mode pd_audio_modes[] = {
56 { TLG_TUNE_TVAUDIO_MODE_MONO, V4L2_TUNER_SUB_MONO,
57 V4L2_TUNER_MODE_MONO },
58 { TLG_TUNE_TVAUDIO_MODE_STEREO, V4L2_TUNER_SUB_STEREO,
59 V4L2_TUNER_MODE_STEREO },
60 { TLG_TUNE_TVAUDIO_MODE_LANG_A, V4L2_TUNER_SUB_LANG1,
61 V4L2_TUNER_MODE_LANG1 },
62 { TLG_TUNE_TVAUDIO_MODE_LANG_B, V4L2_TUNER_SUB_LANG2,
63 V4L2_TUNER_MODE_LANG2 },
64 { TLG_TUNE_TVAUDIO_MODE_LANG_C, V4L2_TUNER_SUB_LANG1,
65 V4L2_TUNER_MODE_LANG1_LANG2 }
66};
67static const unsigned int POSEIDON_AUDIOMODS = ARRAY_SIZE(pd_audio_modes);
68
69struct pd_input {
70 char *name;
71 uint32_t tlg_src;
72};
73
74static const struct pd_input pd_inputs[] = {
75 { "TV Antenna", TLG_SIG_SRC_ANTENNA },
76 { "TV Cable", TLG_SIG_SRC_CABLE },
77 { "TV SVideo", TLG_SIG_SRC_SVIDEO },
78 { "TV Composite", TLG_SIG_SRC_COMPOSITE }
79};
80static const unsigned int POSEIDON_INPUTS = ARRAY_SIZE(pd_inputs);
81
82struct poseidon_control {
83 struct v4l2_queryctrl v4l2_ctrl;
84 enum cmd_custom_param_id vc_id;
85};
86
87static struct poseidon_control controls[] = {
88 {
89 { V4L2_CID_BRIGHTNESS, V4L2_CTRL_TYPE_INTEGER,
90 "brightness", 0, 10000, 1, 100, 0, },
91 CUST_PARM_ID_BRIGHTNESS_CTRL
92 }, {
93 { V4L2_CID_CONTRAST, V4L2_CTRL_TYPE_INTEGER,
94 "contrast", 0, 10000, 1, 100, 0, },
95 CUST_PARM_ID_CONTRAST_CTRL,
96 }, {
97 { V4L2_CID_HUE, V4L2_CTRL_TYPE_INTEGER,
98 "hue", 0, 10000, 1, 100, 0, },
99 CUST_PARM_ID_HUE_CTRL,
100 }, {
101 { V4L2_CID_SATURATION, V4L2_CTRL_TYPE_INTEGER,
102 "saturation", 0, 10000, 1, 100, 0, },
103 CUST_PARM_ID_SATURATION_CTRL,
104 },
105};
106
107struct video_std_to_audio_std {
108 v4l2_std_id video_std;
109 int audio_std;
110};
111
112static const struct video_std_to_audio_std video_to_audio_map[] = {
113 /* country : { 27, 32, 33, 34, 36, 44, 45, 46, 47, 48, 64,
114 65, 86, 351, 352, 353, 354, 358, 372, 852, 972 } */
115 { (V4L2_STD_PAL_I | V4L2_STD_PAL_B | V4L2_STD_PAL_D |
116 V4L2_STD_SECAM_L | V4L2_STD_SECAM_D), TLG_TUNE_ASTD_NICAM },
117
118 /* country : { 1, 52, 54, 55, 886 } */
119 {V4L2_STD_NTSC_M | V4L2_STD_PAL_N | V4L2_STD_PAL_M, TLG_TUNE_ASTD_BTSC},
120
121 /* country : { 81 } */
122 { V4L2_STD_NTSC_M_JP, TLG_TUNE_ASTD_EIAJ },
123
124 /* other country : TLG_TUNE_ASTD_A2 */
125};
126static const unsigned int map_size = ARRAY_SIZE(video_to_audio_map);
127
128static int get_audio_std(v4l2_std_id v4l2_std)
129{
130 int i = 0;
131
132 for (; i < map_size; i++) {
133 if (v4l2_std & video_to_audio_map[i].video_std)
134 return video_to_audio_map[i].audio_std;
135 }
136 return TLG_TUNE_ASTD_A2;
137}
138
139static int vidioc_querycap(struct file *file, void *fh,
140 struct v4l2_capability *cap)
141{
142 struct front_face *front = fh;
143 struct poseidon *p = front->pd;
144
145 logs(front);
146
147 strcpy(cap->driver, "tele-video");
148 strcpy(cap->card, "Telegent Poseidon");
149 usb_make_path(p->udev, cap->bus_info, sizeof(cap->bus_info));
150 cap->version = KERNEL_VERSION(0, 0, 1);
151 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER |
152 V4L2_CAP_AUDIO | V4L2_CAP_STREAMING |
153 V4L2_CAP_READWRITE | V4L2_CAP_VBI_CAPTURE;
154 return 0;
155}
156
157/*====================================================================*/
158static void init_copy(struct video_data *video, bool index)
159{
160 struct front_face *front = video->front;
161
162 video->field_count = index;
163 video->lines_copied = 0;
164 video->prev_left = 0 ;
165 video->dst = (char *)videobuf_to_vmalloc(front->curr_frame)
166 + index * video->lines_size;
167 video->vbi->copied = 0; /* set it here */
168}
169
170static bool get_frame(struct front_face *front, int *need_init)
171{
172 struct videobuf_buffer *vb = front->curr_frame;
173
174 if (vb)
175 return true;
176
177 spin_lock(&front->queue_lock);
178 if (!list_empty(&front->active)) {
179 vb = list_entry(front->active.next,
180 struct videobuf_buffer, queue);
181 if (need_init)
182 *need_init = 1;
183 front->curr_frame = vb;
184 list_del_init(&vb->queue);
185 }
186 spin_unlock(&front->queue_lock);
187
188 return !!vb;
189}
190
191/* check if the video's buffer is ready */
192static bool get_video_frame(struct front_face *front, struct video_data *video)
193{
194 int need_init = 0;
195 bool ret = true;
196
197 ret = get_frame(front, &need_init);
198 if (ret && need_init)
199 init_copy(video, 0);
200 return ret;
201}
202
203static void submit_frame(struct front_face *front)
204{
205 struct videobuf_buffer *vb = front->curr_frame;
206
207 if (vb == NULL)
208 return;
209
210 front->curr_frame = NULL;
211 vb->state = VIDEOBUF_DONE;
212 vb->field_count++;
213 do_gettimeofday(&vb->ts);
214
215 wake_up(&vb->done);
216}
217
218/*
219 * A frame is composed of two fields. If we receive all the two fields,
220 * call the submit_frame() to submit the whole frame to applications.
221 */
222static void end_field(struct video_data *video)
223{
224 /* logs(video->front); */
225 if (1 == video->field_count)
226 submit_frame(video->front);
227 else
228 init_copy(video, 1);
229}
230
231static void copy_video_data(struct video_data *video, char *src,
232 unsigned int count)
233{
234#define copy_data(len) \
235 do { \
236 if (++video->lines_copied > video->lines_per_field) \
237 goto overflow; \
238 memcpy(video->dst, src, len);\
239 video->dst += len + video->lines_size; \
240 src += len; \
241 count -= len; \
242 } while (0)
243
244 while (count && count >= video->lines_size) {
245 if (video->prev_left) {
246 copy_data(video->prev_left);
247 video->prev_left = 0;
248 continue;
249 }
250 copy_data(video->lines_size);
251 }
252 if (count && count < video->lines_size) {
253 memcpy(video->dst, src, count);
254
255 video->prev_left = video->lines_size - count;
256 video->dst += count;
257 }
258 return;
259
260overflow:
261 end_field(video);
262}
263
264static void check_trailer(struct video_data *video, char *src, int count)
265{
266 struct vbi_data *vbi = video->vbi;
267 int offset; /* trailer's offset */
268 char *buf;
269
270 offset = (video->context.pix.sizeimage / 2 + vbi->vbi_size / 2)
271 - (vbi->copied + video->lines_size * video->lines_copied);
272 if (video->prev_left)
273 offset -= (video->lines_size - video->prev_left);
274
275 if (offset > count || offset <= 0)
276 goto short_package;
277
278 buf = src + offset;
279
280 /* trailer : (VFHS) + U32 + U32 + field_num */
281 if (!strncmp(buf, "VFHS", 4)) {
282 int field_num = *((u32 *)(buf + 12));
283
284 if ((field_num & 1) ^ video->field_count) {
285 init_copy(video, video->field_count);
286 return;
287 }
288 copy_video_data(video, src, offset);
289 }
290short_package:
291 end_field(video);
292}
293
294/* ========== Check this more carefully! =========== */
295static inline void copy_vbi_data(struct vbi_data *vbi,
296 char *src, unsigned int count)
297{
298 struct front_face *front = vbi->front;
299
300 if (front && get_frame(front, NULL)) {
301 char *buf = videobuf_to_vmalloc(front->curr_frame);
302
303 if (vbi->video->field_count)
304 buf += (vbi->vbi_size / 2);
305 memcpy(buf + vbi->copied, src, count);
306 }
307 vbi->copied += count;
308}
309
310/*
311 * Copy the normal data (VBI or VIDEO) without the trailer.
312 * VBI is not interlaced, while VIDEO is interlaced.
313 */
314static inline void copy_vbi_video_data(struct video_data *video,
315 char *src, unsigned int count)
316{
317 struct vbi_data *vbi = video->vbi;
318 unsigned int vbi_delta = (vbi->vbi_size / 2) - vbi->copied;
319
320 if (vbi_delta >= count) {
321 copy_vbi_data(vbi, src, count);
322 } else {
323 if (vbi_delta) {
324 copy_vbi_data(vbi, src, vbi_delta);
325
326 /* we receive the two fields of the VBI*/
327 if (vbi->front && video->field_count)
328 submit_frame(vbi->front);
329 }
330 copy_video_data(video, src + vbi_delta, count - vbi_delta);
331 }
332}
333
334static void urb_complete_bulk(struct urb *urb)
335{
336 struct front_face *front = urb->context;
337 struct video_data *video = &front->pd->video_data;
338 char *src = (char *)urb->transfer_buffer;
339 int count = urb->actual_length;
340 int ret = 0;
341
342 if (!video->is_streaming || urb->status) {
343 if (urb->status == -EPROTO)
344 goto resend_it;
345 return;
346 }
347 if (!get_video_frame(front, video))
348 goto resend_it;
349
350 if (count == urb->transfer_buffer_length)
351 copy_vbi_video_data(video, src, count);
352 else
353 check_trailer(video, src, count);
354
355resend_it:
356 ret = usb_submit_urb(urb, GFP_ATOMIC);
357 if (ret)
358 log(" submit failed: error %d", ret);
359}
360
361/************************* for ISO *********************/
362#define GET_SUCCESS (0)
363#define GET_TRAILER (1)
364#define GET_TOO_MUCH_BUBBLE (2)
365#define GET_NONE (3)
366static int get_chunk(int start, struct urb *urb,
367 int *head, int *tail, int *bubble_err)
368{
369 struct usb_iso_packet_descriptor *pkt = NULL;
370 int ret = GET_SUCCESS;
371
372 for (*head = *tail = -1; start < urb->number_of_packets; start++) {
373 pkt = &urb->iso_frame_desc[start];
374
375 /* handle the bubble of the Hub */
376 if (-EOVERFLOW == pkt->status) {
377 if (++*bubble_err > urb->number_of_packets / 3)
378 return GET_TOO_MUCH_BUBBLE;
379 continue;
380 }
381
382 /* This is the gap */
383 if (pkt->status || pkt->actual_length <= 0
384 || pkt->actual_length > ISO_PKT_SIZE) {
385 if (*head != -1)
386 break;
387 continue;
388 }
389
390 /* a good isochronous packet */
391 if (pkt->actual_length == ISO_PKT_SIZE) {
392 if (*head == -1)
393 *head = start;
394 *tail = start;
395 continue;
396 }
397
398 /* trailer is here */
399 if (pkt->actual_length < ISO_PKT_SIZE) {
400 if (*head == -1) {
401 *head = start;
402 *tail = start;
403 return GET_TRAILER;
404 }
405 break;
406 }
407 }
408
409 if (*head == -1 && *tail == -1)
410 ret = GET_NONE;
411 return ret;
412}
413
414/*
415 * |__|------|___|-----|_______|
416 * ^ ^
417 * | |
418 * gap gap
419 */
420static void urb_complete_iso(struct urb *urb)
421{
422 struct front_face *front = urb->context;
423 struct video_data *video = &front->pd->video_data;
424 int bubble_err = 0, head = 0, tail = 0;
425 char *src = (char *)urb->transfer_buffer;
426 int ret = 0;
427
428 if (!video->is_streaming)
429 return;
430
431 do {
432 if (!get_video_frame(front, video))
433 goto out;
434
435 switch (get_chunk(head, urb, &head, &tail, &bubble_err)) {
436 case GET_SUCCESS:
437 copy_vbi_video_data(video, src + (head * ISO_PKT_SIZE),
438 (tail - head + 1) * ISO_PKT_SIZE);
439 break;
440 case GET_TRAILER:
441 check_trailer(video, src + (head * ISO_PKT_SIZE),
442 ISO_PKT_SIZE);
443 break;
444 case GET_NONE:
445 goto out;
446 case GET_TOO_MUCH_BUBBLE:
447 log("\t We got too much bubble");
448 schedule_work(&video->bubble_work);
449 return;
450 }
451 } while (head = tail + 1, head < urb->number_of_packets);
452
453out:
454 ret = usb_submit_urb(urb, GFP_ATOMIC);
455 if (ret)
456 log("usb_submit_urb err : %d", ret);
457}
458/*============================= [ end ] =====================*/
459
460static int prepare_iso_urb(struct video_data *video)
461{
462 struct usb_device *udev = video->pd->udev;
463 int i;
464
465 if (video->urb_array[0])
466 return 0;
467
468 for (i = 0; i < SBUF_NUM; i++) {
469 struct urb *urb;
470 void *mem;
471 int j;
472
473 urb = usb_alloc_urb(PK_PER_URB, GFP_KERNEL);
474 if (urb == NULL)
475 goto out;
476
477 video->urb_array[i] = urb;
478 mem = usb_buffer_alloc(udev,
479 ISO_PKT_SIZE * PK_PER_URB,
480 GFP_KERNEL,
481 &urb->transfer_dma);
482
483 urb->complete = urb_complete_iso; /* handler */
484 urb->dev = udev;
485 urb->context = video->front;
486 urb->pipe = usb_rcvisocpipe(udev,
487 video->endpoint_addr);
488 urb->interval = 1;
489 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
490 urb->number_of_packets = PK_PER_URB;
491 urb->transfer_buffer = mem;
492 urb->transfer_buffer_length = PK_PER_URB * ISO_PKT_SIZE;
493
494 for (j = 0; j < PK_PER_URB; j++) {
495 urb->iso_frame_desc[j].offset = ISO_PKT_SIZE * j;
496 urb->iso_frame_desc[j].length = ISO_PKT_SIZE;
497 }
498 }
499 return 0;
500out:
501 for (; i > 0; i--)
502 ;
503 return -ENOMEM;
504}
505
506/* return the succeeded number of the allocation */
507int alloc_bulk_urbs_generic(struct urb **urb_array, int num,
508 struct usb_device *udev, u8 ep_addr,
509 int buf_size, gfp_t gfp_flags,
510 usb_complete_t complete_fn, void *context)
511{
512 struct urb *urb;
513 void *mem;
514 int i;
515
516 for (i = 0; i < num; i++) {
517 urb = usb_alloc_urb(0, gfp_flags);
518 if (urb == NULL)
519 return i;
520
521 mem = usb_buffer_alloc(udev, buf_size, gfp_flags,
522 &urb->transfer_dma);
523 if (mem == NULL)
524 return i;
525
526 usb_fill_bulk_urb(urb, udev, usb_rcvbulkpipe(udev, ep_addr),
527 mem, buf_size, complete_fn, context);
528 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
529 urb_array[i] = urb;
530 }
531 return i;
532}
533
534void free_all_urb_generic(struct urb **urb_array, int num)
535{
536 int i;
537 struct urb *urb;
538
539 for (i = 0; i < num; i++) {
540 urb = urb_array[i];
541 if (urb) {
542 usb_buffer_free(urb->dev,
543 urb->transfer_buffer_length,
544 urb->transfer_buffer,
545 urb->transfer_dma);
546 usb_free_urb(urb);
547 urb_array[i] = NULL;
548 }
549 }
550}
551
552static int prepare_bulk_urb(struct video_data *video)
553{
554 if (video->urb_array[0])
555 return 0;
556
557 alloc_bulk_urbs_generic(video->urb_array, SBUF_NUM,
558 video->pd->udev, video->endpoint_addr,
559 0x2000, GFP_KERNEL,
560 urb_complete_bulk, video->front);
561 return 0;
562}
563
564/* free the URBs */
565static void free_all_urb(struct video_data *video)
566{
567 free_all_urb_generic(video->urb_array, SBUF_NUM);
568}
569
570static void pd_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
571{
572 videobuf_vmalloc_free(vb);
573 vb->state = VIDEOBUF_NEEDS_INIT;
574}
575
576static void pd_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
577{
578 struct front_face *front = q->priv_data;
579 vb->state = VIDEOBUF_QUEUED;
580 list_add_tail(&vb->queue, &front->active);
581}
582
583static int pd_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
584 enum v4l2_field field)
585{
586 struct front_face *front = q->priv_data;
587 int rc;
588
589 switch (front->type) {
590 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
591 if (VIDEOBUF_NEEDS_INIT == vb->state) {
592 struct v4l2_pix_format *pix;
593
594 pix = &front->pd->video_data.context.pix;
595 vb->size = pix->sizeimage; /* real frame size */
596 vb->width = pix->width;
597 vb->height = pix->height;
598 rc = videobuf_iolock(q, vb, NULL);
599 if (rc < 0)
600 return rc;
601 }
602 break;
603 case V4L2_BUF_TYPE_VBI_CAPTURE:
604 if (VIDEOBUF_NEEDS_INIT == vb->state) {
605 vb->size = front->pd->vbi_data.vbi_size;
606 rc = videobuf_iolock(q, vb, NULL);
607 if (rc < 0)
608 return rc;
609 }
610 break;
611 default:
612 return -EINVAL;
613 }
614 vb->field = field;
615 vb->state = VIDEOBUF_PREPARED;
616 return 0;
617}
618
619int fire_all_urb(struct video_data *video)
620{
621 int i, ret;
622
623 video->is_streaming = 1;
624
625 for (i = 0; i < SBUF_NUM; i++) {
626 ret = usb_submit_urb(video->urb_array[i], GFP_KERNEL);
627 if (ret)
628 log("(%d) failed: error %d", i, ret);
629 }
630 return ret;
631}
632
633static int start_video_stream(struct poseidon *pd)
634{
635 struct video_data *video = &pd->video_data;
636 s32 cmd_status;
637
638 send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
639 send_set_req(pd, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_START, &cmd_status);
640
641 if (pd->cur_transfer_mode) {
642 prepare_iso_urb(video);
643 INIT_WORK(&video->bubble_work, iso_bubble_handler);
644 } else {
645 /* The bulk mode does not need a bubble handler */
646 prepare_bulk_urb(video);
647 }
648 fire_all_urb(video);
649 return 0;
650}
651
652static int pd_buf_setup(struct videobuf_queue *q, unsigned int *count,
653 unsigned int *size)
654{
655 struct front_face *front = q->priv_data;
656 struct poseidon *pd = front->pd;
657
658 switch (front->type) {
659 default:
660 return -EINVAL;
661 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
662 struct video_data *video = &pd->video_data;
663 struct v4l2_pix_format *pix = &video->context.pix;
664
665 *size = PAGE_ALIGN(pix->sizeimage);/* page aligned frame size */
666 if (*count < 4)
667 *count = 4;
668 if (1) {
669 /* same in different altersetting */
670 video->endpoint_addr = 0x82;
671 video->vbi = &pd->vbi_data;
672 video->vbi->video = video;
673 video->pd = pd;
674 video->lines_per_field = pix->height / 2;
675 video->lines_size = pix->width * 2;
676 video->front = front;
677 }
678 return start_video_stream(pd);
679 }
680
681 case V4L2_BUF_TYPE_VBI_CAPTURE: {
682 struct vbi_data *vbi = &pd->vbi_data;
683
684 *size = PAGE_ALIGN(vbi->vbi_size);
685 log("size : %d", *size);
686 if (*count == 0)
687 *count = 4;
688 }
689 break;
690 }
691 return 0;
692}
693
694static struct videobuf_queue_ops pd_video_qops = {
695 .buf_setup = pd_buf_setup,
696 .buf_prepare = pd_buf_prepare,
697 .buf_queue = pd_buf_queue,
698 .buf_release = pd_buf_release,
699};
700
701static int vidioc_enum_fmt(struct file *file, void *fh,
702 struct v4l2_fmtdesc *f)
703{
704 if (ARRAY_SIZE(poseidon_formats) <= f->index)
705 return -EINVAL;
706 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
707 f->flags = 0;
708 f->pixelformat = poseidon_formats[f->index].fourcc;
709 strcpy(f->description, poseidon_formats[f->index].name);
710 return 0;
711}
712
713static int vidioc_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
714{
715 struct front_face *front = fh;
716 struct poseidon *pd = front->pd;
717
718 logs(front);
719 f->fmt.pix = pd->video_data.context.pix;
720 return 0;
721}
722
723static int vidioc_try_fmt(struct file *file, void *fh,
724 struct v4l2_format *f)
725{
726 return 0;
727}
728
729/*
730 * VLC calls VIDIOC_S_STD before VIDIOC_S_FMT, while
731 * Mplayer calls them in the reverse order.
732 */
733static int pd_vidioc_s_fmt(struct poseidon *pd, struct v4l2_pix_format *pix)
734{
735 struct video_data *video = &pd->video_data;
736 struct running_context *context = &video->context;
737 struct v4l2_pix_format *pix_def = &context->pix;
738 s32 ret = 0, cmd_status = 0, vid_resol;
739
740 /* set the pixel format to firmware */
741 if (pix->pixelformat == V4L2_PIX_FMT_RGB565) {
742 vid_resol = TLG_TUNER_VID_FORMAT_RGB_565;
743 } else {
744 pix->pixelformat = V4L2_PIX_FMT_YUYV;
745 vid_resol = TLG_TUNER_VID_FORMAT_YUV;
746 }
747 ret = send_set_req(pd, VIDEO_STREAM_FMT_SEL,
748 vid_resol, &cmd_status);
749
750 /* set the resolution to firmware */
751 vid_resol = TLG_TUNE_VID_RES_720;
752 switch (pix->width) {
753 case 704:
754 vid_resol = TLG_TUNE_VID_RES_704;
755 break;
756 default:
757 pix->width = 720;
758 case 720:
759 break;
760 }
761 ret |= send_set_req(pd, VIDEO_ROSOLU_SEL,
762 vid_resol, &cmd_status);
763 if (ret || cmd_status) {
764 mutex_unlock(&pd->lock);
765 return -EBUSY;
766 }
767
768 pix_def->pixelformat = pix->pixelformat; /* save it */
769 pix->height = (context->tvnormid & V4L2_STD_525_60) ? 480 : 576;
770
771 /* Compare with the default setting */
772 if ((pix_def->width != pix->width)
773 || (pix_def->height != pix->height)) {
774 pix_def->width = pix->width;
775 pix_def->height = pix->height;
776 pix_def->bytesperline = pix->width * 2;
777 pix_def->sizeimage = pix->width * pix->height * 2;
778 }
779 *pix = *pix_def;
780
781 return 0;
782}
783
784static int vidioc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
785{
786 struct front_face *front = fh;
787 struct poseidon *pd = front->pd;
788
789 logs(front);
790 /* stop VBI here */
791 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
792 return -EINVAL;
793
794 mutex_lock(&pd->lock);
795 if (pd->file_for_stream == NULL)
796 pd->file_for_stream = file;
797 else if (file != pd->file_for_stream) {
798 mutex_unlock(&pd->lock);
799 return -EINVAL;
800 }
801
802 pd_vidioc_s_fmt(pd, &f->fmt.pix);
803 mutex_unlock(&pd->lock);
804 return 0;
805}
806
807static int vidioc_g_fmt_vbi(struct file *file, void *fh,
808 struct v4l2_format *v4l2_f)
809{
810 struct front_face *front = fh;
811 struct poseidon *pd = front->pd;
812 struct v4l2_vbi_format *vbi_fmt = &v4l2_f->fmt.vbi;
813
814 vbi_fmt->samples_per_line = 720 * 2;
815 vbi_fmt->sampling_rate = 6750000 * 4;
816 vbi_fmt->sample_format = V4L2_PIX_FMT_GREY;
817 vbi_fmt->offset = 64 * 4; /*FIXME: why offset */
818 if (pd->video_data.context.tvnormid & V4L2_STD_525_60) {
819 vbi_fmt->start[0] = 10;
820 vbi_fmt->start[1] = 264;
821 vbi_fmt->count[0] = V4L_NTSC_VBI_LINES;
822 vbi_fmt->count[1] = V4L_NTSC_VBI_LINES;
823 } else {
824 vbi_fmt->start[0] = 6;
825 vbi_fmt->start[1] = 314;
826 vbi_fmt->count[0] = V4L_PAL_VBI_LINES;
827 vbi_fmt->count[1] = V4L_PAL_VBI_LINES;
828 }
829 vbi_fmt->flags = V4L2_VBI_UNSYNC;
830 logs(front);
831 return 0;
832}
833
834static int set_std(struct poseidon *pd, v4l2_std_id *norm)
835{
836 struct video_data *video = &pd->video_data;
837 struct vbi_data *vbi = &pd->vbi_data;
838 struct running_context *context;
839 struct v4l2_pix_format *pix;
840 s32 i, ret = 0, cmd_status, param;
841 int height;
842
843 for (i = 0; i < POSEIDON_TVNORMS; i++) {
844 if (*norm & poseidon_tvnorms[i].v4l2_id) {
845 param = poseidon_tvnorms[i].tlg_tvnorm;
846 log("name : %s", poseidon_tvnorms[i].name);
847 goto found;
848 }
849 }
850 return -EINVAL;
851found:
852 mutex_lock(&pd->lock);
853 ret = send_set_req(pd, VIDEO_STD_SEL, param, &cmd_status);
854 if (ret || cmd_status)
855 goto out;
856
857 /* Set vbi size and check the height of the frame */
858 context = &video->context;
859 context->tvnormid = poseidon_tvnorms[i].v4l2_id;
860 if (context->tvnormid & V4L2_STD_525_60) {
861 vbi->vbi_size = V4L_NTSC_VBI_FRAMESIZE;
862 height = 480;
863 } else {
864 vbi->vbi_size = V4L_PAL_VBI_FRAMESIZE;
865 height = 576;
866 }
867
868 pix = &context->pix;
869 if (pix->height != height) {
870 pix->height = height;
871 pix->sizeimage = pix->width * pix->height * 2;
872 }
873
874out:
875 mutex_unlock(&pd->lock);
876 return ret;
877}
878
879int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *norm)
880{
881 struct front_face *front = fh;
882 logs(front);
883 return set_std(front->pd, norm);
884}
885
886static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *in)
887{
888 struct front_face *front = fh;
889
890 if (in->index < 0 || in->index >= POSEIDON_INPUTS)
891 return -EINVAL;
892 strcpy(in->name, pd_inputs[in->index].name);
893 in->type = V4L2_INPUT_TYPE_TUNER;
894
895 /*
896 * the audio input index mixed with this video input,
897 * Poseidon only have one audio/video, set to "0"
898 */
899 in->audioset = 0;
900 in->tuner = 0;
901 in->std = V4L2_STD_ALL;
902 in->status = 0;
903 logs(front);
904 return 0;
905}
906
907static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
908{
909 struct front_face *front = fh;
910 struct poseidon *pd = front->pd;
911 struct running_context *context = &pd->video_data.context;
912
913 logs(front);
914 *i = context->sig_index;
915 return 0;
916}
917
918/* We can support several inputs */
919static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
920{
921 struct front_face *front = fh;
922 struct poseidon *pd = front->pd;
923 s32 ret, cmd_status;
924
925 if (i < 0 || i >= POSEIDON_INPUTS)
926 return -EINVAL;
927 ret = send_set_req(pd, SGNL_SRC_SEL,
928 pd_inputs[i].tlg_src, &cmd_status);
929 if (ret)
930 return ret;
931
932 pd->video_data.context.sig_index = i;
933 return 0;
934}
935
936static struct poseidon_control *check_control_id(__u32 id)
937{
938 struct poseidon_control *control = &controls[0];
939 int array_size = ARRAY_SIZE(controls);
940
941 for (; control < &controls[array_size]; control++)
942 if (control->v4l2_ctrl.id == id)
943 return control;
944 return NULL;
945}
946
947static int vidioc_queryctrl(struct file *file, void *fh,
948 struct v4l2_queryctrl *a)
949{
950 struct poseidon_control *control = NULL;
951
952 control = check_control_id(a->id);
953 if (!control)
954 return -EINVAL;
955
956 *a = control->v4l2_ctrl;
957 return 0;
958}
959
960static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *ctrl)
961{
962 struct front_face *front = fh;
963 struct poseidon *pd = front->pd;
964 struct poseidon_control *control = NULL;
965 struct tuner_custom_parameter_s tuner_param;
966 s32 ret = 0, cmd_status;
967
968 control = check_control_id(ctrl->id);
969 if (!control)
970 return -EINVAL;
971
972 mutex_lock(&pd->lock);
973 ret = send_get_req(pd, TUNER_CUSTOM_PARAMETER, control->vc_id,
974 &tuner_param, &cmd_status, sizeof(tuner_param));
975 mutex_unlock(&pd->lock);
976
977 if (ret || cmd_status)
978 return -1;
979
980 ctrl->value = tuner_param.param_value;
981 return 0;
982}
983
984static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *a)
985{
986 struct tuner_custom_parameter_s param = {0};
987 struct poseidon_control *control = NULL;
988 struct front_face *front = fh;
989 struct poseidon *pd = front->pd;
990 s32 ret = 0, cmd_status, params;
991
992 control = check_control_id(a->id);
993 if (!control)
994 return -EINVAL;
995
996 param.param_value = a->value;
997 param.param_id = control->vc_id;
998 params = *(s32 *)&param; /* temp code */
999
1000 mutex_lock(&pd->lock);
1001 ret = send_set_req(pd, TUNER_CUSTOM_PARAMETER, params, &cmd_status);
1002 ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
1003 mutex_unlock(&pd->lock);
1004
1005 set_current_state(TASK_INTERRUPTIBLE);
1006 schedule_timeout(HZ/4);
1007 return ret;
1008}
1009
1010/* Audio ioctls */
1011static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a)
1012{
1013 if (0 != a->index)
1014 return -EINVAL;
1015 a->capability = V4L2_AUDCAP_STEREO;
1016 strcpy(a->name, "USB audio in");
1017 /*Poseidon have no AVL function.*/
1018 a->mode = 0;
1019 return 0;
1020}
1021
1022int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
1023{
1024 a->index = 0;
1025 a->capability = V4L2_AUDCAP_STEREO;
1026 strcpy(a->name, "USB audio in");
1027 a->mode = 0;
1028 return 0;
1029}
1030
1031int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
1032{
1033 return (0 == a->index) ? 0 : -EINVAL;
1034}
1035
1036/* Tuner ioctls */
1037static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *tuner)
1038{
1039 struct front_face *front = fh;
1040 struct poseidon *pd = front->pd;
1041 struct tuner_atv_sig_stat_s atv_stat;
1042 s32 count = 5, ret, cmd_status;
1043 int index;
1044
1045 if (0 != tuner->index)
1046 return -EINVAL;
1047
1048 mutex_lock(&pd->lock);
1049 ret = send_get_req(pd, TUNER_STATUS, TLG_MODE_ANALOG_TV,
1050 &atv_stat, &cmd_status, sizeof(atv_stat));
1051
1052 while (atv_stat.sig_lock_busy && count-- && !ret) {
1053 set_current_state(TASK_INTERRUPTIBLE);
1054 schedule_timeout(HZ);
1055
1056 ret = send_get_req(pd, TUNER_STATUS, TLG_MODE_ANALOG_TV,
1057 &atv_stat, &cmd_status, sizeof(atv_stat));
1058 }
1059 mutex_unlock(&pd->lock);
1060
1061 if (debug_mode)
1062 log("P:%d,S:%d", atv_stat.sig_present, atv_stat.sig_strength);
1063
1064 if (ret || cmd_status)
1065 tuner->signal = 0;
1066 else if (atv_stat.sig_present && !atv_stat.sig_strength)
1067 tuner->signal = 0xFFFF;
1068 else
1069 tuner->signal = (atv_stat.sig_strength * 255 / 10) << 8;
1070
1071 strcpy(tuner->name, "Telegent Systems");
1072 tuner->type = V4L2_TUNER_ANALOG_TV;
1073 tuner->rangelow = TUNER_FREQ_MIN / 62500;
1074 tuner->rangehigh = TUNER_FREQ_MAX / 62500;
1075 tuner->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
1076 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
1077 index = pd->video_data.context.audio_idx;
1078 tuner->rxsubchans = pd_audio_modes[index].v4l2_audio_sub;
1079 tuner->audmode = pd_audio_modes[index].v4l2_audio_mode;
1080 tuner->afc = 0;
1081 logs(front);
1082 return 0;
1083}
1084
1085static int pd_vidioc_s_tuner(struct poseidon *pd, int index)
1086{
1087 s32 ret = 0, cmd_status, param, audiomode;
1088
1089 mutex_lock(&pd->lock);
1090 param = pd_audio_modes[index].tlg_audio_mode;
1091 ret = send_set_req(pd, TUNER_AUD_MODE, param, &cmd_status);
1092 audiomode = get_audio_std(pd->video_data.context.tvnormid);
1093 ret |= send_set_req(pd, TUNER_AUD_ANA_STD, audiomode,
1094 &cmd_status);
1095 if (!ret)
1096 pd->video_data.context.audio_idx = index;
1097 mutex_unlock(&pd->lock);
1098 return ret;
1099}
1100
1101static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *a)
1102{
1103 struct front_face *front = fh;
1104 struct poseidon *pd = front->pd;
1105 int index;
1106
1107 if (0 != a->index)
1108 return -EINVAL;
1109 logs(front);
1110 for (index = 0; index < POSEIDON_AUDIOMODS; index++)
1111 if (a->audmode == pd_audio_modes[index].v4l2_audio_mode)
1112 return pd_vidioc_s_tuner(pd, index);
1113 return -EINVAL;
1114}
1115
1116static int vidioc_g_frequency(struct file *file, void *fh,
1117 struct v4l2_frequency *freq)
1118{
1119 struct front_face *front = fh;
1120 struct poseidon *pd = front->pd;
1121 struct running_context *context = &pd->video_data.context;
1122
1123 if (0 != freq->tuner)
1124 return -EINVAL;
1125 freq->frequency = context->freq;
1126 freq->type = V4L2_TUNER_ANALOG_TV;
1127 return 0;
1128}
1129
1130static int set_frequency(struct poseidon *pd, __u32 frequency)
1131{
1132 s32 ret = 0, param, cmd_status;
1133 struct running_context *context = &pd->video_data.context;
1134
1135 param = frequency * 62500 / 1000;
1136 if (param < TUNER_FREQ_MIN/1000 || param > TUNER_FREQ_MAX / 1000)
1137 return -EINVAL;
1138
1139 mutex_lock(&pd->lock);
1140 ret = send_set_req(pd, TUNE_FREQ_SELECT, param, &cmd_status);
1141 ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
1142
1143 msleep(250); /* wait for a while until the hardware is ready. */
1144 context->freq = frequency;
1145 mutex_unlock(&pd->lock);
1146 return ret;
1147}
1148
1149static int vidioc_s_frequency(struct file *file, void *fh,
1150 struct v4l2_frequency *freq)
1151{
1152 struct front_face *front = fh;
1153 struct poseidon *pd = front->pd;
1154
1155 logs(front);
1156#ifdef CONFIG_PM
1157 pd->pm_suspend = pm_video_suspend;
1158 pd->pm_resume = pm_video_resume;
1159#endif
1160 return set_frequency(pd, freq->frequency);
1161}
1162
1163static int vidioc_reqbufs(struct file *file, void *fh,
1164 struct v4l2_requestbuffers *b)
1165{
1166 struct front_face *front = file->private_data;
1167 logs(front);
1168 return videobuf_reqbufs(&front->q, b);
1169}
1170
1171static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
1172{
1173 struct front_face *front = file->private_data;
1174 logs(front);
1175 return videobuf_querybuf(&front->q, b);
1176}
1177
1178static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
1179{
1180 struct front_face *front = file->private_data;
1181 return videobuf_qbuf(&front->q, b);
1182}
1183
1184static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
1185{
1186 struct front_face *front = file->private_data;
1187 return videobuf_dqbuf(&front->q, b, file->f_flags & O_NONBLOCK);
1188}
1189
1190/* Just stop the URBs, do not free the URBs */
1191int usb_transfer_stop(struct video_data *video)
1192{
1193 if (video->is_streaming) {
1194 int i;
1195 s32 cmd_status;
1196 struct poseidon *pd = video->pd;
1197
1198 video->is_streaming = 0;
1199 for (i = 0; i < SBUF_NUM; ++i) {
1200 if (video->urb_array[i])
1201 usb_kill_urb(video->urb_array[i]);
1202 }
1203
1204 send_set_req(pd, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_STOP,
1205 &cmd_status);
1206 }
1207 return 0;
1208}
1209
1210int stop_all_video_stream(struct poseidon *pd)
1211{
1212 struct video_data *video = &pd->video_data;
1213 struct vbi_data *vbi = &pd->vbi_data;
1214
1215 mutex_lock(&pd->lock);
1216 if (video->is_streaming) {
1217 struct front_face *front = video->front;
1218
1219 /* stop the URBs */
1220 usb_transfer_stop(video);
1221 free_all_urb(video);
1222
1223 /* stop the host side of VIDEO */
1224 videobuf_stop(&front->q);
1225 videobuf_mmap_free(&front->q);
1226
1227 /* stop the host side of VBI */
1228 front = vbi->front;
1229 if (front) {
1230 videobuf_stop(&front->q);
1231 videobuf_mmap_free(&front->q);
1232 }
1233 }
1234 mutex_unlock(&pd->lock);
1235 return 0;
1236}
1237
1238/*
1239 * The bubbles can seriously damage the video's quality,
1240 * though it occurs in very rare situation.
1241 */
1242static void iso_bubble_handler(struct work_struct *w)
1243{
1244 struct video_data *video;
1245 struct poseidon *pd;
1246
1247 video = container_of(w, struct video_data, bubble_work);
1248 pd = video->pd;
1249
1250 mutex_lock(&pd->lock);
1251 usb_transfer_stop(video);
1252 msleep(500);
1253 start_video_stream(pd);
1254 mutex_unlock(&pd->lock);
1255}
1256
1257
1258static int vidioc_streamon(struct file *file, void *fh,
1259 enum v4l2_buf_type type)
1260{
1261 struct front_face *front = fh;
1262
1263 logs(front);
1264 if (unlikely(type != front->type))
1265 return -EINVAL;
1266 return videobuf_streamon(&front->q);
1267}
1268
1269static int vidioc_streamoff(struct file *file, void *fh,
1270 enum v4l2_buf_type type)
1271{
1272 struct front_face *front = file->private_data;
1273
1274 logs(front);
1275 if (unlikely(type != front->type))
1276 return -EINVAL;
1277 return videobuf_streamoff(&front->q);
1278}
1279
1280/* Set the firmware's default values : need altersetting */
1281static int pd_video_checkmode(struct poseidon *pd)
1282{
1283 s32 ret = 0, cmd_status, audiomode;
1284
1285 set_current_state(TASK_INTERRUPTIBLE);
1286 schedule_timeout(HZ/2);
1287
1288 /* choose the altersetting */
1289 ret = usb_set_interface(pd->udev, 0,
1290 (pd->cur_transfer_mode ?
1291 ISO_3K_BULK_ALTERNATE_IFACE :
1292 BULK_ALTERNATE_IFACE));
1293 if (ret < 0)
1294 goto error;
1295
1296 /* set default parameters for PAL-D , with the VBI enabled*/
1297 ret = set_tuner_mode(pd, TLG_MODE_ANALOG_TV);
1298 ret |= send_set_req(pd, SGNL_SRC_SEL,
1299 TLG_SIG_SRC_ANTENNA, &cmd_status);
1300 ret |= send_set_req(pd, VIDEO_STD_SEL,
1301 TLG_TUNE_VSTD_PAL_D, &cmd_status);
1302 ret |= send_set_req(pd, VIDEO_STREAM_FMT_SEL,
1303 TLG_TUNER_VID_FORMAT_YUV, &cmd_status);
1304 ret |= send_set_req(pd, VIDEO_ROSOLU_SEL,
1305 TLG_TUNE_VID_RES_720, &cmd_status);
1306 ret |= send_set_req(pd, TUNE_FREQ_SELECT, TUNER_FREQ_MIN, &cmd_status);
1307 ret |= send_set_req(pd, VBI_DATA_SEL, 1, &cmd_status);/* enable vbi */
1308
1309 /* set the audio */
1310 audiomode = get_audio_std(pd->video_data.context.tvnormid);
1311 ret |= send_set_req(pd, TUNER_AUD_ANA_STD, audiomode, &cmd_status);
1312 ret |= send_set_req(pd, TUNER_AUD_MODE,
1313 TLG_TUNE_TVAUDIO_MODE_STEREO, &cmd_status);
1314 ret |= send_set_req(pd, AUDIO_SAMPLE_RATE_SEL,
1315 ATV_AUDIO_RATE_48K, &cmd_status);
1316error:
1317 return ret;
1318}
1319
1320#ifdef CONFIG_PM
1321static int pm_video_suspend(struct poseidon *pd)
1322{
1323 /* stop audio */
1324 pm_alsa_suspend(pd);
1325
1326 /* stop and free all the URBs */
1327 usb_transfer_stop(&pd->video_data);
1328 free_all_urb(&pd->video_data);
1329
1330 /* reset the interface */
1331 usb_set_interface(pd->udev, 0, 0);
1332 msleep(300);
1333 return 0;
1334}
1335
1336static int restore_v4l2_context(struct poseidon *pd,
1337 struct running_context *context)
1338{
1339 struct front_face *front = pd->video_data.front;
1340
1341 pd_video_checkmode(pd);
1342
1343 set_std(pd, &context->tvnormid);
1344 vidioc_s_input(NULL, front, context->sig_index);
1345 pd_vidioc_s_tuner(pd, context->audio_idx);
1346 pd_vidioc_s_fmt(pd, &context->pix);
1347 set_frequency(pd, context->freq);
1348 return 0;
1349}
1350
1351static int pm_video_resume(struct poseidon *pd)
1352{
1353 struct video_data *video = &pd->video_data;
1354
1355 /* resume the video */
1356 /* [1] restore the origin V4L2 parameters */
1357 restore_v4l2_context(pd, &video->context);
1358
1359 /* [2] initiate video copy variables */
1360 if (video->front->curr_frame)
1361 init_copy(video, 0);
1362
1363 /* [3] fire urbs */
1364 start_video_stream(pd);
1365
1366 /* resume the audio */
1367 pm_alsa_resume(pd);
1368 return 0;
1369}
1370#endif
1371
1372void set_debug_mode(struct video_device *vfd, int debug_mode)
1373{
1374 vfd->debug = 0;
1375 if (debug_mode & 0x1)
1376 vfd->debug = V4L2_DEBUG_IOCTL;
1377 if (debug_mode & 0x2)
1378 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
1379}
1380
1381static void init_video_context(struct running_context *context)
1382{
1383 context->sig_index = 0;
1384 context->audio_idx = 1; /* stereo */
1385 context->tvnormid = V4L2_STD_PAL_D;
1386 context->pix = (struct v4l2_pix_format) {
1387 .width = 720,
1388 .height = 576,
1389 .pixelformat = V4L2_PIX_FMT_YUYV,
1390 .field = V4L2_FIELD_INTERLACED,
1391 .bytesperline = 720 * 2,
1392 .sizeimage = 720 * 576 * 2,
1393 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1394 .priv = 0
1395 };
1396}
1397
1398static int pd_video_open(struct file *file)
1399{
1400 struct video_device *vfd = video_devdata(file);
1401 struct poseidon *pd = video_get_drvdata(vfd);
1402 struct front_face *front = NULL;
1403 int ret = -ENOMEM;
1404
1405 mutex_lock(&pd->lock);
1406 usb_autopm_get_interface(pd->interface);
1407
1408 if (vfd->vfl_type == VFL_TYPE_GRABBER
1409 && !(pd->state & POSEIDON_STATE_ANALOG)) {
1410 front = kzalloc(sizeof(struct front_face), GFP_KERNEL);
1411 if (!front)
1412 goto out;
1413
1414 pd->cur_transfer_mode = usb_transfer_mode;/* bulk or iso */
1415 init_video_context(&pd->video_data.context);
1416
1417 ret = pd_video_checkmode(pd);
1418 if (ret < 0) {
1419 kfree(front);
1420 ret = -1;
1421 goto out;
1422 }
1423
1424 pd->state |= POSEIDON_STATE_ANALOG;
1425 front->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1426 pd->video_data.users++;
1427 set_debug_mode(vfd, debug_mode);
1428
1429 videobuf_queue_vmalloc_init(&front->q, &pd_video_qops,
1430 NULL, &front->queue_lock,
1431 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1432 V4L2_FIELD_INTERLACED,/* video is interlacd */
1433 sizeof(struct videobuf_buffer),/*it's enough*/
1434 front);
1435 } else if (vfd->vfl_type == VFL_TYPE_VBI
1436 && !(pd->state & POSEIDON_STATE_VBI)) {
1437 front = kzalloc(sizeof(struct front_face), GFP_KERNEL);
1438 if (!front)
1439 goto out;
1440
1441 pd->state |= POSEIDON_STATE_VBI;
1442 front->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1443 pd->vbi_data.front = front;
1444 pd->vbi_data.users++;
1445
1446 videobuf_queue_vmalloc_init(&front->q, &pd_video_qops,
1447 NULL, &front->queue_lock,
1448 V4L2_BUF_TYPE_VBI_CAPTURE,
1449 V4L2_FIELD_NONE, /* vbi is NONE mode */
1450 sizeof(struct videobuf_buffer),
1451 front);
1452 } else {
1453 /* maybe add FM support here */
1454 log("other ");
1455 ret = -EINVAL;
1456 goto out;
1457 }
1458
1459 front->pd = pd;
1460 front->curr_frame = NULL;
1461 INIT_LIST_HEAD(&front->active);
1462 spin_lock_init(&front->queue_lock);
1463
1464 file->private_data = front;
1465 kref_get(&pd->kref);
1466
1467 mutex_unlock(&pd->lock);
1468 return 0;
1469out:
1470 usb_autopm_put_interface(pd->interface);
1471 mutex_unlock(&pd->lock);
1472 return ret;
1473}
1474
1475static int pd_video_release(struct file *file)
1476{
1477 struct front_face *front = file->private_data;
1478 struct poseidon *pd = front->pd;
1479 s32 cmd_status = 0;
1480
1481 logs(front);
1482 mutex_lock(&pd->lock);
1483
1484 if (front->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1485 pd->state &= ~POSEIDON_STATE_ANALOG;
1486
1487 /* stop the device, and free the URBs */
1488 usb_transfer_stop(&pd->video_data);
1489 free_all_urb(&pd->video_data);
1490
1491 /* stop the firmware */
1492 send_set_req(pd, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_STOP,
1493 &cmd_status);
1494
1495 pd->file_for_stream = NULL;
1496 pd->video_data.users--;
1497 } else if (front->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1498 pd->state &= ~POSEIDON_STATE_VBI;
1499 pd->vbi_data.front = NULL;
1500 pd->vbi_data.users--;
1501 }
1502 videobuf_stop(&front->q);
1503 videobuf_mmap_free(&front->q);
1504
1505 usb_autopm_put_interface(pd->interface);
1506 mutex_unlock(&pd->lock);
1507
1508 kfree(front);
1509 file->private_data = NULL;
1510 kref_put(&pd->kref, poseidon_delete);
1511 return 0;
1512}
1513
1514static int pd_video_mmap(struct file *file, struct vm_area_struct *vma)
1515{
1516 struct front_face *front = file->private_data;
1517 return videobuf_mmap_mapper(&front->q, vma);
1518}
1519
1520unsigned int pd_video_poll(struct file *file, poll_table *table)
1521{
1522 struct front_face *front = file->private_data;
1523 return videobuf_poll_stream(file, &front->q, table);
1524}
1525
1526ssize_t pd_video_read(struct file *file, char __user *buffer,
1527 size_t count, loff_t *ppos)
1528{
1529 struct front_face *front = file->private_data;
1530 return videobuf_read_stream(&front->q, buffer, count, ppos,
1531 0, file->f_flags & O_NONBLOCK);
1532}
1533
1534/* This struct works for both VIDEO and VBI */
1535static const struct v4l2_file_operations pd_video_fops = {
1536 .owner = THIS_MODULE,
1537 .open = pd_video_open,
1538 .release = pd_video_release,
1539 .read = pd_video_read,
1540 .poll = pd_video_poll,
1541 .mmap = pd_video_mmap,
1542 .ioctl = video_ioctl2, /* maybe changed in future */
1543};
1544
1545static const struct v4l2_ioctl_ops pd_video_ioctl_ops = {
1546 .vidioc_querycap = vidioc_querycap,
1547
1548 /* Video format */
1549 .vidioc_g_fmt_vid_cap = vidioc_g_fmt,
1550 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt,
1551 .vidioc_s_fmt_vid_cap = vidioc_s_fmt,
1552 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi, /* VBI */
1553 .vidioc_try_fmt_vid_cap = vidioc_try_fmt,
1554
1555 /* Input */
1556 .vidioc_g_input = vidioc_g_input,
1557 .vidioc_s_input = vidioc_s_input,
1558 .vidioc_enum_input = vidioc_enum_input,
1559
1560 /* Audio ioctls */
1561 .vidioc_enumaudio = vidioc_enumaudio,
1562 .vidioc_g_audio = vidioc_g_audio,
1563 .vidioc_s_audio = vidioc_s_audio,
1564
1565 /* Tuner ioctls */
1566 .vidioc_g_tuner = vidioc_g_tuner,
1567 .vidioc_s_tuner = vidioc_s_tuner,
1568 .vidioc_s_std = vidioc_s_std,
1569 .vidioc_g_frequency = vidioc_g_frequency,
1570 .vidioc_s_frequency = vidioc_s_frequency,
1571
1572 /* Buffer handlers */
1573 .vidioc_reqbufs = vidioc_reqbufs,
1574 .vidioc_querybuf = vidioc_querybuf,
1575 .vidioc_qbuf = vidioc_qbuf,
1576 .vidioc_dqbuf = vidioc_dqbuf,
1577
1578 /* Stream on/off */
1579 .vidioc_streamon = vidioc_streamon,
1580 .vidioc_streamoff = vidioc_streamoff,
1581
1582 /* Control handling */
1583 .vidioc_queryctrl = vidioc_queryctrl,
1584 .vidioc_g_ctrl = vidioc_g_ctrl,
1585 .vidioc_s_ctrl = vidioc_s_ctrl,
1586};
1587
1588static struct video_device pd_video_template = {
1589 .name = "Telegent-Video",
1590 .fops = &pd_video_fops,
1591 .minor = -1,
1592 .release = video_device_release,
1593 .tvnorms = V4L2_STD_ALL,
1594 .ioctl_ops = &pd_video_ioctl_ops,
1595};
1596
1597struct video_device *vdev_init(struct poseidon *pd, struct video_device *tmp)
1598{
1599 struct video_device *vfd;
1600
1601 vfd = video_device_alloc();
1602 if (vfd == NULL)
1603 return NULL;
1604 *vfd = *tmp;
1605 vfd->minor = -1;
1606 vfd->v4l2_dev = &pd->v4l2_dev;
1607 /*vfd->parent = &(pd->udev->dev); */
1608 vfd->release = video_device_release;
1609 video_set_drvdata(vfd, pd);
1610 return vfd;
1611}
1612
1613void destroy_video_device(struct video_device **v_dev)
1614{
1615 struct video_device *dev = *v_dev;
1616
1617 if (dev == NULL)
1618 return;
1619
1620 if (video_is_registered(dev))
1621 video_unregister_device(dev);
1622 else
1623 video_device_release(dev);
1624 *v_dev = NULL;
1625}
1626
1627void pd_video_exit(struct poseidon *pd)
1628{
1629 struct video_data *video = &pd->video_data;
1630 struct vbi_data *vbi = &pd->vbi_data;
1631
1632 destroy_video_device(&video->v_dev);
1633 destroy_video_device(&vbi->v_dev);
1634 log();
1635}
1636
1637int pd_video_init(struct poseidon *pd)
1638{
1639 struct video_data *video = &pd->video_data;
1640 struct vbi_data *vbi = &pd->vbi_data;
1641 int ret = -ENOMEM;
1642
1643 video->v_dev = vdev_init(pd, &pd_video_template);
1644 if (video->v_dev == NULL)
1645 goto out;
1646
1647 ret = video_register_device(video->v_dev, VFL_TYPE_GRABBER, -1);
1648 if (ret != 0)
1649 goto out;
1650
1651 /* VBI uses the same template as video */
1652 vbi->v_dev = vdev_init(pd, &pd_video_template);
1653 if (vbi->v_dev == NULL) {
1654 ret = -ENOMEM;
1655 goto out;
1656 }
1657 ret = video_register_device(vbi->v_dev, VFL_TYPE_VBI, -1);
1658 if (ret != 0)
1659 goto out;
1660 log("register VIDEO/VBI devices");
1661 return 0;
1662out:
1663 log("VIDEO/VBI devices register failed, : %d", ret);
1664 pd_video_exit(pd);
1665 return ret;
1666}
1667
diff --git a/drivers/media/video/tlg2300/vendorcmds.h b/drivers/media/video/tlg2300/vendorcmds.h
new file mode 100644
index 000000000000..ba6f4ae3b2c2
--- /dev/null
+++ b/drivers/media/video/tlg2300/vendorcmds.h
@@ -0,0 +1,243 @@
1#ifndef VENDOR_CMD_H_
2#define VENDOR_CMD_H_
3
4#define BULK_ALTERNATE_IFACE (2)
5#define ISO_3K_BULK_ALTERNATE_IFACE (1)
6#define REQ_SET_CMD (0X00)
7#define REQ_GET_CMD (0X80)
8
9enum tlg__analog_audio_standard {
10 TLG_TUNE_ASTD_NONE = 0x00000000,
11 TLG_TUNE_ASTD_A2 = 0x00000001,
12 TLG_TUNE_ASTD_NICAM = 0x00000002,
13 TLG_TUNE_ASTD_EIAJ = 0x00000004,
14 TLG_TUNE_ASTD_BTSC = 0x00000008,
15 TLG_TUNE_ASTD_FM_US = 0x00000010,
16 TLG_TUNE_ASTD_FM_EUR = 0x00000020,
17 TLG_TUNE_ASTD_ALL = 0x0000003f
18};
19
20/*
21 * identifiers for Custom Parameter messages.
22 * @typedef cmd_custom_param_id_t
23 */
24enum cmd_custom_param_id {
25 CUST_PARM_ID_NONE = 0x00,
26 CUST_PARM_ID_BRIGHTNESS_CTRL = 0x01,
27 CUST_PARM_ID_CONTRAST_CTRL = 0x02,
28 CUST_PARM_ID_HUE_CTRL = 0x03,
29 CUST_PARM_ID_SATURATION_CTRL = 0x04,
30 CUST_PARM_ID_AUDIO_SNR_THRESHOLD = 0x10,
31 CUST_PARM_ID_AUDIO_AGC_THRESHOLD = 0x11,
32 CUST_PARM_ID_MAX
33};
34
35struct tuner_custom_parameter_s {
36 uint16_t param_id; /* Parameter identifier */
37 uint16_t param_value; /* Parameter value */
38};
39
40struct tuner_ber_rate_s {
41 uint32_t ber_rate; /* BER sample rate in seconds */
42};
43
44struct tuner_atv_sig_stat_s {
45 uint32_t sig_present;
46 uint32_t sig_locked;
47 uint32_t sig_lock_busy;
48 uint32_t sig_strength; /* milliDb */
49 uint32_t tv_audio_chan; /* mono/stereo/sap*/
50 uint32_t mvision_stat; /* macrovision status */
51};
52
53struct tuner_dtv_sig_stat_s {
54 uint32_t sig_present; /* Boolean*/
55 uint32_t sig_locked; /* Boolean */
56 uint32_t sig_lock_busy; /* Boolean (Can this time-out?) */
57 uint32_t sig_strength; /* milliDb*/
58};
59
60struct tuner_fm_sig_stat_s {
61 uint32_t sig_present; /* Boolean*/
62 uint32_t sig_locked; /* Boolean */
63 uint32_t sig_lock_busy; /* Boolean */
64 uint32_t sig_stereo_mono;/* TBD*/
65 uint32_t sig_strength; /* milliDb*/
66};
67
68enum _tag_tlg_tune_srv_cmd {
69 TLG_TUNE_PLAY_SVC_START = 1,
70 TLG_TUNE_PLAY_SVC_STOP
71};
72
73enum _tag_tune_atv_audio_mode_caps {
74 TLG_TUNE_TVAUDIO_MODE_MONO = 0x00000001,
75 TLG_TUNE_TVAUDIO_MODE_STEREO = 0x00000002,
76 TLG_TUNE_TVAUDIO_MODE_LANG_A = 0x00000010,/* Primary language*/
77 TLG_TUNE_TVAUDIO_MODE_LANG_B = 0x00000020,/* 2nd avail language*/
78 TLG_TUNE_TVAUDIO_MODE_LANG_C = 0x00000040
79};
80
81
82enum _tag_tuner_atv_audio_rates {
83 ATV_AUDIO_RATE_NONE = 0x00,/* Audio not supported*/
84 ATV_AUDIO_RATE_32K = 0x01,/* Audio rate = 32 KHz*/
85 ATV_AUDIO_RATE_48K = 0x02, /* Audio rate = 48 KHz*/
86 ATV_AUDIO_RATE_31_25K = 0x04 /* Audio rate = 31.25KHz */
87};
88
89enum _tag_tune_atv_vid_res_caps {
90 TLG_TUNE_VID_RES_NONE = 0x00000000,
91 TLG_TUNE_VID_RES_720 = 0x00000001,
92 TLG_TUNE_VID_RES_704 = 0x00000002,
93 TLG_TUNE_VID_RES_360 = 0x00000004
94};
95
96enum _tag_tuner_analog_video_format {
97 TLG_TUNER_VID_FORMAT_YUV = 0x00000001,
98 TLG_TUNER_VID_FORMAT_YCRCB = 0x00000002,
99 TLG_TUNER_VID_FORMAT_RGB_565 = 0x00000004,
100};
101
102enum tlg_ext_audio_support {
103 TLG_EXT_AUDIO_NONE = 0x00,/* No external audio input supported */
104 TLG_EXT_AUDIO_LR = 0x01/* LR external audio inputs supported*/
105};
106
107enum {
108 TLG_MODE_NONE = 0x00, /* No Mode specified*/
109 TLG_MODE_ANALOG_TV = 0x01, /* Analog Television mode*/
110 TLG_MODE_ANALOG_TV_UNCOMP = 0x01, /* Analog Television mode*/
111 TLG_MODE_ANALOG_TV_COMP = 0x02, /* Analog TV mode (compressed)*/
112 TLG_MODE_FM_RADIO = 0x04, /* FM Radio mode*/
113 TLG_MODE_DVB_T = 0x08, /* Digital TV (DVB-T)*/
114};
115
116enum tlg_signal_sources_t {
117 TLG_SIG_SRC_NONE = 0x00,/* Signal source not specified */
118 TLG_SIG_SRC_ANTENNA = 0x01,/* Signal src is: Antenna */
119 TLG_SIG_SRC_CABLE = 0x02,/* Signal src is: Coax Cable*/
120 TLG_SIG_SRC_SVIDEO = 0x04,/* Signal src is: S_VIDEO */
121 TLG_SIG_SRC_COMPOSITE = 0x08 /* Signal src is: Composite Video */
122};
123
124enum tuner_analog_video_standard {
125 TLG_TUNE_VSTD_NONE = 0x00000000,
126 TLG_TUNE_VSTD_NTSC_M = 0x00000001,
127 TLG_TUNE_VSTD_NTSC_M_J = 0x00000002,/* Japan */
128 TLG_TUNE_VSTD_PAL_B = 0x00000010,
129 TLG_TUNE_VSTD_PAL_D = 0x00000020,
130 TLG_TUNE_VSTD_PAL_G = 0x00000040,
131 TLG_TUNE_VSTD_PAL_H = 0x00000080,
132 TLG_TUNE_VSTD_PAL_I = 0x00000100,
133 TLG_TUNE_VSTD_PAL_M = 0x00000200,
134 TLG_TUNE_VSTD_PAL_N = 0x00000400,
135 TLG_TUNE_VSTD_SECAM_B = 0x00001000,
136 TLG_TUNE_VSTD_SECAM_D = 0x00002000,
137 TLG_TUNE_VSTD_SECAM_G = 0x00004000,
138 TLG_TUNE_VSTD_SECAM_H = 0x00008000,
139 TLG_TUNE_VSTD_SECAM_K = 0x00010000,
140 TLG_TUNE_VSTD_SECAM_K1 = 0x00020000,
141 TLG_TUNE_VSTD_SECAM_L = 0x00040000,
142 TLG_TUNE_VSTD_SECAM_L1 = 0x00080000,
143 TLG_TUNE_VSTD_PAL_N_COMBO = 0x00100000
144};
145
146enum tlg_mode_caps {
147 TLG_MODE_CAPS_NONE = 0x00, /* No Mode specified */
148 TLG_MODE_CAPS_ANALOG_TV_UNCOMP = 0x01, /* Analog TV mode */
149 TLG_MODE_CAPS_ANALOG_TV_COMP = 0x02, /* Analog TV (compressed)*/
150 TLG_MODE_CAPS_FM_RADIO = 0x04, /* FM Radio mode */
151 TLG_MODE_CAPS_DVB_T = 0x08, /* Digital TV (DVB-T) */
152};
153
154enum poseidon_vendor_cmds {
155 LAST_CMD_STAT = 0x00,
156 GET_CHIP_ID = 0x01,
157 GET_FW_ID = 0x02,
158 PRODUCT_CAPS = 0x03,
159
160 TUNE_MODE_CAP_ATV = 0x10,
161 TUNE_MODE_CAP_ATVCOMP = 0X10,
162 TUNE_MODE_CAP_DVBT = 0x10,
163 TUNE_MODE_CAP_FM = 0x10,
164 TUNE_MODE_SELECT = 0x11,
165 TUNE_FREQ_SELECT = 0x12,
166 SGNL_SRC_SEL = 0x13,
167
168 VIDEO_STD_SEL = 0x14,
169 VIDEO_STREAM_FMT_SEL = 0x15,
170 VIDEO_ROSOLU_AVAIL = 0x16,
171 VIDEO_ROSOLU_SEL = 0x17,
172 VIDEO_CONT_PROTECT = 0x20,
173
174 VCR_TIMING_MODSEL = 0x21,
175 EXT_AUDIO_CAP = 0x22,
176 EXT_AUDIO_SEL = 0x23,
177 TEST_PATTERN_SEL = 0x24,
178 VBI_DATA_SEL = 0x25,
179 AUDIO_SAMPLE_RATE_CAP = 0x28,
180 AUDIO_SAMPLE_RATE_SEL = 0x29,
181 TUNER_AUD_MODE = 0x2a,
182 TUNER_AUD_MODE_AVAIL = 0x2b,
183 TUNER_AUD_ANA_STD = 0x2c,
184 TUNER_CUSTOM_PARAMETER = 0x2f,
185
186 DVBT_TUNE_MODE_SEL = 0x30,
187 DVBT_BANDW_CAP = 0x31,
188 DVBT_BANDW_SEL = 0x32,
189 DVBT_GUARD_INTERV_CAP = 0x33,
190 DVBT_GUARD_INTERV_SEL = 0x34,
191 DVBT_MODULATION_CAP = 0x35,
192 DVBT_MODULATION_SEL = 0x36,
193 DVBT_INNER_FEC_RATE_CAP = 0x37,
194 DVBT_INNER_FEC_RATE_SEL = 0x38,
195 DVBT_TRANS_MODE_CAP = 0x39,
196 DVBT_TRANS_MODE_SEL = 0x3a,
197 DVBT_SEARCH_RANG = 0x3c,
198
199 TUNER_SETUP_ANALOG = 0x40,
200 TUNER_SETUP_DIGITAL = 0x41,
201 TUNER_SETUP_FM_RADIO = 0x42,
202 TAKE_REQUEST = 0x43, /* Take effect of the command */
203 PLAY_SERVICE = 0x44, /* Play start or Play stop */
204 TUNER_STATUS = 0x45,
205 TUNE_PROP_DVBT = 0x46,
206 ERR_RATE_STATS = 0x47,
207 TUNER_BER_RATE = 0x48,
208
209 SCAN_CAPS = 0x50,
210 SCAN_SETUP = 0x51,
211 SCAN_SERVICE = 0x52,
212 SCAN_STATS = 0x53,
213
214 PID_SET = 0x58,
215 PID_UNSET = 0x59,
216 PID_LIST = 0x5a,
217
218 IRD_CAP = 0x60,
219 IRD_MODE_SEL = 0x61,
220 IRD_SETUP = 0x62,
221
222 PTM_MODE_CAP = 0x70,
223 PTM_MODE_SEL = 0x71,
224 PTM_SERVICE = 0x72,
225 TUNER_REG_SCRIPT = 0x73,
226 CMD_CHIP_RST = 0x74,
227};
228
229enum tlg_bw {
230 TLG_BW_5 = 5,
231 TLG_BW_6 = 6,
232 TLG_BW_7 = 7,
233 TLG_BW_8 = 8,
234 TLG_BW_12 = 12,
235 TLG_BW_15 = 15
236};
237
238struct cmd_firmware_vers_s {
239 uint8_t fw_rev_major;
240 uint8_t fw_rev_minor;
241 uint16_t fw_patch;
242};
243#endif /* VENDOR_CMD_H_ */
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 5b3eaa16afd2..c4dab6cfd948 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -1078,6 +1078,7 @@ static int tuner_probe(struct i2c_client *client,
1078 1078
1079 goto register_client; 1079 goto register_client;
1080 } 1080 }
1081 kfree(t);
1081 return -ENODEV; 1082 return -ENODEV;
1082 case 0x42: 1083 case 0x42:
1083 case 0x43: 1084 case 0x43:
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index d533ea57e7b1..0a877497b93f 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -680,10 +680,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
680 tveeprom_info("Hauppauge model %d, rev %s, serial# %d\n", 680 tveeprom_info("Hauppauge model %d, rev %s, serial# %d\n",
681 tvee->model, tvee->rev_str, tvee->serial_number); 681 tvee->model, tvee->rev_str, tvee->serial_number);
682 if (tvee->has_MAC_address == 1) 682 if (tvee->has_MAC_address == 1)
683 tveeprom_info("MAC address is %02X-%02X-%02X-%02X-%02X-%02X\n", 683 tveeprom_info("MAC address is %pM\n", tvee->MAC_address);
684 tvee->MAC_address[0], tvee->MAC_address[1],
685 tvee->MAC_address[2], tvee->MAC_address[3],
686 tvee->MAC_address[4], tvee->MAC_address[5]);
687 tveeprom_info("tuner model is %s (idx %d, type %d)\n", 684 tveeprom_info("tuner model is %s (idx %d, type %d)\n",
688 t_name1, tuner1, tvee->tuner_type); 685 t_name1, tuner1, tvee->tuner_type);
689 tveeprom_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n", 686 tveeprom_info("TV standards%s%s%s%s%s%s%s%s (eeprom 0x%02x)\n",
diff --git a/drivers/media/video/tvp7002.c b/drivers/media/video/tvp7002.c
new file mode 100644
index 000000000000..5a878bca02d4
--- /dev/null
+++ b/drivers/media/video/tvp7002.c
@@ -0,0 +1,1187 @@
1/* Texas Instruments Triple 8-/10-BIT 165-/110-MSPS Video and Graphics
2 * Digitizer with Horizontal PLL registers
3 *
4 * Copyright (C) 2009 Texas Instruments Inc
5 * Author: Santiago Nunez-Corrales <santiago.nunez@ridgerun.com>
6 *
7 * This code is partially based upon the TVP5150 driver
8 * written by Mauro Carvalho Chehab (mchehab@infradead.org),
9 * the TVP514x driver written by Vaibhav Hiremath <hvaibhav@ti.com>
10 * and the TVP7002 driver in the TI LSP 2.10.00.14. Revisions by
11 * Muralidharan Karicheri and Snehaprabha Narnakaje (TI).
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27#include <linux/delay.h>
28#include <linux/i2c.h>
29#include <linux/videodev2.h>
30#include <media/tvp7002.h>
31#include <media/v4l2-device.h>
32#include <media/v4l2-chip-ident.h>
33#include <media/v4l2-common.h>
34#include "tvp7002_reg.h"
35
36MODULE_DESCRIPTION("TI TVP7002 Video and Graphics Digitizer driver");
37MODULE_AUTHOR("Santiago Nunez-Corrales <santiago.nunez@ridgerun.com>");
38MODULE_LICENSE("GPL");
39
40/* Module Name */
41#define TVP7002_MODULE_NAME "tvp7002"
42
43/* I2C retry attempts */
44#define I2C_RETRY_COUNT (5)
45
46/* End of registers */
47#define TVP7002_EOR 0x5c
48
49/* Read write definition for registers */
50#define TVP7002_READ 0
51#define TVP7002_WRITE 1
52#define TVP7002_RESERVED 2
53
54/* Interlaced vs progressive mask and shift */
55#define TVP7002_IP_SHIFT 5
56#define TVP7002_INPR_MASK (0x01 << TVP7002_IP_SHIFT)
57
58/* Shift for CPL and LPF registers */
59#define TVP7002_CL_SHIFT 8
60#define TVP7002_CL_MASK 0x0f
61
62/* Debug functions */
63static int debug;
64module_param(debug, bool, 0644);
65MODULE_PARM_DESC(debug, "Debug level (0-2)");
66
67/* Structure for register values */
68struct i2c_reg_value {
69 u8 reg;
70 u8 value;
71 u8 type;
72};
73
74/*
75 * Register default values (according to tvp7002 datasheet)
76 * In the case of read-only registers, the value (0xff) is
77 * never written. R/W functionality is controlled by the
78 * writable bit in the register struct definition.
79 */
80static const struct i2c_reg_value tvp7002_init_default[] = {
81 { TVP7002_CHIP_REV, 0xff, TVP7002_READ },
82 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x67, TVP7002_WRITE },
83 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x20, TVP7002_WRITE },
84 { TVP7002_HPLL_CRTL, 0xa0, TVP7002_WRITE },
85 { TVP7002_HPLL_PHASE_SEL, 0x80, TVP7002_WRITE },
86 { TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
87 { TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
88 { TVP7002_HSYNC_OUT_W, 0x60, TVP7002_WRITE },
89 { TVP7002_B_FINE_GAIN, 0x00, TVP7002_WRITE },
90 { TVP7002_G_FINE_GAIN, 0x00, TVP7002_WRITE },
91 { TVP7002_R_FINE_GAIN, 0x00, TVP7002_WRITE },
92 { TVP7002_B_FINE_OFF_MSBS, 0x80, TVP7002_WRITE },
93 { TVP7002_G_FINE_OFF_MSBS, 0x80, TVP7002_WRITE },
94 { TVP7002_R_FINE_OFF_MSBS, 0x80, TVP7002_WRITE },
95 { TVP7002_SYNC_CTL_1, 0x20, TVP7002_WRITE },
96 { TVP7002_HPLL_AND_CLAMP_CTL, 0x2e, TVP7002_WRITE },
97 { TVP7002_SYNC_ON_G_THRS, 0x5d, TVP7002_WRITE },
98 { TVP7002_SYNC_SEPARATOR_THRS, 0x47, TVP7002_WRITE },
99 { TVP7002_HPLL_PRE_COAST, 0x00, TVP7002_WRITE },
100 { TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
101 { TVP7002_SYNC_DETECT_STAT, 0xff, TVP7002_READ },
102 { TVP7002_OUT_FORMATTER, 0x47, TVP7002_WRITE },
103 { TVP7002_MISC_CTL_1, 0x01, TVP7002_WRITE },
104 { TVP7002_MISC_CTL_2, 0x00, TVP7002_WRITE },
105 { TVP7002_MISC_CTL_3, 0x01, TVP7002_WRITE },
106 { TVP7002_IN_MUX_SEL_1, 0x00, TVP7002_WRITE },
107 { TVP7002_IN_MUX_SEL_2, 0x67, TVP7002_WRITE },
108 { TVP7002_B_AND_G_COARSE_GAIN, 0x77, TVP7002_WRITE },
109 { TVP7002_R_COARSE_GAIN, 0x07, TVP7002_WRITE },
110 { TVP7002_FINE_OFF_LSBS, 0x00, TVP7002_WRITE },
111 { TVP7002_B_COARSE_OFF, 0x10, TVP7002_WRITE },
112 { TVP7002_G_COARSE_OFF, 0x10, TVP7002_WRITE },
113 { TVP7002_R_COARSE_OFF, 0x10, TVP7002_WRITE },
114 { TVP7002_HSOUT_OUT_START, 0x08, TVP7002_WRITE },
115 { TVP7002_MISC_CTL_4, 0x00, TVP7002_WRITE },
116 { TVP7002_B_DGTL_ALC_OUT_LSBS, 0xff, TVP7002_READ },
117 { TVP7002_G_DGTL_ALC_OUT_LSBS, 0xff, TVP7002_READ },
118 { TVP7002_R_DGTL_ALC_OUT_LSBS, 0xff, TVP7002_READ },
119 { TVP7002_AUTO_LVL_CTL_ENABLE, 0x80, TVP7002_WRITE },
120 { TVP7002_DGTL_ALC_OUT_MSBS, 0xff, TVP7002_READ },
121 { TVP7002_AUTO_LVL_CTL_FILTER, 0x53, TVP7002_WRITE },
122 { 0x29, 0x08, TVP7002_RESERVED },
123 { TVP7002_FINE_CLAMP_CTL, 0x07, TVP7002_WRITE },
124 /* PWR_CTL is controlled only by the probe and reset functions */
125 { TVP7002_PWR_CTL, 0x00, TVP7002_RESERVED },
126 { TVP7002_ADC_SETUP, 0x50, TVP7002_WRITE },
127 { TVP7002_COARSE_CLAMP_CTL, 0x00, TVP7002_WRITE },
128 { TVP7002_SOG_CLAMP, 0x80, TVP7002_WRITE },
129 { TVP7002_RGB_COARSE_CLAMP_CTL, 0x00, TVP7002_WRITE },
130 { TVP7002_SOG_COARSE_CLAMP_CTL, 0x04, TVP7002_WRITE },
131 { TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
132 { 0x32, 0x18, TVP7002_RESERVED },
133 { 0x33, 0x60, TVP7002_RESERVED },
134 { TVP7002_MVIS_STRIPPER_W, 0xff, TVP7002_RESERVED },
135 { TVP7002_VSYNC_ALGN, 0x10, TVP7002_WRITE },
136 { TVP7002_SYNC_BYPASS, 0x00, TVP7002_WRITE },
137 { TVP7002_L_FRAME_STAT_LSBS, 0xff, TVP7002_READ },
138 { TVP7002_L_FRAME_STAT_MSBS, 0xff, TVP7002_READ },
139 { TVP7002_CLK_L_STAT_LSBS, 0xff, TVP7002_READ },
140 { TVP7002_CLK_L_STAT_MSBS, 0xff, TVP7002_READ },
141 { TVP7002_HSYNC_W, 0xff, TVP7002_READ },
142 { TVP7002_VSYNC_W, 0xff, TVP7002_READ },
143 { TVP7002_L_LENGTH_TOL, 0x03, TVP7002_WRITE },
144 { 0x3e, 0x60, TVP7002_RESERVED },
145 { TVP7002_VIDEO_BWTH_CTL, 0x01, TVP7002_WRITE },
146 { TVP7002_AVID_START_PIXEL_LSBS, 0x01, TVP7002_WRITE },
147 { TVP7002_AVID_START_PIXEL_MSBS, 0x2c, TVP7002_WRITE },
148 { TVP7002_AVID_STOP_PIXEL_LSBS, 0x06, TVP7002_WRITE },
149 { TVP7002_AVID_STOP_PIXEL_MSBS, 0x2c, TVP7002_WRITE },
150 { TVP7002_VBLK_F_0_START_L_OFF, 0x05, TVP7002_WRITE },
151 { TVP7002_VBLK_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
152 { TVP7002_VBLK_F_0_DURATION, 0x1e, TVP7002_WRITE },
153 { TVP7002_VBLK_F_1_DURATION, 0x00, TVP7002_WRITE },
154 { TVP7002_FBIT_F_0_START_L_OFF, 0x00, TVP7002_WRITE },
155 { TVP7002_FBIT_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
156 { TVP7002_YUV_Y_G_COEF_LSBS, 0xe3, TVP7002_WRITE },
157 { TVP7002_YUV_Y_G_COEF_MSBS, 0x16, TVP7002_WRITE },
158 { TVP7002_YUV_Y_B_COEF_LSBS, 0x4f, TVP7002_WRITE },
159 { TVP7002_YUV_Y_B_COEF_MSBS, 0x02, TVP7002_WRITE },
160 { TVP7002_YUV_Y_R_COEF_LSBS, 0xce, TVP7002_WRITE },
161 { TVP7002_YUV_Y_R_COEF_MSBS, 0x06, TVP7002_WRITE },
162 { TVP7002_YUV_U_G_COEF_LSBS, 0xab, TVP7002_WRITE },
163 { TVP7002_YUV_U_G_COEF_MSBS, 0xf3, TVP7002_WRITE },
164 { TVP7002_YUV_U_B_COEF_LSBS, 0x00, TVP7002_WRITE },
165 { TVP7002_YUV_U_B_COEF_MSBS, 0x10, TVP7002_WRITE },
166 { TVP7002_YUV_U_R_COEF_LSBS, 0x55, TVP7002_WRITE },
167 { TVP7002_YUV_U_R_COEF_MSBS, 0xfc, TVP7002_WRITE },
168 { TVP7002_YUV_V_G_COEF_LSBS, 0x78, TVP7002_WRITE },
169 { TVP7002_YUV_V_G_COEF_MSBS, 0xf1, TVP7002_WRITE },
170 { TVP7002_YUV_V_B_COEF_LSBS, 0x88, TVP7002_WRITE },
171 { TVP7002_YUV_V_B_COEF_MSBS, 0xfe, TVP7002_WRITE },
172 { TVP7002_YUV_V_R_COEF_LSBS, 0x00, TVP7002_WRITE },
173 { TVP7002_YUV_V_R_COEF_MSBS, 0x10, TVP7002_WRITE },
174 /* This signals end of register values */
175 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
176};
177
178/* Register parameters for 480P */
179static const struct i2c_reg_value tvp7002_parms_480P[] = {
180 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x35, TVP7002_WRITE },
181 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x0a, TVP7002_WRITE },
182 { TVP7002_HPLL_CRTL, 0x02, TVP7002_WRITE },
183 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
184 { TVP7002_AVID_START_PIXEL_LSBS, 0x91, TVP7002_WRITE },
185 { TVP7002_AVID_START_PIXEL_MSBS, 0x00, TVP7002_WRITE },
186 { TVP7002_AVID_STOP_PIXEL_LSBS, 0x0B, TVP7002_WRITE },
187 { TVP7002_AVID_STOP_PIXEL_MSBS, 0x00, TVP7002_WRITE },
188 { TVP7002_VBLK_F_0_START_L_OFF, 0x03, TVP7002_WRITE },
189 { TVP7002_VBLK_F_1_START_L_OFF, 0x01, TVP7002_WRITE },
190 { TVP7002_VBLK_F_0_DURATION, 0x13, TVP7002_WRITE },
191 { TVP7002_VBLK_F_1_DURATION, 0x13, TVP7002_WRITE },
192 { TVP7002_ALC_PLACEMENT, 0x18, TVP7002_WRITE },
193 { TVP7002_CLAMP_START, 0x06, TVP7002_WRITE },
194 { TVP7002_CLAMP_W, 0x10, TVP7002_WRITE },
195 { TVP7002_HPLL_PRE_COAST, 0x03, TVP7002_WRITE },
196 { TVP7002_HPLL_POST_COAST, 0x03, TVP7002_WRITE },
197 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
198};
199
200/* Register parameters for 576P */
201static const struct i2c_reg_value tvp7002_parms_576P[] = {
202 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x36, TVP7002_WRITE },
203 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x00, TVP7002_WRITE },
204 { TVP7002_HPLL_CRTL, 0x18, TVP7002_WRITE },
205 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
206 { TVP7002_AVID_START_PIXEL_LSBS, 0x9B, TVP7002_WRITE },
207 { TVP7002_AVID_START_PIXEL_MSBS, 0x00, TVP7002_WRITE },
208 { TVP7002_AVID_STOP_PIXEL_LSBS, 0x0F, TVP7002_WRITE },
209 { TVP7002_AVID_STOP_PIXEL_MSBS, 0x00, TVP7002_WRITE },
210 { TVP7002_VBLK_F_0_START_L_OFF, 0x00, TVP7002_WRITE },
211 { TVP7002_VBLK_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
212 { TVP7002_VBLK_F_0_DURATION, 0x2D, TVP7002_WRITE },
213 { TVP7002_VBLK_F_1_DURATION, 0x00, TVP7002_WRITE },
214 { TVP7002_ALC_PLACEMENT, 0x18, TVP7002_WRITE },
215 { TVP7002_CLAMP_START, 0x06, TVP7002_WRITE },
216 { TVP7002_CLAMP_W, 0x10, TVP7002_WRITE },
217 { TVP7002_HPLL_PRE_COAST, 0x03, TVP7002_WRITE },
218 { TVP7002_HPLL_POST_COAST, 0x03, TVP7002_WRITE },
219 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
220};
221
222/* Register parameters for 1080I60 */
223static const struct i2c_reg_value tvp7002_parms_1080I60[] = {
224 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE },
225 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x08, TVP7002_WRITE },
226 { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
227 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
228 { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
229 { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
230 { TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
231 { TVP7002_AVID_STOP_PIXEL_MSBS, 0x08, TVP7002_WRITE },
232 { TVP7002_VBLK_F_0_START_L_OFF, 0x02, TVP7002_WRITE },
233 { TVP7002_VBLK_F_1_START_L_OFF, 0x02, TVP7002_WRITE },
234 { TVP7002_VBLK_F_0_DURATION, 0x16, TVP7002_WRITE },
235 { TVP7002_VBLK_F_1_DURATION, 0x17, TVP7002_WRITE },
236 { TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
237 { TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
238 { TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
239 { TVP7002_HPLL_PRE_COAST, 0x01, TVP7002_WRITE },
240 { TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
241 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
242};
243
244/* Register parameters for 1080P60 */
245static const struct i2c_reg_value tvp7002_parms_1080P60[] = {
246 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x89, TVP7002_WRITE },
247 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x08, TVP7002_WRITE },
248 { TVP7002_HPLL_CRTL, 0xE0, TVP7002_WRITE },
249 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
250 { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
251 { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
252 { TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
253 { TVP7002_AVID_STOP_PIXEL_MSBS, 0x08, TVP7002_WRITE },
254 { TVP7002_VBLK_F_0_START_L_OFF, 0x02, TVP7002_WRITE },
255 { TVP7002_VBLK_F_1_START_L_OFF, 0x02, TVP7002_WRITE },
256 { TVP7002_VBLK_F_0_DURATION, 0x16, TVP7002_WRITE },
257 { TVP7002_VBLK_F_1_DURATION, 0x17, TVP7002_WRITE },
258 { TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
259 { TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
260 { TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
261 { TVP7002_HPLL_PRE_COAST, 0x01, TVP7002_WRITE },
262 { TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
263 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
264};
265
266/* Register parameters for 1080I50 */
267static const struct i2c_reg_value tvp7002_parms_1080I50[] = {
268 { TVP7002_HPLL_FDBK_DIV_MSBS, 0xa5, TVP7002_WRITE },
269 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x00, TVP7002_WRITE },
270 { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
271 { TVP7002_HPLL_PHASE_SEL, 0x14, TVP7002_WRITE },
272 { TVP7002_AVID_START_PIXEL_LSBS, 0x06, TVP7002_WRITE },
273 { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
274 { TVP7002_AVID_STOP_PIXEL_LSBS, 0x8a, TVP7002_WRITE },
275 { TVP7002_AVID_STOP_PIXEL_MSBS, 0x08, TVP7002_WRITE },
276 { TVP7002_VBLK_F_0_START_L_OFF, 0x02, TVP7002_WRITE },
277 { TVP7002_VBLK_F_1_START_L_OFF, 0x02, TVP7002_WRITE },
278 { TVP7002_VBLK_F_0_DURATION, 0x16, TVP7002_WRITE },
279 { TVP7002_VBLK_F_1_DURATION, 0x17, TVP7002_WRITE },
280 { TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
281 { TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
282 { TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
283 { TVP7002_HPLL_PRE_COAST, 0x01, TVP7002_WRITE },
284 { TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
285 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
286};
287
288/* Register parameters for 720P60 */
289static const struct i2c_reg_value tvp7002_parms_720P60[] = {
290 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x67, TVP7002_WRITE },
291 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x02, TVP7002_WRITE },
292 { TVP7002_HPLL_CRTL, 0xa0, TVP7002_WRITE },
293 { TVP7002_HPLL_PHASE_SEL, 0x16, TVP7002_WRITE },
294 { TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE },
295 { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
296 { TVP7002_AVID_STOP_PIXEL_LSBS, 0x4B, TVP7002_WRITE },
297 { TVP7002_AVID_STOP_PIXEL_MSBS, 0x06, TVP7002_WRITE },
298 { TVP7002_VBLK_F_0_START_L_OFF, 0x05, TVP7002_WRITE },
299 { TVP7002_VBLK_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
300 { TVP7002_VBLK_F_0_DURATION, 0x2D, TVP7002_WRITE },
301 { TVP7002_VBLK_F_1_DURATION, 0x00, TVP7002_WRITE },
302 { TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
303 { TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
304 { TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
305 { TVP7002_HPLL_PRE_COAST, 0x00, TVP7002_WRITE },
306 { TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
307 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
308};
309
310/* Register parameters for 720P50 */
311static const struct i2c_reg_value tvp7002_parms_720P50[] = {
312 { TVP7002_HPLL_FDBK_DIV_MSBS, 0x7b, TVP7002_WRITE },
313 { TVP7002_HPLL_FDBK_DIV_LSBS, 0x0c, TVP7002_WRITE },
314 { TVP7002_HPLL_CRTL, 0x98, TVP7002_WRITE },
315 { TVP7002_HPLL_PHASE_SEL, 0x16, TVP7002_WRITE },
316 { TVP7002_AVID_START_PIXEL_LSBS, 0x47, TVP7002_WRITE },
317 { TVP7002_AVID_START_PIXEL_MSBS, 0x01, TVP7002_WRITE },
318 { TVP7002_AVID_STOP_PIXEL_LSBS, 0x4B, TVP7002_WRITE },
319 { TVP7002_AVID_STOP_PIXEL_MSBS, 0x06, TVP7002_WRITE },
320 { TVP7002_VBLK_F_0_START_L_OFF, 0x05, TVP7002_WRITE },
321 { TVP7002_VBLK_F_1_START_L_OFF, 0x00, TVP7002_WRITE },
322 { TVP7002_VBLK_F_0_DURATION, 0x2D, TVP7002_WRITE },
323 { TVP7002_VBLK_F_1_DURATION, 0x00, TVP7002_WRITE },
324 { TVP7002_ALC_PLACEMENT, 0x5a, TVP7002_WRITE },
325 { TVP7002_CLAMP_START, 0x32, TVP7002_WRITE },
326 { TVP7002_CLAMP_W, 0x20, TVP7002_WRITE },
327 { TVP7002_HPLL_PRE_COAST, 0x01, TVP7002_WRITE },
328 { TVP7002_HPLL_POST_COAST, 0x00, TVP7002_WRITE },
329 { TVP7002_EOR, 0xff, TVP7002_RESERVED }
330};
331
332/* Struct list for available formats */
333static const struct v4l2_fmtdesc tvp7002_fmt_list[] = {
334 {
335 .index = 0,
336 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
337 .flags = 0,
338 .description = "8-bit UYVY 4:2:2 Format",
339 .pixelformat = V4L2_PIX_FMT_UYVY,
340 },
341};
342
343#define NUM_FORMATS ARRAY_SIZE(tvp7002_fmt_list)
344
345/* Preset definition for handling device operation */
346struct tvp7002_preset_definition {
347 u32 preset;
348 const struct i2c_reg_value *p_settings;
349 enum v4l2_colorspace color_space;
350 enum v4l2_field scanmode;
351 u16 progressive;
352 u16 lines_per_frame;
353 u16 cpl_min;
354 u16 cpl_max;
355};
356
357/* Struct list for digital video presets */
358static const struct tvp7002_preset_definition tvp7002_presets[] = {
359 {
360 V4L2_DV_720P60,
361 tvp7002_parms_720P60,
362 V4L2_COLORSPACE_REC709,
363 V4L2_FIELD_NONE,
364 1,
365 0x2EE,
366 135,
367 153
368 },
369 {
370 V4L2_DV_1080I60,
371 tvp7002_parms_1080I60,
372 V4L2_COLORSPACE_REC709,
373 V4L2_FIELD_INTERLACED,
374 0,
375 0x465,
376 181,
377 205
378 },
379 {
380 V4L2_DV_1080I50,
381 tvp7002_parms_1080I50,
382 V4L2_COLORSPACE_REC709,
383 V4L2_FIELD_INTERLACED,
384 0,
385 0x465,
386 217,
387 245
388 },
389 {
390 V4L2_DV_720P50,
391 tvp7002_parms_720P50,
392 V4L2_COLORSPACE_REC709,
393 V4L2_FIELD_NONE,
394 1,
395 0x2EE,
396 163,
397 183
398 },
399 {
400 V4L2_DV_1080P60,
401 tvp7002_parms_1080P60,
402 V4L2_COLORSPACE_REC709,
403 V4L2_FIELD_NONE,
404 1,
405 0x465,
406 90,
407 102
408 },
409 {
410 V4L2_DV_480P59_94,
411 tvp7002_parms_480P,
412 V4L2_COLORSPACE_SMPTE170M,
413 V4L2_FIELD_NONE,
414 1,
415 0x20D,
416 0xffff,
417 0xffff
418 },
419 {
420 V4L2_DV_576P50,
421 tvp7002_parms_576P,
422 V4L2_COLORSPACE_SMPTE170M,
423 V4L2_FIELD_NONE,
424 1,
425 0x271,
426 0xffff,
427 0xffff
428 }
429};
430
431#define NUM_PRESETS ARRAY_SIZE(tvp7002_presets)
432
433/* Device definition */
434struct tvp7002 {
435 struct v4l2_subdev sd;
436 const struct tvp7002_config *pdata;
437
438 int ver;
439 int streaming;
440
441 struct v4l2_pix_format pix;
442 const struct tvp7002_preset_definition *current_preset;
443 u8 gain;
444};
445
446/*
447 * to_tvp7002 - Obtain device handler TVP7002
448 * @sd: ptr to v4l2_subdev struct
449 *
450 * Returns device handler tvp7002.
451 */
452static inline struct tvp7002 *to_tvp7002(struct v4l2_subdev *sd)
453{
454 return container_of(sd, struct tvp7002, sd);
455}
456
457/*
458 * tvp7002_read - Read a value from a register in an TVP7002
459 * @sd: ptr to v4l2_subdev struct
460 * @reg: TVP7002 register address
461 * @dst: pointer to 8-bit destination
462 *
463 * Returns value read if successful, or non-zero (-1) otherwise.
464 */
465static int tvp7002_read(struct v4l2_subdev *sd, u8 addr, u8 *dst)
466{
467 struct i2c_client *c = v4l2_get_subdevdata(sd);
468 int retry;
469 int error;
470
471 for (retry = 0; retry < I2C_RETRY_COUNT; retry++) {
472 error = i2c_smbus_read_byte_data(c, addr);
473
474 if (error >= 0) {
475 *dst = (u8)error;
476 return 0;
477 }
478
479 msleep_interruptible(10);
480 }
481 v4l2_err(sd, "TVP7002 read error %d\n", error);
482 return error;
483}
484
485/*
486 * tvp7002_read_err() - Read a register value with error code
487 * @sd: pointer to standard V4L2 sub-device structure
488 * @reg: destination register
489 * @val: value to be read
490 * @error: pointer to error value
491 *
492 * Read a value in a register and save error value in pointer.
493 * Also update the register table if successful
494 */
495static inline void tvp7002_read_err(struct v4l2_subdev *sd, u8 reg,
496 u8 *dst, int *err)
497{
498 if (!*err)
499 *err = tvp7002_read(sd, reg, dst);
500}
501
502/*
503 * tvp7002_write() - Write a value to a register in TVP7002
504 * @sd: ptr to v4l2_subdev struct
505 * @addr: TVP7002 register address
506 * @value: value to be written to the register
507 *
508 * Write a value to a register in an TVP7002 decoder device.
509 * Returns zero if successful, or non-zero otherwise.
510 */
511static int tvp7002_write(struct v4l2_subdev *sd, u8 addr, u8 value)
512{
513 struct i2c_client *c;
514 int retry;
515 int error;
516
517 c = v4l2_get_subdevdata(sd);
518
519 for (retry = 0; retry < I2C_RETRY_COUNT; retry++) {
520 error = i2c_smbus_write_byte_data(c, addr, value);
521
522 if (error >= 0)
523 return 0;
524
525 v4l2_warn(sd, "Write: retry ... %d\n", retry);
526 msleep_interruptible(10);
527 }
528 v4l2_err(sd, "TVP7002 write error %d\n", error);
529 return error;
530}
531
532/*
533 * tvp7002_write_err() - Write a register value with error code
534 * @sd: pointer to standard V4L2 sub-device structure
535 * @reg: destination register
536 * @val: value to be written
537 * @error: pointer to error value
538 *
539 * Write a value in a register and save error value in pointer.
540 * Also update the register table if successful
541 */
542static inline void tvp7002_write_err(struct v4l2_subdev *sd, u8 reg,
543 u8 val, int *err)
544{
545 if (!*err)
546 *err = tvp7002_write(sd, reg, val);
547}
548
549/*
550 * tvp7002_g_chip_ident() - Get chip identification number
551 * @sd: ptr to v4l2_subdev struct
552 * @chip: ptr to v4l2_dbg_chip_ident struct
553 *
554 * Obtains the chip's identification number.
555 * Returns zero or -EINVAL if read operation fails.
556 */
557static int tvp7002_g_chip_ident(struct v4l2_subdev *sd,
558 struct v4l2_dbg_chip_ident *chip)
559{
560 u8 rev;
561 int error;
562 struct i2c_client *client = v4l2_get_subdevdata(sd);
563
564 error = tvp7002_read(sd, TVP7002_CHIP_REV, &rev);
565
566 if (error < 0)
567 return error;
568
569 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVP7002, rev);
570}
571
572/*
573 * tvp7002_write_inittab() - Write initialization values
574 * @sd: ptr to v4l2_subdev struct
575 * @regs: ptr to i2c_reg_value struct
576 *
577 * Write initialization values.
578 * Returns zero or -EINVAL if read operation fails.
579 */
580static int tvp7002_write_inittab(struct v4l2_subdev *sd,
581 const struct i2c_reg_value *regs)
582{
583 int error = 0;
584
585 /* Initialize the first (defined) registers */
586 while (TVP7002_EOR != regs->reg) {
587 if (TVP7002_WRITE == regs->type)
588 tvp7002_write_err(sd, regs->reg, regs->value, &error);
589 regs++;
590 }
591
592 return error;
593}
594
595/*
596 * tvp7002_s_dv_preset() - Set digital video preset
597 * @sd: ptr to v4l2_subdev struct
598 * @std: ptr to v4l2_dv_preset struct
599 *
600 * Set the digital video preset for a TVP7002 decoder device.
601 * Returns zero when successful or -EINVAL if register access fails.
602 */
603static int tvp7002_s_dv_preset(struct v4l2_subdev *sd,
604 struct v4l2_dv_preset *dv_preset)
605{
606 struct tvp7002 *device = to_tvp7002(sd);
607 u32 preset;
608 int i;
609
610 for (i = 0; i < NUM_PRESETS; i++) {
611 preset = tvp7002_presets[i].preset;
612 if (preset == dv_preset->preset) {
613 device->current_preset = &tvp7002_presets[i];
614 return tvp7002_write_inittab(sd, tvp7002_presets[i].p_settings);
615 }
616 }
617
618 return -EINVAL;
619}
620
621/*
622 * tvp7002_g_ctrl() - Get a control
623 * @sd: ptr to v4l2_subdev struct
624 * @ctrl: ptr to v4l2_control struct
625 *
626 * Get a control for a TVP7002 decoder device.
627 * Returns zero when successful or -EINVAL if register access fails.
628 */
629static int tvp7002_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
630{
631 struct tvp7002 *device = to_tvp7002(sd);
632
633 switch (ctrl->id) {
634 case V4L2_CID_GAIN:
635 ctrl->value = device->gain;
636 return 0;
637 default:
638 return -EINVAL;
639 }
640}
641
642/*
643 * tvp7002_s_ctrl() - Set a control
644 * @sd: ptr to v4l2_subdev struct
645 * @ctrl: ptr to v4l2_control struct
646 *
647 * Set a control in TVP7002 decoder device.
648 * Returns zero when successful or -EINVAL if register access fails.
649 */
650static int tvp7002_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
651{
652 struct tvp7002 *device = to_tvp7002(sd);
653 int error = 0;
654
655 switch (ctrl->id) {
656 case V4L2_CID_GAIN:
657 tvp7002_write_err(sd, TVP7002_R_FINE_GAIN,
658 ctrl->value & 0xff, &error);
659 tvp7002_write_err(sd, TVP7002_G_FINE_GAIN,
660 ctrl->value & 0xff, &error);
661 tvp7002_write_err(sd, TVP7002_B_FINE_GAIN,
662 ctrl->value & 0xff, &error);
663
664 if (error < 0)
665 return error;
666
667 /* Set only after knowing there is no error */
668 device->gain = ctrl->value & 0xff;
669 return 0;
670 default:
671 return -EINVAL;
672 }
673}
674
675/*
676 * tvp7002_queryctrl() - Query a control
677 * @sd: ptr to v4l2_subdev struct
678 * @ctrl: ptr to v4l2_queryctrl struct
679 *
680 * Query a control of a TVP7002 decoder device.
681 * Returns zero when successful or -EINVAL if register read fails.
682 */
683static int tvp7002_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
684{
685 switch (qc->id) {
686 case V4L2_CID_GAIN:
687 /*
688 * Gain is supported [0-255, default=0, step=1]
689 */
690 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 0);
691 default:
692 return -EINVAL;
693 }
694}
695
696/*
697 * tvp7002_try_fmt_cap() - V4L2 decoder interface handler for try_fmt
698 * @sd: pointer to standard V4L2 sub-device structure
699 * @f: pointer to standard V4L2 VIDIOC_TRY_FMT ioctl structure
700 *
701 * Implement the VIDIOC_TRY_FMT ioctl for the CAPTURE buffer type. This
702 * ioctl is used to negotiate the image capture size and pixel format
703 * without actually making it take effect.
704 */
705static int tvp7002_try_fmt_cap(struct v4l2_subdev *sd, struct v4l2_format *f)
706{
707 struct tvp7002 *device = to_tvp7002(sd);
708 struct v4l2_dv_enum_preset e_preset;
709 struct v4l2_pix_format *pix;
710 int error = 0;
711
712 pix = &f->fmt.pix;
713
714 /* Calculate height and width based on current standard */
715 error = v4l_fill_dv_preset_info(device->current_preset->preset, &e_preset);
716 if (error)
717 return -EINVAL;
718
719 pix->width = e_preset.width;
720 pix->height = e_preset.height;
721 pix->pixelformat = V4L2_PIX_FMT_UYVY;
722 pix->field = device->current_preset->scanmode;
723 pix->bytesperline = pix->width * 2;
724 pix->sizeimage = pix->bytesperline * pix->height;
725 pix->colorspace = device->current_preset->color_space;
726 pix->priv = 0;
727
728 v4l2_dbg(1, debug, sd, "Try FMT: pixelformat - %s, bytesperline - %d"
729 "Width - %d, Height - %d", "8-bit UYVY 4:2:2 Format",
730 pix->bytesperline, pix->width, pix->height);
731 return error;
732}
733
734/*
735 * tvp7002_s_fmt() - V4L2 decoder interface handler for s_fmt
736 * @sd: pointer to standard V4L2 sub-device structure
737 * @f: pointer to standard V4L2 VIDIOC_S_FMT ioctl structure
738 *
739 * If the requested format is supported, configures the HW to use that
740 * format, returns error code if format not supported or HW can't be
741 * correctly configured.
742 */
743static int tvp7002_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
744{
745 struct tvp7002 *decoder = to_tvp7002(sd);
746 int rval;
747
748 rval = tvp7002_try_fmt_cap(sd, f);
749 if (!rval)
750 decoder->pix = f->fmt.pix;
751 return rval;
752}
753
754/*
755 * tvp7002_g_fmt() - V4L2 decoder interface handler for tvp7002_g_fmt
756 * @sd: pointer to standard V4L2 sub-device structure
757 * @f: pointer to standard V4L2 v4l2_format structure
758 *
759 * Returns the decoder's current pixel format in the v4l2_format
760 * parameter.
761 */
762static int tvp7002_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
763{
764 struct tvp7002 *decoder = to_tvp7002(sd);
765
766 f->fmt.pix = decoder->pix;
767
768 v4l2_dbg(1, debug, sd, "Current FMT: bytesperline - %d"
769 "Width - %d, Height - %d",
770 decoder->pix.bytesperline,
771 decoder->pix.width, decoder->pix.height);
772 return 0;
773}
774
775/*
776 * tvp7002_query_dv_preset() - query DV preset
777 * @sd: pointer to standard V4L2 sub-device structure
778 * @std_id: standard V4L2 v4l2_dv_preset
779 *
780 * Returns the current DV preset by TVP7002. If no active input is
781 * detected, returns -EINVAL
782 */
783static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
784 struct v4l2_dv_preset *qpreset)
785{
786 const struct tvp7002_preset_definition *presets = tvp7002_presets;
787 struct v4l2_dv_enum_preset e_preset;
788 struct tvp7002 *device;
789 u8 progressive;
790 u32 lpfr;
791 u32 cpln;
792 int error = 0;
793 u8 lpf_lsb;
794 u8 lpf_msb;
795 u8 cpl_lsb;
796 u8 cpl_msb;
797 int index;
798
799 device = to_tvp7002(sd);
800
801 /* Read standards from device registers */
802 tvp7002_read_err(sd, TVP7002_L_FRAME_STAT_LSBS, &lpf_lsb, &error);
803 tvp7002_read_err(sd, TVP7002_L_FRAME_STAT_MSBS, &lpf_msb, &error);
804
805 if (error < 0)
806 return error;
807
808 tvp7002_read_err(sd, TVP7002_CLK_L_STAT_LSBS, &cpl_lsb, &error);
809 tvp7002_read_err(sd, TVP7002_CLK_L_STAT_MSBS, &cpl_msb, &error);
810
811 if (error < 0)
812 return error;
813
814 /* Get lines per frame, clocks per line and interlaced/progresive */
815 lpfr = lpf_lsb | ((TVP7002_CL_MASK & lpf_msb) << TVP7002_CL_SHIFT);
816 cpln = cpl_lsb | ((TVP7002_CL_MASK & cpl_msb) << TVP7002_CL_SHIFT);
817 progressive = (lpf_msb & TVP7002_INPR_MASK) >> TVP7002_IP_SHIFT;
818
819 /* Do checking of video modes */
820 for (index = 0; index < NUM_PRESETS; index++, presets++)
821 if (lpfr == presets->lines_per_frame &&
822 progressive == presets->progressive) {
823 if (presets->cpl_min == 0xffff)
824 break;
825 if (cpln >= presets->cpl_min && cpln <= presets->cpl_max)
826 break;
827 }
828
829 if (index == NUM_PRESETS) {
830 v4l2_err(sd, "querystd error, lpf = %x, cpl = %x\n",
831 lpfr, cpln);
832 return -EINVAL;
833 }
834
835 if (v4l_fill_dv_preset_info(presets->preset, &e_preset))
836 return -EINVAL;
837
838 /* Set values in found preset */
839 qpreset->preset = presets->preset;
840
841 /* Update lines per frame and clocks per line info */
842 v4l2_dbg(1, debug, sd, "Current preset: %d %d",
843 e_preset.width, e_preset.height);
844 return 0;
845}
846
847#ifdef CONFIG_VIDEO_ADV_DEBUG
848/*
849 * tvp7002_g_register() - Get the value of a register
850 * @sd: ptr to v4l2_subdev struct
851 * @vreg: ptr to v4l2_dbg_register struct
852 *
853 * Get the value of a TVP7002 decoder device register.
854 * Returns zero when successful, -EINVAL if register read fails or
855 * access to I2C client fails, -EPERM if the call is not allowed
856 * by diabled CAP_SYS_ADMIN.
857 */
858static int tvp7002_g_register(struct v4l2_subdev *sd,
859 struct v4l2_dbg_register *reg)
860{
861 struct i2c_client *client = v4l2_get_subdevdata(sd);
862 u8 val;
863 int ret;
864
865 if (!v4l2_chip_match_i2c_client(client, &reg->match))
866 return -EINVAL;
867 if (!capable(CAP_SYS_ADMIN))
868 return -EPERM;
869
870 ret = tvp7002_read(sd, reg->reg & 0xff, &val);
871 reg->val = val;
872 return ret;
873}
874
875/*
876 * tvp7002_s_register() - set a control
877 * @sd: ptr to v4l2_subdev struct
878 * @ctrl: ptr to v4l2_control struct
879 *
880 * Get the value of a TVP7002 decoder device register.
881 * Returns zero when successful, -EINVAL if register read fails or
882 * -EPERM if call not allowed.
883 */
884static int tvp7002_s_register(struct v4l2_subdev *sd,
885 struct v4l2_dbg_register *reg)
886{
887 struct i2c_client *client = v4l2_get_subdevdata(sd);
888
889 if (!v4l2_chip_match_i2c_client(client, &reg->match))
890 return -EINVAL;
891 if (!capable(CAP_SYS_ADMIN))
892 return -EPERM;
893
894 return tvp7002_write(sd, reg->reg & 0xff, reg->val & 0xff);
895}
896#endif
897
898/*
899 * tvp7002_enum_fmt() - Enum supported formats
900 * @sd: pointer to standard V4L2 sub-device structure
901 * @enable: pointer to format struct
902 *
903 * Enumerate supported formats.
904 */
905
906static int tvp7002_enum_fmt(struct v4l2_subdev *sd,
907 struct v4l2_fmtdesc *fmtdesc)
908{
909 /* Check requested format index is within range */
910 if (fmtdesc->index < 0 || fmtdesc->index >= NUM_FORMATS)
911 return -EINVAL;
912 *fmtdesc = tvp7002_fmt_list[fmtdesc->index];
913
914 return 0;
915}
916
917/*
918 * tvp7002_s_stream() - V4L2 decoder i/f handler for s_stream
919 * @sd: pointer to standard V4L2 sub-device structure
920 * @enable: streaming enable or disable
921 *
922 * Sets streaming to enable or disable, if possible.
923 */
924static int tvp7002_s_stream(struct v4l2_subdev *sd, int enable)
925{
926 struct tvp7002 *device = to_tvp7002(sd);
927 int error = 0;
928
929 if (device->streaming == enable)
930 return 0;
931
932 if (enable) {
933 /* Set output state on (low impedance means stream on) */
934 error = tvp7002_write(sd, TVP7002_MISC_CTL_2, 0x00);
935 device->streaming = enable;
936 } else {
937 /* Set output state off (high impedance means stream off) */
938 error = tvp7002_write(sd, TVP7002_MISC_CTL_2, 0x03);
939 if (error)
940 v4l2_dbg(1, debug, sd, "Unable to stop streaming\n");
941
942 device->streaming = enable;
943 }
944
945 return error;
946}
947
948/*
949 * tvp7002_log_status() - Print information about register settings
950 * @sd: ptr to v4l2_subdev struct
951 *
952 * Log register values of a TVP7002 decoder device.
953 * Returns zero or -EINVAL if read operation fails.
954 */
955static int tvp7002_log_status(struct v4l2_subdev *sd)
956{
957 const struct tvp7002_preset_definition *presets = tvp7002_presets;
958 struct tvp7002 *device = to_tvp7002(sd);
959 struct v4l2_dv_enum_preset e_preset;
960 struct v4l2_dv_preset detected;
961 int i;
962
963 detected.preset = V4L2_DV_INVALID;
964 /* Find my current standard*/
965 tvp7002_query_dv_preset(sd, &detected);
966
967 /* Print standard related code values */
968 for (i = 0; i < NUM_PRESETS; i++, presets++)
969 if (presets->preset == detected.preset)
970 break;
971
972 if (v4l_fill_dv_preset_info(device->current_preset->preset, &e_preset))
973 return -EINVAL;
974
975 v4l2_info(sd, "Selected DV Preset: %s\n", e_preset.name);
976 v4l2_info(sd, " Pixels per line: %u\n", e_preset.width);
977 v4l2_info(sd, " Lines per frame: %u\n\n", e_preset.height);
978 if (i == NUM_PRESETS) {
979 v4l2_info(sd, "Detected DV Preset: None\n");
980 } else {
981 if (v4l_fill_dv_preset_info(presets->preset, &e_preset))
982 return -EINVAL;
983 v4l2_info(sd, "Detected DV Preset: %s\n", e_preset.name);
984 v4l2_info(sd, " Pixels per line: %u\n", e_preset.width);
985 v4l2_info(sd, " Lines per frame: %u\n\n", e_preset.height);
986 }
987 v4l2_info(sd, "Streaming enabled: %s\n",
988 device->streaming ? "yes" : "no");
989
990 /* Print the current value of the gain control */
991 v4l2_info(sd, "Gain: %u\n", device->gain);
992
993 return 0;
994}
995
996/* V4L2 core operation handlers */
997static const struct v4l2_subdev_core_ops tvp7002_core_ops = {
998 .g_chip_ident = tvp7002_g_chip_ident,
999 .log_status = tvp7002_log_status,
1000 .g_ctrl = tvp7002_g_ctrl,
1001 .s_ctrl = tvp7002_s_ctrl,
1002 .queryctrl = tvp7002_queryctrl,
1003#ifdef CONFIG_VIDEO_ADV_DEBUG
1004 .g_register = tvp7002_g_register,
1005 .s_register = tvp7002_s_register,
1006#endif
1007};
1008
1009/* Specific video subsystem operation handlers */
1010static const struct v4l2_subdev_video_ops tvp7002_video_ops = {
1011 .s_dv_preset = tvp7002_s_dv_preset,
1012 .query_dv_preset = tvp7002_query_dv_preset,
1013 .s_stream = tvp7002_s_stream,
1014 .g_fmt = tvp7002_g_fmt,
1015 .s_fmt = tvp7002_s_fmt,
1016 .enum_fmt = tvp7002_enum_fmt,
1017};
1018
1019/* V4L2 top level operation handlers */
1020static const struct v4l2_subdev_ops tvp7002_ops = {
1021 .core = &tvp7002_core_ops,
1022 .video = &tvp7002_video_ops,
1023};
1024
1025static struct tvp7002 tvp7002_dev = {
1026 .streaming = 0,
1027
1028 .pix = {
1029 .width = 1280,
1030 .height = 720,
1031 .pixelformat = V4L2_PIX_FMT_UYVY,
1032 .field = V4L2_FIELD_NONE,
1033 .bytesperline = 1280 * 2,
1034 .sizeimage = 1280 * 2 * 720,
1035 .colorspace = V4L2_COLORSPACE_REC709,
1036 },
1037
1038 .current_preset = tvp7002_presets,
1039 .gain = 0,
1040};
1041
1042/*
1043 * tvp7002_probe - Probe a TVP7002 device
1044 * @sd: ptr to v4l2_subdev struct
1045 * @ctrl: ptr to i2c_device_id struct
1046 *
1047 * Initialize the TVP7002 device
1048 * Returns zero when successful, -EINVAL if register read fails or
1049 * -EIO if i2c access is not available.
1050 */
1051static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1052{
1053 struct v4l2_subdev *sd;
1054 struct tvp7002 *device;
1055 struct v4l2_dv_preset preset;
1056 int polarity_a;
1057 int polarity_b;
1058 u8 revision;
1059
1060 int error;
1061
1062 /* Check if the adapter supports the needed features */
1063 if (!i2c_check_functionality(c->adapter,
1064 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
1065 return -EIO;
1066
1067 if (!c->dev.platform_data) {
1068 v4l_err(c, "No platform data!!\n");
1069 return -ENODEV;
1070 }
1071
1072 device = kmalloc(sizeof(struct tvp7002), GFP_KERNEL);
1073
1074 if (!device)
1075 return -ENOMEM;
1076
1077 *device = tvp7002_dev;
1078 sd = &device->sd;
1079 device->pdata = c->dev.platform_data;
1080
1081 /* Tell v4l2 the device is ready */
1082 v4l2_i2c_subdev_init(sd, c, &tvp7002_ops);
1083 v4l_info(c, "tvp7002 found @ 0x%02x (%s)\n",
1084 c->addr, c->adapter->name);
1085
1086 error = tvp7002_read(sd, TVP7002_CHIP_REV, &revision);
1087 if (error < 0)
1088 goto found_error;
1089
1090 /* Get revision number */
1091 v4l2_info(sd, "Rev. %02x detected.\n", revision);
1092 if (revision != 0x02)
1093 v4l2_info(sd, "Unknown revision detected.\n");
1094
1095 /* Initializes TVP7002 to its default values */
1096 error = tvp7002_write_inittab(sd, tvp7002_init_default);
1097
1098 if (error < 0)
1099 goto found_error;
1100
1101 /* Set polarity information after registers have been set */
1102 polarity_a = 0x20 | device->pdata->hs_polarity << 5
1103 | device->pdata->vs_polarity << 2;
1104 error = tvp7002_write(sd, TVP7002_SYNC_CTL_1, polarity_a);
1105 if (error < 0)
1106 goto found_error;
1107
1108 polarity_b = 0x01 | device->pdata->fid_polarity << 2
1109 | device->pdata->sog_polarity << 1
1110 | device->pdata->clk_polarity;
1111 error = tvp7002_write(sd, TVP7002_MISC_CTL_3, polarity_b);
1112 if (error < 0)
1113 goto found_error;
1114
1115 /* Set registers according to default video mode */
1116 preset.preset = device->current_preset->preset;
1117 error = tvp7002_s_dv_preset(sd, &preset);
1118
1119found_error:
1120 if (error < 0)
1121 kfree(device);
1122
1123 return error;
1124}
1125
1126/*
1127 * tvp7002_remove - Remove TVP7002 device support
1128 * @c: ptr to i2c_client struct
1129 *
1130 * Reset the TVP7002 device
1131 * Returns zero.
1132 */
1133static int tvp7002_remove(struct i2c_client *c)
1134{
1135 struct v4l2_subdev *sd = i2c_get_clientdata(c);
1136 struct tvp7002 *device = to_tvp7002(sd);
1137
1138 v4l2_dbg(1, debug, sd, "Removing tvp7002 adapter"
1139 "on address 0x%x\n", c->addr);
1140
1141 v4l2_device_unregister_subdev(sd);
1142 kfree(device);
1143 return 0;
1144}
1145
1146/* I2C Device ID table */
1147static const struct i2c_device_id tvp7002_id[] = {
1148 { "tvp7002", 0 },
1149 { }
1150};
1151MODULE_DEVICE_TABLE(i2c, tvp7002_id);
1152
1153/* I2C driver data */
1154static struct i2c_driver tvp7002_driver = {
1155 .driver = {
1156 .owner = THIS_MODULE,
1157 .name = TVP7002_MODULE_NAME,
1158 },
1159 .probe = tvp7002_probe,
1160 .remove = tvp7002_remove,
1161 .id_table = tvp7002_id,
1162};
1163
1164/*
1165 * tvp7002_init - Initialize driver via I2C interface
1166 *
1167 * Register the TVP7002 driver.
1168 * Return 0 on success or error code on failure.
1169 */
1170static int __init tvp7002_init(void)
1171{
1172 return i2c_add_driver(&tvp7002_driver);
1173}
1174
1175/*
1176 * tvp7002_exit - Remove driver via I2C interface
1177 *
1178 * Unregister the TVP7002 driver.
1179 * Returns nothing.
1180 */
1181static void __exit tvp7002_exit(void)
1182{
1183 i2c_del_driver(&tvp7002_driver);
1184}
1185
1186module_init(tvp7002_init);
1187module_exit(tvp7002_exit);
diff --git a/drivers/media/video/tvp7002_reg.h b/drivers/media/video/tvp7002_reg.h
new file mode 100644
index 000000000000..0e34ca9bccf3
--- /dev/null
+++ b/drivers/media/video/tvp7002_reg.h
@@ -0,0 +1,150 @@
1/* Texas Instruments Triple 8-/10-BIT 165-/110-MSPS Video and Graphics
2 * Digitizer with Horizontal PLL registers
3 *
4 * Copyright (C) 2009 Texas Instruments Inc
5 * Author: Santiago Nunez-Corrales <santiago.nunez@ridgerun.com>
6 *
7 * This code is partially based upon the TVP5150 driver
8 * written by Mauro Carvalho Chehab (mchehab@infradead.org),
9 * the TVP514x driver written by Vaibhav Hiremath <hvaibhav@ti.com>
10 * and the TVP7002 driver in the TI LSP 2.10.00.14
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27/* Naming conventions
28 * ------------------
29 *
30 * FDBK: Feedback
31 * DIV: Divider
32 * CTL: Control
33 * SEL: Select
34 * IN: Input
35 * OUT: Output
36 * R: Red
37 * G: Green
38 * B: Blue
39 * OFF: Offset
40 * THRS: Threshold
41 * DGTL: Digital
42 * LVL: Level
43 * PWR: Power
44 * MVIS: Macrovision
45 * W: Width
46 * H: Height
47 * ALGN: Alignment
48 * CLK: Clocks
49 * TOL: Tolerance
50 * BWTH: Bandwidth
51 * COEF: Coefficient
52 * STAT: Status
53 * AUTO: Automatic
54 * FLD: Field
55 * L: Line
56 */
57
58#define TVP7002_CHIP_REV 0x00
59#define TVP7002_HPLL_FDBK_DIV_MSBS 0x01
60#define TVP7002_HPLL_FDBK_DIV_LSBS 0x02
61#define TVP7002_HPLL_CRTL 0x03
62#define TVP7002_HPLL_PHASE_SEL 0x04
63#define TVP7002_CLAMP_START 0x05
64#define TVP7002_CLAMP_W 0x06
65#define TVP7002_HSYNC_OUT_W 0x07
66#define TVP7002_B_FINE_GAIN 0x08
67#define TVP7002_G_FINE_GAIN 0x09
68#define TVP7002_R_FINE_GAIN 0x0a
69#define TVP7002_B_FINE_OFF_MSBS 0x0b
70#define TVP7002_G_FINE_OFF_MSBS 0x0c
71#define TVP7002_R_FINE_OFF_MSBS 0x0d
72#define TVP7002_SYNC_CTL_1 0x0e
73#define TVP7002_HPLL_AND_CLAMP_CTL 0x0f
74#define TVP7002_SYNC_ON_G_THRS 0x10
75#define TVP7002_SYNC_SEPARATOR_THRS 0x11
76#define TVP7002_HPLL_PRE_COAST 0x12
77#define TVP7002_HPLL_POST_COAST 0x13
78#define TVP7002_SYNC_DETECT_STAT 0x14
79#define TVP7002_OUT_FORMATTER 0x15
80#define TVP7002_MISC_CTL_1 0x16
81#define TVP7002_MISC_CTL_2 0x17
82#define TVP7002_MISC_CTL_3 0x18
83#define TVP7002_IN_MUX_SEL_1 0x19
84#define TVP7002_IN_MUX_SEL_2 0x1a
85#define TVP7002_B_AND_G_COARSE_GAIN 0x1b
86#define TVP7002_R_COARSE_GAIN 0x1c
87#define TVP7002_FINE_OFF_LSBS 0x1d
88#define TVP7002_B_COARSE_OFF 0x1e
89#define TVP7002_G_COARSE_OFF 0x1f
90#define TVP7002_R_COARSE_OFF 0x20
91#define TVP7002_HSOUT_OUT_START 0x21
92#define TVP7002_MISC_CTL_4 0x22
93#define TVP7002_B_DGTL_ALC_OUT_LSBS 0x23
94#define TVP7002_G_DGTL_ALC_OUT_LSBS 0x24
95#define TVP7002_R_DGTL_ALC_OUT_LSBS 0x25
96#define TVP7002_AUTO_LVL_CTL_ENABLE 0x26
97#define TVP7002_DGTL_ALC_OUT_MSBS 0x27
98#define TVP7002_AUTO_LVL_CTL_FILTER 0x28
99/* Reserved 0x29*/
100#define TVP7002_FINE_CLAMP_CTL 0x2a
101#define TVP7002_PWR_CTL 0x2b
102#define TVP7002_ADC_SETUP 0x2c
103#define TVP7002_COARSE_CLAMP_CTL 0x2d
104#define TVP7002_SOG_CLAMP 0x2e
105#define TVP7002_RGB_COARSE_CLAMP_CTL 0x2f
106#define TVP7002_SOG_COARSE_CLAMP_CTL 0x30
107#define TVP7002_ALC_PLACEMENT 0x31
108/* Reserved 0x32 */
109/* Reserved 0x33 */
110#define TVP7002_MVIS_STRIPPER_W 0x34
111#define TVP7002_VSYNC_ALGN 0x35
112#define TVP7002_SYNC_BYPASS 0x36
113#define TVP7002_L_FRAME_STAT_LSBS 0x37
114#define TVP7002_L_FRAME_STAT_MSBS 0x38
115#define TVP7002_CLK_L_STAT_LSBS 0x39
116#define TVP7002_CLK_L_STAT_MSBS 0x3a
117#define TVP7002_HSYNC_W 0x3b
118#define TVP7002_VSYNC_W 0x3c
119#define TVP7002_L_LENGTH_TOL 0x3d
120/* Reserved 0x3e */
121#define TVP7002_VIDEO_BWTH_CTL 0x3f
122#define TVP7002_AVID_START_PIXEL_LSBS 0x40
123#define TVP7002_AVID_START_PIXEL_MSBS 0x41
124#define TVP7002_AVID_STOP_PIXEL_LSBS 0x42
125#define TVP7002_AVID_STOP_PIXEL_MSBS 0x43
126#define TVP7002_VBLK_F_0_START_L_OFF 0x44
127#define TVP7002_VBLK_F_1_START_L_OFF 0x45
128#define TVP7002_VBLK_F_0_DURATION 0x46
129#define TVP7002_VBLK_F_1_DURATION 0x47
130#define TVP7002_FBIT_F_0_START_L_OFF 0x48
131#define TVP7002_FBIT_F_1_START_L_OFF 0x49
132#define TVP7002_YUV_Y_G_COEF_LSBS 0x4a
133#define TVP7002_YUV_Y_G_COEF_MSBS 0x4b
134#define TVP7002_YUV_Y_B_COEF_LSBS 0x4c
135#define TVP7002_YUV_Y_B_COEF_MSBS 0x4d
136#define TVP7002_YUV_Y_R_COEF_LSBS 0x4e
137#define TVP7002_YUV_Y_R_COEF_MSBS 0x4f
138#define TVP7002_YUV_U_G_COEF_LSBS 0x50
139#define TVP7002_YUV_U_G_COEF_MSBS 0x51
140#define TVP7002_YUV_U_B_COEF_LSBS 0x52
141#define TVP7002_YUV_U_B_COEF_MSBS 0x53
142#define TVP7002_YUV_U_R_COEF_LSBS 0x54
143#define TVP7002_YUV_U_R_COEF_MSBS 0x55
144#define TVP7002_YUV_V_G_COEF_LSBS 0x56
145#define TVP7002_YUV_V_G_COEF_MSBS 0x57
146#define TVP7002_YUV_V_B_COEF_LSBS 0x58
147#define TVP7002_YUV_V_B_COEF_MSBS 0x59
148#define TVP7002_YUV_V_R_COEF_LSBS 0x5a
149#define TVP7002_YUV_V_R_COEF_MSBS 0x5b
150
diff --git a/drivers/media/video/tw9910.c b/drivers/media/video/tw9910.c
index 5b801a6e1eea..76be733eabfd 100644
--- a/drivers/media/video/tw9910.c
+++ b/drivers/media/video/tw9910.c
@@ -233,10 +233,10 @@ struct tw9910_hsync_ctrl {
233}; 233};
234 234
235struct tw9910_priv { 235struct tw9910_priv {
236 struct v4l2_subdev subdev; 236 struct v4l2_subdev subdev;
237 struct tw9910_video_info *info; 237 struct tw9910_video_info *info;
238 const struct tw9910_scale_ctrl *scale; 238 const struct tw9910_scale_ctrl *scale;
239 u32 revision; 239 u32 revision;
240}; 240};
241 241
242static const struct tw9910_scale_ctrl tw9910_ntsc_scales[] = { 242static const struct tw9910_scale_ctrl tw9910_ntsc_scales[] = {
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 1054546db908..7c17ec63c5da 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -1487,7 +1487,7 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1487 usbvision->vbi = usbvision_vdev_init(usbvision, 1487 usbvision->vbi = usbvision_vdev_init(usbvision,
1488 &usbvision_vbi_template, 1488 &usbvision_vbi_template,
1489 "USBVision VBI"); 1489 "USBVision VBI");
1490 if (usbvision->vdev == NULL) { 1490 if (usbvision->vbi == NULL) {
1491 goto err_exit; 1491 goto err_exit;
1492 } 1492 }
1493 if (video_register_device(usbvision->vbi, 1493 if (video_register_device(usbvision->vbi,
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index ec8ef8c5560a..3b2e7800d56f 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -23,9 +23,13 @@
23 23
24#include "uvcvideo.h" 24#include "uvcvideo.h"
25 25
26#define UVC_CTRL_NDATA 2
27#define UVC_CTRL_DATA_CURRENT 0 26#define UVC_CTRL_DATA_CURRENT 0
28#define UVC_CTRL_DATA_BACKUP 1 27#define UVC_CTRL_DATA_BACKUP 1
28#define UVC_CTRL_DATA_MIN 2
29#define UVC_CTRL_DATA_MAX 3
30#define UVC_CTRL_DATA_RES 4
31#define UVC_CTRL_DATA_DEF 5
32#define UVC_CTRL_DATA_LAST 6
29 33
30/* ------------------------------------------------------------------------ 34/* ------------------------------------------------------------------------
31 * Controls 35 * Controls
@@ -755,6 +759,49 @@ struct uvc_control *uvc_find_control(struct uvc_video_chain *chain,
755 return ctrl; 759 return ctrl;
756} 760}
757 761
762static int uvc_ctrl_populate_cache(struct uvc_video_chain *chain,
763 struct uvc_control *ctrl)
764{
765 int ret;
766
767 if (ctrl->info->flags & UVC_CONTROL_GET_DEF) {
768 ret = uvc_query_ctrl(chain->dev, UVC_GET_DEF, ctrl->entity->id,
769 chain->dev->intfnum, ctrl->info->selector,
770 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF),
771 ctrl->info->size);
772 if (ret < 0)
773 return ret;
774 }
775
776 if (ctrl->info->flags & UVC_CONTROL_GET_MIN) {
777 ret = uvc_query_ctrl(chain->dev, UVC_GET_MIN, ctrl->entity->id,
778 chain->dev->intfnum, ctrl->info->selector,
779 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN),
780 ctrl->info->size);
781 if (ret < 0)
782 return ret;
783 }
784 if (ctrl->info->flags & UVC_CONTROL_GET_MAX) {
785 ret = uvc_query_ctrl(chain->dev, UVC_GET_MAX, ctrl->entity->id,
786 chain->dev->intfnum, ctrl->info->selector,
787 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX),
788 ctrl->info->size);
789 if (ret < 0)
790 return ret;
791 }
792 if (ctrl->info->flags & UVC_CONTROL_GET_RES) {
793 ret = uvc_query_ctrl(chain->dev, UVC_GET_RES, ctrl->entity->id,
794 chain->dev->intfnum, ctrl->info->selector,
795 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES),
796 ctrl->info->size);
797 if (ret < 0)
798 return ret;
799 }
800
801 ctrl->cached = 1;
802 return 0;
803}
804
758int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain, 805int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
759 struct v4l2_queryctrl *v4l2_ctrl) 806 struct v4l2_queryctrl *v4l2_ctrl)
760{ 807{
@@ -762,17 +809,12 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
762 struct uvc_control_mapping *mapping; 809 struct uvc_control_mapping *mapping;
763 struct uvc_menu_info *menu; 810 struct uvc_menu_info *menu;
764 unsigned int i; 811 unsigned int i;
765 __u8 *data;
766 int ret; 812 int ret;
767 813
768 ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping); 814 ctrl = uvc_find_control(chain, v4l2_ctrl->id, &mapping);
769 if (ctrl == NULL) 815 if (ctrl == NULL)
770 return -EINVAL; 816 return -EINVAL;
771 817
772 data = kmalloc(ctrl->info->size, GFP_KERNEL);
773 if (data == NULL)
774 return -ENOMEM;
775
776 memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl); 818 memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
777 v4l2_ctrl->id = mapping->id; 819 v4l2_ctrl->id = mapping->id;
778 v4l2_ctrl->type = mapping->v4l2_type; 820 v4l2_ctrl->type = mapping->v4l2_type;
@@ -782,14 +824,15 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
782 if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR)) 824 if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR))
783 v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; 825 v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
784 826
785 if (ctrl->info->flags & UVC_CONTROL_GET_DEF) { 827 if (!ctrl->cached) {
786 ret = uvc_query_ctrl(chain->dev, UVC_GET_DEF, ctrl->entity->id, 828 ret = uvc_ctrl_populate_cache(chain, ctrl);
787 chain->dev->intfnum, ctrl->info->selector,
788 data, ctrl->info->size);
789 if (ret < 0) 829 if (ret < 0)
790 goto out; 830 return ret;
791 v4l2_ctrl->default_value = 831 }
792 mapping->get(mapping, UVC_GET_DEF, data); 832
833 if (ctrl->info->flags & UVC_CONTROL_GET_DEF) {
834 v4l2_ctrl->default_value = mapping->get(mapping, UVC_GET_DEF,
835 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_DEF));
793 } 836 }
794 837
795 switch (mapping->v4l2_type) { 838 switch (mapping->v4l2_type) {
@@ -806,56 +849,37 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
806 } 849 }
807 } 850 }
808 851
809 ret = 0; 852 return 0;
810 goto out;
811 853
812 case V4L2_CTRL_TYPE_BOOLEAN: 854 case V4L2_CTRL_TYPE_BOOLEAN:
813 v4l2_ctrl->minimum = 0; 855 v4l2_ctrl->minimum = 0;
814 v4l2_ctrl->maximum = 1; 856 v4l2_ctrl->maximum = 1;
815 v4l2_ctrl->step = 1; 857 v4l2_ctrl->step = 1;
816 ret = 0; 858 return 0;
817 goto out;
818 859
819 case V4L2_CTRL_TYPE_BUTTON: 860 case V4L2_CTRL_TYPE_BUTTON:
820 v4l2_ctrl->minimum = 0; 861 v4l2_ctrl->minimum = 0;
821 v4l2_ctrl->maximum = 0; 862 v4l2_ctrl->maximum = 0;
822 v4l2_ctrl->step = 0; 863 v4l2_ctrl->step = 0;
823 ret = 0; 864 return 0;
824 goto out;
825 865
826 default: 866 default:
827 break; 867 break;
828 } 868 }
829 869
830 if (ctrl->info->flags & UVC_CONTROL_GET_MIN) { 870 if (ctrl->info->flags & UVC_CONTROL_GET_MIN)
831 ret = uvc_query_ctrl(chain->dev, UVC_GET_MIN, ctrl->entity->id, 871 v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN,
832 chain->dev->intfnum, ctrl->info->selector, 872 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
833 data, ctrl->info->size);
834 if (ret < 0)
835 goto out;
836 v4l2_ctrl->minimum = mapping->get(mapping, UVC_GET_MIN, data);
837 }
838 if (ctrl->info->flags & UVC_CONTROL_GET_MAX) {
839 ret = uvc_query_ctrl(chain->dev, UVC_GET_MAX, ctrl->entity->id,
840 chain->dev->intfnum, ctrl->info->selector,
841 data, ctrl->info->size);
842 if (ret < 0)
843 goto out;
844 v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX, data);
845 }
846 if (ctrl->info->flags & UVC_CONTROL_GET_RES) {
847 ret = uvc_query_ctrl(chain->dev, UVC_GET_RES, ctrl->entity->id,
848 chain->dev->intfnum, ctrl->info->selector,
849 data, ctrl->info->size);
850 if (ret < 0)
851 goto out;
852 v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES, data);
853 }
854 873
855 ret = 0; 874 if (ctrl->info->flags & UVC_CONTROL_GET_MAX)
856out: 875 v4l2_ctrl->maximum = mapping->get(mapping, UVC_GET_MAX,
857 kfree(data); 876 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
858 return ret; 877
878 if (ctrl->info->flags & UVC_CONTROL_GET_RES)
879 v4l2_ctrl->step = mapping->get(mapping, UVC_GET_RES,
880 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
881
882 return 0;
859} 883}
860 884
861 885
@@ -997,19 +1021,57 @@ int uvc_ctrl_set(struct uvc_video_chain *chain,
997{ 1021{
998 struct uvc_control *ctrl; 1022 struct uvc_control *ctrl;
999 struct uvc_control_mapping *mapping; 1023 struct uvc_control_mapping *mapping;
1000 s32 value = xctrl->value; 1024 s32 value;
1025 u32 step;
1026 s32 min;
1027 s32 max;
1001 int ret; 1028 int ret;
1002 1029
1003 ctrl = uvc_find_control(chain, xctrl->id, &mapping); 1030 ctrl = uvc_find_control(chain, xctrl->id, &mapping);
1004 if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_SET_CUR) == 0) 1031 if (ctrl == NULL || (ctrl->info->flags & UVC_CONTROL_SET_CUR) == 0)
1005 return -EINVAL; 1032 return -EINVAL;
1006 1033
1007 if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { 1034 /* Clamp out of range values. */
1008 if (value < 0 || value >= mapping->menu_count) 1035 switch (mapping->v4l2_type) {
1009 return -EINVAL; 1036 case V4L2_CTRL_TYPE_INTEGER:
1010 value = mapping->menu_info[value].value; 1037 if (!ctrl->cached) {
1038 ret = uvc_ctrl_populate_cache(chain, ctrl);
1039 if (ret < 0)
1040 return ret;
1041 }
1042
1043 min = mapping->get(mapping, UVC_GET_MIN,
1044 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MIN));
1045 max = mapping->get(mapping, UVC_GET_MAX,
1046 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
1047 step = mapping->get(mapping, UVC_GET_RES,
1048 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
1049
1050 xctrl->value = min + (xctrl->value - min + step/2) / step * step;
1051 xctrl->value = clamp(xctrl->value, min, max);
1052 value = xctrl->value;
1053 break;
1054
1055 case V4L2_CTRL_TYPE_BOOLEAN:
1056 xctrl->value = clamp(xctrl->value, 0, 1);
1057 value = xctrl->value;
1058 break;
1059
1060 case V4L2_CTRL_TYPE_MENU:
1061 if (xctrl->value < 0 || xctrl->value >= mapping->menu_count)
1062 return -ERANGE;
1063 value = mapping->menu_info[xctrl->value].value;
1064 break;
1065
1066 default:
1067 value = xctrl->value;
1068 break;
1011 } 1069 }
1012 1070
1071 /* If the mapping doesn't span the whole UVC control, the current value
1072 * needs to be loaded from the device to perform the read-modify-write
1073 * operation.
1074 */
1013 if (!ctrl->loaded && (ctrl->info->size * 8) != mapping->size) { 1075 if (!ctrl->loaded && (ctrl->info->size * 8) != mapping->size) {
1014 if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) { 1076 if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0) {
1015 memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), 1077 memset(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
@@ -1027,6 +1089,7 @@ int uvc_ctrl_set(struct uvc_video_chain *chain,
1027 ctrl->loaded = 1; 1089 ctrl->loaded = 1;
1028 } 1090 }
1029 1091
1092 /* Backup the current value in case we need to rollback later. */
1030 if (!ctrl->dirty) { 1093 if (!ctrl->dirty) {
1031 memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), 1094 memcpy(uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
1032 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT), 1095 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT),
@@ -1080,10 +1143,8 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
1080 } 1143 }
1081 1144
1082 if (!found) { 1145 if (!found) {
1083 uvc_trace(UVC_TRACE_CONTROL, 1146 uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u not found.\n",
1084 "Control " UVC_GUID_FORMAT "/%u not found.\n", 1147 entity->extension.guidExtensionCode, xctrl->selector);
1085 UVC_GUID_ARGS(entity->extension.guidExtensionCode),
1086 xctrl->selector);
1087 return -EINVAL; 1148 return -EINVAL;
1088 } 1149 }
1089 1150
@@ -1159,9 +1220,9 @@ int uvc_ctrl_resume_device(struct uvc_device *dev)
1159 (ctrl->info->flags & UVC_CONTROL_RESTORE) == 0) 1220 (ctrl->info->flags & UVC_CONTROL_RESTORE) == 0)
1160 continue; 1221 continue;
1161 1222
1162 printk(KERN_INFO "restoring control " UVC_GUID_FORMAT 1223 printk(KERN_INFO "restoring control %pUl/%u/%u\n",
1163 "/%u/%u\n", UVC_GUID_ARGS(ctrl->info->entity), 1224 ctrl->info->entity, ctrl->info->index,
1164 ctrl->info->index, ctrl->info->selector); 1225 ctrl->info->selector);
1165 ctrl->dirty = 1; 1226 ctrl->dirty = 1;
1166 } 1227 }
1167 1228
@@ -1215,47 +1276,43 @@ static void uvc_ctrl_add_ctrl(struct uvc_device *dev,
1215 ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id, 1276 ret = uvc_query_ctrl(dev, UVC_GET_LEN, ctrl->entity->id,
1216 dev->intfnum, info->selector, (__u8 *)&size, 2); 1277 dev->intfnum, info->selector, (__u8 *)&size, 2);
1217 if (ret < 0) { 1278 if (ret < 0) {
1218 uvc_trace(UVC_TRACE_CONTROL, "GET_LEN failed on " 1279 uvc_trace(UVC_TRACE_CONTROL,
1219 "control " UVC_GUID_FORMAT "/%u (%d).\n", 1280 "GET_LEN failed on control %pUl/%u (%d).\n",
1220 UVC_GUID_ARGS(info->entity), info->selector, 1281 info->entity, info->selector, ret);
1221 ret);
1222 return; 1282 return;
1223 } 1283 }
1224 1284
1225 if (info->size != le16_to_cpu(size)) { 1285 if (info->size != le16_to_cpu(size)) {
1226 uvc_trace(UVC_TRACE_CONTROL, "Control " UVC_GUID_FORMAT 1286 uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u size "
1227 "/%u size doesn't match user supplied " 1287 "doesn't match user supplied value.\n",
1228 "value.\n", UVC_GUID_ARGS(info->entity), 1288 info->entity, info->selector);
1229 info->selector);
1230 return; 1289 return;
1231 } 1290 }
1232 1291
1233 ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id, 1292 ret = uvc_query_ctrl(dev, UVC_GET_INFO, ctrl->entity->id,
1234 dev->intfnum, info->selector, &inf, 1); 1293 dev->intfnum, info->selector, &inf, 1);
1235 if (ret < 0) { 1294 if (ret < 0) {
1236 uvc_trace(UVC_TRACE_CONTROL, "GET_INFO failed on " 1295 uvc_trace(UVC_TRACE_CONTROL,
1237 "control " UVC_GUID_FORMAT "/%u (%d).\n", 1296 "GET_INFO failed on control %pUl/%u (%d).\n",
1238 UVC_GUID_ARGS(info->entity), info->selector, 1297 info->entity, info->selector, ret);
1239 ret);
1240 return; 1298 return;
1241 } 1299 }
1242 1300
1243 flags = info->flags; 1301 flags = info->flags;
1244 if (((flags & UVC_CONTROL_GET_CUR) && !(inf & (1 << 0))) || 1302 if (((flags & UVC_CONTROL_GET_CUR) && !(inf & (1 << 0))) ||
1245 ((flags & UVC_CONTROL_SET_CUR) && !(inf & (1 << 1)))) { 1303 ((flags & UVC_CONTROL_SET_CUR) && !(inf & (1 << 1)))) {
1246 uvc_trace(UVC_TRACE_CONTROL, "Control " 1304 uvc_trace(UVC_TRACE_CONTROL, "Control %pUl/%u flags "
1247 UVC_GUID_FORMAT "/%u flags don't match " 1305 "don't match supported operations.\n",
1248 "supported operations.\n", 1306 info->entity, info->selector);
1249 UVC_GUID_ARGS(info->entity), info->selector);
1250 return; 1307 return;
1251 } 1308 }
1252 } 1309 }
1253 1310
1254 ctrl->info = info; 1311 ctrl->info = info;
1255 ctrl->data = kmalloc(ctrl->info->size * UVC_CTRL_NDATA, GFP_KERNEL); 1312 ctrl->data = kmalloc(ctrl->info->size * UVC_CTRL_DATA_LAST, GFP_KERNEL);
1256 uvc_trace(UVC_TRACE_CONTROL, "Added control " UVC_GUID_FORMAT "/%u " 1313 uvc_trace(UVC_TRACE_CONTROL, "Added control %pUl/%u to device %s "
1257 "to device %s entity %u\n", UVC_GUID_ARGS(ctrl->info->entity), 1314 "entity %u\n", ctrl->info->entity, ctrl->info->selector,
1258 ctrl->info->selector, dev->udev->devpath, entity->id); 1315 dev->udev->devpath, entity->id);
1259} 1316}
1260 1317
1261/* 1318/*
@@ -1281,17 +1338,16 @@ int uvc_ctrl_add_info(struct uvc_control_info *info)
1281 continue; 1338 continue;
1282 1339
1283 if (ctrl->selector == info->selector) { 1340 if (ctrl->selector == info->selector) {
1284 uvc_trace(UVC_TRACE_CONTROL, "Control " 1341 uvc_trace(UVC_TRACE_CONTROL,
1285 UVC_GUID_FORMAT "/%u is already defined.\n", 1342 "Control %pUl/%u is already defined.\n",
1286 UVC_GUID_ARGS(info->entity), info->selector); 1343 info->entity, info->selector);
1287 ret = -EEXIST; 1344 ret = -EEXIST;
1288 goto end; 1345 goto end;
1289 } 1346 }
1290 if (ctrl->index == info->index) { 1347 if (ctrl->index == info->index) {
1291 uvc_trace(UVC_TRACE_CONTROL, "Control " 1348 uvc_trace(UVC_TRACE_CONTROL,
1292 UVC_GUID_FORMAT "/%u would overwrite index " 1349 "Control %pUl/%u would overwrite index %d.\n",
1293 "%d.\n", UVC_GUID_ARGS(info->entity), 1350 info->entity, info->selector, info->index);
1294 info->selector, info->index);
1295 ret = -EEXIST; 1351 ret = -EEXIST;
1296 goto end; 1352 goto end;
1297 } 1353 }
@@ -1332,10 +1388,9 @@ int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping)
1332 continue; 1388 continue;
1333 1389
1334 if (info->size * 8 < mapping->size + mapping->offset) { 1390 if (info->size * 8 < mapping->size + mapping->offset) {
1335 uvc_trace(UVC_TRACE_CONTROL, "Mapping '%s' would " 1391 uvc_trace(UVC_TRACE_CONTROL,
1336 "overflow control " UVC_GUID_FORMAT "/%u\n", 1392 "Mapping '%s' would overflow control %pUl/%u\n",
1337 mapping->name, UVC_GUID_ARGS(info->entity), 1393 mapping->name, info->entity, info->selector);
1338 info->selector);
1339 ret = -EOVERFLOW; 1394 ret = -EOVERFLOW;
1340 goto end; 1395 goto end;
1341 } 1396 }
@@ -1354,9 +1409,9 @@ int uvc_ctrl_add_mapping(struct uvc_control_mapping *mapping)
1354 1409
1355 mapping->ctrl = info; 1410 mapping->ctrl = info;
1356 list_add_tail(&mapping->list, &info->mappings); 1411 list_add_tail(&mapping->list, &info->mappings);
1357 uvc_trace(UVC_TRACE_CONTROL, "Adding mapping %s to control " 1412 uvc_trace(UVC_TRACE_CONTROL,
1358 UVC_GUID_FORMAT "/%u.\n", mapping->name, 1413 "Adding mapping %s to control %pUl/%u.\n",
1359 UVC_GUID_ARGS(info->entity), info->selector); 1414 mapping->name, info->entity, info->selector);
1360 1415
1361 ret = 0; 1416 ret = 0;
1362 break; 1417 break;
@@ -1378,6 +1433,7 @@ uvc_ctrl_prune_entity(struct uvc_device *dev, struct uvc_entity *entity)
1378 struct usb_device_id id; 1433 struct usb_device_id id;
1379 u8 index; 1434 u8 index;
1380 } blacklist[] = { 1435 } blacklist[] = {
1436 { { USB_DEVICE(0x13d3, 0x509b) }, 9 }, /* Gain */
1381 { { USB_DEVICE(0x1c4f, 0x3000) }, 6 }, /* WB Temperature */ 1437 { { USB_DEVICE(0x1c4f, 0x3000) }, 6 }, /* WB Temperature */
1382 { { USB_DEVICE(0x5986, 0x0241) }, 2 }, /* Hue */ 1438 { { USB_DEVICE(0x5986, 0x0241) }, 2 }, /* Hue */
1383 }; 1439 };
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
index 391cccca7ffc..a814820a3f6e 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -43,8 +43,9 @@
43#define DRIVER_VERSION "v0.1.0" 43#define DRIVER_VERSION "v0.1.0"
44#endif 44#endif
45 45
46unsigned int uvc_clock_param = CLOCK_MONOTONIC;
46unsigned int uvc_no_drop_param; 47unsigned int uvc_no_drop_param;
47static unsigned int uvc_quirks_param; 48static unsigned int uvc_quirks_param = -1;
48unsigned int uvc_trace_param; 49unsigned int uvc_trace_param;
49unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT; 50unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
50 51
@@ -59,6 +60,11 @@ static struct uvc_format_desc uvc_fmts[] = {
59 .fcc = V4L2_PIX_FMT_YUYV, 60 .fcc = V4L2_PIX_FMT_YUYV,
60 }, 61 },
61 { 62 {
63 .name = "YUV 4:2:2 (YUYV)",
64 .guid = UVC_GUID_FORMAT_YUY2_ISIGHT,
65 .fcc = V4L2_PIX_FMT_YUYV,
66 },
67 {
62 .name = "YUV 4:2:0 (NV12)", 68 .name = "YUV 4:2:0 (NV12)",
63 .guid = UVC_GUID_FORMAT_NV12, 69 .guid = UVC_GUID_FORMAT_NV12,
64 .fcc = V4L2_PIX_FMT_NV12, 70 .fcc = V4L2_PIX_FMT_NV12,
@@ -309,11 +315,10 @@ static int uvc_parse_format(struct uvc_device *dev,
309 sizeof format->name); 315 sizeof format->name);
310 format->fcc = fmtdesc->fcc; 316 format->fcc = fmtdesc->fcc;
311 } else { 317 } else {
312 uvc_printk(KERN_INFO, "Unknown video format " 318 uvc_printk(KERN_INFO, "Unknown video format %pUl\n",
313 UVC_GUID_FORMAT "\n", 319 &buffer[5]);
314 UVC_GUID_ARGS(&buffer[5])); 320 snprintf(format->name, sizeof(format->name), "%pUl\n",
315 snprintf(format->name, sizeof format->name, 321 &buffer[5]);
316 UVC_GUID_FORMAT, UVC_GUID_ARGS(&buffer[5]));
317 format->fcc = 0; 322 format->fcc = 0;
318 } 323 }
319 324
@@ -1750,7 +1755,8 @@ static int uvc_probe(struct usb_interface *intf,
1750 dev->udev = usb_get_dev(udev); 1755 dev->udev = usb_get_dev(udev);
1751 dev->intf = usb_get_intf(intf); 1756 dev->intf = usb_get_intf(intf);
1752 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber; 1757 dev->intfnum = intf->cur_altsetting->desc.bInterfaceNumber;
1753 dev->quirks = id->driver_info | uvc_quirks_param; 1758 dev->quirks = (uvc_quirks_param == -1)
1759 ? id->driver_info : uvc_quirks_param;
1754 1760
1755 if (udev->product != NULL) 1761 if (udev->product != NULL)
1756 strlcpy(dev->name, udev->product, sizeof dev->name); 1762 strlcpy(dev->name, udev->product, sizeof dev->name);
@@ -1773,9 +1779,9 @@ static int uvc_probe(struct usb_interface *intf,
1773 le16_to_cpu(udev->descriptor.idVendor), 1779 le16_to_cpu(udev->descriptor.idVendor),
1774 le16_to_cpu(udev->descriptor.idProduct)); 1780 le16_to_cpu(udev->descriptor.idProduct));
1775 1781
1776 if (uvc_quirks_param != 0) { 1782 if (dev->quirks != id->driver_info) {
1777 uvc_printk(KERN_INFO, "Forcing device quirks 0x%x by module " 1783 uvc_printk(KERN_INFO, "Forcing device quirks to 0x%x by module "
1778 "parameter for testing purpose.\n", uvc_quirks_param); 1784 "parameter for testing purpose.\n", dev->quirks);
1779 uvc_printk(KERN_INFO, "Please report required quirks to the " 1785 uvc_printk(KERN_INFO, "Please report required quirks to the "
1780 "linux-uvc-devel mailing list.\n"); 1786 "linux-uvc-devel mailing list.\n");
1781 } 1787 }
@@ -1892,6 +1898,45 @@ static int uvc_reset_resume(struct usb_interface *intf)
1892} 1898}
1893 1899
1894/* ------------------------------------------------------------------------ 1900/* ------------------------------------------------------------------------
1901 * Module parameters
1902 */
1903
1904static int uvc_clock_param_get(char *buffer, struct kernel_param *kp)
1905{
1906 if (uvc_clock_param == CLOCK_MONOTONIC)
1907 return sprintf(buffer, "CLOCK_MONOTONIC");
1908 else
1909 return sprintf(buffer, "CLOCK_REALTIME");
1910}
1911
1912static int uvc_clock_param_set(const char *val, struct kernel_param *kp)
1913{
1914 if (strncasecmp(val, "clock_", strlen("clock_")) == 0)
1915 val += strlen("clock_");
1916
1917 if (strcasecmp(val, "monotonic") == 0)
1918 uvc_clock_param = CLOCK_MONOTONIC;
1919 else if (strcasecmp(val, "realtime") == 0)
1920 uvc_clock_param = CLOCK_REALTIME;
1921 else
1922 return -EINVAL;
1923
1924 return 0;
1925}
1926
1927module_param_call(clock, uvc_clock_param_set, uvc_clock_param_get,
1928 &uvc_clock_param, S_IRUGO|S_IWUSR);
1929MODULE_PARM_DESC(clock, "Video buffers timestamp clock");
1930module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
1931MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
1932module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
1933MODULE_PARM_DESC(quirks, "Forced device quirks");
1934module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
1935MODULE_PARM_DESC(trace, "Trace level bitmask");
1936module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
1937MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
1938
1939/* ------------------------------------------------------------------------
1895 * Driver initialization and cleanup 1940 * Driver initialization and cleanup
1896 */ 1941 */
1897 1942
@@ -2197,15 +2242,6 @@ static void __exit uvc_cleanup(void)
2197module_init(uvc_init); 2242module_init(uvc_init);
2198module_exit(uvc_cleanup); 2243module_exit(uvc_cleanup);
2199 2244
2200module_param_named(nodrop, uvc_no_drop_param, uint, S_IRUGO|S_IWUSR);
2201MODULE_PARM_DESC(nodrop, "Don't drop incomplete frames");
2202module_param_named(quirks, uvc_quirks_param, uint, S_IRUGO|S_IWUSR);
2203MODULE_PARM_DESC(quirks, "Forced device quirks");
2204module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
2205MODULE_PARM_DESC(trace, "Trace level bitmask");
2206module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
2207MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
2208
2209MODULE_AUTHOR(DRIVER_AUTHOR); 2245MODULE_AUTHOR(DRIVER_AUTHOR);
2210MODULE_DESCRIPTION(DRIVER_DESC); 2246MODULE_DESCRIPTION(DRIVER_DESC);
2211MODULE_LICENSE("GPL"); 2247MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/uvc/uvc_queue.c b/drivers/media/video/uvc/uvc_queue.c
index ea11839cba4a..4a925a31b0e0 100644
--- a/drivers/media/video/uvc/uvc_queue.c
+++ b/drivers/media/video/uvc/uvc_queue.c
@@ -502,7 +502,6 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
502 spin_unlock_irqrestore(&queue->irqlock, flags); 502 spin_unlock_irqrestore(&queue->irqlock, flags);
503 503
504 buf->buf.sequence = queue->sequence++; 504 buf->buf.sequence = queue->sequence++;
505 do_gettimeofday(&buf->buf.timestamp);
506 505
507 wake_up(&buf->wait); 506 wake_up(&buf->wait);
508 return nextbuf; 507 return nextbuf;
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index 23239a4adefe..43152aa52227 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -539,7 +539,7 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
539 xctrl.id = ctrl->id; 539 xctrl.id = ctrl->id;
540 xctrl.value = ctrl->value; 540 xctrl.value = ctrl->value;
541 541
542 uvc_ctrl_begin(chain); 542 ret = uvc_ctrl_begin(chain);
543 if (ret < 0) 543 if (ret < 0)
544 return ret; 544 return ret;
545 545
@@ -549,6 +549,8 @@ static long uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
549 return ret; 549 return ret;
550 } 550 }
551 ret = uvc_ctrl_commit(chain); 551 ret = uvc_ctrl_commit(chain);
552 if (ret == 0)
553 ctrl->value = xctrl.value;
552 break; 554 break;
553 } 555 }
554 556
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
index 7dcf534a0cf3..6b0666be370f 100644
--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -410,6 +410,8 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
410 * when the EOF bit is set to force synchronisation on the next packet. 410 * when the EOF bit is set to force synchronisation on the next packet.
411 */ 411 */
412 if (buf->state != UVC_BUF_STATE_ACTIVE) { 412 if (buf->state != UVC_BUF_STATE_ACTIVE) {
413 struct timespec ts;
414
413 if (fid == stream->last_fid) { 415 if (fid == stream->last_fid) {
414 uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of " 416 uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of "
415 "sync).\n"); 417 "sync).\n");
@@ -419,6 +421,14 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
419 return -ENODATA; 421 return -ENODATA;
420 } 422 }
421 423
424 if (uvc_clock_param == CLOCK_MONOTONIC)
425 ktime_get_ts(&ts);
426 else
427 ktime_get_real_ts(&ts);
428
429 buf->buf.timestamp.tv_sec = ts.tv_sec;
430 buf->buf.timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
431
422 /* TODO: Handle PTS and SCR. */ 432 /* TODO: Handle PTS and SCR. */
423 buf->state = UVC_BUF_STATE_ACTIVE; 433 buf->state = UVC_BUF_STATE_ACTIVE;
424 } 434 }
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
index 2337585001ea..2bba059259e6 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -113,6 +113,9 @@ struct uvc_xu_control {
113#define UVC_GUID_FORMAT_YUY2 \ 113#define UVC_GUID_FORMAT_YUY2 \
114 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \ 114 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
115 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 115 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
116#define UVC_GUID_FORMAT_YUY2_ISIGHT \
117 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00, \
118 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x9b, 0x71}
116#define UVC_GUID_FORMAT_NV12 \ 119#define UVC_GUID_FORMAT_NV12 \
117 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \ 120 { 'N', 'V', '1', '2', 0x00, 0x00, 0x10, 0x00, \
118 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 121 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
@@ -149,7 +152,7 @@ struct uvc_xu_control {
149#define UVC_MAX_STATUS_SIZE 16 152#define UVC_MAX_STATUS_SIZE 16
150 153
151#define UVC_CTRL_CONTROL_TIMEOUT 300 154#define UVC_CTRL_CONTROL_TIMEOUT 300
152#define UVC_CTRL_STREAMING_TIMEOUT 3000 155#define UVC_CTRL_STREAMING_TIMEOUT 5000
153 156
154/* Devices quirks */ 157/* Devices quirks */
155#define UVC_QUIRK_STATUS_INTERVAL 0x00000001 158#define UVC_QUIRK_STATUS_INTERVAL 0x00000001
@@ -242,7 +245,8 @@ struct uvc_control {
242 uvc_control_info. */ 245 uvc_control_info. */
243 __u8 dirty : 1, 246 __u8 dirty : 1,
244 loaded : 1, 247 loaded : 1,
245 modified : 1; 248 modified : 1,
249 cached : 1;
246 250
247 __u8 *data; 251 __u8 *data;
248}; 252};
@@ -533,6 +537,7 @@ struct uvc_driver {
533#define UVC_WARN_MINMAX 0 537#define UVC_WARN_MINMAX 0
534#define UVC_WARN_PROBE_DEF 1 538#define UVC_WARN_PROBE_DEF 1
535 539
540extern unsigned int uvc_clock_param;
536extern unsigned int uvc_no_drop_param; 541extern unsigned int uvc_no_drop_param;
537extern unsigned int uvc_trace_param; 542extern unsigned int uvc_trace_param;
538extern unsigned int uvc_timeout_param; 543extern unsigned int uvc_timeout_param;
@@ -552,16 +557,6 @@ extern unsigned int uvc_timeout_param;
552#define uvc_printk(level, msg...) \ 557#define uvc_printk(level, msg...) \
553 printk(level "uvcvideo: " msg) 558 printk(level "uvcvideo: " msg)
554 559
555#define UVC_GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
556 "%02x%02x%02x%02x%02x%02x"
557#define UVC_GUID_ARGS(guid) \
558 (guid)[3], (guid)[2], (guid)[1], (guid)[0], \
559 (guid)[5], (guid)[4], \
560 (guid)[7], (guid)[6], \
561 (guid)[8], (guid)[9], \
562 (guid)[10], (guid)[11], (guid)[12], \
563 (guid)[13], (guid)[14], (guid)[15]
564
565/* -------------------------------------------------------------------------- 560/* --------------------------------------------------------------------------
566 * Internal functions. 561 * Internal functions.
567 */ 562 */
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index c4150bd26337..f77f84bfe714 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -288,7 +288,7 @@ static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user
288 288
289static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) 289static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
290{ 290{
291 if (copy_to_user(&up->w, &kp->w, sizeof(up->w)) || 291 if (copy_to_user(&up->w, &kp->w, sizeof(kp->w)) ||
292 put_user(kp->field, &up->field) || 292 put_user(kp->field, &up->field) ||
293 put_user(kp->chromakey, &up->chromakey) || 293 put_user(kp->chromakey, &up->chromakey) ||
294 put_user(kp->clipcount, &up->clipcount)) 294 put_user(kp->clipcount, &up->clipcount))
@@ -475,6 +475,9 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
475 return -EFAULT; 475 return -EFAULT;
476 switch (kp->memory) { 476 switch (kp->memory) {
477 case V4L2_MEMORY_MMAP: 477 case V4L2_MEMORY_MMAP:
478 if (get_user(kp->length, &up->length) ||
479 get_user(kp->m.offset, &up->m.offset))
480 return -EFAULT;
478 break; 481 break;
479 case V4L2_MEMORY_USERPTR: 482 case V4L2_MEMORY_USERPTR:
480 { 483 {
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index fa78555b118b..fcd045e7a1c1 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -418,6 +418,8 @@ static void *__videobuf_alloc(size_t size)
418 struct videobuf_buffer *vb; 418 struct videobuf_buffer *vb;
419 419
420 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL); 420 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
421 if (!vb)
422 return vb;
421 423
422 mem = vb->priv = ((char *)vb)+size; 424 mem = vb->priv = ((char *)vb)+size;
423 mem->magic=MAGIC_SG_MEM; 425 mem->magic=MAGIC_SG_MEM;
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index d6e6a28fb6b8..136e09383c06 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -138,6 +138,8 @@ static void *__videobuf_alloc(size_t size)
138 struct videobuf_buffer *vb; 138 struct videobuf_buffer *vb;
139 139
140 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL); 140 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
141 if (!vb)
142 return vb;
141 143
142 mem = vb->priv = ((char *)vb)+size; 144 mem = vb->priv = ((char *)vb)+size;
143 mem->magic=MAGIC_VMAL_MEM; 145 mem->magic=MAGIC_VMAL_MEM;
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 37632a064966..cdbe70385c12 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -1371,7 +1371,7 @@ static int __init vivi_create_instance(int inst)
1371 /* Now that everything is fine, let's add it to device list */ 1371 /* Now that everything is fine, let's add it to device list */
1372 list_add_tail(&dev->vivi_devlist, &vivi_devlist); 1372 list_add_tail(&dev->vivi_devlist, &vivi_devlist);
1373 1373
1374 if (video_nr >= 0) 1374 if (video_nr != -1)
1375 video_nr++; 1375 video_nr++;
1376 1376
1377 dev->vfd = vfd; 1377 dev->vfd = vfd;
diff --git a/drivers/media/video/zc0301/Kconfig b/drivers/media/video/zc0301/Kconfig
index edb00293cd59..a7e610e0be9e 100644
--- a/drivers/media/video/zc0301/Kconfig
+++ b/drivers/media/video/zc0301/Kconfig
@@ -1,7 +1,11 @@
1config USB_ZC0301 1config USB_ZC0301
2 tristate "USB ZC0301[P] Image Processor and Control Chip support" 2 tristate "USB ZC0301[P] webcam support (DEPRECATED)"
3 depends on VIDEO_V4L2 3 depends on VIDEO_V4L2
4 default n
4 ---help--- 5 ---help---
6 This driver is DEPRECATED please use the gspca zc3xx module
7 instead.
8
5 Say Y here if you want support for cameras based on the ZC0301 or 9 Say Y here if you want support for cameras based on the ZC0301 or
6 ZC0301P Image Processors and Control Chips. 10 ZC0301P Image Processors and Control Chips.
7 11
diff --git a/drivers/media/video/zoran/zoran_device.c b/drivers/media/video/zoran/zoran_device.c
index f6c2fb4fc3b4..e6ad4b205611 100644
--- a/drivers/media/video/zoran/zoran_device.c
+++ b/drivers/media/video/zoran/zoran_device.c
@@ -1196,7 +1196,8 @@ zoran_reap_stat_com (struct zoran *zr)
1196static void zoran_restart(struct zoran *zr) 1196static void zoran_restart(struct zoran *zr)
1197{ 1197{
1198 /* Now the stat_comm buffer is ready for restart */ 1198 /* Now the stat_comm buffer is ready for restart */
1199 int status = 0, mode; 1199 unsigned int status = 0;
1200 int mode;
1200 1201
1201 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { 1202 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1202 decoder_call(zr, video, g_input_status, &status); 1203 decoder_call(zr, video, g_input_status, &status);
@@ -1228,7 +1229,7 @@ error_handler (struct zoran *zr,
1228 u32 astat, 1229 u32 astat,
1229 u32 stat) 1230 u32 stat)
1230{ 1231{
1231 int i, j; 1232 int i;
1232 1233
1233 /* This is JPEG error handling part */ 1234 /* This is JPEG error handling part */
1234 if (zr->codec_mode != BUZ_MODE_MOTION_COMPRESS && 1235 if (zr->codec_mode != BUZ_MODE_MOTION_COMPRESS &&
@@ -1279,6 +1280,7 @@ error_handler (struct zoran *zr,
1279 /* Report error */ 1280 /* Report error */
1280 if (zr36067_debug > 1 && zr->num_errors <= 8) { 1281 if (zr36067_debug > 1 && zr->num_errors <= 8) {
1281 long frame; 1282 long frame;
1283 int j;
1282 1284
1283 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME]; 1285 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1284 printk(KERN_ERR 1286 printk(KERN_ERR
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index 2ddffed019ee..ec41303544e5 100644
--- a/drivers/media/video/zoran/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -324,7 +324,7 @@ static int jpg_fbuffer_alloc(struct zoran_fh *fh)
324 /* Allocate fragment table for this buffer */ 324 /* Allocate fragment table for this buffer */
325 325
326 mem = (void *)get_zeroed_page(GFP_KERNEL); 326 mem = (void *)get_zeroed_page(GFP_KERNEL);
327 if (mem == 0) { 327 if (!mem) {
328 dprintk(1, 328 dprintk(1,
329 KERN_ERR 329 KERN_ERR
330 "%s: %s - get_zeroed_page (frag_tab) failed for buffer %d\n", 330 "%s: %s - get_zeroed_page (frag_tab) failed for buffer %d\n",
@@ -1444,7 +1444,7 @@ zoran_set_norm (struct zoran *zr,
1444 } 1444 }
1445 1445
1446 if (norm == V4L2_STD_ALL) { 1446 if (norm == V4L2_STD_ALL) {
1447 int status = 0; 1447 unsigned int status = 0;
1448 v4l2_std_id std = 0; 1448 v4l2_std_id std = 0;
1449 1449
1450 decoder_call(zr, video, querystd, &std); 1450 decoder_call(zr, video, querystd, &std);
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index f0eae83e3d89..3d4bac252902 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -78,6 +78,7 @@
78#define METHOD0 0 78#define METHOD0 0
79#define METHOD1 1 79#define METHOD1 1
80#define METHOD2 2 80#define METHOD2 2
81#define METHOD3 3
81 82
82 83
83/* Module parameters */ 84/* Module parameters */
@@ -114,7 +115,7 @@ static struct usb_device_id device_table[] = {
114 {USB_DEVICE(0x06d6, 0x003b), .driver_info = METHOD0 }, 115 {USB_DEVICE(0x06d6, 0x003b), .driver_info = METHOD0 },
115 {USB_DEVICE(0x0a17, 0x004e), .driver_info = METHOD2 }, 116 {USB_DEVICE(0x0a17, 0x004e), .driver_info = METHOD2 },
116 {USB_DEVICE(0x041e, 0x405d), .driver_info = METHOD2 }, 117 {USB_DEVICE(0x041e, 0x405d), .driver_info = METHOD2 },
117 {USB_DEVICE(0x08ca, 0x2102), .driver_info = METHOD2 }, 118 {USB_DEVICE(0x08ca, 0x2102), .driver_info = METHOD3 },
118 {USB_DEVICE(0x06d6, 0x003d), .driver_info = METHOD0 }, 119 {USB_DEVICE(0x06d6, 0x003d), .driver_info = METHOD0 },
119 {} /* Terminating entry */ 120 {} /* Terminating entry */
120}; 121};
@@ -302,7 +303,7 @@ static message m2[] = {
302}; 303};
303 304
304/* init table */ 305/* init table */
305static message *init[3] = { m0, m1, m2 }; 306static message *init[4] = { m0, m1, m2, m2 };
306 307
307 308
308/* JPEG static data in header (Huffman table, etc) */ 309/* JPEG static data in header (Huffman table, etc) */
@@ -967,6 +968,22 @@ static int zr364xx_vidioc_s_fmt_vid_cap(struct file *file, void *priv,
967 m0d1[0] = mode; 968 m0d1[0] = mode;
968 m1[2].value = 0xf000 + mode; 969 m1[2].value = 0xf000 + mode;
969 m2[1].value = 0xf000 + mode; 970 m2[1].value = 0xf000 + mode;
971
972 /* special case for METHOD3, the modes are different */
973 if (cam->method == METHOD3) {
974 switch (mode) {
975 case 1:
976 m2[1].value = 0xf000 + 4;
977 break;
978 case 2:
979 m2[1].value = 0xf000 + 0;
980 break;
981 default:
982 m2[1].value = 0xf000 + 1;
983 break;
984 }
985 }
986
970 header2[437] = cam->height / 256; 987 header2[437] = cam->height / 256;
971 header2[438] = cam->height % 256; 988 header2[438] = cam->height % 256;
972 header2[439] = cam->width / 256; 989 header2[439] = cam->width / 256;
@@ -1582,6 +1599,22 @@ static int zr364xx_probe(struct usb_interface *intf,
1582 m0d1[0] = mode; 1599 m0d1[0] = mode;
1583 m1[2].value = 0xf000 + mode; 1600 m1[2].value = 0xf000 + mode;
1584 m2[1].value = 0xf000 + mode; 1601 m2[1].value = 0xf000 + mode;
1602
1603 /* special case for METHOD3, the modes are different */
1604 if (cam->method == METHOD3) {
1605 switch (mode) {
1606 case 1:
1607 m2[1].value = 0xf000 + 4;
1608 break;
1609 case 2:
1610 m2[1].value = 0xf000 + 0;
1611 break;
1612 default:
1613 m2[1].value = 0xf000 + 1;
1614 break;
1615 }
1616 }
1617
1585 header2[437] = cam->height / 256; 1618 header2[437] = cam->height / 256;
1586 header2[438] = cam->height % 256; 1619 header2[438] = cam->height % 256;
1587 header2[439] = cam->width / 256; 1620 header2[439] = cam->width / 256;
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 44d2037e9e56..5382b5a44aff 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -126,8 +126,6 @@ static int mfcounter = 0;
126 * Public data... 126 * Public data...
127 */ 127 */
128 128
129static struct proc_dir_entry *mpt_proc_root_dir;
130
131#define WHOINIT_UNKNOWN 0xAA 129#define WHOINIT_UNKNOWN 0xAA
132 130
133/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 131/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -146,6 +144,9 @@ static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
146static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS]; 144static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
147static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS]; 145static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
148 146
147#ifdef CONFIG_PROC_FS
148static struct proc_dir_entry *mpt_proc_root_dir;
149#endif
149 150
150/* 151/*
151 * Driver Callback Index's 152 * Driver Callback Index's
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index b4948671eb92..9718c8f2e959 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -76,8 +76,8 @@
76#define COPYRIGHT "Copyright (c) 1999-2008 " MODULEAUTHOR 76#define COPYRIGHT "Copyright (c) 1999-2008 " MODULEAUTHOR
77#endif 77#endif
78 78
79#define MPT_LINUX_VERSION_COMMON "3.04.13" 79#define MPT_LINUX_VERSION_COMMON "3.04.14"
80#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.13" 80#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.14"
81#define WHAT_MAGIC_STRING "@" "(" "#" ")" 81#define WHAT_MAGIC_STRING "@" "(" "#" ")"
82 82
83#define show_mptmod_ver(s,ver) \ 83#define show_mptmod_ver(s,ver) \
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 352acd05c46b..caa8f568a41c 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -360,8 +360,8 @@ static int mptctl_bus_reset(MPT_ADAPTER *ioc, u8 function)
360 u16 iocstatus; 360 u16 iocstatus;
361 361
362 /* bus reset is only good for SCSI IO, RAID PASSTHRU */ 362 /* bus reset is only good for SCSI IO, RAID PASSTHRU */
363 if (!(function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) || 363 if (!(function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
364 (function == MPI_FUNCTION_SCSI_IO_REQUEST)) { 364 function == MPI_FUNCTION_SCSI_IO_REQUEST)) {
365 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT 365 dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
366 "TaskMgmt, not SCSI_IO!!\n", ioc->name)); 366 "TaskMgmt, not SCSI_IO!!\n", ioc->name));
367 return -EPERM; 367 return -EPERM;
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index ebf6ae024da4..612ab3c51a6b 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -195,29 +195,34 @@ mptfc_block_error_handler(struct scsi_cmnd *SCpnt,
195 unsigned long flags; 195 unsigned long flags;
196 int ready; 196 int ready;
197 MPT_ADAPTER *ioc; 197 MPT_ADAPTER *ioc;
198 int loops = 40; /* seconds */
198 199
199 hd = shost_priv(SCpnt->device->host); 200 hd = shost_priv(SCpnt->device->host);
200 ioc = hd->ioc; 201 ioc = hd->ioc;
201 spin_lock_irqsave(shost->host_lock, flags); 202 spin_lock_irqsave(shost->host_lock, flags);
202 while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY) { 203 while ((ready = fc_remote_port_chkready(rport) >> 16) == DID_IMM_RETRY
204 || (loops > 0 && ioc->active == 0)) {
203 spin_unlock_irqrestore(shost->host_lock, flags); 205 spin_unlock_irqrestore(shost->host_lock, flags);
204 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 206 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
205 "mptfc_block_error_handler.%d: %d:%d, port status is " 207 "mptfc_block_error_handler.%d: %d:%d, port status is "
206 "DID_IMM_RETRY, deferring %s recovery.\n", 208 "%x, active flag %d, deferring %s recovery.\n",
207 ioc->name, ioc->sh->host_no, 209 ioc->name, ioc->sh->host_no,
208 SCpnt->device->id, SCpnt->device->lun, caller)); 210 SCpnt->device->id, SCpnt->device->lun,
211 ready, ioc->active, caller));
209 msleep(1000); 212 msleep(1000);
210 spin_lock_irqsave(shost->host_lock, flags); 213 spin_lock_irqsave(shost->host_lock, flags);
214 loops --;
211 } 215 }
212 spin_unlock_irqrestore(shost->host_lock, flags); 216 spin_unlock_irqrestore(shost->host_lock, flags);
213 217
214 if (ready == DID_NO_CONNECT || !SCpnt->device->hostdata) { 218 if (ready == DID_NO_CONNECT || !SCpnt->device->hostdata
219 || ioc->active == 0) {
215 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 220 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
216 "%s.%d: %d:%d, failing recovery, " 221 "%s.%d: %d:%d, failing recovery, "
217 "port state %d, vdevice %p.\n", caller, 222 "port state %x, active %d, vdevice %p.\n", caller,
218 ioc->name, ioc->sh->host_no, 223 ioc->name, ioc->sh->host_no,
219 SCpnt->device->id, SCpnt->device->lun, ready, 224 SCpnt->device->id, SCpnt->device->lun, ready,
220 SCpnt->device->hostdata)); 225 ioc->active, SCpnt->device->hostdata));
221 return FAILED; 226 return FAILED;
222 } 227 }
223 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT 228 dfcprintk (ioc, printk(MYIOC_s_DEBUG_FMT
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 83873e3d0ce7..c20bbe45da82 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -1075,6 +1075,19 @@ mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
1075 return 0; 1075 return 0;
1076} 1076}
1077 1077
1078static void
1079mptsas_block_io_sdev(struct scsi_device *sdev, void *data)
1080{
1081 scsi_device_set_state(sdev, SDEV_BLOCK);
1082}
1083
1084static void
1085mptsas_block_io_starget(struct scsi_target *starget)
1086{
1087 if (starget)
1088 starget_for_each_device(starget, NULL, mptsas_block_io_sdev);
1089}
1090
1078/** 1091/**
1079 * mptsas_target_reset_queue 1092 * mptsas_target_reset_queue
1080 * 1093 *
@@ -1098,10 +1111,11 @@ mptsas_target_reset_queue(MPT_ADAPTER *ioc,
1098 id = sas_event_data->TargetID; 1111 id = sas_event_data->TargetID;
1099 channel = sas_event_data->Bus; 1112 channel = sas_event_data->Bus;
1100 1113
1101 if (!(vtarget = mptsas_find_vtarget(ioc, channel, id))) 1114 vtarget = mptsas_find_vtarget(ioc, channel, id);
1102 return; 1115 if (vtarget) {
1103 1116 mptsas_block_io_starget(vtarget->starget);
1104 vtarget->deleted = 1; /* block IO */ 1117 vtarget->deleted = 1; /* block IO */
1118 }
1105 1119
1106 target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event), 1120 target_reset_list = kzalloc(sizeof(struct mptsas_target_reset_event),
1107 GFP_ATOMIC); 1121 GFP_ATOMIC);
@@ -1868,7 +1882,8 @@ mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1868 if (ioc->sas_discovery_quiesce_io) 1882 if (ioc->sas_discovery_quiesce_io)
1869 return SCSI_MLQUEUE_HOST_BUSY; 1883 return SCSI_MLQUEUE_HOST_BUSY;
1870 1884
1871// scsi_print_command(SCpnt); 1885 if (ioc->debug_level & MPT_DEBUG_SCSI)
1886 scsi_print_command(SCpnt);
1872 1887
1873 return mptscsih_qcmd(SCpnt,done); 1888 return mptscsih_qcmd(SCpnt,done);
1874} 1889}
@@ -2686,6 +2701,187 @@ mptsas_sas_expander_pg1(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info,
2686 return error; 2701 return error;
2687} 2702}
2688 2703
2704struct rep_manu_request{
2705 u8 smp_frame_type;
2706 u8 function;
2707 u8 reserved;
2708 u8 request_length;
2709};
2710
2711struct rep_manu_reply{
2712 u8 smp_frame_type; /* 0x41 */
2713 u8 function; /* 0x01 */
2714 u8 function_result;
2715 u8 response_length;
2716 u16 expander_change_count;
2717 u8 reserved0[2];
2718 u8 sas_format:1;
2719 u8 reserved1:7;
2720 u8 reserved2[3];
2721 u8 vendor_id[SAS_EXPANDER_VENDOR_ID_LEN];
2722 u8 product_id[SAS_EXPANDER_PRODUCT_ID_LEN];
2723 u8 product_rev[SAS_EXPANDER_PRODUCT_REV_LEN];
2724 u8 component_vendor_id[SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN];
2725 u16 component_id;
2726 u8 component_revision_id;
2727 u8 reserved3;
2728 u8 vendor_specific[8];
2729};
2730
2731/**
2732 * mptsas_exp_repmanufacture_info -
2733 * @ioc: per adapter object
2734 * @sas_address: expander sas address
2735 * @edev: the sas_expander_device object
2736 *
2737 * Fills in the sas_expander_device object when SMP port is created.
2738 *
2739 * Returns 0 for success, non-zero for failure.
2740 */
2741static int
2742mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
2743 u64 sas_address, struct sas_expander_device *edev)
2744{
2745 MPT_FRAME_HDR *mf;
2746 SmpPassthroughRequest_t *smpreq;
2747 SmpPassthroughReply_t *smprep;
2748 struct rep_manu_reply *manufacture_reply;
2749 struct rep_manu_request *manufacture_request;
2750 int ret;
2751 int flagsLength;
2752 unsigned long timeleft;
2753 char *psge;
2754 unsigned long flags;
2755 void *data_out = NULL;
2756 dma_addr_t data_out_dma = 0;
2757 u32 sz;
2758
2759 spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
2760 if (ioc->ioc_reset_in_progress) {
2761 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2762 printk(MYIOC_s_INFO_FMT "%s: host reset in progress!\n",
2763 __func__, ioc->name);
2764 return -EFAULT;
2765 }
2766 spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
2767
2768 ret = mutex_lock_interruptible(&ioc->sas_mgmt.mutex);
2769 if (ret)
2770 goto out;
2771
2772 mf = mpt_get_msg_frame(mptsasMgmtCtx, ioc);
2773 if (!mf) {
2774 ret = -ENOMEM;
2775 goto out_unlock;
2776 }
2777
2778 smpreq = (SmpPassthroughRequest_t *)mf;
2779 memset(smpreq, 0, sizeof(*smpreq));
2780
2781 sz = sizeof(struct rep_manu_request) + sizeof(struct rep_manu_reply);
2782
2783 data_out = pci_alloc_consistent(ioc->pcidev, sz, &data_out_dma);
2784 if (!data_out) {
2785 printk(KERN_ERR "Memory allocation failure at %s:%d/%s()!\n",
2786 __FILE__, __LINE__, __func__);
2787 ret = -ENOMEM;
2788 goto put_mf;
2789 }
2790
2791 manufacture_request = data_out;
2792 manufacture_request->smp_frame_type = 0x40;
2793 manufacture_request->function = 1;
2794 manufacture_request->reserved = 0;
2795 manufacture_request->request_length = 0;
2796
2797 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
2798 smpreq->PhysicalPort = 0xFF;
2799 *((u64 *)&smpreq->SASAddress) = cpu_to_le64(sas_address);
2800 smpreq->RequestDataLength = sizeof(struct rep_manu_request);
2801
2802 psge = (char *)
2803 (((int *) mf) + (offsetof(SmpPassthroughRequest_t, SGL) / 4));
2804
2805 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2806 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2807 MPI_SGE_FLAGS_HOST_TO_IOC |
2808 MPI_SGE_FLAGS_END_OF_BUFFER;
2809 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2810 flagsLength |= sizeof(struct rep_manu_request);
2811
2812 ioc->add_sge(psge, flagsLength, data_out_dma);
2813 psge += ioc->SGE_size;
2814
2815 flagsLength = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
2816 MPI_SGE_FLAGS_SYSTEM_ADDRESS |
2817 MPI_SGE_FLAGS_IOC_TO_HOST |
2818 MPI_SGE_FLAGS_END_OF_BUFFER;
2819 flagsLength = flagsLength << MPI_SGE_FLAGS_SHIFT;
2820 flagsLength |= sizeof(struct rep_manu_reply);
2821 ioc->add_sge(psge, flagsLength, data_out_dma +
2822 sizeof(struct rep_manu_request));
2823
2824 INITIALIZE_MGMT_STATUS(ioc->sas_mgmt.status)
2825 mpt_put_msg_frame(mptsasMgmtCtx, ioc, mf);
2826
2827 timeleft = wait_for_completion_timeout(&ioc->sas_mgmt.done, 10 * HZ);
2828 if (!(ioc->sas_mgmt.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
2829 ret = -ETIME;
2830 mpt_free_msg_frame(ioc, mf);
2831 mf = NULL;
2832 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_DID_IOCRESET)
2833 goto out_free;
2834 if (!timeleft)
2835 mpt_HardResetHandler(ioc, CAN_SLEEP);
2836 goto out_free;
2837 }
2838
2839 mf = NULL;
2840
2841 if (ioc->sas_mgmt.status & MPT_MGMT_STATUS_RF_VALID) {
2842 u8 *tmp;
2843
2844 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
2845 if (le16_to_cpu(smprep->ResponseDataLength) !=
2846 sizeof(struct rep_manu_reply))
2847 goto out_free;
2848
2849 manufacture_reply = data_out + sizeof(struct rep_manu_request);
2850 strncpy(edev->vendor_id, manufacture_reply->vendor_id,
2851 SAS_EXPANDER_VENDOR_ID_LEN);
2852 strncpy(edev->product_id, manufacture_reply->product_id,
2853 SAS_EXPANDER_PRODUCT_ID_LEN);
2854 strncpy(edev->product_rev, manufacture_reply->product_rev,
2855 SAS_EXPANDER_PRODUCT_REV_LEN);
2856 edev->level = manufacture_reply->sas_format;
2857 if (manufacture_reply->sas_format) {
2858 strncpy(edev->component_vendor_id,
2859 manufacture_reply->component_vendor_id,
2860 SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
2861 tmp = (u8 *)&manufacture_reply->component_id;
2862 edev->component_id = tmp[0] << 8 | tmp[1];
2863 edev->component_revision_id =
2864 manufacture_reply->component_revision_id;
2865 }
2866 } else {
2867 printk(MYIOC_s_ERR_FMT
2868 "%s: smp passthru reply failed to be returned\n",
2869 ioc->name, __func__);
2870 ret = -ENXIO;
2871 }
2872out_free:
2873 if (data_out_dma)
2874 pci_free_consistent(ioc->pcidev, sz, data_out, data_out_dma);
2875put_mf:
2876 if (mf)
2877 mpt_free_msg_frame(ioc, mf);
2878out_unlock:
2879 CLEAR_MGMT_STATUS(ioc->sas_mgmt.status)
2880 mutex_unlock(&ioc->sas_mgmt.mutex);
2881out:
2882 return ret;
2883 }
2884
2689static void 2885static void
2690mptsas_parse_device_info(struct sas_identify *identify, 2886mptsas_parse_device_info(struct sas_identify *identify,
2691 struct mptsas_devinfo *device_info) 2887 struct mptsas_devinfo *device_info)
@@ -2967,6 +3163,11 @@ static int mptsas_probe_one_phy(struct device *dev,
2967 goto out; 3163 goto out;
2968 } 3164 }
2969 mptsas_set_rphy(ioc, phy_info, rphy); 3165 mptsas_set_rphy(ioc, phy_info, rphy);
3166 if (identify.device_type == SAS_EDGE_EXPANDER_DEVICE ||
3167 identify.device_type == SAS_FANOUT_EXPANDER_DEVICE)
3168 mptsas_exp_repmanufacture_info(ioc,
3169 identify.sas_address,
3170 rphy_to_expander_device(rphy));
2970 } 3171 }
2971 3172
2972 out: 3173 out:
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index 81279b3d694c..4a7d1afcb666 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -1438,9 +1438,14 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1438 && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES) 1438 && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
1439 && (SCpnt->device->tagged_supported)) { 1439 && (SCpnt->device->tagged_supported)) {
1440 scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ; 1440 scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
1441 } else { 1441 if (SCpnt->request && SCpnt->request->ioprio) {
1442 if (((SCpnt->request->ioprio & 0x7) == 1) ||
1443 !(SCpnt->request->ioprio & 0x7))
1444 scsictl |= MPI_SCSIIO_CONTROL_HEADOFQ;
1445 }
1446 } else
1442 scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED; 1447 scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
1443 } 1448
1444 1449
1445 /* Use the above information to set up the message frame 1450 /* Use the above information to set up the message frame
1446 */ 1451 */
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 87829789243e..413576a2f313 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -348,6 +348,16 @@ config AB4500_CORE
348 read/write functions for the devices to get access to this chip. 348 read/write functions for the devices to get access to this chip.
349 This chip embeds various other multimedia funtionalities as well. 349 This chip embeds various other multimedia funtionalities as well.
350 350
351config MFD_TIMBERDALE
352 tristate "Support for the Timberdale FPGA"
353 select MFD_CORE
354 depends on PCI && GPIOLIB
355 ---help---
356 This is the core driver for the timberdale FPGA. This device is a
357 multifunction device which exposes numerous platform devices.
358
359 The timberdale FPGA can be found on the Intel Atom development board
360 for in-vehicle infontainment, called Russellville.
351endmenu 361endmenu
352 362
353menu "Multimedia Capabilities Port drivers" 363menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index e09eb4870db6..78295d6a75f7 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -54,5 +54,6 @@ obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o
54obj-$(CONFIG_AB3100_CORE) += ab3100-core.o 54obj-$(CONFIG_AB3100_CORE) += ab3100-core.o
55obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o 55obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o
56obj-$(CONFIG_AB4500_CORE) += ab4500-core.o 56obj-$(CONFIG_AB4500_CORE) += ab4500-core.o
57obj-$(CONFIG_MFD_TIMBERDALE) += timberdale.o
57obj-$(CONFIG_MFD_88PM8607) += 88pm8607.o 58obj-$(CONFIG_MFD_88PM8607) += 88pm8607.o
58obj-$(CONFIG_PMIC_ADP5520) += adp5520.o \ No newline at end of file 59obj-$(CONFIG_PMIC_ADP5520) += adp5520.o
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c
new file mode 100644
index 000000000000..1ed44d283803
--- /dev/null
+++ b/drivers/mfd/timberdale.c
@@ -0,0 +1,727 @@
1/*
2 * timberdale.c timberdale FPGA MFD driver
3 * Copyright (c) 2009 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* Supports:
20 * Timberdale FPGA
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/pci.h>
26#include <linux/msi.h>
27#include <linux/mfd/core.h>
28
29#include <linux/timb_gpio.h>
30
31#include <linux/i2c.h>
32#include <linux/i2c-ocores.h>
33#include <linux/i2c/tsc2007.h>
34
35#include <linux/spi/spi.h>
36#include <linux/spi/xilinx_spi.h>
37#include <linux/spi/max7301.h>
38#include <linux/spi/mc33880.h>
39
40#include <media/timb_radio.h>
41
42#include "timberdale.h"
43
44#define DRIVER_NAME "timberdale"
45
46struct timberdale_device {
47 resource_size_t ctl_mapbase;
48 unsigned char __iomem *ctl_membase;
49 struct {
50 u32 major;
51 u32 minor;
52 u32 config;
53 } fw;
54};
55
56/*--------------------------------------------------------------------------*/
57
58static struct tsc2007_platform_data timberdale_tsc2007_platform_data = {
59 .model = 2003,
60 .x_plate_ohms = 100
61};
62
63static struct i2c_board_info timberdale_i2c_board_info[] = {
64 {
65 I2C_BOARD_INFO("tsc2007", 0x48),
66 .platform_data = &timberdale_tsc2007_platform_data,
67 .irq = IRQ_TIMBERDALE_TSC_INT
68 },
69};
70
71static __devinitdata struct ocores_i2c_platform_data
72timberdale_ocores_platform_data = {
73 .regstep = 4,
74 .clock_khz = 62500,
75 .devices = timberdale_i2c_board_info,
76 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
77};
78
79const static __devinitconst struct resource timberdale_ocores_resources[] = {
80 {
81 .start = OCORESOFFSET,
82 .end = OCORESEND,
83 .flags = IORESOURCE_MEM,
84 },
85 {
86 .start = IRQ_TIMBERDALE_I2C,
87 .end = IRQ_TIMBERDALE_I2C,
88 .flags = IORESOURCE_IRQ,
89 },
90};
91
92const struct max7301_platform_data timberdale_max7301_platform_data = {
93 .base = 200
94};
95
96const struct mc33880_platform_data timberdale_mc33880_platform_data = {
97 .base = 100
98};
99
100static struct spi_board_info timberdale_spi_16bit_board_info[] = {
101 {
102 .modalias = "max7301",
103 .max_speed_hz = 26000,
104 .chip_select = 2,
105 .mode = SPI_MODE_0,
106 .platform_data = &timberdale_max7301_platform_data
107 },
108};
109
110static struct spi_board_info timberdale_spi_8bit_board_info[] = {
111 {
112 .modalias = "mc33880",
113 .max_speed_hz = 4000,
114 .chip_select = 1,
115 .mode = SPI_MODE_1,
116 .platform_data = &timberdale_mc33880_platform_data
117 },
118};
119
120static __devinitdata struct xspi_platform_data timberdale_xspi_platform_data = {
121 .num_chipselect = 3,
122 .little_endian = true,
123 /* bits per word and devices will be filled in runtime depending
124 * on the HW config
125 */
126};
127
128const static __devinitconst struct resource timberdale_spi_resources[] = {
129 {
130 .start = SPIOFFSET,
131 .end = SPIEND,
132 .flags = IORESOURCE_MEM,
133 },
134 {
135 .start = IRQ_TIMBERDALE_SPI,
136 .end = IRQ_TIMBERDALE_SPI,
137 .flags = IORESOURCE_IRQ,
138 },
139};
140
141const static __devinitconst struct resource timberdale_eth_resources[] = {
142 {
143 .start = ETHOFFSET,
144 .end = ETHEND,
145 .flags = IORESOURCE_MEM,
146 },
147 {
148 .start = IRQ_TIMBERDALE_ETHSW_IF,
149 .end = IRQ_TIMBERDALE_ETHSW_IF,
150 .flags = IORESOURCE_IRQ,
151 },
152};
153
154static __devinitdata struct timbgpio_platform_data
155 timberdale_gpio_platform_data = {
156 .gpio_base = 0,
157 .nr_pins = GPIO_NR_PINS,
158 .irq_base = 200,
159};
160
161const static __devinitconst struct resource timberdale_gpio_resources[] = {
162 {
163 .start = GPIOOFFSET,
164 .end = GPIOEND,
165 .flags = IORESOURCE_MEM,
166 },
167 {
168 .start = IRQ_TIMBERDALE_GPIO,
169 .end = IRQ_TIMBERDALE_GPIO,
170 .flags = IORESOURCE_IRQ,
171 },
172};
173
174const static __devinitconst struct resource timberdale_mlogicore_resources[] = {
175 {
176 .start = MLCOREOFFSET,
177 .end = MLCOREEND,
178 .flags = IORESOURCE_MEM,
179 },
180 {
181 .start = IRQ_TIMBERDALE_MLCORE,
182 .end = IRQ_TIMBERDALE_MLCORE,
183 .flags = IORESOURCE_IRQ,
184 },
185 {
186 .start = IRQ_TIMBERDALE_MLCORE_BUF,
187 .end = IRQ_TIMBERDALE_MLCORE_BUF,
188 .flags = IORESOURCE_IRQ,
189 },
190};
191
192const static __devinitconst struct resource timberdale_uart_resources[] = {
193 {
194 .start = UARTOFFSET,
195 .end = UARTEND,
196 .flags = IORESOURCE_MEM,
197 },
198 {
199 .start = IRQ_TIMBERDALE_UART,
200 .end = IRQ_TIMBERDALE_UART,
201 .flags = IORESOURCE_IRQ,
202 },
203};
204
205const static __devinitconst struct resource timberdale_uartlite_resources[] = {
206 {
207 .start = UARTLITEOFFSET,
208 .end = UARTLITEEND,
209 .flags = IORESOURCE_MEM,
210 },
211 {
212 .start = IRQ_TIMBERDALE_UARTLITE,
213 .end = IRQ_TIMBERDALE_UARTLITE,
214 .flags = IORESOURCE_IRQ,
215 },
216};
217
218const static __devinitconst struct resource timberdale_radio_resources[] = {
219 {
220 .start = RDSOFFSET,
221 .end = RDSEND,
222 .flags = IORESOURCE_MEM,
223 },
224 {
225 .start = IRQ_TIMBERDALE_RDS,
226 .end = IRQ_TIMBERDALE_RDS,
227 .flags = IORESOURCE_IRQ,
228 },
229};
230
231static __devinitdata struct i2c_board_info timberdale_tef6868_i2c_board_info = {
232 I2C_BOARD_INFO("tef6862", 0x60)
233};
234
235static __devinitdata struct i2c_board_info timberdale_saa7706_i2c_board_info = {
236 I2C_BOARD_INFO("saa7706h", 0x1C)
237};
238
239static __devinitdata struct timb_radio_platform_data
240 timberdale_radio_platform_data = {
241 .i2c_adapter = 0,
242 .tuner = {
243 .module_name = "tef6862",
244 .info = &timberdale_tef6868_i2c_board_info
245 },
246 .dsp = {
247 .module_name = "saa7706h",
248 .info = &timberdale_saa7706_i2c_board_info
249 }
250};
251
252const static __devinitconst struct resource timberdale_dma_resources[] = {
253 {
254 .start = DMAOFFSET,
255 .end = DMAEND,
256 .flags = IORESOURCE_MEM,
257 },
258 {
259 .start = IRQ_TIMBERDALE_DMA,
260 .end = IRQ_TIMBERDALE_DMA,
261 .flags = IORESOURCE_IRQ,
262 },
263};
264
265static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg0[] = {
266 {
267 .name = "timb-uart",
268 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
269 .resources = timberdale_uart_resources,
270 },
271 {
272 .name = "timb-gpio",
273 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
274 .resources = timberdale_gpio_resources,
275 .platform_data = &timberdale_gpio_platform_data,
276 .data_size = sizeof(timberdale_gpio_platform_data),
277 },
278 {
279 .name = "timb-radio",
280 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
281 .resources = timberdale_radio_resources,
282 .platform_data = &timberdale_radio_platform_data,
283 .data_size = sizeof(timberdale_radio_platform_data),
284 },
285 {
286 .name = "xilinx_spi",
287 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
288 .resources = timberdale_spi_resources,
289 .platform_data = &timberdale_xspi_platform_data,
290 .data_size = sizeof(timberdale_xspi_platform_data),
291 },
292 {
293 .name = "ks8842",
294 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
295 .resources = timberdale_eth_resources,
296 },
297 {
298 .name = "timb-dma",
299 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
300 .resources = timberdale_dma_resources,
301 },
302};
303
304static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg1[] = {
305 {
306 .name = "timb-uart",
307 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
308 .resources = timberdale_uart_resources,
309 },
310 {
311 .name = "uartlite",
312 .num_resources = ARRAY_SIZE(timberdale_uartlite_resources),
313 .resources = timberdale_uartlite_resources,
314 },
315 {
316 .name = "timb-gpio",
317 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
318 .resources = timberdale_gpio_resources,
319 .platform_data = &timberdale_gpio_platform_data,
320 .data_size = sizeof(timberdale_gpio_platform_data),
321 },
322 {
323 .name = "timb-mlogicore",
324 .num_resources = ARRAY_SIZE(timberdale_mlogicore_resources),
325 .resources = timberdale_mlogicore_resources,
326 },
327 {
328 .name = "timb-radio",
329 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
330 .resources = timberdale_radio_resources,
331 .platform_data = &timberdale_radio_platform_data,
332 .data_size = sizeof(timberdale_radio_platform_data),
333 },
334 {
335 .name = "xilinx_spi",
336 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
337 .resources = timberdale_spi_resources,
338 .platform_data = &timberdale_xspi_platform_data,
339 .data_size = sizeof(timberdale_xspi_platform_data),
340 },
341 {
342 .name = "ks8842",
343 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
344 .resources = timberdale_eth_resources,
345 },
346 {
347 .name = "timb-dma",
348 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
349 .resources = timberdale_dma_resources,
350 },
351};
352
353static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg2[] = {
354 {
355 .name = "timb-uart",
356 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
357 .resources = timberdale_uart_resources,
358 },
359 {
360 .name = "timb-gpio",
361 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
362 .resources = timberdale_gpio_resources,
363 .platform_data = &timberdale_gpio_platform_data,
364 .data_size = sizeof(timberdale_gpio_platform_data),
365 },
366 {
367 .name = "timb-radio",
368 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
369 .resources = timberdale_radio_resources,
370 .platform_data = &timberdale_radio_platform_data,
371 .data_size = sizeof(timberdale_radio_platform_data),
372 },
373 {
374 .name = "xilinx_spi",
375 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
376 .resources = timberdale_spi_resources,
377 .platform_data = &timberdale_xspi_platform_data,
378 .data_size = sizeof(timberdale_xspi_platform_data),
379 },
380 {
381 .name = "timb-dma",
382 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
383 .resources = timberdale_dma_resources,
384 },
385};
386
387static __devinitdata struct mfd_cell timberdale_cells_bar0_cfg3[] = {
388 {
389 .name = "timb-uart",
390 .num_resources = ARRAY_SIZE(timberdale_uart_resources),
391 .resources = timberdale_uart_resources,
392 },
393 {
394 .name = "ocores-i2c",
395 .num_resources = ARRAY_SIZE(timberdale_ocores_resources),
396 .resources = timberdale_ocores_resources,
397 .platform_data = &timberdale_ocores_platform_data,
398 .data_size = sizeof(timberdale_ocores_platform_data),
399 },
400 {
401 .name = "timb-gpio",
402 .num_resources = ARRAY_SIZE(timberdale_gpio_resources),
403 .resources = timberdale_gpio_resources,
404 .platform_data = &timberdale_gpio_platform_data,
405 .data_size = sizeof(timberdale_gpio_platform_data),
406 },
407 {
408 .name = "timb-radio",
409 .num_resources = ARRAY_SIZE(timberdale_radio_resources),
410 .resources = timberdale_radio_resources,
411 .platform_data = &timberdale_radio_platform_data,
412 .data_size = sizeof(timberdale_radio_platform_data),
413 },
414 {
415 .name = "xilinx_spi",
416 .num_resources = ARRAY_SIZE(timberdale_spi_resources),
417 .resources = timberdale_spi_resources,
418 .platform_data = &timberdale_xspi_platform_data,
419 .data_size = sizeof(timberdale_xspi_platform_data),
420 },
421 {
422 .name = "ks8842",
423 .num_resources = ARRAY_SIZE(timberdale_eth_resources),
424 .resources = timberdale_eth_resources,
425 },
426 {
427 .name = "timb-dma",
428 .num_resources = ARRAY_SIZE(timberdale_dma_resources),
429 .resources = timberdale_dma_resources,
430 },
431};
432
433static const __devinitconst struct resource timberdale_sdhc_resources[] = {
434 /* located in bar 1 and bar 2 */
435 {
436 .start = SDHC0OFFSET,
437 .end = SDHC0END,
438 .flags = IORESOURCE_MEM,
439 },
440 {
441 .start = IRQ_TIMBERDALE_SDHC,
442 .end = IRQ_TIMBERDALE_SDHC,
443 .flags = IORESOURCE_IRQ,
444 },
445};
446
447static __devinitdata struct mfd_cell timberdale_cells_bar1[] = {
448 {
449 .name = "sdhci",
450 .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
451 .resources = timberdale_sdhc_resources,
452 },
453};
454
455static __devinitdata struct mfd_cell timberdale_cells_bar2[] = {
456 {
457 .name = "sdhci",
458 .num_resources = ARRAY_SIZE(timberdale_sdhc_resources),
459 .resources = timberdale_sdhc_resources,
460 },
461};
462
463static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
464 char *buf)
465{
466 struct pci_dev *pdev = to_pci_dev(dev);
467 struct timberdale_device *priv = pci_get_drvdata(pdev);
468
469 return sprintf(buf, "%d.%d.%d\n", priv->fw.major, priv->fw.minor,
470 priv->fw.config);
471}
472
473static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
474
475/*--------------------------------------------------------------------------*/
476
477static int __devinit timb_probe(struct pci_dev *dev,
478 const struct pci_device_id *id)
479{
480 struct timberdale_device *priv;
481 int err, i;
482 resource_size_t mapbase;
483 struct msix_entry *msix_entries = NULL;
484 u8 ip_setup;
485
486 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
487 if (!priv)
488 return -ENOMEM;
489
490 pci_set_drvdata(dev, priv);
491
492 err = pci_enable_device(dev);
493 if (err)
494 goto err_enable;
495
496 mapbase = pci_resource_start(dev, 0);
497 if (!mapbase) {
498 dev_err(&dev->dev, "No resource\n");
499 goto err_start;
500 }
501
502 /* create a resource for the PCI master register */
503 priv->ctl_mapbase = mapbase + CHIPCTLOFFSET;
504 if (!request_mem_region(priv->ctl_mapbase, CHIPCTLSIZE, "timb-ctl")) {
505 dev_err(&dev->dev, "Failed to request ctl mem\n");
506 goto err_request;
507 }
508
509 priv->ctl_membase = ioremap(priv->ctl_mapbase, CHIPCTLSIZE);
510 if (!priv->ctl_membase) {
511 dev_err(&dev->dev, "ioremap failed for ctl mem\n");
512 goto err_ioremap;
513 }
514
515 /* read the HW config */
516 priv->fw.major = ioread32(priv->ctl_membase + TIMB_REV_MAJOR);
517 priv->fw.minor = ioread32(priv->ctl_membase + TIMB_REV_MINOR);
518 priv->fw.config = ioread32(priv->ctl_membase + TIMB_HW_CONFIG);
519
520 if (priv->fw.major > TIMB_SUPPORTED_MAJOR) {
521 dev_err(&dev->dev, "The driver supports an older "
522 "version of the FPGA, please update the driver to "
523 "support %d.%d\n", priv->fw.major, priv->fw.minor);
524 goto err_ioremap;
525 }
526 if (priv->fw.major < TIMB_SUPPORTED_MAJOR ||
527 priv->fw.minor < TIMB_REQUIRED_MINOR) {
528 dev_err(&dev->dev, "The FPGA image is too old (%d.%d), "
529 "please upgrade the FPGA to at least: %d.%d\n",
530 priv->fw.major, priv->fw.minor,
531 TIMB_SUPPORTED_MAJOR, TIMB_REQUIRED_MINOR);
532 goto err_ioremap;
533 }
534
535 msix_entries = kzalloc(TIMBERDALE_NR_IRQS * sizeof(*msix_entries),
536 GFP_KERNEL);
537 if (!msix_entries)
538 goto err_ioremap;
539
540 for (i = 0; i < TIMBERDALE_NR_IRQS; i++)
541 msix_entries[i].entry = i;
542
543 err = pci_enable_msix(dev, msix_entries, TIMBERDALE_NR_IRQS);
544 if (err) {
545 dev_err(&dev->dev,
546 "MSI-X init failed: %d, expected entries: %d\n",
547 err, TIMBERDALE_NR_IRQS);
548 goto err_msix;
549 }
550
551 err = device_create_file(&dev->dev, &dev_attr_fw_ver);
552 if (err)
553 goto err_create_file;
554
555 /* Reset all FPGA PLB peripherals */
556 iowrite32(0x1, priv->ctl_membase + TIMB_SW_RST);
557
558 /* update IRQ offsets in I2C board info */
559 for (i = 0; i < ARRAY_SIZE(timberdale_i2c_board_info); i++)
560 timberdale_i2c_board_info[i].irq =
561 msix_entries[timberdale_i2c_board_info[i].irq].vector;
562
563 /* Update the SPI configuration depending on the HW (8 or 16 bit) */
564 if (priv->fw.config & TIMB_HW_CONFIG_SPI_8BIT) {
565 timberdale_xspi_platform_data.bits_per_word = 8;
566 timberdale_xspi_platform_data.devices =
567 timberdale_spi_8bit_board_info;
568 timberdale_xspi_platform_data.num_devices =
569 ARRAY_SIZE(timberdale_spi_8bit_board_info);
570 } else {
571 timberdale_xspi_platform_data.bits_per_word = 16;
572 timberdale_xspi_platform_data.devices =
573 timberdale_spi_16bit_board_info;
574 timberdale_xspi_platform_data.num_devices =
575 ARRAY_SIZE(timberdale_spi_16bit_board_info);
576 }
577
578 ip_setup = priv->fw.config & TIMB_HW_VER_MASK;
579 switch (ip_setup) {
580 case TIMB_HW_VER0:
581 err = mfd_add_devices(&dev->dev, -1,
582 timberdale_cells_bar0_cfg0,
583 ARRAY_SIZE(timberdale_cells_bar0_cfg0),
584 &dev->resource[0], msix_entries[0].vector);
585 break;
586 case TIMB_HW_VER1:
587 err = mfd_add_devices(&dev->dev, -1,
588 timberdale_cells_bar0_cfg1,
589 ARRAY_SIZE(timberdale_cells_bar0_cfg1),
590 &dev->resource[0], msix_entries[0].vector);
591 break;
592 case TIMB_HW_VER2:
593 err = mfd_add_devices(&dev->dev, -1,
594 timberdale_cells_bar0_cfg2,
595 ARRAY_SIZE(timberdale_cells_bar0_cfg2),
596 &dev->resource[0], msix_entries[0].vector);
597 break;
598 case TIMB_HW_VER3:
599 err = mfd_add_devices(&dev->dev, -1,
600 timberdale_cells_bar0_cfg3,
601 ARRAY_SIZE(timberdale_cells_bar0_cfg3),
602 &dev->resource[0], msix_entries[0].vector);
603 break;
604 default:
605 dev_err(&dev->dev, "Uknown IP setup: %d.%d.%d\n",
606 priv->fw.major, priv->fw.minor, ip_setup);
607 err = -ENODEV;
608 goto err_mfd;
609 break;
610 }
611
612 if (err) {
613 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
614 goto err_mfd;
615 }
616
617 err = mfd_add_devices(&dev->dev, 0,
618 timberdale_cells_bar1, ARRAY_SIZE(timberdale_cells_bar1),
619 &dev->resource[1], msix_entries[0].vector);
620 if (err) {
621 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
622 goto err_mfd2;
623 }
624
625 /* only version 0 and 3 have the iNand routed to SDHCI */
626 if (((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER0) ||
627 ((priv->fw.config & TIMB_HW_VER_MASK) == TIMB_HW_VER3)) {
628 err = mfd_add_devices(&dev->dev, 1, timberdale_cells_bar2,
629 ARRAY_SIZE(timberdale_cells_bar2),
630 &dev->resource[2], msix_entries[0].vector);
631 if (err) {
632 dev_err(&dev->dev, "mfd_add_devices failed: %d\n", err);
633 goto err_mfd2;
634 }
635 }
636
637 kfree(msix_entries);
638
639 dev_info(&dev->dev,
640 "Found Timberdale Card. Rev: %d.%d, HW config: 0x%02x\n",
641 priv->fw.major, priv->fw.minor, priv->fw.config);
642
643 return 0;
644
645err_mfd2:
646 mfd_remove_devices(&dev->dev);
647err_mfd:
648 device_remove_file(&dev->dev, &dev_attr_fw_ver);
649err_create_file:
650 pci_disable_msix(dev);
651err_msix:
652 iounmap(priv->ctl_membase);
653err_ioremap:
654 release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
655err_request:
656 pci_set_drvdata(dev, NULL);
657err_start:
658 pci_disable_device(dev);
659err_enable:
660 kfree(msix_entries);
661 kfree(priv);
662 pci_set_drvdata(dev, NULL);
663 return -ENODEV;
664}
665
666static void __devexit timb_remove(struct pci_dev *dev)
667{
668 struct timberdale_device *priv = pci_get_drvdata(dev);
669
670 mfd_remove_devices(&dev->dev);
671
672 device_remove_file(&dev->dev, &dev_attr_fw_ver);
673
674 iounmap(priv->ctl_membase);
675 release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
676
677 pci_disable_msix(dev);
678 pci_disable_device(dev);
679 pci_set_drvdata(dev, NULL);
680 kfree(priv);
681}
682
683static struct pci_device_id timberdale_pci_tbl[] = {
684 { PCI_DEVICE(PCI_VENDOR_ID_TIMB, PCI_DEVICE_ID_TIMB) },
685 { 0 }
686};
687MODULE_DEVICE_TABLE(pci, timberdale_pci_tbl);
688
689static struct pci_driver timberdale_pci_driver = {
690 .name = DRIVER_NAME,
691 .id_table = timberdale_pci_tbl,
692 .probe = timb_probe,
693 .remove = __devexit_p(timb_remove),
694};
695
696static int __init timberdale_init(void)
697{
698 int err;
699
700 err = pci_register_driver(&timberdale_pci_driver);
701 if (err < 0) {
702 printk(KERN_ERR
703 "Failed to register PCI driver for %s device.\n",
704 timberdale_pci_driver.name);
705 return -ENODEV;
706 }
707
708 printk(KERN_INFO "Driver for %s has been successfully registered.\n",
709 timberdale_pci_driver.name);
710
711 return 0;
712}
713
714static void __exit timberdale_exit(void)
715{
716 pci_unregister_driver(&timberdale_pci_driver);
717
718 printk(KERN_INFO "Driver for %s has been successfully unregistered.\n",
719 timberdale_pci_driver.name);
720}
721
722module_init(timberdale_init);
723module_exit(timberdale_exit);
724
725MODULE_AUTHOR("Mocean Laboratories <info@mocean-labs.com>");
726MODULE_VERSION(DRV_VERSION);
727MODULE_LICENSE("GPL v2");
diff --git a/drivers/mfd/timberdale.h b/drivers/mfd/timberdale.h
new file mode 100644
index 000000000000..8d27ffabc25d
--- /dev/null
+++ b/drivers/mfd/timberdale.h
@@ -0,0 +1,130 @@
1/*
2 * timberdale.h timberdale FPGA MFD driver defines
3 * Copyright (c) 2009 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* Supports:
20 * Timberdale FPGA
21 */
22
23#ifndef MFD_TIMBERDALE_H
24#define MFD_TIMBERDALE_H
25
26#define DRV_VERSION "0.1"
27
28/* This driver only support versions >= 3.8 and < 4.0 */
29#define TIMB_SUPPORTED_MAJOR 3
30
31/* This driver only support minor >= 8 */
32#define TIMB_REQUIRED_MINOR 8
33
34/* Registers of the control area */
35#define TIMB_REV_MAJOR 0x00
36#define TIMB_REV_MINOR 0x04
37#define TIMB_HW_CONFIG 0x08
38#define TIMB_SW_RST 0x40
39
40/* bits in the TIMB_HW_CONFIG register */
41#define TIMB_HW_CONFIG_SPI_8BIT 0x80
42
43#define TIMB_HW_VER_MASK 0x0f
44#define TIMB_HW_VER0 0x00
45#define TIMB_HW_VER1 0x01
46#define TIMB_HW_VER2 0x02
47#define TIMB_HW_VER3 0x03
48
49#define OCORESOFFSET 0x0
50#define OCORESEND 0x1f
51
52#define SPIOFFSET 0x80
53#define SPIEND 0xff
54
55#define UARTLITEOFFSET 0x100
56#define UARTLITEEND 0x10f
57
58#define RDSOFFSET 0x180
59#define RDSEND 0x183
60
61#define ETHOFFSET 0x300
62#define ETHEND 0x3ff
63
64#define GPIOOFFSET 0x400
65#define GPIOEND 0x7ff
66
67#define CHIPCTLOFFSET 0x800
68#define CHIPCTLEND 0x8ff
69#define CHIPCTLSIZE (CHIPCTLEND - CHIPCTLOFFSET)
70
71#define INTCOFFSET 0xc00
72#define INTCEND 0xfff
73#define INTCSIZE (INTCEND - INTCOFFSET)
74
75#define MOSTOFFSET 0x1000
76#define MOSTEND 0x13ff
77
78#define UARTOFFSET 0x1400
79#define UARTEND 0x17ff
80
81#define XIICOFFSET 0x1800
82#define XIICEND 0x19ff
83
84#define I2SOFFSET 0x1C00
85#define I2SEND 0x1fff
86
87#define LOGIWOFFSET 0x30000
88#define LOGIWEND 0x37fff
89
90#define MLCOREOFFSET 0x40000
91#define MLCOREEND 0x43fff
92
93#define DMAOFFSET 0x01000000
94#define DMAEND 0x013fffff
95
96/* SDHC0 is placed in PCI bar 1 */
97#define SDHC0OFFSET 0x00
98#define SDHC0END 0xff
99
100/* SDHC1 is placed in PCI bar 2 */
101#define SDHC1OFFSET 0x00
102#define SDHC1END 0xff
103
104#define PCI_VENDOR_ID_TIMB 0x10ee
105#define PCI_DEVICE_ID_TIMB 0xa123
106
107#define IRQ_TIMBERDALE_INIC 0
108#define IRQ_TIMBERDALE_MLB 1
109#define IRQ_TIMBERDALE_GPIO 2
110#define IRQ_TIMBERDALE_I2C 3
111#define IRQ_TIMBERDALE_UART 4
112#define IRQ_TIMBERDALE_DMA 5
113#define IRQ_TIMBERDALE_I2S 6
114#define IRQ_TIMBERDALE_TSC_INT 7
115#define IRQ_TIMBERDALE_SDHC 8
116#define IRQ_TIMBERDALE_ADV7180 9
117#define IRQ_TIMBERDALE_ETHSW_IF 10
118#define IRQ_TIMBERDALE_SPI 11
119#define IRQ_TIMBERDALE_UARTLITE 12
120#define IRQ_TIMBERDALE_MLCORE 13
121#define IRQ_TIMBERDALE_MLCORE_BUF 14
122#define IRQ_TIMBERDALE_RDS 15
123#define TIMBERDALE_NR_IRQS 16
124
125#define GPIO_PIN_ASCB 8
126#define GPIO_PIN_INIC_RST 14
127#define GPIO_PIN_BT_RST 15
128#define GPIO_NR_PINS 16
129
130#endif
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index d3f55615c099..57b21198828f 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -650,11 +650,11 @@ static int au1xmmc_prepare_data(struct au1xmmc_host *host,
650 flags = DDMA_FLAGS_IE; 650 flags = DDMA_FLAGS_IE;
651 651
652 if (host->flags & HOST_F_XMIT) { 652 if (host->flags & HOST_F_XMIT) {
653 ret = au1xxx_dbdma_put_source_flags(channel, 653 ret = au1xxx_dbdma_put_source(channel,
654 (void *)sg_virt(sg), len, flags); 654 sg_phys(sg), len, flags);
655 } else { 655 } else {
656 ret = au1xxx_dbdma_put_dest_flags(channel, 656 ret = au1xxx_dbdma_put_dest(channel,
657 (void *)sg_virt(sg), len, flags); 657 sg_phys(sg), len, flags);
658 } 658 }
659 659
660 if (!ret) 660 if (!ret)
@@ -1017,6 +1017,10 @@ static int __devinit au1xmmc_probe(struct platform_device *pdev)
1017 } else 1017 } else
1018 mmc->caps |= MMC_CAP_NEEDS_POLL; 1018 mmc->caps |= MMC_CAP_NEEDS_POLL;
1019 1019
1020 /* platform may not be able to use all advertised caps */
1021 if (host->platdata)
1022 mmc->caps &= ~(host->platdata->mask_host_caps);
1023
1020 tasklet_init(&host->data_task, au1xmmc_tasklet_data, 1024 tasklet_init(&host->data_task, au1xmmc_tasklet_data,
1021 (unsigned long)host); 1025 (unsigned long)host);
1022 1026
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 2de0cc823d60..2bb03a8b9ef1 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -251,12 +251,6 @@ config MTD_NETtel
251 help 251 help
252 Support for flash chips on NETtel/SecureEdge/SnapGear boards. 252 Support for flash chips on NETtel/SecureEdge/SnapGear boards.
253 253
254config MTD_ALCHEMY
255 tristate "AMD Alchemy Pb1xxx/Db1xxx/RDK MTD support"
256 depends on SOC_AU1X00 && MTD_PARTITIONS && MTD_CFI
257 help
258 Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards
259
260config MTD_DILNETPC 254config MTD_DILNETPC
261 tristate "CFI Flash device mapped on DIL/Net PC" 255 tristate "CFI Flash device mapped on DIL/Net PC"
262 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN 256 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index ce315214ff2b..a44919f3f3d2 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -40,7 +40,6 @@ obj-$(CONFIG_MTD_SCx200_DOCFLASH)+= scx200_docflash.o
40obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o 40obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o
41obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o 41obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
42obj-$(CONFIG_MTD_PCI) += pci.o 42obj-$(CONFIG_MTD_PCI) += pci.o
43obj-$(CONFIG_MTD_ALCHEMY) += alchemy-flash.o
44obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o 43obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o
45obj-$(CONFIG_MTD_EDB7312) += edb7312.o 44obj-$(CONFIG_MTD_EDB7312) += edb7312.o
46obj-$(CONFIG_MTD_IMPA7) += impa7.o 45obj-$(CONFIG_MTD_IMPA7) += impa7.o
diff --git a/drivers/mtd/maps/alchemy-flash.c b/drivers/mtd/maps/alchemy-flash.c
deleted file mode 100644
index 845ad4f2a542..000000000000
--- a/drivers/mtd/maps/alchemy-flash.c
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 * Flash memory access on AMD Alchemy evaluation boards
3 *
4 * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com>
5 */
6
7#include <linux/init.h>
8#include <linux/module.h>
9#include <linux/types.h>
10#include <linux/kernel.h>
11
12#include <linux/mtd/mtd.h>
13#include <linux/mtd/map.h>
14#include <linux/mtd/partitions.h>
15
16#include <asm/io.h>
17
18#ifdef CONFIG_MIPS_PB1000
19#define BOARD_MAP_NAME "Pb1000 Flash"
20#define BOARD_FLASH_SIZE 0x00800000 /* 8MB */
21#define BOARD_FLASH_WIDTH 4 /* 32-bits */
22#endif
23
24#ifdef CONFIG_MIPS_PB1500
25#define BOARD_MAP_NAME "Pb1500 Flash"
26#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
27#define BOARD_FLASH_WIDTH 4 /* 32-bits */
28#endif
29
30#ifdef CONFIG_MIPS_PB1100
31#define BOARD_MAP_NAME "Pb1100 Flash"
32#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
33#define BOARD_FLASH_WIDTH 4 /* 32-bits */
34#endif
35
36#ifdef CONFIG_MIPS_PB1550
37#define BOARD_MAP_NAME "Pb1550 Flash"
38#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
39#define BOARD_FLASH_WIDTH 4 /* 32-bits */
40#endif
41
42#ifdef CONFIG_MIPS_PB1200
43#define BOARD_MAP_NAME "Pb1200 Flash"
44#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
45#define BOARD_FLASH_WIDTH 2 /* 16-bits */
46#endif
47
48#ifdef CONFIG_MIPS_DB1000
49#define BOARD_MAP_NAME "Db1000 Flash"
50#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
51#define BOARD_FLASH_WIDTH 4 /* 32-bits */
52#endif
53
54#ifdef CONFIG_MIPS_DB1500
55#define BOARD_MAP_NAME "Db1500 Flash"
56#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
57#define BOARD_FLASH_WIDTH 4 /* 32-bits */
58#endif
59
60#ifdef CONFIG_MIPS_DB1100
61#define BOARD_MAP_NAME "Db1100 Flash"
62#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
63#define BOARD_FLASH_WIDTH 4 /* 32-bits */
64#endif
65
66#ifdef CONFIG_MIPS_DB1550
67#define BOARD_MAP_NAME "Db1550 Flash"
68#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
69#define BOARD_FLASH_WIDTH 4 /* 32-bits */
70#endif
71
72#ifdef CONFIG_MIPS_DB1200
73#define BOARD_MAP_NAME "Db1200 Flash"
74#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
75#define BOARD_FLASH_WIDTH 2 /* 16-bits */
76#endif
77
78#ifdef CONFIG_MIPS_BOSPORUS
79#define BOARD_MAP_NAME "Bosporus Flash"
80#define BOARD_FLASH_SIZE 0x01000000 /* 16MB */
81#define BOARD_FLASH_WIDTH 2 /* 16-bits */
82#endif
83
84#ifdef CONFIG_MIPS_MIRAGE
85#define BOARD_MAP_NAME "Mirage Flash"
86#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
87#define BOARD_FLASH_WIDTH 4 /* 32-bits */
88#define USE_LOCAL_ACCESSORS /* why? */
89#endif
90
91static struct map_info alchemy_map = {
92 .name = BOARD_MAP_NAME,
93};
94
95static struct mtd_partition alchemy_partitions[] = {
96 {
97 .name = "User FS",
98 .size = BOARD_FLASH_SIZE - 0x00400000,
99 .offset = 0x0000000
100 },{
101 .name = "YAMON",
102 .size = 0x0100000,
103 .offset = MTDPART_OFS_APPEND,
104 .mask_flags = MTD_WRITEABLE
105 },{
106 .name = "raw kernel",
107 .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
108 .offset = MTDPART_OFS_APPEND,
109 }
110};
111
112static struct mtd_info *mymtd;
113
114static int __init alchemy_mtd_init(void)
115{
116 struct mtd_partition *parts;
117 int nb_parts = 0;
118 unsigned long window_addr;
119 unsigned long window_size;
120
121 /* Default flash buswidth */
122 alchemy_map.bankwidth = BOARD_FLASH_WIDTH;
123
124 window_addr = 0x20000000 - BOARD_FLASH_SIZE;
125 window_size = BOARD_FLASH_SIZE;
126
127 /*
128 * Static partition definition selection
129 */
130 parts = alchemy_partitions;
131 nb_parts = ARRAY_SIZE(alchemy_partitions);
132 alchemy_map.size = window_size;
133
134 /*
135 * Now let's probe for the actual flash. Do it here since
136 * specific machine settings might have been set above.
137 */
138 printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n",
139 alchemy_map.bankwidth*8);
140 alchemy_map.virt = ioremap(window_addr, window_size);
141 mymtd = do_map_probe("cfi_probe", &alchemy_map);
142 if (!mymtd) {
143 iounmap(alchemy_map.virt);
144 return -ENXIO;
145 }
146 mymtd->owner = THIS_MODULE;
147
148 add_mtd_partitions(mymtd, parts, nb_parts);
149 return 0;
150}
151
152static void __exit alchemy_mtd_cleanup(void)
153{
154 if (mymtd) {
155 del_mtd_partitions(mymtd);
156 map_destroy(mymtd);
157 iounmap(alchemy_map.virt);
158 }
159}
160
161module_init(alchemy_mtd_init);
162module_exit(alchemy_mtd_cleanup);
163
164MODULE_AUTHOR("Embedded Alley Solutions, Inc");
165MODULE_DESCRIPTION(BOARD_MAP_NAME " MTD driver");
166MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 677cd53f18c3..bb6465604235 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -457,10 +457,10 @@ config MTD_NAND_NOMADIK
457 457
458config MTD_NAND_SH_FLCTL 458config MTD_NAND_SH_FLCTL
459 tristate "Support for NAND on Renesas SuperH FLCTL" 459 tristate "Support for NAND on Renesas SuperH FLCTL"
460 depends on MTD_NAND && SUPERH && CPU_SUBTYPE_SH7723 460 depends on MTD_NAND && SUPERH
461 help 461 help
462 Several Renesas SuperH CPU has FLCTL. This option enables support 462 Several Renesas SuperH CPU has FLCTL. This option enables support
463 for NAND Flash using FLCTL. This driver support SH7723. 463 for NAND Flash using FLCTL.
464 464
465config MTD_NAND_DAVINCI 465config MTD_NAND_DAVINCI
466 tristate "Support NAND on DaVinci SoC" 466 tristate "Support NAND on DaVinci SoC"
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 92c334ff4508..43d46e424040 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -19,6 +19,7 @@
19#include <asm/io.h> 19#include <asm/io.h>
20 20
21#include <asm/mach-au1x00/au1xxx.h> 21#include <asm/mach-au1x00/au1xxx.h>
22#include <asm/mach-db1x00/bcsr.h>
22 23
23/* 24/*
24 * MTD structure for NAND controller 25 * MTD structure for NAND controller
@@ -475,7 +476,8 @@ static int __init au1xxx_nand_init(void)
475 /* set gpio206 high */ 476 /* set gpio206 high */
476 au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR); 477 au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR);
477 478
478 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr->status >> 6) & 0x1); 479 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1);
480
479 switch (boot_swapboot) { 481 switch (boot_swapboot) {
480 case 0: 482 case 0:
481 case 2: 483 case 2:
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index 02bef21f2e4b..1842df8bdd93 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * SuperH FLCTL nand controller 2 * SuperH FLCTL nand controller
3 * 3 *
4 * Copyright © 2008 Renesas Solutions Corp. 4 * Copyright (c) 2008 Renesas Solutions Corp.
5 * Copyright © 2008 Atom Create Engineering Co., Ltd. 5 * Copyright (c) 2008 Atom Create Engineering Co., Ltd.
6 * 6 *
7 * Based on fsl_elbc_nand.c, Copyright © 2006-2007 Freescale Semiconductor 7 * Based on fsl_elbc_nand.c, Copyright (c) 2006-2007 Freescale Semiconductor
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -75,6 +75,11 @@ static void start_translation(struct sh_flctl *flctl)
75 writeb(TRSTRT, FLTRCR(flctl)); 75 writeb(TRSTRT, FLTRCR(flctl));
76} 76}
77 77
78static void timeout_error(struct sh_flctl *flctl, const char *str)
79{
80 dev_err(&flctl->pdev->dev, "Timeout occured in %s\n", str);
81}
82
78static void wait_completion(struct sh_flctl *flctl) 83static void wait_completion(struct sh_flctl *flctl)
79{ 84{
80 uint32_t timeout = LOOP_TIMEOUT_MAX; 85 uint32_t timeout = LOOP_TIMEOUT_MAX;
@@ -87,7 +92,7 @@ static void wait_completion(struct sh_flctl *flctl)
87 udelay(1); 92 udelay(1);
88 } 93 }
89 94
90 printk(KERN_ERR "wait_completion(): Timeout occured \n"); 95 timeout_error(flctl, __func__);
91 writeb(0x0, FLTRCR(flctl)); 96 writeb(0x0, FLTRCR(flctl));
92} 97}
93 98
@@ -100,6 +105,8 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr)
100 addr = page_addr; /* ERASE1 */ 105 addr = page_addr; /* ERASE1 */
101 } else if (page_addr != -1) { 106 } else if (page_addr != -1) {
102 /* SEQIN, READ0, etc.. */ 107 /* SEQIN, READ0, etc.. */
108 if (flctl->chip.options & NAND_BUSWIDTH_16)
109 column >>= 1;
103 if (flctl->page_size) { 110 if (flctl->page_size) {
104 addr = column & 0x0FFF; 111 addr = column & 0x0FFF;
105 addr |= (page_addr & 0xff) << 16; 112 addr |= (page_addr & 0xff) << 16;
@@ -132,7 +139,7 @@ static void wait_rfifo_ready(struct sh_flctl *flctl)
132 return; 139 return;
133 udelay(1); 140 udelay(1);
134 } 141 }
135 printk(KERN_ERR "wait_rfifo_ready(): Timeout occured \n"); 142 timeout_error(flctl, __func__);
136} 143}
137 144
138static void wait_wfifo_ready(struct sh_flctl *flctl) 145static void wait_wfifo_ready(struct sh_flctl *flctl)
@@ -146,7 +153,7 @@ static void wait_wfifo_ready(struct sh_flctl *flctl)
146 return; 153 return;
147 udelay(1); 154 udelay(1);
148 } 155 }
149 printk(KERN_ERR "wait_wfifo_ready(): Timeout occured \n"); 156 timeout_error(flctl, __func__);
150} 157}
151 158
152static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) 159static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number)
@@ -198,7 +205,7 @@ static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number)
198 writel(0, FL4ECCCR(flctl)); 205 writel(0, FL4ECCCR(flctl));
199 } 206 }
200 207
201 printk(KERN_ERR "wait_recfifo_ready(): Timeout occured \n"); 208 timeout_error(flctl, __func__);
202 return 1; /* timeout */ 209 return 1; /* timeout */
203} 210}
204 211
@@ -214,7 +221,7 @@ static void wait_wecfifo_ready(struct sh_flctl *flctl)
214 return; 221 return;
215 udelay(1); 222 udelay(1);
216 } 223 }
217 printk(KERN_ERR "wait_wecfifo_ready(): Timeout occured \n"); 224 timeout_error(flctl, __func__);
218} 225}
219 226
220static void read_datareg(struct sh_flctl *flctl, int offset) 227static void read_datareg(struct sh_flctl *flctl, int offset)
@@ -275,7 +282,7 @@ static void write_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
275static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val) 282static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val)
276{ 283{
277 struct sh_flctl *flctl = mtd_to_flctl(mtd); 284 struct sh_flctl *flctl = mtd_to_flctl(mtd);
278 uint32_t flcmncr_val = readl(FLCMNCR(flctl)); 285 uint32_t flcmncr_val = readl(FLCMNCR(flctl)) & ~SEL_16BIT;
279 uint32_t flcmdcr_val, addr_len_bytes = 0; 286 uint32_t flcmdcr_val, addr_len_bytes = 0;
280 287
281 /* Set SNAND bit if page size is 2048byte */ 288 /* Set SNAND bit if page size is 2048byte */
@@ -297,6 +304,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va
297 case NAND_CMD_READOOB: 304 case NAND_CMD_READOOB:
298 addr_len_bytes = flctl->rw_ADRCNT; 305 addr_len_bytes = flctl->rw_ADRCNT;
299 flcmdcr_val |= CDSRC_E; 306 flcmdcr_val |= CDSRC_E;
307 if (flctl->chip.options & NAND_BUSWIDTH_16)
308 flcmncr_val |= SEL_16BIT;
300 break; 309 break;
301 case NAND_CMD_SEQIN: 310 case NAND_CMD_SEQIN:
302 /* This case is that cmd is READ0 or READ1 or READ00 */ 311 /* This case is that cmd is READ0 or READ1 or READ00 */
@@ -305,6 +314,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va
305 case NAND_CMD_PAGEPROG: 314 case NAND_CMD_PAGEPROG:
306 addr_len_bytes = flctl->rw_ADRCNT; 315 addr_len_bytes = flctl->rw_ADRCNT;
307 flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW; 316 flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW;
317 if (flctl->chip.options & NAND_BUSWIDTH_16)
318 flcmncr_val |= SEL_16BIT;
308 break; 319 break;
309 case NAND_CMD_READID: 320 case NAND_CMD_READID:
310 flcmncr_val &= ~SNAND_E; 321 flcmncr_val &= ~SNAND_E;
@@ -523,6 +534,8 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command,
523 set_addr(mtd, 0, page_addr); 534 set_addr(mtd, 0, page_addr);
524 535
525 flctl->read_bytes = mtd->writesize + mtd->oobsize; 536 flctl->read_bytes = mtd->writesize + mtd->oobsize;
537 if (flctl->chip.options & NAND_BUSWIDTH_16)
538 column >>= 1;
526 flctl->index += column; 539 flctl->index += column;
527 goto read_normal_exit; 540 goto read_normal_exit;
528 541
@@ -686,6 +699,18 @@ static uint8_t flctl_read_byte(struct mtd_info *mtd)
686 return data; 699 return data;
687} 700}
688 701
702static uint16_t flctl_read_word(struct mtd_info *mtd)
703{
704 struct sh_flctl *flctl = mtd_to_flctl(mtd);
705 int index = flctl->index;
706 uint16_t data;
707 uint16_t *buf = (uint16_t *)&flctl->done_buff[index];
708
709 data = *buf;
710 flctl->index += 2;
711 return data;
712}
713
689static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 714static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
690{ 715{
691 int i; 716 int i;
@@ -769,38 +794,36 @@ static int flctl_chip_init_tail(struct mtd_info *mtd)
769 return 0; 794 return 0;
770} 795}
771 796
772static int __init flctl_probe(struct platform_device *pdev) 797static int __devinit flctl_probe(struct platform_device *pdev)
773{ 798{
774 struct resource *res; 799 struct resource *res;
775 struct sh_flctl *flctl; 800 struct sh_flctl *flctl;
776 struct mtd_info *flctl_mtd; 801 struct mtd_info *flctl_mtd;
777 struct nand_chip *nand; 802 struct nand_chip *nand;
778 struct sh_flctl_platform_data *pdata; 803 struct sh_flctl_platform_data *pdata;
779 int ret; 804 int ret = -ENXIO;
780 805
781 pdata = pdev->dev.platform_data; 806 pdata = pdev->dev.platform_data;
782 if (pdata == NULL) { 807 if (pdata == NULL) {
783 printk(KERN_ERR "sh_flctl platform_data not found.\n"); 808 dev_err(&pdev->dev, "no platform data defined\n");
784 return -ENODEV; 809 return -EINVAL;
785 } 810 }
786 811
787 flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL); 812 flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL);
788 if (!flctl) { 813 if (!flctl) {
789 printk(KERN_ERR "Unable to allocate NAND MTD dev structure.\n"); 814 dev_err(&pdev->dev, "failed to allocate driver data\n");
790 return -ENOMEM; 815 return -ENOMEM;
791 } 816 }
792 817
793 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 818 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
794 if (!res) { 819 if (!res) {
795 printk(KERN_ERR "%s: resource not found.\n", __func__); 820 dev_err(&pdev->dev, "failed to get I/O memory\n");
796 ret = -ENODEV;
797 goto err; 821 goto err;
798 } 822 }
799 823
800 flctl->reg = ioremap(res->start, res->end - res->start + 1); 824 flctl->reg = ioremap(res->start, resource_size(res));
801 if (flctl->reg == NULL) { 825 if (flctl->reg == NULL) {
802 printk(KERN_ERR "%s: ioremap error.\n", __func__); 826 dev_err(&pdev->dev, "failed to remap I/O memory\n");
803 ret = -ENOMEM;
804 goto err; 827 goto err;
805 } 828 }
806 829
@@ -808,6 +831,7 @@ static int __init flctl_probe(struct platform_device *pdev)
808 flctl_mtd = &flctl->mtd; 831 flctl_mtd = &flctl->mtd;
809 nand = &flctl->chip; 832 nand = &flctl->chip;
810 flctl_mtd->priv = nand; 833 flctl_mtd->priv = nand;
834 flctl->pdev = pdev;
811 flctl->hwecc = pdata->has_hwecc; 835 flctl->hwecc = pdata->has_hwecc;
812 836
813 flctl_register_init(flctl, pdata->flcmncr_val); 837 flctl_register_init(flctl, pdata->flcmncr_val);
@@ -825,6 +849,11 @@ static int __init flctl_probe(struct platform_device *pdev)
825 nand->select_chip = flctl_select_chip; 849 nand->select_chip = flctl_select_chip;
826 nand->cmdfunc = flctl_cmdfunc; 850 nand->cmdfunc = flctl_cmdfunc;
827 851
852 if (pdata->flcmncr_val & SEL_16BIT) {
853 nand->options |= NAND_BUSWIDTH_16;
854 nand->read_word = flctl_read_word;
855 }
856
828 ret = nand_scan_ident(flctl_mtd, 1); 857 ret = nand_scan_ident(flctl_mtd, 1);
829 if (ret) 858 if (ret)
830 goto err; 859 goto err;
@@ -846,7 +875,7 @@ err:
846 return ret; 875 return ret;
847} 876}
848 877
849static int __exit flctl_remove(struct platform_device *pdev) 878static int __devexit flctl_remove(struct platform_device *pdev)
850{ 879{
851 struct sh_flctl *flctl = platform_get_drvdata(pdev); 880 struct sh_flctl *flctl = platform_get_drvdata(pdev);
852 881
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index a66b06aa1f0b..4da191b87b0d 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -55,6 +55,7 @@
55#include <linux/delay.h> 55#include <linux/delay.h>
56#include <linux/crc32.h> 56#include <linux/crc32.h>
57#include <linux/phy.h> 57#include <linux/phy.h>
58#include <linux/platform_device.h>
58 59
59#include <asm/cpu.h> 60#include <asm/cpu.h>
60#include <asm/mipsregs.h> 61#include <asm/mipsregs.h>
@@ -63,6 +64,7 @@
63#include <asm/processor.h> 64#include <asm/processor.h>
64 65
65#include <au1000.h> 66#include <au1000.h>
67#include <au1xxx_eth.h>
66#include <prom.h> 68#include <prom.h>
67 69
68#include "au1000_eth.h" 70#include "au1000_eth.h"
@@ -112,15 +114,15 @@ struct au1000_private *au_macs[NUM_ETH_INTERFACES];
112 * 114 *
113 * PHY detection algorithm 115 * PHY detection algorithm
114 * 116 *
115 * If AU1XXX_PHY_STATIC_CONFIG is undefined, the PHY setup is 117 * If phy_static_config is undefined, the PHY setup is
116 * autodetected: 118 * autodetected:
117 * 119 *
118 * mii_probe() first searches the current MAC's MII bus for a PHY, 120 * mii_probe() first searches the current MAC's MII bus for a PHY,
119 * selecting the first (or last, if AU1XXX_PHY_SEARCH_HIGHEST_ADDR is 121 * selecting the first (or last, if phy_search_highest_addr is
120 * defined) PHY address not already claimed by another netdev. 122 * defined) PHY address not already claimed by another netdev.
121 * 123 *
122 * If nothing was found that way when searching for the 2nd ethernet 124 * If nothing was found that way when searching for the 2nd ethernet
123 * controller's PHY and AU1XXX_PHY1_SEARCH_ON_MAC0 is defined, then 125 * controller's PHY and phy1_search_mac0 is defined, then
124 * the first MII bus is searched as well for an unclaimed PHY; this is 126 * the first MII bus is searched as well for an unclaimed PHY; this is
125 * needed in case of a dual-PHY accessible only through the MAC0's MII 127 * needed in case of a dual-PHY accessible only through the MAC0's MII
126 * bus. 128 * bus.
@@ -129,9 +131,7 @@ struct au1000_private *au_macs[NUM_ETH_INTERFACES];
129 * controller is not registered to the network subsystem. 131 * controller is not registered to the network subsystem.
130 */ 132 */
131 133
132/* autodetection defaults */ 134/* autodetection defaults: phy1_search_mac0 */
133#undef AU1XXX_PHY_SEARCH_HIGHEST_ADDR
134#define AU1XXX_PHY1_SEARCH_ON_MAC0
135 135
136/* static PHY setup 136/* static PHY setup
137 * 137 *
@@ -148,29 +148,6 @@ struct au1000_private *au_macs[NUM_ETH_INTERFACES];
148 * specific irq-map 148 * specific irq-map
149 */ 149 */
150 150
151#if defined(CONFIG_MIPS_BOSPORUS)
152/*
153 * Micrel/Kendin 5 port switch attached to MAC0,
154 * MAC0 is associated with PHY address 5 (== WAN port)
155 * MAC1 is not associated with any PHY, since it's connected directly
156 * to the switch.
157 * no interrupts are used
158 */
159# define AU1XXX_PHY_STATIC_CONFIG
160
161# define AU1XXX_PHY0_ADDR 5
162# define AU1XXX_PHY0_BUSID 0
163# undef AU1XXX_PHY0_IRQ
164
165# undef AU1XXX_PHY1_ADDR
166# undef AU1XXX_PHY1_BUSID
167# undef AU1XXX_PHY1_IRQ
168#endif
169
170#if defined(AU1XXX_PHY0_BUSID) && (AU1XXX_PHY0_BUSID > 0)
171# error MAC0-associated PHY attached 2nd MACs MII bus not supported yet
172#endif
173
174static void enable_mac(struct net_device *dev, int force_reset) 151static void enable_mac(struct net_device *dev, int force_reset)
175{ 152{
176 unsigned long flags; 153 unsigned long flags;
@@ -390,67 +367,55 @@ static int mii_probe (struct net_device *dev)
390 struct au1000_private *const aup = netdev_priv(dev); 367 struct au1000_private *const aup = netdev_priv(dev);
391 struct phy_device *phydev = NULL; 368 struct phy_device *phydev = NULL;
392 369
393#if defined(AU1XXX_PHY_STATIC_CONFIG) 370 if (aup->phy_static_config) {
394 BUG_ON(aup->mac_id < 0 || aup->mac_id > 1); 371 BUG_ON(aup->mac_id < 0 || aup->mac_id > 1);
395 372
396 if(aup->mac_id == 0) { /* get PHY0 */ 373 if (aup->phy_addr)
397# if defined(AU1XXX_PHY0_ADDR) 374 phydev = aup->mii_bus->phy_map[aup->phy_addr];
398 phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus->phy_map[AU1XXX_PHY0_ADDR]; 375 else
399# else 376 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
400 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n", 377 dev->name);
401 dev->name);
402 return 0;
403# endif /* defined(AU1XXX_PHY0_ADDR) */
404 } else if (aup->mac_id == 1) { /* get PHY1 */
405# if defined(AU1XXX_PHY1_ADDR)
406 phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus->phy_map[AU1XXX_PHY1_ADDR];
407# else
408 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
409 dev->name);
410 return 0; 378 return 0;
411# endif /* defined(AU1XXX_PHY1_ADDR) */ 379 } else {
412 } 380 int phy_addr;
413 381
414#else /* defined(AU1XXX_PHY_STATIC_CONFIG) */ 382 /* find the first (lowest address) PHY on the current MAC's MII bus */
415 int phy_addr; 383 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++)
416 384 if (aup->mii_bus->phy_map[phy_addr]) {
417 /* find the first (lowest address) PHY on the current MAC's MII bus */ 385 phydev = aup->mii_bus->phy_map[phy_addr];
418 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) 386 if (!aup->phy_search_highest_addr)
419 if (aup->mii_bus->phy_map[phy_addr]) { 387 break; /* break out with first one found */
420 phydev = aup->mii_bus->phy_map[phy_addr]; 388 }
421# if !defined(AU1XXX_PHY_SEARCH_HIGHEST_ADDR)
422 break; /* break out with first one found */
423# endif
424 }
425 389
426# if defined(AU1XXX_PHY1_SEARCH_ON_MAC0) 390 if (aup->phy1_search_mac0) {
427 /* try harder to find a PHY */ 391 /* try harder to find a PHY */
428 if (!phydev && (aup->mac_id == 1)) { 392 if (!phydev && (aup->mac_id == 1)) {
429 /* no PHY found, maybe we have a dual PHY? */ 393 /* no PHY found, maybe we have a dual PHY? */
430 printk (KERN_INFO DRV_NAME ": no PHY found on MAC1, " 394 printk (KERN_INFO DRV_NAME ": no PHY found on MAC1, "
431 "let's see if it's attached to MAC0...\n"); 395 "let's see if it's attached to MAC0...\n");
432 396
433 BUG_ON(!au_macs[0]); 397 /* find the first (lowest address) non-attached PHY on
398 * the MAC0 MII bus */
399 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
400 struct phy_device *const tmp_phydev =
401 aup->mii_bus->phy_map[phy_addr];
434 402
435 /* find the first (lowest address) non-attached PHY on 403 if (aup->mac_id == 1)
436 * the MAC0 MII bus */ 404 break;
437 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
438 struct phy_device *const tmp_phydev =
439 au_macs[0]->mii_bus->phy_map[phy_addr];
440 405
441 if (!tmp_phydev) 406 if (!tmp_phydev)
442 continue; /* no PHY here... */ 407 continue; /* no PHY here... */
443 408
444 if (tmp_phydev->attached_dev) 409 if (tmp_phydev->attached_dev)
445 continue; /* already claimed by MAC0 */ 410 continue; /* already claimed by MAC0 */
446 411
447 phydev = tmp_phydev; 412 phydev = tmp_phydev;
448 break; /* found it */ 413 break; /* found it */
414 }
415 }
449 } 416 }
450 } 417 }
451# endif /* defined(AU1XXX_PHY1_SEARCH_OTHER_BUS) */
452 418
453#endif /* defined(AU1XXX_PHY_STATIC_CONFIG) */
454 if (!phydev) { 419 if (!phydev) {
455 printk (KERN_ERR DRV_NAME ":%s: no PHY found\n", dev->name); 420 printk (KERN_ERR DRV_NAME ":%s: no PHY found\n", dev->name);
456 return -1; 421 return -1;
@@ -578,31 +543,6 @@ setup_hw_rings(struct au1000_private *aup, u32 rx_base, u32 tx_base)
578 } 543 }
579} 544}
580 545
581static struct {
582 u32 base_addr;
583 u32 macen_addr;
584 int irq;
585 struct net_device *dev;
586} iflist[2] = {
587#ifdef CONFIG_SOC_AU1000
588 {AU1000_ETH0_BASE, AU1000_MAC0_ENABLE, AU1000_MAC0_DMA_INT},
589 {AU1000_ETH1_BASE, AU1000_MAC1_ENABLE, AU1000_MAC1_DMA_INT}
590#endif
591#ifdef CONFIG_SOC_AU1100
592 {AU1100_ETH0_BASE, AU1100_MAC0_ENABLE, AU1100_MAC0_DMA_INT}
593#endif
594#ifdef CONFIG_SOC_AU1500
595 {AU1500_ETH0_BASE, AU1500_MAC0_ENABLE, AU1500_MAC0_DMA_INT},
596 {AU1500_ETH1_BASE, AU1500_MAC1_ENABLE, AU1500_MAC1_DMA_INT}
597#endif
598#ifdef CONFIG_SOC_AU1550
599 {AU1550_ETH0_BASE, AU1550_MAC0_ENABLE, AU1550_MAC0_DMA_INT},
600 {AU1550_ETH1_BASE, AU1550_MAC1_ENABLE, AU1550_MAC1_DMA_INT}
601#endif
602};
603
604static int num_ifs;
605
606/* 546/*
607 * ethtool operations 547 * ethtool operations
608 */ 548 */
@@ -711,7 +651,6 @@ static int au1000_init(struct net_device *dev)
711 651
712static inline void update_rx_stats(struct net_device *dev, u32 status) 652static inline void update_rx_stats(struct net_device *dev, u32 status)
713{ 653{
714 struct au1000_private *aup = netdev_priv(dev);
715 struct net_device_stats *ps = &dev->stats; 654 struct net_device_stats *ps = &dev->stats;
716 655
717 ps->rx_packets++; 656 ps->rx_packets++;
@@ -969,7 +908,7 @@ static netdev_tx_t au1000_tx(struct sk_buff *skb, struct net_device *dev)
969 } 908 }
970 909
971 pDB = aup->tx_db_inuse[aup->tx_head]; 910 pDB = aup->tx_db_inuse[aup->tx_head];
972 skb_copy_from_linear_data(skb, pDB->vaddr, skb->len); 911 skb_copy_from_linear_data(skb, (void *)pDB->vaddr, skb->len);
973 if (skb->len < ETH_ZLEN) { 912 if (skb->len < ETH_ZLEN) {
974 for (i=skb->len; i<ETH_ZLEN; i++) { 913 for (i=skb->len; i<ETH_ZLEN; i++) {
975 ((char *)pDB->vaddr)[i] = 0; 914 ((char *)pDB->vaddr)[i] = 0;
@@ -1055,53 +994,59 @@ static const struct net_device_ops au1000_netdev_ops = {
1055 .ndo_change_mtu = eth_change_mtu, 994 .ndo_change_mtu = eth_change_mtu,
1056}; 995};
1057 996
1058static struct net_device * au1000_probe(int port_num) 997static int __devinit au1000_probe(struct platform_device *pdev)
1059{ 998{
1060 static unsigned version_printed = 0; 999 static unsigned version_printed = 0;
1061 struct au1000_private *aup = NULL; 1000 struct au1000_private *aup = NULL;
1001 struct au1000_eth_platform_data *pd;
1062 struct net_device *dev = NULL; 1002 struct net_device *dev = NULL;
1063 db_dest_t *pDB, *pDBfree; 1003 db_dest_t *pDB, *pDBfree;
1004 int irq, i, err = 0;
1005 struct resource *base, *macen;
1064 char ethaddr[6]; 1006 char ethaddr[6];
1065 int irq, i, err;
1066 u32 base, macen;
1067 1007
1068 if (port_num >= NUM_ETH_INTERFACES) 1008 base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1069 return NULL; 1009 if (!base) {
1010 printk(KERN_ERR DRV_NAME ": failed to retrieve base register\n");
1011 err = -ENODEV;
1012 goto out;
1013 }
1070 1014
1071 base = CPHYSADDR(iflist[port_num].base_addr ); 1015 macen = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1072 macen = CPHYSADDR(iflist[port_num].macen_addr); 1016 if (!macen) {
1073 irq = iflist[port_num].irq; 1017 printk(KERN_ERR DRV_NAME ": failed to retrieve MAC Enable register\n");
1018 err = -ENODEV;
1019 goto out;
1020 }
1074 1021
1075 if (!request_mem_region( base, MAC_IOSIZE, "Au1x00 ENET") || 1022 irq = platform_get_irq(pdev, 0);
1076 !request_mem_region(macen, 4, "Au1x00 ENET")) 1023 if (irq < 0) {
1077 return NULL; 1024 printk(KERN_ERR DRV_NAME ": failed to retrieve IRQ\n");
1025 err = -ENODEV;
1026 goto out;
1027 }
1078 1028
1079 if (version_printed++ == 0) 1029 if (!request_mem_region(base->start, resource_size(base), pdev->name)) {
1080 printk("%s version %s %s\n", DRV_NAME, DRV_VERSION, DRV_AUTHOR); 1030 printk(KERN_ERR DRV_NAME ": failed to request memory region for base registers\n");
1031 err = -ENXIO;
1032 goto out;
1033 }
1034
1035 if (!request_mem_region(macen->start, resource_size(macen), pdev->name)) {
1036 printk(KERN_ERR DRV_NAME ": failed to request memory region for MAC enable register\n");
1037 err = -ENXIO;
1038 goto err_request;
1039 }
1081 1040
1082 dev = alloc_etherdev(sizeof(struct au1000_private)); 1041 dev = alloc_etherdev(sizeof(struct au1000_private));
1083 if (!dev) { 1042 if (!dev) {
1084 printk(KERN_ERR "%s: alloc_etherdev failed\n", DRV_NAME); 1043 printk(KERN_ERR "%s: alloc_etherdev failed\n", DRV_NAME);
1085 return NULL; 1044 err = -ENOMEM;
1045 goto err_alloc;
1086 } 1046 }
1087 1047
1088 dev->base_addr = base; 1048 SET_NETDEV_DEV(dev, &pdev->dev);
1089 dev->irq = irq; 1049 platform_set_drvdata(pdev, dev);
1090 dev->netdev_ops = &au1000_netdev_ops;
1091 SET_ETHTOOL_OPS(dev, &au1000_ethtool_ops);
1092 dev->watchdog_timeo = ETH_TX_TIMEOUT;
1093
1094 err = register_netdev(dev);
1095 if (err != 0) {
1096 printk(KERN_ERR "%s: Cannot register net device, error %d\n",
1097 DRV_NAME, err);
1098 free_netdev(dev);
1099 return NULL;
1100 }
1101
1102 printk("%s: Au1xx0 Ethernet found at 0x%x, irq %d\n",
1103 dev->name, base, irq);
1104
1105 aup = netdev_priv(dev); 1050 aup = netdev_priv(dev);
1106 1051
1107 spin_lock_init(&aup->lock); 1052 spin_lock_init(&aup->lock);
@@ -1112,21 +1057,29 @@ static struct net_device * au1000_probe(int port_num)
1112 (NUM_TX_BUFFS + NUM_RX_BUFFS), 1057 (NUM_TX_BUFFS + NUM_RX_BUFFS),
1113 &aup->dma_addr, 0); 1058 &aup->dma_addr, 0);
1114 if (!aup->vaddr) { 1059 if (!aup->vaddr) {
1115 free_netdev(dev); 1060 printk(KERN_ERR DRV_NAME ": failed to allocate data buffers\n");
1116 release_mem_region( base, MAC_IOSIZE); 1061 err = -ENOMEM;
1117 release_mem_region(macen, 4); 1062 goto err_vaddr;
1118 return NULL;
1119 } 1063 }
1120 1064
1121 /* aup->mac is the base address of the MAC's registers */ 1065 /* aup->mac is the base address of the MAC's registers */
1122 aup->mac = (volatile mac_reg_t *)iflist[port_num].base_addr; 1066 aup->mac = (volatile mac_reg_t *)ioremap_nocache(base->start, resource_size(base));
1067 if (!aup->mac) {
1068 printk(KERN_ERR DRV_NAME ": failed to ioremap MAC registers\n");
1069 err = -ENXIO;
1070 goto err_remap1;
1071 }
1123 1072
1124 /* Setup some variables for quick register address access */ 1073 /* Setup some variables for quick register address access */
1125 aup->enable = (volatile u32 *)iflist[port_num].macen_addr; 1074 aup->enable = (volatile u32 *)ioremap_nocache(macen->start, resource_size(macen));
1126 aup->mac_id = port_num; 1075 if (!aup->enable) {
1127 au_macs[port_num] = aup; 1076 printk(KERN_ERR DRV_NAME ": failed to ioremap MAC enable register\n");
1077 err = -ENXIO;
1078 goto err_remap2;
1079 }
1080 aup->mac_id = pdev->id;
1128 1081
1129 if (port_num == 0) { 1082 if (pdev->id == 0) {
1130 if (prom_get_ethernet_addr(ethaddr) == 0) 1083 if (prom_get_ethernet_addr(ethaddr) == 0)
1131 memcpy(au1000_mac_addr, ethaddr, sizeof(au1000_mac_addr)); 1084 memcpy(au1000_mac_addr, ethaddr, sizeof(au1000_mac_addr));
1132 else { 1085 else {
@@ -1136,7 +1089,7 @@ static struct net_device * au1000_probe(int port_num)
1136 } 1089 }
1137 1090
1138 setup_hw_rings(aup, MAC0_RX_DMA_ADDR, MAC0_TX_DMA_ADDR); 1091 setup_hw_rings(aup, MAC0_RX_DMA_ADDR, MAC0_TX_DMA_ADDR);
1139 } else if (port_num == 1) 1092 } else if (pdev->id == 1)
1140 setup_hw_rings(aup, MAC1_RX_DMA_ADDR, MAC1_TX_DMA_ADDR); 1093 setup_hw_rings(aup, MAC1_RX_DMA_ADDR, MAC1_TX_DMA_ADDR);
1141 1094
1142 /* 1095 /*
@@ -1144,14 +1097,37 @@ static struct net_device * au1000_probe(int port_num)
1144 * to match those that are printed on their stickers 1097 * to match those that are printed on their stickers
1145 */ 1098 */
1146 memcpy(dev->dev_addr, au1000_mac_addr, sizeof(au1000_mac_addr)); 1099 memcpy(dev->dev_addr, au1000_mac_addr, sizeof(au1000_mac_addr));
1147 dev->dev_addr[5] += port_num; 1100 dev->dev_addr[5] += pdev->id;
1148 1101
1149 *aup->enable = 0; 1102 *aup->enable = 0;
1150 aup->mac_enabled = 0; 1103 aup->mac_enabled = 0;
1151 1104
1105 pd = pdev->dev.platform_data;
1106 if (!pd) {
1107 printk(KERN_INFO DRV_NAME ": no platform_data passed, PHY search on MAC0\n");
1108 aup->phy1_search_mac0 = 1;
1109 } else {
1110 aup->phy_static_config = pd->phy_static_config;
1111 aup->phy_search_highest_addr = pd->phy_search_highest_addr;
1112 aup->phy1_search_mac0 = pd->phy1_search_mac0;
1113 aup->phy_addr = pd->phy_addr;
1114 aup->phy_busid = pd->phy_busid;
1115 aup->phy_irq = pd->phy_irq;
1116 }
1117
1118 if (aup->phy_busid && aup->phy_busid > 0) {
1119 printk(KERN_ERR DRV_NAME ": MAC0-associated PHY attached 2nd MACs MII"
1120 "bus not supported yet\n");
1121 err = -ENODEV;
1122 goto err_mdiobus_alloc;
1123 }
1124
1152 aup->mii_bus = mdiobus_alloc(); 1125 aup->mii_bus = mdiobus_alloc();
1153 if (aup->mii_bus == NULL) 1126 if (aup->mii_bus == NULL) {
1154 goto err_out; 1127 printk(KERN_ERR DRV_NAME ": failed to allocate mdiobus structure\n");
1128 err = -ENOMEM;
1129 goto err_mdiobus_alloc;
1130 }
1155 1131
1156 aup->mii_bus->priv = dev; 1132 aup->mii_bus->priv = dev;
1157 aup->mii_bus->read = au1000_mdiobus_read; 1133 aup->mii_bus->read = au1000_mdiobus_read;
@@ -1165,23 +1141,19 @@ static struct net_device * au1000_probe(int port_num)
1165 1141
1166 for(i = 0; i < PHY_MAX_ADDR; ++i) 1142 for(i = 0; i < PHY_MAX_ADDR; ++i)
1167 aup->mii_bus->irq[i] = PHY_POLL; 1143 aup->mii_bus->irq[i] = PHY_POLL;
1168
1169 /* if known, set corresponding PHY IRQs */ 1144 /* if known, set corresponding PHY IRQs */
1170#if defined(AU1XXX_PHY_STATIC_CONFIG) 1145 if (aup->phy_static_config)
1171# if defined(AU1XXX_PHY0_IRQ) 1146 if (aup->phy_irq && aup->phy_busid == aup->mac_id)
1172 if (AU1XXX_PHY0_BUSID == aup->mac_id) 1147 aup->mii_bus->irq[aup->phy_addr] = aup->phy_irq;
1173 aup->mii_bus->irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ; 1148
1174# endif 1149 err = mdiobus_register(aup->mii_bus);
1175# if defined(AU1XXX_PHY1_IRQ) 1150 if (err) {
1176 if (AU1XXX_PHY1_BUSID == aup->mac_id) 1151 printk(KERN_ERR DRV_NAME " failed to register MDIO bus\n");
1177 aup->mii_bus->irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ; 1152 goto err_mdiobus_reg;
1178# endif 1153 }
1179#endif
1180 mdiobus_register(aup->mii_bus);
1181 1154
1182 if (mii_probe(dev) != 0) { 1155 if (mii_probe(dev) != 0)
1183 goto err_out; 1156 goto err_out;
1184 }
1185 1157
1186 pDBfree = NULL; 1158 pDBfree = NULL;
1187 /* setup the data buffer descriptors and attach a buffer to each one */ 1159 /* setup the data buffer descriptors and attach a buffer to each one */
@@ -1213,19 +1185,35 @@ static struct net_device * au1000_probe(int port_num)
1213 aup->tx_db_inuse[i] = pDB; 1185 aup->tx_db_inuse[i] = pDB;
1214 } 1186 }
1215 1187
1188 dev->base_addr = base->start;
1189 dev->irq = irq;
1190 dev->netdev_ops = &au1000_netdev_ops;
1191 SET_ETHTOOL_OPS(dev, &au1000_ethtool_ops);
1192 dev->watchdog_timeo = ETH_TX_TIMEOUT;
1193
1216 /* 1194 /*
1217 * The boot code uses the ethernet controller, so reset it to start 1195 * The boot code uses the ethernet controller, so reset it to start
1218 * fresh. au1000_init() expects that the device is in reset state. 1196 * fresh. au1000_init() expects that the device is in reset state.
1219 */ 1197 */
1220 reset_mac(dev); 1198 reset_mac(dev);
1221 1199
1222 return dev; 1200 err = register_netdev(dev);
1201 if (err) {
1202 printk(KERN_ERR DRV_NAME "%s: Cannot register net device, aborting.\n",
1203 dev->name);
1204 goto err_out;
1205 }
1206
1207 printk("%s: Au1xx0 Ethernet found at 0x%lx, irq %d\n",
1208 dev->name, (unsigned long)base->start, irq);
1209 if (version_printed++ == 0)
1210 printk("%s version %s %s\n", DRV_NAME, DRV_VERSION, DRV_AUTHOR);
1211
1212 return 0;
1223 1213
1224err_out: 1214err_out:
1225 if (aup->mii_bus != NULL) { 1215 if (aup->mii_bus != NULL)
1226 mdiobus_unregister(aup->mii_bus); 1216 mdiobus_unregister(aup->mii_bus);
1227 mdiobus_free(aup->mii_bus);
1228 }
1229 1217
1230 /* here we should have a valid dev plus aup-> register addresses 1218 /* here we should have a valid dev plus aup-> register addresses
1231 * so we can reset the mac properly.*/ 1219 * so we can reset the mac properly.*/
@@ -1239,67 +1227,84 @@ err_out:
1239 if (aup->tx_db_inuse[i]) 1227 if (aup->tx_db_inuse[i])
1240 ReleaseDB(aup, aup->tx_db_inuse[i]); 1228 ReleaseDB(aup, aup->tx_db_inuse[i]);
1241 } 1229 }
1230err_mdiobus_reg:
1231 mdiobus_free(aup->mii_bus);
1232err_mdiobus_alloc:
1233 iounmap(aup->enable);
1234err_remap2:
1235 iounmap(aup->mac);
1236err_remap1:
1242 dma_free_noncoherent(NULL, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), 1237 dma_free_noncoherent(NULL, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS),
1243 (void *)aup->vaddr, aup->dma_addr); 1238 (void *)aup->vaddr, aup->dma_addr);
1244 unregister_netdev(dev); 1239err_vaddr:
1245 free_netdev(dev); 1240 free_netdev(dev);
1246 release_mem_region( base, MAC_IOSIZE); 1241err_alloc:
1247 release_mem_region(macen, 4); 1242 release_mem_region(macen->start, resource_size(macen));
1248 return NULL; 1243err_request:
1244 release_mem_region(base->start, resource_size(base));
1245out:
1246 return err;
1249} 1247}
1250 1248
1251/* 1249static int __devexit au1000_remove(struct platform_device *pdev)
1252 * Setup the base address and interrupt of the Au1xxx ethernet macs
1253 * based on cpu type and whether the interface is enabled in sys_pinfunc
1254 * register. The last interface is enabled if SYS_PF_NI2 (bit 4) is 0.
1255 */
1256static int __init au1000_init_module(void)
1257{ 1250{
1258 int ni = (int)((au_readl(SYS_PINFUNC) & (u32)(SYS_PF_NI2)) >> 4); 1251 struct net_device *dev = platform_get_drvdata(pdev);
1259 struct net_device *dev; 1252 struct au1000_private *aup = netdev_priv(dev);
1260 int i, found_one = 0; 1253 int i;
1254 struct resource *base, *macen;
1261 1255
1262 num_ifs = NUM_ETH_INTERFACES - ni; 1256 platform_set_drvdata(pdev, NULL);
1257
1258 unregister_netdev(dev);
1259 mdiobus_unregister(aup->mii_bus);
1260 mdiobus_free(aup->mii_bus);
1261
1262 for (i = 0; i < NUM_RX_DMA; i++)
1263 if (aup->rx_db_inuse[i])
1264 ReleaseDB(aup, aup->rx_db_inuse[i]);
1265
1266 for (i = 0; i < NUM_TX_DMA; i++)
1267 if (aup->tx_db_inuse[i])
1268 ReleaseDB(aup, aup->tx_db_inuse[i]);
1269
1270 dma_free_noncoherent(NULL, MAX_BUF_SIZE *
1271 (NUM_TX_BUFFS + NUM_RX_BUFFS),
1272 (void *)aup->vaddr, aup->dma_addr);
1273
1274 iounmap(aup->mac);
1275 iounmap(aup->enable);
1276
1277 base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1278 release_mem_region(base->start, resource_size(base));
1279
1280 macen = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1281 release_mem_region(macen->start, resource_size(macen));
1282
1283 free_netdev(dev);
1263 1284
1264 for(i = 0; i < num_ifs; i++) {
1265 dev = au1000_probe(i);
1266 iflist[i].dev = dev;
1267 if (dev)
1268 found_one++;
1269 }
1270 if (!found_one)
1271 return -ENODEV;
1272 return 0; 1285 return 0;
1273} 1286}
1274 1287
1275static void __exit au1000_cleanup_module(void) 1288static struct platform_driver au1000_eth_driver = {
1289 .probe = au1000_probe,
1290 .remove = __devexit_p(au1000_remove),
1291 .driver = {
1292 .name = "au1000-eth",
1293 .owner = THIS_MODULE,
1294 },
1295};
1296MODULE_ALIAS("platform:au1000-eth");
1297
1298
1299static int __init au1000_init_module(void)
1300{
1301 return platform_driver_register(&au1000_eth_driver);
1302}
1303
1304static void __exit au1000_exit_module(void)
1276{ 1305{
1277 int i, j; 1306 platform_driver_unregister(&au1000_eth_driver);
1278 struct net_device *dev;
1279 struct au1000_private *aup;
1280
1281 for (i = 0; i < num_ifs; i++) {
1282 dev = iflist[i].dev;
1283 if (dev) {
1284 aup = netdev_priv(dev);
1285 unregister_netdev(dev);
1286 mdiobus_unregister(aup->mii_bus);
1287 mdiobus_free(aup->mii_bus);
1288 for (j = 0; j < NUM_RX_DMA; j++)
1289 if (aup->rx_db_inuse[j])
1290 ReleaseDB(aup, aup->rx_db_inuse[j]);
1291 for (j = 0; j < NUM_TX_DMA; j++)
1292 if (aup->tx_db_inuse[j])
1293 ReleaseDB(aup, aup->tx_db_inuse[j]);
1294 dma_free_noncoherent(NULL, MAX_BUF_SIZE *
1295 (NUM_TX_BUFFS + NUM_RX_BUFFS),
1296 (void *)aup->vaddr, aup->dma_addr);
1297 release_mem_region(dev->base_addr, MAC_IOSIZE);
1298 release_mem_region(CPHYSADDR(iflist[i].macen_addr), 4);
1299 free_netdev(dev);
1300 }
1301 }
1302} 1307}
1303 1308
1304module_init(au1000_init_module); 1309module_init(au1000_init_module);
1305module_exit(au1000_cleanup_module); 1310module_exit(au1000_exit_module);
diff --git a/drivers/net/au1000_eth.h b/drivers/net/au1000_eth.h
index 824ecd5ff3a8..f9d29a29b8fd 100644
--- a/drivers/net/au1000_eth.h
+++ b/drivers/net/au1000_eth.h
@@ -108,6 +108,15 @@ struct au1000_private {
108 struct phy_device *phy_dev; 108 struct phy_device *phy_dev;
109 struct mii_bus *mii_bus; 109 struct mii_bus *mii_bus;
110 110
111 /* PHY configuration */
112 int phy_static_config;
113 int phy_search_highest_addr;
114 int phy1_search_mac0;
115
116 int phy_addr;
117 int phy_busid;
118 int phy_irq;
119
111 /* These variables are just for quick access to certain regs addresses. */ 120 /* These variables are just for quick access to certain regs addresses. */
112 volatile mac_reg_t *mac; /* mac registers */ 121 volatile mac_reg_t *mac; /* mac registers */
113 volatile u32 *enable; /* address of MAC Enable Register */ 122 volatile u32 *enable; /* address of MAC Enable Register */
diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c
index 0074f3bf17be..b85c81f60d10 100644
--- a/drivers/net/cpmac.c
+++ b/drivers/net/cpmac.c
@@ -36,6 +36,7 @@
36#include <linux/phy_fixed.h> 36#include <linux/phy_fixed.h>
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
39#include <linux/clk.h>
39#include <asm/gpio.h> 40#include <asm/gpio.h>
40#include <asm/atomic.h> 41#include <asm/atomic.h>
41 42
@@ -294,9 +295,16 @@ static int cpmac_mdio_write(struct mii_bus *bus, int phy_id,
294 295
295static int cpmac_mdio_reset(struct mii_bus *bus) 296static int cpmac_mdio_reset(struct mii_bus *bus)
296{ 297{
298 struct clk *cpmac_clk;
299
300 cpmac_clk = clk_get(&bus->dev, "cpmac");
301 if (IS_ERR(cpmac_clk)) {
302 printk(KERN_ERR "unable to get cpmac clock\n");
303 return -1;
304 }
297 ar7_device_reset(AR7_RESET_BIT_MDIO); 305 ar7_device_reset(AR7_RESET_BIT_MDIO);
298 cpmac_write(bus->priv, CPMAC_MDIO_CONTROL, MDIOC_ENABLE | 306 cpmac_write(bus->priv, CPMAC_MDIO_CONTROL, MDIOC_ENABLE |
299 MDIOC_CLKDIV(ar7_cpmac_freq() / 2200000 - 1)); 307 MDIOC_CLKDIV(clk_get_rate(cpmac_clk) / 2200000 - 1));
300 return 0; 308 return 0;
301} 309}
302 310
diff --git a/drivers/net/irda/au1k_ir.c b/drivers/net/irda/au1k_ir.c
index 9b2eebdbb25b..b5cbd39d0685 100644
--- a/drivers/net/irda/au1k_ir.c
+++ b/drivers/net/irda/au1k_ir.c
@@ -36,6 +36,7 @@
36#include <asm/pb1000.h> 36#include <asm/pb1000.h>
37#elif defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) 37#elif defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100)
38#include <asm/db1x00.h> 38#include <asm/db1x00.h>
39#include <asm/mach-db1x00/bcsr.h>
39#else 40#else
40#error au1k_ir: unsupported board 41#error au1k_ir: unsupported board
41#endif 42#endif
@@ -66,10 +67,6 @@ static char version[] __devinitdata =
66 67
67#define RUN_AT(x) (jiffies + (x)) 68#define RUN_AT(x) (jiffies + (x))
68 69
69#if defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100)
70static BCSR * const bcsr = (BCSR *)0xAE000000;
71#endif
72
73static DEFINE_SPINLOCK(ir_lock); 70static DEFINE_SPINLOCK(ir_lock);
74 71
75/* 72/*
@@ -282,9 +279,8 @@ static int au1k_irda_net_init(struct net_device *dev)
282 279
283#if defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) 280#if defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100)
284 /* power on */ 281 /* power on */
285 bcsr->resets &= ~BCSR_RESETS_IRDA_MODE_MASK; 282 bcsr_mod(BCSR_RESETS, BCSR_RESETS_IRDA_MODE_MASK,
286 bcsr->resets |= BCSR_RESETS_IRDA_MODE_FULL; 283 BCSR_RESETS_IRDA_MODE_FULL);
287 au_sync();
288#endif 284#endif
289 285
290 return 0; 286 return 0;
@@ -720,14 +716,14 @@ au1k_irda_set_speed(struct net_device *dev, int speed)
720 716
721 if (speed == 4000000) { 717 if (speed == 4000000) {
722#if defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) 718#if defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100)
723 bcsr->resets |= BCSR_RESETS_FIR_SEL; 719 bcsr_mod(BCSR_RESETS, 0, BCSR_RESETS_FIR_SEL);
724#else /* Pb1000 and Pb1100 */ 720#else /* Pb1000 and Pb1100 */
725 writel(1<<13, CPLD_AUX1); 721 writel(1<<13, CPLD_AUX1);
726#endif 722#endif
727 } 723 }
728 else { 724 else {
729#if defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) 725#if defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100)
730 bcsr->resets &= ~BCSR_RESETS_FIR_SEL; 726 bcsr_mod(BCSR_RESETS, BCSR_RESETS_FIR_SEL, 0);
731#else /* Pb1000 and Pb1100 */ 727#else /* Pb1000 and Pb1100 */
732 writel(readl(CPLD_AUX1) & ~(1<<13), CPLD_AUX1); 728 writel(readl(CPLD_AUX1) & ~(1<<13), CPLD_AUX1);
733#endif 729#endif
diff --git a/drivers/net/mace.c b/drivers/net/mace.c
index 57534f0e906d..ab5f0bf6d1ae 100644
--- a/drivers/net/mace.c
+++ b/drivers/net/mace.c
@@ -206,7 +206,7 @@ static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_i
206 mp->port_aaui = port_aaui; 206 mp->port_aaui = port_aaui;
207 else { 207 else {
208 /* Apple Network Server uses the AAUI port */ 208 /* Apple Network Server uses the AAUI port */
209 if (machine_is_compatible("AAPL,ShinerESB")) 209 if (of_machine_is_compatible("AAPL,ShinerESB"))
210 mp->port_aaui = 1; 210 mp->port_aaui = 1;
211 else { 211 else {
212#ifdef CONFIG_MACE_AAUI_PORT 212#ifdef CONFIG_MACE_AAUI_PORT
diff --git a/drivers/net/macmace.c b/drivers/net/macmace.c
index 4e4eac0ba176..13ba8f4afb7e 100644
--- a/drivers/net/macmace.c
+++ b/drivers/net/macmace.c
@@ -39,7 +39,6 @@
39#include "mace.h" 39#include "mace.h"
40 40
41static char mac_mace_string[] = "macmace"; 41static char mac_mace_string[] = "macmace";
42static struct platform_device *mac_mace_device;
43 42
44#define N_TX_BUFF_ORDER 0 43#define N_TX_BUFF_ORDER 0
45#define N_TX_RING (1 << N_TX_BUFF_ORDER) 44#define N_TX_RING (1 << N_TX_BUFF_ORDER)
@@ -752,6 +751,7 @@ static irqreturn_t mace_dma_intr(int irq, void *dev_id)
752 751
753MODULE_LICENSE("GPL"); 752MODULE_LICENSE("GPL");
754MODULE_DESCRIPTION("Macintosh MACE ethernet driver"); 753MODULE_DESCRIPTION("Macintosh MACE ethernet driver");
754MODULE_ALIAS("platform:macmace");
755 755
756static int __devexit mac_mace_device_remove (struct platform_device *pdev) 756static int __devexit mac_mace_device_remove (struct platform_device *pdev)
757{ 757{
@@ -777,47 +777,22 @@ static struct platform_driver mac_mace_driver = {
777 .probe = mace_probe, 777 .probe = mace_probe,
778 .remove = __devexit_p(mac_mace_device_remove), 778 .remove = __devexit_p(mac_mace_device_remove),
779 .driver = { 779 .driver = {
780 .name = mac_mace_string, 780 .name = mac_mace_string,
781 .owner = THIS_MODULE,
781 }, 782 },
782}; 783};
783 784
784static int __init mac_mace_init_module(void) 785static int __init mac_mace_init_module(void)
785{ 786{
786 int err;
787
788 if (!MACH_IS_MAC) 787 if (!MACH_IS_MAC)
789 return -ENODEV; 788 return -ENODEV;
790 789
791 if ((err = platform_driver_register(&mac_mace_driver))) { 790 return platform_driver_register(&mac_mace_driver);
792 printk(KERN_ERR "Driver registration failed\n");
793 return err;
794 }
795
796 mac_mace_device = platform_device_alloc(mac_mace_string, 0);
797 if (!mac_mace_device)
798 goto out_unregister;
799
800 if (platform_device_add(mac_mace_device)) {
801 platform_device_put(mac_mace_device);
802 mac_mace_device = NULL;
803 }
804
805 return 0;
806
807out_unregister:
808 platform_driver_unregister(&mac_mace_driver);
809
810 return -ENOMEM;
811} 791}
812 792
813static void __exit mac_mace_cleanup_module(void) 793static void __exit mac_mace_cleanup_module(void)
814{ 794{
815 platform_driver_unregister(&mac_mace_driver); 795 platform_driver_unregister(&mac_mace_driver);
816
817 if (mac_mace_device) {
818 platform_device_unregister(mac_mace_device);
819 mac_mace_device = NULL;
820 }
821} 796}
822 797
823module_init(mac_mace_init_module); 798module_init(mac_mace_init_module);
diff --git a/drivers/net/macsonic.c b/drivers/net/macsonic.c
index 875d361fb79d..24109c288108 100644
--- a/drivers/net/macsonic.c
+++ b/drivers/net/macsonic.c
@@ -62,7 +62,6 @@
62#include <asm/mac_via.h> 62#include <asm/mac_via.h>
63 63
64static char mac_sonic_string[] = "macsonic"; 64static char mac_sonic_string[] = "macsonic";
65static struct platform_device *mac_sonic_device;
66 65
67#include "sonic.h" 66#include "sonic.h"
68 67
@@ -607,6 +606,7 @@ out:
607MODULE_DESCRIPTION("Macintosh SONIC ethernet driver"); 606MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
608module_param(sonic_debug, int, 0); 607module_param(sonic_debug, int, 0);
609MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)"); 608MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)");
609MODULE_ALIAS("platform:macsonic");
610 610
611#include "sonic.c" 611#include "sonic.c"
612 612
@@ -627,44 +627,19 @@ static struct platform_driver mac_sonic_driver = {
627 .probe = mac_sonic_probe, 627 .probe = mac_sonic_probe,
628 .remove = __devexit_p(mac_sonic_device_remove), 628 .remove = __devexit_p(mac_sonic_device_remove),
629 .driver = { 629 .driver = {
630 .name = mac_sonic_string, 630 .name = mac_sonic_string,
631 .owner = THIS_MODULE,
631 }, 632 },
632}; 633};
633 634
634static int __init mac_sonic_init_module(void) 635static int __init mac_sonic_init_module(void)
635{ 636{
636 int err; 637 return platform_driver_register(&mac_sonic_driver);
637
638 if ((err = platform_driver_register(&mac_sonic_driver))) {
639 printk(KERN_ERR "Driver registration failed\n");
640 return err;
641 }
642
643 mac_sonic_device = platform_device_alloc(mac_sonic_string, 0);
644 if (!mac_sonic_device)
645 goto out_unregister;
646
647 if (platform_device_add(mac_sonic_device)) {
648 platform_device_put(mac_sonic_device);
649 mac_sonic_device = NULL;
650 }
651
652 return 0;
653
654out_unregister:
655 platform_driver_unregister(&mac_sonic_driver);
656
657 return -ENOMEM;
658} 638}
659 639
660static void __exit mac_sonic_cleanup_module(void) 640static void __exit mac_sonic_cleanup_module(void)
661{ 641{
662 platform_driver_unregister(&mac_sonic_driver); 642 platform_driver_unregister(&mac_sonic_driver);
663
664 if (mac_sonic_device) {
665 platform_device_unregister(mac_sonic_device);
666 mac_sonic_device = NULL;
667 }
668} 643}
669 644
670module_init(mac_sonic_init_module); 645module_init(mac_sonic_init_module);
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index d29c22a80a06..5adc662c4bfb 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -453,8 +453,7 @@ static int mhz_mfc_config(struct pcmcia_device *link)
453 453
454 link->conf.Attributes |= CONF_ENABLE_SPKR; 454 link->conf.Attributes |= CONF_ENABLE_SPKR;
455 link->conf.Status = CCSR_AUDIO_ENA; 455 link->conf.Status = CCSR_AUDIO_ENA;
456 link->irq.Attributes = 456 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
457 IRQ_TYPE_DYNAMIC_SHARING;
458 link->io.IOAddrLines = 16; 457 link->io.IOAddrLines = 16;
459 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 458 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
460 link->io.NumPorts2 = 8; 459 link->io.NumPorts2 = 8;
@@ -652,8 +651,7 @@ static int osi_config(struct pcmcia_device *link)
652 651
653 link->conf.Attributes |= CONF_ENABLE_SPKR; 652 link->conf.Attributes |= CONF_ENABLE_SPKR;
654 link->conf.Status = CCSR_AUDIO_ENA; 653 link->conf.Status = CCSR_AUDIO_ENA;
655 link->irq.Attributes = 654 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
656 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
657 link->io.NumPorts1 = 64; 655 link->io.NumPorts1 = 64;
658 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 656 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
659 link->io.NumPorts2 = 8; 657 link->io.NumPorts2 = 8;
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index d2fa27c5c1b2..7cecc8fea9bd 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -1,3 +1,11 @@
1config OF_FLATTREE
2 bool
3 depends on OF
4
5config OF_DYNAMIC
6 def_bool y
7 depends on OF && PPC_OF
8
1config OF_DEVICE 9config OF_DEVICE
2 def_bool y 10 def_bool y
3 depends on OF && (SPARC || PPC_OF || MICROBLAZE) 11 depends on OF && (SPARC || PPC_OF || MICROBLAZE)
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index bdfb5f5d4b06..f232cc98ce00 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,4 +1,5 @@
1obj-y = base.o 1obj-y = base.o
2obj-$(CONFIG_OF_FLATTREE) += fdt.o
2obj-$(CONFIG_OF_DEVICE) += device.o platform.o 3obj-$(CONFIG_OF_DEVICE) += device.o platform.o
3obj-$(CONFIG_OF_GPIO) += gpio.o 4obj-$(CONFIG_OF_GPIO) += gpio.o
4obj-$(CONFIG_OF_I2C) += of_i2c.o 5obj-$(CONFIG_OF_I2C) += of_i2c.o
diff --git a/drivers/of/base.c b/drivers/of/base.c
index e6627b2320f1..cb96888d1427 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -20,8 +20,10 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/of.h> 21#include <linux/of.h>
22#include <linux/spinlock.h> 22#include <linux/spinlock.h>
23#include <linux/proc_fs.h>
23 24
24struct device_node *allnodes; 25struct device_node *allnodes;
26struct device_node *of_chosen;
25 27
26/* use when traversing tree through the allnext, child, sibling, 28/* use when traversing tree through the allnext, child, sibling,
27 * or parent members of struct device_node. 29 * or parent members of struct device_node.
@@ -37,7 +39,7 @@ int of_n_addr_cells(struct device_node *np)
37 np = np->parent; 39 np = np->parent;
38 ip = of_get_property(np, "#address-cells", NULL); 40 ip = of_get_property(np, "#address-cells", NULL);
39 if (ip) 41 if (ip)
40 return *ip; 42 return be32_to_cpup(ip);
41 } while (np->parent); 43 } while (np->parent);
42 /* No #address-cells property for the root node */ 44 /* No #address-cells property for the root node */
43 return OF_ROOT_NODE_ADDR_CELLS_DEFAULT; 45 return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
@@ -53,13 +55,88 @@ int of_n_size_cells(struct device_node *np)
53 np = np->parent; 55 np = np->parent;
54 ip = of_get_property(np, "#size-cells", NULL); 56 ip = of_get_property(np, "#size-cells", NULL);
55 if (ip) 57 if (ip)
56 return *ip; 58 return be32_to_cpup(ip);
57 } while (np->parent); 59 } while (np->parent);
58 /* No #size-cells property for the root node */ 60 /* No #size-cells property for the root node */
59 return OF_ROOT_NODE_SIZE_CELLS_DEFAULT; 61 return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
60} 62}
61EXPORT_SYMBOL(of_n_size_cells); 63EXPORT_SYMBOL(of_n_size_cells);
62 64
65#if !defined(CONFIG_SPARC) /* SPARC doesn't do ref counting (yet) */
66/**
67 * of_node_get - Increment refcount of a node
68 * @node: Node to inc refcount, NULL is supported to
69 * simplify writing of callers
70 *
71 * Returns node.
72 */
73struct device_node *of_node_get(struct device_node *node)
74{
75 if (node)
76 kref_get(&node->kref);
77 return node;
78}
79EXPORT_SYMBOL(of_node_get);
80
81static inline struct device_node *kref_to_device_node(struct kref *kref)
82{
83 return container_of(kref, struct device_node, kref);
84}
85
86/**
87 * of_node_release - release a dynamically allocated node
88 * @kref: kref element of the node to be released
89 *
90 * In of_node_put() this function is passed to kref_put()
91 * as the destructor.
92 */
93static void of_node_release(struct kref *kref)
94{
95 struct device_node *node = kref_to_device_node(kref);
96 struct property *prop = node->properties;
97
98 /* We should never be releasing nodes that haven't been detached. */
99 if (!of_node_check_flag(node, OF_DETACHED)) {
100 pr_err("ERROR: Bad of_node_put() on %s\n", node->full_name);
101 dump_stack();
102 kref_init(&node->kref);
103 return;
104 }
105
106 if (!of_node_check_flag(node, OF_DYNAMIC))
107 return;
108
109 while (prop) {
110 struct property *next = prop->next;
111 kfree(prop->name);
112 kfree(prop->value);
113 kfree(prop);
114 prop = next;
115
116 if (!prop) {
117 prop = node->deadprops;
118 node->deadprops = NULL;
119 }
120 }
121 kfree(node->full_name);
122 kfree(node->data);
123 kfree(node);
124}
125
126/**
127 * of_node_put - Decrement refcount of a node
128 * @node: Node to dec refcount, NULL is supported to
129 * simplify writing of callers
130 *
131 */
132void of_node_put(struct device_node *node)
133{
134 if (node)
135 kref_put(&node->kref, of_node_release);
136}
137EXPORT_SYMBOL(of_node_put);
138#endif /* !CONFIG_SPARC */
139
63struct property *of_find_property(const struct device_node *np, 140struct property *of_find_property(const struct device_node *np,
64 const char *name, 141 const char *name,
65 int *lenp) 142 int *lenp)
@@ -144,6 +221,27 @@ int of_device_is_compatible(const struct device_node *device,
144EXPORT_SYMBOL(of_device_is_compatible); 221EXPORT_SYMBOL(of_device_is_compatible);
145 222
146/** 223/**
224 * of_machine_is_compatible - Test root of device tree for a given compatible value
225 * @compat: compatible string to look for in root node's compatible property.
226 *
227 * Returns true if the root node has the given value in its
228 * compatible property.
229 */
230int of_machine_is_compatible(const char *compat)
231{
232 struct device_node *root;
233 int rc = 0;
234
235 root = of_find_node_by_path("/");
236 if (root) {
237 rc = of_device_is_compatible(root, compat);
238 of_node_put(root);
239 }
240 return rc;
241}
242EXPORT_SYMBOL(of_machine_is_compatible);
243
244/**
147 * of_device_is_available - check if a device is available for use 245 * of_device_is_available - check if a device is available for use
148 * 246 *
149 * @device: Node to check for availability 247 * @device: Node to check for availability
@@ -519,6 +617,27 @@ int of_modalias_node(struct device_node *node, char *modalias, int len)
519EXPORT_SYMBOL_GPL(of_modalias_node); 617EXPORT_SYMBOL_GPL(of_modalias_node);
520 618
521/** 619/**
620 * of_find_node_by_phandle - Find a node given a phandle
621 * @handle: phandle of the node to find
622 *
623 * Returns a node pointer with refcount incremented, use
624 * of_node_put() on it when done.
625 */
626struct device_node *of_find_node_by_phandle(phandle handle)
627{
628 struct device_node *np;
629
630 read_lock(&devtree_lock);
631 for (np = allnodes; np; np = np->allnext)
632 if (np->phandle == handle)
633 break;
634 of_node_get(np);
635 read_unlock(&devtree_lock);
636 return np;
637}
638EXPORT_SYMBOL(of_find_node_by_phandle);
639
640/**
522 * of_parse_phandle - Resolve a phandle property to a device_node pointer 641 * of_parse_phandle - Resolve a phandle property to a device_node pointer
523 * @np: Pointer to device node holding phandle property 642 * @np: Pointer to device node holding phandle property
524 * @phandle_name: Name of property holding a phandle value 643 * @phandle_name: Name of property holding a phandle value
@@ -578,8 +697,8 @@ int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
578 const void **out_args) 697 const void **out_args)
579{ 698{
580 int ret = -EINVAL; 699 int ret = -EINVAL;
581 const u32 *list; 700 const __be32 *list;
582 const u32 *list_end; 701 const __be32 *list_end;
583 int size; 702 int size;
584 int cur_index = 0; 703 int cur_index = 0;
585 struct device_node *node = NULL; 704 struct device_node *node = NULL;
@@ -593,7 +712,7 @@ int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
593 list_end = list + size / sizeof(*list); 712 list_end = list + size / sizeof(*list);
594 713
595 while (list < list_end) { 714 while (list < list_end) {
596 const u32 *cells; 715 const __be32 *cells;
597 const phandle *phandle; 716 const phandle *phandle;
598 717
599 phandle = list++; 718 phandle = list++;
@@ -617,7 +736,7 @@ int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
617 goto err1; 736 goto err1;
618 } 737 }
619 738
620 list += *cells; 739 list += be32_to_cpup(cells);
621 if (list > list_end) { 740 if (list > list_end) {
622 pr_debug("%s: insufficient arguments length\n", 741 pr_debug("%s: insufficient arguments length\n",
623 np->full_name); 742 np->full_name);
@@ -658,3 +777,190 @@ err0:
658 return ret; 777 return ret;
659} 778}
660EXPORT_SYMBOL(of_parse_phandles_with_args); 779EXPORT_SYMBOL(of_parse_phandles_with_args);
780
781/**
782 * prom_add_property - Add a property to a node
783 */
784int prom_add_property(struct device_node *np, struct property *prop)
785{
786 struct property **next;
787 unsigned long flags;
788
789 prop->next = NULL;
790 write_lock_irqsave(&devtree_lock, flags);
791 next = &np->properties;
792 while (*next) {
793 if (strcmp(prop->name, (*next)->name) == 0) {
794 /* duplicate ! don't insert it */
795 write_unlock_irqrestore(&devtree_lock, flags);
796 return -1;
797 }
798 next = &(*next)->next;
799 }
800 *next = prop;
801 write_unlock_irqrestore(&devtree_lock, flags);
802
803#ifdef CONFIG_PROC_DEVICETREE
804 /* try to add to proc as well if it was initialized */
805 if (np->pde)
806 proc_device_tree_add_prop(np->pde, prop);
807#endif /* CONFIG_PROC_DEVICETREE */
808
809 return 0;
810}
811
812/**
813 * prom_remove_property - Remove a property from a node.
814 *
815 * Note that we don't actually remove it, since we have given out
816 * who-knows-how-many pointers to the data using get-property.
817 * Instead we just move the property to the "dead properties"
818 * list, so it won't be found any more.
819 */
820int prom_remove_property(struct device_node *np, struct property *prop)
821{
822 struct property **next;
823 unsigned long flags;
824 int found = 0;
825
826 write_lock_irqsave(&devtree_lock, flags);
827 next = &np->properties;
828 while (*next) {
829 if (*next == prop) {
830 /* found the node */
831 *next = prop->next;
832 prop->next = np->deadprops;
833 np->deadprops = prop;
834 found = 1;
835 break;
836 }
837 next = &(*next)->next;
838 }
839 write_unlock_irqrestore(&devtree_lock, flags);
840
841 if (!found)
842 return -ENODEV;
843
844#ifdef CONFIG_PROC_DEVICETREE
845 /* try to remove the proc node as well */
846 if (np->pde)
847 proc_device_tree_remove_prop(np->pde, prop);
848#endif /* CONFIG_PROC_DEVICETREE */
849
850 return 0;
851}
852
853/*
854 * prom_update_property - Update a property in a node.
855 *
856 * Note that we don't actually remove it, since we have given out
857 * who-knows-how-many pointers to the data using get-property.
858 * Instead we just move the property to the "dead properties" list,
859 * and add the new property to the property list
860 */
861int prom_update_property(struct device_node *np,
862 struct property *newprop,
863 struct property *oldprop)
864{
865 struct property **next;
866 unsigned long flags;
867 int found = 0;
868
869 write_lock_irqsave(&devtree_lock, flags);
870 next = &np->properties;
871 while (*next) {
872 if (*next == oldprop) {
873 /* found the node */
874 newprop->next = oldprop->next;
875 *next = newprop;
876 oldprop->next = np->deadprops;
877 np->deadprops = oldprop;
878 found = 1;
879 break;
880 }
881 next = &(*next)->next;
882 }
883 write_unlock_irqrestore(&devtree_lock, flags);
884
885 if (!found)
886 return -ENODEV;
887
888#ifdef CONFIG_PROC_DEVICETREE
889 /* try to add to proc as well if it was initialized */
890 if (np->pde)
891 proc_device_tree_update_prop(np->pde, newprop, oldprop);
892#endif /* CONFIG_PROC_DEVICETREE */
893
894 return 0;
895}
896
897#if defined(CONFIG_OF_DYNAMIC)
898/*
899 * Support for dynamic device trees.
900 *
901 * On some platforms, the device tree can be manipulated at runtime.
902 * The routines in this section support adding, removing and changing
903 * device tree nodes.
904 */
905
906/**
907 * of_attach_node - Plug a device node into the tree and global list.
908 */
909void of_attach_node(struct device_node *np)
910{
911 unsigned long flags;
912
913 write_lock_irqsave(&devtree_lock, flags);
914 np->sibling = np->parent->child;
915 np->allnext = allnodes;
916 np->parent->child = np;
917 allnodes = np;
918 write_unlock_irqrestore(&devtree_lock, flags);
919}
920
921/**
922 * of_detach_node - "Unplug" a node from the device tree.
923 *
924 * The caller must hold a reference to the node. The memory associated with
925 * the node is not freed until its refcount goes to zero.
926 */
927void of_detach_node(struct device_node *np)
928{
929 struct device_node *parent;
930 unsigned long flags;
931
932 write_lock_irqsave(&devtree_lock, flags);
933
934 parent = np->parent;
935 if (!parent)
936 goto out_unlock;
937
938 if (allnodes == np)
939 allnodes = np->allnext;
940 else {
941 struct device_node *prev;
942 for (prev = allnodes;
943 prev->allnext != np;
944 prev = prev->allnext)
945 ;
946 prev->allnext = np->allnext;
947 }
948
949 if (parent->child == np)
950 parent->child = np->sibling;
951 else {
952 struct device_node *prevsib;
953 for (prevsib = np->parent->child;
954 prevsib->sibling != np;
955 prevsib = prevsib->sibling)
956 ;
957 prevsib->sibling = np->sibling;
958 }
959
960 of_node_set_flag(np, OF_DETACHED);
961
962out_unlock:
963 write_unlock_irqrestore(&devtree_lock, flags);
964}
965#endif /* defined(CONFIG_OF_DYNAMIC) */
966
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
new file mode 100644
index 000000000000..406757a9d7ea
--- /dev/null
+++ b/drivers/of/fdt.c
@@ -0,0 +1,590 @@
1/*
2 * Functions for working with the Flattened Device Tree data format
3 *
4 * Copyright 2009 Benjamin Herrenschmidt, IBM Corp
5 * benh@kernel.crashing.org
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/initrd.h>
14#include <linux/of.h>
15#include <linux/of_fdt.h>
16#include <linux/string.h>
17#include <linux/errno.h>
18
19#ifdef CONFIG_PPC
20#include <asm/machdep.h>
21#endif /* CONFIG_PPC */
22
23#include <asm/page.h>
24
25int __initdata dt_root_addr_cells;
26int __initdata dt_root_size_cells;
27
28struct boot_param_header *initial_boot_params;
29
30char *find_flat_dt_string(u32 offset)
31{
32 return ((char *)initial_boot_params) +
33 be32_to_cpu(initial_boot_params->off_dt_strings) + offset;
34}
35
36/**
37 * of_scan_flat_dt - scan flattened tree blob and call callback on each.
38 * @it: callback function
39 * @data: context data pointer
40 *
41 * This function is used to scan the flattened device-tree, it is
42 * used to extract the memory information at boot before we can
43 * unflatten the tree
44 */
45int __init of_scan_flat_dt(int (*it)(unsigned long node,
46 const char *uname, int depth,
47 void *data),
48 void *data)
49{
50 unsigned long p = ((unsigned long)initial_boot_params) +
51 be32_to_cpu(initial_boot_params->off_dt_struct);
52 int rc = 0;
53 int depth = -1;
54
55 do {
56 u32 tag = be32_to_cpup((__be32 *)p);
57 char *pathp;
58
59 p += 4;
60 if (tag == OF_DT_END_NODE) {
61 depth--;
62 continue;
63 }
64 if (tag == OF_DT_NOP)
65 continue;
66 if (tag == OF_DT_END)
67 break;
68 if (tag == OF_DT_PROP) {
69 u32 sz = be32_to_cpup((__be32 *)p);
70 p += 8;
71 if (be32_to_cpu(initial_boot_params->version) < 0x10)
72 p = _ALIGN(p, sz >= 8 ? 8 : 4);
73 p += sz;
74 p = _ALIGN(p, 4);
75 continue;
76 }
77 if (tag != OF_DT_BEGIN_NODE) {
78 pr_err("Invalid tag %x in flat device tree!\n", tag);
79 return -EINVAL;
80 }
81 depth++;
82 pathp = (char *)p;
83 p = _ALIGN(p + strlen(pathp) + 1, 4);
84 if ((*pathp) == '/') {
85 char *lp, *np;
86 for (lp = NULL, np = pathp; *np; np++)
87 if ((*np) == '/')
88 lp = np+1;
89 if (lp != NULL)
90 pathp = lp;
91 }
92 rc = it(p, pathp, depth, data);
93 if (rc != 0)
94 break;
95 } while (1);
96
97 return rc;
98}
99
100/**
101 * of_get_flat_dt_root - find the root node in the flat blob
102 */
103unsigned long __init of_get_flat_dt_root(void)
104{
105 unsigned long p = ((unsigned long)initial_boot_params) +
106 be32_to_cpu(initial_boot_params->off_dt_struct);
107
108 while (be32_to_cpup((__be32 *)p) == OF_DT_NOP)
109 p += 4;
110 BUG_ON(be32_to_cpup((__be32 *)p) != OF_DT_BEGIN_NODE);
111 p += 4;
112 return _ALIGN(p + strlen((char *)p) + 1, 4);
113}
114
115/**
116 * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr
117 *
118 * This function can be used within scan_flattened_dt callback to get
119 * access to properties
120 */
121void *__init of_get_flat_dt_prop(unsigned long node, const char *name,
122 unsigned long *size)
123{
124 unsigned long p = node;
125
126 do {
127 u32 tag = be32_to_cpup((__be32 *)p);
128 u32 sz, noff;
129 const char *nstr;
130
131 p += 4;
132 if (tag == OF_DT_NOP)
133 continue;
134 if (tag != OF_DT_PROP)
135 return NULL;
136
137 sz = be32_to_cpup((__be32 *)p);
138 noff = be32_to_cpup((__be32 *)(p + 4));
139 p += 8;
140 if (be32_to_cpu(initial_boot_params->version) < 0x10)
141 p = _ALIGN(p, sz >= 8 ? 8 : 4);
142
143 nstr = find_flat_dt_string(noff);
144 if (nstr == NULL) {
145 pr_warning("Can't find property index name !\n");
146 return NULL;
147 }
148 if (strcmp(name, nstr) == 0) {
149 if (size)
150 *size = sz;
151 return (void *)p;
152 }
153 p += sz;
154 p = _ALIGN(p, 4);
155 } while (1);
156}
157
158/**
159 * of_flat_dt_is_compatible - Return true if given node has compat in compatible list
160 * @node: node to test
161 * @compat: compatible string to compare with compatible list.
162 */
163int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
164{
165 const char *cp;
166 unsigned long cplen, l;
167
168 cp = of_get_flat_dt_prop(node, "compatible", &cplen);
169 if (cp == NULL)
170 return 0;
171 while (cplen > 0) {
172 if (strncasecmp(cp, compat, strlen(compat)) == 0)
173 return 1;
174 l = strlen(cp) + 1;
175 cp += l;
176 cplen -= l;
177 }
178
179 return 0;
180}
181
182static void *__init unflatten_dt_alloc(unsigned long *mem, unsigned long size,
183 unsigned long align)
184{
185 void *res;
186
187 *mem = _ALIGN(*mem, align);
188 res = (void *)*mem;
189 *mem += size;
190
191 return res;
192}
193
194/**
195 * unflatten_dt_node - Alloc and populate a device_node from the flat tree
196 * @p: pointer to node in flat tree
197 * @dad: Parent struct device_node
198 * @allnextpp: pointer to ->allnext from last allocated device_node
199 * @fpsize: Size of the node path up at the current depth.
200 */
201unsigned long __init unflatten_dt_node(unsigned long mem,
202 unsigned long *p,
203 struct device_node *dad,
204 struct device_node ***allnextpp,
205 unsigned long fpsize)
206{
207 struct device_node *np;
208 struct property *pp, **prev_pp = NULL;
209 char *pathp;
210 u32 tag;
211 unsigned int l, allocl;
212 int has_name = 0;
213 int new_format = 0;
214
215 tag = be32_to_cpup((__be32 *)(*p));
216 if (tag != OF_DT_BEGIN_NODE) {
217 pr_err("Weird tag at start of node: %x\n", tag);
218 return mem;
219 }
220 *p += 4;
221 pathp = (char *)*p;
222 l = allocl = strlen(pathp) + 1;
223 *p = _ALIGN(*p + l, 4);
224
225 /* version 0x10 has a more compact unit name here instead of the full
226 * path. we accumulate the full path size using "fpsize", we'll rebuild
227 * it later. We detect this because the first character of the name is
228 * not '/'.
229 */
230 if ((*pathp) != '/') {
231 new_format = 1;
232 if (fpsize == 0) {
233 /* root node: special case. fpsize accounts for path
234 * plus terminating zero. root node only has '/', so
235 * fpsize should be 2, but we want to avoid the first
236 * level nodes to have two '/' so we use fpsize 1 here
237 */
238 fpsize = 1;
239 allocl = 2;
240 } else {
241 /* account for '/' and path size minus terminal 0
242 * already in 'l'
243 */
244 fpsize += l;
245 allocl = fpsize;
246 }
247 }
248
249 np = unflatten_dt_alloc(&mem, sizeof(struct device_node) + allocl,
250 __alignof__(struct device_node));
251 if (allnextpp) {
252 memset(np, 0, sizeof(*np));
253 np->full_name = ((char *)np) + sizeof(struct device_node);
254 if (new_format) {
255 char *fn = np->full_name;
256 /* rebuild full path for new format */
257 if (dad && dad->parent) {
258 strcpy(fn, dad->full_name);
259#ifdef DEBUG
260 if ((strlen(fn) + l + 1) != allocl) {
261 pr_debug("%s: p: %d, l: %d, a: %d\n",
262 pathp, (int)strlen(fn),
263 l, allocl);
264 }
265#endif
266 fn += strlen(fn);
267 }
268 *(fn++) = '/';
269 memcpy(fn, pathp, l);
270 } else
271 memcpy(np->full_name, pathp, l);
272 prev_pp = &np->properties;
273 **allnextpp = np;
274 *allnextpp = &np->allnext;
275 if (dad != NULL) {
276 np->parent = dad;
277 /* we temporarily use the next field as `last_child'*/
278 if (dad->next == NULL)
279 dad->child = np;
280 else
281 dad->next->sibling = np;
282 dad->next = np;
283 }
284 kref_init(&np->kref);
285 }
286 while (1) {
287 u32 sz, noff;
288 char *pname;
289
290 tag = be32_to_cpup((__be32 *)(*p));
291 if (tag == OF_DT_NOP) {
292 *p += 4;
293 continue;
294 }
295 if (tag != OF_DT_PROP)
296 break;
297 *p += 4;
298 sz = be32_to_cpup((__be32 *)(*p));
299 noff = be32_to_cpup((__be32 *)((*p) + 4));
300 *p += 8;
301 if (be32_to_cpu(initial_boot_params->version) < 0x10)
302 *p = _ALIGN(*p, sz >= 8 ? 8 : 4);
303
304 pname = find_flat_dt_string(noff);
305 if (pname == NULL) {
306 pr_info("Can't find property name in list !\n");
307 break;
308 }
309 if (strcmp(pname, "name") == 0)
310 has_name = 1;
311 l = strlen(pname) + 1;
312 pp = unflatten_dt_alloc(&mem, sizeof(struct property),
313 __alignof__(struct property));
314 if (allnextpp) {
315 /* We accept flattened tree phandles either in
316 * ePAPR-style "phandle" properties, or the
317 * legacy "linux,phandle" properties. If both
318 * appear and have different values, things
319 * will get weird. Don't do that. */
320 if ((strcmp(pname, "phandle") == 0) ||
321 (strcmp(pname, "linux,phandle") == 0)) {
322 if (np->phandle == 0)
323 np->phandle = *((u32 *)*p);
324 }
325 /* And we process the "ibm,phandle" property
326 * used in pSeries dynamic device tree
327 * stuff */
328 if (strcmp(pname, "ibm,phandle") == 0)
329 np->phandle = *((u32 *)*p);
330 pp->name = pname;
331 pp->length = sz;
332 pp->value = (void *)*p;
333 *prev_pp = pp;
334 prev_pp = &pp->next;
335 }
336 *p = _ALIGN((*p) + sz, 4);
337 }
338 /* with version 0x10 we may not have the name property, recreate
339 * it here from the unit name if absent
340 */
341 if (!has_name) {
342 char *p1 = pathp, *ps = pathp, *pa = NULL;
343 int sz;
344
345 while (*p1) {
346 if ((*p1) == '@')
347 pa = p1;
348 if ((*p1) == '/')
349 ps = p1 + 1;
350 p1++;
351 }
352 if (pa < ps)
353 pa = p1;
354 sz = (pa - ps) + 1;
355 pp = unflatten_dt_alloc(&mem, sizeof(struct property) + sz,
356 __alignof__(struct property));
357 if (allnextpp) {
358 pp->name = "name";
359 pp->length = sz;
360 pp->value = pp + 1;
361 *prev_pp = pp;
362 prev_pp = &pp->next;
363 memcpy(pp->value, ps, sz - 1);
364 ((char *)pp->value)[sz - 1] = 0;
365 pr_debug("fixed up name for %s -> %s\n", pathp,
366 (char *)pp->value);
367 }
368 }
369 if (allnextpp) {
370 *prev_pp = NULL;
371 np->name = of_get_property(np, "name", NULL);
372 np->type = of_get_property(np, "device_type", NULL);
373
374 if (!np->name)
375 np->name = "<NULL>";
376 if (!np->type)
377 np->type = "<NULL>";
378 }
379 while (tag == OF_DT_BEGIN_NODE) {
380 mem = unflatten_dt_node(mem, p, np, allnextpp, fpsize);
381 tag = be32_to_cpup((__be32 *)(*p));
382 }
383 if (tag != OF_DT_END_NODE) {
384 pr_err("Weird tag at end of node: %x\n", tag);
385 return mem;
386 }
387 *p += 4;
388 return mem;
389}
390
391#ifdef CONFIG_BLK_DEV_INITRD
392/**
393 * early_init_dt_check_for_initrd - Decode initrd location from flat tree
394 * @node: reference to node containing initrd location ('chosen')
395 */
396void __init early_init_dt_check_for_initrd(unsigned long node)
397{
398 unsigned long start, end, len;
399 __be32 *prop;
400
401 pr_debug("Looking for initrd properties... ");
402
403 prop = of_get_flat_dt_prop(node, "linux,initrd-start", &len);
404 if (!prop)
405 return;
406 start = of_read_ulong(prop, len/4);
407
408 prop = of_get_flat_dt_prop(node, "linux,initrd-end", &len);
409 if (!prop)
410 return;
411 end = of_read_ulong(prop, len/4);
412
413 early_init_dt_setup_initrd_arch(start, end);
414 pr_debug("initrd_start=0x%lx initrd_end=0x%lx\n", start, end);
415}
416#else
417inline void early_init_dt_check_for_initrd(unsigned long node)
418{
419}
420#endif /* CONFIG_BLK_DEV_INITRD */
421
422/**
423 * early_init_dt_scan_root - fetch the top level address and size cells
424 */
425int __init early_init_dt_scan_root(unsigned long node, const char *uname,
426 int depth, void *data)
427{
428 __be32 *prop;
429
430 if (depth != 0)
431 return 0;
432
433 dt_root_size_cells = OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
434 dt_root_addr_cells = OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
435
436 prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
437 if (prop)
438 dt_root_size_cells = be32_to_cpup(prop);
439 pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells);
440
441 prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
442 if (prop)
443 dt_root_addr_cells = be32_to_cpup(prop);
444 pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells);
445
446 /* break now */
447 return 1;
448}
449
450u64 __init dt_mem_next_cell(int s, __be32 **cellp)
451{
452 __be32 *p = *cellp;
453
454 *cellp = p + s;
455 return of_read_number(p, s);
456}
457
458/**
459 * early_init_dt_scan_memory - Look for an parse memory nodes
460 */
461int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
462 int depth, void *data)
463{
464 char *type = of_get_flat_dt_prop(node, "device_type", NULL);
465 __be32 *reg, *endp;
466 unsigned long l;
467
468 /* We are scanning "memory" nodes only */
469 if (type == NULL) {
470 /*
471 * The longtrail doesn't have a device_type on the
472 * /memory node, so look for the node called /memory@0.
473 */
474 if (depth != 1 || strcmp(uname, "memory@0") != 0)
475 return 0;
476 } else if (strcmp(type, "memory") != 0)
477 return 0;
478
479 reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
480 if (reg == NULL)
481 reg = of_get_flat_dt_prop(node, "reg", &l);
482 if (reg == NULL)
483 return 0;
484
485 endp = reg + (l / sizeof(__be32));
486
487 pr_debug("memory scan node %s, reg size %ld, data: %x %x %x %x,\n",
488 uname, l, reg[0], reg[1], reg[2], reg[3]);
489
490 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
491 u64 base, size;
492
493 base = dt_mem_next_cell(dt_root_addr_cells, &reg);
494 size = dt_mem_next_cell(dt_root_size_cells, &reg);
495
496 if (size == 0)
497 continue;
498 pr_debug(" - %llx , %llx\n", (unsigned long long)base,
499 (unsigned long long)size);
500
501 early_init_dt_add_memory_arch(base, size);
502 }
503
504 return 0;
505}
506
507int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
508 int depth, void *data)
509{
510 unsigned long l;
511 char *p;
512
513 pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
514
515 if (depth != 1 ||
516 (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
517 return 0;
518
519 early_init_dt_check_for_initrd(node);
520
521 /* Retreive command line */
522 p = of_get_flat_dt_prop(node, "bootargs", &l);
523 if (p != NULL && l > 0)
524 strlcpy(cmd_line, p, min((int)l, COMMAND_LINE_SIZE));
525
526#ifdef CONFIG_CMDLINE
527#ifndef CONFIG_CMDLINE_FORCE
528 if (p == NULL || l == 0 || (l == 1 && (*p) == 0))
529#endif
530 strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
531#endif /* CONFIG_CMDLINE */
532
533 early_init_dt_scan_chosen_arch(node);
534
535 pr_debug("Command line is: %s\n", cmd_line);
536
537 /* break now */
538 return 1;
539}
540
541/**
542 * unflatten_device_tree - create tree of device_nodes from flat blob
543 *
544 * unflattens the device-tree passed by the firmware, creating the
545 * tree of struct device_node. It also fills the "name" and "type"
546 * pointers of the nodes so the normal device-tree walking functions
547 * can be used.
548 */
549void __init unflatten_device_tree(void)
550{
551 unsigned long start, mem, size;
552 struct device_node **allnextp = &allnodes;
553
554 pr_debug(" -> unflatten_device_tree()\n");
555
556 /* First pass, scan for size */
557 start = ((unsigned long)initial_boot_params) +
558 be32_to_cpu(initial_boot_params->off_dt_struct);
559 size = unflatten_dt_node(0, &start, NULL, NULL, 0);
560 size = (size | 3) + 1;
561
562 pr_debug(" size is %lx, allocating...\n", size);
563
564 /* Allocate memory for the expanded device tree */
565 mem = early_init_dt_alloc_memory_arch(size + 4,
566 __alignof__(struct device_node));
567 mem = (unsigned long) __va(mem);
568
569 ((__be32 *)mem)[size / 4] = cpu_to_be32(0xdeadbeef);
570
571 pr_debug(" unflattening %lx...\n", mem);
572
573 /* Second pass, do actual unflattening */
574 start = ((unsigned long)initial_boot_params) +
575 be32_to_cpu(initial_boot_params->off_dt_struct);
576 unflatten_dt_node(mem, &start, NULL, &allnextp, 0);
577 if (be32_to_cpup((__be32 *)start) != OF_DT_END)
578 pr_warning("Weird tag at end of tree: %08x\n", *((u32 *)start));
579 if (be32_to_cpu(((__be32 *)mem)[size / 4]) != 0xdeadbeef)
580 pr_warning("End of tree marker overwritten: %08x\n",
581 be32_to_cpu(((__be32 *)mem)[size / 4]));
582 *allnextp = NULL;
583
584 /* Get pointer to OF "/chosen" node for use everywhere */
585 of_chosen = of_find_node_by_path("/chosen");
586 if (of_chosen == NULL)
587 of_chosen = of_find_node_by_path("/chosen@0");
588
589 pr_debug(" <- unflatten_device_tree()\n");
590}
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 6eea601a9204..24c3606217f8 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -36,7 +36,7 @@ int of_get_gpio_flags(struct device_node *np, int index,
36 struct of_gpio_chip *of_gc = NULL; 36 struct of_gpio_chip *of_gc = NULL;
37 int size; 37 int size;
38 const void *gpio_spec; 38 const void *gpio_spec;
39 const u32 *gpio_cells; 39 const __be32 *gpio_cells;
40 40
41 ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, 41 ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index,
42 &gc, &gpio_spec); 42 &gc, &gpio_spec);
@@ -55,7 +55,7 @@ int of_get_gpio_flags(struct device_node *np, int index,
55 55
56 gpio_cells = of_get_property(gc, "#gpio-cells", &size); 56 gpio_cells = of_get_property(gc, "#gpio-cells", &size);
57 if (!gpio_cells || size != sizeof(*gpio_cells) || 57 if (!gpio_cells || size != sizeof(*gpio_cells) ||
58 *gpio_cells != of_gc->gpio_cells) { 58 be32_to_cpup(gpio_cells) != of_gc->gpio_cells) {
59 pr_debug("%s: wrong #gpio-cells for %s\n", 59 pr_debug("%s: wrong #gpio-cells for %s\n",
60 np->full_name, gc->full_name); 60 np->full_name, gc->full_name);
61 ret = -EINVAL; 61 ret = -EINVAL;
@@ -127,7 +127,8 @@ EXPORT_SYMBOL(of_gpio_count);
127int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, 127int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
128 const void *gpio_spec, enum of_gpio_flags *flags) 128 const void *gpio_spec, enum of_gpio_flags *flags)
129{ 129{
130 const u32 *gpio = gpio_spec; 130 const __be32 *gpio = gpio_spec;
131 const u32 n = be32_to_cpup(gpio);
131 132
132 /* 133 /*
133 * We're discouraging gpio_cells < 2, since that way you'll have to 134 * We're discouraging gpio_cells < 2, since that way you'll have to
@@ -140,13 +141,13 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
140 return -EINVAL; 141 return -EINVAL;
141 } 142 }
142 143
143 if (*gpio > of_gc->gc.ngpio) 144 if (n > of_gc->gc.ngpio)
144 return -EINVAL; 145 return -EINVAL;
145 146
146 if (flags) 147 if (flags)
147 *flags = gpio[1]; 148 *flags = be32_to_cpu(gpio[1]);
148 149
149 return *gpio; 150 return n;
150} 151}
151EXPORT_SYMBOL(of_gpio_simple_xlate); 152EXPORT_SYMBOL(of_gpio_simple_xlate);
152 153
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index fa65a2b2ae2e..a3a708e590d0 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -25,7 +25,7 @@ void of_register_i2c_devices(struct i2c_adapter *adap,
25 for_each_child_of_node(adap_node, node) { 25 for_each_child_of_node(adap_node, node) {
26 struct i2c_board_info info = {}; 26 struct i2c_board_info info = {};
27 struct dev_archdata dev_ad = {}; 27 struct dev_archdata dev_ad = {};
28 const u32 *addr; 28 const __be32 *addr;
29 int len; 29 int len;
30 30
31 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) 31 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0)
@@ -40,7 +40,7 @@ void of_register_i2c_devices(struct i2c_adapter *adap,
40 40
41 info.irq = irq_of_parse_and_map(node, 0); 41 info.irq = irq_of_parse_and_map(node, 0);
42 42
43 info.addr = *addr; 43 info.addr = be32_to_cpup(addr);
44 44
45 dev_archdata_set_node(&dev_ad, node); 45 dev_archdata_set_node(&dev_ad, node);
46 info.archdata = &dev_ad; 46 info.archdata = &dev_ad;
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 4b22ba568b19..18ecae4a4375 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -51,7 +51,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
51 51
52 /* Loop over the child nodes and register a phy_device for each one */ 52 /* Loop over the child nodes and register a phy_device for each one */
53 for_each_child_of_node(np, child) { 53 for_each_child_of_node(np, child) {
54 const u32 *addr; 54 const __be32 *addr;
55 int len; 55 int len;
56 56
57 /* A PHY must have a reg property in the range [0-31] */ 57 /* A PHY must have a reg property in the range [0-31] */
@@ -68,7 +68,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
68 mdio->irq[*addr] = PHY_POLL; 68 mdio->irq[*addr] = PHY_POLL;
69 } 69 }
70 70
71 phy = get_phy_device(mdio, *addr); 71 phy = get_phy_device(mdio, be32_to_cpup(addr));
72 if (!phy) { 72 if (!phy) {
73 dev_err(&mdio->dev, "error probing PHY at address %i\n", 73 dev_err(&mdio->dev, "error probing PHY at address %i\n",
74 *addr); 74 *addr);
@@ -160,7 +160,7 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
160 struct device_node *net_np; 160 struct device_node *net_np;
161 char bus_id[MII_BUS_ID_SIZE + 3]; 161 char bus_id[MII_BUS_ID_SIZE + 3];
162 struct phy_device *phy; 162 struct phy_device *phy;
163 const u32 *phy_id; 163 const __be32 *phy_id;
164 int sz; 164 int sz;
165 165
166 if (!dev->dev.parent) 166 if (!dev->dev.parent)
@@ -174,7 +174,7 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
174 if (!phy_id || sz < sizeof(*phy_id)) 174 if (!phy_id || sz < sizeof(*phy_id))
175 return NULL; 175 return NULL;
176 176
177 sprintf(bus_id, PHY_ID_FMT, "0", phy_id[0]); 177 sprintf(bus_id, PHY_ID_FMT, "0", be32_to_cpu(phy_id[0]));
178 178
179 phy = phy_connect(dev, bus_id, hndlr, 0, iface); 179 phy = phy_connect(dev, bus_id, hndlr, 0, iface);
180 return IS_ERR(phy) ? NULL : phy; 180 return IS_ERR(phy) ? NULL : phy;
diff --git a/drivers/of/of_spi.c b/drivers/of/of_spi.c
index bed0ed6dcdc1..f65f48b98448 100644
--- a/drivers/of/of_spi.c
+++ b/drivers/of/of_spi.c
@@ -23,7 +23,7 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np)
23{ 23{
24 struct spi_device *spi; 24 struct spi_device *spi;
25 struct device_node *nc; 25 struct device_node *nc;
26 const u32 *prop; 26 const __be32 *prop;
27 int rc; 27 int rc;
28 int len; 28 int len;
29 29
@@ -54,7 +54,7 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np)
54 spi_dev_put(spi); 54 spi_dev_put(spi);
55 continue; 55 continue;
56 } 56 }
57 spi->chip_select = *prop; 57 spi->chip_select = be32_to_cpup(prop);
58 58
59 /* Mode (clock phase/polarity/etc.) */ 59 /* Mode (clock phase/polarity/etc.) */
60 if (of_find_property(nc, "spi-cpha", NULL)) 60 if (of_find_property(nc, "spi-cpha", NULL))
@@ -72,7 +72,7 @@ void of_register_spi_devices(struct spi_master *master, struct device_node *np)
72 spi_dev_put(spi); 72 spi_dev_put(spi);
73 continue; 73 continue;
74 } 74 }
75 spi->max_speed_hz = *prop; 75 spi->max_speed_hz = be32_to_cpup(prop);
76 76
77 /* IRQ */ 77 /* IRQ */
78 spi->irq = irq_of_parse_and_map(nc, 0); 78 spi->irq = irq_of_parse_and_map(nc, 0);
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index b1ecefa2a23d..7858a117e80b 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -21,17 +21,6 @@ config PCI_MSI
21 21
22 If you don't know what to do here, say N. 22 If you don't know what to do here, say N.
23 23
24config PCI_LEGACY
25 bool "Enable deprecated pci_find_* API"
26 depends on PCI
27 default y
28 help
29 Say Y here if you want to include support for the deprecated
30 pci_find_device() API. Most drivers have been converted over
31 to using the proper hotplug APIs, so this option serves to
32 include/exclude only a few drivers that are still using this
33 API.
34
35config PCI_DEBUG 24config PCI_DEBUG
36 bool "PCI Debugging" 25 bool "PCI Debugging"
37 depends on PCI && DEBUG_KERNEL 26 depends on PCI && DEBUG_KERNEL
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index b2f6d777a084..3d102dd87c9f 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -2,14 +2,13 @@
2# Makefile for the PCI bus specific drivers. 2# Makefile for the PCI bus specific drivers.
3# 3#
4 4
5obj-y += access.o bus.o probe.o remove.o pci.o quirks.o \ 5obj-y += access.o bus.o probe.o remove.o pci.o \
6 pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \ 6 pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \
7 irq.o vpd.o 7 irq.o vpd.o
8obj-$(CONFIG_PROC_FS) += proc.o 8obj-$(CONFIG_PROC_FS) += proc.o
9obj-$(CONFIG_SYSFS) += slot.o 9obj-$(CONFIG_SYSFS) += slot.o
10 10
11obj-$(CONFIG_PCI_LEGACY) += legacy.o 11obj-$(CONFIG_PCI_QUIRKS) += quirks.o
12CFLAGS_legacy.o += -Wno-deprecated-declarations
13 12
14# Build PCI Express stuff if needed 13# Build PCI Express stuff if needed
15obj-$(CONFIG_PCIEPORTBUS) += pcie/ 14obj-$(CONFIG_PCIEPORTBUS) += pcie/
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index cef28a79103f..712250f5874a 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -17,6 +17,52 @@
17 17
18#include "pci.h" 18#include "pci.h"
19 19
20void pci_bus_add_resource(struct pci_bus *bus, struct resource *res,
21 unsigned int flags)
22{
23 struct pci_bus_resource *bus_res;
24
25 bus_res = kzalloc(sizeof(struct pci_bus_resource), GFP_KERNEL);
26 if (!bus_res) {
27 dev_err(&bus->dev, "can't add %pR resource\n", res);
28 return;
29 }
30
31 bus_res->res = res;
32 bus_res->flags = flags;
33 list_add_tail(&bus_res->list, &bus->resources);
34}
35
36struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n)
37{
38 struct pci_bus_resource *bus_res;
39
40 if (n < PCI_BRIDGE_RESOURCE_NUM)
41 return bus->resource[n];
42
43 n -= PCI_BRIDGE_RESOURCE_NUM;
44 list_for_each_entry(bus_res, &bus->resources, list) {
45 if (n-- == 0)
46 return bus_res->res;
47 }
48 return NULL;
49}
50EXPORT_SYMBOL_GPL(pci_bus_resource_n);
51
52void pci_bus_remove_resources(struct pci_bus *bus)
53{
54 struct pci_bus_resource *bus_res, *tmp;
55 int i;
56
57 for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++)
58 bus->resource[i] = 0;
59
60 list_for_each_entry_safe(bus_res, tmp, &bus->resources, list) {
61 list_del(&bus_res->list);
62 kfree(bus_res);
63 }
64}
65
20/** 66/**
21 * pci_bus_alloc_resource - allocate a resource from a parent bus 67 * pci_bus_alloc_resource - allocate a resource from a parent bus
22 * @bus: PCI bus 68 * @bus: PCI bus
@@ -36,11 +82,14 @@ int
36pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, 82pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
37 resource_size_t size, resource_size_t align, 83 resource_size_t size, resource_size_t align,
38 resource_size_t min, unsigned int type_mask, 84 resource_size_t min, unsigned int type_mask,
39 void (*alignf)(void *, struct resource *, resource_size_t, 85 resource_size_t (*alignf)(void *,
40 resource_size_t), 86 const struct resource *,
87 resource_size_t,
88 resource_size_t),
41 void *alignf_data) 89 void *alignf_data)
42{ 90{
43 int i, ret = -ENOMEM; 91 int i, ret = -ENOMEM;
92 struct resource *r;
44 resource_size_t max = -1; 93 resource_size_t max = -1;
45 94
46 type_mask |= IORESOURCE_IO | IORESOURCE_MEM; 95 type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
@@ -49,8 +98,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
49 if (!(res->flags & IORESOURCE_MEM_64)) 98 if (!(res->flags & IORESOURCE_MEM_64))
50 max = PCIBIOS_MAX_MEM_32; 99 max = PCIBIOS_MAX_MEM_32;
51 100
52 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { 101 pci_bus_for_each_resource(bus, r, i) {
53 struct resource *r = bus->resource[i];
54 if (!r) 102 if (!r)
55 continue; 103 continue;
56 104
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index 4dd7114964ac..efa9f2de51c1 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -332,8 +332,6 @@ int acpiphp_register_hotplug_slot(struct acpiphp_slot *acpiphp_slot)
332 slot->hotplug_slot->info->attention_status = 0; 332 slot->hotplug_slot->info->attention_status = 0;
333 slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot); 333 slot->hotplug_slot->info->latch_status = acpiphp_get_latch_status(slot->acpi_slot);
334 slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot); 334 slot->hotplug_slot->info->adapter_status = acpiphp_get_adapter_status(slot->acpi_slot);
335 slot->hotplug_slot->info->max_bus_speed = PCI_SPEED_UNKNOWN;
336 slot->hotplug_slot->info->cur_bus_speed = PCI_SPEED_UNKNOWN;
337 335
338 acpiphp_slot->slot = slot; 336 acpiphp_slot->slot = slot;
339 snprintf(name, SLOT_NAME_SIZE, "%llu", slot->acpi_slot->sun); 337 snprintf(name, SLOT_NAME_SIZE, "%llu", slot->acpi_slot->sun);
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 8e952fdab764..cb2fd01eddae 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -720,12 +720,6 @@ static int acpiphp_bus_add(struct acpiphp_func *func)
720 -ret_val); 720 -ret_val);
721 goto acpiphp_bus_add_out; 721 goto acpiphp_bus_add_out;
722 } 722 }
723 /*
724 * try to start anyway. We could have failed to add
725 * simply because this bus had previously been added
726 * on another add. Don't bother with the return value
727 * we just keep going.
728 */
729 ret_val = acpi_bus_start(device); 723 ret_val = acpi_bus_start(device);
730 724
731acpiphp_bus_add_out: 725acpiphp_bus_add_out:
diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
index 148fb463b81c..fb3f84661bdc 100644
--- a/drivers/pci/hotplug/cpcihp_generic.c
+++ b/drivers/pci/hotplug/cpcihp_generic.c
@@ -162,6 +162,7 @@ static int __init cpcihp_generic_init(void)
162 dev = pci_get_slot(bus, PCI_DEVFN(bridge_slot, 0)); 162 dev = pci_get_slot(bus, PCI_DEVFN(bridge_slot, 0));
163 if(!dev || dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) { 163 if(!dev || dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
164 err("Invalid bridge device %s", bridge); 164 err("Invalid bridge device %s", bridge);
165 pci_dev_put(dev);
165 return -EINVAL; 166 return -EINVAL;
166 } 167 }
167 bus = dev->subordinate; 168 bus = dev->subordinate;
diff --git a/drivers/pci/hotplug/cpqphp.h b/drivers/pci/hotplug/cpqphp.h
index 9c6a9fd26812..d8ffc7366801 100644
--- a/drivers/pci/hotplug/cpqphp.h
+++ b/drivers/pci/hotplug/cpqphp.h
@@ -310,8 +310,6 @@ struct controller {
310 u8 first_slot; 310 u8 first_slot;
311 u8 add_support; 311 u8 add_support;
312 u8 push_flag; 312 u8 push_flag;
313 enum pci_bus_speed speed;
314 enum pci_bus_speed speed_capability;
315 u8 push_button; /* 0 = no pushbutton, 1 = pushbutton present */ 313 u8 push_button; /* 0 = no pushbutton, 1 = pushbutton present */
316 u8 slot_switch_type; /* 0 = no switch, 1 = switch present */ 314 u8 slot_switch_type; /* 0 = no switch, 1 = switch present */
317 u8 defeature_PHP; /* 0 = PHP not supported, 1 = PHP supported */ 315 u8 defeature_PHP; /* 0 = PHP not supported, 1 = PHP supported */
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index 075b4f4b6e0d..f184d1d2ecbe 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -583,30 +583,6 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
583 return 0; 583 return 0;
584} 584}
585 585
586static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
587{
588 struct slot *slot = hotplug_slot->private;
589 struct controller *ctrl = slot->ctrl;
590
591 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
592
593 *value = ctrl->speed_capability;
594
595 return 0;
596}
597
598static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
599{
600 struct slot *slot = hotplug_slot->private;
601 struct controller *ctrl = slot->ctrl;
602
603 dbg("%s - physical_slot = %s\n", __func__, slot_name(slot));
604
605 *value = ctrl->speed;
606
607 return 0;
608}
609
610static struct hotplug_slot_ops cpqphp_hotplug_slot_ops = { 586static struct hotplug_slot_ops cpqphp_hotplug_slot_ops = {
611 .set_attention_status = set_attention_status, 587 .set_attention_status = set_attention_status,
612 .enable_slot = process_SI, 588 .enable_slot = process_SI,
@@ -616,8 +592,6 @@ static struct hotplug_slot_ops cpqphp_hotplug_slot_ops = {
616 .get_attention_status = get_attention_status, 592 .get_attention_status = get_attention_status,
617 .get_latch_status = get_latch_status, 593 .get_latch_status = get_latch_status,
618 .get_adapter_status = get_adapter_status, 594 .get_adapter_status = get_adapter_status,
619 .get_max_bus_speed = get_max_bus_speed,
620 .get_cur_bus_speed = get_cur_bus_speed,
621}; 595};
622 596
623#define SLOT_NAME_SIZE 10 597#define SLOT_NAME_SIZE 10
@@ -629,6 +603,7 @@ static int ctrl_slot_setup(struct controller *ctrl,
629 struct slot *slot; 603 struct slot *slot;
630 struct hotplug_slot *hotplug_slot; 604 struct hotplug_slot *hotplug_slot;
631 struct hotplug_slot_info *hotplug_slot_info; 605 struct hotplug_slot_info *hotplug_slot_info;
606 struct pci_bus *bus = ctrl->pci_bus;
632 u8 number_of_slots; 607 u8 number_of_slots;
633 u8 slot_device; 608 u8 slot_device;
634 u8 slot_number; 609 u8 slot_number;
@@ -694,7 +669,7 @@ static int ctrl_slot_setup(struct controller *ctrl,
694 slot->capabilities |= PCISLOT_64_BIT_SUPPORTED; 669 slot->capabilities |= PCISLOT_64_BIT_SUPPORTED;
695 if (is_slot66mhz(slot)) 670 if (is_slot66mhz(slot))
696 slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED; 671 slot->capabilities |= PCISLOT_66_MHZ_SUPPORTED;
697 if (ctrl->speed == PCI_SPEED_66MHz) 672 if (bus->cur_bus_speed == PCI_SPEED_66MHz)
698 slot->capabilities |= PCISLOT_66_MHZ_OPERATION; 673 slot->capabilities |= PCISLOT_66_MHZ_OPERATION;
699 674
700 ctrl_slot = 675 ctrl_slot =
@@ -844,6 +819,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
844 u32 rc; 819 u32 rc;
845 struct controller *ctrl; 820 struct controller *ctrl;
846 struct pci_func *func; 821 struct pci_func *func;
822 struct pci_bus *bus;
847 int err; 823 int err;
848 824
849 err = pci_enable_device(pdev); 825 err = pci_enable_device(pdev);
@@ -852,6 +828,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
852 pci_name(pdev), err); 828 pci_name(pdev), err);
853 return err; 829 return err;
854 } 830 }
831 bus = pdev->subordinate;
855 832
856 /* Need to read VID early b/c it's used to differentiate CPQ and INTC 833 /* Need to read VID early b/c it's used to differentiate CPQ and INTC
857 * discovery 834 * discovery
@@ -929,22 +906,22 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
929 pci_read_config_byte(pdev, 0x41, &bus_cap); 906 pci_read_config_byte(pdev, 0x41, &bus_cap);
930 if (bus_cap & 0x80) { 907 if (bus_cap & 0x80) {
931 dbg("bus max supports 133MHz PCI-X\n"); 908 dbg("bus max supports 133MHz PCI-X\n");
932 ctrl->speed_capability = PCI_SPEED_133MHz_PCIX; 909 bus->max_bus_speed = PCI_SPEED_133MHz_PCIX;
933 break; 910 break;
934 } 911 }
935 if (bus_cap & 0x40) { 912 if (bus_cap & 0x40) {
936 dbg("bus max supports 100MHz PCI-X\n"); 913 dbg("bus max supports 100MHz PCI-X\n");
937 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX; 914 bus->max_bus_speed = PCI_SPEED_100MHz_PCIX;
938 break; 915 break;
939 } 916 }
940 if (bus_cap & 20) { 917 if (bus_cap & 20) {
941 dbg("bus max supports 66MHz PCI-X\n"); 918 dbg("bus max supports 66MHz PCI-X\n");
942 ctrl->speed_capability = PCI_SPEED_66MHz_PCIX; 919 bus->max_bus_speed = PCI_SPEED_66MHz_PCIX;
943 break; 920 break;
944 } 921 }
945 if (bus_cap & 10) { 922 if (bus_cap & 10) {
946 dbg("bus max supports 66MHz PCI\n"); 923 dbg("bus max supports 66MHz PCI\n");
947 ctrl->speed_capability = PCI_SPEED_66MHz; 924 bus->max_bus_speed = PCI_SPEED_66MHz;
948 break; 925 break;
949 } 926 }
950 927
@@ -955,7 +932,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
955 case PCI_SUB_HPC_ID: 932 case PCI_SUB_HPC_ID:
956 /* Original 6500/7000 implementation */ 933 /* Original 6500/7000 implementation */
957 ctrl->slot_switch_type = 1; 934 ctrl->slot_switch_type = 1;
958 ctrl->speed_capability = PCI_SPEED_33MHz; 935 bus->max_bus_speed = PCI_SPEED_33MHz;
959 ctrl->push_button = 0; 936 ctrl->push_button = 0;
960 ctrl->pci_config_space = 1; 937 ctrl->pci_config_space = 1;
961 ctrl->defeature_PHP = 1; 938 ctrl->defeature_PHP = 1;
@@ -966,7 +943,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
966 /* First Pushbutton implementation */ 943 /* First Pushbutton implementation */
967 ctrl->push_flag = 1; 944 ctrl->push_flag = 1;
968 ctrl->slot_switch_type = 1; 945 ctrl->slot_switch_type = 1;
969 ctrl->speed_capability = PCI_SPEED_33MHz; 946 bus->max_bus_speed = PCI_SPEED_33MHz;
970 ctrl->push_button = 1; 947 ctrl->push_button = 1;
971 ctrl->pci_config_space = 1; 948 ctrl->pci_config_space = 1;
972 ctrl->defeature_PHP = 1; 949 ctrl->defeature_PHP = 1;
@@ -976,7 +953,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
976 case PCI_SUB_HPC_ID_INTC: 953 case PCI_SUB_HPC_ID_INTC:
977 /* Third party (6500/7000) */ 954 /* Third party (6500/7000) */
978 ctrl->slot_switch_type = 1; 955 ctrl->slot_switch_type = 1;
979 ctrl->speed_capability = PCI_SPEED_33MHz; 956 bus->max_bus_speed = PCI_SPEED_33MHz;
980 ctrl->push_button = 0; 957 ctrl->push_button = 0;
981 ctrl->pci_config_space = 1; 958 ctrl->pci_config_space = 1;
982 ctrl->defeature_PHP = 1; 959 ctrl->defeature_PHP = 1;
@@ -987,7 +964,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
987 /* First 66 Mhz implementation */ 964 /* First 66 Mhz implementation */
988 ctrl->push_flag = 1; 965 ctrl->push_flag = 1;
989 ctrl->slot_switch_type = 1; 966 ctrl->slot_switch_type = 1;
990 ctrl->speed_capability = PCI_SPEED_66MHz; 967 bus->max_bus_speed = PCI_SPEED_66MHz;
991 ctrl->push_button = 1; 968 ctrl->push_button = 1;
992 ctrl->pci_config_space = 1; 969 ctrl->pci_config_space = 1;
993 ctrl->defeature_PHP = 1; 970 ctrl->defeature_PHP = 1;
@@ -998,7 +975,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
998 /* First PCI-X implementation, 100MHz */ 975 /* First PCI-X implementation, 100MHz */
999 ctrl->push_flag = 1; 976 ctrl->push_flag = 1;
1000 ctrl->slot_switch_type = 1; 977 ctrl->slot_switch_type = 1;
1001 ctrl->speed_capability = PCI_SPEED_100MHz_PCIX; 978 bus->max_bus_speed = PCI_SPEED_100MHz_PCIX;
1002 ctrl->push_button = 1; 979 ctrl->push_button = 1;
1003 ctrl->pci_config_space = 1; 980 ctrl->pci_config_space = 1;
1004 ctrl->defeature_PHP = 1; 981 ctrl->defeature_PHP = 1;
@@ -1015,9 +992,9 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1015 case PCI_VENDOR_ID_INTEL: 992 case PCI_VENDOR_ID_INTEL:
1016 /* Check for speed capability (0=33, 1=66) */ 993 /* Check for speed capability (0=33, 1=66) */
1017 if (subsystem_deviceid & 0x0001) 994 if (subsystem_deviceid & 0x0001)
1018 ctrl->speed_capability = PCI_SPEED_66MHz; 995 bus->max_bus_speed = PCI_SPEED_66MHz;
1019 else 996 else
1020 ctrl->speed_capability = PCI_SPEED_33MHz; 997 bus->max_bus_speed = PCI_SPEED_33MHz;
1021 998
1022 /* Check for push button */ 999 /* Check for push button */
1023 if (subsystem_deviceid & 0x0002) 1000 if (subsystem_deviceid & 0x0002)
@@ -1079,7 +1056,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1079 pdev->bus->number); 1056 pdev->bus->number);
1080 1057
1081 dbg("Hotplug controller capabilities:\n"); 1058 dbg("Hotplug controller capabilities:\n");
1082 dbg(" speed_capability %d\n", ctrl->speed_capability); 1059 dbg(" speed_capability %d\n", bus->max_bus_speed);
1083 dbg(" slot_switch_type %s\n", ctrl->slot_switch_type ? 1060 dbg(" slot_switch_type %s\n", ctrl->slot_switch_type ?
1084 "switch present" : "no switch"); 1061 "switch present" : "no switch");
1085 dbg(" defeature_PHP %s\n", ctrl->defeature_PHP ? 1062 dbg(" defeature_PHP %s\n", ctrl->defeature_PHP ?
@@ -1142,7 +1119,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1142 } 1119 }
1143 1120
1144 /* Check for 66Mhz operation */ 1121 /* Check for 66Mhz operation */
1145 ctrl->speed = get_controller_speed(ctrl); 1122 bus->cur_bus_speed = get_controller_speed(ctrl);
1146 1123
1147 1124
1148 /******************************************************** 1125 /********************************************************
diff --git a/drivers/pci/hotplug/cpqphp_ctrl.c b/drivers/pci/hotplug/cpqphp_ctrl.c
index 0ff689afa757..e43908d9b5df 100644
--- a/drivers/pci/hotplug/cpqphp_ctrl.c
+++ b/drivers/pci/hotplug/cpqphp_ctrl.c
@@ -1130,12 +1130,13 @@ static int is_bridge(struct pci_func * func)
1130static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_slot) 1130static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_slot)
1131{ 1131{
1132 struct slot *slot; 1132 struct slot *slot;
1133 struct pci_bus *bus = ctrl->pci_bus;
1133 u8 reg; 1134 u8 reg;
1134 u8 slot_power = readb(ctrl->hpc_reg + SLOT_POWER); 1135 u8 slot_power = readb(ctrl->hpc_reg + SLOT_POWER);
1135 u16 reg16; 1136 u16 reg16;
1136 u32 leds = readl(ctrl->hpc_reg + LED_CONTROL); 1137 u32 leds = readl(ctrl->hpc_reg + LED_CONTROL);
1137 1138
1138 if (ctrl->speed == adapter_speed) 1139 if (bus->cur_bus_speed == adapter_speed)
1139 return 0; 1140 return 0;
1140 1141
1141 /* We don't allow freq/mode changes if we find another adapter running 1142 /* We don't allow freq/mode changes if we find another adapter running
@@ -1152,7 +1153,7 @@ static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_
1152 * lower speed/mode, we allow the new adapter to function at 1153 * lower speed/mode, we allow the new adapter to function at
1153 * this rate if supported 1154 * this rate if supported
1154 */ 1155 */
1155 if (ctrl->speed < adapter_speed) 1156 if (bus->cur_bus_speed < adapter_speed)
1156 return 0; 1157 return 0;
1157 1158
1158 return 1; 1159 return 1;
@@ -1161,20 +1162,20 @@ static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_
1161 /* If the controller doesn't support freq/mode changes and the 1162 /* If the controller doesn't support freq/mode changes and the
1162 * controller is running at a higher mode, we bail 1163 * controller is running at a higher mode, we bail
1163 */ 1164 */
1164 if ((ctrl->speed > adapter_speed) && (!ctrl->pcix_speed_capability)) 1165 if ((bus->cur_bus_speed > adapter_speed) && (!ctrl->pcix_speed_capability))
1165 return 1; 1166 return 1;
1166 1167
1167 /* But we allow the adapter to run at a lower rate if possible */ 1168 /* But we allow the adapter to run at a lower rate if possible */
1168 if ((ctrl->speed < adapter_speed) && (!ctrl->pcix_speed_capability)) 1169 if ((bus->cur_bus_speed < adapter_speed) && (!ctrl->pcix_speed_capability))
1169 return 0; 1170 return 0;
1170 1171
1171 /* We try to set the max speed supported by both the adapter and 1172 /* We try to set the max speed supported by both the adapter and
1172 * controller 1173 * controller
1173 */ 1174 */
1174 if (ctrl->speed_capability < adapter_speed) { 1175 if (bus->max_bus_speed < adapter_speed) {
1175 if (ctrl->speed == ctrl->speed_capability) 1176 if (bus->cur_bus_speed == bus->max_bus_speed)
1176 return 0; 1177 return 0;
1177 adapter_speed = ctrl->speed_capability; 1178 adapter_speed = bus->max_bus_speed;
1178 } 1179 }
1179 1180
1180 writel(0x0L, ctrl->hpc_reg + LED_CONTROL); 1181 writel(0x0L, ctrl->hpc_reg + LED_CONTROL);
@@ -1229,8 +1230,8 @@ static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_
1229 pci_write_config_byte(ctrl->pci_dev, 0x43, reg); 1230 pci_write_config_byte(ctrl->pci_dev, 0x43, reg);
1230 1231
1231 /* Only if mode change...*/ 1232 /* Only if mode change...*/
1232 if (((ctrl->speed == PCI_SPEED_66MHz) && (adapter_speed == PCI_SPEED_66MHz_PCIX)) || 1233 if (((bus->cur_bus_speed == PCI_SPEED_66MHz) && (adapter_speed == PCI_SPEED_66MHz_PCIX)) ||
1233 ((ctrl->speed == PCI_SPEED_66MHz_PCIX) && (adapter_speed == PCI_SPEED_66MHz))) 1234 ((bus->cur_bus_speed == PCI_SPEED_66MHz_PCIX) && (adapter_speed == PCI_SPEED_66MHz)))
1234 set_SOGO(ctrl); 1235 set_SOGO(ctrl);
1235 1236
1236 wait_for_ctrl_irq(ctrl); 1237 wait_for_ctrl_irq(ctrl);
@@ -1243,7 +1244,7 @@ static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_
1243 set_SOGO(ctrl); 1244 set_SOGO(ctrl);
1244 wait_for_ctrl_irq(ctrl); 1245 wait_for_ctrl_irq(ctrl);
1245 1246
1246 ctrl->speed = adapter_speed; 1247 bus->cur_bus_speed = adapter_speed;
1247 slot = cpqhp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); 1248 slot = cpqhp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset);
1248 1249
1249 info("Successfully changed frequency/mode for adapter in slot %d\n", 1250 info("Successfully changed frequency/mode for adapter in slot %d\n",
@@ -1269,6 +1270,7 @@ static u8 set_controller_speed(struct controller *ctrl, u8 adapter_speed, u8 hp_
1269 */ 1270 */
1270static u32 board_replaced(struct pci_func *func, struct controller *ctrl) 1271static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1271{ 1272{
1273 struct pci_bus *bus = ctrl->pci_bus;
1272 u8 hp_slot; 1274 u8 hp_slot;
1273 u8 temp_byte; 1275 u8 temp_byte;
1274 u8 adapter_speed; 1276 u8 adapter_speed;
@@ -1309,7 +1311,7 @@ static u32 board_replaced(struct pci_func *func, struct controller *ctrl)
1309 wait_for_ctrl_irq (ctrl); 1311 wait_for_ctrl_irq (ctrl);
1310 1312
1311 adapter_speed = get_adapter_speed(ctrl, hp_slot); 1313 adapter_speed = get_adapter_speed(ctrl, hp_slot);
1312 if (ctrl->speed != adapter_speed) 1314 if (bus->cur_bus_speed != adapter_speed)
1313 if (set_controller_speed(ctrl, adapter_speed, hp_slot)) 1315 if (set_controller_speed(ctrl, adapter_speed, hp_slot))
1314 rc = WRONG_BUS_FREQUENCY; 1316 rc = WRONG_BUS_FREQUENCY;
1315 1317
@@ -1426,6 +1428,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1426 u32 temp_register = 0xFFFFFFFF; 1428 u32 temp_register = 0xFFFFFFFF;
1427 u32 rc = 0; 1429 u32 rc = 0;
1428 struct pci_func *new_slot = NULL; 1430 struct pci_func *new_slot = NULL;
1431 struct pci_bus *bus = ctrl->pci_bus;
1429 struct slot *p_slot; 1432 struct slot *p_slot;
1430 struct resource_lists res_lists; 1433 struct resource_lists res_lists;
1431 1434
@@ -1456,7 +1459,7 @@ static u32 board_added(struct pci_func *func, struct controller *ctrl)
1456 wait_for_ctrl_irq (ctrl); 1459 wait_for_ctrl_irq (ctrl);
1457 1460
1458 adapter_speed = get_adapter_speed(ctrl, hp_slot); 1461 adapter_speed = get_adapter_speed(ctrl, hp_slot);
1459 if (ctrl->speed != adapter_speed) 1462 if (bus->cur_bus_speed != adapter_speed)
1460 if (set_controller_speed(ctrl, adapter_speed, hp_slot)) 1463 if (set_controller_speed(ctrl, adapter_speed, hp_slot))
1461 rc = WRONG_BUS_FREQUENCY; 1464 rc = WRONG_BUS_FREQUENCY;
1462 1465
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index 7485ffda950c..d934dd4fa873 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -395,89 +395,40 @@ static int get_adapter_present(struct hotplug_slot *hotplug_slot, u8 * value)
395 return rc; 395 return rc;
396} 396}
397 397
398static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 398static int get_max_bus_speed(struct slot *slot)
399{ 399{
400 int rc = -ENODEV; 400 int rc;
401 struct slot *pslot;
402 u8 mode = 0; 401 u8 mode = 0;
402 enum pci_bus_speed speed;
403 struct pci_bus *bus = slot->hotplug_slot->pci_slot->bus;
403 404
404 debug("%s - Entry hotplug_slot[%p] pvalue[%p]\n", __func__, 405 debug("%s - Entry slot[%p]\n", __func__, slot);
405 hotplug_slot, value);
406 406
407 ibmphp_lock_operations(); 407 ibmphp_lock_operations();
408 408 mode = slot->supported_bus_mode;
409 if (hotplug_slot) { 409 speed = slot->supported_speed;
410 pslot = hotplug_slot->private;
411 if (pslot) {
412 rc = 0;
413 mode = pslot->supported_bus_mode;
414 *value = pslot->supported_speed;
415 switch (*value) {
416 case BUS_SPEED_33:
417 break;
418 case BUS_SPEED_66:
419 if (mode == BUS_MODE_PCIX)
420 *value += 0x01;
421 break;
422 case BUS_SPEED_100:
423 case BUS_SPEED_133:
424 *value = pslot->supported_speed + 0x01;
425 break;
426 default:
427 /* Note (will need to change): there would be soon 256, 512 also */
428 rc = -ENODEV;
429 }
430 }
431 }
432
433 ibmphp_unlock_operations(); 410 ibmphp_unlock_operations();
434 debug("%s - Exit rc[%d] value[%x]\n", __func__, rc, *value);
435 return rc;
436}
437 411
438static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 412 switch (speed) {
439{ 413 case BUS_SPEED_33:
440 int rc = -ENODEV; 414 break;
441 struct slot *pslot; 415 case BUS_SPEED_66:
442 u8 mode = 0; 416 if (mode == BUS_MODE_PCIX)
443 417 speed += 0x01;
444 debug("%s - Entry hotplug_slot[%p] pvalue[%p]\n", __func__, 418 break;
445 hotplug_slot, value); 419 case BUS_SPEED_100:
446 420 case BUS_SPEED_133:
447 ibmphp_lock_operations(); 421 speed += 0x01;
448 422 break;
449 if (hotplug_slot) { 423 default:
450 pslot = hotplug_slot->private; 424 /* Note (will need to change): there would be soon 256, 512 also */
451 if (pslot) { 425 rc = -ENODEV;
452 rc = get_cur_bus_info(&pslot);
453 if (!rc) {
454 mode = pslot->bus_on->current_bus_mode;
455 *value = pslot->bus_on->current_speed;
456 switch (*value) {
457 case BUS_SPEED_33:
458 break;
459 case BUS_SPEED_66:
460 if (mode == BUS_MODE_PCIX)
461 *value += 0x01;
462 else if (mode == BUS_MODE_PCI)
463 ;
464 else
465 *value = PCI_SPEED_UNKNOWN;
466 break;
467 case BUS_SPEED_100:
468 case BUS_SPEED_133:
469 *value += 0x01;
470 break;
471 default:
472 /* Note of change: there would also be 256, 512 soon */
473 rc = -ENODEV;
474 }
475 }
476 }
477 } 426 }
478 427
479 ibmphp_unlock_operations(); 428 if (!rc)
480 debug("%s - Exit rc[%d] value[%x]\n", __func__, rc, *value); 429 bus->max_bus_speed = speed;
430
431 debug("%s - Exit rc[%d] speed[%x]\n", __func__, rc, speed);
481 return rc; 432 return rc;
482} 433}
483 434
@@ -572,6 +523,7 @@ static int __init init_ops(void)
572 if (slot_cur->bus_on->current_speed == 0xFF) 523 if (slot_cur->bus_on->current_speed == 0xFF)
573 if (get_cur_bus_info(&slot_cur)) 524 if (get_cur_bus_info(&slot_cur))
574 return -1; 525 return -1;
526 get_max_bus_speed(slot_cur);
575 527
576 if (slot_cur->ctrl->options == 0xFF) 528 if (slot_cur->ctrl->options == 0xFF)
577 if (get_hpc_options(slot_cur, &slot_cur->ctrl->options)) 529 if (get_hpc_options(slot_cur, &slot_cur->ctrl->options))
@@ -655,6 +607,7 @@ static int validate(struct slot *slot_cur, int opn)
655int ibmphp_update_slot_info(struct slot *slot_cur) 607int ibmphp_update_slot_info(struct slot *slot_cur)
656{ 608{
657 struct hotplug_slot_info *info; 609 struct hotplug_slot_info *info;
610 struct pci_bus *bus = slot_cur->hotplug_slot->pci_slot->bus;
658 int rc; 611 int rc;
659 u8 bus_speed; 612 u8 bus_speed;
660 u8 mode; 613 u8 mode;
@@ -700,8 +653,7 @@ int ibmphp_update_slot_info(struct slot *slot_cur)
700 bus_speed = PCI_SPEED_UNKNOWN; 653 bus_speed = PCI_SPEED_UNKNOWN;
701 } 654 }
702 655
703 info->cur_bus_speed = bus_speed; 656 bus->cur_bus_speed = bus_speed;
704 info->max_bus_speed = slot_cur->hotplug_slot->info->max_bus_speed;
705 // To do: bus_names 657 // To do: bus_names
706 658
707 rc = pci_hp_change_slot_info(slot_cur->hotplug_slot, info); 659 rc = pci_hp_change_slot_info(slot_cur->hotplug_slot, info);
@@ -1326,8 +1278,6 @@ struct hotplug_slot_ops ibmphp_hotplug_slot_ops = {
1326 .get_attention_status = get_attention_status, 1278 .get_attention_status = get_attention_status,
1327 .get_latch_status = get_latch_status, 1279 .get_latch_status = get_latch_status,
1328 .get_adapter_status = get_adapter_present, 1280 .get_adapter_status = get_adapter_present,
1329 .get_max_bus_speed = get_max_bus_speed,
1330 .get_cur_bus_speed = get_cur_bus_speed,
1331/* .get_max_adapter_speed = get_max_adapter_speed, 1281/* .get_max_adapter_speed = get_max_adapter_speed,
1332 .get_bus_name_status = get_bus_name, 1282 .get_bus_name_status = get_bus_name,
1333*/ 1283*/
diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c
index c1abac8ab5c3..5becbdee4027 100644
--- a/drivers/pci/hotplug/ibmphp_ebda.c
+++ b/drivers/pci/hotplug/ibmphp_ebda.c
@@ -245,7 +245,7 @@ static void __init print_ebda_hpc (void)
245 245
246int __init ibmphp_access_ebda (void) 246int __init ibmphp_access_ebda (void)
247{ 247{
248 u8 format, num_ctlrs, rio_complete, hs_complete; 248 u8 format, num_ctlrs, rio_complete, hs_complete, ebda_sz;
249 u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base; 249 u16 ebda_seg, num_entries, next_offset, offset, blk_id, sub_addr, re, rc_id, re_id, base;
250 int rc = 0; 250 int rc = 0;
251 251
@@ -260,7 +260,16 @@ int __init ibmphp_access_ebda (void)
260 iounmap (io_mem); 260 iounmap (io_mem);
261 debug ("returned ebda segment: %x\n", ebda_seg); 261 debug ("returned ebda segment: %x\n", ebda_seg);
262 262
263 io_mem = ioremap(ebda_seg<<4, 1024); 263 io_mem = ioremap(ebda_seg<<4, 1);
264 if (!io_mem)
265 return -ENOMEM;
266 ebda_sz = readb(io_mem);
267 iounmap(io_mem);
268 debug("ebda size: %d(KiB)\n", ebda_sz);
269 if (ebda_sz == 0)
270 return -ENOMEM;
271
272 io_mem = ioremap(ebda_seg<<4, (ebda_sz * 1024));
264 if (!io_mem ) 273 if (!io_mem )
265 return -ENOMEM; 274 return -ENOMEM;
266 next_offset = 0x180; 275 next_offset = 0x180;
diff --git a/drivers/pci/hotplug/ibmphp_hpc.c b/drivers/pci/hotplug/ibmphp_hpc.c
index c7084f0eca5a..1aaf3f32d3cd 100644
--- a/drivers/pci/hotplug/ibmphp_hpc.c
+++ b/drivers/pci/hotplug/ibmphp_hpc.c
@@ -35,6 +35,7 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/semaphore.h>
38#include <linux/kthread.h> 39#include <linux/kthread.h>
39#include "ibmphp.h" 40#include "ibmphp.h"
40 41
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 38183a534b65..728b119f71ad 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -64,32 +64,6 @@ static int debug;
64static LIST_HEAD(pci_hotplug_slot_list); 64static LIST_HEAD(pci_hotplug_slot_list);
65static DEFINE_MUTEX(pci_hp_mutex); 65static DEFINE_MUTEX(pci_hp_mutex);
66 66
67/* these strings match up with the values in pci_bus_speed */
68static char *pci_bus_speed_strings[] = {
69 "33 MHz PCI", /* 0x00 */
70 "66 MHz PCI", /* 0x01 */
71 "66 MHz PCI-X", /* 0x02 */
72 "100 MHz PCI-X", /* 0x03 */
73 "133 MHz PCI-X", /* 0x04 */
74 NULL, /* 0x05 */
75 NULL, /* 0x06 */
76 NULL, /* 0x07 */
77 NULL, /* 0x08 */
78 "66 MHz PCI-X 266", /* 0x09 */
79 "100 MHz PCI-X 266", /* 0x0a */
80 "133 MHz PCI-X 266", /* 0x0b */
81 NULL, /* 0x0c */
82 NULL, /* 0x0d */
83 NULL, /* 0x0e */
84 NULL, /* 0x0f */
85 NULL, /* 0x10 */
86 "66 MHz PCI-X 533", /* 0x11 */
87 "100 MHz PCI-X 533", /* 0x12 */
88 "133 MHz PCI-X 533", /* 0x13 */
89 "2.5 GT/s PCIe", /* 0x14 */
90 "5.0 GT/s PCIe", /* 0x15 */
91};
92
93#ifdef CONFIG_HOTPLUG_PCI_CPCI 67#ifdef CONFIG_HOTPLUG_PCI_CPCI
94extern int cpci_hotplug_init(int debug); 68extern int cpci_hotplug_init(int debug);
95extern void cpci_hotplug_exit(void); 69extern void cpci_hotplug_exit(void);
@@ -118,8 +92,6 @@ GET_STATUS(power_status, u8)
118GET_STATUS(attention_status, u8) 92GET_STATUS(attention_status, u8)
119GET_STATUS(latch_status, u8) 93GET_STATUS(latch_status, u8)
120GET_STATUS(adapter_status, u8) 94GET_STATUS(adapter_status, u8)
121GET_STATUS(max_bus_speed, enum pci_bus_speed)
122GET_STATUS(cur_bus_speed, enum pci_bus_speed)
123 95
124static ssize_t power_read_file(struct pci_slot *slot, char *buf) 96static ssize_t power_read_file(struct pci_slot *slot, char *buf)
125{ 97{
@@ -263,60 +235,6 @@ static struct pci_slot_attribute hotplug_slot_attr_presence = {
263 .show = presence_read_file, 235 .show = presence_read_file,
264}; 236};
265 237
266static char *unknown_speed = "Unknown bus speed";
267
268static ssize_t max_bus_speed_read_file(struct pci_slot *slot, char *buf)
269{
270 char *speed_string;
271 int retval;
272 enum pci_bus_speed value;
273
274 retval = get_max_bus_speed(slot->hotplug, &value);
275 if (retval)
276 goto exit;
277
278 if (value == PCI_SPEED_UNKNOWN)
279 speed_string = unknown_speed;
280 else
281 speed_string = pci_bus_speed_strings[value];
282
283 retval = sprintf (buf, "%s\n", speed_string);
284
285exit:
286 return retval;
287}
288
289static struct pci_slot_attribute hotplug_slot_attr_max_bus_speed = {
290 .attr = {.name = "max_bus_speed", .mode = S_IFREG | S_IRUGO},
291 .show = max_bus_speed_read_file,
292};
293
294static ssize_t cur_bus_speed_read_file(struct pci_slot *slot, char *buf)
295{
296 char *speed_string;
297 int retval;
298 enum pci_bus_speed value;
299
300 retval = get_cur_bus_speed(slot->hotplug, &value);
301 if (retval)
302 goto exit;
303
304 if (value == PCI_SPEED_UNKNOWN)
305 speed_string = unknown_speed;
306 else
307 speed_string = pci_bus_speed_strings[value];
308
309 retval = sprintf (buf, "%s\n", speed_string);
310
311exit:
312 return retval;
313}
314
315static struct pci_slot_attribute hotplug_slot_attr_cur_bus_speed = {
316 .attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO},
317 .show = cur_bus_speed_read_file,
318};
319
320static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf, 238static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf,
321 size_t count) 239 size_t count)
322{ 240{
@@ -391,26 +309,6 @@ static bool has_adapter_file(struct pci_slot *pci_slot)
391 return false; 309 return false;
392} 310}
393 311
394static bool has_max_bus_speed_file(struct pci_slot *pci_slot)
395{
396 struct hotplug_slot *slot = pci_slot->hotplug;
397 if ((!slot) || (!slot->ops))
398 return false;
399 if (slot->ops->get_max_bus_speed)
400 return true;
401 return false;
402}
403
404static bool has_cur_bus_speed_file(struct pci_slot *pci_slot)
405{
406 struct hotplug_slot *slot = pci_slot->hotplug;
407 if ((!slot) || (!slot->ops))
408 return false;
409 if (slot->ops->get_cur_bus_speed)
410 return true;
411 return false;
412}
413
414static bool has_test_file(struct pci_slot *pci_slot) 312static bool has_test_file(struct pci_slot *pci_slot)
415{ 313{
416 struct hotplug_slot *slot = pci_slot->hotplug; 314 struct hotplug_slot *slot = pci_slot->hotplug;
@@ -456,20 +354,6 @@ static int fs_add_slot(struct pci_slot *slot)
456 goto exit_adapter; 354 goto exit_adapter;
457 } 355 }
458 356
459 if (has_max_bus_speed_file(slot)) {
460 retval = sysfs_create_file(&slot->kobj,
461 &hotplug_slot_attr_max_bus_speed.attr);
462 if (retval)
463 goto exit_max_speed;
464 }
465
466 if (has_cur_bus_speed_file(slot)) {
467 retval = sysfs_create_file(&slot->kobj,
468 &hotplug_slot_attr_cur_bus_speed.attr);
469 if (retval)
470 goto exit_cur_speed;
471 }
472
473 if (has_test_file(slot)) { 357 if (has_test_file(slot)) {
474 retval = sysfs_create_file(&slot->kobj, 358 retval = sysfs_create_file(&slot->kobj,
475 &hotplug_slot_attr_test.attr); 359 &hotplug_slot_attr_test.attr);
@@ -480,14 +364,6 @@ static int fs_add_slot(struct pci_slot *slot)
480 goto exit; 364 goto exit;
481 365
482exit_test: 366exit_test:
483 if (has_cur_bus_speed_file(slot))
484 sysfs_remove_file(&slot->kobj,
485 &hotplug_slot_attr_cur_bus_speed.attr);
486exit_cur_speed:
487 if (has_max_bus_speed_file(slot))
488 sysfs_remove_file(&slot->kobj,
489 &hotplug_slot_attr_max_bus_speed.attr);
490exit_max_speed:
491 if (has_adapter_file(slot)) 367 if (has_adapter_file(slot))
492 sysfs_remove_file(&slot->kobj, 368 sysfs_remove_file(&slot->kobj,
493 &hotplug_slot_attr_presence.attr); 369 &hotplug_slot_attr_presence.attr);
@@ -523,14 +399,6 @@ static void fs_remove_slot(struct pci_slot *slot)
523 sysfs_remove_file(&slot->kobj, 399 sysfs_remove_file(&slot->kobj,
524 &hotplug_slot_attr_presence.attr); 400 &hotplug_slot_attr_presence.attr);
525 401
526 if (has_max_bus_speed_file(slot))
527 sysfs_remove_file(&slot->kobj,
528 &hotplug_slot_attr_max_bus_speed.attr);
529
530 if (has_cur_bus_speed_file(slot))
531 sysfs_remove_file(&slot->kobj,
532 &hotplug_slot_attr_cur_bus_speed.attr);
533
534 if (has_test_file(slot)) 402 if (has_test_file(slot))
535 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_test.attr); 403 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_test.attr);
536 404
diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
index 5674b2075bdc..920f820edf87 100644
--- a/drivers/pci/hotplug/pciehp_core.c
+++ b/drivers/pci/hotplug/pciehp_core.c
@@ -69,8 +69,6 @@ static int get_power_status (struct hotplug_slot *slot, u8 *value);
69static int get_attention_status (struct hotplug_slot *slot, u8 *value); 69static int get_attention_status (struct hotplug_slot *slot, u8 *value);
70static int get_latch_status (struct hotplug_slot *slot, u8 *value); 70static int get_latch_status (struct hotplug_slot *slot, u8 *value);
71static int get_adapter_status (struct hotplug_slot *slot, u8 *value); 71static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
72static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
73static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
74 72
75/** 73/**
76 * release_slot - free up the memory used by a slot 74 * release_slot - free up the memory used by a slot
@@ -113,8 +111,6 @@ static int init_slot(struct controller *ctrl)
113 ops->disable_slot = disable_slot; 111 ops->disable_slot = disable_slot;
114 ops->get_power_status = get_power_status; 112 ops->get_power_status = get_power_status;
115 ops->get_adapter_status = get_adapter_status; 113 ops->get_adapter_status = get_adapter_status;
116 ops->get_max_bus_speed = get_max_bus_speed;
117 ops->get_cur_bus_speed = get_cur_bus_speed;
118 if (MRL_SENS(ctrl)) 114 if (MRL_SENS(ctrl))
119 ops->get_latch_status = get_latch_status; 115 ops->get_latch_status = get_latch_status;
120 if (ATTN_LED(ctrl)) { 116 if (ATTN_LED(ctrl)) {
@@ -227,27 +223,6 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
227 return pciehp_get_adapter_status(slot, value); 223 return pciehp_get_adapter_status(slot, value);
228} 224}
229 225
230static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
231 enum pci_bus_speed *value)
232{
233 struct slot *slot = hotplug_slot->private;
234
235 ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
236 __func__, slot_name(slot));
237
238 return pciehp_get_max_link_speed(slot, value);
239}
240
241static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
242{
243 struct slot *slot = hotplug_slot->private;
244
245 ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
246 __func__, slot_name(slot));
247
248 return pciehp_get_cur_link_speed(slot, value);
249}
250
251static int pciehp_probe(struct pcie_device *dev) 226static int pciehp_probe(struct pcie_device *dev)
252{ 227{
253 int rc; 228 int rc;
diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
index d6ac1b261dd9..9a7f247e8ac1 100644
--- a/drivers/pci/hotplug/pciehp_ctrl.c
+++ b/drivers/pci/hotplug/pciehp_ctrl.c
@@ -341,6 +341,7 @@ void pciehp_queue_pushbutton_work(struct work_struct *work)
341 p_slot->state = POWERON_STATE; 341 p_slot->state = POWERON_STATE;
342 break; 342 break;
343 default: 343 default:
344 kfree(info);
344 goto out; 345 goto out;
345 } 346 }
346 queue_work(pciehp_wq, &info->work); 347 queue_work(pciehp_wq, &info->work);
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 10040d58c8ef..40b48f569b1e 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -492,6 +492,7 @@ int pciehp_power_on_slot(struct slot * slot)
492 u16 slot_cmd; 492 u16 slot_cmd;
493 u16 cmd_mask; 493 u16 cmd_mask;
494 u16 slot_status; 494 u16 slot_status;
495 u16 lnk_status;
495 int retval = 0; 496 int retval = 0;
496 497
497 /* Clear sticky power-fault bit from previous power failures */ 498 /* Clear sticky power-fault bit from previous power failures */
@@ -523,6 +524,14 @@ int pciehp_power_on_slot(struct slot * slot)
523 ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, 524 ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__,
524 pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd); 525 pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, slot_cmd);
525 526
527 retval = pciehp_readw(ctrl, PCI_EXP_LNKSTA, &lnk_status);
528 if (retval) {
529 ctrl_err(ctrl, "%s: Cannot read LNKSTA register\n",
530 __func__);
531 return retval;
532 }
533 pcie_update_link_speed(ctrl->pcie->port->subordinate, lnk_status);
534
526 return retval; 535 return retval;
527} 536}
528 537
@@ -610,37 +619,6 @@ static irqreturn_t pcie_isr(int irq, void *dev_id)
610 return IRQ_HANDLED; 619 return IRQ_HANDLED;
611} 620}
612 621
613int pciehp_get_max_link_speed(struct slot *slot, enum pci_bus_speed *value)
614{
615 struct controller *ctrl = slot->ctrl;
616 enum pcie_link_speed lnk_speed;
617 u32 lnk_cap;
618 int retval = 0;
619
620 retval = pciehp_readl(ctrl, PCI_EXP_LNKCAP, &lnk_cap);
621 if (retval) {
622 ctrl_err(ctrl, "%s: Cannot read LNKCAP register\n", __func__);
623 return retval;
624 }
625
626 switch (lnk_cap & 0x000F) {
627 case 1:
628 lnk_speed = PCIE_2_5GB;
629 break;
630 case 2:
631 lnk_speed = PCIE_5_0GB;
632 break;
633 default:
634 lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
635 break;
636 }
637
638 *value = lnk_speed;
639 ctrl_dbg(ctrl, "Max link speed = %d\n", lnk_speed);
640
641 return retval;
642}
643
644int pciehp_get_max_lnk_width(struct slot *slot, 622int pciehp_get_max_lnk_width(struct slot *slot,
645 enum pcie_link_width *value) 623 enum pcie_link_width *value)
646{ 624{
@@ -691,38 +669,6 @@ int pciehp_get_max_lnk_width(struct slot *slot,
691 return retval; 669 return retval;
692} 670}
693 671
694int pciehp_get_cur_link_speed(struct slot *slot, enum pci_bus_speed *value)
695{
696 struct controller *ctrl = slot->ctrl;
697 enum pcie_link_speed lnk_speed = PCI_SPEED_UNKNOWN;
698 int retval = 0;
699 u16 lnk_status;
700
701 retval = pciehp_readw(ctrl, PCI_EXP_LNKSTA, &lnk_status);
702 if (retval) {
703 ctrl_err(ctrl, "%s: Cannot read LNKSTATUS register\n",
704 __func__);
705 return retval;
706 }
707
708 switch (lnk_status & PCI_EXP_LNKSTA_CLS) {
709 case 1:
710 lnk_speed = PCIE_2_5GB;
711 break;
712 case 2:
713 lnk_speed = PCIE_5_0GB;
714 break;
715 default:
716 lnk_speed = PCIE_LNK_SPEED_UNKNOWN;
717 break;
718 }
719
720 *value = lnk_speed;
721 ctrl_dbg(ctrl, "Current link speed = %d\n", lnk_speed);
722
723 return retval;
724}
725
726int pciehp_get_cur_lnk_width(struct slot *slot, 672int pciehp_get_cur_lnk_width(struct slot *slot,
727 enum pcie_link_width *value) 673 enum pcie_link_width *value)
728{ 674{
diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c
index 21733108adde..0a16444c14c9 100644
--- a/drivers/pci/hotplug/pciehp_pci.c
+++ b/drivers/pci/hotplug/pciehp_pci.c
@@ -53,17 +53,15 @@ static int __ref pciehp_add_bridge(struct pci_dev *dev)
53 busnr = pci_scan_bridge(parent, dev, busnr, pass); 53 busnr = pci_scan_bridge(parent, dev, busnr, pass);
54 if (!dev->subordinate) 54 if (!dev->subordinate)
55 return -1; 55 return -1;
56 pci_bus_size_bridges(dev->subordinate); 56
57 pci_bus_assign_resources(parent);
58 pci_enable_bridges(parent);
59 pci_bus_add_devices(parent);
60 return 0; 57 return 0;
61} 58}
62 59
63int pciehp_configure_device(struct slot *p_slot) 60int pciehp_configure_device(struct slot *p_slot)
64{ 61{
65 struct pci_dev *dev; 62 struct pci_dev *dev;
66 struct pci_bus *parent = p_slot->ctrl->pcie->port->subordinate; 63 struct pci_dev *bridge = p_slot->ctrl->pcie->port;
64 struct pci_bus *parent = bridge->subordinate;
67 int num, fn; 65 int num, fn;
68 struct controller *ctrl = p_slot->ctrl; 66 struct controller *ctrl = p_slot->ctrl;
69 67
@@ -96,12 +94,25 @@ int pciehp_configure_device(struct slot *p_slot)
96 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) { 94 (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)) {
97 pciehp_add_bridge(dev); 95 pciehp_add_bridge(dev);
98 } 96 }
97 pci_dev_put(dev);
98 }
99
100 pci_assign_unassigned_bridge_resources(bridge);
101
102 for (fn = 0; fn < 8; fn++) {
103 dev = pci_get_slot(parent, PCI_DEVFN(0, fn));
104 if (!dev)
105 continue;
106 if ((dev->class >> 16) == PCI_BASE_CLASS_DISPLAY) {
107 pci_dev_put(dev);
108 continue;
109 }
99 pci_configure_slot(dev); 110 pci_configure_slot(dev);
100 pci_dev_put(dev); 111 pci_dev_put(dev);
101 } 112 }
102 113
103 pci_bus_assign_resources(parent);
104 pci_bus_add_devices(parent); 114 pci_bus_add_devices(parent);
115
105 return 0; 116 return 0;
106} 117}
107 118
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index c159223389ec..dcaae725fd79 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -130,10 +130,9 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 * value)
130 return 0; 130 return 0;
131} 131}
132 132
133static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 133static enum pci_bus_speed get_max_bus_speed(struct slot *slot)
134{ 134{
135 struct slot *slot = (struct slot *)hotplug_slot->private; 135 enum pci_bus_speed speed;
136
137 switch (slot->type) { 136 switch (slot->type) {
138 case 1: 137 case 1:
139 case 2: 138 case 2:
@@ -141,30 +140,30 @@ static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_spe
141 case 4: 140 case 4:
142 case 5: 141 case 5:
143 case 6: 142 case 6:
144 *value = PCI_SPEED_33MHz; /* speed for case 1-6 */ 143 speed = PCI_SPEED_33MHz; /* speed for case 1-6 */
145 break; 144 break;
146 case 7: 145 case 7:
147 case 8: 146 case 8:
148 *value = PCI_SPEED_66MHz; 147 speed = PCI_SPEED_66MHz;
149 break; 148 break;
150 case 11: 149 case 11:
151 case 14: 150 case 14:
152 *value = PCI_SPEED_66MHz_PCIX; 151 speed = PCI_SPEED_66MHz_PCIX;
153 break; 152 break;
154 case 12: 153 case 12:
155 case 15: 154 case 15:
156 *value = PCI_SPEED_100MHz_PCIX; 155 speed = PCI_SPEED_100MHz_PCIX;
157 break; 156 break;
158 case 13: 157 case 13:
159 case 16: 158 case 16:
160 *value = PCI_SPEED_133MHz_PCIX; 159 speed = PCI_SPEED_133MHz_PCIX;
161 break; 160 break;
162 default: 161 default:
163 *value = PCI_SPEED_UNKNOWN; 162 speed = PCI_SPEED_UNKNOWN;
164 break; 163 break;
165
166 } 164 }
167 return 0; 165
166 return speed;
168} 167}
169 168
170static int get_children_props(struct device_node *dn, const int **drc_indexes, 169static int get_children_props(struct device_node *dn, const int **drc_indexes,
@@ -408,6 +407,8 @@ static int enable_slot(struct hotplug_slot *hotplug_slot)
408 slot->state = NOT_VALID; 407 slot->state = NOT_VALID;
409 return -EINVAL; 408 return -EINVAL;
410 } 409 }
410
411 slot->bus->max_bus_speed = get_max_bus_speed(slot);
411 return 0; 412 return 0;
412} 413}
413 414
@@ -429,7 +430,6 @@ struct hotplug_slot_ops rpaphp_hotplug_slot_ops = {
429 .get_power_status = get_power_status, 430 .get_power_status = get_power_status,
430 .get_attention_status = get_attention_status, 431 .get_attention_status = get_attention_status,
431 .get_adapter_status = get_adapter_status, 432 .get_adapter_status = get_adapter_status,
432 .get_max_bus_speed = get_max_bus_speed,
433}; 433};
434 434
435module_init(rpaphp_init); 435module_init(rpaphp_init);
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index 8e210cd76e55..d2627e1c3ac1 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -333,8 +333,6 @@ struct hpc_ops {
333 int (*set_attention_status)(struct slot *slot, u8 status); 333 int (*set_attention_status)(struct slot *slot, u8 status);
334 int (*get_latch_status)(struct slot *slot, u8 *status); 334 int (*get_latch_status)(struct slot *slot, u8 *status);
335 int (*get_adapter_status)(struct slot *slot, u8 *status); 335 int (*get_adapter_status)(struct slot *slot, u8 *status);
336 int (*get_max_bus_speed)(struct slot *slot, enum pci_bus_speed *speed);
337 int (*get_cur_bus_speed)(struct slot *slot, enum pci_bus_speed *speed);
338 int (*get_adapter_speed)(struct slot *slot, enum pci_bus_speed *speed); 336 int (*get_adapter_speed)(struct slot *slot, enum pci_bus_speed *speed);
339 int (*get_mode1_ECC_cap)(struct slot *slot, u8 *mode); 337 int (*get_mode1_ECC_cap)(struct slot *slot, u8 *mode);
340 int (*get_prog_int)(struct slot *slot, u8 *prog_int); 338 int (*get_prog_int)(struct slot *slot, u8 *prog_int);
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 8a520a3d0f59..a5062297f488 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -65,8 +65,6 @@ static int get_power_status (struct hotplug_slot *slot, u8 *value);
65static int get_attention_status (struct hotplug_slot *slot, u8 *value); 65static int get_attention_status (struct hotplug_slot *slot, u8 *value);
66static int get_latch_status (struct hotplug_slot *slot, u8 *value); 66static int get_latch_status (struct hotplug_slot *slot, u8 *value);
67static int get_adapter_status (struct hotplug_slot *slot, u8 *value); 67static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
68static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
69static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
70 68
71static struct hotplug_slot_ops shpchp_hotplug_slot_ops = { 69static struct hotplug_slot_ops shpchp_hotplug_slot_ops = {
72 .set_attention_status = set_attention_status, 70 .set_attention_status = set_attention_status,
@@ -76,8 +74,6 @@ static struct hotplug_slot_ops shpchp_hotplug_slot_ops = {
76 .get_attention_status = get_attention_status, 74 .get_attention_status = get_attention_status,
77 .get_latch_status = get_latch_status, 75 .get_latch_status = get_latch_status,
78 .get_adapter_status = get_adapter_status, 76 .get_adapter_status = get_adapter_status,
79 .get_max_bus_speed = get_max_bus_speed,
80 .get_cur_bus_speed = get_cur_bus_speed,
81}; 77};
82 78
83/** 79/**
@@ -279,37 +275,6 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
279 return 0; 275 return 0;
280} 276}
281 277
282static int get_max_bus_speed(struct hotplug_slot *hotplug_slot,
283 enum pci_bus_speed *value)
284{
285 struct slot *slot = get_slot(hotplug_slot);
286 int retval;
287
288 ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
289 __func__, slot_name(slot));
290
291 retval = slot->hpc_ops->get_max_bus_speed(slot, value);
292 if (retval < 0)
293 *value = PCI_SPEED_UNKNOWN;
294
295 return 0;
296}
297
298static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
299{
300 struct slot *slot = get_slot(hotplug_slot);
301 int retval;
302
303 ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
304 __func__, slot_name(slot));
305
306 retval = slot->hpc_ops->get_cur_bus_speed(slot, value);
307 if (retval < 0)
308 *value = PCI_SPEED_UNKNOWN;
309
310 return 0;
311}
312
313static int is_shpc_capable(struct pci_dev *dev) 278static int is_shpc_capable(struct pci_dev *dev)
314{ 279{
315 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device == 280 if ((dev->vendor == PCI_VENDOR_ID_AMD) || (dev->device ==
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index b8ab2796e66a..3bba0c0888ff 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -285,17 +285,8 @@ static int board_added(struct slot *p_slot)
285 return WRONG_BUS_FREQUENCY; 285 return WRONG_BUS_FREQUENCY;
286 } 286 }
287 287
288 rc = p_slot->hpc_ops->get_cur_bus_speed(p_slot, &bsp); 288 bsp = ctrl->pci_dev->bus->cur_bus_speed;
289 if (rc) { 289 msp = ctrl->pci_dev->bus->max_bus_speed;
290 ctrl_err(ctrl, "Can't get bus operation speed\n");
291 return WRONG_BUS_FREQUENCY;
292 }
293
294 rc = p_slot->hpc_ops->get_max_bus_speed(p_slot, &msp);
295 if (rc) {
296 ctrl_err(ctrl, "Can't get max bus operation speed\n");
297 msp = bsp;
298 }
299 290
300 /* Check if there are other slots or devices on the same bus */ 291 /* Check if there are other slots or devices on the same bus */
301 if (!list_empty(&ctrl->pci_dev->subordinate->devices)) 292 if (!list_empty(&ctrl->pci_dev->subordinate->devices))
@@ -462,6 +453,7 @@ void shpchp_queue_pushbutton_work(struct work_struct *work)
462 p_slot->state = POWERON_STATE; 453 p_slot->state = POWERON_STATE;
463 break; 454 break;
464 default: 455 default:
456 kfree(info);
465 goto out; 457 goto out;
466 } 458 }
467 queue_work(shpchp_wq, &info->work); 459 queue_work(shpchp_wq, &info->work);
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
index 86dc39847769..5f5e8d2e3552 100644
--- a/drivers/pci/hotplug/shpchp_hpc.c
+++ b/drivers/pci/hotplug/shpchp_hpc.c
@@ -660,6 +660,75 @@ static int hpc_slot_disable(struct slot * slot)
660 return retval; 660 return retval;
661} 661}
662 662
663static int shpc_get_cur_bus_speed(struct controller *ctrl)
664{
665 int retval = 0;
666 struct pci_bus *bus = ctrl->pci_dev->subordinate;
667 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
668 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
669 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
670 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
671
672 if ((pi == 1) && (speed_mode > 4)) {
673 retval = -ENODEV;
674 goto out;
675 }
676
677 switch (speed_mode) {
678 case 0x0:
679 bus_speed = PCI_SPEED_33MHz;
680 break;
681 case 0x1:
682 bus_speed = PCI_SPEED_66MHz;
683 break;
684 case 0x2:
685 bus_speed = PCI_SPEED_66MHz_PCIX;
686 break;
687 case 0x3:
688 bus_speed = PCI_SPEED_100MHz_PCIX;
689 break;
690 case 0x4:
691 bus_speed = PCI_SPEED_133MHz_PCIX;
692 break;
693 case 0x5:
694 bus_speed = PCI_SPEED_66MHz_PCIX_ECC;
695 break;
696 case 0x6:
697 bus_speed = PCI_SPEED_100MHz_PCIX_ECC;
698 break;
699 case 0x7:
700 bus_speed = PCI_SPEED_133MHz_PCIX_ECC;
701 break;
702 case 0x8:
703 bus_speed = PCI_SPEED_66MHz_PCIX_266;
704 break;
705 case 0x9:
706 bus_speed = PCI_SPEED_100MHz_PCIX_266;
707 break;
708 case 0xa:
709 bus_speed = PCI_SPEED_133MHz_PCIX_266;
710 break;
711 case 0xb:
712 bus_speed = PCI_SPEED_66MHz_PCIX_533;
713 break;
714 case 0xc:
715 bus_speed = PCI_SPEED_100MHz_PCIX_533;
716 break;
717 case 0xd:
718 bus_speed = PCI_SPEED_133MHz_PCIX_533;
719 break;
720 default:
721 retval = -ENODEV;
722 break;
723 }
724
725 out:
726 bus->cur_bus_speed = bus_speed;
727 dbg("Current bus speed = %d\n", bus_speed);
728 return retval;
729}
730
731
663static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value) 732static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
664{ 733{
665 int retval; 734 int retval;
@@ -720,6 +789,8 @@ static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
720 retval = shpc_write_cmd(slot, 0, cmd); 789 retval = shpc_write_cmd(slot, 0, cmd);
721 if (retval) 790 if (retval)
722 ctrl_err(ctrl, "%s: Write command failed!\n", __func__); 791 ctrl_err(ctrl, "%s: Write command failed!\n", __func__);
792 else
793 shpc_get_cur_bus_speed(ctrl);
723 794
724 return retval; 795 return retval;
725} 796}
@@ -803,10 +874,10 @@ static irqreturn_t shpc_isr(int irq, void *dev_id)
803 return IRQ_HANDLED; 874 return IRQ_HANDLED;
804} 875}
805 876
806static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value) 877static int shpc_get_max_bus_speed(struct controller *ctrl)
807{ 878{
808 int retval = 0; 879 int retval = 0;
809 struct controller *ctrl = slot->ctrl; 880 struct pci_bus *bus = ctrl->pci_dev->subordinate;
810 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN; 881 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
811 u8 pi = shpc_readb(ctrl, PROG_INTERFACE); 882 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
812 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1); 883 u32 slot_avail1 = shpc_readl(ctrl, SLOT_AVAIL1);
@@ -842,79 +913,12 @@ static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value)
842 retval = -ENODEV; 913 retval = -ENODEV;
843 } 914 }
844 915
845 *value = bus_speed; 916 bus->max_bus_speed = bus_speed;
846 ctrl_dbg(ctrl, "Max bus speed = %d\n", bus_speed); 917 ctrl_dbg(ctrl, "Max bus speed = %d\n", bus_speed);
847 918
848 return retval; 919 return retval;
849} 920}
850 921
851static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value)
852{
853 int retval = 0;
854 struct controller *ctrl = slot->ctrl;
855 enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;
856 u16 sec_bus_reg = shpc_readw(ctrl, SEC_BUS_CONFIG);
857 u8 pi = shpc_readb(ctrl, PROG_INTERFACE);
858 u8 speed_mode = (pi == 2) ? (sec_bus_reg & 0xF) : (sec_bus_reg & 0x7);
859
860 if ((pi == 1) && (speed_mode > 4)) {
861 *value = PCI_SPEED_UNKNOWN;
862 return -ENODEV;
863 }
864
865 switch (speed_mode) {
866 case 0x0:
867 *value = PCI_SPEED_33MHz;
868 break;
869 case 0x1:
870 *value = PCI_SPEED_66MHz;
871 break;
872 case 0x2:
873 *value = PCI_SPEED_66MHz_PCIX;
874 break;
875 case 0x3:
876 *value = PCI_SPEED_100MHz_PCIX;
877 break;
878 case 0x4:
879 *value = PCI_SPEED_133MHz_PCIX;
880 break;
881 case 0x5:
882 *value = PCI_SPEED_66MHz_PCIX_ECC;
883 break;
884 case 0x6:
885 *value = PCI_SPEED_100MHz_PCIX_ECC;
886 break;
887 case 0x7:
888 *value = PCI_SPEED_133MHz_PCIX_ECC;
889 break;
890 case 0x8:
891 *value = PCI_SPEED_66MHz_PCIX_266;
892 break;
893 case 0x9:
894 *value = PCI_SPEED_100MHz_PCIX_266;
895 break;
896 case 0xa:
897 *value = PCI_SPEED_133MHz_PCIX_266;
898 break;
899 case 0xb:
900 *value = PCI_SPEED_66MHz_PCIX_533;
901 break;
902 case 0xc:
903 *value = PCI_SPEED_100MHz_PCIX_533;
904 break;
905 case 0xd:
906 *value = PCI_SPEED_133MHz_PCIX_533;
907 break;
908 default:
909 *value = PCI_SPEED_UNKNOWN;
910 retval = -ENODEV;
911 break;
912 }
913
914 ctrl_dbg(ctrl, "Current bus speed = %d\n", bus_speed);
915 return retval;
916}
917
918static struct hpc_ops shpchp_hpc_ops = { 922static struct hpc_ops shpchp_hpc_ops = {
919 .power_on_slot = hpc_power_on_slot, 923 .power_on_slot = hpc_power_on_slot,
920 .slot_enable = hpc_slot_enable, 924 .slot_enable = hpc_slot_enable,
@@ -926,8 +930,6 @@ static struct hpc_ops shpchp_hpc_ops = {
926 .get_latch_status = hpc_get_latch_status, 930 .get_latch_status = hpc_get_latch_status,
927 .get_adapter_status = hpc_get_adapter_status, 931 .get_adapter_status = hpc_get_adapter_status,
928 932
929 .get_max_bus_speed = hpc_get_max_bus_speed,
930 .get_cur_bus_speed = hpc_get_cur_bus_speed,
931 .get_adapter_speed = hpc_get_adapter_speed, 933 .get_adapter_speed = hpc_get_adapter_speed,
932 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap, 934 .get_mode1_ECC_cap = hpc_get_mode1_ECC_cap,
933 .get_prog_int = hpc_get_prog_int, 935 .get_prog_int = hpc_get_prog_int,
@@ -1086,6 +1088,9 @@ int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
1086 } 1088 }
1087 ctrl_dbg(ctrl, "HPC at %s irq=%x\n", pci_name(pdev), pdev->irq); 1089 ctrl_dbg(ctrl, "HPC at %s irq=%x\n", pci_name(pdev), pdev->irq);
1088 1090
1091 shpc_get_max_bus_speed(ctrl);
1092 shpc_get_cur_bus_speed(ctrl);
1093
1089 /* 1094 /*
1090 * If this is the first controller to be initialized, 1095 * If this is the first controller to be initialized,
1091 * initialize the shpchpd work queue 1096 * initialize the shpchpd work queue
diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c
index 29fa9d26adae..071b7dc0094b 100644
--- a/drivers/pci/hotplug/shpchp_sysfs.c
+++ b/drivers/pci/hotplug/shpchp_sysfs.c
@@ -47,8 +47,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
47 bus = pdev->subordinate; 47 bus = pdev->subordinate;
48 48
49 out += sprintf(buf, "Free resources: memory\n"); 49 out += sprintf(buf, "Free resources: memory\n");
50 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { 50 pci_bus_for_each_resource(bus, res, index) {
51 res = bus->resource[index];
52 if (res && (res->flags & IORESOURCE_MEM) && 51 if (res && (res->flags & IORESOURCE_MEM) &&
53 !(res->flags & IORESOURCE_PREFETCH)) { 52 !(res->flags & IORESOURCE_PREFETCH)) {
54 out += sprintf(out, "start = %8.8llx, " 53 out += sprintf(out, "start = %8.8llx, "
@@ -58,8 +57,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
58 } 57 }
59 } 58 }
60 out += sprintf(out, "Free resources: prefetchable memory\n"); 59 out += sprintf(out, "Free resources: prefetchable memory\n");
61 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { 60 pci_bus_for_each_resource(bus, res, index) {
62 res = bus->resource[index];
63 if (res && (res->flags & IORESOURCE_MEM) && 61 if (res && (res->flags & IORESOURCE_MEM) &&
64 (res->flags & IORESOURCE_PREFETCH)) { 62 (res->flags & IORESOURCE_PREFETCH)) {
65 out += sprintf(out, "start = %8.8llx, " 63 out += sprintf(out, "start = %8.8llx, "
@@ -69,8 +67,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
69 } 67 }
70 } 68 }
71 out += sprintf(out, "Free resources: IO\n"); 69 out += sprintf(out, "Free resources: IO\n");
72 for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { 70 pci_bus_for_each_resource(bus, res, index) {
73 res = bus->resource[index];
74 if (res && (res->flags & IORESOURCE_IO)) { 71 if (res && (res->flags & IORESOURCE_IO)) {
75 out += sprintf(out, "start = %8.8llx, " 72 out += sprintf(out, "start = %8.8llx, "
76 "length = %8.8llx\n", 73 "length = %8.8llx\n",
diff --git a/drivers/pci/legacy.c b/drivers/pci/legacy.c
deleted file mode 100644
index 871f65c15936..000000000000
--- a/drivers/pci/legacy.c
+++ /dev/null
@@ -1,34 +0,0 @@
1#include <linux/init.h>
2#include <linux/pci.h>
3#include <linux/module.h>
4#include <linux/interrupt.h>
5#include "pci.h"
6
7/**
8 * pci_find_device - begin or continue searching for a PCI device by vendor/device id
9 * @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids
10 * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
11 * @from: Previous PCI device found in search, or %NULL for new search.
12 *
13 * Iterates through the list of known PCI devices. If a PCI device is found
14 * with a matching @vendor and @device, a pointer to its device structure is
15 * returned. Otherwise, %NULL is returned.
16 * A new search is initiated by passing %NULL as the @from argument.
17 * Otherwise if @from is not %NULL, searches continue from next device
18 * on the global list.
19 *
20 * NOTE: Do not use this function any more; use pci_get_device() instead, as
21 * the PCI device returned by this function can disappear at any moment in
22 * time.
23 */
24struct pci_dev *pci_find_device(unsigned int vendor, unsigned int device,
25 struct pci_dev *from)
26{
27 struct pci_dev *pdev;
28
29 pci_dev_get(from);
30 pdev = pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
31 pci_dev_put(pdev);
32 return pdev;
33}
34EXPORT_SYMBOL(pci_find_device);
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index 7e2829538a4c..c0c73913833d 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -16,8 +16,144 @@
16#include <acpi/acpi_bus.h> 16#include <acpi/acpi_bus.h>
17 17
18#include <linux/pci-acpi.h> 18#include <linux/pci-acpi.h>
19#include <linux/pm_runtime.h>
19#include "pci.h" 20#include "pci.h"
20 21
22static DEFINE_MUTEX(pci_acpi_pm_notify_mtx);
23
24/**
25 * pci_acpi_wake_bus - Wake-up notification handler for root buses.
26 * @handle: ACPI handle of a device the notification is for.
27 * @event: Type of the signaled event.
28 * @context: PCI root bus to wake up devices on.
29 */
30static void pci_acpi_wake_bus(acpi_handle handle, u32 event, void *context)
31{
32 struct pci_bus *pci_bus = context;
33
34 if (event == ACPI_NOTIFY_DEVICE_WAKE && pci_bus)
35 pci_pme_wakeup_bus(pci_bus);
36}
37
38/**
39 * pci_acpi_wake_dev - Wake-up notification handler for PCI devices.
40 * @handle: ACPI handle of a device the notification is for.
41 * @event: Type of the signaled event.
42 * @context: PCI device object to wake up.
43 */
44static void pci_acpi_wake_dev(acpi_handle handle, u32 event, void *context)
45{
46 struct pci_dev *pci_dev = context;
47
48 if (event == ACPI_NOTIFY_DEVICE_WAKE && pci_dev) {
49 pci_check_pme_status(pci_dev);
50 pm_runtime_resume(&pci_dev->dev);
51 if (pci_dev->subordinate)
52 pci_pme_wakeup_bus(pci_dev->subordinate);
53 }
54}
55
56/**
57 * add_pm_notifier - Register PM notifier for given ACPI device.
58 * @dev: ACPI device to add the notifier for.
59 * @context: PCI device or bus to check for PME status if an event is signaled.
60 *
61 * NOTE: @dev need not be a run-wake or wake-up device to be a valid source of
62 * PM wake-up events. For example, wake-up events may be generated for bridges
63 * if one of the devices below the bridge is signaling PME, even if the bridge
64 * itself doesn't have a wake-up GPE associated with it.
65 */
66static acpi_status add_pm_notifier(struct acpi_device *dev,
67 acpi_notify_handler handler,
68 void *context)
69{
70 acpi_status status = AE_ALREADY_EXISTS;
71
72 mutex_lock(&pci_acpi_pm_notify_mtx);
73
74 if (dev->wakeup.flags.notifier_present)
75 goto out;
76
77 status = acpi_install_notify_handler(dev->handle,
78 ACPI_SYSTEM_NOTIFY,
79 handler, context);
80 if (ACPI_FAILURE(status))
81 goto out;
82
83 dev->wakeup.flags.notifier_present = true;
84
85 out:
86 mutex_unlock(&pci_acpi_pm_notify_mtx);
87 return status;
88}
89
90/**
91 * remove_pm_notifier - Unregister PM notifier from given ACPI device.
92 * @dev: ACPI device to remove the notifier from.
93 */
94static acpi_status remove_pm_notifier(struct acpi_device *dev,
95 acpi_notify_handler handler)
96{
97 acpi_status status = AE_BAD_PARAMETER;
98
99 mutex_lock(&pci_acpi_pm_notify_mtx);
100
101 if (!dev->wakeup.flags.notifier_present)
102 goto out;
103
104 status = acpi_remove_notify_handler(dev->handle,
105 ACPI_SYSTEM_NOTIFY,
106 handler);
107 if (ACPI_FAILURE(status))
108 goto out;
109
110 dev->wakeup.flags.notifier_present = false;
111
112 out:
113 mutex_unlock(&pci_acpi_pm_notify_mtx);
114 return status;
115}
116
117/**
118 * pci_acpi_add_bus_pm_notifier - Register PM notifier for given PCI bus.
119 * @dev: ACPI device to add the notifier for.
120 * @pci_bus: PCI bus to walk checking for PME status if an event is signaled.
121 */
122acpi_status pci_acpi_add_bus_pm_notifier(struct acpi_device *dev,
123 struct pci_bus *pci_bus)
124{
125 return add_pm_notifier(dev, pci_acpi_wake_bus, pci_bus);
126}
127
128/**
129 * pci_acpi_remove_bus_pm_notifier - Unregister PCI bus PM notifier.
130 * @dev: ACPI device to remove the notifier from.
131 */
132acpi_status pci_acpi_remove_bus_pm_notifier(struct acpi_device *dev)
133{
134 return remove_pm_notifier(dev, pci_acpi_wake_bus);
135}
136
137/**
138 * pci_acpi_add_pm_notifier - Register PM notifier for given PCI device.
139 * @dev: ACPI device to add the notifier for.
140 * @pci_dev: PCI device to check for the PME status if an event is signaled.
141 */
142acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev,
143 struct pci_dev *pci_dev)
144{
145 return add_pm_notifier(dev, pci_acpi_wake_dev, pci_dev);
146}
147
148/**
149 * pci_acpi_remove_pm_notifier - Unregister PCI device PM notifier.
150 * @dev: ACPI device to remove the notifier from.
151 */
152acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev)
153{
154 return remove_pm_notifier(dev, pci_acpi_wake_dev);
155}
156
21/* 157/*
22 * _SxD returns the D-state with the highest power 158 * _SxD returns the D-state with the highest power
23 * (lowest D-state number) supported in the S-state "x". 159 * (lowest D-state number) supported in the S-state "x".
@@ -131,12 +267,87 @@ static int acpi_pci_sleep_wake(struct pci_dev *dev, bool enable)
131 return 0; 267 return 0;
132} 268}
133 269
270/**
271 * acpi_dev_run_wake - Enable/disable wake-up for given device.
272 * @phys_dev: Device to enable/disable the platform to wake-up the system for.
273 * @enable: Whether enable or disable the wake-up functionality.
274 *
275 * Find the ACPI device object corresponding to @pci_dev and try to
276 * enable/disable the GPE associated with it.
277 */
278static int acpi_dev_run_wake(struct device *phys_dev, bool enable)
279{
280 struct acpi_device *dev;
281 acpi_handle handle;
282 int error = -ENODEV;
283
284 if (!device_run_wake(phys_dev))
285 return -EINVAL;
286
287 handle = DEVICE_ACPI_HANDLE(phys_dev);
288 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) {
289 dev_dbg(phys_dev, "ACPI handle has no context in %s!\n",
290 __func__);
291 return -ENODEV;
292 }
293
294 if (enable) {
295 if (!dev->wakeup.run_wake_count++) {
296 acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0);
297 acpi_enable_gpe(dev->wakeup.gpe_device,
298 dev->wakeup.gpe_number,
299 ACPI_GPE_TYPE_RUNTIME);
300 }
301 } else if (dev->wakeup.run_wake_count > 0) {
302 if (!--dev->wakeup.run_wake_count) {
303 acpi_disable_gpe(dev->wakeup.gpe_device,
304 dev->wakeup.gpe_number,
305 ACPI_GPE_TYPE_RUNTIME);
306 acpi_disable_wakeup_device_power(dev);
307 }
308 } else {
309 error = -EALREADY;
310 }
311
312 return error;
313}
314
315static void acpi_pci_propagate_run_wake(struct pci_bus *bus, bool enable)
316{
317 while (bus->parent) {
318 struct pci_dev *bridge = bus->self;
319
320 if (bridge->pme_interrupt)
321 return;
322 if (!acpi_dev_run_wake(&bridge->dev, enable))
323 return;
324 bus = bus->parent;
325 }
326
327 /* We have reached the root bus. */
328 if (bus->bridge)
329 acpi_dev_run_wake(bus->bridge, enable);
330}
331
332static int acpi_pci_run_wake(struct pci_dev *dev, bool enable)
333{
334 if (dev->pme_interrupt)
335 return 0;
336
337 if (!acpi_dev_run_wake(&dev->dev, enable))
338 return 0;
339
340 acpi_pci_propagate_run_wake(dev->bus, enable);
341 return 0;
342}
343
134static struct pci_platform_pm_ops acpi_pci_platform_pm = { 344static struct pci_platform_pm_ops acpi_pci_platform_pm = {
135 .is_manageable = acpi_pci_power_manageable, 345 .is_manageable = acpi_pci_power_manageable,
136 .set_state = acpi_pci_set_power_state, 346 .set_state = acpi_pci_set_power_state,
137 .choose_state = acpi_pci_choose_state, 347 .choose_state = acpi_pci_choose_state,
138 .can_wakeup = acpi_pci_can_wakeup, 348 .can_wakeup = acpi_pci_can_wakeup,
139 .sleep_wake = acpi_pci_sleep_wake, 349 .sleep_wake = acpi_pci_sleep_wake,
350 .run_wake = acpi_pci_run_wake,
140}; 351};
141 352
142/* ACPI bus type */ 353/* ACPI bus type */
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index e5d47be3c6d7..f9a0aec3abcf 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -17,6 +17,7 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/cpu.h> 19#include <linux/cpu.h>
20#include <linux/pm_runtime.h>
20#include "pci.h" 21#include "pci.h"
21 22
22struct pci_dynid { 23struct pci_dynid {
@@ -404,6 +405,35 @@ static void pci_device_shutdown(struct device *dev)
404 pci_msix_shutdown(pci_dev); 405 pci_msix_shutdown(pci_dev);
405} 406}
406 407
408#ifdef CONFIG_PM_OPS
409
410/* Auxiliary functions used for system resume and run-time resume. */
411
412/**
413 * pci_restore_standard_config - restore standard config registers of PCI device
414 * @pci_dev: PCI device to handle
415 */
416static int pci_restore_standard_config(struct pci_dev *pci_dev)
417{
418 pci_update_current_state(pci_dev, PCI_UNKNOWN);
419
420 if (pci_dev->current_state != PCI_D0) {
421 int error = pci_set_power_state(pci_dev, PCI_D0);
422 if (error)
423 return error;
424 }
425
426 return pci_restore_state(pci_dev);
427}
428
429static void pci_pm_default_resume_early(struct pci_dev *pci_dev)
430{
431 pci_restore_standard_config(pci_dev);
432 pci_fixup_device(pci_fixup_resume_early, pci_dev);
433}
434
435#endif
436
407#ifdef CONFIG_PM_SLEEP 437#ifdef CONFIG_PM_SLEEP
408 438
409/* 439/*
@@ -520,29 +550,6 @@ static int pci_legacy_resume(struct device *dev)
520 550
521/* Auxiliary functions used by the new power management framework */ 551/* Auxiliary functions used by the new power management framework */
522 552
523/**
524 * pci_restore_standard_config - restore standard config registers of PCI device
525 * @pci_dev: PCI device to handle
526 */
527static int pci_restore_standard_config(struct pci_dev *pci_dev)
528{
529 pci_update_current_state(pci_dev, PCI_UNKNOWN);
530
531 if (pci_dev->current_state != PCI_D0) {
532 int error = pci_set_power_state(pci_dev, PCI_D0);
533 if (error)
534 return error;
535 }
536
537 return pci_restore_state(pci_dev);
538}
539
540static void pci_pm_default_resume_noirq(struct pci_dev *pci_dev)
541{
542 pci_restore_standard_config(pci_dev);
543 pci_fixup_device(pci_fixup_resume_early, pci_dev);
544}
545
546static void pci_pm_default_resume(struct pci_dev *pci_dev) 553static void pci_pm_default_resume(struct pci_dev *pci_dev)
547{ 554{
548 pci_fixup_device(pci_fixup_resume, pci_dev); 555 pci_fixup_device(pci_fixup_resume, pci_dev);
@@ -581,6 +588,17 @@ static int pci_pm_prepare(struct device *dev)
581 struct device_driver *drv = dev->driver; 588 struct device_driver *drv = dev->driver;
582 int error = 0; 589 int error = 0;
583 590
591 /*
592 * PCI devices suspended at run time need to be resumed at this
593 * point, because in general it is necessary to reconfigure them for
594 * system suspend. Namely, if the device is supposed to wake up the
595 * system from the sleep state, we may need to reconfigure it for this
596 * purpose. In turn, if the device is not supposed to wake up the
597 * system from the sleep state, we'll have to prevent it from signaling
598 * wake-up.
599 */
600 pm_runtime_resume(dev);
601
584 if (drv && drv->pm && drv->pm->prepare) 602 if (drv && drv->pm && drv->pm->prepare)
585 error = drv->pm->prepare(dev); 603 error = drv->pm->prepare(dev);
586 604
@@ -595,6 +613,13 @@ static void pci_pm_complete(struct device *dev)
595 drv->pm->complete(dev); 613 drv->pm->complete(dev);
596} 614}
597 615
616#else /* !CONFIG_PM_SLEEP */
617
618#define pci_pm_prepare NULL
619#define pci_pm_complete NULL
620
621#endif /* !CONFIG_PM_SLEEP */
622
598#ifdef CONFIG_SUSPEND 623#ifdef CONFIG_SUSPEND
599 624
600static int pci_pm_suspend(struct device *dev) 625static int pci_pm_suspend(struct device *dev)
@@ -681,7 +706,7 @@ static int pci_pm_resume_noirq(struct device *dev)
681 struct device_driver *drv = dev->driver; 706 struct device_driver *drv = dev->driver;
682 int error = 0; 707 int error = 0;
683 708
684 pci_pm_default_resume_noirq(pci_dev); 709 pci_pm_default_resume_early(pci_dev);
685 710
686 if (pci_has_legacy_pm_support(pci_dev)) 711 if (pci_has_legacy_pm_support(pci_dev))
687 return pci_legacy_resume_early(dev); 712 return pci_legacy_resume_early(dev);
@@ -879,7 +904,7 @@ static int pci_pm_restore_noirq(struct device *dev)
879 struct device_driver *drv = dev->driver; 904 struct device_driver *drv = dev->driver;
880 int error = 0; 905 int error = 0;
881 906
882 pci_pm_default_resume_noirq(pci_dev); 907 pci_pm_default_resume_early(pci_dev);
883 908
884 if (pci_has_legacy_pm_support(pci_dev)) 909 if (pci_has_legacy_pm_support(pci_dev))
885 return pci_legacy_resume_early(dev); 910 return pci_legacy_resume_early(dev);
@@ -931,6 +956,84 @@ static int pci_pm_restore(struct device *dev)
931 956
932#endif /* !CONFIG_HIBERNATION */ 957#endif /* !CONFIG_HIBERNATION */
933 958
959#ifdef CONFIG_PM_RUNTIME
960
961static int pci_pm_runtime_suspend(struct device *dev)
962{
963 struct pci_dev *pci_dev = to_pci_dev(dev);
964 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
965 pci_power_t prev = pci_dev->current_state;
966 int error;
967
968 if (!pm || !pm->runtime_suspend)
969 return -ENOSYS;
970
971 error = pm->runtime_suspend(dev);
972 suspend_report_result(pm->runtime_suspend, error);
973 if (error)
974 return error;
975
976 pci_fixup_device(pci_fixup_suspend, pci_dev);
977
978 if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0
979 && pci_dev->current_state != PCI_UNKNOWN) {
980 WARN_ONCE(pci_dev->current_state != prev,
981 "PCI PM: State of device not saved by %pF\n",
982 pm->runtime_suspend);
983 return 0;
984 }
985
986 if (!pci_dev->state_saved)
987 pci_save_state(pci_dev);
988
989 pci_finish_runtime_suspend(pci_dev);
990
991 return 0;
992}
993
994static int pci_pm_runtime_resume(struct device *dev)
995{
996 struct pci_dev *pci_dev = to_pci_dev(dev);
997 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
998
999 if (!pm || !pm->runtime_resume)
1000 return -ENOSYS;
1001
1002 pci_pm_default_resume_early(pci_dev);
1003 __pci_enable_wake(pci_dev, PCI_D0, true, false);
1004 pci_fixup_device(pci_fixup_resume, pci_dev);
1005
1006 return pm->runtime_resume(dev);
1007}
1008
1009static int pci_pm_runtime_idle(struct device *dev)
1010{
1011 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1012
1013 if (!pm)
1014 return -ENOSYS;
1015
1016 if (pm->runtime_idle) {
1017 int ret = pm->runtime_idle(dev);
1018 if (ret)
1019 return ret;
1020 }
1021
1022 pm_runtime_suspend(dev);
1023
1024 return 0;
1025}
1026
1027#else /* !CONFIG_PM_RUNTIME */
1028
1029#define pci_pm_runtime_suspend NULL
1030#define pci_pm_runtime_resume NULL
1031#define pci_pm_runtime_idle NULL
1032
1033#endif /* !CONFIG_PM_RUNTIME */
1034
1035#ifdef CONFIG_PM_OPS
1036
934const struct dev_pm_ops pci_dev_pm_ops = { 1037const struct dev_pm_ops pci_dev_pm_ops = {
935 .prepare = pci_pm_prepare, 1038 .prepare = pci_pm_prepare,
936 .complete = pci_pm_complete, 1039 .complete = pci_pm_complete,
@@ -946,15 +1049,18 @@ const struct dev_pm_ops pci_dev_pm_ops = {
946 .thaw_noirq = pci_pm_thaw_noirq, 1049 .thaw_noirq = pci_pm_thaw_noirq,
947 .poweroff_noirq = pci_pm_poweroff_noirq, 1050 .poweroff_noirq = pci_pm_poweroff_noirq,
948 .restore_noirq = pci_pm_restore_noirq, 1051 .restore_noirq = pci_pm_restore_noirq,
1052 .runtime_suspend = pci_pm_runtime_suspend,
1053 .runtime_resume = pci_pm_runtime_resume,
1054 .runtime_idle = pci_pm_runtime_idle,
949}; 1055};
950 1056
951#define PCI_PM_OPS_PTR (&pci_dev_pm_ops) 1057#define PCI_PM_OPS_PTR (&pci_dev_pm_ops)
952 1058
953#else /* !CONFIG_PM_SLEEP */ 1059#else /* !COMFIG_PM_OPS */
954 1060
955#define PCI_PM_OPS_PTR NULL 1061#define PCI_PM_OPS_PTR NULL
956 1062
957#endif /* !CONFIG_PM_SLEEP */ 1063#endif /* !COMFIG_PM_OPS */
958 1064
959/** 1065/**
960 * __pci_register_driver - register a new pci driver 1066 * __pci_register_driver - register a new pci driver
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 315fea47e784..5b548aee9cbc 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -19,8 +19,8 @@
19#include <linux/pci-aspm.h> 19#include <linux/pci-aspm.h>
20#include <linux/pm_wakeup.h> 20#include <linux/pm_wakeup.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <asm/dma.h> /* isa_dma_bridge_buggy */
23#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/pm_runtime.h>
24#include <asm/setup.h> 24#include <asm/setup.h>
25#include "pci.h" 25#include "pci.h"
26 26
@@ -29,6 +29,12 @@ const char *pci_power_names[] = {
29}; 29};
30EXPORT_SYMBOL_GPL(pci_power_names); 30EXPORT_SYMBOL_GPL(pci_power_names);
31 31
32int isa_dma_bridge_buggy;
33EXPORT_SYMBOL(isa_dma_bridge_buggy);
34
35int pci_pci_problems;
36EXPORT_SYMBOL(pci_pci_problems);
37
32unsigned int pci_pm_d3_delay; 38unsigned int pci_pm_d3_delay;
33 39
34static void pci_dev_d3_sleep(struct pci_dev *dev) 40static void pci_dev_d3_sleep(struct pci_dev *dev)
@@ -380,10 +386,9 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
380{ 386{
381 const struct pci_bus *bus = dev->bus; 387 const struct pci_bus *bus = dev->bus;
382 int i; 388 int i;
383 struct resource *best = NULL; 389 struct resource *best = NULL, *r;
384 390
385 for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { 391 pci_bus_for_each_resource(bus, r, i) {
386 struct resource *r = bus->resource[i];
387 if (!r) 392 if (!r)
388 continue; 393 continue;
389 if (res->start && !(res->start >= r->start && res->end <= r->end)) 394 if (res->start && !(res->start >= r->start && res->end <= r->end))
@@ -457,6 +462,12 @@ static inline int platform_pci_sleep_wake(struct pci_dev *dev, bool enable)
457 pci_platform_pm->sleep_wake(dev, enable) : -ENODEV; 462 pci_platform_pm->sleep_wake(dev, enable) : -ENODEV;
458} 463}
459 464
465static inline int platform_pci_run_wake(struct pci_dev *dev, bool enable)
466{
467 return pci_platform_pm ?
468 pci_platform_pm->run_wake(dev, enable) : -ENODEV;
469}
470
460/** 471/**
461 * pci_raw_set_power_state - Use PCI PM registers to set the power state of 472 * pci_raw_set_power_state - Use PCI PM registers to set the power state of
462 * given PCI device 473 * given PCI device
@@ -1190,6 +1201,66 @@ int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
1190} 1201}
1191 1202
1192/** 1203/**
1204 * pci_check_pme_status - Check if given device has generated PME.
1205 * @dev: Device to check.
1206 *
1207 * Check the PME status of the device and if set, clear it and clear PME enable
1208 * (if set). Return 'true' if PME status and PME enable were both set or
1209 * 'false' otherwise.
1210 */
1211bool pci_check_pme_status(struct pci_dev *dev)
1212{
1213 int pmcsr_pos;
1214 u16 pmcsr;
1215 bool ret = false;
1216
1217 if (!dev->pm_cap)
1218 return false;
1219
1220 pmcsr_pos = dev->pm_cap + PCI_PM_CTRL;
1221 pci_read_config_word(dev, pmcsr_pos, &pmcsr);
1222 if (!(pmcsr & PCI_PM_CTRL_PME_STATUS))
1223 return false;
1224
1225 /* Clear PME status. */
1226 pmcsr |= PCI_PM_CTRL_PME_STATUS;
1227 if (pmcsr & PCI_PM_CTRL_PME_ENABLE) {
1228 /* Disable PME to avoid interrupt flood. */
1229 pmcsr &= ~PCI_PM_CTRL_PME_ENABLE;
1230 ret = true;
1231 }
1232
1233 pci_write_config_word(dev, pmcsr_pos, pmcsr);
1234
1235 return ret;
1236}
1237
1238/**
1239 * pci_pme_wakeup - Wake up a PCI device if its PME Status bit is set.
1240 * @dev: Device to handle.
1241 * @ign: Ignored.
1242 *
1243 * Check if @dev has generated PME and queue a resume request for it in that
1244 * case.
1245 */
1246static int pci_pme_wakeup(struct pci_dev *dev, void *ign)
1247{
1248 if (pci_check_pme_status(dev))
1249 pm_request_resume(&dev->dev);
1250 return 0;
1251}
1252
1253/**
1254 * pci_pme_wakeup_bus - Walk given bus and wake up devices on it, if necessary.
1255 * @bus: Top bus of the subtree to walk.
1256 */
1257void pci_pme_wakeup_bus(struct pci_bus *bus)
1258{
1259 if (bus)
1260 pci_walk_bus(bus, pci_pme_wakeup, NULL);
1261}
1262
1263/**
1193 * pci_pme_capable - check the capability of PCI device to generate PME# 1264 * pci_pme_capable - check the capability of PCI device to generate PME#
1194 * @dev: PCI device to handle. 1265 * @dev: PCI device to handle.
1195 * @state: PCI state from which device will issue PME#. 1266 * @state: PCI state from which device will issue PME#.
@@ -1230,9 +1301,10 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
1230} 1301}
1231 1302
1232/** 1303/**
1233 * pci_enable_wake - enable PCI device as wakeup event source 1304 * __pci_enable_wake - enable PCI device as wakeup event source
1234 * @dev: PCI device affected 1305 * @dev: PCI device affected
1235 * @state: PCI state from which device will issue wakeup events 1306 * @state: PCI state from which device will issue wakeup events
1307 * @runtime: True if the events are to be generated at run time
1236 * @enable: True to enable event generation; false to disable 1308 * @enable: True to enable event generation; false to disable
1237 * 1309 *
1238 * This enables the device as a wakeup event source, or disables it. 1310 * This enables the device as a wakeup event source, or disables it.
@@ -1248,11 +1320,12 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
1248 * Error code depending on the platform is returned if both the platform and 1320 * Error code depending on the platform is returned if both the platform and
1249 * the native mechanism fail to enable the generation of wake-up events 1321 * the native mechanism fail to enable the generation of wake-up events
1250 */ 1322 */
1251int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable) 1323int __pci_enable_wake(struct pci_dev *dev, pci_power_t state,
1324 bool runtime, bool enable)
1252{ 1325{
1253 int ret = 0; 1326 int ret = 0;
1254 1327
1255 if (enable && !device_may_wakeup(&dev->dev)) 1328 if (enable && !runtime && !device_may_wakeup(&dev->dev))
1256 return -EINVAL; 1329 return -EINVAL;
1257 1330
1258 /* Don't do the same thing twice in a row for one device. */ 1331 /* Don't do the same thing twice in a row for one device. */
@@ -1272,19 +1345,24 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable)
1272 pci_pme_active(dev, true); 1345 pci_pme_active(dev, true);
1273 else 1346 else
1274 ret = 1; 1347 ret = 1;
1275 error = platform_pci_sleep_wake(dev, true); 1348 error = runtime ? platform_pci_run_wake(dev, true) :
1349 platform_pci_sleep_wake(dev, true);
1276 if (ret) 1350 if (ret)
1277 ret = error; 1351 ret = error;
1278 if (!ret) 1352 if (!ret)
1279 dev->wakeup_prepared = true; 1353 dev->wakeup_prepared = true;
1280 } else { 1354 } else {
1281 platform_pci_sleep_wake(dev, false); 1355 if (runtime)
1356 platform_pci_run_wake(dev, false);
1357 else
1358 platform_pci_sleep_wake(dev, false);
1282 pci_pme_active(dev, false); 1359 pci_pme_active(dev, false);
1283 dev->wakeup_prepared = false; 1360 dev->wakeup_prepared = false;
1284 } 1361 }
1285 1362
1286 return ret; 1363 return ret;
1287} 1364}
1365EXPORT_SYMBOL(__pci_enable_wake);
1288 1366
1289/** 1367/**
1290 * pci_wake_from_d3 - enable/disable device to wake up from D3_hot or D3_cold 1368 * pci_wake_from_d3 - enable/disable device to wake up from D3_hot or D3_cold
@@ -1394,6 +1472,66 @@ int pci_back_from_sleep(struct pci_dev *dev)
1394} 1472}
1395 1473
1396/** 1474/**
1475 * pci_finish_runtime_suspend - Carry out PCI-specific part of runtime suspend.
1476 * @dev: PCI device being suspended.
1477 *
1478 * Prepare @dev to generate wake-up events at run time and put it into a low
1479 * power state.
1480 */
1481int pci_finish_runtime_suspend(struct pci_dev *dev)
1482{
1483 pci_power_t target_state = pci_target_state(dev);
1484 int error;
1485
1486 if (target_state == PCI_POWER_ERROR)
1487 return -EIO;
1488
1489 __pci_enable_wake(dev, target_state, true, pci_dev_run_wake(dev));
1490
1491 error = pci_set_power_state(dev, target_state);
1492
1493 if (error)
1494 __pci_enable_wake(dev, target_state, true, false);
1495
1496 return error;
1497}
1498
1499/**
1500 * pci_dev_run_wake - Check if device can generate run-time wake-up events.
1501 * @dev: Device to check.
1502 *
1503 * Return true if the device itself is cabable of generating wake-up events
1504 * (through the platform or using the native PCIe PME) or if the device supports
1505 * PME and one of its upstream bridges can generate wake-up events.
1506 */
1507bool pci_dev_run_wake(struct pci_dev *dev)
1508{
1509 struct pci_bus *bus = dev->bus;
1510
1511 if (device_run_wake(&dev->dev))
1512 return true;
1513
1514 if (!dev->pme_support)
1515 return false;
1516
1517 while (bus->parent) {
1518 struct pci_dev *bridge = bus->self;
1519
1520 if (device_run_wake(&bridge->dev))
1521 return true;
1522
1523 bus = bus->parent;
1524 }
1525
1526 /* We have reached the root bus. */
1527 if (bus->bridge)
1528 return device_run_wake(bus->bridge);
1529
1530 return false;
1531}
1532EXPORT_SYMBOL_GPL(pci_dev_run_wake);
1533
1534/**
1397 * pci_pm_init - Initialize PM functions of given PCI device 1535 * pci_pm_init - Initialize PM functions of given PCI device
1398 * @dev: PCI device to handle. 1536 * @dev: PCI device to handle.
1399 */ 1537 */
@@ -1402,6 +1540,7 @@ void pci_pm_init(struct pci_dev *dev)
1402 int pm; 1540 int pm;
1403 u16 pmc; 1541 u16 pmc;
1404 1542
1543 device_enable_async_suspend(&dev->dev);
1405 dev->wakeup_prepared = false; 1544 dev->wakeup_prepared = false;
1406 dev->pm_cap = 0; 1545 dev->pm_cap = 0;
1407 1546
@@ -2615,6 +2754,23 @@ int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type)
2615 return 0; 2754 return 0;
2616} 2755}
2617 2756
2757/* Some architectures require additional programming to enable VGA */
2758static arch_set_vga_state_t arch_set_vga_state;
2759
2760void __init pci_register_set_vga_state(arch_set_vga_state_t func)
2761{
2762 arch_set_vga_state = func; /* NULL disables */
2763}
2764
2765static int pci_set_vga_state_arch(struct pci_dev *dev, bool decode,
2766 unsigned int command_bits, bool change_bridge)
2767{
2768 if (arch_set_vga_state)
2769 return arch_set_vga_state(dev, decode, command_bits,
2770 change_bridge);
2771 return 0;
2772}
2773
2618/** 2774/**
2619 * pci_set_vga_state - set VGA decode state on device and parents if requested 2775 * pci_set_vga_state - set VGA decode state on device and parents if requested
2620 * @dev: the PCI device 2776 * @dev: the PCI device
@@ -2628,9 +2784,15 @@ int pci_set_vga_state(struct pci_dev *dev, bool decode,
2628 struct pci_bus *bus; 2784 struct pci_bus *bus;
2629 struct pci_dev *bridge; 2785 struct pci_dev *bridge;
2630 u16 cmd; 2786 u16 cmd;
2787 int rc;
2631 2788
2632 WARN_ON(command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY)); 2789 WARN_ON(command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY));
2633 2790
2791 /* ARCH specific VGA enables */
2792 rc = pci_set_vga_state_arch(dev, decode, command_bits, change_bridge);
2793 if (rc)
2794 return rc;
2795
2634 pci_read_config_word(dev, PCI_COMMAND, &cmd); 2796 pci_read_config_word(dev, PCI_COMMAND, &cmd);
2635 if (decode == true) 2797 if (decode == true)
2636 cmd |= command_bits; 2798 cmd |= command_bits;
@@ -2845,6 +3007,7 @@ EXPORT_SYMBOL(pcim_pin_device);
2845EXPORT_SYMBOL(pci_disable_device); 3007EXPORT_SYMBOL(pci_disable_device);
2846EXPORT_SYMBOL(pci_find_capability); 3008EXPORT_SYMBOL(pci_find_capability);
2847EXPORT_SYMBOL(pci_bus_find_capability); 3009EXPORT_SYMBOL(pci_bus_find_capability);
3010EXPORT_SYMBOL(pci_register_set_vga_state);
2848EXPORT_SYMBOL(pci_release_regions); 3011EXPORT_SYMBOL(pci_release_regions);
2849EXPORT_SYMBOL(pci_request_regions); 3012EXPORT_SYMBOL(pci_request_regions);
2850EXPORT_SYMBOL(pci_request_regions_exclusive); 3013EXPORT_SYMBOL(pci_request_regions_exclusive);
@@ -2871,10 +3034,8 @@ EXPORT_SYMBOL(pci_save_state);
2871EXPORT_SYMBOL(pci_restore_state); 3034EXPORT_SYMBOL(pci_restore_state);
2872EXPORT_SYMBOL(pci_pme_capable); 3035EXPORT_SYMBOL(pci_pme_capable);
2873EXPORT_SYMBOL(pci_pme_active); 3036EXPORT_SYMBOL(pci_pme_active);
2874EXPORT_SYMBOL(pci_enable_wake);
2875EXPORT_SYMBOL(pci_wake_from_d3); 3037EXPORT_SYMBOL(pci_wake_from_d3);
2876EXPORT_SYMBOL(pci_target_state); 3038EXPORT_SYMBOL(pci_target_state);
2877EXPORT_SYMBOL(pci_prepare_to_sleep); 3039EXPORT_SYMBOL(pci_prepare_to_sleep);
2878EXPORT_SYMBOL(pci_back_from_sleep); 3040EXPORT_SYMBOL(pci_back_from_sleep);
2879EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state); 3041EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state);
2880
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index fbd0e3adbca3..4eb10f48d270 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -35,6 +35,10 @@ int pci_probe_reset_function(struct pci_dev *dev);
35 * 35 *
36 * @sleep_wake: enables/disables the system wake up capability of given device 36 * @sleep_wake: enables/disables the system wake up capability of given device
37 * 37 *
38 * @run_wake: enables/disables the platform to generate run-time wake-up events
39 * for given device (the device's wake-up capability has to be
40 * enabled by @sleep_wake for this feature to work)
41 *
38 * If given platform is generally capable of power managing PCI devices, all of 42 * If given platform is generally capable of power managing PCI devices, all of
39 * these callbacks are mandatory. 43 * these callbacks are mandatory.
40 */ 44 */
@@ -44,11 +48,16 @@ struct pci_platform_pm_ops {
44 pci_power_t (*choose_state)(struct pci_dev *dev); 48 pci_power_t (*choose_state)(struct pci_dev *dev);
45 bool (*can_wakeup)(struct pci_dev *dev); 49 bool (*can_wakeup)(struct pci_dev *dev);
46 int (*sleep_wake)(struct pci_dev *dev, bool enable); 50 int (*sleep_wake)(struct pci_dev *dev, bool enable);
51 int (*run_wake)(struct pci_dev *dev, bool enable);
47}; 52};
48 53
49extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops); 54extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
50extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state); 55extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
51extern void pci_disable_enabled_device(struct pci_dev *dev); 56extern void pci_disable_enabled_device(struct pci_dev *dev);
57extern bool pci_check_pme_status(struct pci_dev *dev);
58extern int pci_finish_runtime_suspend(struct pci_dev *dev);
59extern int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
60extern void pci_pme_wakeup_bus(struct pci_bus *bus);
52extern void pci_pm_init(struct pci_dev *dev); 61extern void pci_pm_init(struct pci_dev *dev);
53extern void platform_pci_wakeup_init(struct pci_dev *dev); 62extern void platform_pci_wakeup_init(struct pci_dev *dev);
54extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); 63extern void pci_allocate_cap_save_buffers(struct pci_dev *dev);
@@ -319,6 +328,13 @@ struct pci_dev_reset_methods {
319 int (*reset)(struct pci_dev *dev, int probe); 328 int (*reset)(struct pci_dev *dev, int probe);
320}; 329};
321 330
331#ifdef CONFIG_PCI_QUIRKS
322extern int pci_dev_specific_reset(struct pci_dev *dev, int probe); 332extern int pci_dev_specific_reset(struct pci_dev *dev, int probe);
333#else
334static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe)
335{
336 return -ENOTTY;
337}
338#endif
323 339
324#endif /* DRIVERS_PCI_H */ 340#endif /* DRIVERS_PCI_H */
diff --git a/drivers/pci/pcie/Kconfig b/drivers/pci/pcie/Kconfig
index 5a0c6ad53f8e..b8b494b3e0d0 100644
--- a/drivers/pci/pcie/Kconfig
+++ b/drivers/pci/pcie/Kconfig
@@ -46,3 +46,7 @@ config PCIEASPM_DEBUG
46 help 46 help
47 This enables PCI Express ASPM debug support. It will add per-device 47 This enables PCI Express ASPM debug support. It will add per-device
48 interface to control ASPM. 48 interface to control ASPM.
49
50config PCIE_PME
51 def_bool y
52 depends on PCIEPORTBUS && PM_RUNTIME && EXPERIMENTAL && ACPI
diff --git a/drivers/pci/pcie/Makefile b/drivers/pci/pcie/Makefile
index 11f6bb1eae24..ea654545e7c4 100644
--- a/drivers/pci/pcie/Makefile
+++ b/drivers/pci/pcie/Makefile
@@ -11,3 +11,5 @@ obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o
11 11
12# Build PCI Express AER if needed 12# Build PCI Express AER if needed
13obj-$(CONFIG_PCIEAER) += aer/ 13obj-$(CONFIG_PCIEAER) += aer/
14
15obj-$(CONFIG_PCIE_PME) += pme/
diff --git a/drivers/pci/pcie/pme/Makefile b/drivers/pci/pcie/pme/Makefile
new file mode 100644
index 000000000000..8b9238053080
--- /dev/null
+++ b/drivers/pci/pcie/pme/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for PCI-Express Root Port PME signaling driver
3#
4
5obj-$(CONFIG_PCIE_PME) += pmedriver.o
6
7pmedriver-objs := pcie_pme.o
8pmedriver-$(CONFIG_ACPI) += pcie_pme_acpi.o
diff --git a/drivers/pci/pcie/pme/pcie_pme.c b/drivers/pci/pcie/pme/pcie_pme.c
new file mode 100644
index 000000000000..7b3cbff547ee
--- /dev/null
+++ b/drivers/pci/pcie/pme/pcie_pme.c
@@ -0,0 +1,505 @@
1/*
2 * PCIe Native PME support
3 *
4 * Copyright (C) 2007 - 2009 Intel Corp
5 * Copyright (C) 2007 - 2009 Shaohua Li <shaohua.li@intel.com>
6 * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License V2. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/module.h>
14#include <linux/pci.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/init.h>
18#include <linux/interrupt.h>
19#include <linux/device.h>
20#include <linux/pcieport_if.h>
21#include <linux/acpi.h>
22#include <linux/pci-acpi.h>
23#include <linux/pm_runtime.h>
24
25#include "../../pci.h"
26#include "pcie_pme.h"
27
28#define PCI_EXP_RTSTA_PME 0x10000 /* PME status */
29#define PCI_EXP_RTSTA_PENDING 0x20000 /* PME pending */
30
31/*
32 * If set, this switch will prevent the PCIe root port PME service driver from
33 * being registered. Consequently, the interrupt-based PCIe PME signaling will
34 * not be used by any PCIe root ports in that case.
35 */
36static bool pcie_pme_disabled;
37
38/*
39 * The PCI Express Base Specification 2.0, Section 6.1.8, states the following:
40 * "In order to maintain compatibility with non-PCI Express-aware system
41 * software, system power management logic must be configured by firmware to use
42 * the legacy mechanism of signaling PME by default. PCI Express-aware system
43 * software must notify the firmware prior to enabling native, interrupt-based
44 * PME signaling." However, if the platform doesn't provide us with a suitable
45 * notification mechanism or the notification fails, it is not clear whether or
46 * not we are supposed to use the interrupt-based PCIe PME signaling. The
47 * switch below can be used to indicate the desired behaviour. When set, it
48 * will make the kernel use the interrupt-based PCIe PME signaling regardless of
49 * the platform notification status, although the kernel will attempt to notify
50 * the platform anyway. When unset, it will prevent the kernel from using the
51 * the interrupt-based PCIe PME signaling if the platform notification fails,
52 * which is the default.
53 */
54static bool pcie_pme_force_enable;
55
56/*
57 * If this switch is set, MSI will not be used for PCIe PME signaling. This
58 * causes the PCIe port driver to use INTx interrupts only, but it turns out
59 * that using MSI for PCIe PME signaling doesn't play well with PCIe PME-based
60 * wake-up from system sleep states.
61 */
62bool pcie_pme_msi_disabled;
63
64static int __init pcie_pme_setup(char *str)
65{
66 if (!strcmp(str, "off"))
67 pcie_pme_disabled = true;
68 else if (!strcmp(str, "force"))
69 pcie_pme_force_enable = true;
70 else if (!strcmp(str, "nomsi"))
71 pcie_pme_msi_disabled = true;
72 return 1;
73}
74__setup("pcie_pme=", pcie_pme_setup);
75
76/**
77 * pcie_pme_platform_setup - Ensure that the kernel controls the PCIe PME.
78 * @srv: PCIe PME root port service to use for carrying out the check.
79 *
80 * Notify the platform that the native PCIe PME is going to be used and return
81 * 'true' if the control of the PCIe PME registers has been acquired from the
82 * platform.
83 */
84static bool pcie_pme_platform_setup(struct pcie_device *srv)
85{
86 if (!pcie_pme_platform_notify(srv))
87 return true;
88 return pcie_pme_force_enable;
89}
90
91struct pcie_pme_service_data {
92 spinlock_t lock;
93 struct pcie_device *srv;
94 struct work_struct work;
95 bool noirq; /* Don't enable the PME interrupt used by this service. */
96};
97
98/**
99 * pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation.
100 * @dev: PCIe root port or event collector.
101 * @enable: Enable or disable the interrupt.
102 */
103static void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable)
104{
105 int rtctl_pos;
106 u16 rtctl;
107
108 rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;
109
110 pci_read_config_word(dev, rtctl_pos, &rtctl);
111 if (enable)
112 rtctl |= PCI_EXP_RTCTL_PMEIE;
113 else
114 rtctl &= ~PCI_EXP_RTCTL_PMEIE;
115 pci_write_config_word(dev, rtctl_pos, rtctl);
116}
117
118/**
119 * pcie_pme_clear_status - Clear root port PME interrupt status.
120 * @dev: PCIe root port or event collector.
121 */
122static void pcie_pme_clear_status(struct pci_dev *dev)
123{
124 int rtsta_pos;
125 u32 rtsta;
126
127 rtsta_pos = pci_pcie_cap(dev) + PCI_EXP_RTSTA;
128
129 pci_read_config_dword(dev, rtsta_pos, &rtsta);
130 rtsta |= PCI_EXP_RTSTA_PME;
131 pci_write_config_dword(dev, rtsta_pos, rtsta);
132}
133
134/**
135 * pcie_pme_walk_bus - Scan a PCI bus for devices asserting PME#.
136 * @bus: PCI bus to scan.
137 *
138 * Scan given PCI bus and all buses under it for devices asserting PME#.
139 */
140static bool pcie_pme_walk_bus(struct pci_bus *bus)
141{
142 struct pci_dev *dev;
143 bool ret = false;
144
145 list_for_each_entry(dev, &bus->devices, bus_list) {
146 /* Skip PCIe devices in case we started from a root port. */
147 if (!pci_is_pcie(dev) && pci_check_pme_status(dev)) {
148 pm_request_resume(&dev->dev);
149 ret = true;
150 }
151
152 if (dev->subordinate && pcie_pme_walk_bus(dev->subordinate))
153 ret = true;
154 }
155
156 return ret;
157}
158
159/**
160 * pcie_pme_from_pci_bridge - Check if PCIe-PCI bridge generated a PME.
161 * @bus: Secondary bus of the bridge.
162 * @devfn: Device/function number to check.
163 *
164 * PME from PCI devices under a PCIe-PCI bridge may be converted to an in-band
165 * PCIe PME message. In such that case the bridge should use the Requester ID
166 * of device/function number 0 on its secondary bus.
167 */
168static bool pcie_pme_from_pci_bridge(struct pci_bus *bus, u8 devfn)
169{
170 struct pci_dev *dev;
171 bool found = false;
172
173 if (devfn)
174 return false;
175
176 dev = pci_dev_get(bus->self);
177 if (!dev)
178 return false;
179
180 if (pci_is_pcie(dev) && dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) {
181 down_read(&pci_bus_sem);
182 if (pcie_pme_walk_bus(bus))
183 found = true;
184 up_read(&pci_bus_sem);
185 }
186
187 pci_dev_put(dev);
188 return found;
189}
190
191/**
192 * pcie_pme_handle_request - Find device that generated PME and handle it.
193 * @port: Root port or event collector that generated the PME interrupt.
194 * @req_id: PCIe Requester ID of the device that generated the PME.
195 */
196static void pcie_pme_handle_request(struct pci_dev *port, u16 req_id)
197{
198 u8 busnr = req_id >> 8, devfn = req_id & 0xff;
199 struct pci_bus *bus;
200 struct pci_dev *dev;
201 bool found = false;
202
203 /* First, check if the PME is from the root port itself. */
204 if (port->devfn == devfn && port->bus->number == busnr) {
205 if (pci_check_pme_status(port)) {
206 pm_request_resume(&port->dev);
207 found = true;
208 } else {
209 /*
210 * Apparently, the root port generated the PME on behalf
211 * of a non-PCIe device downstream. If this is done by
212 * a root port, the Requester ID field in its status
213 * register may contain either the root port's, or the
214 * source device's information (PCI Express Base
215 * Specification, Rev. 2.0, Section 6.1.9).
216 */
217 down_read(&pci_bus_sem);
218 found = pcie_pme_walk_bus(port->subordinate);
219 up_read(&pci_bus_sem);
220 }
221 goto out;
222 }
223
224 /* Second, find the bus the source device is on. */
225 bus = pci_find_bus(pci_domain_nr(port->bus), busnr);
226 if (!bus)
227 goto out;
228
229 /* Next, check if the PME is from a PCIe-PCI bridge. */
230 found = pcie_pme_from_pci_bridge(bus, devfn);
231 if (found)
232 goto out;
233
234 /* Finally, try to find the PME source on the bus. */
235 down_read(&pci_bus_sem);
236 list_for_each_entry(dev, &bus->devices, bus_list) {
237 pci_dev_get(dev);
238 if (dev->devfn == devfn) {
239 found = true;
240 break;
241 }
242 pci_dev_put(dev);
243 }
244 up_read(&pci_bus_sem);
245
246 if (found) {
247 /* The device is there, but we have to check its PME status. */
248 found = pci_check_pme_status(dev);
249 if (found)
250 pm_request_resume(&dev->dev);
251 pci_dev_put(dev);
252 } else if (devfn) {
253 /*
254 * The device is not there, but we can still try to recover by
255 * assuming that the PME was reported by a PCIe-PCI bridge that
256 * used devfn different from zero.
257 */
258 dev_dbg(&port->dev, "PME interrupt generated for "
259 "non-existent device %02x:%02x.%d\n",
260 busnr, PCI_SLOT(devfn), PCI_FUNC(devfn));
261 found = pcie_pme_from_pci_bridge(bus, 0);
262 }
263
264 out:
265 if (!found)
266 dev_dbg(&port->dev, "Spurious native PME interrupt!\n");
267}
268
269/**
270 * pcie_pme_work_fn - Work handler for PCIe PME interrupt.
271 * @work: Work structure giving access to service data.
272 */
273static void pcie_pme_work_fn(struct work_struct *work)
274{
275 struct pcie_pme_service_data *data =
276 container_of(work, struct pcie_pme_service_data, work);
277 struct pci_dev *port = data->srv->port;
278 int rtsta_pos;
279 u32 rtsta;
280
281 rtsta_pos = pci_pcie_cap(port) + PCI_EXP_RTSTA;
282
283 spin_lock_irq(&data->lock);
284
285 for (;;) {
286 if (data->noirq)
287 break;
288
289 pci_read_config_dword(port, rtsta_pos, &rtsta);
290 if (rtsta & PCI_EXP_RTSTA_PME) {
291 /*
292 * Clear PME status of the port. If there are other
293 * pending PMEs, the status will be set again.
294 */
295 pcie_pme_clear_status(port);
296
297 spin_unlock_irq(&data->lock);
298 pcie_pme_handle_request(port, rtsta & 0xffff);
299 spin_lock_irq(&data->lock);
300
301 continue;
302 }
303
304 /* No need to loop if there are no more PMEs pending. */
305 if (!(rtsta & PCI_EXP_RTSTA_PENDING))
306 break;
307
308 spin_unlock_irq(&data->lock);
309 cpu_relax();
310 spin_lock_irq(&data->lock);
311 }
312
313 if (!data->noirq)
314 pcie_pme_interrupt_enable(port, true);
315
316 spin_unlock_irq(&data->lock);
317}
318
319/**
320 * pcie_pme_irq - Interrupt handler for PCIe root port PME interrupt.
321 * @irq: Interrupt vector.
322 * @context: Interrupt context pointer.
323 */
324static irqreturn_t pcie_pme_irq(int irq, void *context)
325{
326 struct pci_dev *port;
327 struct pcie_pme_service_data *data;
328 int rtsta_pos;
329 u32 rtsta;
330 unsigned long flags;
331
332 port = ((struct pcie_device *)context)->port;
333 data = get_service_data((struct pcie_device *)context);
334
335 rtsta_pos = pci_pcie_cap(port) + PCI_EXP_RTSTA;
336
337 spin_lock_irqsave(&data->lock, flags);
338 pci_read_config_dword(port, rtsta_pos, &rtsta);
339
340 if (!(rtsta & PCI_EXP_RTSTA_PME)) {
341 spin_unlock_irqrestore(&data->lock, flags);
342 return IRQ_NONE;
343 }
344
345 pcie_pme_interrupt_enable(port, false);
346 spin_unlock_irqrestore(&data->lock, flags);
347
348 /* We don't use pm_wq, because it's freezable. */
349 schedule_work(&data->work);
350
351 return IRQ_HANDLED;
352}
353
354/**
355 * pcie_pme_set_native - Set the PME interrupt flag for given device.
356 * @dev: PCI device to handle.
357 * @ign: Ignored.
358 */
359static int pcie_pme_set_native(struct pci_dev *dev, void *ign)
360{
361 dev_info(&dev->dev, "Signaling PME through PCIe PME interrupt\n");
362
363 device_set_run_wake(&dev->dev, true);
364 dev->pme_interrupt = true;
365 return 0;
366}
367
368/**
369 * pcie_pme_mark_devices - Set the PME interrupt flag for devices below a port.
370 * @port: PCIe root port or event collector to handle.
371 *
372 * For each device below given root port, including the port itself (or for each
373 * root complex integrated endpoint if @port is a root complex event collector)
374 * set the flag indicating that it can signal run-time wake-up events via PCIe
375 * PME interrupts.
376 */
377static void pcie_pme_mark_devices(struct pci_dev *port)
378{
379 pcie_pme_set_native(port, NULL);
380 if (port->subordinate) {
381 pci_walk_bus(port->subordinate, pcie_pme_set_native, NULL);
382 } else {
383 struct pci_bus *bus = port->bus;
384 struct pci_dev *dev;
385
386 /* Check if this is a root port event collector. */
387 if (port->pcie_type != PCI_EXP_TYPE_RC_EC || !bus)
388 return;
389
390 down_read(&pci_bus_sem);
391 list_for_each_entry(dev, &bus->devices, bus_list)
392 if (pci_is_pcie(dev)
393 && dev->pcie_type == PCI_EXP_TYPE_RC_END)
394 pcie_pme_set_native(dev, NULL);
395 up_read(&pci_bus_sem);
396 }
397}
398
399/**
400 * pcie_pme_probe - Initialize PCIe PME service for given root port.
401 * @srv: PCIe service to initialize.
402 */
403static int pcie_pme_probe(struct pcie_device *srv)
404{
405 struct pci_dev *port;
406 struct pcie_pme_service_data *data;
407 int ret;
408
409 if (!pcie_pme_platform_setup(srv))
410 return -EACCES;
411
412 data = kzalloc(sizeof(*data), GFP_KERNEL);
413 if (!data)
414 return -ENOMEM;
415
416 spin_lock_init(&data->lock);
417 INIT_WORK(&data->work, pcie_pme_work_fn);
418 data->srv = srv;
419 set_service_data(srv, data);
420
421 port = srv->port;
422 pcie_pme_interrupt_enable(port, false);
423 pcie_pme_clear_status(port);
424
425 ret = request_irq(srv->irq, pcie_pme_irq, IRQF_SHARED, "PCIe PME", srv);
426 if (ret) {
427 kfree(data);
428 } else {
429 pcie_pme_mark_devices(port);
430 pcie_pme_interrupt_enable(port, true);
431 }
432
433 return ret;
434}
435
436/**
437 * pcie_pme_suspend - Suspend PCIe PME service device.
438 * @srv: PCIe service device to suspend.
439 */
440static int pcie_pme_suspend(struct pcie_device *srv)
441{
442 struct pcie_pme_service_data *data = get_service_data(srv);
443 struct pci_dev *port = srv->port;
444
445 spin_lock_irq(&data->lock);
446 pcie_pme_interrupt_enable(port, false);
447 pcie_pme_clear_status(port);
448 data->noirq = true;
449 spin_unlock_irq(&data->lock);
450
451 synchronize_irq(srv->irq);
452
453 return 0;
454}
455
456/**
457 * pcie_pme_resume - Resume PCIe PME service device.
458 * @srv - PCIe service device to resume.
459 */
460static int pcie_pme_resume(struct pcie_device *srv)
461{
462 struct pcie_pme_service_data *data = get_service_data(srv);
463 struct pci_dev *port = srv->port;
464
465 spin_lock_irq(&data->lock);
466 data->noirq = false;
467 pcie_pme_clear_status(port);
468 pcie_pme_interrupt_enable(port, true);
469 spin_unlock_irq(&data->lock);
470
471 return 0;
472}
473
474/**
475 * pcie_pme_remove - Prepare PCIe PME service device for removal.
476 * @srv - PCIe service device to resume.
477 */
478static void pcie_pme_remove(struct pcie_device *srv)
479{
480 pcie_pme_suspend(srv);
481 free_irq(srv->irq, srv);
482 kfree(get_service_data(srv));
483}
484
485static struct pcie_port_service_driver pcie_pme_driver = {
486 .name = "pcie_pme",
487 .port_type = PCI_EXP_TYPE_ROOT_PORT,
488 .service = PCIE_PORT_SERVICE_PME,
489
490 .probe = pcie_pme_probe,
491 .suspend = pcie_pme_suspend,
492 .resume = pcie_pme_resume,
493 .remove = pcie_pme_remove,
494};
495
496/**
497 * pcie_pme_service_init - Register the PCIe PME service driver.
498 */
499static int __init pcie_pme_service_init(void)
500{
501 return pcie_pme_disabled ?
502 -ENODEV : pcie_port_service_register(&pcie_pme_driver);
503}
504
505module_init(pcie_pme_service_init);
diff --git a/drivers/pci/pcie/pme/pcie_pme.h b/drivers/pci/pcie/pme/pcie_pme.h
new file mode 100644
index 000000000000..b30d2b7c9775
--- /dev/null
+++ b/drivers/pci/pcie/pme/pcie_pme.h
@@ -0,0 +1,28 @@
1/*
2 * drivers/pci/pcie/pme/pcie_pme.h
3 *
4 * PCI Express Root Port PME signaling support
5 *
6 * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
7 */
8
9#ifndef _PCIE_PME_H_
10#define _PCIE_PME_H_
11
12struct pcie_device;
13
14#ifdef CONFIG_ACPI
15extern int pcie_pme_acpi_setup(struct pcie_device *srv);
16
17static inline int pcie_pme_platform_notify(struct pcie_device *srv)
18{
19 return pcie_pme_acpi_setup(srv);
20}
21#else /* !CONFIG_ACPI */
22static inline int pcie_pme_platform_notify(struct pcie_device *srv)
23{
24 return 0;
25}
26#endif /* !CONFIG_ACPI */
27
28#endif
diff --git a/drivers/pci/pcie/pme/pcie_pme_acpi.c b/drivers/pci/pcie/pme/pcie_pme_acpi.c
new file mode 100644
index 000000000000..83ab2287ae3f
--- /dev/null
+++ b/drivers/pci/pcie/pme/pcie_pme_acpi.c
@@ -0,0 +1,54 @@
1/*
2 * PCIe Native PME support, ACPI-related part
3 *
4 * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License V2. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/pci.h>
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/acpi.h>
15#include <linux/pci-acpi.h>
16#include <linux/pcieport_if.h>
17
18/**
19 * pcie_pme_acpi_setup - Request the ACPI BIOS to release control over PCIe PME.
20 * @srv - PCIe PME service for a root port or event collector.
21 *
22 * Invoked when the PCIe bus type loads PCIe PME service driver. To avoid
23 * conflict with the BIOS PCIe support requires the BIOS to yield PCIe PME
24 * control to the kernel.
25 */
26int pcie_pme_acpi_setup(struct pcie_device *srv)
27{
28 acpi_status status = AE_NOT_FOUND;
29 struct pci_dev *port = srv->port;
30 acpi_handle handle;
31 int error = 0;
32
33 if (acpi_pci_disabled)
34 return -ENOSYS;
35
36 dev_info(&port->dev, "Requesting control of PCIe PME from ACPI BIOS\n");
37
38 handle = acpi_find_root_bridge_handle(port);
39 if (!handle)
40 return -EINVAL;
41
42 status = acpi_pci_osc_control_set(handle,
43 OSC_PCI_EXPRESS_PME_CONTROL |
44 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
45 if (ACPI_FAILURE(status)) {
46 dev_info(&port->dev,
47 "Failed to receive control of PCIe PME service: %s\n",
48 (status == AE_SUPPORT || status == AE_NOT_FOUND) ?
49 "no _OSC support" : "ACPI _OSC failed");
50 error = -ENODEV;
51 }
52
53 return error;
54}
diff --git a/drivers/pci/pcie/portdrv.h b/drivers/pci/pcie/portdrv.h
index aaeb9d21cba5..813a5c3427b6 100644
--- a/drivers/pci/pcie/portdrv.h
+++ b/drivers/pci/pcie/portdrv.h
@@ -30,4 +30,21 @@ extern void pcie_port_device_remove(struct pci_dev *dev);
30extern int __must_check pcie_port_bus_register(void); 30extern int __must_check pcie_port_bus_register(void);
31extern void pcie_port_bus_unregister(void); 31extern void pcie_port_bus_unregister(void);
32 32
33#ifdef CONFIG_PCIE_PME
34extern bool pcie_pme_msi_disabled;
35
36static inline void pcie_pme_disable_msi(void)
37{
38 pcie_pme_msi_disabled = true;
39}
40
41static inline bool pcie_pme_no_msi(void)
42{
43 return pcie_pme_msi_disabled;
44}
45#else /* !CONFIG_PCIE_PME */
46static inline void pcie_pme_disable_msi(void) {}
47static inline bool pcie_pme_no_msi(void) { return false; }
48#endif /* !CONFIG_PCIE_PME */
49
33#endif /* _PORTDRV_H_ */ 50#endif /* _PORTDRV_H_ */
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index b174188ac121..e73effbe402c 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -186,16 +186,24 @@ static int pcie_port_enable_msix(struct pci_dev *dev, int *vectors, int mask)
186 */ 186 */
187static int init_service_irqs(struct pci_dev *dev, int *irqs, int mask) 187static int init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
188{ 188{
189 int i, irq; 189 int i, irq = -1;
190
191 /* We have to use INTx if MSI cannot be used for PCIe PME. */
192 if ((mask & PCIE_PORT_SERVICE_PME) && pcie_pme_no_msi()) {
193 if (dev->pin)
194 irq = dev->irq;
195 goto no_msi;
196 }
190 197
191 /* Try to use MSI-X if supported */ 198 /* Try to use MSI-X if supported */
192 if (!pcie_port_enable_msix(dev, irqs, mask)) 199 if (!pcie_port_enable_msix(dev, irqs, mask))
193 return 0; 200 return 0;
201
194 /* We're not going to use MSI-X, so try MSI and fall back to INTx */ 202 /* We're not going to use MSI-X, so try MSI and fall back to INTx */
195 irq = -1;
196 if (!pci_enable_msi(dev) || dev->pin) 203 if (!pci_enable_msi(dev) || dev->pin)
197 irq = dev->irq; 204 irq = dev->irq;
198 205
206 no_msi:
199 for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++) 207 for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++)
200 irqs[i] = irq; 208 irqs[i] = irq;
201 irqs[PCIE_PORT_SERVICE_VC_SHIFT] = -1; 209 irqs[PCIE_PORT_SERVICE_VC_SHIFT] = -1;
@@ -277,6 +285,7 @@ static int pcie_device_init(struct pci_dev *pdev, int service, int irq)
277 pci_name(pdev), 285 pci_name(pdev),
278 get_descriptor_id(pdev->pcie_type, service)); 286 get_descriptor_id(pdev->pcie_type, service));
279 device->parent = &pdev->dev; 287 device->parent = &pdev->dev;
288 device_enable_async_suspend(device);
280 289
281 retval = device_register(device); 290 retval = device_register(device);
282 if (retval) 291 if (retval)
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 13c8972886e6..127e8f169d9c 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -15,6 +15,7 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/pcieport_if.h> 16#include <linux/pcieport_if.h>
17#include <linux/aer.h> 17#include <linux/aer.h>
18#include <linux/dmi.h>
18 19
19#include "portdrv.h" 20#include "portdrv.h"
20#include "aer/aerdrv.h" 21#include "aer/aerdrv.h"
@@ -273,10 +274,36 @@ static struct pci_driver pcie_portdriver = {
273 .driver.pm = PCIE_PORTDRV_PM_OPS, 274 .driver.pm = PCIE_PORTDRV_PM_OPS,
274}; 275};
275 276
277static int __init dmi_pcie_pme_disable_msi(const struct dmi_system_id *d)
278{
279 pr_notice("%s detected: will not use MSI for PCIe PME signaling\n",
280 d->ident);
281 pcie_pme_disable_msi();
282 return 0;
283}
284
285static struct dmi_system_id __initdata pcie_portdrv_dmi_table[] = {
286 /*
287 * Boxes that should not use MSI for PCIe PME signaling.
288 */
289 {
290 .callback = dmi_pcie_pme_disable_msi,
291 .ident = "MSI Wind U-100",
292 .matches = {
293 DMI_MATCH(DMI_SYS_VENDOR,
294 "MICRO-STAR INTERNATIONAL CO., LTD"),
295 DMI_MATCH(DMI_PRODUCT_NAME, "U-100"),
296 },
297 },
298 {}
299};
300
276static int __init pcie_portdrv_init(void) 301static int __init pcie_portdrv_init(void)
277{ 302{
278 int retval; 303 int retval;
279 304
305 dmi_check_system(pcie_portdrv_dmi_table);
306
280 retval = pcie_port_bus_register(); 307 retval = pcie_port_bus_register();
281 if (retval) { 308 if (retval) {
282 printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval); 309 printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 446e4a94d7d3..2a943090a3b7 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -89,6 +89,7 @@ static void release_pcibus_dev(struct device *dev)
89 89
90 if (pci_bus->bridge) 90 if (pci_bus->bridge)
91 put_device(pci_bus->bridge); 91 put_device(pci_bus->bridge);
92 pci_bus_remove_resources(pci_bus);
92 kfree(pci_bus); 93 kfree(pci_bus);
93} 94}
94 95
@@ -281,26 +282,12 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
281 } 282 }
282} 283}
283 284
284void __devinit pci_read_bridge_bases(struct pci_bus *child) 285static void __devinit pci_read_bridge_io(struct pci_bus *child)
285{ 286{
286 struct pci_dev *dev = child->self; 287 struct pci_dev *dev = child->self;
287 u8 io_base_lo, io_limit_lo; 288 u8 io_base_lo, io_limit_lo;
288 u16 mem_base_lo, mem_limit_lo;
289 unsigned long base, limit; 289 unsigned long base, limit;
290 struct resource *res; 290 struct resource *res;
291 int i;
292
293 if (pci_is_root_bus(child)) /* It's a host bus, nothing to read */
294 return;
295
296 dev_info(&dev->dev, "PCI bridge to [bus %02x-%02x]%s\n",
297 child->secondary, child->subordinate,
298 dev->transparent ? " (subtractive decode)": "");
299
300 if (dev->transparent) {
301 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
302 child->resource[i] = child->parent->resource[i - 3];
303 }
304 291
305 res = child->resource[0]; 292 res = child->resource[0];
306 pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo); 293 pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo);
@@ -316,26 +303,50 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
316 limit |= (io_limit_hi << 16); 303 limit |= (io_limit_hi << 16);
317 } 304 }
318 305
319 if (base <= limit) { 306 if (base && base <= limit) {
320 res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO; 307 res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO;
321 if (!res->start) 308 if (!res->start)
322 res->start = base; 309 res->start = base;
323 if (!res->end) 310 if (!res->end)
324 res->end = limit + 0xfff; 311 res->end = limit + 0xfff;
325 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); 312 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
313 } else {
314 dev_printk(KERN_DEBUG, &dev->dev,
315 " bridge window [io %04lx - %04lx] reg reading\n",
316 base, limit);
326 } 317 }
318}
319
320static void __devinit pci_read_bridge_mmio(struct pci_bus *child)
321{
322 struct pci_dev *dev = child->self;
323 u16 mem_base_lo, mem_limit_lo;
324 unsigned long base, limit;
325 struct resource *res;
327 326
328 res = child->resource[1]; 327 res = child->resource[1];
329 pci_read_config_word(dev, PCI_MEMORY_BASE, &mem_base_lo); 328 pci_read_config_word(dev, PCI_MEMORY_BASE, &mem_base_lo);
330 pci_read_config_word(dev, PCI_MEMORY_LIMIT, &mem_limit_lo); 329 pci_read_config_word(dev, PCI_MEMORY_LIMIT, &mem_limit_lo);
331 base = (mem_base_lo & PCI_MEMORY_RANGE_MASK) << 16; 330 base = (mem_base_lo & PCI_MEMORY_RANGE_MASK) << 16;
332 limit = (mem_limit_lo & PCI_MEMORY_RANGE_MASK) << 16; 331 limit = (mem_limit_lo & PCI_MEMORY_RANGE_MASK) << 16;
333 if (base <= limit) { 332 if (base && base <= limit) {
334 res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; 333 res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM;
335 res->start = base; 334 res->start = base;
336 res->end = limit + 0xfffff; 335 res->end = limit + 0xfffff;
337 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); 336 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
337 } else {
338 dev_printk(KERN_DEBUG, &dev->dev,
339 " bridge window [mem 0x%08lx - 0x%08lx] reg reading\n",
340 base, limit + 0xfffff);
338 } 341 }
342}
343
344static void __devinit pci_read_bridge_mmio_pref(struct pci_bus *child)
345{
346 struct pci_dev *dev = child->self;
347 u16 mem_base_lo, mem_limit_lo;
348 unsigned long base, limit;
349 struct resource *res;
339 350
340 res = child->resource[2]; 351 res = child->resource[2];
341 pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo); 352 pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo);
@@ -366,7 +377,7 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
366#endif 377#endif
367 } 378 }
368 } 379 }
369 if (base <= limit) { 380 if (base && base <= limit) {
370 res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) | 381 res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) |
371 IORESOURCE_MEM | IORESOURCE_PREFETCH; 382 IORESOURCE_MEM | IORESOURCE_PREFETCH;
372 if (res->flags & PCI_PREF_RANGE_TYPE_64) 383 if (res->flags & PCI_PREF_RANGE_TYPE_64)
@@ -374,6 +385,44 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
374 res->start = base; 385 res->start = base;
375 res->end = limit + 0xfffff; 386 res->end = limit + 0xfffff;
376 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); 387 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
388 } else {
389 dev_printk(KERN_DEBUG, &dev->dev,
390 " bridge window [mem 0x%08lx - %08lx pref] reg reading\n",
391 base, limit + 0xfffff);
392 }
393}
394
395void __devinit pci_read_bridge_bases(struct pci_bus *child)
396{
397 struct pci_dev *dev = child->self;
398 struct resource *res;
399 int i;
400
401 if (pci_is_root_bus(child)) /* It's a host bus, nothing to read */
402 return;
403
404 dev_info(&dev->dev, "PCI bridge to [bus %02x-%02x]%s\n",
405 child->secondary, child->subordinate,
406 dev->transparent ? " (subtractive decode)" : "");
407
408 pci_bus_remove_resources(child);
409 for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++)
410 child->resource[i] = &dev->resource[PCI_BRIDGE_RESOURCES+i];
411
412 pci_read_bridge_io(child);
413 pci_read_bridge_mmio(child);
414 pci_read_bridge_mmio_pref(child);
415
416 if (dev->transparent) {
417 pci_bus_for_each_resource(child->parent, res, i) {
418 if (res) {
419 pci_bus_add_resource(child, res,
420 PCI_SUBTRACTIVE_DECODE);
421 dev_printk(KERN_DEBUG, &dev->dev,
422 " bridge window %pR (subtractive decode)\n",
423 res);
424 }
425 }
377 } 426 }
378} 427}
379 428
@@ -387,10 +436,147 @@ static struct pci_bus * pci_alloc_bus(void)
387 INIT_LIST_HEAD(&b->children); 436 INIT_LIST_HEAD(&b->children);
388 INIT_LIST_HEAD(&b->devices); 437 INIT_LIST_HEAD(&b->devices);
389 INIT_LIST_HEAD(&b->slots); 438 INIT_LIST_HEAD(&b->slots);
439 INIT_LIST_HEAD(&b->resources);
440 b->max_bus_speed = PCI_SPEED_UNKNOWN;
441 b->cur_bus_speed = PCI_SPEED_UNKNOWN;
390 } 442 }
391 return b; 443 return b;
392} 444}
393 445
446static unsigned char pcix_bus_speed[] = {
447 PCI_SPEED_UNKNOWN, /* 0 */
448 PCI_SPEED_66MHz_PCIX, /* 1 */
449 PCI_SPEED_100MHz_PCIX, /* 2 */
450 PCI_SPEED_133MHz_PCIX, /* 3 */
451 PCI_SPEED_UNKNOWN, /* 4 */
452 PCI_SPEED_66MHz_PCIX_ECC, /* 5 */
453 PCI_SPEED_100MHz_PCIX_ECC, /* 6 */
454 PCI_SPEED_133MHz_PCIX_ECC, /* 7 */
455 PCI_SPEED_UNKNOWN, /* 8 */
456 PCI_SPEED_66MHz_PCIX_266, /* 9 */
457 PCI_SPEED_100MHz_PCIX_266, /* A */
458 PCI_SPEED_133MHz_PCIX_266, /* B */
459 PCI_SPEED_UNKNOWN, /* C */
460 PCI_SPEED_66MHz_PCIX_533, /* D */
461 PCI_SPEED_100MHz_PCIX_533, /* E */
462 PCI_SPEED_133MHz_PCIX_533 /* F */
463};
464
465static unsigned char pcie_link_speed[] = {
466 PCI_SPEED_UNKNOWN, /* 0 */
467 PCIE_SPEED_2_5GT, /* 1 */
468 PCIE_SPEED_5_0GT, /* 2 */
469 PCIE_SPEED_8_0GT, /* 3 */
470 PCI_SPEED_UNKNOWN, /* 4 */
471 PCI_SPEED_UNKNOWN, /* 5 */
472 PCI_SPEED_UNKNOWN, /* 6 */
473 PCI_SPEED_UNKNOWN, /* 7 */
474 PCI_SPEED_UNKNOWN, /* 8 */
475 PCI_SPEED_UNKNOWN, /* 9 */
476 PCI_SPEED_UNKNOWN, /* A */
477 PCI_SPEED_UNKNOWN, /* B */
478 PCI_SPEED_UNKNOWN, /* C */
479 PCI_SPEED_UNKNOWN, /* D */
480 PCI_SPEED_UNKNOWN, /* E */
481 PCI_SPEED_UNKNOWN /* F */
482};
483
484void pcie_update_link_speed(struct pci_bus *bus, u16 linksta)
485{
486 bus->cur_bus_speed = pcie_link_speed[linksta & 0xf];
487}
488EXPORT_SYMBOL_GPL(pcie_update_link_speed);
489
490static unsigned char agp_speeds[] = {
491 AGP_UNKNOWN,
492 AGP_1X,
493 AGP_2X,
494 AGP_4X,
495 AGP_8X
496};
497
498static enum pci_bus_speed agp_speed(int agp3, int agpstat)
499{
500 int index = 0;
501
502 if (agpstat & 4)
503 index = 3;
504 else if (agpstat & 2)
505 index = 2;
506 else if (agpstat & 1)
507 index = 1;
508 else
509 goto out;
510
511 if (agp3) {
512 index += 2;
513 if (index == 5)
514 index = 0;
515 }
516
517 out:
518 return agp_speeds[index];
519}
520
521
522static void pci_set_bus_speed(struct pci_bus *bus)
523{
524 struct pci_dev *bridge = bus->self;
525 int pos;
526
527 pos = pci_find_capability(bridge, PCI_CAP_ID_AGP);
528 if (!pos)
529 pos = pci_find_capability(bridge, PCI_CAP_ID_AGP3);
530 if (pos) {
531 u32 agpstat, agpcmd;
532
533 pci_read_config_dword(bridge, pos + PCI_AGP_STATUS, &agpstat);
534 bus->max_bus_speed = agp_speed(agpstat & 8, agpstat & 7);
535
536 pci_read_config_dword(bridge, pos + PCI_AGP_COMMAND, &agpcmd);
537 bus->cur_bus_speed = agp_speed(agpstat & 8, agpcmd & 7);
538 }
539
540 pos = pci_find_capability(bridge, PCI_CAP_ID_PCIX);
541 if (pos) {
542 u16 status;
543 enum pci_bus_speed max;
544 pci_read_config_word(bridge, pos + 2, &status);
545
546 if (status & 0x8000) {
547 max = PCI_SPEED_133MHz_PCIX_533;
548 } else if (status & 0x4000) {
549 max = PCI_SPEED_133MHz_PCIX_266;
550 } else if (status & 0x0002) {
551 if (((status >> 12) & 0x3) == 2) {
552 max = PCI_SPEED_133MHz_PCIX_ECC;
553 } else {
554 max = PCI_SPEED_133MHz_PCIX;
555 }
556 } else {
557 max = PCI_SPEED_66MHz_PCIX;
558 }
559
560 bus->max_bus_speed = max;
561 bus->cur_bus_speed = pcix_bus_speed[(status >> 6) & 0xf];
562
563 return;
564 }
565
566 pos = pci_find_capability(bridge, PCI_CAP_ID_EXP);
567 if (pos) {
568 u32 linkcap;
569 u16 linksta;
570
571 pci_read_config_dword(bridge, pos + PCI_EXP_LNKCAP, &linkcap);
572 bus->max_bus_speed = pcie_link_speed[linkcap & 0xf];
573
574 pci_read_config_word(bridge, pos + PCI_EXP_LNKSTA, &linksta);
575 pcie_update_link_speed(bus, linksta);
576 }
577}
578
579
394static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent, 580static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
395 struct pci_dev *bridge, int busnr) 581 struct pci_dev *bridge, int busnr)
396{ 582{
@@ -430,6 +616,8 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
430 child->self = bridge; 616 child->self = bridge;
431 child->bridge = get_device(&bridge->dev); 617 child->bridge = get_device(&bridge->dev);
432 618
619 pci_set_bus_speed(child);
620
433 /* Set up default resource pointers and names.. */ 621 /* Set up default resource pointers and names.. */
434 for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { 622 for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) {
435 child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES+i]; 623 child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES+i];
@@ -1081,6 +1269,45 @@ struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn)
1081} 1269}
1082EXPORT_SYMBOL(pci_scan_single_device); 1270EXPORT_SYMBOL(pci_scan_single_device);
1083 1271
1272static unsigned next_ari_fn(struct pci_dev *dev, unsigned fn)
1273{
1274 u16 cap;
1275 unsigned pos, next_fn;
1276
1277 if (!dev)
1278 return 0;
1279
1280 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI);
1281 if (!pos)
1282 return 0;
1283 pci_read_config_word(dev, pos + 4, &cap);
1284 next_fn = cap >> 8;
1285 if (next_fn <= fn)
1286 return 0;
1287 return next_fn;
1288}
1289
1290static unsigned next_trad_fn(struct pci_dev *dev, unsigned fn)
1291{
1292 return (fn + 1) % 8;
1293}
1294
1295static unsigned no_next_fn(struct pci_dev *dev, unsigned fn)
1296{
1297 return 0;
1298}
1299
1300static int only_one_child(struct pci_bus *bus)
1301{
1302 struct pci_dev *parent = bus->self;
1303 if (!parent || !pci_is_pcie(parent))
1304 return 0;
1305 if (parent->pcie_type == PCI_EXP_TYPE_ROOT_PORT ||
1306 parent->pcie_type == PCI_EXP_TYPE_DOWNSTREAM)
1307 return 1;
1308 return 0;
1309}
1310
1084/** 1311/**
1085 * pci_scan_slot - scan a PCI slot on a bus for devices. 1312 * pci_scan_slot - scan a PCI slot on a bus for devices.
1086 * @bus: PCI bus to scan 1313 * @bus: PCI bus to scan
@@ -1094,21 +1321,30 @@ EXPORT_SYMBOL(pci_scan_single_device);
1094 */ 1321 */
1095int pci_scan_slot(struct pci_bus *bus, int devfn) 1322int pci_scan_slot(struct pci_bus *bus, int devfn)
1096{ 1323{
1097 int fn, nr = 0; 1324 unsigned fn, nr = 0;
1098 struct pci_dev *dev; 1325 struct pci_dev *dev;
1326 unsigned (*next_fn)(struct pci_dev *, unsigned) = no_next_fn;
1327
1328 if (only_one_child(bus) && (devfn > 0))
1329 return 0; /* Already scanned the entire slot */
1099 1330
1100 dev = pci_scan_single_device(bus, devfn); 1331 dev = pci_scan_single_device(bus, devfn);
1101 if (dev && !dev->is_added) /* new device? */ 1332 if (!dev)
1333 return 0;
1334 if (!dev->is_added)
1102 nr++; 1335 nr++;
1103 1336
1104 if (dev && dev->multifunction) { 1337 if (pci_ari_enabled(bus))
1105 for (fn = 1; fn < 8; fn++) { 1338 next_fn = next_ari_fn;
1106 dev = pci_scan_single_device(bus, devfn + fn); 1339 else if (dev->multifunction)
1107 if (dev) { 1340 next_fn = next_trad_fn;
1108 if (!dev->is_added) 1341
1109 nr++; 1342 for (fn = next_fn(dev, 0); fn > 0; fn = next_fn(dev, fn)) {
1110 dev->multifunction = 1; 1343 dev = pci_scan_single_device(bus, devfn + fn);
1111 } 1344 if (dev) {
1345 if (!dev->is_added)
1346 nr++;
1347 dev->multifunction = 1;
1112 } 1348 }
1113 } 1349 }
1114 1350
@@ -1200,6 +1436,7 @@ struct pci_bus * pci_create_bus(struct device *parent,
1200 if (error) 1436 if (error)
1201 goto dev_reg_err; 1437 goto dev_reg_err;
1202 b->bridge = get_device(dev); 1438 b->bridge = get_device(dev);
1439 device_enable_async_suspend(b->bridge);
1203 1440
1204 if (!parent) 1441 if (!parent)
1205 set_dev_node(b->bridge, pcibus_to_node(b)); 1442 set_dev_node(b->bridge, pcibus_to_node(b));
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 456c265b1fe9..039e87b71442 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -25,14 +25,9 @@
25#include <linux/dmi.h> 25#include <linux/dmi.h>
26#include <linux/pci-aspm.h> 26#include <linux/pci-aspm.h>
27#include <linux/ioport.h> 27#include <linux/ioport.h>
28#include <asm/dma.h> /* isa_dma_bridge_buggy */
28#include "pci.h" 29#include "pci.h"
29 30
30int isa_dma_bridge_buggy;
31EXPORT_SYMBOL(isa_dma_bridge_buggy);
32int pci_pci_problems;
33EXPORT_SYMBOL(pci_pci_problems);
34
35#ifdef CONFIG_PCI_QUIRKS
36/* 31/*
37 * This quirk function disables memory decoding and releases memory resources 32 * This quirk function disables memory decoding and releases memory resources
38 * of the device specified by kernel's boot parameter 'pci=resource_alignment='. 33 * of the device specified by kernel's boot parameter 'pci=resource_alignment='.
@@ -2613,6 +2608,7 @@ void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
2613 } 2608 }
2614 pci_do_fixups(dev, start, end); 2609 pci_do_fixups(dev, start, end);
2615} 2610}
2611EXPORT_SYMBOL(pci_fixup_device);
2616 2612
2617static int __init pci_apply_final_quirks(void) 2613static int __init pci_apply_final_quirks(void)
2618{ 2614{
@@ -2724,9 +2720,3 @@ int pci_dev_specific_reset(struct pci_dev *dev, int probe)
2724 2720
2725 return -ENOTTY; 2721 return -ENOTTY;
2726} 2722}
2727
2728#else
2729void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) {}
2730int pci_dev_specific_reset(struct pci_dev *dev, int probe) { return -ENOTTY; }
2731#endif
2732EXPORT_SYMBOL(pci_fixup_device);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c48cd377b3f5..bf32f07c4efb 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -27,37 +27,83 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include "pci.h" 28#include "pci.h"
29 29
30static void pbus_assign_resources_sorted(const struct pci_bus *bus) 30struct resource_list_x {
31{ 31 struct resource_list_x *next;
32 struct pci_dev *dev;
33 struct resource *res; 32 struct resource *res;
34 struct resource_list head, *list, *tmp; 33 struct pci_dev *dev;
35 int idx; 34 resource_size_t start;
35 resource_size_t end;
36 unsigned long flags;
37};
36 38
37 head.next = NULL; 39static void add_to_failed_list(struct resource_list_x *head,
38 list_for_each_entry(dev, &bus->devices, bus_list) { 40 struct pci_dev *dev, struct resource *res)
39 u16 class = dev->class >> 8; 41{
42 struct resource_list_x *list = head;
43 struct resource_list_x *ln = list->next;
44 struct resource_list_x *tmp;
40 45
41 /* Don't touch classless devices or host bridges or ioapics. */ 46 tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
42 if (class == PCI_CLASS_NOT_DEFINED || 47 if (!tmp) {
43 class == PCI_CLASS_BRIDGE_HOST) 48 pr_warning("add_to_failed_list: kmalloc() failed!\n");
44 continue; 49 return;
50 }
45 51
46 /* Don't touch ioapic devices already enabled by firmware */ 52 tmp->next = ln;
47 if (class == PCI_CLASS_SYSTEM_PIC) { 53 tmp->res = res;
48 u16 command; 54 tmp->dev = dev;
49 pci_read_config_word(dev, PCI_COMMAND, &command); 55 tmp->start = res->start;
50 if (command & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) 56 tmp->end = res->end;
51 continue; 57 tmp->flags = res->flags;
52 } 58 list->next = tmp;
59}
60
61static void free_failed_list(struct resource_list_x *head)
62{
63 struct resource_list_x *list, *tmp;
53 64
54 pdev_sort_resources(dev, &head); 65 for (list = head->next; list;) {
66 tmp = list;
67 list = list->next;
68 kfree(tmp);
55 } 69 }
56 70
57 for (list = head.next; list;) { 71 head->next = NULL;
72}
73
74static void __dev_sort_resources(struct pci_dev *dev,
75 struct resource_list *head)
76{
77 u16 class = dev->class >> 8;
78
79 /* Don't touch classless devices or host bridges or ioapics. */
80 if (class == PCI_CLASS_NOT_DEFINED || class == PCI_CLASS_BRIDGE_HOST)
81 return;
82
83 /* Don't touch ioapic devices already enabled by firmware */
84 if (class == PCI_CLASS_SYSTEM_PIC) {
85 u16 command;
86 pci_read_config_word(dev, PCI_COMMAND, &command);
87 if (command & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY))
88 return;
89 }
90
91 pdev_sort_resources(dev, head);
92}
93
94static void __assign_resources_sorted(struct resource_list *head,
95 struct resource_list_x *fail_head)
96{
97 struct resource *res;
98 struct resource_list *list, *tmp;
99 int idx;
100
101 for (list = head->next; list;) {
58 res = list->res; 102 res = list->res;
59 idx = res - &list->dev->resource[0]; 103 idx = res - &list->dev->resource[0];
60 if (pci_assign_resource(list->dev, idx)) { 104 if (pci_assign_resource(list->dev, idx)) {
105 if (fail_head && !pci_is_root_bus(list->dev->bus))
106 add_to_failed_list(fail_head, list->dev, res);
61 res->start = 0; 107 res->start = 0;
62 res->end = 0; 108 res->end = 0;
63 res->flags = 0; 109 res->flags = 0;
@@ -68,6 +114,30 @@ static void pbus_assign_resources_sorted(const struct pci_bus *bus)
68 } 114 }
69} 115}
70 116
117static void pdev_assign_resources_sorted(struct pci_dev *dev,
118 struct resource_list_x *fail_head)
119{
120 struct resource_list head;
121
122 head.next = NULL;
123 __dev_sort_resources(dev, &head);
124 __assign_resources_sorted(&head, fail_head);
125
126}
127
128static void pbus_assign_resources_sorted(const struct pci_bus *bus,
129 struct resource_list_x *fail_head)
130{
131 struct pci_dev *dev;
132 struct resource_list head;
133
134 head.next = NULL;
135 list_for_each_entry(dev, &bus->devices, bus_list)
136 __dev_sort_resources(dev, &head);
137
138 __assign_resources_sorted(&head, fail_head);
139}
140
71void pci_setup_cardbus(struct pci_bus *bus) 141void pci_setup_cardbus(struct pci_bus *bus)
72{ 142{
73 struct pci_dev *bridge = bus->self; 143 struct pci_dev *bridge = bus->self;
@@ -134,18 +204,12 @@ EXPORT_SYMBOL(pci_setup_cardbus);
134 config space writes, so it's quite possible that an I/O window of 204 config space writes, so it's quite possible that an I/O window of
135 the bridge will have some undesirable address (e.g. 0) after the 205 the bridge will have some undesirable address (e.g. 0) after the
136 first write. Ditto 64-bit prefetchable MMIO. */ 206 first write. Ditto 64-bit prefetchable MMIO. */
137static void pci_setup_bridge(struct pci_bus *bus) 207static void pci_setup_bridge_io(struct pci_bus *bus)
138{ 208{
139 struct pci_dev *bridge = bus->self; 209 struct pci_dev *bridge = bus->self;
140 struct resource *res; 210 struct resource *res;
141 struct pci_bus_region region; 211 struct pci_bus_region region;
142 u32 l, bu, lu, io_upper16; 212 u32 l, io_upper16;
143
144 if (pci_is_enabled(bridge))
145 return;
146
147 dev_info(&bridge->dev, "PCI bridge to [bus %02x-%02x]\n",
148 bus->secondary, bus->subordinate);
149 213
150 /* Set up the top and bottom of the PCI I/O segment for this bus. */ 214 /* Set up the top and bottom of the PCI I/O segment for this bus. */
151 res = bus->resource[0]; 215 res = bus->resource[0];
@@ -158,8 +222,7 @@ static void pci_setup_bridge(struct pci_bus *bus)
158 /* Set up upper 16 bits of I/O base/limit. */ 222 /* Set up upper 16 bits of I/O base/limit. */
159 io_upper16 = (region.end & 0xffff0000) | (region.start >> 16); 223 io_upper16 = (region.end & 0xffff0000) | (region.start >> 16);
160 dev_info(&bridge->dev, " bridge window %pR\n", res); 224 dev_info(&bridge->dev, " bridge window %pR\n", res);
161 } 225 } else {
162 else {
163 /* Clear upper 16 bits of I/O base/limit. */ 226 /* Clear upper 16 bits of I/O base/limit. */
164 io_upper16 = 0; 227 io_upper16 = 0;
165 l = 0x00f0; 228 l = 0x00f0;
@@ -171,21 +234,35 @@ static void pci_setup_bridge(struct pci_bus *bus)
171 pci_write_config_dword(bridge, PCI_IO_BASE, l); 234 pci_write_config_dword(bridge, PCI_IO_BASE, l);
172 /* Update upper 16 bits of I/O base/limit. */ 235 /* Update upper 16 bits of I/O base/limit. */
173 pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, io_upper16); 236 pci_write_config_dword(bridge, PCI_IO_BASE_UPPER16, io_upper16);
237}
174 238
175 /* Set up the top and bottom of the PCI Memory segment 239static void pci_setup_bridge_mmio(struct pci_bus *bus)
176 for this bus. */ 240{
241 struct pci_dev *bridge = bus->self;
242 struct resource *res;
243 struct pci_bus_region region;
244 u32 l;
245
246 /* Set up the top and bottom of the PCI Memory segment for this bus. */
177 res = bus->resource[1]; 247 res = bus->resource[1];
178 pcibios_resource_to_bus(bridge, &region, res); 248 pcibios_resource_to_bus(bridge, &region, res);
179 if (res->flags & IORESOURCE_MEM) { 249 if (res->flags & IORESOURCE_MEM) {
180 l = (region.start >> 16) & 0xfff0; 250 l = (region.start >> 16) & 0xfff0;
181 l |= region.end & 0xfff00000; 251 l |= region.end & 0xfff00000;
182 dev_info(&bridge->dev, " bridge window %pR\n", res); 252 dev_info(&bridge->dev, " bridge window %pR\n", res);
183 } 253 } else {
184 else {
185 l = 0x0000fff0; 254 l = 0x0000fff0;
186 dev_info(&bridge->dev, " bridge window [mem disabled]\n"); 255 dev_info(&bridge->dev, " bridge window [mem disabled]\n");
187 } 256 }
188 pci_write_config_dword(bridge, PCI_MEMORY_BASE, l); 257 pci_write_config_dword(bridge, PCI_MEMORY_BASE, l);
258}
259
260static void pci_setup_bridge_mmio_pref(struct pci_bus *bus)
261{
262 struct pci_dev *bridge = bus->self;
263 struct resource *res;
264 struct pci_bus_region region;
265 u32 l, bu, lu;
189 266
190 /* Clear out the upper 32 bits of PREF limit. 267 /* Clear out the upper 32 bits of PREF limit.
191 If PCI_PREF_BASE_UPPER32 was non-zero, this temporarily 268 If PCI_PREF_BASE_UPPER32 was non-zero, this temporarily
@@ -204,8 +281,7 @@ static void pci_setup_bridge(struct pci_bus *bus)
204 lu = upper_32_bits(region.end); 281 lu = upper_32_bits(region.end);
205 } 282 }
206 dev_info(&bridge->dev, " bridge window %pR\n", res); 283 dev_info(&bridge->dev, " bridge window %pR\n", res);
207 } 284 } else {
208 else {
209 l = 0x0000fff0; 285 l = 0x0000fff0;
210 dev_info(&bridge->dev, " bridge window [mem pref disabled]\n"); 286 dev_info(&bridge->dev, " bridge window [mem pref disabled]\n");
211 } 287 }
@@ -214,10 +290,35 @@ static void pci_setup_bridge(struct pci_bus *bus)
214 /* Set the upper 32 bits of PREF base & limit. */ 290 /* Set the upper 32 bits of PREF base & limit. */
215 pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, bu); 291 pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, bu);
216 pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, lu); 292 pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, lu);
293}
294
295static void __pci_setup_bridge(struct pci_bus *bus, unsigned long type)
296{
297 struct pci_dev *bridge = bus->self;
298
299 dev_info(&bridge->dev, "PCI bridge to [bus %02x-%02x]\n",
300 bus->secondary, bus->subordinate);
301
302 if (type & IORESOURCE_IO)
303 pci_setup_bridge_io(bus);
304
305 if (type & IORESOURCE_MEM)
306 pci_setup_bridge_mmio(bus);
307
308 if (type & IORESOURCE_PREFETCH)
309 pci_setup_bridge_mmio_pref(bus);
217 310
218 pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl); 311 pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl);
219} 312}
220 313
314static void pci_setup_bridge(struct pci_bus *bus)
315{
316 unsigned long type = IORESOURCE_IO | IORESOURCE_MEM |
317 IORESOURCE_PREFETCH;
318
319 __pci_setup_bridge(bus, type);
320}
321
221/* Check whether the bridge supports optional I/O and 322/* Check whether the bridge supports optional I/O and
222 prefetchable memory ranges. If not, the respective 323 prefetchable memory ranges. If not, the respective
223 base/limit registers must be read-only and read as 0. */ 324 base/limit registers must be read-only and read as 0. */
@@ -253,8 +354,11 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)
253 } 354 }
254 if (pmem) { 355 if (pmem) {
255 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH; 356 b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
256 if ((pmem & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) 357 if ((pmem & PCI_PREF_RANGE_TYPE_MASK) ==
358 PCI_PREF_RANGE_TYPE_64) {
257 b_res[2].flags |= IORESOURCE_MEM_64; 359 b_res[2].flags |= IORESOURCE_MEM_64;
360 b_res[2].flags |= PCI_PREF_RANGE_TYPE_64;
361 }
258 } 362 }
259 363
260 /* double check if bridge does support 64 bit pref */ 364 /* double check if bridge does support 64 bit pref */
@@ -283,8 +387,7 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned lon
283 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 387 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
284 IORESOURCE_PREFETCH; 388 IORESOURCE_PREFETCH;
285 389
286 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { 390 pci_bus_for_each_resource(bus, r, i) {
287 r = bus->resource[i];
288 if (r == &ioport_resource || r == &iomem_resource) 391 if (r == &ioport_resource || r == &iomem_resource)
289 continue; 392 continue;
290 if (r && (r->flags & type_mask) == type && !r->parent) 393 if (r && (r->flags & type_mask) == type && !r->parent)
@@ -301,7 +404,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size)
301{ 404{
302 struct pci_dev *dev; 405 struct pci_dev *dev;
303 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO); 406 struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO);
304 unsigned long size = 0, size1 = 0; 407 unsigned long size = 0, size1 = 0, old_size;
305 408
306 if (!b_res) 409 if (!b_res)
307 return; 410 return;
@@ -326,12 +429,17 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size)
326 } 429 }
327 if (size < min_size) 430 if (size < min_size)
328 size = min_size; 431 size = min_size;
432 old_size = resource_size(b_res);
433 if (old_size == 1)
434 old_size = 0;
329/* To be fixed in 2.5: we should have sort of HAVE_ISA 435/* To be fixed in 2.5: we should have sort of HAVE_ISA
330 flag in the struct pci_bus. */ 436 flag in the struct pci_bus. */
331#if defined(CONFIG_ISA) || defined(CONFIG_EISA) 437#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
332 size = (size & 0xff) + ((size & ~0xffUL) << 2); 438 size = (size & 0xff) + ((size & ~0xffUL) << 2);
333#endif 439#endif
334 size = ALIGN(size + size1, 4096); 440 size = ALIGN(size + size1, 4096);
441 if (size < old_size)
442 size = old_size;
335 if (!size) { 443 if (!size) {
336 if (b_res->start || b_res->end) 444 if (b_res->start || b_res->end)
337 dev_info(&bus->self->dev, "disabling bridge window " 445 dev_info(&bus->self->dev, "disabling bridge window "
@@ -352,7 +460,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
352 unsigned long type, resource_size_t min_size) 460 unsigned long type, resource_size_t min_size)
353{ 461{
354 struct pci_dev *dev; 462 struct pci_dev *dev;
355 resource_size_t min_align, align, size; 463 resource_size_t min_align, align, size, old_size;
356 resource_size_t aligns[12]; /* Alignments from 1Mb to 2Gb */ 464 resource_size_t aligns[12]; /* Alignments from 1Mb to 2Gb */
357 int order, max_order; 465 int order, max_order;
358 struct resource *b_res = find_free_bus_resource(bus, type); 466 struct resource *b_res = find_free_bus_resource(bus, type);
@@ -402,6 +510,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
402 } 510 }
403 if (size < min_size) 511 if (size < min_size)
404 size = min_size; 512 size = min_size;
513 old_size = resource_size(b_res);
514 if (old_size == 1)
515 old_size = 0;
516 if (size < old_size)
517 size = old_size;
405 518
406 align = 0; 519 align = 0;
407 min_align = 0; 520 min_align = 0;
@@ -538,23 +651,25 @@ void __ref pci_bus_size_bridges(struct pci_bus *bus)
538} 651}
539EXPORT_SYMBOL(pci_bus_size_bridges); 652EXPORT_SYMBOL(pci_bus_size_bridges);
540 653
541void __ref pci_bus_assign_resources(const struct pci_bus *bus) 654static void __ref __pci_bus_assign_resources(const struct pci_bus *bus,
655 struct resource_list_x *fail_head)
542{ 656{
543 struct pci_bus *b; 657 struct pci_bus *b;
544 struct pci_dev *dev; 658 struct pci_dev *dev;
545 659
546 pbus_assign_resources_sorted(bus); 660 pbus_assign_resources_sorted(bus, fail_head);
547 661
548 list_for_each_entry(dev, &bus->devices, bus_list) { 662 list_for_each_entry(dev, &bus->devices, bus_list) {
549 b = dev->subordinate; 663 b = dev->subordinate;
550 if (!b) 664 if (!b)
551 continue; 665 continue;
552 666
553 pci_bus_assign_resources(b); 667 __pci_bus_assign_resources(b, fail_head);
554 668
555 switch (dev->class >> 8) { 669 switch (dev->class >> 8) {
556 case PCI_CLASS_BRIDGE_PCI: 670 case PCI_CLASS_BRIDGE_PCI:
557 pci_setup_bridge(b); 671 if (!pci_is_enabled(dev))
672 pci_setup_bridge(b);
558 break; 673 break;
559 674
560 case PCI_CLASS_BRIDGE_CARDBUS: 675 case PCI_CLASS_BRIDGE_CARDBUS:
@@ -568,15 +683,130 @@ void __ref pci_bus_assign_resources(const struct pci_bus *bus)
568 } 683 }
569 } 684 }
570} 685}
686
687void __ref pci_bus_assign_resources(const struct pci_bus *bus)
688{
689 __pci_bus_assign_resources(bus, NULL);
690}
571EXPORT_SYMBOL(pci_bus_assign_resources); 691EXPORT_SYMBOL(pci_bus_assign_resources);
572 692
693static void __ref __pci_bridge_assign_resources(const struct pci_dev *bridge,
694 struct resource_list_x *fail_head)
695{
696 struct pci_bus *b;
697
698 pdev_assign_resources_sorted((struct pci_dev *)bridge, fail_head);
699
700 b = bridge->subordinate;
701 if (!b)
702 return;
703
704 __pci_bus_assign_resources(b, fail_head);
705
706 switch (bridge->class >> 8) {
707 case PCI_CLASS_BRIDGE_PCI:
708 pci_setup_bridge(b);
709 break;
710
711 case PCI_CLASS_BRIDGE_CARDBUS:
712 pci_setup_cardbus(b);
713 break;
714
715 default:
716 dev_info(&bridge->dev, "not setting up bridge for bus "
717 "%04x:%02x\n", pci_domain_nr(b), b->number);
718 break;
719 }
720}
721static void pci_bridge_release_resources(struct pci_bus *bus,
722 unsigned long type)
723{
724 int idx;
725 bool changed = false;
726 struct pci_dev *dev;
727 struct resource *r;
728 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
729 IORESOURCE_PREFETCH;
730
731 dev = bus->self;
732 for (idx = PCI_BRIDGE_RESOURCES; idx <= PCI_BRIDGE_RESOURCE_END;
733 idx++) {
734 r = &dev->resource[idx];
735 if ((r->flags & type_mask) != type)
736 continue;
737 if (!r->parent)
738 continue;
739 /*
740 * if there are children under that, we should release them
741 * all
742 */
743 release_child_resources(r);
744 if (!release_resource(r)) {
745 dev_printk(KERN_DEBUG, &dev->dev,
746 "resource %d %pR released\n", idx, r);
747 /* keep the old size */
748 r->end = resource_size(r) - 1;
749 r->start = 0;
750 r->flags = 0;
751 changed = true;
752 }
753 }
754
755 if (changed) {
756 /* avoiding touch the one without PREF */
757 if (type & IORESOURCE_PREFETCH)
758 type = IORESOURCE_PREFETCH;
759 __pci_setup_bridge(bus, type);
760 }
761}
762
763enum release_type {
764 leaf_only,
765 whole_subtree,
766};
767/*
768 * try to release pci bridge resources that is from leaf bridge,
769 * so we can allocate big new one later
770 */
771static void __ref pci_bus_release_bridge_resources(struct pci_bus *bus,
772 unsigned long type,
773 enum release_type rel_type)
774{
775 struct pci_dev *dev;
776 bool is_leaf_bridge = true;
777
778 list_for_each_entry(dev, &bus->devices, bus_list) {
779 struct pci_bus *b = dev->subordinate;
780 if (!b)
781 continue;
782
783 is_leaf_bridge = false;
784
785 if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
786 continue;
787
788 if (rel_type == whole_subtree)
789 pci_bus_release_bridge_resources(b, type,
790 whole_subtree);
791 }
792
793 if (pci_is_root_bus(bus))
794 return;
795
796 if ((bus->self->class >> 8) != PCI_CLASS_BRIDGE_PCI)
797 return;
798
799 if ((rel_type == whole_subtree) || is_leaf_bridge)
800 pci_bridge_release_resources(bus, type);
801}
802
573static void pci_bus_dump_res(struct pci_bus *bus) 803static void pci_bus_dump_res(struct pci_bus *bus)
574{ 804{
575 int i; 805 struct resource *res;
806 int i;
576 807
577 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { 808 pci_bus_for_each_resource(bus, res, i) {
578 struct resource *res = bus->resource[i]; 809 if (!res || !res->end || !res->flags)
579 if (!res || !res->end)
580 continue; 810 continue;
581 811
582 dev_printk(KERN_DEBUG, &bus->dev, "resource %d %pR\n", i, res); 812 dev_printk(KERN_DEBUG, &bus->dev, "resource %d %pR\n", i, res);
@@ -600,11 +830,65 @@ static void pci_bus_dump_resources(struct pci_bus *bus)
600 } 830 }
601} 831}
602 832
833static int __init pci_bus_get_depth(struct pci_bus *bus)
834{
835 int depth = 0;
836 struct pci_dev *dev;
837
838 list_for_each_entry(dev, &bus->devices, bus_list) {
839 int ret;
840 struct pci_bus *b = dev->subordinate;
841 if (!b)
842 continue;
843
844 ret = pci_bus_get_depth(b);
845 if (ret + 1 > depth)
846 depth = ret + 1;
847 }
848
849 return depth;
850}
851static int __init pci_get_max_depth(void)
852{
853 int depth = 0;
854 struct pci_bus *bus;
855
856 list_for_each_entry(bus, &pci_root_buses, node) {
857 int ret;
858
859 ret = pci_bus_get_depth(bus);
860 if (ret > depth)
861 depth = ret;
862 }
863
864 return depth;
865}
866
867/*
868 * first try will not touch pci bridge res
869 * second and later try will clear small leaf bridge res
870 * will stop till to the max deepth if can not find good one
871 */
603void __init 872void __init
604pci_assign_unassigned_resources(void) 873pci_assign_unassigned_resources(void)
605{ 874{
606 struct pci_bus *bus; 875 struct pci_bus *bus;
876 int tried_times = 0;
877 enum release_type rel_type = leaf_only;
878 struct resource_list_x head, *list;
879 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
880 IORESOURCE_PREFETCH;
881 unsigned long failed_type;
882 int max_depth = pci_get_max_depth();
883 int pci_try_num;
607 884
885 head.next = NULL;
886
887 pci_try_num = max_depth + 1;
888 printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n",
889 max_depth, pci_try_num);
890
891again:
608 /* Depth first, calculate sizes and alignments of all 892 /* Depth first, calculate sizes and alignments of all
609 subordinate buses. */ 893 subordinate buses. */
610 list_for_each_entry(bus, &pci_root_buses, node) { 894 list_for_each_entry(bus, &pci_root_buses, node) {
@@ -612,12 +896,130 @@ pci_assign_unassigned_resources(void)
612 } 896 }
613 /* Depth last, allocate resources and update the hardware. */ 897 /* Depth last, allocate resources and update the hardware. */
614 list_for_each_entry(bus, &pci_root_buses, node) { 898 list_for_each_entry(bus, &pci_root_buses, node) {
615 pci_bus_assign_resources(bus); 899 __pci_bus_assign_resources(bus, &head);
616 pci_enable_bridges(bus);
617 } 900 }
901 tried_times++;
902
903 /* any device complain? */
904 if (!head.next)
905 goto enable_and_dump;
906 failed_type = 0;
907 for (list = head.next; list;) {
908 failed_type |= list->flags;
909 list = list->next;
910 }
911 /*
912 * io port are tight, don't try extra
913 * or if reach the limit, don't want to try more
914 */
915 failed_type &= type_mask;
916 if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) {
917 free_failed_list(&head);
918 goto enable_and_dump;
919 }
920
921 printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n",
922 tried_times + 1);
923
924 /* third times and later will not check if it is leaf */
925 if ((tried_times + 1) > 2)
926 rel_type = whole_subtree;
927
928 /*
929 * Try to release leaf bridge's resources that doesn't fit resource of
930 * child device under that bridge
931 */
932 for (list = head.next; list;) {
933 bus = list->dev->bus;
934 pci_bus_release_bridge_resources(bus, list->flags & type_mask,
935 rel_type);
936 list = list->next;
937 }
938 /* restore size and flags */
939 for (list = head.next; list;) {
940 struct resource *res = list->res;
941
942 res->start = list->start;
943 res->end = list->end;
944 res->flags = list->flags;
945 if (list->dev->subordinate)
946 res->flags = 0;
947
948 list = list->next;
949 }
950 free_failed_list(&head);
951
952 goto again;
953
954enable_and_dump:
955 /* Depth last, update the hardware. */
956 list_for_each_entry(bus, &pci_root_buses, node)
957 pci_enable_bridges(bus);
618 958
619 /* dump the resource on buses */ 959 /* dump the resource on buses */
620 list_for_each_entry(bus, &pci_root_buses, node) { 960 list_for_each_entry(bus, &pci_root_buses, node) {
621 pci_bus_dump_resources(bus); 961 pci_bus_dump_resources(bus);
622 } 962 }
623} 963}
964
965void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
966{
967 struct pci_bus *parent = bridge->subordinate;
968 int tried_times = 0;
969 struct resource_list_x head, *list;
970 int retval;
971 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
972 IORESOURCE_PREFETCH;
973
974 head.next = NULL;
975
976again:
977 pci_bus_size_bridges(parent);
978 __pci_bridge_assign_resources(bridge, &head);
979 retval = pci_reenable_device(bridge);
980 pci_set_master(bridge);
981 pci_enable_bridges(parent);
982
983 tried_times++;
984
985 if (!head.next)
986 return;
987
988 if (tried_times >= 2) {
989 /* still fail, don't need to try more */
990 free_failed_list(&head);
991 return;
992 }
993
994 printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n",
995 tried_times + 1);
996
997 /*
998 * Try to release leaf bridge's resources that doesn't fit resource of
999 * child device under that bridge
1000 */
1001 for (list = head.next; list;) {
1002 struct pci_bus *bus = list->dev->bus;
1003 unsigned long flags = list->flags;
1004
1005 pci_bus_release_bridge_resources(bus, flags & type_mask,
1006 whole_subtree);
1007 list = list->next;
1008 }
1009 /* restore size and flags */
1010 for (list = head.next; list;) {
1011 struct resource *res = list->res;
1012
1013 res->start = list->start;
1014 res->end = list->end;
1015 res->flags = list->flags;
1016 if (list->dev->subordinate)
1017 res->flags = 0;
1018
1019 list = list->next;
1020 }
1021 free_failed_list(&head);
1022
1023 goto again;
1024}
1025EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);
diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
index 8c02b6c53bdb..49c9e6c9779a 100644
--- a/drivers/pci/slot.c
+++ b/drivers/pci/slot.c
@@ -47,6 +47,55 @@ static ssize_t address_read_file(struct pci_slot *slot, char *buf)
47 slot->number); 47 slot->number);
48} 48}
49 49
50/* these strings match up with the values in pci_bus_speed */
51static char *pci_bus_speed_strings[] = {
52 "33 MHz PCI", /* 0x00 */
53 "66 MHz PCI", /* 0x01 */
54 "66 MHz PCI-X", /* 0x02 */
55 "100 MHz PCI-X", /* 0x03 */
56 "133 MHz PCI-X", /* 0x04 */
57 NULL, /* 0x05 */
58 NULL, /* 0x06 */
59 NULL, /* 0x07 */
60 NULL, /* 0x08 */
61 "66 MHz PCI-X 266", /* 0x09 */
62 "100 MHz PCI-X 266", /* 0x0a */
63 "133 MHz PCI-X 266", /* 0x0b */
64 "Unknown AGP", /* 0x0c */
65 "1x AGP", /* 0x0d */
66 "2x AGP", /* 0x0e */
67 "4x AGP", /* 0x0f */
68 "8x AGP", /* 0x10 */
69 "66 MHz PCI-X 533", /* 0x11 */
70 "100 MHz PCI-X 533", /* 0x12 */
71 "133 MHz PCI-X 533", /* 0x13 */
72 "2.5 GT/s PCIe", /* 0x14 */
73 "5.0 GT/s PCIe", /* 0x15 */
74 "8.0 GT/s PCIe", /* 0x16 */
75};
76
77static ssize_t bus_speed_read(enum pci_bus_speed speed, char *buf)
78{
79 const char *speed_string;
80
81 if (speed < ARRAY_SIZE(pci_bus_speed_strings))
82 speed_string = pci_bus_speed_strings[speed];
83 else
84 speed_string = "Unknown";
85
86 return sprintf(buf, "%s\n", speed_string);
87}
88
89static ssize_t max_speed_read_file(struct pci_slot *slot, char *buf)
90{
91 return bus_speed_read(slot->bus->max_bus_speed, buf);
92}
93
94static ssize_t cur_speed_read_file(struct pci_slot *slot, char *buf)
95{
96 return bus_speed_read(slot->bus->cur_bus_speed, buf);
97}
98
50static void pci_slot_release(struct kobject *kobj) 99static void pci_slot_release(struct kobject *kobj)
51{ 100{
52 struct pci_dev *dev; 101 struct pci_dev *dev;
@@ -66,9 +115,15 @@ static void pci_slot_release(struct kobject *kobj)
66 115
67static struct pci_slot_attribute pci_slot_attr_address = 116static struct pci_slot_attribute pci_slot_attr_address =
68 __ATTR(address, (S_IFREG | S_IRUGO), address_read_file, NULL); 117 __ATTR(address, (S_IFREG | S_IRUGO), address_read_file, NULL);
118static struct pci_slot_attribute pci_slot_attr_max_speed =
119 __ATTR(max_bus_speed, (S_IFREG | S_IRUGO), max_speed_read_file, NULL);
120static struct pci_slot_attribute pci_slot_attr_cur_speed =
121 __ATTR(cur_bus_speed, (S_IFREG | S_IRUGO), cur_speed_read_file, NULL);
69 122
70static struct attribute *pci_slot_default_attrs[] = { 123static struct attribute *pci_slot_default_attrs[] = {
71 &pci_slot_attr_address.attr, 124 &pci_slot_attr_address.attr,
125 &pci_slot_attr_max_speed.attr,
126 &pci_slot_attr_cur_speed.attr,
72 NULL, 127 NULL,
73}; 128};
74 129
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 9f3adbd9f700..0a6601c76809 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -84,7 +84,7 @@ config YENTA
84 tristate "CardBus yenta-compatible bridge support" 84 tristate "CardBus yenta-compatible bridge support"
85 depends on PCI 85 depends on PCI
86 select CARDBUS if !EMBEDDED 86 select CARDBUS if !EMBEDDED
87 select PCCARD_NONSTATIC 87 select PCCARD_NONSTATIC if PCMCIA != n
88 ---help--- 88 ---help---
89 This option enables support for CardBus host bridges. Virtually 89 This option enables support for CardBus host bridges. Virtually
90 all modern PCMCIA bridges are CardBus compatible. A "bridge" is 90 all modern PCMCIA bridges are CardBus compatible. A "bridge" is
@@ -161,9 +161,8 @@ config TCIC
161 161
162config PCMCIA_M8XX 162config PCMCIA_M8XX
163 tristate "MPC8xx PCMCIA support" 163 tristate "MPC8xx PCMCIA support"
164 depends on PCMCIA && PPC && 8xx 164 depends on PCCARD && PPC && 8xx
165 select PCCARD_IODYN 165 select PCCARD_IODYN if PCMCIA != n
166 select PCCARD_NONSTATIC
167 help 166 help
168 Say Y here to include support for PowerPC 8xx series PCMCIA 167 Say Y here to include support for PowerPC 8xx series PCMCIA
169 controller. 168 controller.
@@ -174,6 +173,27 @@ config PCMCIA_AU1X00
174 tristate "Au1x00 pcmcia support" 173 tristate "Au1x00 pcmcia support"
175 depends on SOC_AU1X00 && PCMCIA 174 depends on SOC_AU1X00 && PCMCIA
176 175
176config PCMCIA_ALCHEMY_DEVBOARD
177 tristate "Alchemy Db/Pb1xxx PCMCIA socket services"
178 depends on SOC_AU1X00 && PCMCIA
179 select 64BIT_PHYS_ADDR
180 help
181 Enable this driver of you want PCMCIA support on your Alchemy
182 Db1000, Db/Pb1100, Db/Pb1500, Db/Pb1550, Db/Pb1200 board.
183 NOT suitable for the PB1000!
184
185 This driver is also available as a module called db1xxx_ss.ko
186
187config PCMCIA_XXS1500
188 tristate "MyCable XXS1500 PCMCIA socket support"
189 depends on PCMCIA && MIPS_XXS1500
190 select 64BIT_PHYS_ADDR
191 help
192 Support for the PCMCIA/CF socket interface on MyCable XXS1500
193 systems.
194
195 This driver is also available as a module called xxs1500_ss.ko
196
177config PCMCIA_BCM63XX 197config PCMCIA_BCM63XX
178 tristate "bcm63xx pcmcia support" 198 tristate "bcm63xx pcmcia support"
179 depends on BCM63XX && PCMCIA 199 depends on BCM63XX && PCMCIA
@@ -238,14 +258,12 @@ config PCMCIA_PROBE
238config M32R_PCC 258config M32R_PCC
239 bool "M32R PCMCIA I/F" 259 bool "M32R PCMCIA I/F"
240 depends on M32R && CHIP_M32700 && PCMCIA 260 depends on M32R && CHIP_M32700 && PCMCIA
241 select PCCARD_NONSTATIC
242 help 261 help
243 Say Y here to use the M32R PCMCIA controller. 262 Say Y here to use the M32R PCMCIA controller.
244 263
245config M32R_CFC 264config M32R_CFC
246 bool "M32R CF I/F Controller" 265 bool "M32R CF I/F Controller"
247 depends on M32R && (PLAT_USRV || PLAT_M32700UT || PLAT_MAPPI2 || PLAT_MAPPI3 || PLAT_OPSPUT) 266 depends on M32R && (PLAT_USRV || PLAT_M32700UT || PLAT_MAPPI2 || PLAT_MAPPI3 || PLAT_OPSPUT)
248 select PCCARD_NONSTATIC
249 help 267 help
250 Say Y here to use the M32R CompactFlash controller. 268 Say Y here to use the M32R CompactFlash controller.
251 269
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index 83ff802de544..381b031d9d75 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -2,11 +2,11 @@
2# Makefile for the kernel pcmcia subsystem (c/o David Hinds) 2# Makefile for the kernel pcmcia subsystem (c/o David Hinds)
3# 3#
4 4
5pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o 5pcmcia_core-y += cs.o rsrc_mgr.o socket_sysfs.o
6pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 6pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o
7obj-$(CONFIG_PCCARD) += pcmcia_core.o 7obj-$(CONFIG_PCCARD) += pcmcia_core.o
8 8
9pcmcia-y += ds.o pcmcia_resource.o 9pcmcia-y += ds.o pcmcia_resource.o cistpl.o
10pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o 10pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o
11obj-$(CONFIG_PCMCIA) += pcmcia.o 11obj-$(CONFIG_PCMCIA) += pcmcia.o
12 12
@@ -35,18 +35,10 @@ obj-$(CONFIG_OMAP_CF) += omap_cf.o
35obj-$(CONFIG_BFIN_CFPCMCIA) += bfin_cf_pcmcia.o 35obj-$(CONFIG_BFIN_CFPCMCIA) += bfin_cf_pcmcia.o
36obj-$(CONFIG_AT91_CF) += at91_cf.o 36obj-$(CONFIG_AT91_CF) += at91_cf.o
37obj-$(CONFIG_ELECTRA_CF) += electra_cf.o 37obj-$(CONFIG_ELECTRA_CF) += electra_cf.o
38obj-$(CONFIG_PCMCIA_ALCHEMY_DEVBOARD) += db1xxx_ss.o
38 39
39au1x00_ss-y += au1000_generic.o 40au1x00_ss-y += au1000_generic.o
40au1x00_ss-$(CONFIG_MIPS_PB1000) += au1000_pb1x00.o 41au1x00_ss-$(CONFIG_MIPS_PB1000) += au1000_pb1x00.o
41au1x00_ss-$(CONFIG_MIPS_PB1100) += au1000_pb1x00.o
42au1x00_ss-$(CONFIG_MIPS_PB1200) += au1000_db1x00.o
43au1x00_ss-$(CONFIG_MIPS_PB1500) += au1000_pb1x00.o
44au1x00_ss-$(CONFIG_MIPS_DB1000) += au1000_db1x00.o
45au1x00_ss-$(CONFIG_MIPS_DB1100) += au1000_db1x00.o
46au1x00_ss-$(CONFIG_MIPS_DB1200) += au1000_db1x00.o
47au1x00_ss-$(CONFIG_MIPS_DB1500) += au1000_db1x00.o
48au1x00_ss-$(CONFIG_MIPS_DB1550) += au1000_db1x00.o
49au1x00_ss-$(CONFIG_MIPS_XXS1500) += au1000_xxs1500.o
50 42
51sa1111_cs-y += sa1111_generic.o 43sa1111_cs-y += sa1111_generic.o
52sa1111_cs-$(CONFIG_ASSABET_NEPONSET) += sa1100_neponset.o 44sa1111_cs-$(CONFIG_ASSABET_NEPONSET) += sa1100_neponset.o
@@ -76,3 +68,5 @@ pxa2xx-obj-$(CONFIG_MACH_E740) += pxa2xx_e740.o
76pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o 68pxa2xx-obj-$(CONFIG_MACH_STARGATE2) += pxa2xx_stargate2.o
77 69
78obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y) 70obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_base.o $(pxa2xx-obj-y)
71
72obj-$(CONFIG_PCMCIA_XXS1500) += xxs1500_ss.o
diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c
index e1dccedc5960..5d228071ec69 100644
--- a/drivers/pcmcia/at91_cf.c
+++ b/drivers/pcmcia/at91_cf.c
@@ -52,8 +52,6 @@ struct at91_cf_socket {
52 unsigned long phys_baseaddr; 52 unsigned long phys_baseaddr;
53}; 53};
54 54
55#define SZ_2K (2 * SZ_1K)
56
57static inline int at91_cf_present(struct at91_cf_socket *cf) 55static inline int at91_cf_present(struct at91_cf_socket *cf)
58{ 56{
59 return !gpio_get_value(cf->board->det_pin); 57 return !gpio_get_value(cf->board->det_pin);
diff --git a/drivers/pcmcia/au1000_db1x00.c b/drivers/pcmcia/au1000_db1x00.c
deleted file mode 100644
index c78d77fd7e3b..000000000000
--- a/drivers/pcmcia/au1000_db1x00.c
+++ /dev/null
@@ -1,305 +0,0 @@
1/*
2 *
3 * Alchemy Semi Db1x00 boards specific pcmcia routines.
4 *
5 * Copyright 2002 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc.
7 * ppopov@mvista.com or source@mvista.com
8 *
9 * Copyright 2004 Pete Popov, updated the driver to 2.6.
10 * Followed the sa11xx API and largely copied many of the hardware
11 * independent functions.
12 *
13 * ########################################################################
14 *
15 * This program is free software; you can distribute it and/or modify it
16 * under the terms of the GNU General Public License (Version 2) as
17 * published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
27 *
28 * ########################################################################
29 *
30 *
31 */
32
33#include <linux/module.h>
34#include <linux/kernel.h>
35#include <linux/errno.h>
36#include <linux/interrupt.h>
37#include <linux/device.h>
38#include <linux/init.h>
39
40#include <asm/irq.h>
41#include <asm/signal.h>
42#include <asm/mach-au1x00/au1000.h>
43
44#if defined(CONFIG_MIPS_DB1200)
45 #include <db1200.h>
46#elif defined(CONFIG_MIPS_PB1200)
47 #include <pb1200.h>
48#else
49 #include <asm/mach-db1x00/db1x00.h>
50 static BCSR * const bcsr = (BCSR *)BCSR_KSEG1_ADDR;
51#endif
52
53#include "au1000_generic.h"
54
55#if 0
56#define debug(x,args...) printk(KERN_DEBUG "%s: " x, __func__ , ##args)
57#else
58#define debug(x,args...)
59#endif
60
61
62struct au1000_pcmcia_socket au1000_pcmcia_socket[PCMCIA_NUM_SOCKS];
63extern int au1x00_pcmcia_socket_probe(struct device *, struct pcmcia_low_level *, int, int);
64
65static int db1x00_pcmcia_hw_init(struct au1000_pcmcia_socket *skt)
66{
67#ifdef CONFIG_MIPS_DB1550
68 skt->irq = skt->nr ? AU1000_GPIO_5 : AU1000_GPIO_3;
69#elif defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
70 skt->irq = skt->nr ? BOARD_PC1_INT : BOARD_PC0_INT;
71#else
72 skt->irq = skt->nr ? AU1000_GPIO_5 : AU1000_GPIO_2;
73#endif
74 return 0;
75}
76
77static void db1x00_pcmcia_shutdown(struct au1000_pcmcia_socket *skt)
78{
79 bcsr->pcmcia = 0; /* turn off power */
80 au_sync_delay(2);
81}
82
83static void
84db1x00_pcmcia_socket_state(struct au1000_pcmcia_socket *skt, struct pcmcia_state *state)
85{
86 u32 inserted;
87 unsigned char vs;
88
89 state->ready = 0;
90 state->vs_Xv = 0;
91 state->vs_3v = 0;
92 state->detect = 0;
93
94 switch (skt->nr) {
95 case 0:
96 vs = bcsr->status & 0x3;
97#if defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
98 inserted = BOARD_CARD_INSERTED(0);
99#else
100 inserted = !(bcsr->status & (1<<4));
101#endif
102 break;
103 case 1:
104 vs = (bcsr->status & 0xC)>>2;
105#if defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
106 inserted = BOARD_CARD_INSERTED(1);
107#else
108 inserted = !(bcsr->status & (1<<5));
109#endif
110 break;
111 default:/* should never happen */
112 return;
113 }
114
115 if (inserted)
116 debug("db1x00 socket %d: inserted %d, vs %d pcmcia %x\n",
117 skt->nr, inserted, vs, bcsr->pcmcia);
118
119 if (inserted) {
120 switch (vs) {
121 case 0:
122 case 2:
123 state->vs_3v=1;
124 break;
125 case 3: /* 5V */
126 break;
127 default:
128 /* return without setting 'detect' */
129 printk(KERN_ERR "db1x00 bad VS (%d)\n",
130 vs);
131 }
132 state->detect = 1;
133 state->ready = 1;
134 }
135 else {
136 /* if the card was previously inserted and then ejected,
137 * we should turn off power to it
138 */
139 if ((skt->nr == 0) && (bcsr->pcmcia & BCSR_PCMCIA_PC0RST)) {
140 bcsr->pcmcia &= ~(BCSR_PCMCIA_PC0RST |
141 BCSR_PCMCIA_PC0DRVEN |
142 BCSR_PCMCIA_PC0VPP |
143 BCSR_PCMCIA_PC0VCC);
144 au_sync_delay(10);
145 }
146 else if ((skt->nr == 1) && bcsr->pcmcia & BCSR_PCMCIA_PC1RST) {
147 bcsr->pcmcia &= ~(BCSR_PCMCIA_PC1RST |
148 BCSR_PCMCIA_PC1DRVEN |
149 BCSR_PCMCIA_PC1VPP |
150 BCSR_PCMCIA_PC1VCC);
151 au_sync_delay(10);
152 }
153 }
154
155 state->bvd1=1;
156 state->bvd2=1;
157 state->wrprot=0;
158}
159
160static int
161db1x00_pcmcia_configure_socket(struct au1000_pcmcia_socket *skt, struct socket_state_t *state)
162{
163 u16 pwr;
164 int sock = skt->nr;
165
166 debug("config_skt %d Vcc %dV Vpp %dV, reset %d\n",
167 sock, state->Vcc, state->Vpp,
168 state->flags & SS_RESET);
169
170 /* pcmcia reg was set to zero at init time. Be careful when
171 * initializing a socket not to wipe out the settings of the
172 * other socket.
173 */
174 pwr = bcsr->pcmcia;
175 pwr &= ~(0xf << sock*8); /* clear voltage settings */
176
177 state->Vpp = 0;
178 switch(state->Vcc){
179 case 0: /* Vcc 0 */
180 pwr |= SET_VCC_VPP(0,0,sock);
181 break;
182 case 50: /* Vcc 5V */
183 switch(state->Vpp) {
184 case 0:
185 pwr |= SET_VCC_VPP(2,0,sock);
186 break;
187 case 50:
188 pwr |= SET_VCC_VPP(2,1,sock);
189 break;
190 case 12:
191 pwr |= SET_VCC_VPP(2,2,sock);
192 break;
193 case 33:
194 default:
195 pwr |= SET_VCC_VPP(0,0,sock);
196 printk("%s: bad Vcc/Vpp (%d:%d)\n",
197 __func__,
198 state->Vcc,
199 state->Vpp);
200 break;
201 }
202 break;
203 case 33: /* Vcc 3.3V */
204 switch(state->Vpp) {
205 case 0:
206 pwr |= SET_VCC_VPP(1,0,sock);
207 break;
208 case 12:
209 pwr |= SET_VCC_VPP(1,2,sock);
210 break;
211 case 33:
212 pwr |= SET_VCC_VPP(1,1,sock);
213 break;
214 case 50:
215 default:
216 pwr |= SET_VCC_VPP(0,0,sock);
217 printk("%s: bad Vcc/Vpp (%d:%d)\n",
218 __func__,
219 state->Vcc,
220 state->Vpp);
221 break;
222 }
223 break;
224 default: /* what's this ? */
225 pwr |= SET_VCC_VPP(0,0,sock);
226 printk(KERN_ERR "%s: bad Vcc %d\n",
227 __func__, state->Vcc);
228 break;
229 }
230
231 bcsr->pcmcia = pwr;
232 au_sync_delay(300);
233
234 if (sock == 0) {
235 if (!(state->flags & SS_RESET)) {
236 pwr |= BCSR_PCMCIA_PC0DRVEN;
237 bcsr->pcmcia = pwr;
238 au_sync_delay(300);
239 pwr |= BCSR_PCMCIA_PC0RST;
240 bcsr->pcmcia = pwr;
241 au_sync_delay(100);
242 }
243 else {
244 pwr &= ~(BCSR_PCMCIA_PC0RST | BCSR_PCMCIA_PC0DRVEN);
245 bcsr->pcmcia = pwr;
246 au_sync_delay(100);
247 }
248 }
249 else {
250 if (!(state->flags & SS_RESET)) {
251 pwr |= BCSR_PCMCIA_PC1DRVEN;
252 bcsr->pcmcia = pwr;
253 au_sync_delay(300);
254 pwr |= BCSR_PCMCIA_PC1RST;
255 bcsr->pcmcia = pwr;
256 au_sync_delay(100);
257 }
258 else {
259 pwr &= ~(BCSR_PCMCIA_PC1RST | BCSR_PCMCIA_PC1DRVEN);
260 bcsr->pcmcia = pwr;
261 au_sync_delay(100);
262 }
263 }
264 return 0;
265}
266
267/*
268 * Enable card status IRQs on (re-)initialisation. This can
269 * be called at initialisation, power management event, or
270 * pcmcia event.
271 */
272void db1x00_socket_init(struct au1000_pcmcia_socket *skt)
273{
274 /* nothing to do for now */
275}
276
277/*
278 * Disable card status IRQs and PCMCIA bus on suspend.
279 */
280void db1x00_socket_suspend(struct au1000_pcmcia_socket *skt)
281{
282 /* nothing to do for now */
283}
284
285struct pcmcia_low_level db1x00_pcmcia_ops = {
286 .owner = THIS_MODULE,
287
288 .hw_init = db1x00_pcmcia_hw_init,
289 .hw_shutdown = db1x00_pcmcia_shutdown,
290
291 .socket_state = db1x00_pcmcia_socket_state,
292 .configure_socket = db1x00_pcmcia_configure_socket,
293
294 .socket_init = db1x00_socket_init,
295 .socket_suspend = db1x00_socket_suspend
296};
297
298int au1x_board_init(struct device *dev)
299{
300 int ret = -ENODEV;
301 bcsr->pcmcia = 0; /* turn off power, if it's not already off */
302 au_sync_delay(2);
303 ret = au1x00_pcmcia_socket_probe(dev, &db1x00_pcmcia_ops, 0, 2);
304 return ret;
305}
diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c
index 02088704ac2c..171c8a654887 100644
--- a/drivers/pcmcia/au1000_generic.c
+++ b/drivers/pcmcia/au1000_generic.c
@@ -405,18 +405,16 @@ int au1x00_pcmcia_socket_probe(struct device *dev, struct pcmcia_low_level *ops,
405 skt->virt_io = (void *) 405 skt->virt_io = (void *)
406 (ioremap((phys_t)AU1X_SOCK0_IO, 0x1000) - 406 (ioremap((phys_t)AU1X_SOCK0_IO, 0x1000) -
407 (u32)mips_io_port_base); 407 (u32)mips_io_port_base);
408 skt->phys_attr = AU1X_SOCK0_PSEUDO_PHYS_ATTR; 408 skt->phys_attr = AU1X_SOCK0_PHYS_ATTR;
409 skt->phys_mem = AU1X_SOCK0_PSEUDO_PHYS_MEM; 409 skt->phys_mem = AU1X_SOCK0_PHYS_MEM;
410 } 410 }
411#ifndef CONFIG_MIPS_XXS1500
412 else { 411 else {
413 skt->virt_io = (void *) 412 skt->virt_io = (void *)
414 (ioremap((phys_t)AU1X_SOCK1_IO, 0x1000) - 413 (ioremap((phys_t)AU1X_SOCK1_IO, 0x1000) -
415 (u32)mips_io_port_base); 414 (u32)mips_io_port_base);
416 skt->phys_attr = AU1X_SOCK1_PSEUDO_PHYS_ATTR; 415 skt->phys_attr = AU1X_SOCK1_PHYS_ATTR;
417 skt->phys_mem = AU1X_SOCK1_PSEUDO_PHYS_MEM; 416 skt->phys_mem = AU1X_SOCK1_PHYS_MEM;
418 } 417 }
419#endif
420 pcmcia_base_vaddrs[i] = (u32 *)skt->virt_io; 418 pcmcia_base_vaddrs[i] = (u32 *)skt->virt_io;
421 ret = ops->hw_init(skt); 419 ret = ops->hw_init(skt);
422 420
diff --git a/drivers/pcmcia/au1000_generic.h b/drivers/pcmcia/au1000_generic.h
index 13a4fbc58711..a324d329dea6 100644
--- a/drivers/pcmcia/au1000_generic.h
+++ b/drivers/pcmcia/au1000_generic.h
@@ -36,30 +36,14 @@
36#define AU1X_SOCK0_IO 0xF00000000ULL 36#define AU1X_SOCK0_IO 0xF00000000ULL
37#define AU1X_SOCK0_PHYS_ATTR 0xF40000000ULL 37#define AU1X_SOCK0_PHYS_ATTR 0xF40000000ULL
38#define AU1X_SOCK0_PHYS_MEM 0xF80000000ULL 38#define AU1X_SOCK0_PHYS_MEM 0xF80000000ULL
39/* pseudo 32 bit phys addresses, which get fixed up to the
40 * real 36 bit address in fixup_bigphys_addr() */
41#define AU1X_SOCK0_PSEUDO_PHYS_ATTR 0xF4000000
42#define AU1X_SOCK0_PSEUDO_PHYS_MEM 0xF8000000
43 39
44/* pcmcia socket 1 needs external glue logic so the memory map 40/* pcmcia socket 1 needs external glue logic so the memory map
45 * differs from board to board. 41 * differs from board to board.
46 */ 42 */
47#if defined(CONFIG_MIPS_PB1000) || defined(CONFIG_MIPS_PB1100) || \ 43#if defined(CONFIG_MIPS_PB1000)
48 defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1550) || \
49 defined(CONFIG_MIPS_PB1200)
50#define AU1X_SOCK1_IO 0xF08000000ULL 44#define AU1X_SOCK1_IO 0xF08000000ULL
51#define AU1X_SOCK1_PHYS_ATTR 0xF48000000ULL 45#define AU1X_SOCK1_PHYS_ATTR 0xF48000000ULL
52#define AU1X_SOCK1_PHYS_MEM 0xF88000000ULL 46#define AU1X_SOCK1_PHYS_MEM 0xF88000000ULL
53#define AU1X_SOCK1_PSEUDO_PHYS_ATTR 0xF4800000
54#define AU1X_SOCK1_PSEUDO_PHYS_MEM 0xF8800000
55#elif defined(CONFIG_MIPS_DB1000) || defined(CONFIG_MIPS_DB1100) || \
56 defined(CONFIG_MIPS_DB1500) || defined(CONFIG_MIPS_DB1550) || \
57 defined(CONFIG_MIPS_DB1200)
58#define AU1X_SOCK1_IO 0xF04000000ULL
59#define AU1X_SOCK1_PHYS_ATTR 0xF44000000ULL
60#define AU1X_SOCK1_PHYS_MEM 0xF84000000ULL
61#define AU1X_SOCK1_PSEUDO_PHYS_ATTR 0xF4400000
62#define AU1X_SOCK1_PSEUDO_PHYS_MEM 0xF8400000
63#endif 47#endif
64 48
65struct pcmcia_state { 49struct pcmcia_state {
diff --git a/drivers/pcmcia/au1000_pb1x00.c b/drivers/pcmcia/au1000_pb1x00.c
index b1984ed72d1d..5a979cb8f3e6 100644
--- a/drivers/pcmcia/au1000_pb1x00.c
+++ b/drivers/pcmcia/au1000_pb1x00.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * 2 *
3 * Alchemy Semi Pb1x00 boards specific pcmcia routines. 3 * Alchemy Semi Pb1000 boards specific pcmcia routines.
4 * 4 *
5 * Copyright 2002 MontaVista Software Inc. 5 * Copyright 2002 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc. 6 * Author: MontaVista Software, Inc.
@@ -46,20 +46,11 @@
46 46
47#define debug(fmt, arg...) do { } while (0) 47#define debug(fmt, arg...) do { } while (0)
48 48
49#ifdef CONFIG_MIPS_PB1000
50#include <asm/pb1000.h> 49#include <asm/pb1000.h>
51#define PCMCIA_IRQ AU1000_GPIO_15 50#define PCMCIA_IRQ AU1000_GPIO_15
52#elif defined (CONFIG_MIPS_PB1500)
53#include <asm/pb1500.h>
54#define PCMCIA_IRQ AU1500_GPIO_203
55#elif defined (CONFIG_MIPS_PB1100)
56#include <asm/pb1100.h>
57#define PCMCIA_IRQ AU1000_GPIO_11
58#endif
59 51
60static int pb1x00_pcmcia_init(struct pcmcia_init *init) 52static int pb1x00_pcmcia_init(struct pcmcia_init *init)
61{ 53{
62#ifdef CONFIG_MIPS_PB1000
63 u16 pcr; 54 u16 pcr;
64 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST; 55 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
65 56
@@ -74,21 +65,10 @@ static int pb1x00_pcmcia_init(struct pcmcia_init *init)
74 au_sync_delay(20); 65 au_sync_delay(20);
75 66
76 return PCMCIA_NUM_SOCKS; 67 return PCMCIA_NUM_SOCKS;
77
78#else /* fixme -- take care of the Pb1500 at some point */
79
80 u16 pcr;
81 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
82 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
83 au_writew(pcr, PCMCIA_BOARD_REG);
84 au_sync_delay(500);
85 return PCMCIA_NUM_SOCKS;
86#endif
87} 68}
88 69
89static int pb1x00_pcmcia_shutdown(void) 70static int pb1x00_pcmcia_shutdown(void)
90{ 71{
91#ifdef CONFIG_MIPS_PB1000
92 u16 pcr; 72 u16 pcr;
93 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST; 73 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
94 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0); 74 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
@@ -96,14 +76,6 @@ static int pb1x00_pcmcia_shutdown(void)
96 au_writel(pcr, PB1000_PCR); 76 au_writel(pcr, PB1000_PCR);
97 au_sync_delay(20); 77 au_sync_delay(20);
98 return 0; 78 return 0;
99#else
100 u16 pcr;
101 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
102 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
103 au_writew(pcr, PCMCIA_BOARD_REG);
104 au_sync_delay(2);
105 return 0;
106#endif
107} 79}
108 80
109static int 81static int
@@ -112,21 +84,11 @@ pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
112 u32 inserted0, inserted1; 84 u32 inserted0, inserted1;
113 u16 vs0, vs1; 85 u16 vs0, vs1;
114 86
115#ifdef CONFIG_MIPS_PB1000
116 vs0 = vs1 = (u16)au_readl(PB1000_ACR1); 87 vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
117 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2)); 88 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
118 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2)); 89 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
119 vs0 = (vs0 >> 4) & 0x3; 90 vs0 = (vs0 >> 4) & 0x3;
120 vs1 = (vs1 >> 12) & 0x3; 91 vs1 = (vs1 >> 12) & 0x3;
121#else
122 vs0 = (au_readw(BOARD_STATUS_REG) >> 4) & 0x3;
123#ifdef CONFIG_MIPS_PB1500
124 inserted0 = !((au_readl(GPIO2_PINSTATE) >> 1) & 0x1); /* gpio 201 */
125#else /* Pb1100 */
126 inserted0 = !((au_readl(SYS_PINSTATERD) >> 9) & 0x1); /* gpio 9 */
127#endif
128 inserted1 = 0;
129#endif
130 92
131 state->ready = 0; 93 state->ready = 0;
132 state->vs_Xv = 0; 94 state->vs_Xv = 0;
@@ -203,7 +165,6 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
203 165
204 if(configure->sock > PCMCIA_MAX_SOCK) return -1; 166 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
205 167
206#ifdef CONFIG_MIPS_PB1000
207 pcr = au_readl(PB1000_PCR); 168 pcr = au_readl(PB1000_PCR);
208 169
209 if (configure->sock == 0) { 170 if (configure->sock == 0) {
@@ -323,84 +284,6 @@ pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
323 au_writel(pcr, PB1000_PCR); 284 au_writel(pcr, PB1000_PCR);
324 au_sync_delay(300); 285 au_sync_delay(300);
325 286
326#else
327
328 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf;
329
330 debug("Vcc %dV Vpp %dV, pcr %x, reset %d\n",
331 configure->vcc, configure->vpp, pcr, configure->reset);
332
333
334 switch(configure->vcc){
335 case 0: /* Vcc 0 */
336 pcr |= SET_VCC_VPP(0,0);
337 break;
338 case 50: /* Vcc 5V */
339 switch(configure->vpp) {
340 case 0:
341 pcr |= SET_VCC_VPP(2,0);
342 break;
343 case 50:
344 pcr |= SET_VCC_VPP(2,1);
345 break;
346 case 12:
347 pcr |= SET_VCC_VPP(2,2);
348 break;
349 case 33:
350 default:
351 pcr |= SET_VCC_VPP(0,0);
352 printk("%s: bad Vcc/Vpp (%d:%d)\n",
353 __func__,
354 configure->vcc,
355 configure->vpp);
356 break;
357 }
358 break;
359 case 33: /* Vcc 3.3V */
360 switch(configure->vpp) {
361 case 0:
362 pcr |= SET_VCC_VPP(1,0);
363 break;
364 case 12:
365 pcr |= SET_VCC_VPP(1,2);
366 break;
367 case 33:
368 pcr |= SET_VCC_VPP(1,1);
369 break;
370 case 50:
371 default:
372 pcr |= SET_VCC_VPP(0,0);
373 printk("%s: bad Vcc/Vpp (%d:%d)\n",
374 __func__,
375 configure->vcc,
376 configure->vpp);
377 break;
378 }
379 break;
380 default: /* what's this ? */
381 pcr |= SET_VCC_VPP(0,0);
382 printk(KERN_ERR "%s: bad Vcc %d\n",
383 __func__, configure->vcc);
384 break;
385 }
386
387 au_writew(pcr, PCMCIA_BOARD_REG);
388 au_sync_delay(300);
389
390 if (!configure->reset) {
391 pcr |= PC_DRV_EN;
392 au_writew(pcr, PCMCIA_BOARD_REG);
393 au_sync_delay(100);
394 pcr |= PC_DEASSERT_RST;
395 au_writew(pcr, PCMCIA_BOARD_REG);
396 au_sync_delay(100);
397 }
398 else {
399 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
400 au_writew(pcr, PCMCIA_BOARD_REG);
401 au_sync_delay(100);
402 }
403#endif
404 return 0; 287 return 0;
405} 288}
406 289
diff --git a/drivers/pcmcia/au1000_xxs1500.c b/drivers/pcmcia/au1000_xxs1500.c
deleted file mode 100644
index b43d47b50819..000000000000
--- a/drivers/pcmcia/au1000_xxs1500.c
+++ /dev/null
@@ -1,188 +0,0 @@
1/*
2 *
3 * MyCable board specific pcmcia routines.
4 *
5 * Copyright 2003 MontaVista Software Inc.
6 * Author: Pete Popov, MontaVista Software, Inc.
7 * ppopov@mvista.com or source@mvista.com
8 *
9 * ########################################################################
10 *
11 * This program is free software; you can distribute it and/or modify it
12 * under the terms of the GNU General Public License (Version 2) as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * 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 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 *
24 * ########################################################################
25 *
26 *
27 */
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/delay.h>
31#include <linux/ioport.h>
32#include <linux/kernel.h>
33#include <linux/timer.h>
34#include <linux/mm.h>
35#include <linux/proc_fs.h>
36#include <linux/types.h>
37
38#include <pcmcia/cs_types.h>
39#include <pcmcia/cs.h>
40#include <pcmcia/ss.h>
41#include <pcmcia/cistpl.h>
42#include <pcmcia/bus_ops.h>
43
44#include <asm/io.h>
45#include <asm/irq.h>
46#include <asm/system.h>
47
48#include <asm/au1000.h>
49#include <asm/au1000_pcmcia.h>
50
51#define PCMCIA_MAX_SOCK 0
52#define PCMCIA_NUM_SOCKS (PCMCIA_MAX_SOCK + 1)
53#define PCMCIA_IRQ AU1000_GPIO_4
54
55#if 0
56#define DEBUG(x, args...) printk(__func__ ": " x, ##args)
57#else
58#define DEBUG(x,args...)
59#endif
60
61static int xxs1500_pcmcia_init(struct pcmcia_init *init)
62{
63 return PCMCIA_NUM_SOCKS;
64}
65
66static int xxs1500_pcmcia_shutdown(void)
67{
68 /* turn off power */
69 au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30),
70 GPIO2_OUTPUT);
71 au_sync_delay(100);
72
73 /* assert reset */
74 au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20),
75 GPIO2_OUTPUT);
76 au_sync_delay(100);
77 return 0;
78}
79
80
81static int
82xxs1500_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
83{
84 u32 inserted; u32 vs;
85 unsigned long gpio, gpio2;
86
87 if(sock > PCMCIA_MAX_SOCK) return -1;
88
89 gpio = au_readl(SYS_PINSTATERD);
90 gpio2 = au_readl(GPIO2_PINSTATE);
91
92 vs = gpio2 & ((1<<8) | (1<<9));
93 inserted = (!(gpio & 0x1) && !(gpio & 0x2));
94
95 state->ready = 0;
96 state->vs_Xv = 0;
97 state->vs_3v = 0;
98 state->detect = 0;
99
100 if (inserted) {
101 switch (vs) {
102 case 0:
103 case 1:
104 case 2:
105 state->vs_3v=1;
106 break;
107 case 3: /* 5V */
108 default:
109 /* return without setting 'detect' */
110 printk(KERN_ERR "au1x00_cs: unsupported VS\n",
111 vs);
112 return;
113 }
114 state->detect = 1;
115 }
116
117 if (state->detect) {
118 state->ready = 1;
119 }
120
121 state->bvd1= gpio2 & (1<<10);
122 state->bvd2 = gpio2 & (1<<11);
123 state->wrprot=0;
124 return 1;
125}
126
127
128static int xxs1500_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
129{
130
131 if(info->sock > PCMCIA_MAX_SOCK) return -1;
132 info->irq = PCMCIA_IRQ;
133 return 0;
134}
135
136
137static int
138xxs1500_pcmcia_configure_socket(const struct pcmcia_configure *configure)
139{
140
141 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
142
143 DEBUG("Vcc %dV Vpp %dV, reset %d\n",
144 configure->vcc, configure->vpp, configure->reset);
145
146 switch(configure->vcc){
147 case 33: /* Vcc 3.3V */
148 /* turn on power */
149 DEBUG("turn on power\n");
150 au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<14))|(1<<30),
151 GPIO2_OUTPUT);
152 au_sync_delay(100);
153 break;
154 case 50: /* Vcc 5V */
155 default: /* what's this ? */
156 printk(KERN_ERR "au1x00_cs: unsupported VCC\n");
157 case 0: /* Vcc 0 */
158 /* turn off power */
159 au_sync_delay(100);
160 au_writel(au_readl(GPIO2_PINSTATE) | (1<<14)|(1<<30),
161 GPIO2_OUTPUT);
162 break;
163 }
164
165 if (!configure->reset) {
166 DEBUG("deassert reset\n");
167 au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<4))|(1<<20),
168 GPIO2_OUTPUT);
169 au_sync_delay(100);
170 au_writel((au_readl(GPIO2_PINSTATE) & ~(1<<5))|(1<<21),
171 GPIO2_OUTPUT);
172 }
173 else {
174 DEBUG("assert reset\n");
175 au_writel(au_readl(GPIO2_PINSTATE) | (1<<4)|(1<<20),
176 GPIO2_OUTPUT);
177 }
178 au_sync_delay(100);
179 return 0;
180}
181
182struct pcmcia_low_level xxs1500_pcmcia_ops = {
183 xxs1500_pcmcia_init,
184 xxs1500_pcmcia_shutdown,
185 xxs1500_pcmcia_socket_state,
186 xxs1500_pcmcia_get_irq_info,
187 xxs1500_pcmcia_configure_socket
188};
diff --git a/drivers/pcmcia/bfin_cf_pcmcia.c b/drivers/pcmcia/bfin_cf_pcmcia.c
index 300b368605c9..2482ce7ac6dc 100644
--- a/drivers/pcmcia/bfin_cf_pcmcia.c
+++ b/drivers/pcmcia/bfin_cf_pcmcia.c
@@ -205,7 +205,7 @@ static int __devinit bfin_cf_probe(struct platform_device *pdev)
205 dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n"); 205 dev_info(&pdev->dev, "Blackfin CompactFlash/PCMCIA Socket Driver\n");
206 206
207 irq = platform_get_irq(pdev, 0); 207 irq = platform_get_irq(pdev, 0);
208 if (!irq) 208 if (irq <= 0)
209 return -EINVAL; 209 return -EINVAL;
210 210
211 cd_pfx = platform_get_irq(pdev, 1); /*Card Detect GPIO PIN */ 211 cd_pfx = platform_get_irq(pdev, 1); /*Card Detect GPIO PIN */
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index d99f846451a3..ac0686efbf75 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -20,170 +20,12 @@
20 */ 20 */
21 21
22 22
23#include <linux/module.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
25#include <linux/string.h> 24#include <linux/module.h>
26#include <linux/slab.h>
27#include <linux/mm.h>
28#include <linux/pci.h> 25#include <linux/pci.h>
29#include <linux/ioport.h>
30#include <linux/io.h>
31#include <asm/irq.h>
32 26
33#include <pcmcia/cs_types.h>
34#include <pcmcia/ss.h> 27#include <pcmcia/ss.h>
35#include <pcmcia/cs.h>
36#include <pcmcia/cistpl.h>
37#include "cs_internal.h"
38
39/*====================================================================*/
40
41/* Offsets in the Expansion ROM Image Header */
42#define ROM_SIGNATURE 0x0000 /* 2 bytes */
43#define ROM_DATA_PTR 0x0018 /* 2 bytes */
44
45/* Offsets in the CardBus PC Card Data Structure */
46#define PCDATA_SIGNATURE 0x0000 /* 4 bytes */
47#define PCDATA_VPD_PTR 0x0008 /* 2 bytes */
48#define PCDATA_LENGTH 0x000a /* 2 bytes */
49#define PCDATA_REVISION 0x000c
50#define PCDATA_IMAGE_SZ 0x0010 /* 2 bytes */
51#define PCDATA_ROM_LEVEL 0x0012 /* 2 bytes */
52#define PCDATA_CODE_TYPE 0x0014
53#define PCDATA_INDICATOR 0x0015
54
55/*=====================================================================
56
57 Expansion ROM's have a special layout, and pointers specify an
58 image number and an offset within that image. xlate_rom_addr()
59 converts an image/offset address to an absolute offset from the
60 ROM's base address.
61
62=====================================================================*/
63
64static u_int xlate_rom_addr(void __iomem *b, u_int addr)
65{
66 u_int img = 0, ofs = 0, sz;
67 u_short data;
68 while ((readb(b) == 0x55) && (readb(b + 1) == 0xaa)) {
69 if (img == (addr >> 28))
70 return (addr & 0x0fffffff) + ofs;
71 data = readb(b + ROM_DATA_PTR) + (readb(b + ROM_DATA_PTR + 1) << 8);
72 sz = 512 * (readb(b + data + PCDATA_IMAGE_SZ) +
73 (readb(b + data + PCDATA_IMAGE_SZ + 1) << 8));
74 if ((sz == 0) || (readb(b + data + PCDATA_INDICATOR) & 0x80))
75 break;
76 b += sz;
77 ofs += sz;
78 img++;
79 }
80 return 0;
81}
82
83/*=====================================================================
84
85 These are similar to setup_cis_mem and release_cis_mem for 16-bit
86 cards. The "result" that is used externally is the cb_cis_virt
87 pointer in the struct pcmcia_socket structure.
88
89=====================================================================*/
90
91static void cb_release_cis_mem(struct pcmcia_socket *s)
92{
93 if (s->cb_cis_virt) {
94 dev_dbg(&s->dev, "cb_release_cis_mem()\n");
95 iounmap(s->cb_cis_virt);
96 s->cb_cis_virt = NULL;
97 s->cb_cis_res = NULL;
98 }
99}
100
101static int cb_setup_cis_mem(struct pcmcia_socket *s, struct resource *res)
102{
103 unsigned int start, size;
104
105 if (res == s->cb_cis_res)
106 return 0;
107
108 if (s->cb_cis_res)
109 cb_release_cis_mem(s);
110
111 start = res->start;
112 size = res->end - start + 1;
113 s->cb_cis_virt = ioremap(start, size);
114
115 if (!s->cb_cis_virt)
116 return -1;
117
118 s->cb_cis_res = res;
119
120 return 0;
121}
122
123/*=====================================================================
124
125 This is used by the CIS processing code to read CIS information
126 from a CardBus device.
127
128=====================================================================*/
129
130int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len,
131 void *ptr)
132{
133 struct pci_dev *dev;
134 struct resource *res;
135
136 dev_dbg(&s->dev, "read_cb_mem(%d, %#x, %u)\n", space, addr, len);
137 28
138 dev = pci_get_slot(s->cb_dev->subordinate, 0);
139 if (!dev)
140 goto fail;
141
142 /* Config space? */
143 if (space == 0) {
144 if (addr + len > 0x100)
145 goto failput;
146 for (; len; addr++, ptr++, len--)
147 pci_read_config_byte(dev, addr, ptr);
148 return 0;
149 }
150
151 res = dev->resource + space - 1;
152
153 pci_dev_put(dev);
154
155 if (!res->flags)
156 goto fail;
157
158 if (cb_setup_cis_mem(s, res) != 0)
159 goto fail;
160
161 if (space == 7) {
162 addr = xlate_rom_addr(s->cb_cis_virt, addr);
163 if (addr == 0)
164 goto fail;
165 }
166
167 if (addr + len > res->end - res->start)
168 goto fail;
169
170 memcpy_fromio(ptr, s->cb_cis_virt + addr, len);
171 return 0;
172
173failput:
174 pci_dev_put(dev);
175fail:
176 memset(ptr, 0xff, len);
177 return -1;
178}
179
180/*=====================================================================
181
182 cb_alloc() and cb_free() allocate and free the kernel data
183 structures for a Cardbus device, and handle the lowest level PCI
184 device setup issues.
185
186=====================================================================*/
187 29
188static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq) 30static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq)
189{ 31{
@@ -215,6 +57,13 @@ static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq)
215 } 57 }
216} 58}
217 59
60/**
61 * cb_alloc() - add CardBus device
62 * @s: the pcmcia_socket where the CardBus device is located
63 *
64 * cb_alloc() allocates the kernel data structures for a Cardbus device
65 * and handles the lowest level PCI device setup issues.
66 */
218int __ref cb_alloc(struct pcmcia_socket *s) 67int __ref cb_alloc(struct pcmcia_socket *s)
219{ 68{
220 struct pci_bus *bus = s->cb_dev->subordinate; 69 struct pci_bus *bus = s->cb_dev->subordinate;
@@ -249,12 +98,16 @@ int __ref cb_alloc(struct pcmcia_socket *s)
249 return 0; 98 return 0;
250} 99}
251 100
101/**
102 * cb_free() - remove CardBus device
103 * @s: the pcmcia_socket where the CardBus device was located
104 *
105 * cb_free() handles the lowest level PCI device cleanup.
106 */
252void cb_free(struct pcmcia_socket *s) 107void cb_free(struct pcmcia_socket *s)
253{ 108{
254 struct pci_dev *bridge = s->cb_dev; 109 struct pci_dev *bridge = s->cb_dev;
255 110
256 cb_release_cis_mem(s);
257
258 if (bridge) 111 if (bridge)
259 pci_remove_behind_bridge(bridge); 112 pci_remove_behind_bridge(bridge);
260} 113}
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 25b1cd219e37..2f3622dd4b69 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -64,6 +64,7 @@ module_param(cis_width, int, 0444);
64 64
65void release_cis_mem(struct pcmcia_socket *s) 65void release_cis_mem(struct pcmcia_socket *s)
66{ 66{
67 mutex_lock(&s->ops_mutex);
67 if (s->cis_mem.flags & MAP_ACTIVE) { 68 if (s->cis_mem.flags & MAP_ACTIVE) {
68 s->cis_mem.flags &= ~MAP_ACTIVE; 69 s->cis_mem.flags &= ~MAP_ACTIVE;
69 s->ops->set_mem_map(s, &s->cis_mem); 70 s->ops->set_mem_map(s, &s->cis_mem);
@@ -75,13 +76,15 @@ void release_cis_mem(struct pcmcia_socket *s)
75 iounmap(s->cis_virt); 76 iounmap(s->cis_virt);
76 s->cis_virt = NULL; 77 s->cis_virt = NULL;
77 } 78 }
79 mutex_unlock(&s->ops_mutex);
78} 80}
79EXPORT_SYMBOL(release_cis_mem);
80 81
81/* 82/*
82 * Map the card memory at "card_offset" into virtual space. 83 * Map the card memory at "card_offset" into virtual space.
83 * If flags & MAP_ATTRIB, map the attribute space, otherwise 84 * If flags & MAP_ATTRIB, map the attribute space, otherwise
84 * map the memory space. 85 * map the memory space.
86 *
87 * Must be called with ops_mutex held.
85 */ 88 */
86static void __iomem * 89static void __iomem *
87set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags) 90set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flags)
@@ -140,6 +143,7 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
140 143
141 dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len); 144 dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len);
142 145
146 mutex_lock(&s->ops_mutex);
143 if (attr & IS_INDIRECT) { 147 if (attr & IS_INDIRECT) {
144 /* Indirect accesses use a bunch of special registers at fixed 148 /* Indirect accesses use a bunch of special registers at fixed
145 locations in common memory */ 149 locations in common memory */
@@ -151,7 +155,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
151 155
152 sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); 156 sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0));
153 if (!sys) { 157 if (!sys) {
158 dev_dbg(&s->dev, "could not map memory\n");
154 memset(ptr, 0xff, len); 159 memset(ptr, 0xff, len);
160 mutex_unlock(&s->ops_mutex);
155 return -1; 161 return -1;
156 } 162 }
157 163
@@ -165,6 +171,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
165 } else { 171 } else {
166 u_int inc = 1, card_offset, flags; 172 u_int inc = 1, card_offset, flags;
167 173
174 if (addr > CISTPL_MAX_CIS_SIZE)
175 dev_dbg(&s->dev, "attempt to read CIS mem at addr %#x", addr);
176
168 flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0); 177 flags = MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0);
169 if (attr) { 178 if (attr) {
170 flags |= MAP_ATTRIB; 179 flags |= MAP_ATTRIB;
@@ -176,7 +185,9 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
176 while (len) { 185 while (len) {
177 sys = set_cis_map(s, card_offset, flags); 186 sys = set_cis_map(s, card_offset, flags);
178 if (!sys) { 187 if (!sys) {
188 dev_dbg(&s->dev, "could not map memory\n");
179 memset(ptr, 0xff, len); 189 memset(ptr, 0xff, len);
190 mutex_unlock(&s->ops_mutex);
180 return -1; 191 return -1;
181 } 192 }
182 end = sys + s->map_size; 193 end = sys + s->map_size;
@@ -190,12 +201,12 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
190 addr = 0; 201 addr = 0;
191 } 202 }
192 } 203 }
204 mutex_unlock(&s->ops_mutex);
193 dev_dbg(&s->dev, " %#2.2x %#2.2x %#2.2x %#2.2x ...\n", 205 dev_dbg(&s->dev, " %#2.2x %#2.2x %#2.2x %#2.2x ...\n",
194 *(u_char *)(ptr+0), *(u_char *)(ptr+1), 206 *(u_char *)(ptr+0), *(u_char *)(ptr+1),
195 *(u_char *)(ptr+2), *(u_char *)(ptr+3)); 207 *(u_char *)(ptr+2), *(u_char *)(ptr+3));
196 return 0; 208 return 0;
197} 209}
198EXPORT_SYMBOL(pcmcia_read_cis_mem);
199 210
200 211
201void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr, 212void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
@@ -206,6 +217,7 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
206 217
207 dev_dbg(&s->dev, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len); 218 dev_dbg(&s->dev, "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len);
208 219
220 mutex_lock(&s->ops_mutex);
209 if (attr & IS_INDIRECT) { 221 if (attr & IS_INDIRECT) {
210 /* Indirect accesses use a bunch of special registers at fixed 222 /* Indirect accesses use a bunch of special registers at fixed
211 locations in common memory */ 223 locations in common memory */
@@ -216,8 +228,11 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
216 } 228 }
217 229
218 sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0)); 230 sys = set_cis_map(s, 0, MAP_ACTIVE | ((cis_width) ? MAP_16BIT : 0));
219 if (!sys) 231 if (!sys) {
232 dev_dbg(&s->dev, "could not map memory\n");
233 mutex_unlock(&s->ops_mutex);
220 return; /* FIXME: Error */ 234 return; /* FIXME: Error */
235 }
221 236
222 writeb(flags, sys+CISREG_ICTRL0); 237 writeb(flags, sys+CISREG_ICTRL0);
223 writeb(addr & 0xff, sys+CISREG_IADDR0); 238 writeb(addr & 0xff, sys+CISREG_IADDR0);
@@ -239,8 +254,11 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
239 card_offset = addr & ~(s->map_size-1); 254 card_offset = addr & ~(s->map_size-1);
240 while (len) { 255 while (len) {
241 sys = set_cis_map(s, card_offset, flags); 256 sys = set_cis_map(s, card_offset, flags);
242 if (!sys) 257 if (!sys) {
258 dev_dbg(&s->dev, "could not map memory\n");
259 mutex_unlock(&s->ops_mutex);
243 return; /* FIXME: error */ 260 return; /* FIXME: error */
261 }
244 262
245 end = sys + s->map_size; 263 end = sys + s->map_size;
246 sys = sys + (addr & (s->map_size-1)); 264 sys = sys + (addr & (s->map_size-1));
@@ -253,8 +271,8 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
253 addr = 0; 271 addr = 0;
254 } 272 }
255 } 273 }
274 mutex_unlock(&s->ops_mutex);
256} 275}
257EXPORT_SYMBOL(pcmcia_write_cis_mem);
258 276
259 277
260/*====================================================================== 278/*======================================================================
@@ -265,32 +283,36 @@ EXPORT_SYMBOL(pcmcia_write_cis_mem);
265 283
266======================================================================*/ 284======================================================================*/
267 285
268static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, 286static int read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
269 size_t len, void *ptr) 287 size_t len, void *ptr)
270{ 288{
271 struct cis_cache_entry *cis; 289 struct cis_cache_entry *cis;
272 int ret; 290 int ret = 0;
273 291
274 if (s->fake_cis) { 292 if (s->state & SOCKET_CARDBUS)
275 if (s->fake_cis_len >= addr+len) 293 return -EINVAL;
276 memcpy(ptr, s->fake_cis+addr, len);
277 else
278 memset(ptr, 0xff, len);
279 return;
280 }
281 294
282 list_for_each_entry(cis, &s->cis_cache, node) { 295 mutex_lock(&s->ops_mutex);
283 if (cis->addr == addr && cis->len == len && cis->attr == attr) { 296 if (s->fake_cis) {
284 memcpy(ptr, cis->cache, len); 297 if (s->fake_cis_len >= addr+len)
285 return; 298 memcpy(ptr, s->fake_cis+addr, len);
299 else {
300 memset(ptr, 0xff, len);
301 ret = -EINVAL;
302 }
303 mutex_unlock(&s->ops_mutex);
304 return ret;
286 } 305 }
287 }
288 306
289#ifdef CONFIG_CARDBUS 307 list_for_each_entry(cis, &s->cis_cache, node) {
290 if (s->state & SOCKET_CARDBUS) 308 if (cis->addr == addr && cis->len == len && cis->attr == attr) {
291 ret = read_cb_mem(s, attr, addr, len, ptr); 309 memcpy(ptr, cis->cache, len);
292 else 310 mutex_unlock(&s->ops_mutex);
293#endif 311 return 0;
312 }
313 }
314 mutex_unlock(&s->ops_mutex);
315
294 ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr); 316 ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr);
295 317
296 if (ret == 0) { 318 if (ret == 0) {
@@ -301,9 +323,12 @@ static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
301 cis->len = len; 323 cis->len = len;
302 cis->attr = attr; 324 cis->attr = attr;
303 memcpy(cis->cache, ptr, len); 325 memcpy(cis->cache, ptr, len);
326 mutex_lock(&s->ops_mutex);
304 list_add(&cis->node, &s->cis_cache); 327 list_add(&cis->node, &s->cis_cache);
328 mutex_unlock(&s->ops_mutex);
305 } 329 }
306 } 330 }
331 return ret;
307} 332}
308 333
309static void 334static void
@@ -311,32 +336,35 @@ remove_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, u_int len)
311{ 336{
312 struct cis_cache_entry *cis; 337 struct cis_cache_entry *cis;
313 338
339 mutex_lock(&s->ops_mutex);
314 list_for_each_entry(cis, &s->cis_cache, node) 340 list_for_each_entry(cis, &s->cis_cache, node)
315 if (cis->addr == addr && cis->len == len && cis->attr == attr) { 341 if (cis->addr == addr && cis->len == len && cis->attr == attr) {
316 list_del(&cis->node); 342 list_del(&cis->node);
317 kfree(cis); 343 kfree(cis);
318 break; 344 break;
319 } 345 }
346 mutex_unlock(&s->ops_mutex);
320} 347}
321 348
349/**
350 * destroy_cis_cache() - destroy the CIS cache
351 * @s: pcmcia_socket for which CIS cache shall be destroyed
352 *
353 * This destroys the CIS cache but keeps any fake CIS alive. Must be
354 * called with ops_mutex held.
355 */
356
322void destroy_cis_cache(struct pcmcia_socket *s) 357void destroy_cis_cache(struct pcmcia_socket *s)
323{ 358{
324 struct list_head *l, *n; 359 struct list_head *l, *n;
360 struct cis_cache_entry *cis;
325 361
326 list_for_each_safe(l, n, &s->cis_cache) { 362 list_for_each_safe(l, n, &s->cis_cache) {
327 struct cis_cache_entry *cis = list_entry(l, struct cis_cache_entry, node); 363 cis = list_entry(l, struct cis_cache_entry, node);
328
329 list_del(&cis->node); 364 list_del(&cis->node);
330 kfree(cis); 365 kfree(cis);
331 } 366 }
332
333 /*
334 * If there was a fake CIS, destroy that as well.
335 */
336 kfree(s->fake_cis);
337 s->fake_cis = NULL;
338} 367}
339EXPORT_SYMBOL(destroy_cis_cache);
340 368
341/*====================================================================== 369/*======================================================================
342 370
@@ -349,6 +377,10 @@ int verify_cis_cache(struct pcmcia_socket *s)
349{ 377{
350 struct cis_cache_entry *cis; 378 struct cis_cache_entry *cis;
351 char *buf; 379 char *buf;
380 int ret;
381
382 if (s->state & SOCKET_CARDBUS)
383 return -EINVAL;
352 384
353 buf = kmalloc(256, GFP_KERNEL); 385 buf = kmalloc(256, GFP_KERNEL);
354 if (buf == NULL) { 386 if (buf == NULL) {
@@ -361,14 +393,9 @@ int verify_cis_cache(struct pcmcia_socket *s)
361 393
362 if (len > 256) 394 if (len > 256)
363 len = 256; 395 len = 256;
364#ifdef CONFIG_CARDBUS
365 if (s->state & SOCKET_CARDBUS)
366 read_cb_mem(s, cis->attr, cis->addr, len, buf);
367 else
368#endif
369 pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf);
370 396
371 if (memcmp(buf, cis->cache, len) != 0) { 397 ret = pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf);
398 if (ret || memcmp(buf, cis->cache, len) != 0) {
372 kfree(buf); 399 kfree(buf);
373 return -1; 400 return -1;
374 } 401 }
@@ -391,17 +418,20 @@ int pcmcia_replace_cis(struct pcmcia_socket *s,
391 dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n"); 418 dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n");
392 return -EINVAL; 419 return -EINVAL;
393 } 420 }
421 mutex_lock(&s->ops_mutex);
394 kfree(s->fake_cis); 422 kfree(s->fake_cis);
395 s->fake_cis = kmalloc(len, GFP_KERNEL); 423 s->fake_cis = kmalloc(len, GFP_KERNEL);
396 if (s->fake_cis == NULL) { 424 if (s->fake_cis == NULL) {
397 dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n"); 425 dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n");
426 mutex_unlock(&s->ops_mutex);
398 return -ENOMEM; 427 return -ENOMEM;
399 } 428 }
400 s->fake_cis_len = len; 429 s->fake_cis_len = len;
401 memcpy(s->fake_cis, data, len); 430 memcpy(s->fake_cis, data, len);
431 dev_info(&s->dev, "Using replacement CIS\n");
432 mutex_unlock(&s->ops_mutex);
402 return 0; 433 return 0;
403} 434}
404EXPORT_SYMBOL(pcmcia_replace_cis);
405 435
406/*====================================================================== 436/*======================================================================
407 437
@@ -425,25 +455,16 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple
425{ 455{
426 if (!s) 456 if (!s)
427 return -EINVAL; 457 return -EINVAL;
428 if (!(s->state & SOCKET_PRESENT)) 458
459 if (!(s->state & SOCKET_PRESENT) || (s->state & SOCKET_CARDBUS))
429 return -ENODEV; 460 return -ENODEV;
430 tuple->TupleLink = tuple->Flags = 0; 461 tuple->TupleLink = tuple->Flags = 0;
431#ifdef CONFIG_CARDBUS 462
432 if (s->state & SOCKET_CARDBUS) { 463 /* Assume presence of a LONGLINK_C to address 0 */
433 struct pci_dev *dev = s->cb_dev; 464 tuple->CISOffset = tuple->LinkOffset = 0;
434 u_int ptr; 465 SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1;
435 pci_bus_read_config_dword(dev->subordinate, 0, PCI_CARDBUS_CIS, &ptr); 466
436 tuple->CISOffset = ptr & ~7; 467 if ((s->functions > 1) && !(tuple->Attributes & TUPLE_RETURN_COMMON)) {
437 SPACE(tuple->Flags) = (ptr & 7);
438 } else
439#endif
440 {
441 /* Assume presence of a LONGLINK_C to address 0 */
442 tuple->CISOffset = tuple->LinkOffset = 0;
443 SPACE(tuple->Flags) = HAS_LINK(tuple->Flags) = 1;
444 }
445 if (!(s->state & SOCKET_CARDBUS) && (s->functions > 1) &&
446 !(tuple->Attributes & TUPLE_RETURN_COMMON)) {
447 cisdata_t req = tuple->DesiredTuple; 468 cisdata_t req = tuple->DesiredTuple;
448 tuple->DesiredTuple = CISTPL_LONGLINK_MFC; 469 tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
449 if (pccard_get_next_tuple(s, function, tuple) == 0) { 470 if (pccard_get_next_tuple(s, function, tuple) == 0) {
@@ -456,17 +477,19 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple
456 } 477 }
457 return pccard_get_next_tuple(s, function, tuple); 478 return pccard_get_next_tuple(s, function, tuple);
458} 479}
459EXPORT_SYMBOL(pccard_get_first_tuple);
460 480
461static int follow_link(struct pcmcia_socket *s, tuple_t *tuple) 481static int follow_link(struct pcmcia_socket *s, tuple_t *tuple)
462{ 482{
463 u_char link[5]; 483 u_char link[5];
464 u_int ofs; 484 u_int ofs;
485 int ret;
465 486
466 if (MFC_FN(tuple->Flags)) { 487 if (MFC_FN(tuple->Flags)) {
467 /* Get indirect link from the MFC tuple */ 488 /* Get indirect link from the MFC tuple */
468 read_cis_cache(s, LINK_SPACE(tuple->Flags), 489 ret = read_cis_cache(s, LINK_SPACE(tuple->Flags),
469 tuple->LinkOffset, 5, link); 490 tuple->LinkOffset, 5, link);
491 if (ret)
492 return -1;
470 ofs = get_unaligned_le32(link + 1); 493 ofs = get_unaligned_le32(link + 1);
471 SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR); 494 SPACE(tuple->Flags) = (link[0] == CISTPL_MFC_ATTR);
472 /* Move to the next indirect link */ 495 /* Move to the next indirect link */
@@ -479,10 +502,12 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple)
479 } else { 502 } else {
480 return -1; 503 return -1;
481 } 504 }
482 if (!(s->state & SOCKET_CARDBUS) && SPACE(tuple->Flags)) { 505 if (SPACE(tuple->Flags)) {
483 /* This is ugly, but a common CIS error is to code the long 506 /* This is ugly, but a common CIS error is to code the long
484 link offset incorrectly, so we check the right spot... */ 507 link offset incorrectly, so we check the right spot... */
485 read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); 508 ret = read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link);
509 if (ret)
510 return -1;
486 if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && 511 if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) &&
487 (strncmp(link+2, "CIS", 3) == 0)) 512 (strncmp(link+2, "CIS", 3) == 0))
488 return ofs; 513 return ofs;
@@ -490,7 +515,9 @@ static int follow_link(struct pcmcia_socket *s, tuple_t *tuple)
490 /* Then, we try the wrong spot... */ 515 /* Then, we try the wrong spot... */
491 ofs = ofs >> 1; 516 ofs = ofs >> 1;
492 } 517 }
493 read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link); 518 ret = read_cis_cache(s, SPACE(tuple->Flags), ofs, 5, link);
519 if (ret)
520 return -1;
494 if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) && 521 if ((link[0] == CISTPL_LINKTARGET) && (link[1] >= 3) &&
495 (strncmp(link+2, "CIS", 3) == 0)) 522 (strncmp(link+2, "CIS", 3) == 0))
496 return ofs; 523 return ofs;
@@ -502,10 +529,11 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
502{ 529{
503 u_char link[2], tmp; 530 u_char link[2], tmp;
504 int ofs, i, attr; 531 int ofs, i, attr;
532 int ret;
505 533
506 if (!s) 534 if (!s)
507 return -EINVAL; 535 return -EINVAL;
508 if (!(s->state & SOCKET_PRESENT)) 536 if (!(s->state & SOCKET_PRESENT) || (s->state & SOCKET_CARDBUS))
509 return -ENODEV; 537 return -ENODEV;
510 538
511 link[1] = tuple->TupleLink; 539 link[1] = tuple->TupleLink;
@@ -516,7 +544,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
516 if (link[1] == 0xff) { 544 if (link[1] == 0xff) {
517 link[0] = CISTPL_END; 545 link[0] = CISTPL_END;
518 } else { 546 } else {
519 read_cis_cache(s, attr, ofs, 2, link); 547 ret = read_cis_cache(s, attr, ofs, 2, link);
548 if (ret)
549 return -1;
520 if (link[0] == CISTPL_NULL) { 550 if (link[0] == CISTPL_NULL) {
521 ofs++; continue; 551 ofs++; continue;
522 } 552 }
@@ -528,7 +558,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
528 if (ofs < 0) 558 if (ofs < 0)
529 return -ENOSPC; 559 return -ENOSPC;
530 attr = SPACE(tuple->Flags); 560 attr = SPACE(tuple->Flags);
531 read_cis_cache(s, attr, ofs, 2, link); 561 ret = read_cis_cache(s, attr, ofs, 2, link);
562 if (ret)
563 return -1;
532 } 564 }
533 565
534 /* Is this a link tuple? Make a note of it */ 566 /* Is this a link tuple? Make a note of it */
@@ -542,12 +574,16 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
542 case CISTPL_LONGLINK_A: 574 case CISTPL_LONGLINK_A:
543 HAS_LINK(tuple->Flags) = 1; 575 HAS_LINK(tuple->Flags) = 1;
544 LINK_SPACE(tuple->Flags) = attr | IS_ATTR; 576 LINK_SPACE(tuple->Flags) = attr | IS_ATTR;
545 read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); 577 ret = read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset);
578 if (ret)
579 return -1;
546 break; 580 break;
547 case CISTPL_LONGLINK_C: 581 case CISTPL_LONGLINK_C:
548 HAS_LINK(tuple->Flags) = 1; 582 HAS_LINK(tuple->Flags) = 1;
549 LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR; 583 LINK_SPACE(tuple->Flags) = attr & ~IS_ATTR;
550 read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset); 584 ret = read_cis_cache(s, attr, ofs+2, 4, &tuple->LinkOffset);
585 if (ret)
586 return -1;
551 break; 587 break;
552 case CISTPL_INDIRECT: 588 case CISTPL_INDIRECT:
553 HAS_LINK(tuple->Flags) = 1; 589 HAS_LINK(tuple->Flags) = 1;
@@ -559,7 +595,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
559 LINK_SPACE(tuple->Flags) = attr; 595 LINK_SPACE(tuple->Flags) = attr;
560 if (function == BIND_FN_ALL) { 596 if (function == BIND_FN_ALL) {
561 /* Follow all the MFC links */ 597 /* Follow all the MFC links */
562 read_cis_cache(s, attr, ofs+2, 1, &tmp); 598 ret = read_cis_cache(s, attr, ofs+2, 1, &tmp);
599 if (ret)
600 return -1;
563 MFC_FN(tuple->Flags) = tmp; 601 MFC_FN(tuple->Flags) = tmp;
564 } else { 602 } else {
565 /* Follow exactly one of the links */ 603 /* Follow exactly one of the links */
@@ -592,7 +630,6 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
592 tuple->CISOffset = ofs + 2; 630 tuple->CISOffset = ofs + 2;
593 return 0; 631 return 0;
594} 632}
595EXPORT_SYMBOL(pccard_get_next_tuple);
596 633
597/*====================================================================*/ 634/*====================================================================*/
598 635
@@ -601,6 +638,7 @@ EXPORT_SYMBOL(pccard_get_next_tuple);
601int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple) 638int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple)
602{ 639{
603 u_int len; 640 u_int len;
641 int ret;
604 642
605 if (!s) 643 if (!s)
606 return -EINVAL; 644 return -EINVAL;
@@ -611,12 +649,13 @@ int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple)
611 tuple->TupleDataLen = tuple->TupleLink; 649 tuple->TupleDataLen = tuple->TupleLink;
612 if (len == 0) 650 if (len == 0)
613 return 0; 651 return 0;
614 read_cis_cache(s, SPACE(tuple->Flags), 652 ret = read_cis_cache(s, SPACE(tuple->Flags),
615 tuple->CISOffset + tuple->TupleOffset, 653 tuple->CISOffset + tuple->TupleOffset,
616 _MIN(len, tuple->TupleDataMax), tuple->TupleData); 654 _MIN(len, tuple->TupleDataMax), tuple->TupleData);
655 if (ret)
656 return -1;
617 return 0; 657 return 0;
618} 658}
619EXPORT_SYMBOL(pccard_get_tuple_data);
620 659
621 660
622/*====================================================================== 661/*======================================================================
@@ -1190,119 +1229,6 @@ static int parse_cftable_entry(tuple_t *tuple,
1190 1229
1191/*====================================================================*/ 1230/*====================================================================*/
1192 1231
1193#ifdef CONFIG_CARDBUS
1194
1195static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar)
1196{
1197 u_char *p;
1198 if (tuple->TupleDataLen < 6)
1199 return -EINVAL;
1200 p = (u_char *)tuple->TupleData;
1201 bar->attr = *p;
1202 p += 2;
1203 bar->size = get_unaligned_le32(p);
1204 return 0;
1205}
1206
1207static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config)
1208{
1209 u_char *p;
1210
1211 p = (u_char *)tuple->TupleData;
1212 if ((*p != 3) || (tuple->TupleDataLen < 6))
1213 return -EINVAL;
1214 config->last_idx = *(++p);
1215 p++;
1216 config->base = get_unaligned_le32(p);
1217 config->subtuples = tuple->TupleDataLen - 6;
1218 return 0;
1219}
1220
1221static int parse_cftable_entry_cb(tuple_t *tuple,
1222 cistpl_cftable_entry_cb_t *entry)
1223{
1224 u_char *p, *q, features;
1225
1226 p = tuple->TupleData;
1227 q = p + tuple->TupleDataLen;
1228 entry->index = *p & 0x3f;
1229 entry->flags = 0;
1230 if (*p & 0x40)
1231 entry->flags |= CISTPL_CFTABLE_DEFAULT;
1232
1233 /* Process optional features */
1234 if (++p == q)
1235 return -EINVAL;
1236 features = *p; p++;
1237
1238 /* Power options */
1239 if ((features & 3) > 0) {
1240 p = parse_power(p, q, &entry->vcc);
1241 if (p == NULL)
1242 return -EINVAL;
1243 } else
1244 entry->vcc.present = 0;
1245 if ((features & 3) > 1) {
1246 p = parse_power(p, q, &entry->vpp1);
1247 if (p == NULL)
1248 return -EINVAL;
1249 } else
1250 entry->vpp1.present = 0;
1251 if ((features & 3) > 2) {
1252 p = parse_power(p, q, &entry->vpp2);
1253 if (p == NULL)
1254 return -EINVAL;
1255 } else
1256 entry->vpp2.present = 0;
1257
1258 /* I/O window options */
1259 if (features & 0x08) {
1260 if (p == q)
1261 return -EINVAL;
1262 entry->io = *p; p++;
1263 } else
1264 entry->io = 0;
1265
1266 /* Interrupt options */
1267 if (features & 0x10) {
1268 p = parse_irq(p, q, &entry->irq);
1269 if (p == NULL)
1270 return -EINVAL;
1271 } else
1272 entry->irq.IRQInfo1 = 0;
1273
1274 if (features & 0x20) {
1275 if (p == q)
1276 return -EINVAL;
1277 entry->mem = *p; p++;
1278 } else
1279 entry->mem = 0;
1280
1281 /* Misc features */
1282 if (features & 0x80) {
1283 if (p == q)
1284 return -EINVAL;
1285 entry->flags |= (*p << 8);
1286 if (*p & 0x80) {
1287 if (++p == q)
1288 return -EINVAL;
1289 entry->flags |= (*p << 16);
1290 }
1291 while (*p & 0x80)
1292 if (++p == q)
1293 return -EINVAL;
1294 p++;
1295 }
1296
1297 entry->subtuples = q-p;
1298
1299 return 0;
1300}
1301
1302#endif
1303
1304/*====================================================================*/
1305
1306static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo) 1232static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo)
1307{ 1233{
1308 u_char *p, *q; 1234 u_char *p, *q;
@@ -1404,17 +1330,6 @@ int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse)
1404 case CISTPL_DEVICE_A: 1330 case CISTPL_DEVICE_A:
1405 ret = parse_device(tuple, &parse->device); 1331 ret = parse_device(tuple, &parse->device);
1406 break; 1332 break;
1407#ifdef CONFIG_CARDBUS
1408 case CISTPL_BAR:
1409 ret = parse_bar(tuple, &parse->bar);
1410 break;
1411 case CISTPL_CONFIG_CB:
1412 ret = parse_config_cb(tuple, &parse->config);
1413 break;
1414 case CISTPL_CFTABLE_ENTRY_CB:
1415 ret = parse_cftable_entry_cb(tuple, &parse->cftable_entry_cb);
1416 break;
1417#endif
1418 case CISTPL_CHECKSUM: 1333 case CISTPL_CHECKSUM:
1419 ret = parse_checksum(tuple, &parse->checksum); 1334 ret = parse_checksum(tuple, &parse->checksum);
1420 break; 1335 break;
@@ -1513,7 +1428,6 @@ done:
1513 kfree(buf); 1428 kfree(buf);
1514 return ret; 1429 return ret;
1515} 1430}
1516EXPORT_SYMBOL(pccard_read_tuple);
1517 1431
1518 1432
1519/** 1433/**
@@ -1573,84 +1487,238 @@ next_entry:
1573 kfree(buf); 1487 kfree(buf);
1574 return ret; 1488 return ret;
1575} 1489}
1576EXPORT_SYMBOL(pccard_loop_tuple);
1577 1490
1578 1491
1579/*====================================================================== 1492/**
1580 1493 * pccard_validate_cis() - check whether card has a sensible CIS
1581 This tries to determine if a card has a sensible CIS. It returns 1494 * @s: the struct pcmcia_socket we are to check
1582 the number of tuples in the CIS, or 0 if the CIS looks bad. The 1495 * @info: returns the number of tuples in the (valid) CIS, or 0
1583 checks include making sure several critical tuples are present and 1496 *
1584 valid; seeing if the total number of tuples is reasonable; and 1497 * This tries to determine if a card has a sensible CIS. In @info, it
1585 looking for tuples that use reserved codes. 1498 * returns the number of tuples in the CIS, or 0 if the CIS looks bad. The
1586 1499 * checks include making sure several critical tuples are present and
1587======================================================================*/ 1500 * valid; seeing if the total number of tuples is reasonable; and
1588 1501 * looking for tuples that use reserved codes.
1502 *
1503 * The function returns 0 on success.
1504 */
1589int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info) 1505int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *info)
1590{ 1506{
1591 tuple_t *tuple; 1507 tuple_t *tuple;
1592 cisparse_t *p; 1508 cisparse_t *p;
1593 unsigned int count = 0; 1509 unsigned int count = 0;
1594 int ret, reserved, dev_ok = 0, ident_ok = 0; 1510 int ret, reserved, dev_ok = 0, ident_ok = 0;
1595 1511
1596 if (!s) 1512 if (!s)
1597 return -EINVAL; 1513 return -EINVAL;
1598 1514
1599 tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); 1515 /* We do not want to validate the CIS cache... */
1600 if (tuple == NULL) { 1516 mutex_lock(&s->ops_mutex);
1601 dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n"); 1517 destroy_cis_cache(s);
1602 return -ENOMEM; 1518 mutex_unlock(&s->ops_mutex);
1603 }
1604 p = kmalloc(sizeof(*p), GFP_KERNEL);
1605 if (p == NULL) {
1606 kfree(tuple);
1607 dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n");
1608 return -ENOMEM;
1609 }
1610 1519
1611 count = reserved = 0; 1520 tuple = kmalloc(sizeof(*tuple), GFP_KERNEL);
1612 tuple->DesiredTuple = RETURN_FIRST_TUPLE; 1521 if (tuple == NULL) {
1613 tuple->Attributes = TUPLE_RETURN_COMMON; 1522 dev_warn(&s->dev, "no memory to validate CIS\n");
1614 ret = pccard_get_first_tuple(s, BIND_FN_ALL, tuple); 1523 return -ENOMEM;
1615 if (ret != 0) 1524 }
1616 goto done; 1525 p = kmalloc(sizeof(*p), GFP_KERNEL);
1617 1526 if (p == NULL) {
1618 /* First tuple should be DEVICE; we should really have either that 1527 kfree(tuple);
1619 or a CFTABLE_ENTRY of some sort */ 1528 dev_warn(&s->dev, "no memory to validate CIS\n");
1620 if ((tuple->TupleCode == CISTPL_DEVICE) || 1529 return -ENOMEM;
1621 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p) == 0) || 1530 }
1622 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p) == 0)) 1531
1623 dev_ok++; 1532 count = reserved = 0;
1624 1533 tuple->DesiredTuple = RETURN_FIRST_TUPLE;
1625 /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 1534 tuple->Attributes = TUPLE_RETURN_COMMON;
1626 tuple, for card identification. Certain old D-Link and Linksys 1535 ret = pccard_get_first_tuple(s, BIND_FN_ALL, tuple);
1627 cards have only a broken VERS_2 tuple; hence the bogus test. */
1628 if ((pccard_read_tuple(s, BIND_FN_ALL, CISTPL_MANFID, p) == 0) ||
1629 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_1, p) == 0) ||
1630 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_2, p) != -ENOSPC))
1631 ident_ok++;
1632
1633 if (!dev_ok && !ident_ok)
1634 goto done;
1635
1636 for (count = 1; count < MAX_TUPLES; count++) {
1637 ret = pccard_get_next_tuple(s, BIND_FN_ALL, tuple);
1638 if (ret != 0) 1536 if (ret != 0)
1639 break; 1537 goto done;
1640 if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || 1538
1641 ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || 1539 /* First tuple should be DEVICE; we should really have either that
1642 ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) 1540 or a CFTABLE_ENTRY of some sort */
1643 reserved++; 1541 if ((tuple->TupleCode == CISTPL_DEVICE) ||
1644 } 1542 (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY, p)) ||
1645 if ((count == MAX_TUPLES) || (reserved > 5) || 1543 (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_CFTABLE_ENTRY_CB, p)))
1646 ((!dev_ok || !ident_ok) && (count > 10))) 1544 dev_ok++;
1647 count = 0; 1545
1546 /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2
1547 tuple, for card identification. Certain old D-Link and Linksys
1548 cards have only a broken VERS_2 tuple; hence the bogus test. */
1549 if ((pccard_read_tuple(s, BIND_FN_ALL, CISTPL_MANFID, p) == 0) ||
1550 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_1, p) == 0) ||
1551 (pccard_read_tuple(s, BIND_FN_ALL, CISTPL_VERS_2, p) != -ENOSPC))
1552 ident_ok++;
1553
1554 if (!dev_ok && !ident_ok)
1555 goto done;
1556
1557 for (count = 1; count < MAX_TUPLES; count++) {
1558 ret = pccard_get_next_tuple(s, BIND_FN_ALL, tuple);
1559 if (ret != 0)
1560 break;
1561 if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) ||
1562 ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) ||
1563 ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff)))
1564 reserved++;
1565 }
1566 if ((count == MAX_TUPLES) || (reserved > 5) ||
1567 ((!dev_ok || !ident_ok) && (count > 10)))
1568 count = 0;
1569
1570 ret = 0;
1648 1571
1649done: 1572done:
1650 if (info) 1573 /* invalidate CIS cache on failure */
1651 *info = count; 1574 if (!dev_ok || !ident_ok || !count) {
1652 kfree(tuple); 1575 mutex_lock(&s->ops_mutex);
1653 kfree(p); 1576 destroy_cis_cache(s);
1654 return 0; 1577 mutex_unlock(&s->ops_mutex);
1578 ret = -EIO;
1579 }
1580
1581 if (info)
1582 *info = count;
1583 kfree(tuple);
1584 kfree(p);
1585 return ret;
1655} 1586}
1656EXPORT_SYMBOL(pccard_validate_cis); 1587
1588
1589#define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
1590
1591static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf,
1592 loff_t off, size_t count)
1593{
1594 tuple_t tuple;
1595 int status, i;
1596 loff_t pointer = 0;
1597 ssize_t ret = 0;
1598 u_char *tuplebuffer;
1599 u_char *tempbuffer;
1600
1601 tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL);
1602 if (!tuplebuffer)
1603 return -ENOMEM;
1604
1605 tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL);
1606 if (!tempbuffer) {
1607 ret = -ENOMEM;
1608 goto free_tuple;
1609 }
1610
1611 memset(&tuple, 0, sizeof(tuple_t));
1612
1613 tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON;
1614 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
1615 tuple.TupleOffset = 0;
1616
1617 status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple);
1618 while (!status) {
1619 tuple.TupleData = tuplebuffer;
1620 tuple.TupleDataMax = 255;
1621 memset(tuplebuffer, 0, sizeof(u_char) * 255);
1622
1623 status = pccard_get_tuple_data(s, &tuple);
1624 if (status)
1625 break;
1626
1627 if (off < (pointer + 2 + tuple.TupleDataLen)) {
1628 tempbuffer[0] = tuple.TupleCode & 0xff;
1629 tempbuffer[1] = tuple.TupleLink & 0xff;
1630 for (i = 0; i < tuple.TupleDataLen; i++)
1631 tempbuffer[i + 2] = tuplebuffer[i] & 0xff;
1632
1633 for (i = 0; i < (2 + tuple.TupleDataLen); i++) {
1634 if (((i + pointer) >= off) &&
1635 (i + pointer) < (off + count)) {
1636 buf[ret] = tempbuffer[i];
1637 ret++;
1638 }
1639 }
1640 }
1641
1642 pointer += 2 + tuple.TupleDataLen;
1643
1644 if (pointer >= (off + count))
1645 break;
1646
1647 if (tuple.TupleCode == CISTPL_END)
1648 break;
1649 status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple);
1650 }
1651
1652 kfree(tempbuffer);
1653 free_tuple:
1654 kfree(tuplebuffer);
1655
1656 return ret;
1657}
1658
1659
1660static ssize_t pccard_show_cis(struct kobject *kobj,
1661 struct bin_attribute *bin_attr,
1662 char *buf, loff_t off, size_t count)
1663{
1664 unsigned int size = 0x200;
1665
1666 if (off >= size)
1667 count = 0;
1668 else {
1669 struct pcmcia_socket *s;
1670 unsigned int chains;
1671
1672 if (off + count > size)
1673 count = size - off;
1674
1675 s = to_socket(container_of(kobj, struct device, kobj));
1676
1677 if (!(s->state & SOCKET_PRESENT))
1678 return -ENODEV;
1679 if (pccard_validate_cis(s, &chains))
1680 return -EIO;
1681 if (!chains)
1682 return -ENODATA;
1683
1684 count = pccard_extract_cis(s, buf, off, count);
1685 }
1686
1687 return count;
1688}
1689
1690
1691static ssize_t pccard_store_cis(struct kobject *kobj,
1692 struct bin_attribute *bin_attr,
1693 char *buf, loff_t off, size_t count)
1694{
1695 struct pcmcia_socket *s;
1696 int error;
1697
1698 s = to_socket(container_of(kobj, struct device, kobj));
1699
1700 if (off)
1701 return -EINVAL;
1702
1703 if (count >= CISTPL_MAX_CIS_SIZE)
1704 return -EINVAL;
1705
1706 if (!(s->state & SOCKET_PRESENT))
1707 return -ENODEV;
1708
1709 error = pcmcia_replace_cis(s, buf, count);
1710 if (error)
1711 return -EIO;
1712
1713 pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
1714
1715 return count;
1716}
1717
1718
1719struct bin_attribute pccard_cis_attr = {
1720 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR },
1721 .size = 0x200,
1722 .read = pccard_show_cis,
1723 .write = pccard_store_cis,
1724};
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 6d6f82b38a68..e679e708db63 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -140,19 +140,13 @@ struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt)
140 struct device *dev = get_device(&skt->dev); 140 struct device *dev = get_device(&skt->dev);
141 if (!dev) 141 if (!dev)
142 return NULL; 142 return NULL;
143 skt = dev_get_drvdata(dev); 143 return dev_get_drvdata(dev);
144 if (!try_module_get(skt->owner)) {
145 put_device(&skt->dev);
146 return NULL;
147 }
148 return skt;
149} 144}
150EXPORT_SYMBOL(pcmcia_get_socket); 145EXPORT_SYMBOL(pcmcia_get_socket);
151 146
152 147
153void pcmcia_put_socket(struct pcmcia_socket *skt) 148void pcmcia_put_socket(struct pcmcia_socket *skt)
154{ 149{
155 module_put(skt->owner);
156 put_device(&skt->dev); 150 put_device(&skt->dev);
157} 151}
158EXPORT_SYMBOL(pcmcia_put_socket); 152EXPORT_SYMBOL(pcmcia_put_socket);
@@ -181,8 +175,6 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
181 175
182 dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops); 176 dev_dbg(&socket->dev, "pcmcia_register_socket(0x%p)\n", socket->ops);
183 177
184 spin_lock_init(&socket->lock);
185
186 /* try to obtain a socket number [yes, it gets ugly if we 178 /* try to obtain a socket number [yes, it gets ugly if we
187 * register more than 2^sizeof(unsigned int) pcmcia 179 * register more than 2^sizeof(unsigned int) pcmcia
188 * sockets... but the socket number is deprecated 180 * sockets... but the socket number is deprecated
@@ -228,10 +220,13 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
228 init_completion(&socket->socket_released); 220 init_completion(&socket->socket_released);
229 init_completion(&socket->thread_done); 221 init_completion(&socket->thread_done);
230 mutex_init(&socket->skt_mutex); 222 mutex_init(&socket->skt_mutex);
223 mutex_init(&socket->ops_mutex);
231 spin_lock_init(&socket->thread_lock); 224 spin_lock_init(&socket->thread_lock);
232 225
233 if (socket->resource_ops->init) { 226 if (socket->resource_ops->init) {
227 mutex_lock(&socket->ops_mutex);
234 ret = socket->resource_ops->init(socket); 228 ret = socket->resource_ops->init(socket);
229 mutex_unlock(&socket->ops_mutex);
235 if (ret) 230 if (ret)
236 goto err; 231 goto err;
237 } 232 }
@@ -283,15 +278,17 @@ void pcmcia_unregister_socket(struct pcmcia_socket *socket)
283 if (socket->thread) 278 if (socket->thread)
284 kthread_stop(socket->thread); 279 kthread_stop(socket->thread);
285 280
286 release_cis_mem(socket);
287
288 /* remove from our own list */ 281 /* remove from our own list */
289 down_write(&pcmcia_socket_list_rwsem); 282 down_write(&pcmcia_socket_list_rwsem);
290 list_del(&socket->socket_list); 283 list_del(&socket->socket_list);
291 up_write(&pcmcia_socket_list_rwsem); 284 up_write(&pcmcia_socket_list_rwsem);
292 285
293 /* wait for sysfs to drop all references */ 286 /* wait for sysfs to drop all references */
294 release_resource_db(socket); 287 if (socket->resource_ops->exit) {
288 mutex_lock(&socket->ops_mutex);
289 socket->resource_ops->exit(socket);
290 mutex_unlock(&socket->ops_mutex);
291 }
295 wait_for_completion(&socket->socket_released); 292 wait_for_completion(&socket->socket_released);
296} /* pcmcia_unregister_socket */ 293} /* pcmcia_unregister_socket */
297EXPORT_SYMBOL(pcmcia_unregister_socket); 294EXPORT_SYMBOL(pcmcia_unregister_socket);
@@ -328,7 +325,7 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority)
328{ 325{
329 int ret; 326 int ret;
330 327
331 if (s->state & SOCKET_CARDBUS) 328 if ((s->state & SOCKET_CARDBUS) && (event != CS_EVENT_CARD_REMOVAL))
332 return 0; 329 return 0;
333 330
334 dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n", 331 dev_dbg(&s->dev, "send_event(event %d, pri %d, callback 0x%p)\n",
@@ -346,13 +343,6 @@ static int send_event(struct pcmcia_socket *s, event_t event, int priority)
346 return ret; 343 return ret;
347} 344}
348 345
349static void socket_remove_drivers(struct pcmcia_socket *skt)
350{
351 dev_dbg(&skt->dev, "remove_drivers\n");
352
353 send_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH);
354}
355
356static int socket_reset(struct pcmcia_socket *skt) 346static int socket_reset(struct pcmcia_socket *skt)
357{ 347{
358 int status, i; 348 int status, i;
@@ -395,7 +385,9 @@ static void socket_shutdown(struct pcmcia_socket *s)
395 385
396 dev_dbg(&s->dev, "shutdown\n"); 386 dev_dbg(&s->dev, "shutdown\n");
397 387
398 socket_remove_drivers(s); 388 send_event(s, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH);
389
390 mutex_lock(&s->ops_mutex);
399 s->state &= SOCKET_INUSE | SOCKET_PRESENT; 391 s->state &= SOCKET_INUSE | SOCKET_PRESENT;
400 msleep(shutdown_delay * 10); 392 msleep(shutdown_delay * 10);
401 s->state &= SOCKET_INUSE; 393 s->state &= SOCKET_INUSE;
@@ -406,11 +398,21 @@ static void socket_shutdown(struct pcmcia_socket *s)
406 s->ops->set_socket(s, &s->socket); 398 s->ops->set_socket(s, &s->socket);
407 s->irq.AssignedIRQ = s->irq.Config = 0; 399 s->irq.AssignedIRQ = s->irq.Config = 0;
408 s->lock_count = 0; 400 s->lock_count = 0;
409 destroy_cis_cache(s); 401 kfree(s->fake_cis);
402 s->fake_cis = NULL;
403 s->functions = 0;
404
405 /* From here on we can be sure that only we (that is, the
406 * pccardd thread) accesses this socket, and all (16-bit)
407 * PCMCIA interactions are gone. Therefore, release
408 * ops_mutex so that we don't get a sysfs-related lockdep
409 * warning.
410 */
411 mutex_unlock(&s->ops_mutex);
412
410#ifdef CONFIG_CARDBUS 413#ifdef CONFIG_CARDBUS
411 cb_free(s); 414 cb_free(s);
412#endif 415#endif
413 s->functions = 0;
414 416
415 /* give socket some time to power down */ 417 /* give socket some time to power down */
416 msleep(100); 418 msleep(100);
@@ -421,7 +423,7 @@ static void socket_shutdown(struct pcmcia_socket *s)
421 "*** DANGER *** unable to remove socket power\n"); 423 "*** DANGER *** unable to remove socket power\n");
422 } 424 }
423 425
424 cs_socket_put(s); 426 s->state &= ~SOCKET_INUSE;
425} 427}
426 428
427static int socket_setup(struct pcmcia_socket *skt, int initial_delay) 429static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
@@ -460,7 +462,8 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
460 return -EINVAL; 462 return -EINVAL;
461 } 463 }
462 skt->state |= SOCKET_CARDBUS; 464 skt->state |= SOCKET_CARDBUS;
463 } 465 } else
466 skt->state &= ~SOCKET_CARDBUS;
464 467
465 /* 468 /*
466 * Decode the card voltage requirements, and apply power to the card. 469 * Decode the card voltage requirements, and apply power to the card.
@@ -509,8 +512,12 @@ static int socket_insert(struct pcmcia_socket *skt)
509 512
510 dev_dbg(&skt->dev, "insert\n"); 513 dev_dbg(&skt->dev, "insert\n");
511 514
512 if (!cs_socket_get(skt)) 515 mutex_lock(&skt->ops_mutex);
513 return -ENODEV; 516 if (skt->state & SOCKET_INUSE) {
517 mutex_unlock(&skt->ops_mutex);
518 return -EINVAL;
519 }
520 skt->state |= SOCKET_INUSE;
514 521
515 ret = socket_setup(skt, setup_delay); 522 ret = socket_setup(skt, setup_delay);
516 if (ret == 0) { 523 if (ret == 0) {
@@ -528,9 +535,11 @@ static int socket_insert(struct pcmcia_socket *skt)
528 } 535 }
529#endif 536#endif
530 dev_dbg(&skt->dev, "insert done\n"); 537 dev_dbg(&skt->dev, "insert done\n");
538 mutex_unlock(&skt->ops_mutex);
531 539
532 send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW); 540 send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW);
533 } else { 541 } else {
542 mutex_unlock(&skt->ops_mutex);
534 socket_shutdown(skt); 543 socket_shutdown(skt);
535 } 544 }
536 545
@@ -542,58 +551,66 @@ static int socket_suspend(struct pcmcia_socket *skt)
542 if (skt->state & SOCKET_SUSPEND) 551 if (skt->state & SOCKET_SUSPEND)
543 return -EBUSY; 552 return -EBUSY;
544 553
554 mutex_lock(&skt->ops_mutex);
555 skt->suspended_state = skt->state;
556
545 send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); 557 send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW);
546 skt->socket = dead_socket; 558 skt->socket = dead_socket;
547 skt->ops->set_socket(skt, &skt->socket); 559 skt->ops->set_socket(skt, &skt->socket);
548 if (skt->ops->suspend) 560 if (skt->ops->suspend)
549 skt->ops->suspend(skt); 561 skt->ops->suspend(skt);
550 skt->state |= SOCKET_SUSPEND; 562 skt->state |= SOCKET_SUSPEND;
551 563 mutex_unlock(&skt->ops_mutex);
552 return 0; 564 return 0;
553} 565}
554 566
555static int socket_early_resume(struct pcmcia_socket *skt) 567static int socket_early_resume(struct pcmcia_socket *skt)
556{ 568{
569 mutex_lock(&skt->ops_mutex);
557 skt->socket = dead_socket; 570 skt->socket = dead_socket;
558 skt->ops->init(skt); 571 skt->ops->init(skt);
559 skt->ops->set_socket(skt, &skt->socket); 572 skt->ops->set_socket(skt, &skt->socket);
560 if (skt->state & SOCKET_PRESENT) 573 if (skt->state & SOCKET_PRESENT)
561 skt->resume_status = socket_setup(skt, resume_delay); 574 skt->resume_status = socket_setup(skt, resume_delay);
575 mutex_unlock(&skt->ops_mutex);
562 return 0; 576 return 0;
563} 577}
564 578
565static int socket_late_resume(struct pcmcia_socket *skt) 579static int socket_late_resume(struct pcmcia_socket *skt)
566{ 580{
567 if (!(skt->state & SOCKET_PRESENT)) { 581 mutex_lock(&skt->ops_mutex);
568 skt->state &= ~SOCKET_SUSPEND; 582 skt->state &= ~SOCKET_SUSPEND;
583 mutex_unlock(&skt->ops_mutex);
584
585 if (!(skt->state & SOCKET_PRESENT))
569 return socket_insert(skt); 586 return socket_insert(skt);
587
588 if (skt->resume_status) {
589 socket_shutdown(skt);
590 return 0;
570 } 591 }
571 592
572 if (skt->resume_status == 0) { 593 if (skt->suspended_state != skt->state) {
573 /* 594 dev_dbg(&skt->dev,
574 * FIXME: need a better check here for cardbus cards. 595 "suspend state 0x%x != resume state 0x%x\n",
575 */ 596 skt->suspended_state, skt->state);
576 if (verify_cis_cache(skt) != 0) { 597
577 dev_dbg(&skt->dev, "cis mismatch - different card\n");
578 socket_remove_drivers(skt);
579 destroy_cis_cache(skt);
580 /*
581 * Workaround: give DS time to schedule removal.
582 * Remove me once the 100ms delay is eliminated
583 * in ds.c
584 */
585 msleep(200);
586 send_event(skt, CS_EVENT_CARD_INSERTION, CS_EVENT_PRI_LOW);
587 } else {
588 dev_dbg(&skt->dev, "cis matches cache\n");
589 send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW);
590 }
591 } else {
592 socket_shutdown(skt); 598 socket_shutdown(skt);
599 return socket_insert(skt);
593 } 600 }
594 601
595 skt->state &= ~SOCKET_SUSPEND; 602#ifdef CONFIG_CARDBUS
603 if (skt->state & SOCKET_CARDBUS) {
604 /* We can't be sure the CardBus card is the same
605 * as the one previously inserted. Therefore, remove
606 * and re-add... */
607 cb_free(skt);
608 cb_alloc(skt);
609 return 0;
610 }
611#endif
596 612
613 send_event(skt, CS_EVENT_PM_RESUME, CS_EVENT_PRI_LOW);
597 return 0; 614 return 0;
598} 615}
599 616
@@ -672,20 +689,26 @@ static int pccardd(void *__skt)
672 689
673 complete(&skt->thread_done); 690 complete(&skt->thread_done);
674 691
692 /* wait for userspace to catch up */
693 msleep(250);
694
675 set_freezable(); 695 set_freezable();
676 for (;;) { 696 for (;;) {
677 unsigned long flags; 697 unsigned long flags;
678 unsigned int events; 698 unsigned int events;
699 unsigned int sysfs_events;
679 700
680 set_current_state(TASK_INTERRUPTIBLE); 701 set_current_state(TASK_INTERRUPTIBLE);
681 702
682 spin_lock_irqsave(&skt->thread_lock, flags); 703 spin_lock_irqsave(&skt->thread_lock, flags);
683 events = skt->thread_events; 704 events = skt->thread_events;
684 skt->thread_events = 0; 705 skt->thread_events = 0;
706 sysfs_events = skt->sysfs_events;
707 skt->sysfs_events = 0;
685 spin_unlock_irqrestore(&skt->thread_lock, flags); 708 spin_unlock_irqrestore(&skt->thread_lock, flags);
686 709
710 mutex_lock(&skt->skt_mutex);
687 if (events) { 711 if (events) {
688 mutex_lock(&skt->skt_mutex);
689 if (events & SS_DETECT) 712 if (events & SS_DETECT)
690 socket_detect_change(skt); 713 socket_detect_change(skt);
691 if (events & SS_BATDEAD) 714 if (events & SS_BATDEAD)
@@ -694,10 +717,39 @@ static int pccardd(void *__skt)
694 send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); 717 send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW);
695 if (events & SS_READY) 718 if (events & SS_READY)
696 send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); 719 send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW);
697 mutex_unlock(&skt->skt_mutex);
698 continue;
699 } 720 }
700 721
722 if (sysfs_events) {
723 if (sysfs_events & PCMCIA_UEVENT_EJECT)
724 socket_remove(skt);
725 if (sysfs_events & PCMCIA_UEVENT_INSERT)
726 socket_insert(skt);
727 if ((sysfs_events & PCMCIA_UEVENT_RESUME) &&
728 !(skt->state & SOCKET_CARDBUS)) {
729 ret = socket_resume(skt);
730 if (!ret && skt->callback)
731 skt->callback->resume(skt);
732 }
733 if ((sysfs_events & PCMCIA_UEVENT_SUSPEND) &&
734 !(skt->state & SOCKET_CARDBUS)) {
735 if (skt->callback)
736 ret = skt->callback->suspend(skt);
737 else
738 ret = 0;
739 if (!ret)
740 socket_suspend(skt);
741 }
742 if ((sysfs_events & PCMCIA_UEVENT_REQUERY) &&
743 !(skt->state & SOCKET_CARDBUS)) {
744 if (!ret && skt->callback)
745 skt->callback->requery(skt);
746 }
747 }
748 mutex_unlock(&skt->skt_mutex);
749
750 if (events || sysfs_events)
751 continue;
752
701 if (kthread_should_stop()) 753 if (kthread_should_stop())
702 break; 754 break;
703 755
@@ -707,6 +759,13 @@ static int pccardd(void *__skt)
707 /* make sure we are running before we exit */ 759 /* make sure we are running before we exit */
708 set_current_state(TASK_RUNNING); 760 set_current_state(TASK_RUNNING);
709 761
762 /* shut down socket, if a device is still present */
763 if (skt->state & SOCKET_PRESENT) {
764 mutex_lock(&skt->skt_mutex);
765 socket_remove(skt);
766 mutex_unlock(&skt->skt_mutex);
767 }
768
710 /* remove from the device core */ 769 /* remove from the device core */
711 pccard_sysfs_remove_socket(&skt->dev); 770 pccard_sysfs_remove_socket(&skt->dev);
712 device_unregister(&skt->dev); 771 device_unregister(&skt->dev);
@@ -732,6 +791,31 @@ void pcmcia_parse_events(struct pcmcia_socket *s, u_int events)
732} /* pcmcia_parse_events */ 791} /* pcmcia_parse_events */
733EXPORT_SYMBOL(pcmcia_parse_events); 792EXPORT_SYMBOL(pcmcia_parse_events);
734 793
794/**
795 * pcmcia_parse_uevents() - tell pccardd to issue manual commands
796 * @s: the PCMCIA socket we wan't to command
797 * @events: events to pass to pccardd
798 *
799 * userspace-issued insert, eject, suspend and resume commands must be
800 * handled by pccardd to avoid any sysfs-related deadlocks. Valid events
801 * are PCMCIA_UEVENT_EJECT (for eject), PCMCIA_UEVENT__INSERT (for insert),
802 * PCMCIA_UEVENT_RESUME (for resume), PCMCIA_UEVENT_SUSPEND (for suspend)
803 * and PCMCIA_UEVENT_REQUERY (for re-querying the PCMCIA card).
804 */
805void pcmcia_parse_uevents(struct pcmcia_socket *s, u_int events)
806{
807 unsigned long flags;
808 dev_dbg(&s->dev, "parse_uevents: events %08x\n", events);
809 if (s->thread) {
810 spin_lock_irqsave(&s->thread_lock, flags);
811 s->sysfs_events |= events;
812 spin_unlock_irqrestore(&s->thread_lock, flags);
813
814 wake_up_process(s->thread);
815 }
816}
817EXPORT_SYMBOL(pcmcia_parse_uevents);
818
735 819
736/* register pcmcia_callback */ 820/* register pcmcia_callback */
737int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c) 821int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
@@ -796,7 +880,10 @@ int pcmcia_reset_card(struct pcmcia_socket *skt)
796 send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); 880 send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW);
797 if (skt->callback) 881 if (skt->callback)
798 skt->callback->suspend(skt); 882 skt->callback->suspend(skt);
799 if (socket_reset(skt) == 0) { 883 mutex_lock(&skt->ops_mutex);
884 ret = socket_reset(skt);
885 mutex_unlock(&skt->ops_mutex);
886 if (ret == 0) {
800 send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); 887 send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW);
801 if (skt->callback) 888 if (skt->callback)
802 skt->callback->resume(skt); 889 skt->callback->resume(skt);
@@ -812,121 +899,6 @@ int pcmcia_reset_card(struct pcmcia_socket *skt)
812EXPORT_SYMBOL(pcmcia_reset_card); 899EXPORT_SYMBOL(pcmcia_reset_card);
813 900
814 901
815/* These shut down or wake up a socket. They are sort of user
816 * initiated versions of the APM suspend and resume actions.
817 */
818int pcmcia_suspend_card(struct pcmcia_socket *skt)
819{
820 int ret;
821
822 dev_dbg(&skt->dev, "suspending socket\n");
823
824 mutex_lock(&skt->skt_mutex);
825 do {
826 if (!(skt->state & SOCKET_PRESENT)) {
827 ret = -ENODEV;
828 break;
829 }
830 if (skt->state & SOCKET_CARDBUS) {
831 ret = -EPERM;
832 break;
833 }
834 if (skt->callback) {
835 ret = skt->callback->suspend(skt);
836 if (ret)
837 break;
838 }
839 ret = socket_suspend(skt);
840 } while (0);
841 mutex_unlock(&skt->skt_mutex);
842
843 return ret;
844} /* suspend_card */
845EXPORT_SYMBOL(pcmcia_suspend_card);
846
847
848int pcmcia_resume_card(struct pcmcia_socket *skt)
849{
850 int ret;
851
852 dev_dbg(&skt->dev, "waking up socket\n");
853
854 mutex_lock(&skt->skt_mutex);
855 do {
856 if (!(skt->state & SOCKET_PRESENT)) {
857 ret = -ENODEV;
858 break;
859 }
860 if (skt->state & SOCKET_CARDBUS) {
861 ret = -EPERM;
862 break;
863 }
864 ret = socket_resume(skt);
865 if (!ret && skt->callback)
866 skt->callback->resume(skt);
867 } while (0);
868 mutex_unlock(&skt->skt_mutex);
869
870 return ret;
871} /* resume_card */
872EXPORT_SYMBOL(pcmcia_resume_card);
873
874
875/* These handle user requests to eject or insert a card. */
876int pcmcia_eject_card(struct pcmcia_socket *skt)
877{
878 int ret;
879
880 dev_dbg(&skt->dev, "user eject request\n");
881
882 mutex_lock(&skt->skt_mutex);
883 do {
884 if (!(skt->state & SOCKET_PRESENT)) {
885 ret = -ENODEV;
886 break;
887 }
888
889 ret = send_event(skt, CS_EVENT_EJECTION_REQUEST, CS_EVENT_PRI_LOW);
890 if (ret != 0) {
891 ret = -EINVAL;
892 break;
893 }
894
895 socket_remove(skt);
896 ret = 0;
897 } while (0);
898 mutex_unlock(&skt->skt_mutex);
899
900 return ret;
901} /* eject_card */
902EXPORT_SYMBOL(pcmcia_eject_card);
903
904
905int pcmcia_insert_card(struct pcmcia_socket *skt)
906{
907 int ret;
908
909 dev_dbg(&skt->dev, "user insert request\n");
910
911 mutex_lock(&skt->skt_mutex);
912 do {
913 if (skt->state & SOCKET_PRESENT) {
914 ret = -EBUSY;
915 break;
916 }
917 if (socket_insert(skt) == -ENODEV) {
918 ret = -ENODEV;
919 break;
920 }
921 ret = 0;
922 } while (0);
923 mutex_unlock(&skt->skt_mutex);
924
925 return ret;
926} /* insert_card */
927EXPORT_SYMBOL(pcmcia_insert_card);
928
929
930static int pcmcia_socket_uevent(struct device *dev, 902static int pcmcia_socket_uevent(struct device *dev,
931 struct kobj_uevent_env *env) 903 struct kobj_uevent_env *env)
932{ 904{
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 3bc02d53a3a3..f95864c2191e 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -87,37 +87,11 @@ struct pccard_resource_ops {
87#define SOCKET_CARDBUS 0x8000 87#define SOCKET_CARDBUS 0x8000
88#define SOCKET_CARDBUS_CONFIG 0x10000 88#define SOCKET_CARDBUS_CONFIG 0x10000
89 89
90static inline int cs_socket_get(struct pcmcia_socket *skt)
91{
92 int ret;
93
94 WARN_ON(skt->state & SOCKET_INUSE);
95
96 ret = try_module_get(skt->owner);
97 if (ret)
98 skt->state |= SOCKET_INUSE;
99 return ret;
100}
101
102static inline void cs_socket_put(struct pcmcia_socket *skt)
103{
104 if (skt->state & SOCKET_INUSE) {
105 skt->state &= ~SOCKET_INUSE;
106 module_put(skt->owner);
107 }
108}
109
110 90
111/* 91/*
112 * Stuff internal to module "pcmcia_core": 92 * Stuff internal to module "pcmcia_core":
113 */ 93 */
114 94
115/* cistpl.c */
116int verify_cis_cache(struct pcmcia_socket *s);
117
118/* rsrc_mgr.c */
119void release_resource_db(struct pcmcia_socket *s);
120
121/* socket_sysfs.c */ 95/* socket_sysfs.c */
122extern int pccard_sysfs_add_socket(struct device *dev); 96extern int pccard_sysfs_add_socket(struct device *dev);
123extern void pccard_sysfs_remove_socket(struct device *dev); 97extern void pccard_sysfs_remove_socket(struct device *dev);
@@ -125,8 +99,6 @@ extern void pccard_sysfs_remove_socket(struct device *dev);
125/* cardbus.c */ 99/* cardbus.c */
126int cb_alloc(struct pcmcia_socket *s); 100int cb_alloc(struct pcmcia_socket *s);
127void cb_free(struct pcmcia_socket *s); 101void cb_free(struct pcmcia_socket *s);
128int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len,
129 void *ptr);
130 102
131 103
132 104
@@ -138,7 +110,8 @@ struct pcmcia_callback{
138 struct module *owner; 110 struct module *owner;
139 int (*event) (struct pcmcia_socket *s, 111 int (*event) (struct pcmcia_socket *s,
140 event_t event, int priority); 112 event_t event, int priority);
141 void (*requery) (struct pcmcia_socket *s, int new_cis); 113 void (*requery) (struct pcmcia_socket *s);
114 int (*validate) (struct pcmcia_socket *s, unsigned int *i);
142 int (*suspend) (struct pcmcia_socket *s); 115 int (*suspend) (struct pcmcia_socket *s);
143 int (*resume) (struct pcmcia_socket *s); 116 int (*resume) (struct pcmcia_socket *s);
144}; 117};
@@ -151,16 +124,35 @@ extern struct class pcmcia_socket_class;
151int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); 124int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
152struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr); 125struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
153 126
154int pcmcia_suspend_card(struct pcmcia_socket *skt); 127void pcmcia_parse_uevents(struct pcmcia_socket *socket, unsigned int events);
155int pcmcia_resume_card(struct pcmcia_socket *skt); 128#define PCMCIA_UEVENT_EJECT 0x0001
156 129#define PCMCIA_UEVENT_INSERT 0x0002
157int pcmcia_eject_card(struct pcmcia_socket *skt); 130#define PCMCIA_UEVENT_SUSPEND 0x0004
158int pcmcia_insert_card(struct pcmcia_socket *skt); 131#define PCMCIA_UEVENT_RESUME 0x0008
132#define PCMCIA_UEVENT_REQUERY 0x0010
159 133
160struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt); 134struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt);
161void pcmcia_put_socket(struct pcmcia_socket *skt); 135void pcmcia_put_socket(struct pcmcia_socket *skt);
162 136
137/*
138 * Stuff internal to module "pcmcia".
139 */
140/* ds.c */
141extern struct bus_type pcmcia_bus_type;
142
143/* pcmcia_resource.c */
144extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
145extern int pcmcia_validate_mem(struct pcmcia_socket *s);
146extern struct resource *pcmcia_find_mem_region(u_long base,
147 u_long num,
148 u_long align,
149 int low,
150 struct pcmcia_socket *s);
151
152
163/* cistpl.c */ 153/* cistpl.c */
154extern struct bin_attribute pccard_cis_attr;
155
164int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, 156int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
165 u_int addr, u_int len, void *ptr); 157 u_int addr, u_int len, void *ptr);
166void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, 158void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
@@ -172,8 +164,8 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
172int pcmcia_replace_cis(struct pcmcia_socket *s, 164int pcmcia_replace_cis(struct pcmcia_socket *s,
173 const u8 *data, const size_t len); 165 const u8 *data, const size_t len);
174int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count); 166int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count);
167int verify_cis_cache(struct pcmcia_socket *s);
175 168
176/* loop over CIS entries */
177int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, 169int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
178 cisdata_t code, cisparse_t *parse, void *priv_data, 170 cisdata_t code, cisparse_t *parse, void *priv_data,
179 int (*loop_tuple) (tuple_t *tuple, 171 int (*loop_tuple) (tuple_t *tuple,
@@ -189,35 +181,8 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function,
189int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple); 181int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
190 182
191 183
192/* rsrc_mgr.c */
193int pcmcia_validate_mem(struct pcmcia_socket *s);
194struct resource *pcmcia_find_io_region(unsigned long base,
195 int num,
196 unsigned long align,
197 struct pcmcia_socket *s);
198int pcmcia_adjust_io_region(struct resource *res,
199 unsigned long r_start,
200 unsigned long r_end,
201 struct pcmcia_socket *s);
202struct resource *pcmcia_find_mem_region(u_long base,
203 u_long num,
204 u_long align,
205 int low,
206 struct pcmcia_socket *s);
207
208/*
209 * Stuff internal to module "pcmcia".
210 */
211/* ds.c */
212extern struct bus_type pcmcia_bus_type;
213
214/* pcmcia_resource.c */
215extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
216
217#ifdef CONFIG_PCMCIA_IOCTL 184#ifdef CONFIG_PCMCIA_IOCTL
218/* ds.c */ 185/* ds.c */
219extern spinlock_t pcmcia_dev_list_lock;
220
221extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev); 186extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev);
222extern void pcmcia_put_dev(struct pcmcia_device *p_dev); 187extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
223 188
diff --git a/drivers/pcmcia/db1xxx_ss.c b/drivers/pcmcia/db1xxx_ss.c
new file mode 100644
index 000000000000..3889cf07d6ce
--- /dev/null
+++ b/drivers/pcmcia/db1xxx_ss.c
@@ -0,0 +1,623 @@
1/*
2 * PCMCIA socket code for the Alchemy Db1xxx/Pb1xxx boards.
3 *
4 * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com>
5 *
6 */
7
8/* This is a fairly generic PCMCIA socket driver suitable for the
9 * following Alchemy Development boards:
10 * Db1000, Db/Pb1500, Db/Pb1100, Db/Pb1550, Db/Pb1200.
11 *
12 * The Db1000 is used as a reference: Per-socket card-, carddetect- and
13 * statuschange IRQs connected to SoC GPIOs, control and status register
14 * bits arranged in per-socket groups in an external PLD. All boards
15 * listed here use this layout, including bit positions and meanings.
16 * Of course there are exceptions in later boards:
17 *
18 * - Pb1100/Pb1500: single socket only; voltage key bits VS are
19 * at STATUS[5:4] (instead of STATUS[1:0]).
20 * - Au1200-based: additional card-eject irqs, irqs not gpios!
21 */
22
23#include <linux/delay.h>
24#include <linux/gpio.h>
25#include <linux/interrupt.h>
26#include <linux/pm.h>
27#include <linux/platform_device.h>
28#include <linux/resource.h>
29#include <linux/spinlock.h>
30
31#include <pcmcia/cs_types.h>
32#include <pcmcia/ss.h>
33
34#include <asm/mach-au1x00/au1000.h>
35#include <asm/mach-db1x00/bcsr.h>
36
37#define MEM_MAP_SIZE 0x400000
38#define IO_MAP_SIZE 0x1000
39
40struct db1x_pcmcia_sock {
41 struct pcmcia_socket socket;
42 int nr; /* socket number */
43 void *virt_io;
44
45 /* the "pseudo" addresses of the PCMCIA space. */
46 phys_addr_t phys_io;
47 phys_addr_t phys_attr;
48 phys_addr_t phys_mem;
49
50 /* previous flags for set_socket() */
51 unsigned int old_flags;
52
53 /* interrupt sources: linux irq numbers! */
54 int insert_irq; /* default carddetect irq */
55 int stschg_irq; /* card-status-change irq */
56 int card_irq; /* card irq */
57 int eject_irq; /* db1200/pb1200 have these */
58
59#define BOARD_TYPE_DEFAULT 0 /* most boards */
60#define BOARD_TYPE_DB1200 1 /* IRQs aren't gpios */
61#define BOARD_TYPE_PB1100 2 /* VS bits slightly different */
62 int board_type;
63};
64
65#define to_db1x_socket(x) container_of(x, struct db1x_pcmcia_sock, socket)
66
67/* DB/PB1200: check CPLD SIGSTATUS register bit 10/12 */
68static int db1200_card_inserted(struct db1x_pcmcia_sock *sock)
69{
70 unsigned short sigstat;
71
72 sigstat = bcsr_read(BCSR_SIGSTAT);
73 return sigstat & 1 << (8 + 2 * sock->nr);
74}
75
76/* carddetect gpio: low-active */
77static int db1000_card_inserted(struct db1x_pcmcia_sock *sock)
78{
79 return !gpio_get_value(irq_to_gpio(sock->insert_irq));
80}
81
82static int db1x_card_inserted(struct db1x_pcmcia_sock *sock)
83{
84 switch (sock->board_type) {
85 case BOARD_TYPE_DB1200:
86 return db1200_card_inserted(sock);
87 default:
88 return db1000_card_inserted(sock);
89 }
90}
91
92/* STSCHG tends to bounce heavily when cards are inserted/ejected.
93 * To avoid this, the interrupt is normally disabled and only enabled
94 * after reset to a card has been de-asserted.
95 */
96static inline void set_stschg(struct db1x_pcmcia_sock *sock, int en)
97{
98 if (sock->stschg_irq != -1) {
99 if (en)
100 enable_irq(sock->stschg_irq);
101 else
102 disable_irq(sock->stschg_irq);
103 }
104}
105
106static irqreturn_t db1000_pcmcia_cdirq(int irq, void *data)
107{
108 struct db1x_pcmcia_sock *sock = data;
109
110 pcmcia_parse_events(&sock->socket, SS_DETECT);
111
112 return IRQ_HANDLED;
113}
114
115static irqreturn_t db1000_pcmcia_stschgirq(int irq, void *data)
116{
117 struct db1x_pcmcia_sock *sock = data;
118
119 pcmcia_parse_events(&sock->socket, SS_STSCHG);
120
121 return IRQ_HANDLED;
122}
123
124static irqreturn_t db1200_pcmcia_cdirq(int irq, void *data)
125{
126 struct db1x_pcmcia_sock *sock = data;
127
128 /* Db/Pb1200 have separate per-socket insertion and ejection
129 * interrupts which stay asserted as long as the card is
130 * inserted/missing. The one which caused us to be called
131 * needs to be disabled and the other one enabled.
132 */
133 if (irq == sock->insert_irq) {
134 disable_irq_nosync(sock->insert_irq);
135 enable_irq(sock->eject_irq);
136 } else {
137 disable_irq_nosync(sock->eject_irq);
138 enable_irq(sock->insert_irq);
139 }
140
141 pcmcia_parse_events(&sock->socket, SS_DETECT);
142
143 return IRQ_HANDLED;
144}
145
146static int db1x_pcmcia_setup_irqs(struct db1x_pcmcia_sock *sock)
147{
148 int ret;
149 unsigned long flags;
150
151 if (sock->stschg_irq != -1) {
152 ret = request_irq(sock->stschg_irq, db1000_pcmcia_stschgirq,
153 0, "pcmcia_stschg", sock);
154 if (ret)
155 return ret;
156 }
157
158 /* Db/Pb1200 have separate per-socket insertion and ejection
159 * interrupts, which should show edge behaviour but don't.
160 * So interrupts are disabled until both insertion and
161 * ejection handler have been registered and the currently
162 * active one disabled.
163 */
164 if (sock->board_type == BOARD_TYPE_DB1200) {
165 local_irq_save(flags);
166
167 ret = request_irq(sock->insert_irq, db1200_pcmcia_cdirq,
168 IRQF_DISABLED, "pcmcia_insert", sock);
169 if (ret)
170 goto out1;
171
172 ret = request_irq(sock->eject_irq, db1200_pcmcia_cdirq,
173 IRQF_DISABLED, "pcmcia_eject", sock);
174 if (ret) {
175 free_irq(sock->insert_irq, sock);
176 local_irq_restore(flags);
177 goto out1;
178 }
179
180 /* disable the currently active one */
181 if (db1200_card_inserted(sock))
182 disable_irq_nosync(sock->insert_irq);
183 else
184 disable_irq_nosync(sock->eject_irq);
185
186 local_irq_restore(flags);
187 } else {
188 /* all other (older) Db1x00 boards use a GPIO to show
189 * card detection status: use both-edge triggers.
190 */
191 set_irq_type(sock->insert_irq, IRQ_TYPE_EDGE_BOTH);
192 ret = request_irq(sock->insert_irq, db1000_pcmcia_cdirq,
193 0, "pcmcia_carddetect", sock);
194
195 if (ret)
196 goto out1;
197 }
198
199 return 0; /* all done */
200
201out1:
202 if (sock->stschg_irq != -1)
203 free_irq(sock->stschg_irq, sock);
204
205 return ret;
206}
207
208static void db1x_pcmcia_free_irqs(struct db1x_pcmcia_sock *sock)
209{
210 if (sock->stschg_irq != -1)
211 free_irq(sock->stschg_irq, sock);
212
213 free_irq(sock->insert_irq, sock);
214 if (sock->eject_irq != -1)
215 free_irq(sock->eject_irq, sock);
216}
217
218/*
219 * configure a PCMCIA socket on the Db1x00 series of boards (and
220 * compatibles).
221 *
222 * 2 external registers are involved:
223 * pcmcia_status (offset 0x04): bits [0:1/2:3]: read card voltage id
224 * pcmcia_control(offset 0x10):
225 * bits[0:1] set vcc for card
226 * bits[2:3] set vpp for card
227 * bit 4: enable data buffers
228 * bit 7: reset# for card
229 * add 8 for second socket.
230 */
231static int db1x_pcmcia_configure(struct pcmcia_socket *skt,
232 struct socket_state_t *state)
233{
234 struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
235 unsigned short cr_clr, cr_set;
236 unsigned int changed;
237 int v, p, ret;
238
239 /* card voltage setup */
240 cr_clr = (0xf << (sock->nr * 8)); /* clear voltage settings */
241 cr_set = 0;
242 v = p = ret = 0;
243
244 switch (state->Vcc) {
245 case 50:
246 ++v;
247 case 33:
248 ++v;
249 case 0:
250 break;
251 default:
252 printk(KERN_INFO "pcmcia%d unsupported Vcc %d\n",
253 sock->nr, state->Vcc);
254 }
255
256 switch (state->Vpp) {
257 case 12:
258 ++p;
259 case 33:
260 case 50:
261 ++p;
262 case 0:
263 break;
264 default:
265 printk(KERN_INFO "pcmcia%d unsupported Vpp %d\n",
266 sock->nr, state->Vpp);
267 }
268
269 /* sanity check: Vpp must be 0, 12, or Vcc */
270 if (((state->Vcc == 33) && (state->Vpp == 50)) ||
271 ((state->Vcc == 50) && (state->Vpp == 33))) {
272 printk(KERN_INFO "pcmcia%d bad Vcc/Vpp combo (%d %d)\n",
273 sock->nr, state->Vcc, state->Vpp);
274 v = p = 0;
275 ret = -EINVAL;
276 }
277
278 /* create new voltage code */
279 cr_set |= ((v << 2) | p) << (sock->nr * 8);
280
281 changed = state->flags ^ sock->old_flags;
282
283 if (changed & SS_RESET) {
284 if (state->flags & SS_RESET) {
285 set_stschg(sock, 0);
286 /* assert reset, disable io buffers */
287 cr_clr |= (1 << (7 + (sock->nr * 8)));
288 cr_clr |= (1 << (4 + (sock->nr * 8)));
289 } else {
290 /* de-assert reset, enable io buffers */
291 cr_set |= 1 << (7 + (sock->nr * 8));
292 cr_set |= 1 << (4 + (sock->nr * 8));
293 }
294 }
295
296 /* update PCMCIA configuration */
297 bcsr_mod(BCSR_PCMCIA, cr_clr, cr_set);
298
299 sock->old_flags = state->flags;
300
301 /* reset was taken away: give card time to initialize properly */
302 if ((changed & SS_RESET) && !(state->flags & SS_RESET)) {
303 msleep(500);
304 set_stschg(sock, 1);
305 }
306
307 return ret;
308}
309
310/* VCC bits at [3:2]/[11:10] */
311#define GET_VCC(cr, socknr) \
312 ((((cr) >> 2) >> ((socknr) * 8)) & 3)
313
314/* VS bits at [0:1]/[3:2] */
315#define GET_VS(sr, socknr) \
316 (((sr) >> (2 * (socknr))) & 3)
317
318/* reset bits at [7]/[15] */
319#define GET_RESET(cr, socknr) \
320 ((cr) & (1 << (7 + (8 * (socknr)))))
321
322static int db1x_pcmcia_get_status(struct pcmcia_socket *skt,
323 unsigned int *value)
324{
325 struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
326 unsigned short cr, sr;
327 unsigned int status;
328
329 status = db1x_card_inserted(sock) ? SS_DETECT : 0;
330
331 cr = bcsr_read(BCSR_PCMCIA);
332 sr = bcsr_read(BCSR_STATUS);
333
334 /* PB1100/PB1500: voltage key bits are at [5:4] */
335 if (sock->board_type == BOARD_TYPE_PB1100)
336 sr >>= 4;
337
338 /* determine card type */
339 switch (GET_VS(sr, sock->nr)) {
340 case 0:
341 case 2:
342 status |= SS_3VCARD; /* 3V card */
343 case 3:
344 break; /* 5V card: set nothing */
345 default:
346 status |= SS_XVCARD; /* treated as unsupported in core */
347 }
348
349 /* if Vcc is not zero, we have applied power to a card */
350 status |= GET_VCC(cr, sock->nr) ? SS_POWERON : 0;
351
352 /* reset de-asserted? then we're ready */
353 status |= (GET_RESET(cr, sock->nr)) ? SS_READY : SS_RESET;
354
355 *value = status;
356
357 return 0;
358}
359
360static int db1x_pcmcia_sock_init(struct pcmcia_socket *skt)
361{
362 return 0;
363}
364
365static int db1x_pcmcia_sock_suspend(struct pcmcia_socket *skt)
366{
367 return 0;
368}
369
370static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt,
371 struct pccard_io_map *map)
372{
373 struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
374
375 map->start = (u32)sock->virt_io;
376 map->stop = map->start + IO_MAP_SIZE;
377
378 return 0;
379}
380
381static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt,
382 struct pccard_mem_map *map)
383{
384 struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
385
386 if (map->flags & MAP_ATTRIB)
387 map->static_start = sock->phys_attr + map->card_start;
388 else
389 map->static_start = sock->phys_mem + map->card_start;
390
391 return 0;
392}
393
394static struct pccard_operations db1x_pcmcia_operations = {
395 .init = db1x_pcmcia_sock_init,
396 .suspend = db1x_pcmcia_sock_suspend,
397 .get_status = db1x_pcmcia_get_status,
398 .set_socket = db1x_pcmcia_configure,
399 .set_io_map = au1x00_pcmcia_set_io_map,
400 .set_mem_map = au1x00_pcmcia_set_mem_map,
401};
402
403static int __devinit db1x_pcmcia_socket_probe(struct platform_device *pdev)
404{
405 struct db1x_pcmcia_sock *sock;
406 struct resource *r;
407 int ret, bid;
408
409 sock = kzalloc(sizeof(struct db1x_pcmcia_sock), GFP_KERNEL);
410 if (!sock)
411 return -ENOMEM;
412
413 sock->nr = pdev->id;
414
415 bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
416 switch (bid) {
417 case BCSR_WHOAMI_PB1500:
418 case BCSR_WHOAMI_PB1500R2:
419 case BCSR_WHOAMI_PB1100:
420 sock->board_type = BOARD_TYPE_PB1100;
421 break;
422 case BCSR_WHOAMI_DB1000 ... BCSR_WHOAMI_PB1550_SDR:
423 sock->board_type = BOARD_TYPE_DEFAULT;
424 break;
425 case BCSR_WHOAMI_PB1200 ... BCSR_WHOAMI_DB1200:
426 sock->board_type = BOARD_TYPE_DB1200;
427 break;
428 default:
429 printk(KERN_INFO "db1xxx-ss: unknown board %d!\n", bid);
430 ret = -ENODEV;
431 goto out0;
432 };
433
434 /*
435 * gather resources necessary and optional nice-to-haves to
436 * operate a socket:
437 * This includes IRQs for Carddetection/ejection, the card
438 * itself and optional status change detection.
439 * Also, the memory areas covered by a socket. For these
440 * we require the 32bit "pseudo" addresses (see the au1000.h
441 * header for more information).
442 */
443
444 /* card: irq assigned to the card itself. */
445 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "card");
446 sock->card_irq = r ? r->start : 0;
447
448 /* insert: irq which triggers on card insertion/ejection */
449 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "insert");
450 sock->insert_irq = r ? r->start : -1;
451
452 /* stschg: irq which trigger on card status change (optional) */
453 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "stschg");
454 sock->stschg_irq = r ? r->start : -1;
455
456 /* eject: irq which triggers on ejection (DB1200/PB1200 only) */
457 r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "eject");
458 sock->eject_irq = r ? r->start : -1;
459
460 ret = -ENODEV;
461
462 /*
463 * pseudo-attr: The 32bit address of the PCMCIA attribute space
464 * for this socket (usually the 36bit address shifted 4 to the
465 * right).
466 */
467 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr");
468 if (!r) {
469 printk(KERN_ERR "pcmcia%d has no 'pseudo-attr' resource!\n",
470 sock->nr);
471 goto out0;
472 }
473 sock->phys_attr = r->start;
474
475 /*
476 * pseudo-mem: The 32bit address of the PCMCIA memory space for
477 * this socket (usually the 36bit address shifted 4 to the right)
478 */
479 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem");
480 if (!r) {
481 printk(KERN_ERR "pcmcia%d has no 'pseudo-mem' resource!\n",
482 sock->nr);
483 goto out0;
484 }
485 sock->phys_mem = r->start;
486
487 /*
488 * pseudo-io: The 32bit address of the PCMCIA IO space for this
489 * socket (usually the 36bit address shifted 4 to the right).
490 */
491 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io");
492 if (!r) {
493 printk(KERN_ERR "pcmcia%d has no 'pseudo-io' resource!\n",
494 sock->nr);
495 goto out0;
496 }
497 sock->phys_io = r->start;
498
499 /*
500 * PCMCIA client drivers use the inb/outb macros to access
501 * the IO registers. Since mips_io_port_base is added
502 * to the access address of the mips implementation of
503 * inb/outb, we need to subtract it here because we want
504 * to access the I/O or MEM address directly, without
505 * going through this "mips_io_port_base" mechanism.
506 */
507 sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) -
508 mips_io_port_base);
509
510 if (!sock->virt_io) {
511 printk(KERN_ERR "pcmcia%d: cannot remap IO area\n",
512 sock->nr);
513 ret = -ENOMEM;
514 goto out0;
515 }
516
517 sock->socket.ops = &db1x_pcmcia_operations;
518 sock->socket.owner = THIS_MODULE;
519 sock->socket.pci_irq = sock->card_irq;
520 sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD;
521 sock->socket.map_size = MEM_MAP_SIZE;
522 sock->socket.io_offset = (unsigned long)sock->virt_io;
523 sock->socket.dev.parent = &pdev->dev;
524 sock->socket.resource_ops = &pccard_static_ops;
525
526 platform_set_drvdata(pdev, sock);
527
528 ret = db1x_pcmcia_setup_irqs(sock);
529 if (ret) {
530 printk(KERN_ERR "pcmcia%d cannot setup interrupts\n",
531 sock->nr);
532 goto out1;
533 }
534
535 set_stschg(sock, 0);
536
537 ret = pcmcia_register_socket(&sock->socket);
538 if (ret) {
539 printk(KERN_ERR "pcmcia%d failed to register\n", sock->nr);
540 goto out2;
541 }
542
543 printk(KERN_INFO "Alchemy Db/Pb1xxx pcmcia%d @ io/attr/mem %09llx"
544 "(%p) %09llx %09llx card/insert/stschg/eject irqs @ %d "
545 "%d %d %d\n", sock->nr, sock->phys_io, sock->virt_io,
546 sock->phys_attr, sock->phys_mem, sock->card_irq,
547 sock->insert_irq, sock->stschg_irq, sock->eject_irq);
548
549 return 0;
550
551out2:
552 db1x_pcmcia_free_irqs(sock);
553out1:
554 iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
555out0:
556 kfree(sock);
557 return ret;
558}
559
560static int __devexit db1x_pcmcia_socket_remove(struct platform_device *pdev)
561{
562 struct db1x_pcmcia_sock *sock = platform_get_drvdata(pdev);
563
564 db1x_pcmcia_free_irqs(sock);
565 pcmcia_unregister_socket(&sock->socket);
566 iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
567 kfree(sock);
568
569 return 0;
570}
571
572#ifdef CONFIG_PM
573static int db1x_pcmcia_suspend(struct device *dev)
574{
575 return pcmcia_socket_dev_suspend(dev);
576}
577
578static int db1x_pcmcia_resume(struct device *dev)
579{
580 return pcmcia_socket_dev_resume(dev);
581}
582
583static struct dev_pm_ops db1x_pcmcia_pmops = {
584 .resume = db1x_pcmcia_resume,
585 .suspend = db1x_pcmcia_suspend,
586 .thaw = db1x_pcmcia_resume,
587 .freeze = db1x_pcmcia_suspend,
588};
589
590#define DB1XXX_SS_PMOPS &db1x_pcmcia_pmops
591
592#else
593
594#define DB1XXX_SS_PMOPS NULL
595
596#endif
597
598static struct platform_driver db1x_pcmcia_socket_driver = {
599 .driver = {
600 .name = "db1xxx_pcmcia",
601 .owner = THIS_MODULE,
602 .pm = DB1XXX_SS_PMOPS
603 },
604 .probe = db1x_pcmcia_socket_probe,
605 .remove = __devexit_p(db1x_pcmcia_socket_remove),
606};
607
608int __init db1x_pcmcia_socket_load(void)
609{
610 return platform_driver_register(&db1x_pcmcia_socket_driver);
611}
612
613void __exit db1x_pcmcia_socket_unload(void)
614{
615 platform_driver_unregister(&db1x_pcmcia_socket_driver);
616}
617
618module_init(db1x_pcmcia_socket_load);
619module_exit(db1x_pcmcia_socket_unload);
620
621MODULE_LICENSE("GPL");
622MODULE_DESCRIPTION("PCMCIA Socket Services for Alchemy Db/Pb1x00 boards");
623MODULE_AUTHOR("Manuel Lauss");
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 1a4a3c49cc15..0f98be4450b7 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -42,8 +42,6 @@ MODULE_DESCRIPTION("PCMCIA Driver Services");
42MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
43 43
44 44
45spinlock_t pcmcia_dev_list_lock;
46
47/*====================================================================*/ 45/*====================================================================*/
48 46
49static void pcmcia_check_driver(struct pcmcia_driver *p_drv) 47static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
@@ -126,9 +124,9 @@ pcmcia_store_new_id(struct device_driver *driver, const char *buf, size_t count)
126 dynid->id.device_no = device_no; 124 dynid->id.device_no = device_no;
127 memcpy(dynid->id.prod_id_hash, prod_id_hash, sizeof(__u32) * 4); 125 memcpy(dynid->id.prod_id_hash, prod_id_hash, sizeof(__u32) * 4);
128 126
129 spin_lock(&pdrv->dynids.lock); 127 mutex_lock(&pdrv->dynids.lock);
130 list_add_tail(&dynid->node, &pdrv->dynids.list); 128 list_add_tail(&dynid->node, &pdrv->dynids.list);
131 spin_unlock(&pdrv->dynids.lock); 129 mutex_unlock(&pdrv->dynids.lock);
132 130
133 if (get_driver(&pdrv->drv)) { 131 if (get_driver(&pdrv->drv)) {
134 retval = driver_attach(&pdrv->drv); 132 retval = driver_attach(&pdrv->drv);
@@ -146,12 +144,12 @@ pcmcia_free_dynids(struct pcmcia_driver *drv)
146{ 144{
147 struct pcmcia_dynid *dynid, *n; 145 struct pcmcia_dynid *dynid, *n;
148 146
149 spin_lock(&drv->dynids.lock); 147 mutex_lock(&drv->dynids.lock);
150 list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { 148 list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) {
151 list_del(&dynid->node); 149 list_del(&dynid->node);
152 kfree(dynid); 150 kfree(dynid);
153 } 151 }
154 spin_unlock(&drv->dynids.lock); 152 mutex_unlock(&drv->dynids.lock);
155} 153}
156 154
157static int 155static int
@@ -182,7 +180,7 @@ int pcmcia_register_driver(struct pcmcia_driver *driver)
182 /* initialize common fields */ 180 /* initialize common fields */
183 driver->drv.bus = &pcmcia_bus_type; 181 driver->drv.bus = &pcmcia_bus_type;
184 driver->drv.owner = driver->owner; 182 driver->drv.owner = driver->owner;
185 spin_lock_init(&driver->dynids.lock); 183 mutex_init(&driver->dynids.lock);
186 INIT_LIST_HEAD(&driver->dynids.list); 184 INIT_LIST_HEAD(&driver->dynids.list);
187 185
188 pr_debug("registering driver %s\n", driver->drv.name); 186 pr_debug("registering driver %s\n", driver->drv.name);
@@ -239,30 +237,21 @@ static void pcmcia_release_function(struct kref *ref)
239static void pcmcia_release_dev(struct device *dev) 237static void pcmcia_release_dev(struct device *dev)
240{ 238{
241 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 239 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
240 int i;
242 dev_dbg(dev, "releasing device\n"); 241 dev_dbg(dev, "releasing device\n");
243 pcmcia_put_socket(p_dev->socket); 242 pcmcia_put_socket(p_dev->socket);
243 for (i = 0; i < 4; i++)
244 kfree(p_dev->prod_id[i]);
244 kfree(p_dev->devname); 245 kfree(p_dev->devname);
245 kref_put(&p_dev->function_config->ref, pcmcia_release_function); 246 kref_put(&p_dev->function_config->ref, pcmcia_release_function);
246 kfree(p_dev); 247 kfree(p_dev);
247} 248}
248 249
249static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc)
250{
251 if (!s->pcmcia_state.device_add_pending) {
252 dev_dbg(&s->dev, "scheduling to add %s secondary"
253 " device to %d\n", mfc ? "mfc" : "pfc", s->sock);
254 s->pcmcia_state.device_add_pending = 1;
255 s->pcmcia_state.mfc_pfc = mfc;
256 schedule_work(&s->device_add);
257 }
258 return;
259}
260 250
261static int pcmcia_device_probe(struct device *dev) 251static int pcmcia_device_probe(struct device *dev)
262{ 252{
263 struct pcmcia_device *p_dev; 253 struct pcmcia_device *p_dev;
264 struct pcmcia_driver *p_drv; 254 struct pcmcia_driver *p_drv;
265 struct pcmcia_device_id *did;
266 struct pcmcia_socket *s; 255 struct pcmcia_socket *s;
267 cistpl_config_t cis_config; 256 cistpl_config_t cis_config;
268 int ret = 0; 257 int ret = 0;
@@ -275,18 +264,6 @@ static int pcmcia_device_probe(struct device *dev)
275 p_drv = to_pcmcia_drv(dev->driver); 264 p_drv = to_pcmcia_drv(dev->driver);
276 s = p_dev->socket; 265 s = p_dev->socket;
277 266
278 /* The PCMCIA code passes the match data in via dev_set_drvdata(dev)
279 * which is an ugly hack. Once the driver probe is called it may
280 * and often will overwrite the match data so we must save it first
281 *
282 * handle pseudo multifunction devices:
283 * there are at most two pseudo multifunction devices.
284 * if we're matching against the first, schedule a
285 * call which will then check whether there are two
286 * pseudo devices, and if not, add the second one.
287 */
288 did = dev_get_drvdata(&p_dev->dev);
289
290 dev_dbg(dev, "trying to bind to %s\n", p_drv->drv.name); 267 dev_dbg(dev, "trying to bind to %s\n", p_drv->drv.name);
291 268
292 if ((!p_drv->probe) || (!p_dev->function_config) || 269 if ((!p_drv->probe) || (!p_dev->function_config) ||
@@ -315,9 +292,11 @@ static int pcmcia_device_probe(struct device *dev)
315 goto put_module; 292 goto put_module;
316 } 293 }
317 294
318 if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && 295 mutex_lock(&s->ops_mutex);
296 if ((s->pcmcia_state.has_pfc) &&
319 (p_dev->socket->device_count == 1) && (p_dev->device_no == 0)) 297 (p_dev->socket->device_count == 1) && (p_dev->device_no == 0))
320 pcmcia_add_device_later(p_dev->socket, 0); 298 pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
299 mutex_unlock(&s->ops_mutex);
321 300
322put_module: 301put_module:
323 if (ret) 302 if (ret)
@@ -336,26 +315,27 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le
336{ 315{
337 struct pcmcia_device *p_dev; 316 struct pcmcia_device *p_dev;
338 struct pcmcia_device *tmp; 317 struct pcmcia_device *tmp;
339 unsigned long flags;
340 318
341 dev_dbg(leftover ? &leftover->dev : &s->dev, 319 dev_dbg(leftover ? &leftover->dev : &s->dev,
342 "pcmcia_card_remove(%d) %s\n", s->sock, 320 "pcmcia_card_remove(%d) %s\n", s->sock,
343 leftover ? leftover->devname : ""); 321 leftover ? leftover->devname : "");
344 322
323 mutex_lock(&s->ops_mutex);
345 if (!leftover) 324 if (!leftover)
346 s->device_count = 0; 325 s->device_count = 0;
347 else 326 else
348 s->device_count = 1; 327 s->device_count = 1;
328 mutex_unlock(&s->ops_mutex);
349 329
350 /* unregister all pcmcia_devices registered with this socket, except leftover */ 330 /* unregister all pcmcia_devices registered with this socket, except leftover */
351 list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) { 331 list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) {
352 if (p_dev == leftover) 332 if (p_dev == leftover)
353 continue; 333 continue;
354 334
355 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 335 mutex_lock(&s->ops_mutex);
356 list_del(&p_dev->socket_device_list); 336 list_del(&p_dev->socket_device_list);
357 p_dev->_removed = 1; 337 p_dev->_removed = 1;
358 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 338 mutex_unlock(&s->ops_mutex);
359 339
360 dev_dbg(&p_dev->dev, "unregistering device\n"); 340 dev_dbg(&p_dev->dev, "unregistering device\n");
361 device_unregister(&p_dev->dev); 341 device_unregister(&p_dev->dev);
@@ -368,7 +348,6 @@ static int pcmcia_device_remove(struct device *dev)
368{ 348{
369 struct pcmcia_device *p_dev; 349 struct pcmcia_device *p_dev;
370 struct pcmcia_driver *p_drv; 350 struct pcmcia_driver *p_drv;
371 struct pcmcia_device_id *did;
372 int i; 351 int i;
373 352
374 p_dev = to_pcmcia_dev(dev); 353 p_dev = to_pcmcia_dev(dev);
@@ -380,9 +359,8 @@ static int pcmcia_device_remove(struct device *dev)
380 * pseudo multi-function card, we need to unbind 359 * pseudo multi-function card, we need to unbind
381 * all devices 360 * all devices
382 */ 361 */
383 did = dev_get_drvdata(&p_dev->dev); 362 if ((p_dev->socket->pcmcia_state.has_pfc) &&
384 if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) && 363 (p_dev->socket->device_count > 0) &&
385 (p_dev->socket->device_count != 0) &&
386 (p_dev->device_no == 0)) 364 (p_dev->device_no == 0))
387 pcmcia_card_remove(p_dev->socket, p_dev); 365 pcmcia_card_remove(p_dev->socket, p_dev);
388 366
@@ -431,16 +409,20 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
431 409
432 if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, 410 if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL,
433 CISTPL_MANFID, &manf_id)) { 411 CISTPL_MANFID, &manf_id)) {
412 mutex_lock(&p_dev->socket->ops_mutex);
434 p_dev->manf_id = manf_id.manf; 413 p_dev->manf_id = manf_id.manf;
435 p_dev->card_id = manf_id.card; 414 p_dev->card_id = manf_id.card;
436 p_dev->has_manf_id = 1; 415 p_dev->has_manf_id = 1;
437 p_dev->has_card_id = 1; 416 p_dev->has_card_id = 1;
417 mutex_unlock(&p_dev->socket->ops_mutex);
438 } 418 }
439 419
440 if (!pccard_read_tuple(p_dev->socket, p_dev->func, 420 if (!pccard_read_tuple(p_dev->socket, p_dev->func,
441 CISTPL_FUNCID, &func_id)) { 421 CISTPL_FUNCID, &func_id)) {
422 mutex_lock(&p_dev->socket->ops_mutex);
442 p_dev->func_id = func_id.func; 423 p_dev->func_id = func_id.func;
443 p_dev->has_func_id = 1; 424 p_dev->has_func_id = 1;
425 mutex_unlock(&p_dev->socket->ops_mutex);
444 } else { 426 } else {
445 /* rule of thumb: cards with no FUNCID, but with 427 /* rule of thumb: cards with no FUNCID, but with
446 * common memory device geometry information, are 428 * common memory device geometry information, are
@@ -457,17 +439,21 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
457 dev_dbg(&p_dev->dev, 439 dev_dbg(&p_dev->dev,
458 "mem device geometry probably means " 440 "mem device geometry probably means "
459 "FUNCID_MEMORY\n"); 441 "FUNCID_MEMORY\n");
442 mutex_lock(&p_dev->socket->ops_mutex);
460 p_dev->func_id = CISTPL_FUNCID_MEMORY; 443 p_dev->func_id = CISTPL_FUNCID_MEMORY;
461 p_dev->has_func_id = 1; 444 p_dev->has_func_id = 1;
445 mutex_unlock(&p_dev->socket->ops_mutex);
462 } 446 }
463 kfree(devgeo); 447 kfree(devgeo);
464 } 448 }
465 449
466 if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, CISTPL_VERS_1, 450 if (!pccard_read_tuple(p_dev->socket, BIND_FN_ALL, CISTPL_VERS_1,
467 vers1)) { 451 vers1)) {
452 mutex_lock(&p_dev->socket->ops_mutex);
468 for (i = 0; i < min_t(unsigned int, 4, vers1->ns); i++) { 453 for (i = 0; i < min_t(unsigned int, 4, vers1->ns); i++) {
469 char *tmp; 454 char *tmp;
470 unsigned int length; 455 unsigned int length;
456 char *new;
471 457
472 tmp = vers1->str + vers1->ofs[i]; 458 tmp = vers1->str + vers1->ofs[i];
473 459
@@ -475,14 +461,17 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
475 if ((length < 2) || (length > 255)) 461 if ((length < 2) || (length > 255))
476 continue; 462 continue;
477 463
478 p_dev->prod_id[i] = kmalloc(sizeof(char) * length, 464 new = kmalloc(sizeof(char) * length, GFP_KERNEL);
479 GFP_KERNEL); 465 if (!new)
480 if (!p_dev->prod_id[i])
481 continue; 466 continue;
482 467
483 p_dev->prod_id[i] = strncpy(p_dev->prod_id[i], 468 new = strncpy(new, tmp, length);
484 tmp, length); 469
470 tmp = p_dev->prod_id[i];
471 p_dev->prod_id[i] = new;
472 kfree(tmp);
485 } 473 }
474 mutex_unlock(&p_dev->socket->ops_mutex);
486 } 475 }
487 476
488 kfree(vers1); 477 kfree(vers1);
@@ -502,7 +491,7 @@ static DEFINE_MUTEX(device_add_lock);
502struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) 491struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function)
503{ 492{
504 struct pcmcia_device *p_dev, *tmp_dev; 493 struct pcmcia_device *p_dev, *tmp_dev;
505 unsigned long flags; 494 int i;
506 495
507 s = pcmcia_get_socket(s); 496 s = pcmcia_get_socket(s);
508 if (!s) 497 if (!s)
@@ -512,16 +501,19 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
512 501
513 pr_debug("adding device to %d, function %d\n", s->sock, function); 502 pr_debug("adding device to %d, function %d\n", s->sock, function);
514 503
515 /* max of 4 devices per card */
516 if (s->device_count == 4)
517 goto err_put;
518
519 p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL); 504 p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL);
520 if (!p_dev) 505 if (!p_dev)
521 goto err_put; 506 goto err_put;
522 507
523 p_dev->socket = s; 508 mutex_lock(&s->ops_mutex);
524 p_dev->device_no = (s->device_count++); 509 p_dev->device_no = (s->device_count++);
510 mutex_unlock(&s->ops_mutex);
511
512 /* max of 2 devices per card */
513 if (p_dev->device_no >= 2)
514 goto err_free;
515
516 p_dev->socket = s;
525 p_dev->func = function; 517 p_dev->func = function;
526 518
527 p_dev->dev.bus = &pcmcia_bus_type; 519 p_dev->dev.bus = &pcmcia_bus_type;
@@ -538,7 +530,7 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
538 goto err_free; 530 goto err_free;
539 dev_dbg(&p_dev->dev, "devname is %s\n", p_dev->devname); 531 dev_dbg(&p_dev->dev, "devname is %s\n", p_dev->devname);
540 532
541 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 533 mutex_lock(&s->ops_mutex);
542 534
543 /* 535 /*
544 * p_dev->function_config must be the same for all card functions. 536 * p_dev->function_config must be the same for all card functions.
@@ -556,7 +548,7 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
556 /* Add to the list in pcmcia_bus_socket */ 548 /* Add to the list in pcmcia_bus_socket */
557 list_add(&p_dev->socket_device_list, &s->devices_list); 549 list_add(&p_dev->socket_device_list, &s->devices_list);
558 550
559 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 551 mutex_unlock(&s->ops_mutex);
560 552
561 if (!p_dev->function_config) { 553 if (!p_dev->function_config) {
562 dev_dbg(&p_dev->dev, "creating config_t\n"); 554 dev_dbg(&p_dev->dev, "creating config_t\n");
@@ -581,14 +573,19 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
581 return p_dev; 573 return p_dev;
582 574
583 err_unreg: 575 err_unreg:
584 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 576 mutex_lock(&s->ops_mutex);
585 list_del(&p_dev->socket_device_list); 577 list_del(&p_dev->socket_device_list);
586 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 578 mutex_unlock(&s->ops_mutex);
587 579
588 err_free: 580 err_free:
581 mutex_lock(&s->ops_mutex);
582 s->device_count--;
583 mutex_unlock(&s->ops_mutex);
584
585 for (i = 0; i < 4; i++)
586 kfree(p_dev->prod_id[i]);
589 kfree(p_dev->devname); 587 kfree(p_dev->devname);
590 kfree(p_dev); 588 kfree(p_dev);
591 s->device_count--;
592 err_put: 589 err_put:
593 mutex_unlock(&device_add_lock); 590 mutex_unlock(&device_add_lock);
594 pcmcia_put_socket(s); 591 pcmcia_put_socket(s);
@@ -601,19 +598,23 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
601{ 598{
602 cistpl_longlink_mfc_t mfc; 599 cistpl_longlink_mfc_t mfc;
603 unsigned int no_funcs, i, no_chains; 600 unsigned int no_funcs, i, no_chains;
604 int ret = 0; 601 int ret = -EAGAIN;
605 602
603 mutex_lock(&s->ops_mutex);
606 if (!(s->resource_setup_done)) { 604 if (!(s->resource_setup_done)) {
607 dev_dbg(&s->dev, 605 dev_dbg(&s->dev,
608 "no resources available, delaying card_add\n"); 606 "no resources available, delaying card_add\n");
607 mutex_unlock(&s->ops_mutex);
609 return -EAGAIN; /* try again, but later... */ 608 return -EAGAIN; /* try again, but later... */
610 } 609 }
611 610
612 if (pcmcia_validate_mem(s)) { 611 if (pcmcia_validate_mem(s)) {
613 dev_dbg(&s->dev, "validating mem resources failed, " 612 dev_dbg(&s->dev, "validating mem resources failed, "
614 "delaying card_add\n"); 613 "delaying card_add\n");
614 mutex_unlock(&s->ops_mutex);
615 return -EAGAIN; /* try again, but later... */ 615 return -EAGAIN; /* try again, but later... */
616 } 616 }
617 mutex_unlock(&s->ops_mutex);
617 618
618 ret = pccard_validate_cis(s, &no_chains); 619 ret = pccard_validate_cis(s, &no_chains);
619 if (ret || !no_chains) { 620 if (ret || !no_chains) {
@@ -634,17 +635,7 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
634} 635}
635 636
636 637
637static void pcmcia_delayed_add_device(struct work_struct *work) 638static int pcmcia_requery_callback(struct device *dev, void * _data)
638{
639 struct pcmcia_socket *s =
640 container_of(work, struct pcmcia_socket, device_add);
641 dev_dbg(&s->dev, "adding additional device to %d\n", s->sock);
642 pcmcia_device_add(s, s->pcmcia_state.mfc_pfc);
643 s->pcmcia_state.device_add_pending = 0;
644 s->pcmcia_state.mfc_pfc = 0;
645}
646
647static int pcmcia_requery(struct device *dev, void * _data)
648{ 639{
649 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 640 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
650 if (!p_dev->dev.driver) { 641 if (!p_dev->dev.driver) {
@@ -655,45 +646,67 @@ static int pcmcia_requery(struct device *dev, void * _data)
655 return 0; 646 return 0;
656} 647}
657 648
658static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis)
659{
660 int no_devices = 0;
661 int ret = 0;
662 unsigned long flags;
663 649
664 /* must be called with skt_mutex held */ 650static void pcmcia_requery(struct pcmcia_socket *s)
665 dev_dbg(&skt->dev, "re-scanning socket %d\n", skt->sock); 651{
652 int present, has_pfc;
666 653
667 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 654 mutex_lock(&s->ops_mutex);
668 if (list_empty(&skt->devices_list)) 655 present = s->pcmcia_state.present;
669 no_devices = 1; 656 mutex_unlock(&s->ops_mutex);
670 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
671 657
672 /* If this is because of a CIS override, start over */ 658 if (!present)
673 if (new_cis && !no_devices) 659 return;
674 pcmcia_card_remove(skt, NULL);
675 660
676 /* if no devices were added for this socket yet because of 661 if (s->functions == 0) {
677 * missing resource information or other trouble, we need to 662 pcmcia_card_add(s);
678 * do this now. */ 663 return;
679 if (no_devices || new_cis) {
680 ret = pcmcia_card_add(skt);
681 if (ret)
682 return;
683 } 664 }
684 665
685 /* some device information might have changed because of a CIS 666 /* some device information might have changed because of a CIS
686 * update or because we can finally read it correctly... so 667 * update or because we can finally read it correctly... so
687 * determine it again, overwriting old values if necessary. */ 668 * determine it again, overwriting old values if necessary. */
688 bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery); 669 bus_for_each_dev(&pcmcia_bus_type, NULL, NULL, pcmcia_requery_callback);
670
671 /* if the CIS changed, we need to check whether the number of
672 * functions changed. */
673 if (s->fake_cis) {
674 int old_funcs, new_funcs;
675 cistpl_longlink_mfc_t mfc;
676
677 /* does this cis override add or remove functions? */
678 old_funcs = s->functions;
679
680 if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC,
681 &mfc))
682 new_funcs = mfc.nfn;
683 else
684 new_funcs = 1;
685 if (old_funcs > new_funcs) {
686 pcmcia_card_remove(s, NULL);
687 pcmcia_card_add(s);
688 } else if (new_funcs > old_funcs) {
689 s->functions = new_funcs;
690 pcmcia_device_add(s, 1);
691 }
692 }
693
694 /* If the PCMCIA device consists of two pseudo devices,
695 * call pcmcia_device_add() -- which will fail if both
696 * devices are already registered. */
697 mutex_lock(&s->ops_mutex);
698 has_pfc = s->pcmcia_state.has_pfc;
699 mutex_unlock(&s->ops_mutex);
700 if (has_pfc)
701 pcmcia_device_add(s, 0);
689 702
690 /* we re-scan all devices, not just the ones connected to this 703 /* we re-scan all devices, not just the ones connected to this
691 * socket. This does not matter, though. */ 704 * socket. This does not matter, though. */
692 ret = bus_rescan_devices(&pcmcia_bus_type); 705 if (bus_rescan_devices(&pcmcia_bus_type))
693 if (ret) 706 dev_warn(&s->dev, "rescanning the bus failed\n");
694 printk(KERN_INFO "pcmcia: bus_rescan_devices failed\n");
695} 707}
696 708
709
697#ifdef CONFIG_PCMCIA_LOAD_CIS 710#ifdef CONFIG_PCMCIA_LOAD_CIS
698 711
699/** 712/**
@@ -710,9 +723,6 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
710 struct pcmcia_socket *s = dev->socket; 723 struct pcmcia_socket *s = dev->socket;
711 const struct firmware *fw; 724 const struct firmware *fw;
712 int ret = -ENOMEM; 725 int ret = -ENOMEM;
713 int no_funcs;
714 int old_funcs;
715 cistpl_longlink_mfc_t mfc;
716 726
717 if (!filename) 727 if (!filename)
718 return -EINVAL; 728 return -EINVAL;
@@ -739,19 +749,8 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
739 /* update information */ 749 /* update information */
740 pcmcia_device_query(dev); 750 pcmcia_device_query(dev);
741 751
742 /* does this cis override add or remove functions? */ 752 /* requery (as number of functions might have changed) */
743 old_funcs = s->functions; 753 pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
744
745 if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc))
746 no_funcs = mfc.nfn;
747 else
748 no_funcs = 1;
749 s->functions = no_funcs;
750
751 if (old_funcs > no_funcs)
752 pcmcia_card_remove(s, dev);
753 else if (no_funcs > old_funcs)
754 pcmcia_add_device_later(s, 1);
755 } 754 }
756 release: 755 release:
757 release_firmware(fw); 756 release_firmware(fw);
@@ -818,9 +817,14 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
818 if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) { 817 if (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) {
819 if (dev->device_no != did->device_no) 818 if (dev->device_no != did->device_no)
820 return 0; 819 return 0;
820 mutex_lock(&dev->socket->ops_mutex);
821 dev->socket->pcmcia_state.has_pfc = 1;
822 mutex_unlock(&dev->socket->ops_mutex);
821 } 823 }
822 824
823 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) { 825 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID) {
826 int ret;
827
824 if ((!dev->has_func_id) || (dev->func_id != did->func_id)) 828 if ((!dev->has_func_id) || (dev->func_id != did->func_id))
825 return 0; 829 return 0;
826 830
@@ -835,10 +839,15 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
835 * after it has re-checked that there is no possible module 839 * after it has re-checked that there is no possible module
836 * with a prod_id/manf_id/card_id match. 840 * with a prod_id/manf_id/card_id match.
837 */ 841 */
838 dev_dbg(&dev->dev, 842 mutex_lock(&dev->socket->ops_mutex);
839 "skipping FUNC_ID match until userspace interaction\n"); 843 ret = dev->allow_func_id_match;
840 if (!dev->allow_func_id_match) 844 mutex_unlock(&dev->socket->ops_mutex);
845
846 if (!ret) {
847 dev_dbg(&dev->dev,
848 "skipping FUNC_ID match until userspace ACK\n");
841 return 0; 849 return 0;
850 }
842 } 851 }
843 852
844 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { 853 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) {
@@ -859,8 +868,6 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
859 return 0; 868 return 0;
860 } 869 }
861 870
862 dev_set_drvdata(&dev->dev, did);
863
864 return 1; 871 return 1;
865} 872}
866 873
@@ -873,16 +880,16 @@ static int pcmcia_bus_match(struct device *dev, struct device_driver *drv)
873 struct pcmcia_dynid *dynid; 880 struct pcmcia_dynid *dynid;
874 881
875 /* match dynamic devices first */ 882 /* match dynamic devices first */
876 spin_lock(&p_drv->dynids.lock); 883 mutex_lock(&p_drv->dynids.lock);
877 list_for_each_entry(dynid, &p_drv->dynids.list, node) { 884 list_for_each_entry(dynid, &p_drv->dynids.list, node) {
878 dev_dbg(dev, "trying to match to %s\n", drv->name); 885 dev_dbg(dev, "trying to match to %s\n", drv->name);
879 if (pcmcia_devmatch(p_dev, &dynid->id)) { 886 if (pcmcia_devmatch(p_dev, &dynid->id)) {
880 dev_dbg(dev, "matched to %s\n", drv->name); 887 dev_dbg(dev, "matched to %s\n", drv->name);
881 spin_unlock(&p_drv->dynids.lock); 888 mutex_unlock(&p_drv->dynids.lock);
882 return 1; 889 return 1;
883 } 890 }
884 } 891 }
885 spin_unlock(&p_drv->dynids.lock); 892 mutex_unlock(&p_drv->dynids.lock);
886 893
887#ifdef CONFIG_PCMCIA_IOCTL 894#ifdef CONFIG_PCMCIA_IOCTL
888 /* matching by cardmgr */ 895 /* matching by cardmgr */
@@ -970,13 +977,14 @@ static int runtime_suspend(struct device *dev)
970 return rc; 977 return rc;
971} 978}
972 979
973static void runtime_resume(struct device *dev) 980static int runtime_resume(struct device *dev)
974{ 981{
975 int rc; 982 int rc;
976 983
977 down(&dev->sem); 984 down(&dev->sem);
978 rc = pcmcia_dev_resume(dev); 985 rc = pcmcia_dev_resume(dev);
979 up(&dev->sem); 986 up(&dev->sem);
987 return rc;
980} 988}
981 989
982/************************ per-device sysfs output ***************************/ 990/************************ per-device sysfs output ***************************/
@@ -1027,7 +1035,7 @@ static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute
1027 if ((!p_dev->suspended) && !strncmp(buf, "off", 3)) 1035 if ((!p_dev->suspended) && !strncmp(buf, "off", 3))
1028 ret = runtime_suspend(dev); 1036 ret = runtime_suspend(dev);
1029 else if (p_dev->suspended && !strncmp(buf, "on", 2)) 1037 else if (p_dev->suspended && !strncmp(buf, "on", 2))
1030 runtime_resume(dev); 1038 ret = runtime_resume(dev);
1031 1039
1032 return ret ? ret : count; 1040 return ret ? ret : count;
1033} 1041}
@@ -1059,19 +1067,14 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
1059 struct device_attribute *attr, const char *buf, size_t count) 1067 struct device_attribute *attr, const char *buf, size_t count)
1060{ 1068{
1061 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 1069 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
1062 int ret;
1063 1070
1064 if (!count) 1071 if (!count)
1065 return -EINVAL; 1072 return -EINVAL;
1066 1073
1067 mutex_lock(&p_dev->socket->skt_mutex); 1074 mutex_lock(&p_dev->socket->ops_mutex);
1068 p_dev->allow_func_id_match = 1; 1075 p_dev->allow_func_id_match = 1;
1069 mutex_unlock(&p_dev->socket->skt_mutex); 1076 mutex_unlock(&p_dev->socket->ops_mutex);
1070 1077 pcmcia_parse_uevents(p_dev->socket, PCMCIA_UEVENT_REQUERY);
1071 ret = bus_rescan_devices(&pcmcia_bus_type);
1072 if (ret)
1073 printk(KERN_INFO "pcmcia: bus_rescan_devices failed after "
1074 "allowing func_id matches\n");
1075 1078
1076 return count; 1079 return count;
1077} 1080}
@@ -1099,8 +1102,13 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state)
1099 struct pcmcia_driver *p_drv = NULL; 1102 struct pcmcia_driver *p_drv = NULL;
1100 int ret = 0; 1103 int ret = 0;
1101 1104
1102 if (p_dev->suspended) 1105 mutex_lock(&p_dev->socket->ops_mutex);
1106 if (p_dev->suspended) {
1107 mutex_unlock(&p_dev->socket->ops_mutex);
1103 return 0; 1108 return 0;
1109 }
1110 p_dev->suspended = 1;
1111 mutex_unlock(&p_dev->socket->ops_mutex);
1104 1112
1105 dev_dbg(dev, "suspending\n"); 1113 dev_dbg(dev, "suspending\n");
1106 1114
@@ -1117,6 +1125,9 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state)
1117 "pcmcia: device %s (driver %s) did " 1125 "pcmcia: device %s (driver %s) did "
1118 "not want to go to sleep (%d)\n", 1126 "not want to go to sleep (%d)\n",
1119 p_dev->devname, p_drv->drv.name, ret); 1127 p_dev->devname, p_drv->drv.name, ret);
1128 mutex_lock(&p_dev->socket->ops_mutex);
1129 p_dev->suspended = 0;
1130 mutex_unlock(&p_dev->socket->ops_mutex);
1120 goto out; 1131 goto out;
1121 } 1132 }
1122 } 1133 }
@@ -1127,8 +1138,6 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state)
1127 } 1138 }
1128 1139
1129 out: 1140 out:
1130 if (!ret)
1131 p_dev->suspended = 1;
1132 return ret; 1141 return ret;
1133} 1142}
1134 1143
@@ -1139,8 +1148,13 @@ static int pcmcia_dev_resume(struct device *dev)
1139 struct pcmcia_driver *p_drv = NULL; 1148 struct pcmcia_driver *p_drv = NULL;
1140 int ret = 0; 1149 int ret = 0;
1141 1150
1142 if (!p_dev->suspended) 1151 mutex_lock(&p_dev->socket->ops_mutex);
1152 if (!p_dev->suspended) {
1153 mutex_unlock(&p_dev->socket->ops_mutex);
1143 return 0; 1154 return 0;
1155 }
1156 p_dev->suspended = 0;
1157 mutex_unlock(&p_dev->socket->ops_mutex);
1144 1158
1145 dev_dbg(dev, "resuming\n"); 1159 dev_dbg(dev, "resuming\n");
1146 1160
@@ -1161,8 +1175,6 @@ static int pcmcia_dev_resume(struct device *dev)
1161 ret = p_drv->resume(p_dev); 1175 ret = p_drv->resume(p_dev);
1162 1176
1163 out: 1177 out:
1164 if (!ret)
1165 p_dev->suspended = 0;
1166 return ret; 1178 return ret;
1167} 1179}
1168 1180
@@ -1237,13 +1249,22 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
1237 1249
1238 switch (event) { 1250 switch (event) {
1239 case CS_EVENT_CARD_REMOVAL: 1251 case CS_EVENT_CARD_REMOVAL:
1252 mutex_lock(&s->ops_mutex);
1240 s->pcmcia_state.present = 0; 1253 s->pcmcia_state.present = 0;
1254 mutex_unlock(&s->ops_mutex);
1241 pcmcia_card_remove(skt, NULL); 1255 pcmcia_card_remove(skt, NULL);
1242 handle_event(skt, event); 1256 handle_event(skt, event);
1257 mutex_lock(&s->ops_mutex);
1258 destroy_cis_cache(s);
1259 mutex_unlock(&s->ops_mutex);
1243 break; 1260 break;
1244 1261
1245 case CS_EVENT_CARD_INSERTION: 1262 case CS_EVENT_CARD_INSERTION:
1263 mutex_lock(&s->ops_mutex);
1264 s->pcmcia_state.has_pfc = 0;
1246 s->pcmcia_state.present = 1; 1265 s->pcmcia_state.present = 1;
1266 destroy_cis_cache(s); /* to be on the safe side... */
1267 mutex_unlock(&s->ops_mutex);
1247 pcmcia_card_add(skt); 1268 pcmcia_card_add(skt);
1248 handle_event(skt, event); 1269 handle_event(skt, event);
1249 break; 1270 break;
@@ -1251,8 +1272,24 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
1251 case CS_EVENT_EJECTION_REQUEST: 1272 case CS_EVENT_EJECTION_REQUEST:
1252 break; 1273 break;
1253 1274
1254 case CS_EVENT_PM_SUSPEND:
1255 case CS_EVENT_PM_RESUME: 1275 case CS_EVENT_PM_RESUME:
1276 if (verify_cis_cache(skt) != 0) {
1277 dev_dbg(&skt->dev, "cis mismatch - different card\n");
1278 /* first, remove the card */
1279 ds_event(skt, CS_EVENT_CARD_REMOVAL, CS_EVENT_PRI_HIGH);
1280 mutex_lock(&s->ops_mutex);
1281 destroy_cis_cache(skt);
1282 kfree(skt->fake_cis);
1283 skt->fake_cis = NULL;
1284 mutex_unlock(&s->ops_mutex);
1285 /* now, add the new card */
1286 ds_event(skt, CS_EVENT_CARD_INSERTION,
1287 CS_EVENT_PRI_LOW);
1288 }
1289 handle_event(skt, event);
1290 break;
1291
1292 case CS_EVENT_PM_SUSPEND:
1256 case CS_EVENT_RESET_PHYSICAL: 1293 case CS_EVENT_RESET_PHYSICAL:
1257 case CS_EVENT_CARD_RESET: 1294 case CS_EVENT_CARD_RESET:
1258 default: 1295 default:
@@ -1275,9 +1312,13 @@ struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *_p_dev)
1275 if (!p_dev) 1312 if (!p_dev)
1276 return NULL; 1313 return NULL;
1277 1314
1315 mutex_lock(&p_dev->socket->ops_mutex);
1278 if (!p_dev->socket->pcmcia_state.present) 1316 if (!p_dev->socket->pcmcia_state.present)
1279 goto out; 1317 goto out;
1280 1318
1319 if (p_dev->socket->pcmcia_state.dead)
1320 goto out;
1321
1281 if (p_dev->_removed) 1322 if (p_dev->_removed)
1282 goto out; 1323 goto out;
1283 1324
@@ -1286,6 +1327,7 @@ struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *_p_dev)
1286 1327
1287 ret = p_dev; 1328 ret = p_dev;
1288 out: 1329 out:
1330 mutex_unlock(&p_dev->socket->ops_mutex);
1289 pcmcia_put_dev(p_dev); 1331 pcmcia_put_dev(p_dev);
1290 return ret; 1332 return ret;
1291} 1333}
@@ -1295,7 +1337,8 @@ EXPORT_SYMBOL(pcmcia_dev_present);
1295static struct pcmcia_callback pcmcia_bus_callback = { 1337static struct pcmcia_callback pcmcia_bus_callback = {
1296 .owner = THIS_MODULE, 1338 .owner = THIS_MODULE,
1297 .event = ds_event, 1339 .event = ds_event,
1298 .requery = pcmcia_bus_rescan, 1340 .requery = pcmcia_requery,
1341 .validate = pccard_validate_cis,
1299 .suspend = pcmcia_bus_suspend, 1342 .suspend = pcmcia_bus_suspend,
1300 .resume = pcmcia_bus_resume, 1343 .resume = pcmcia_bus_resume,
1301}; 1344};
@@ -1313,17 +1356,17 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev,
1313 return -ENODEV; 1356 return -ENODEV;
1314 } 1357 }
1315 1358
1316 /* 1359 ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr);
1317 * Ugly. But we want to wait for the socket threads to have started up. 1360 if (ret) {
1318 * We really should let the drivers themselves drive some of this.. 1361 dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n");
1319 */ 1362 pcmcia_put_socket(socket);
1320 msleep(250); 1363 return ret;
1364 }
1321 1365
1322#ifdef CONFIG_PCMCIA_IOCTL 1366#ifdef CONFIG_PCMCIA_IOCTL
1323 init_waitqueue_head(&socket->queue); 1367 init_waitqueue_head(&socket->queue);
1324#endif 1368#endif
1325 INIT_LIST_HEAD(&socket->devices_list); 1369 INIT_LIST_HEAD(&socket->devices_list);
1326 INIT_WORK(&socket->device_add, pcmcia_delayed_add_device);
1327 memset(&socket->pcmcia_state, 0, sizeof(u8)); 1370 memset(&socket->pcmcia_state, 0, sizeof(u8));
1328 socket->device_count = 0; 1371 socket->device_count = 0;
1329 1372
@@ -1345,14 +1388,20 @@ static void pcmcia_bus_remove_socket(struct device *dev,
1345 if (!socket) 1388 if (!socket)
1346 return; 1389 return;
1347 1390
1391 mutex_lock(&socket->ops_mutex);
1348 socket->pcmcia_state.dead = 1; 1392 socket->pcmcia_state.dead = 1;
1393 mutex_unlock(&socket->ops_mutex);
1394
1349 pccard_register_pcmcia(socket, NULL); 1395 pccard_register_pcmcia(socket, NULL);
1350 1396
1351 /* unregister any unbound devices */ 1397 /* unregister any unbound devices */
1352 mutex_lock(&socket->skt_mutex); 1398 mutex_lock(&socket->skt_mutex);
1353 pcmcia_card_remove(socket, NULL); 1399 pcmcia_card_remove(socket, NULL);
1400 release_cis_mem(socket);
1354 mutex_unlock(&socket->skt_mutex); 1401 mutex_unlock(&socket->skt_mutex);
1355 1402
1403 sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr);
1404
1356 pcmcia_put_socket(socket); 1405 pcmcia_put_socket(socket);
1357 1406
1358 return; 1407 return;
@@ -1383,8 +1432,6 @@ static int __init init_pcmcia_bus(void)
1383{ 1432{
1384 int ret; 1433 int ret;
1385 1434
1386 spin_lock_init(&pcmcia_dev_list_lock);
1387
1388 ret = bus_register(&pcmcia_bus_type); 1435 ret = bus_register(&pcmcia_bus_type);
1389 if (ret < 0) { 1436 if (ret < 0) {
1390 printk(KERN_WARNING "pcmcia: bus_register error: %d\n", ret); 1437 printk(KERN_WARNING "pcmcia: bus_register error: %d\n", ret);
diff --git a/drivers/pcmcia/electra_cf.c b/drivers/pcmcia/electra_cf.c
index d187ba4c5e0e..89cfddca089a 100644
--- a/drivers/pcmcia/electra_cf.c
+++ b/drivers/pcmcia/electra_cf.c
@@ -347,7 +347,7 @@ static int __devexit electra_cf_remove(struct of_device *ofdev)
347 return 0; 347 return 0;
348} 348}
349 349
350static struct of_device_id electra_cf_match[] = { 350static const struct of_device_id electra_cf_match[] = {
351 { 351 {
352 .compatible = "electra-cf", 352 .compatible = "electra-cf",
353 }, 353 },
diff --git a/drivers/pcmcia/i82365.h b/drivers/pcmcia/i82365.h
index 622860c689d9..849ef1b5d687 100644
--- a/drivers/pcmcia/i82365.h
+++ b/drivers/pcmcia/i82365.h
@@ -77,8 +77,8 @@
77#define I365_VPP2_5V 0x04 /* Vpp2 = 5.0v */ 77#define I365_VPP2_5V 0x04 /* Vpp2 = 5.0v */
78#define I365_VPP2_12V 0x08 /* Vpp2 = 12.0v */ 78#define I365_VPP2_12V 0x08 /* Vpp2 = 12.0v */
79#define I365_VPP1_MASK 0x03 /* Mask for turning off Vpp1 */ 79#define I365_VPP1_MASK 0x03 /* Mask for turning off Vpp1 */
80#define I365_VPP1_5V 0x01 /* Vpp2 = 5.0v */ 80#define I365_VPP1_5V 0x01 /* Vpp1 = 5.0v */
81#define I365_VPP1_12V 0x02 /* Vpp2 = 12.0v */ 81#define I365_VPP1_12V 0x02 /* Vpp1 = 12.0v */
82 82
83/* Flags for I365_INTCTL */ 83/* Flags for I365_INTCTL */
84#define I365_RING_ENA 0x80 84#define I365_RING_ENA 0x80
diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
index 26a621c9e2fc..0ece2cd4a85e 100644
--- a/drivers/pcmcia/m32r_cfc.c
+++ b/drivers/pcmcia/m32r_cfc.c
@@ -764,7 +764,7 @@ static int __init init_m32r_pcc(void)
764 for (i = 0 ; i < pcc_sockets ; i++) { 764 for (i = 0 ; i < pcc_sockets ; i++) {
765 socket[i].socket.dev.parent = &pcc_device.dev; 765 socket[i].socket.dev.parent = &pcc_device.dev;
766 socket[i].socket.ops = &pcc_operations; 766 socket[i].socket.ops = &pcc_operations;
767 socket[i].socket.resource_ops = &pccard_nonstatic_ops; 767 socket[i].socket.resource_ops = &pccard_static_ops;
768 socket[i].socket.owner = THIS_MODULE; 768 socket[i].socket.owner = THIS_MODULE;
769 socket[i].number = i; 769 socket[i].number = i;
770 ret = pcmcia_register_socket(&socket[i].socket); 770 ret = pcmcia_register_socket(&socket[i].socket);
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
index 7f79c4e169ae..61c215918128 100644
--- a/drivers/pcmcia/m8xx_pcmcia.c
+++ b/drivers/pcmcia/m8xx_pcmcia.c
@@ -1233,7 +1233,7 @@ static int __init m8xx_probe(struct of_device *ofdev,
1233 socket[i].socket.io_offset = 0; 1233 socket[i].socket.io_offset = 0;
1234 socket[i].socket.pci_irq = pcmcia_schlvl; 1234 socket[i].socket.pci_irq = pcmcia_schlvl;
1235 socket[i].socket.ops = &m8xx_services; 1235 socket[i].socket.ops = &m8xx_services;
1236 socket[i].socket.resource_ops = &pccard_nonstatic_ops; 1236 socket[i].socket.resource_ops = &pccard_iodyn_ops;
1237 socket[i].socket.cb_dev = NULL; 1237 socket[i].socket.cb_dev = NULL;
1238 socket[i].socket.dev.parent = &ofdev->dev; 1238 socket[i].socket.dev.parent = &ofdev->dev;
1239 socket[i].pcmcia = pcmcia; 1239 socket[i].pcmcia = pcmcia;
@@ -1303,7 +1303,7 @@ static int m8xx_resume(struct platform_device *pdev)
1303#define m8xx_resume NULL 1303#define m8xx_resume NULL
1304#endif 1304#endif
1305 1305
1306static struct of_device_id m8xx_pcmcia_match[] = { 1306static const struct of_device_id m8xx_pcmcia_match[] = {
1307 { 1307 {
1308 .type = "pcmcia", 1308 .type = "pcmcia",
1309 .compatible = "fsl,pq-pcmcia", 1309 .compatible = "fsl,pq-pcmcia",
diff --git a/drivers/pcmcia/o2micro.h b/drivers/pcmcia/o2micro.h
index 624442fc0d35..e74bebac2695 100644
--- a/drivers/pcmcia/o2micro.h
+++ b/drivers/pcmcia/o2micro.h
@@ -116,13 +116,12 @@ static int o2micro_override(struct yenta_socket *socket)
116 * from Eric Still, 02Micro. 116 * from Eric Still, 02Micro.
117 */ 117 */
118 u8 a, b; 118 u8 a, b;
119 bool use_speedup;
119 120
120 if (PCI_FUNC(socket->dev->devfn) == 0) { 121 if (PCI_FUNC(socket->dev->devfn) == 0) {
121 a = config_readb(socket, O2_RESERVED1); 122 a = config_readb(socket, O2_RESERVED1);
122 b = config_readb(socket, O2_RESERVED2); 123 b = config_readb(socket, O2_RESERVED2);
123 124 dev_dbg(&socket->dev->dev, "O2: 0x94/0xD4: %02x/%02x\n", a, b);
124 dev_printk(KERN_INFO, &socket->dev->dev,
125 "O2: res at 0x94/0xD4: %02x/%02x\n", a, b);
126 125
127 switch (socket->dev->device) { 126 switch (socket->dev->device) {
128 /* 127 /*
@@ -135,23 +134,37 @@ static int o2micro_override(struct yenta_socket *socket)
135 case PCI_DEVICE_ID_O2_6812: 134 case PCI_DEVICE_ID_O2_6812:
136 case PCI_DEVICE_ID_O2_6832: 135 case PCI_DEVICE_ID_O2_6832:
137 case PCI_DEVICE_ID_O2_6836: 136 case PCI_DEVICE_ID_O2_6836:
138 case PCI_DEVICE_ID_O2_6933: 137 case PCI_DEVICE_ID_O2_6933:
139 dev_printk(KERN_INFO, &socket->dev->dev, 138 use_speedup = false;
140 "Yenta O2: old bridge, disabling read "
141 "prefetch/write burst\n");
142 config_writeb(socket, O2_RESERVED1,
143 a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
144 config_writeb(socket, O2_RESERVED2,
145 b & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
146 break; 139 break;
147
148 default: 140 default:
149 dev_printk(KERN_INFO , &socket->dev->dev, 141 use_speedup = true;
150 "O2: enabling read prefetch/write burst\n"); 142 break;
143 }
144
145 /* the user may override our decision */
146 if (strcasecmp(o2_speedup, "on") == 0)
147 use_speedup = true;
148 else if (strcasecmp(o2_speedup, "off") == 0)
149 use_speedup = false;
150 else if (strcasecmp(o2_speedup, "default") != 0)
151 dev_warn(&socket->dev->dev,
152 "O2: Unknown parameter, using 'default'");
153
154 if (use_speedup) {
155 dev_info(&socket->dev->dev,
156 "O2: enabling read prefetch/write burst\n");
157 config_writeb(socket, O2_RESERVED1,
158 a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST);
159 config_writeb(socket, O2_RESERVED2,
160 b | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST);
161 } else {
162 dev_info(&socket->dev->dev,
163 "O2: disabling read prefetch/write burst\n");
151 config_writeb(socket, O2_RESERVED1, 164 config_writeb(socket, O2_RESERVED1,
152 a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); 165 a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
153 config_writeb(socket, O2_RESERVED2, 166 config_writeb(socket, O2_RESERVED2,
154 b | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); 167 b & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
155 } 168 }
156 } 169 }
157 170
diff --git a/drivers/pcmcia/omap_cf.c b/drivers/pcmcia/omap_cf.c
index 663781d20129..3ef991552398 100644
--- a/drivers/pcmcia/omap_cf.c
+++ b/drivers/pcmcia/omap_cf.c
@@ -71,8 +71,6 @@ struct omap_cf_socket {
71 71
72#define POLL_INTERVAL (2 * HZ) 72#define POLL_INTERVAL (2 * HZ)
73 73
74#define SZ_2K (2 * SZ_1K)
75
76/*--------------------------------------------------------------------------*/ 74/*--------------------------------------------------------------------------*/
77 75
78static int omap_cf_ss_init(struct pcmcia_socket *s) 76static int omap_cf_ss_init(struct pcmcia_socket *s)
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
index f73fd5beaa37..13a7132cf688 100644
--- a/drivers/pcmcia/pcmcia_ioctl.c
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -62,16 +62,15 @@ static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s,
62 unsigned int function) 62 unsigned int function)
63{ 63{
64 struct pcmcia_device *p_dev = NULL; 64 struct pcmcia_device *p_dev = NULL;
65 unsigned long flags;
66 65
67 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 66 mutex_lock(&s->ops_mutex);
68 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { 67 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
69 if (p_dev->func == function) { 68 if (p_dev->func == function) {
70 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 69 mutex_unlock(&s->ops_mutex);
71 return pcmcia_get_dev(p_dev); 70 return pcmcia_get_dev(p_dev);
72 } 71 }
73 } 72 }
74 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 73 mutex_unlock(&s->ops_mutex);
75 return NULL; 74 return NULL;
76} 75}
77 76
@@ -169,7 +168,6 @@ static int pcmcia_adjust_resource_info(adjust_t *adj)
169{ 168{
170 struct pcmcia_socket *s; 169 struct pcmcia_socket *s;
171 int ret = -ENOSYS; 170 int ret = -ENOSYS;
172 unsigned long flags;
173 171
174 down_read(&pcmcia_socket_list_rwsem); 172 down_read(&pcmcia_socket_list_rwsem);
175 list_for_each_entry(s, &pcmcia_socket_list, socket_list) { 173 list_for_each_entry(s, &pcmcia_socket_list, socket_list) {
@@ -182,14 +180,13 @@ static int pcmcia_adjust_resource_info(adjust_t *adj)
182 180
183 /* you can't use the old interface if the new 181 /* you can't use the old interface if the new
184 * one was used before */ 182 * one was used before */
185 spin_lock_irqsave(&s->lock, flags); 183 mutex_lock(&s->ops_mutex);
186 if ((s->resource_setup_new) && 184 if ((s->resource_setup_new) &&
187 !(s->resource_setup_old)) { 185 !(s->resource_setup_old)) {
188 spin_unlock_irqrestore(&s->lock, flags); 186 mutex_unlock(&s->ops_mutex);
189 continue; 187 continue;
190 } else if (!(s->resource_setup_old)) 188 } else if (!(s->resource_setup_old))
191 s->resource_setup_old = 1; 189 s->resource_setup_old = 1;
192 spin_unlock_irqrestore(&s->lock, flags);
193 190
194 switch (adj->Resource) { 191 switch (adj->Resource) {
195 case RES_MEMORY_RANGE: 192 case RES_MEMORY_RANGE:
@@ -208,10 +205,9 @@ static int pcmcia_adjust_resource_info(adjust_t *adj)
208 * last call to adjust_resource_info, we 205 * last call to adjust_resource_info, we
209 * always need to assume this is the latest 206 * always need to assume this is the latest
210 * one... */ 207 * one... */
211 spin_lock_irqsave(&s->lock, flags);
212 s->resource_setup_done = 1; 208 s->resource_setup_done = 1;
213 spin_unlock_irqrestore(&s->lock, flags);
214 } 209 }
210 mutex_unlock(&s->ops_mutex);
215 } 211 }
216 } 212 }
217 up_read(&pcmcia_socket_list_rwsem); 213 up_read(&pcmcia_socket_list_rwsem);
@@ -470,7 +466,6 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
470 struct pcmcia_driver *p_drv; 466 struct pcmcia_driver *p_drv;
471 struct pcmcia_device *p_dev; 467 struct pcmcia_device *p_dev;
472 int ret = 0; 468 int ret = 0;
473 unsigned long flags;
474 469
475 s = pcmcia_get_socket(s); 470 s = pcmcia_get_socket(s);
476 if (!s) 471 if (!s)
@@ -490,7 +485,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
490 goto err_put_driver; 485 goto err_put_driver;
491 } 486 }
492 487
493 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 488 mutex_lock(&s->ops_mutex);
494 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { 489 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
495 if (p_dev->func == bind_info->function) { 490 if (p_dev->func == bind_info->function) {
496 if ((p_dev->dev.driver == &p_drv->drv)) { 491 if ((p_dev->dev.driver == &p_drv->drv)) {
@@ -499,7 +494,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
499 * registered, and it was registered 494 * registered, and it was registered
500 * by userspace before, we need to 495 * by userspace before, we need to
501 * return the "instance". */ 496 * return the "instance". */
502 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 497 mutex_unlock(&s->ops_mutex);
503 bind_info->instance = p_dev; 498 bind_info->instance = p_dev;
504 ret = -EBUSY; 499 ret = -EBUSY;
505 goto err_put_module; 500 goto err_put_module;
@@ -507,7 +502,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
507 /* the correct driver managed to bind 502 /* the correct driver managed to bind
508 * itself magically to the correct 503 * itself magically to the correct
509 * device. */ 504 * device. */
510 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 505 mutex_unlock(&s->ops_mutex);
511 p_dev->cardmgr = p_drv; 506 p_dev->cardmgr = p_drv;
512 ret = 0; 507 ret = 0;
513 goto err_put_module; 508 goto err_put_module;
@@ -516,12 +511,12 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
516 /* there's already a device available where 511 /* there's already a device available where
517 * no device has been bound to yet. So we don't 512 * no device has been bound to yet. So we don't
518 * need to register a device! */ 513 * need to register a device! */
519 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 514 mutex_unlock(&s->ops_mutex);
520 goto rescan; 515 goto rescan;
521 } 516 }
522 } 517 }
523 } 518 }
524 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 519 mutex_unlock(&s->ops_mutex);
525 520
526 p_dev = pcmcia_device_add(s, bind_info->function); 521 p_dev = pcmcia_device_add(s, bind_info->function);
527 if (!p_dev) { 522 if (!p_dev) {
@@ -578,7 +573,6 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int
578 dev_node_t *node; 573 dev_node_t *node;
579 struct pcmcia_device *p_dev; 574 struct pcmcia_device *p_dev;
580 struct pcmcia_driver *p_drv; 575 struct pcmcia_driver *p_drv;
581 unsigned long flags;
582 int ret = 0; 576 int ret = 0;
583 577
584#ifdef CONFIG_CARDBUS 578#ifdef CONFIG_CARDBUS
@@ -617,7 +611,7 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int
617 } 611 }
618#endif 612#endif
619 613
620 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 614 mutex_lock(&s->ops_mutex);
621 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) { 615 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
622 if (p_dev->func == bind_info->function) { 616 if (p_dev->func == bind_info->function) {
623 p_dev = pcmcia_get_dev(p_dev); 617 p_dev = pcmcia_get_dev(p_dev);
@@ -626,11 +620,11 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int
626 goto found; 620 goto found;
627 } 621 }
628 } 622 }
629 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 623 mutex_unlock(&s->ops_mutex);
630 return -ENODEV; 624 return -ENODEV;
631 625
632 found: 626 found:
633 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 627 mutex_unlock(&s->ops_mutex);
634 628
635 p_drv = to_pcmcia_drv(p_dev->dev.driver); 629 p_drv = to_pcmcia_drv(p_dev->dev.driver);
636 if (p_drv && !p_dev->_locked) { 630 if (p_drv && !p_dev->_locked) {
@@ -931,16 +925,16 @@ static int ds_ioctl(struct inode *inode, struct file *file,
931 ret = pccard_validate_cis(s, &buf->cisinfo.Chains); 925 ret = pccard_validate_cis(s, &buf->cisinfo.Chains);
932 break; 926 break;
933 case DS_SUSPEND_CARD: 927 case DS_SUSPEND_CARD:
934 ret = pcmcia_suspend_card(s); 928 pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND);
935 break; 929 break;
936 case DS_RESUME_CARD: 930 case DS_RESUME_CARD:
937 ret = pcmcia_resume_card(s); 931 pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME);
938 break; 932 break;
939 case DS_EJECT_CARD: 933 case DS_EJECT_CARD:
940 err = pcmcia_eject_card(s); 934 pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT);
941 break; 935 break;
942 case DS_INSERT_CARD: 936 case DS_INSERT_CARD:
943 err = pcmcia_insert_card(s); 937 pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT);
944 break; 938 break;
945 case DS_ACCESS_CONFIGURATION_REGISTER: 939 case DS_ACCESS_CONFIGURATION_REGISTER:
946 if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) { 940 if ((buf->conf_reg.Action == CS_WRITE) && !capable(CAP_SYS_ADMIN)) {
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index d5db95644b64..b2df04199a21 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -43,6 +43,39 @@ module_param(io_speed, int, 0444);
43static u8 pcmcia_used_irq[NR_IRQS]; 43static u8 pcmcia_used_irq[NR_IRQS];
44#endif 44#endif
45 45
46static int pcmcia_adjust_io_region(struct resource *res, unsigned long start,
47 unsigned long end, struct pcmcia_socket *s)
48{
49 if (s->resource_ops->adjust_io_region)
50 return s->resource_ops->adjust_io_region(res, start, end, s);
51 return -ENOMEM;
52}
53
54static struct resource *pcmcia_find_io_region(unsigned long base, int num,
55 unsigned long align,
56 struct pcmcia_socket *s)
57{
58 if (s->resource_ops->find_io)
59 return s->resource_ops->find_io(base, num, align, s);
60 return NULL;
61}
62
63int pcmcia_validate_mem(struct pcmcia_socket *s)
64{
65 if (s->resource_ops->validate_mem)
66 return s->resource_ops->validate_mem(s);
67 /* if there is no callback, we can assume that everything is OK */
68 return 0;
69}
70
71struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
72 int low, struct pcmcia_socket *s)
73{
74 if (s->resource_ops->find_mem)
75 return s->resource_ops->find_mem(base, num, align, low, s);
76 return NULL;
77}
78
46 79
47/** alloc_io_space 80/** alloc_io_space
48 * 81 *
@@ -158,14 +191,18 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
158 return -EINVAL; 191 return -EINVAL;
159 192
160 s = p_dev->socket; 193 s = p_dev->socket;
194
195 mutex_lock(&s->ops_mutex);
161 c = p_dev->function_config; 196 c = p_dev->function_config;
162 197
163 if (!(c->state & CONFIG_LOCKED)) { 198 if (!(c->state & CONFIG_LOCKED)) {
164 dev_dbg(&s->dev, "Configuration isnt't locked\n"); 199 dev_dbg(&s->dev, "Configuration isnt't locked\n");
200 mutex_unlock(&s->ops_mutex);
165 return -EACCES; 201 return -EACCES;
166 } 202 }
167 203
168 addr = (c->ConfigBase + reg->Offset) >> 1; 204 addr = (c->ConfigBase + reg->Offset) >> 1;
205 mutex_unlock(&s->ops_mutex);
169 206
170 switch (reg->Action) { 207 switch (reg->Action) {
171 case CS_READ: 208 case CS_READ:
@@ -190,6 +227,7 @@ int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh,
190 memreq_t *req) 227 memreq_t *req)
191{ 228{
192 struct pcmcia_socket *s = p_dev->socket; 229 struct pcmcia_socket *s = p_dev->socket;
230 int ret;
193 231
194 wh--; 232 wh--;
195 if (wh >= MAX_WIN) 233 if (wh >= MAX_WIN)
@@ -198,12 +236,13 @@ int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh,
198 dev_dbg(&s->dev, "failure: requested page is zero\n"); 236 dev_dbg(&s->dev, "failure: requested page is zero\n");
199 return -EINVAL; 237 return -EINVAL;
200 } 238 }
239 mutex_lock(&s->ops_mutex);
201 s->win[wh].card_start = req->CardOffset; 240 s->win[wh].card_start = req->CardOffset;
202 if (s->ops->set_mem_map(s, &s->win[wh]) != 0) { 241 ret = s->ops->set_mem_map(s, &s->win[wh]);
203 dev_dbg(&s->dev, "failed to set_mem_map\n"); 242 if (ret)
204 return -EIO; 243 dev_warn(&s->dev, "failed to set_mem_map\n");
205 } 244 mutex_unlock(&s->ops_mutex);
206 return 0; 245 return ret;
207} /* pcmcia_map_mem_page */ 246} /* pcmcia_map_mem_page */
208EXPORT_SYMBOL(pcmcia_map_mem_page); 247EXPORT_SYMBOL(pcmcia_map_mem_page);
209 248
@@ -219,14 +258,18 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
219 config_t *c; 258 config_t *c;
220 259
221 s = p_dev->socket; 260 s = p_dev->socket;
261
262 mutex_lock(&s->ops_mutex);
222 c = p_dev->function_config; 263 c = p_dev->function_config;
223 264
224 if (!(s->state & SOCKET_PRESENT)) { 265 if (!(s->state & SOCKET_PRESENT)) {
225 dev_dbg(&s->dev, "No card present\n"); 266 dev_dbg(&s->dev, "No card present\n");
267 mutex_unlock(&s->ops_mutex);
226 return -ENODEV; 268 return -ENODEV;
227 } 269 }
228 if (!(c->state & CONFIG_LOCKED)) { 270 if (!(c->state & CONFIG_LOCKED)) {
229 dev_dbg(&s->dev, "Configuration isnt't locked\n"); 271 dev_dbg(&s->dev, "Configuration isnt't locked\n");
272 mutex_unlock(&s->ops_mutex);
230 return -EACCES; 273 return -EACCES;
231 } 274 }
232 275
@@ -251,10 +294,12 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
251 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { 294 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
252 if (mod->Vpp1 != mod->Vpp2) { 295 if (mod->Vpp1 != mod->Vpp2) {
253 dev_dbg(&s->dev, "Vpp1 and Vpp2 must be the same\n"); 296 dev_dbg(&s->dev, "Vpp1 and Vpp2 must be the same\n");
297 mutex_unlock(&s->ops_mutex);
254 return -EINVAL; 298 return -EINVAL;
255 } 299 }
256 s->socket.Vpp = mod->Vpp1; 300 s->socket.Vpp = mod->Vpp1;
257 if (s->ops->set_socket(s, &s->socket)) { 301 if (s->ops->set_socket(s, &s->socket)) {
302 mutex_unlock(&s->ops_mutex);
258 dev_printk(KERN_WARNING, &s->dev, 303 dev_printk(KERN_WARNING, &s->dev,
259 "Unable to set VPP\n"); 304 "Unable to set VPP\n");
260 return -EIO; 305 return -EIO;
@@ -262,6 +307,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
262 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || 307 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
263 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { 308 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
264 dev_dbg(&s->dev, "changing Vcc is not allowed at this time\n"); 309 dev_dbg(&s->dev, "changing Vcc is not allowed at this time\n");
310 mutex_unlock(&s->ops_mutex);
265 return -EINVAL; 311 return -EINVAL;
266 } 312 }
267 313
@@ -286,6 +332,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
286 s->ops->set_io_map(s, &io_on); 332 s->ops->set_io_map(s, &io_on);
287 } 333 }
288 } 334 }
335 mutex_unlock(&s->ops_mutex);
289 336
290 return 0; 337 return 0;
291} /* modify_configuration */ 338} /* modify_configuration */
@@ -296,9 +343,11 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
296{ 343{
297 pccard_io_map io = { 0, 0, 0, 0, 1 }; 344 pccard_io_map io = { 0, 0, 0, 0, 1 };
298 struct pcmcia_socket *s = p_dev->socket; 345 struct pcmcia_socket *s = p_dev->socket;
299 config_t *c = p_dev->function_config; 346 config_t *c;
300 int i; 347 int i;
301 348
349 mutex_lock(&s->ops_mutex);
350 c = p_dev->function_config;
302 if (p_dev->_locked) { 351 if (p_dev->_locked) {
303 p_dev->_locked = 0; 352 p_dev->_locked = 0;
304 if (--(s->lock_count) == 0) { 353 if (--(s->lock_count) == 0) {
@@ -321,6 +370,7 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
321 s->ops->set_io_map(s, &io); 370 s->ops->set_io_map(s, &io);
322 } 371 }
323 } 372 }
373 mutex_unlock(&s->ops_mutex);
324 374
325 return 0; 375 return 0;
326} /* pcmcia_release_configuration */ 376} /* pcmcia_release_configuration */
@@ -337,10 +387,14 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
337static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) 387static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
338{ 388{
339 struct pcmcia_socket *s = p_dev->socket; 389 struct pcmcia_socket *s = p_dev->socket;
340 config_t *c = p_dev->function_config; 390 int ret = -EINVAL;
391 config_t *c;
392
393 mutex_lock(&s->ops_mutex);
394 c = p_dev->function_config;
341 395
342 if (!p_dev->_io) 396 if (!p_dev->_io)
343 return -EINVAL; 397 goto out;
344 398
345 p_dev->_io = 0; 399 p_dev->_io = 0;
346 400
@@ -348,7 +402,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
348 (c->io.NumPorts1 != req->NumPorts1) || 402 (c->io.NumPorts1 != req->NumPorts1) ||
349 (c->io.BasePort2 != req->BasePort2) || 403 (c->io.BasePort2 != req->BasePort2) ||
350 (c->io.NumPorts2 != req->NumPorts2)) 404 (c->io.NumPorts2 != req->NumPorts2))
351 return -EINVAL; 405 goto out;
352 406
353 c->state &= ~CONFIG_IO_REQ; 407 c->state &= ~CONFIG_IO_REQ;
354 408
@@ -356,28 +410,38 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
356 if (req->NumPorts2) 410 if (req->NumPorts2)
357 release_io_space(s, req->BasePort2, req->NumPorts2); 411 release_io_space(s, req->BasePort2, req->NumPorts2);
358 412
359 return 0; 413out:
414 mutex_unlock(&s->ops_mutex);
415
416 return ret;
360} /* pcmcia_release_io */ 417} /* pcmcia_release_io */
361 418
362 419
363static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) 420static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
364{ 421{
365 struct pcmcia_socket *s = p_dev->socket; 422 struct pcmcia_socket *s = p_dev->socket;
366 config_t *c = p_dev->function_config; 423 config_t *c;
424 int ret = -EINVAL;
425
426 mutex_lock(&s->ops_mutex);
427
428 c = p_dev->function_config;
367 429
368 if (!p_dev->_irq) 430 if (!p_dev->_irq)
369 return -EINVAL; 431 goto out;
432
370 p_dev->_irq = 0; 433 p_dev->_irq = 0;
371 434
372 if (c->state & CONFIG_LOCKED) 435 if (c->state & CONFIG_LOCKED)
373 return -EACCES; 436 goto out;
437
374 if (c->irq.Attributes != req->Attributes) { 438 if (c->irq.Attributes != req->Attributes) {
375 dev_dbg(&s->dev, "IRQ attributes must match assigned ones\n"); 439 dev_dbg(&s->dev, "IRQ attributes must match assigned ones\n");
376 return -EINVAL; 440 goto out;
377 } 441 }
378 if (s->irq.AssignedIRQ != req->AssignedIRQ) { 442 if (s->irq.AssignedIRQ != req->AssignedIRQ) {
379 dev_dbg(&s->dev, "IRQ must match assigned one\n"); 443 dev_dbg(&s->dev, "IRQ must match assigned one\n");
380 return -EINVAL; 444 goto out;
381 } 445 }
382 if (--s->irq.Config == 0) { 446 if (--s->irq.Config == 0) {
383 c->state &= ~CONFIG_IRQ_REQ; 447 c->state &= ~CONFIG_IRQ_REQ;
@@ -390,8 +454,12 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
390#ifdef CONFIG_PCMCIA_PROBE 454#ifdef CONFIG_PCMCIA_PROBE
391 pcmcia_used_irq[req->AssignedIRQ]--; 455 pcmcia_used_irq[req->AssignedIRQ]--;
392#endif 456#endif
457 ret = 0;
393 458
394 return 0; 459out:
460 mutex_unlock(&s->ops_mutex);
461
462 return ret;
395} /* pcmcia_release_irq */ 463} /* pcmcia_release_irq */
396 464
397 465
@@ -404,10 +472,12 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh)
404 if (wh >= MAX_WIN) 472 if (wh >= MAX_WIN)
405 return -EINVAL; 473 return -EINVAL;
406 474
475 mutex_lock(&s->ops_mutex);
407 win = &s->win[wh]; 476 win = &s->win[wh];
408 477
409 if (!(p_dev->_win & CLIENT_WIN_REQ(wh))) { 478 if (!(p_dev->_win & CLIENT_WIN_REQ(wh))) {
410 dev_dbg(&s->dev, "not releasing unknown window\n"); 479 dev_dbg(&s->dev, "not releasing unknown window\n");
480 mutex_unlock(&s->ops_mutex);
411 return -EINVAL; 481 return -EINVAL;
412 } 482 }
413 483
@@ -423,6 +493,7 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh)
423 win->res = NULL; 493 win->res = NULL;
424 } 494 }
425 p_dev->_win &= ~CLIENT_WIN_REQ(wh); 495 p_dev->_win &= ~CLIENT_WIN_REQ(wh);
496 mutex_unlock(&s->ops_mutex);
426 497
427 return 0; 498 return 0;
428} /* pcmcia_release_window */ 499} /* pcmcia_release_window */
@@ -445,8 +516,11 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
445 dev_dbg(&s->dev, "IntType may not be INT_CARDBUS\n"); 516 dev_dbg(&s->dev, "IntType may not be INT_CARDBUS\n");
446 return -EINVAL; 517 return -EINVAL;
447 } 518 }
519
520 mutex_lock(&s->ops_mutex);
448 c = p_dev->function_config; 521 c = p_dev->function_config;
449 if (c->state & CONFIG_LOCKED) { 522 if (c->state & CONFIG_LOCKED) {
523 mutex_unlock(&s->ops_mutex);
450 dev_dbg(&s->dev, "Configuration is locked\n"); 524 dev_dbg(&s->dev, "Configuration is locked\n");
451 return -EACCES; 525 return -EACCES;
452 } 526 }
@@ -454,6 +528,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
454 /* Do power control. We don't allow changes in Vcc. */ 528 /* Do power control. We don't allow changes in Vcc. */
455 s->socket.Vpp = req->Vpp; 529 s->socket.Vpp = req->Vpp;
456 if (s->ops->set_socket(s, &s->socket)) { 530 if (s->ops->set_socket(s, &s->socket)) {
531 mutex_unlock(&s->ops_mutex);
457 dev_printk(KERN_WARNING, &s->dev, 532 dev_printk(KERN_WARNING, &s->dev,
458 "Unable to set socket state\n"); 533 "Unable to set socket state\n");
459 return -EINVAL; 534 return -EINVAL;
@@ -476,6 +551,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
476 s->socket.io_irq = 0; 551 s->socket.io_irq = 0;
477 s->ops->set_socket(s, &s->socket); 552 s->ops->set_socket(s, &s->socket);
478 s->lock_count++; 553 s->lock_count++;
554 mutex_unlock(&s->ops_mutex);
479 555
480 /* Set up CIS configuration registers */ 556 /* Set up CIS configuration registers */
481 base = c->ConfigBase = req->ConfigBase; 557 base = c->ConfigBase = req->ConfigBase;
@@ -524,6 +600,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
524 600
525 /* Configure I/O windows */ 601 /* Configure I/O windows */
526 if (c->state & CONFIG_IO_REQ) { 602 if (c->state & CONFIG_IO_REQ) {
603 mutex_lock(&s->ops_mutex);
527 iomap.speed = io_speed; 604 iomap.speed = io_speed;
528 for (i = 0; i < MAX_IO_WIN; i++) 605 for (i = 0; i < MAX_IO_WIN; i++)
529 if (s->io[i].res) { 606 if (s->io[i].res) {
@@ -542,6 +619,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
542 s->ops->set_io_map(s, &iomap); 619 s->ops->set_io_map(s, &iomap);
543 s->io[i].Config++; 620 s->io[i].Config++;
544 } 621 }
622 mutex_unlock(&s->ops_mutex);
545 } 623 }
546 624
547 c->state |= CONFIG_LOCKED; 625 c->state |= CONFIG_LOCKED;
@@ -560,54 +638,65 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
560{ 638{
561 struct pcmcia_socket *s = p_dev->socket; 639 struct pcmcia_socket *s = p_dev->socket;
562 config_t *c; 640 config_t *c;
641 int ret = -EINVAL;
642
643 mutex_lock(&s->ops_mutex);
563 644
564 if (!(s->state & SOCKET_PRESENT)) { 645 if (!(s->state & SOCKET_PRESENT)) {
565 dev_dbg(&s->dev, "No card present\n"); 646 dev_dbg(&s->dev, "No card present\n");
566 return -ENODEV; 647 goto out;
567 } 648 }
568 649
569 if (!req) 650 if (!req)
570 return -EINVAL; 651 goto out;
652
571 c = p_dev->function_config; 653 c = p_dev->function_config;
572 if (c->state & CONFIG_LOCKED) { 654 if (c->state & CONFIG_LOCKED) {
573 dev_dbg(&s->dev, "Configuration is locked\n"); 655 dev_dbg(&s->dev, "Configuration is locked\n");
574 return -EACCES; 656 goto out;
575 } 657 }
576 if (c->state & CONFIG_IO_REQ) { 658 if (c->state & CONFIG_IO_REQ) {
577 dev_dbg(&s->dev, "IO already configured\n"); 659 dev_dbg(&s->dev, "IO already configured\n");
578 return -EBUSY; 660 goto out;
579 } 661 }
580 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) { 662 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) {
581 dev_dbg(&s->dev, "bad attribute setting for IO region 1\n"); 663 dev_dbg(&s->dev, "bad attribute setting for IO region 1\n");
582 return -EINVAL; 664 goto out;
583 } 665 }
584 if ((req->NumPorts2 > 0) && 666 if ((req->NumPorts2 > 0) &&
585 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) { 667 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) {
586 dev_dbg(&s->dev, "bad attribute setting for IO region 2\n"); 668 dev_dbg(&s->dev, "bad attribute setting for IO region 2\n");
587 return -EINVAL; 669 goto out;
588 } 670 }
589 671
590 dev_dbg(&s->dev, "trying to allocate resource 1\n"); 672 dev_dbg(&s->dev, "trying to allocate resource 1\n");
591 if (alloc_io_space(s, req->Attributes1, &req->BasePort1, 673 ret = alloc_io_space(s, req->Attributes1, &req->BasePort1,
592 req->NumPorts1, req->IOAddrLines)) { 674 req->NumPorts1, req->IOAddrLines);
675 if (ret) {
593 dev_dbg(&s->dev, "allocation of resource 1 failed\n"); 676 dev_dbg(&s->dev, "allocation of resource 1 failed\n");
594 return -EBUSY; 677 goto out;
595 } 678 }
596 679
597 if (req->NumPorts2) { 680 if (req->NumPorts2) {
598 dev_dbg(&s->dev, "trying to allocate resource 2\n"); 681 dev_dbg(&s->dev, "trying to allocate resource 2\n");
599 if (alloc_io_space(s, req->Attributes2, &req->BasePort2, 682 ret = alloc_io_space(s, req->Attributes2, &req->BasePort2,
600 req->NumPorts2, req->IOAddrLines)) { 683 req->NumPorts2, req->IOAddrLines);
684 if (ret) {
601 dev_dbg(&s->dev, "allocation of resource 2 failed\n"); 685 dev_dbg(&s->dev, "allocation of resource 2 failed\n");
602 release_io_space(s, req->BasePort1, req->NumPorts1); 686 release_io_space(s, req->BasePort1, req->NumPorts1);
603 return -EBUSY; 687 goto out;
604 } 688 }
605 } 689 }
606 690
607 c->io = *req; 691 c->io = *req;
608 c->state |= CONFIG_IO_REQ; 692 c->state |= CONFIG_IO_REQ;
609 p_dev->_io = 1; 693 p_dev->_io = 1;
610 return 0; 694 dev_dbg(&s->dev, "allocating resources succeeded: %d\n", ret);
695
696out:
697 mutex_unlock(&s->ops_mutex);
698
699 return ret;
611} /* pcmcia_request_io */ 700} /* pcmcia_request_io */
612EXPORT_SYMBOL(pcmcia_request_io); 701EXPORT_SYMBOL(pcmcia_request_io);
613 702
@@ -636,18 +725,20 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
636 int ret = -EINVAL, irq = 0; 725 int ret = -EINVAL, irq = 0;
637 int type; 726 int type;
638 727
728 mutex_lock(&s->ops_mutex);
729
639 if (!(s->state & SOCKET_PRESENT)) { 730 if (!(s->state & SOCKET_PRESENT)) {
640 dev_dbg(&s->dev, "No card present\n"); 731 dev_dbg(&s->dev, "No card present\n");
641 return -ENODEV; 732 goto out;
642 } 733 }
643 c = p_dev->function_config; 734 c = p_dev->function_config;
644 if (c->state & CONFIG_LOCKED) { 735 if (c->state & CONFIG_LOCKED) {
645 dev_dbg(&s->dev, "Configuration is locked\n"); 736 dev_dbg(&s->dev, "Configuration is locked\n");
646 return -EACCES; 737 goto out;
647 } 738 }
648 if (c->state & CONFIG_IRQ_REQ) { 739 if (c->state & CONFIG_IRQ_REQ) {
649 dev_dbg(&s->dev, "IRQ already configured\n"); 740 dev_dbg(&s->dev, "IRQ already configured\n");
650 return -EBUSY; 741 goto out;
651 } 742 }
652 743
653 /* Decide what type of interrupt we are registering */ 744 /* Decide what type of interrupt we are registering */
@@ -708,7 +799,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
708 if (ret && !s->irq.AssignedIRQ) { 799 if (ret && !s->irq.AssignedIRQ) {
709 if (!s->pci_irq) { 800 if (!s->pci_irq) {
710 dev_printk(KERN_INFO, &s->dev, "no IRQ found\n"); 801 dev_printk(KERN_INFO, &s->dev, "no IRQ found\n");
711 return ret; 802 goto out;
712 } 803 }
713 type = IRQF_SHARED; 804 type = IRQF_SHARED;
714 irq = s->pci_irq; 805 irq = s->pci_irq;
@@ -720,7 +811,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
720 if (ret) { 811 if (ret) {
721 dev_printk(KERN_INFO, &s->dev, 812 dev_printk(KERN_INFO, &s->dev,
722 "request_irq() failed\n"); 813 "request_irq() failed\n");
723 return ret; 814 goto out;
724 } 815 }
725 } 816 }
726 817
@@ -743,7 +834,10 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
743 pcmcia_used_irq[irq]++; 834 pcmcia_used_irq[irq]++;
744#endif 835#endif
745 836
746 return 0; 837 ret = 0;
838out:
839 mutex_unlock(&s->ops_mutex);
840 return ret;
747} /* pcmcia_request_irq */ 841} /* pcmcia_request_irq */
748EXPORT_SYMBOL(pcmcia_request_irq); 842EXPORT_SYMBOL(pcmcia_request_irq);
749 843
@@ -796,6 +890,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
796 return -EINVAL; 890 return -EINVAL;
797 } 891 }
798 892
893 mutex_lock(&s->ops_mutex);
799 win = &s->win[w]; 894 win = &s->win[w];
800 895
801 if (!(s->features & SS_CAP_STATIC_MAP)) { 896 if (!(s->features & SS_CAP_STATIC_MAP)) {
@@ -803,6 +898,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
803 (req->Attributes & WIN_MAP_BELOW_1MB), s); 898 (req->Attributes & WIN_MAP_BELOW_1MB), s);
804 if (!win->res) { 899 if (!win->res) {
805 dev_dbg(&s->dev, "allocating mem region failed\n"); 900 dev_dbg(&s->dev, "allocating mem region failed\n");
901 mutex_unlock(&s->ops_mutex);
806 return -EINVAL; 902 return -EINVAL;
807 } 903 }
808 } 904 }
@@ -821,8 +917,10 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
821 if (req->Attributes & WIN_USE_WAIT) 917 if (req->Attributes & WIN_USE_WAIT)
822 win->flags |= MAP_USE_WAIT; 918 win->flags |= MAP_USE_WAIT;
823 win->card_start = 0; 919 win->card_start = 0;
920
824 if (s->ops->set_mem_map(s, win) != 0) { 921 if (s->ops->set_mem_map(s, win) != 0) {
825 dev_dbg(&s->dev, "failed to set memory mapping\n"); 922 dev_dbg(&s->dev, "failed to set memory mapping\n");
923 mutex_unlock(&s->ops_mutex);
826 return -EIO; 924 return -EIO;
827 } 925 }
828 s->state |= SOCKET_WIN_REQ(w); 926 s->state |= SOCKET_WIN_REQ(w);
@@ -833,6 +931,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
833 else 931 else
834 req->Base = win->res->start; 932 req->Base = win->res->start;
835 933
934 mutex_unlock(&s->ops_mutex);
836 *wh = w + 1; 935 *wh = w + 1;
837 936
838 return 0; 937 return 0;
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index 52db17263d8b..e6f7d410aed6 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -21,60 +21,12 @@
21#include <pcmcia/cistpl.h> 21#include <pcmcia/cistpl.h>
22#include "cs_internal.h" 22#include "cs_internal.h"
23 23
24
25int pcmcia_validate_mem(struct pcmcia_socket *s)
26{
27 if (s->resource_ops->validate_mem)
28 return s->resource_ops->validate_mem(s);
29 /* if there is no callback, we can assume that everything is OK */
30 return 0;
31}
32EXPORT_SYMBOL(pcmcia_validate_mem);
33
34int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
35 unsigned long r_end, struct pcmcia_socket *s)
36{
37 if (s->resource_ops->adjust_io_region)
38 return s->resource_ops->adjust_io_region(res, r_start, r_end, s);
39 return -ENOMEM;
40}
41EXPORT_SYMBOL(pcmcia_adjust_io_region);
42
43struct resource *pcmcia_find_io_region(unsigned long base, int num,
44 unsigned long align, struct pcmcia_socket *s)
45{
46 if (s->resource_ops->find_io)
47 return s->resource_ops->find_io(base, num, align, s);
48 return NULL;
49}
50EXPORT_SYMBOL(pcmcia_find_io_region);
51
52struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
53 int low, struct pcmcia_socket *s)
54{
55 if (s->resource_ops->find_mem)
56 return s->resource_ops->find_mem(base, num, align, low, s);
57 return NULL;
58}
59EXPORT_SYMBOL(pcmcia_find_mem_region);
60
61void release_resource_db(struct pcmcia_socket *s)
62{
63 if (s->resource_ops->exit)
64 s->resource_ops->exit(s);
65}
66
67
68static int static_init(struct pcmcia_socket *s) 24static int static_init(struct pcmcia_socket *s)
69{ 25{
70 unsigned long flags;
71
72 /* the good thing about SS_CAP_STATIC_MAP sockets is 26 /* the good thing about SS_CAP_STATIC_MAP sockets is
73 * that they don't need a resource database */ 27 * that they don't need a resource database */
74 28
75 spin_lock_irqsave(&s->lock, flags);
76 s->resource_setup_done = 1; 29 s->resource_setup_done = 1;
77 spin_unlock_irqrestore(&s->lock, flags);
78 30
79 return 0; 31 return 0;
80} 32}
@@ -114,22 +66,21 @@ struct pcmcia_align_data {
114 unsigned long offset; 66 unsigned long offset;
115}; 67};
116 68
117static void pcmcia_align(void *align_data, struct resource *res, 69static resource_size_t pcmcia_align(void *align_data,
118 unsigned long size, unsigned long align) 70 const struct resource *res,
71 resource_size_t size, resource_size_t align)
119{ 72{
120 struct pcmcia_align_data *data = align_data; 73 struct pcmcia_align_data *data = align_data;
121 unsigned long start; 74 resource_size_t start;
122 75
123 start = (res->start & ~data->mask) + data->offset; 76 start = (res->start & ~data->mask) + data->offset;
124 if (start < res->start) 77 if (start < res->start)
125 start += data->mask + 1; 78 start += data->mask + 1;
126 res->start = start;
127 79
128#ifdef CONFIG_X86 80#ifdef CONFIG_X86
129 if (res->flags & IORESOURCE_IO) { 81 if (res->flags & IORESOURCE_IO) {
130 if (start & 0x300) { 82 if (start & 0x300) {
131 start = (start + 0x3ff) & ~0x3ff; 83 start = (start + 0x3ff) & ~0x3ff;
132 res->start = start;
133 } 84 }
134 } 85 }
135#endif 86#endif
@@ -137,9 +88,11 @@ static void pcmcia_align(void *align_data, struct resource *res,
137#ifdef CONFIG_M68K 88#ifdef CONFIG_M68K
138 if (res->flags & IORESOURCE_IO) { 89 if (res->flags & IORESOURCE_IO) {
139 if ((res->start + size - 1) >= 1024) 90 if ((res->start + size - 1) >= 1024)
140 res->start = res->end; 91 start = res->end;
141 } 92 }
142#endif 93#endif
94
95 return start;
143} 96}
144 97
145 98
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 9b0dc433a8c3..4663b3fa9f96 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -55,11 +55,10 @@ struct resource_map {
55 55
56struct socket_data { 56struct socket_data {
57 struct resource_map mem_db; 57 struct resource_map mem_db;
58 struct resource_map mem_db_valid;
58 struct resource_map io_db; 59 struct resource_map io_db;
59 unsigned int rsrc_mem_probe;
60}; 60};
61 61
62static DEFINE_MUTEX(rsrc_mutex);
63#define MEM_PROBE_LOW (1 << 0) 62#define MEM_PROBE_LOW (1 << 0)
64#define MEM_PROBE_HIGH (1 << 1) 63#define MEM_PROBE_HIGH (1 << 1)
65 64
@@ -125,8 +124,10 @@ static int add_interval(struct resource_map *map, u_long base, u_long num)
125 struct resource_map *p, *q; 124 struct resource_map *p, *q;
126 125
127 for (p = map; ; p = p->next) { 126 for (p = map; ; p = p->next) {
128 if ((p != map) && (p->base+p->num-1 >= base)) 127 if ((p != map) && (p->base+p->num >= base)) {
129 return -1; 128 p->num = max(num + base - p->base, p->num);
129 return 0;
130 }
130 if ((p->next == map) || (p->next->base > base+num-1)) 131 if ((p->next == map) || (p->next->base > base+num-1))
131 break; 132 break;
132 } 133 }
@@ -264,36 +265,44 @@ static void do_io_probe(struct pcmcia_socket *s, unsigned int base,
264} 265}
265#endif 266#endif
266 267
267/*====================================================================== 268/*======================================================================*/
268
269 This is tricky... when we set up CIS memory, we try to validate
270 the memory window space allocations.
271
272======================================================================*/
273 269
274/* Validation function for cards with a valid CIS */ 270/**
271 * readable() - iomem validation function for cards with a valid CIS
272 */
275static int readable(struct pcmcia_socket *s, struct resource *res, 273static int readable(struct pcmcia_socket *s, struct resource *res,
276 unsigned int *count) 274 unsigned int *count)
277{ 275{
278 int ret = -1; 276 int ret = -EINVAL;
277
278 if (s->fake_cis) {
279 dev_dbg(&s->dev, "fake CIS is being used: can't validate mem\n");
280 return 0;
281 }
279 282
280 s->cis_mem.res = res; 283 s->cis_mem.res = res;
281 s->cis_virt = ioremap(res->start, s->map_size); 284 s->cis_virt = ioremap(res->start, s->map_size);
282 if (s->cis_virt) { 285 if (s->cis_virt) {
283 ret = pccard_validate_cis(s, count); 286 mutex_unlock(&s->ops_mutex);
284 /* invalidate mapping and CIS cache */ 287 /* as we're only called from pcmcia.c, we're safe */
288 if (s->callback->validate)
289 ret = s->callback->validate(s, count);
290 /* invalidate mapping */
291 mutex_lock(&s->ops_mutex);
285 iounmap(s->cis_virt); 292 iounmap(s->cis_virt);
286 s->cis_virt = NULL; 293 s->cis_virt = NULL;
287 destroy_cis_cache(s);
288 } 294 }
289 s->cis_mem.res = NULL; 295 s->cis_mem.res = NULL;
290 if ((ret != 0) || (*count == 0)) 296 if ((ret) || (*count == 0))
291 return 0; 297 return -EINVAL;
292 return 1; 298 return 0;
293} 299}
294 300
295/* Validation function for simple memory cards */ 301/**
296static int checksum(struct pcmcia_socket *s, struct resource *res) 302 * checksum() - iomem validation function for simple memory cards
303 */
304static int checksum(struct pcmcia_socket *s, struct resource *res,
305 unsigned int *value)
297{ 306{
298 pccard_mem_map map; 307 pccard_mem_map map;
299 int i, a = 0, b = -1, d; 308 int i, a = 0, b = -1, d;
@@ -321,61 +330,90 @@ static int checksum(struct pcmcia_socket *s, struct resource *res)
321 iounmap(virt); 330 iounmap(virt);
322 } 331 }
323 332
324 return (b == -1) ? -1 : (a>>1); 333 if (b == -1)
334 return -EINVAL;
335
336 *value = a;
337
338 return 0;
325} 339}
326 340
327static int 341/**
328cis_readable(struct pcmcia_socket *s, unsigned long base, unsigned long size) 342 * do_validate_mem() - low level validate a memory region for PCMCIA use
343 * @s: PCMCIA socket to validate
344 * @base: start address of resource to check
345 * @size: size of resource to check
346 * @validate: validation function to use
347 *
348 * do_validate_mem() splits up the memory region which is to be checked
349 * into two parts. Both are passed to the @validate() function. If
350 * @validate() returns non-zero, or the value parameter to @validate()
351 * is zero, or the value parameter is different between both calls,
352 * the check fails, and -EINVAL is returned. Else, 0 is returned.
353 */
354static int do_validate_mem(struct pcmcia_socket *s,
355 unsigned long base, unsigned long size,
356 int validate (struct pcmcia_socket *s,
357 struct resource *res,
358 unsigned int *value))
329{ 359{
360 struct socket_data *s_data = s->resource_data;
330 struct resource *res1, *res2; 361 struct resource *res1, *res2;
331 unsigned int info1, info2; 362 unsigned int info1 = 1, info2 = 1;
332 int ret = 0; 363 int ret = -EINVAL;
333 364
334 res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "PCMCIA memprobe"); 365 res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "PCMCIA memprobe");
335 res2 = claim_region(s, base + size/2, size/2, IORESOURCE_MEM, 366 res2 = claim_region(s, base + size/2, size/2, IORESOURCE_MEM,
336 "PCMCIA memprobe"); 367 "PCMCIA memprobe");
337 368
338 if (res1 && res2) { 369 if (res1 && res2) {
339 ret = readable(s, res1, &info1); 370 ret = 0;
340 ret += readable(s, res2, &info2); 371 if (validate) {
372 ret = validate(s, res1, &info1);
373 ret += validate(s, res2, &info2);
374 }
341 } 375 }
342 376
343 free_region(res2); 377 free_region(res2);
344 free_region(res1); 378 free_region(res1);
345 379
346 return (ret == 2) && (info1 == info2); 380 dev_dbg(&s->dev, "cs: memory probe 0x%06lx-0x%06lx: %p %p %u %u %u",
347} 381 base, base+size-1, res1, res2, ret, info1, info2);
348
349static int
350checksum_match(struct pcmcia_socket *s, unsigned long base, unsigned long size)
351{
352 struct resource *res1, *res2;
353 int a = -1, b = -1;
354 382
355 res1 = claim_region(s, base, size/2, IORESOURCE_MEM, "PCMCIA memprobe"); 383 if ((ret) || (info1 != info2) || (info1 == 0))
356 res2 = claim_region(s, base + size/2, size/2, IORESOURCE_MEM, 384 return -EINVAL;
357 "PCMCIA memprobe");
358 385
359 if (res1 && res2) { 386 if (validate && !s->fake_cis) {
360 a = checksum(s, res1); 387 /* move it to the validated data set */
361 b = checksum(s, res2); 388 add_interval(&s_data->mem_db_valid, base, size);
389 sub_interval(&s_data->mem_db, base, size);
362 } 390 }
363 391
364 free_region(res2); 392 return 0;
365 free_region(res1);
366
367 return (a == b) && (a >= 0);
368} 393}
369 394
370/*======================================================================
371
372 The memory probe. If the memory list includes a 64K-aligned block
373 below 1MB, we probe in 64K chunks, and as soon as we accumulate at
374 least mem_limit free space, we quit.
375 395
376======================================================================*/ 396/**
377 397 * do_mem_probe() - validate a memory region for PCMCIA use
378static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s) 398 * @s: PCMCIA socket to validate
399 * @base: start address of resource to check
400 * @num: size of resource to check
401 * @validate: validation function to use
402 * @fallback: validation function to use if validate fails
403 *
404 * do_mem_probe() checks a memory region for use by the PCMCIA subsystem.
405 * To do so, the area is split up into sensible parts, and then passed
406 * into the @validate() function. Only if @validate() and @fallback() fail,
407 * the area is marked as unavaibale for use by the PCMCIA subsystem. The
408 * function returns the size of the usable memory area.
409 */
410static int do_mem_probe(struct pcmcia_socket *s, u_long base, u_long num,
411 int validate (struct pcmcia_socket *s,
412 struct resource *res,
413 unsigned int *value),
414 int fallback (struct pcmcia_socket *s,
415 struct resource *res,
416 unsigned int *value))
379{ 417{
380 struct socket_data *s_data = s->resource_data; 418 struct socket_data *s_data = s->resource_data;
381 u_long i, j, bad, fail, step; 419 u_long i, j, bad, fail, step;
@@ -393,15 +431,14 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s)
393 for (i = j = base; i < base+num; i = j + step) { 431 for (i = j = base; i < base+num; i = j + step) {
394 if (!fail) { 432 if (!fail) {
395 for (j = i; j < base+num; j += step) { 433 for (j = i; j < base+num; j += step) {
396 if (cis_readable(s, j, step)) 434 if (!do_validate_mem(s, j, step, validate))
397 break; 435 break;
398 } 436 }
399 fail = ((i == base) && (j == base+num)); 437 fail = ((i == base) && (j == base+num));
400 } 438 }
401 if (fail) { 439 if ((fail) && (fallback)) {
402 for (j = i; j < base+num; j += 2*step) 440 for (j = i; j < base+num; j += step)
403 if (checksum_match(s, j, step) && 441 if (!do_validate_mem(s, j, step, fallback))
404 checksum_match(s, j + step, step))
405 break; 442 break;
406 } 443 }
407 if (i != j) { 444 if (i != j) {
@@ -416,8 +453,14 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s)
416 return num - bad; 453 return num - bad;
417} 454}
418 455
456
419#ifdef CONFIG_PCMCIA_PROBE 457#ifdef CONFIG_PCMCIA_PROBE
420 458
459/**
460 * inv_probe() - top-to-bottom search for one usuable high memory area
461 * @s: PCMCIA socket to validate
462 * @m: resource_map to check
463 */
421static u_long inv_probe(struct resource_map *m, struct pcmcia_socket *s) 464static u_long inv_probe(struct resource_map *m, struct pcmcia_socket *s)
422{ 465{
423 struct socket_data *s_data = s->resource_data; 466 struct socket_data *s_data = s->resource_data;
@@ -432,9 +475,18 @@ static u_long inv_probe(struct resource_map *m, struct pcmcia_socket *s)
432 } 475 }
433 if (m->base < 0x100000) 476 if (m->base < 0x100000)
434 return 0; 477 return 0;
435 return do_mem_probe(m->base, m->num, s); 478 return do_mem_probe(s, m->base, m->num, readable, checksum);
436} 479}
437 480
481/**
482 * validate_mem() - memory probe function
483 * @s: PCMCIA socket to validate
484 * @probe_mask: MEM_PROBE_LOW | MEM_PROBE_HIGH
485 *
486 * The memory probe. If the memory list includes a 64K-aligned block
487 * below 1MB, we probe in 64K chunks, and as soon as we accumulate at
488 * least mem_limit free space, we quit. Returns 0 on usuable ports.
489 */
438static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) 490static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
439{ 491{
440 struct resource_map *m, mm; 492 struct resource_map *m, mm;
@@ -446,6 +498,8 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
446 if (probe_mask & MEM_PROBE_HIGH) { 498 if (probe_mask & MEM_PROBE_HIGH) {
447 if (inv_probe(s_data->mem_db.next, s) > 0) 499 if (inv_probe(s_data->mem_db.next, s) > 0)
448 return 0; 500 return 0;
501 if (s_data->mem_db_valid.next != &s_data->mem_db_valid)
502 return 0;
449 dev_printk(KERN_NOTICE, &s->dev, 503 dev_printk(KERN_NOTICE, &s->dev,
450 "cs: warning: no high memory space available!\n"); 504 "cs: warning: no high memory space available!\n");
451 return -ENODEV; 505 return -ENODEV;
@@ -457,7 +511,8 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
457 if (mm.base >= 0x100000) 511 if (mm.base >= 0x100000)
458 continue; 512 continue;
459 if ((mm.base | mm.num) & 0xffff) { 513 if ((mm.base | mm.num) & 0xffff) {
460 ok += do_mem_probe(mm.base, mm.num, s); 514 ok += do_mem_probe(s, mm.base, mm.num, readable,
515 checksum);
461 continue; 516 continue;
462 } 517 }
463 /* Special probe for 64K-aligned block */ 518 /* Special probe for 64K-aligned block */
@@ -467,7 +522,8 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
467 if (ok >= mem_limit) 522 if (ok >= mem_limit)
468 sub_interval(&s_data->mem_db, b, 0x10000); 523 sub_interval(&s_data->mem_db, b, 0x10000);
469 else 524 else
470 ok += do_mem_probe(b, 0x10000, s); 525 ok += do_mem_probe(s, b, 0x10000,
526 readable, checksum);
471 } 527 }
472 } 528 }
473 } 529 }
@@ -480,6 +536,13 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
480 536
481#else /* CONFIG_PCMCIA_PROBE */ 537#else /* CONFIG_PCMCIA_PROBE */
482 538
539/**
540 * validate_mem() - memory probe function
541 * @s: PCMCIA socket to validate
542 * @probe_mask: ignored
543 *
544 * Returns 0 on usuable ports.
545 */
483static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask) 546static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
484{ 547{
485 struct resource_map *m, mm; 548 struct resource_map *m, mm;
@@ -488,7 +551,7 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
488 551
489 for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) { 552 for (m = s_data->mem_db.next; m != &s_data->mem_db; m = mm.next) {
490 mm = *m; 553 mm = *m;
491 ok += do_mem_probe(mm.base, mm.num, s); 554 ok += do_mem_probe(s, mm.base, mm.num, readable, checksum);
492 } 555 }
493 if (ok > 0) 556 if (ok > 0)
494 return 0; 557 return 0;
@@ -498,31 +561,31 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
498#endif /* CONFIG_PCMCIA_PROBE */ 561#endif /* CONFIG_PCMCIA_PROBE */
499 562
500 563
501/* 564/**
565 * pcmcia_nonstatic_validate_mem() - try to validate iomem for PCMCIA use
566 * @s: PCMCIA socket to validate
567 *
568 * This is tricky... when we set up CIS memory, we try to validate
569 * the memory window space allocations.
570 *
502 * Locking note: Must be called with skt_mutex held! 571 * Locking note: Must be called with skt_mutex held!
503 */ 572 */
504static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) 573static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s)
505{ 574{
506 struct socket_data *s_data = s->resource_data; 575 struct socket_data *s_data = s->resource_data;
507 unsigned int probe_mask = MEM_PROBE_LOW; 576 unsigned int probe_mask = MEM_PROBE_LOW;
508 int ret = 0; 577 int ret;
509 578
510 if (!probe_mem) 579 if (!probe_mem || !(s->state & SOCKET_PRESENT))
511 return 0; 580 return 0;
512 581
513 mutex_lock(&rsrc_mutex);
514
515 if (s->features & SS_CAP_PAGE_REGS) 582 if (s->features & SS_CAP_PAGE_REGS)
516 probe_mask = MEM_PROBE_HIGH; 583 probe_mask = MEM_PROBE_HIGH;
517 584
518 if (probe_mask & ~s_data->rsrc_mem_probe) { 585 ret = validate_mem(s, probe_mask);
519 if (s->state & SOCKET_PRESENT)
520 ret = validate_mem(s, probe_mask);
521 if (!ret)
522 s_data->rsrc_mem_probe |= probe_mask;
523 }
524 586
525 mutex_unlock(&rsrc_mutex); 587 if (s_data->mem_db_valid.next != &s_data->mem_db_valid)
588 return 0;
526 589
527 return ret; 590 return ret;
528} 591}
@@ -533,8 +596,8 @@ struct pcmcia_align_data {
533 struct resource_map *map; 596 struct resource_map *map;
534}; 597};
535 598
536static void 599static resource_size_t
537pcmcia_common_align(void *align_data, struct resource *res, 600pcmcia_common_align(void *align_data, const struct resource *res,
538 resource_size_t size, resource_size_t align) 601 resource_size_t size, resource_size_t align)
539{ 602{
540 struct pcmcia_align_data *data = align_data; 603 struct pcmcia_align_data *data = align_data;
@@ -545,17 +608,18 @@ pcmcia_common_align(void *align_data, struct resource *res,
545 start = (res->start & ~data->mask) + data->offset; 608 start = (res->start & ~data->mask) + data->offset;
546 if (start < res->start) 609 if (start < res->start)
547 start += data->mask + 1; 610 start += data->mask + 1;
548 res->start = start; 611 return start;
549} 612}
550 613
551static void 614static resource_size_t
552pcmcia_align(void *align_data, struct resource *res, resource_size_t size, 615pcmcia_align(void *align_data, const struct resource *res,
553 resource_size_t align) 616 resource_size_t size, resource_size_t align)
554{ 617{
555 struct pcmcia_align_data *data = align_data; 618 struct pcmcia_align_data *data = align_data;
556 struct resource_map *m; 619 struct resource_map *m;
620 resource_size_t start;
557 621
558 pcmcia_common_align(data, res, size, align); 622 start = pcmcia_common_align(data, res, size, align);
559 623
560 for (m = data->map->next; m != data->map; m = m->next) { 624 for (m = data->map->next; m != data->map; m = m->next) {
561 unsigned long start = m->base; 625 unsigned long start = m->base;
@@ -567,8 +631,7 @@ pcmcia_align(void *align_data, struct resource *res, resource_size_t size,
567 * fit here. 631 * fit here.
568 */ 632 */
569 if (res->start < start) { 633 if (res->start < start) {
570 res->start = start; 634 start = pcmcia_common_align(data, res, size, align);
571 pcmcia_common_align(data, res, size, align);
572 } 635 }
573 636
574 /* 637 /*
@@ -586,7 +649,9 @@ pcmcia_align(void *align_data, struct resource *res, resource_size_t size,
586 * If we failed to find something suitable, ensure we fail. 649 * If we failed to find something suitable, ensure we fail.
587 */ 650 */
588 if (m == data->map) 651 if (m == data->map)
589 res->start = res->end; 652 start = res->end;
653
654 return start;
590} 655}
591 656
592/* 657/*
@@ -600,7 +665,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
600 struct socket_data *s_data = s->resource_data; 665 struct socket_data *s_data = s->resource_data;
601 int ret = -ENOMEM; 666 int ret = -ENOMEM;
602 667
603 mutex_lock(&rsrc_mutex);
604 for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) { 668 for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) {
605 unsigned long start = m->base; 669 unsigned long start = m->base;
606 unsigned long end = m->base + m->num - 1; 670 unsigned long end = m->base + m->num - 1;
@@ -611,7 +675,6 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
611 ret = adjust_resource(res, r_start, r_end - r_start + 1); 675 ret = adjust_resource(res, r_start, r_end - r_start + 1);
612 break; 676 break;
613 } 677 }
614 mutex_unlock(&rsrc_mutex);
615 678
616 return ret; 679 return ret;
617} 680}
@@ -645,7 +708,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
645 data.offset = base & data.mask; 708 data.offset = base & data.mask;
646 data.map = &s_data->io_db; 709 data.map = &s_data->io_db;
647 710
648 mutex_lock(&rsrc_mutex);
649#ifdef CONFIG_PCI 711#ifdef CONFIG_PCI
650 if (s->cb_dev) { 712 if (s->cb_dev) {
651 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, 713 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
@@ -654,7 +716,6 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
654#endif 716#endif
655 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, 717 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
656 1, pcmcia_align, &data); 718 1, pcmcia_align, &data);
657 mutex_unlock(&rsrc_mutex);
658 719
659 if (ret != 0) { 720 if (ret != 0) {
660 kfree(res); 721 kfree(res);
@@ -670,15 +731,15 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num,
670 struct socket_data *s_data = s->resource_data; 731 struct socket_data *s_data = s->resource_data;
671 struct pcmcia_align_data data; 732 struct pcmcia_align_data data;
672 unsigned long min, max; 733 unsigned long min, max;
673 int ret, i; 734 int ret, i, j;
674 735
675 low = low || !(s->features & SS_CAP_PAGE_REGS); 736 low = low || !(s->features & SS_CAP_PAGE_REGS);
676 737
677 data.mask = align - 1; 738 data.mask = align - 1;
678 data.offset = base & data.mask; 739 data.offset = base & data.mask;
679 data.map = &s_data->mem_db;
680 740
681 for (i = 0; i < 2; i++) { 741 for (i = 0; i < 2; i++) {
742 data.map = &s_data->mem_db_valid;
682 if (low) { 743 if (low) {
683 max = 0x100000UL; 744 max = 0x100000UL;
684 min = base < max ? base : 0; 745 min = base < max ? base : 0;
@@ -687,17 +748,23 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num,
687 min = 0x100000UL + base; 748 min = 0x100000UL + base;
688 } 749 }
689 750
690 mutex_lock(&rsrc_mutex); 751 for (j = 0; j < 2; j++) {
691#ifdef CONFIG_PCI 752#ifdef CONFIG_PCI
692 if (s->cb_dev) { 753 if (s->cb_dev) {
693 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 754 ret = pci_bus_alloc_resource(s->cb_dev->bus,
694 1, min, 0, 755 res, num, 1, min, 0,
695 pcmcia_align, &data); 756 pcmcia_align, &data);
696 } else 757 } else
697#endif 758#endif
698 ret = allocate_resource(&iomem_resource, res, num, min, 759 {
699 max, 1, pcmcia_align, &data); 760 ret = allocate_resource(&iomem_resource,
700 mutex_unlock(&rsrc_mutex); 761 res, num, min, max, 1,
762 pcmcia_align, &data);
763 }
764 if (ret == 0)
765 break;
766 data.map = &s_data->mem_db;
767 }
701 if (ret == 0 || low) 768 if (ret == 0 || low)
702 break; 769 break;
703 low = 1; 770 low = 1;
@@ -720,25 +787,18 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned
720 if (end < start) 787 if (end < start)
721 return -EINVAL; 788 return -EINVAL;
722 789
723 mutex_lock(&rsrc_mutex);
724 switch (action) { 790 switch (action) {
725 case ADD_MANAGED_RESOURCE: 791 case ADD_MANAGED_RESOURCE:
726 ret = add_interval(&data->mem_db, start, size); 792 ret = add_interval(&data->mem_db, start, size);
793 if (!ret)
794 do_mem_probe(s, start, size, NULL, NULL);
727 break; 795 break;
728 case REMOVE_MANAGED_RESOURCE: 796 case REMOVE_MANAGED_RESOURCE:
729 ret = sub_interval(&data->mem_db, start, size); 797 ret = sub_interval(&data->mem_db, start, size);
730 if (!ret) {
731 struct pcmcia_socket *socket;
732 down_read(&pcmcia_socket_list_rwsem);
733 list_for_each_entry(socket, &pcmcia_socket_list, socket_list)
734 release_cis_mem(socket);
735 up_read(&pcmcia_socket_list_rwsem);
736 }
737 break; 798 break;
738 default: 799 default:
739 ret = -EINVAL; 800 ret = -EINVAL;
740 } 801 }
741 mutex_unlock(&rsrc_mutex);
742 802
743 return ret; 803 return ret;
744} 804}
@@ -756,7 +816,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
756 if (end > IO_SPACE_LIMIT) 816 if (end > IO_SPACE_LIMIT)
757 return -EINVAL; 817 return -EINVAL;
758 818
759 mutex_lock(&rsrc_mutex);
760 switch (action) { 819 switch (action) {
761 case ADD_MANAGED_RESOURCE: 820 case ADD_MANAGED_RESOURCE:
762 if (add_interval(&data->io_db, start, size) != 0) { 821 if (add_interval(&data->io_db, start, size) != 0) {
@@ -775,7 +834,6 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
775 ret = -EINVAL; 834 ret = -EINVAL;
776 break; 835 break;
777 } 836 }
778 mutex_unlock(&rsrc_mutex);
779 837
780 return ret; 838 return ret;
781} 839}
@@ -801,8 +859,7 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
801 return -EINVAL; 859 return -EINVAL;
802#endif 860#endif
803 861
804 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { 862 pci_bus_for_each_resource(s->cb_dev->bus, res, i) {
805 res = s->cb_dev->bus->resource[i];
806 if (!res) 863 if (!res)
807 continue; 864 continue;
808 865
@@ -859,6 +916,7 @@ static int nonstatic_init(struct pcmcia_socket *s)
859 return -ENOMEM; 916 return -ENOMEM;
860 917
861 data->mem_db.next = &data->mem_db; 918 data->mem_db.next = &data->mem_db;
919 data->mem_db_valid.next = &data->mem_db_valid;
862 data->io_db.next = &data->io_db; 920 data->io_db.next = &data->io_db;
863 921
864 s->resource_data = (void *) data; 922 s->resource_data = (void *) data;
@@ -873,7 +931,10 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
873 struct socket_data *data = s->resource_data; 931 struct socket_data *data = s->resource_data;
874 struct resource_map *p, *q; 932 struct resource_map *p, *q;
875 933
876 mutex_lock(&rsrc_mutex); 934 for (p = data->mem_db_valid.next; p != &data->mem_db_valid; p = q) {
935 q = p->next;
936 kfree(p);
937 }
877 for (p = data->mem_db.next; p != &data->mem_db; p = q) { 938 for (p = data->mem_db.next; p != &data->mem_db; p = q) {
878 q = p->next; 939 q = p->next;
879 kfree(p); 940 kfree(p);
@@ -882,7 +943,6 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
882 q = p->next; 943 q = p->next;
883 kfree(p); 944 kfree(p);
884 } 945 }
885 mutex_unlock(&rsrc_mutex);
886} 946}
887 947
888 948
@@ -909,7 +969,7 @@ static ssize_t show_io_db(struct device *dev,
909 struct resource_map *p; 969 struct resource_map *p;
910 ssize_t ret = 0; 970 ssize_t ret = 0;
911 971
912 mutex_lock(&rsrc_mutex); 972 mutex_lock(&s->ops_mutex);
913 data = s->resource_data; 973 data = s->resource_data;
914 974
915 for (p = data->io_db.next; p != &data->io_db; p = p->next) { 975 for (p = data->io_db.next; p != &data->io_db; p = p->next) {
@@ -921,7 +981,7 @@ static ssize_t show_io_db(struct device *dev,
921 ((unsigned long) p->base + p->num - 1)); 981 ((unsigned long) p->base + p->num - 1));
922 } 982 }
923 983
924 mutex_unlock(&rsrc_mutex); 984 mutex_unlock(&s->ops_mutex);
925 return ret; 985 return ret;
926} 986}
927 987
@@ -949,9 +1009,11 @@ static ssize_t store_io_db(struct device *dev,
949 if (end_addr < start_addr) 1009 if (end_addr < start_addr)
950 return -EINVAL; 1010 return -EINVAL;
951 1011
1012 mutex_lock(&s->ops_mutex);
952 ret = adjust_io(s, add, start_addr, end_addr); 1013 ret = adjust_io(s, add, start_addr, end_addr);
953 if (!ret) 1014 if (!ret)
954 s->resource_setup_new = 1; 1015 s->resource_setup_new = 1;
1016 mutex_unlock(&s->ops_mutex);
955 1017
956 return ret ? ret : count; 1018 return ret ? ret : count;
957} 1019}
@@ -965,9 +1027,19 @@ static ssize_t show_mem_db(struct device *dev,
965 struct resource_map *p; 1027 struct resource_map *p;
966 ssize_t ret = 0; 1028 ssize_t ret = 0;
967 1029
968 mutex_lock(&rsrc_mutex); 1030 mutex_lock(&s->ops_mutex);
969 data = s->resource_data; 1031 data = s->resource_data;
970 1032
1033 for (p = data->mem_db_valid.next; p != &data->mem_db_valid;
1034 p = p->next) {
1035 if (ret > (PAGE_SIZE - 10))
1036 continue;
1037 ret += snprintf(&buf[ret], (PAGE_SIZE - ret - 1),
1038 "0x%08lx - 0x%08lx\n",
1039 ((unsigned long) p->base),
1040 ((unsigned long) p->base + p->num - 1));
1041 }
1042
971 for (p = data->mem_db.next; p != &data->mem_db; p = p->next) { 1043 for (p = data->mem_db.next; p != &data->mem_db; p = p->next) {
972 if (ret > (PAGE_SIZE - 10)) 1044 if (ret > (PAGE_SIZE - 10))
973 continue; 1045 continue;
@@ -977,7 +1049,7 @@ static ssize_t show_mem_db(struct device *dev,
977 ((unsigned long) p->base + p->num - 1)); 1049 ((unsigned long) p->base + p->num - 1));
978 } 1050 }
979 1051
980 mutex_unlock(&rsrc_mutex); 1052 mutex_unlock(&s->ops_mutex);
981 return ret; 1053 return ret;
982} 1054}
983 1055
@@ -1005,9 +1077,11 @@ static ssize_t store_mem_db(struct device *dev,
1005 if (end_addr < start_addr) 1077 if (end_addr < start_addr)
1006 return -EINVAL; 1078 return -EINVAL;
1007 1079
1080 mutex_lock(&s->ops_mutex);
1008 ret = adjust_memory(s, add, start_addr, end_addr); 1081 ret = adjust_memory(s, add, start_addr, end_addr);
1009 if (!ret) 1082 if (!ret)
1010 s->resource_setup_new = 1; 1083 s->resource_setup_new = 1;
1084 mutex_unlock(&s->ops_mutex);
1011 1085
1012 return ret ? ret : count; 1086 return ret ? ret : count;
1013} 1087}
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index 7a456000332a..08278016e58d 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -88,15 +88,14 @@ static DEVICE_ATTR(card_vcc, 0444, pccard_show_vcc, NULL);
88static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr, 88static ssize_t pccard_store_insert(struct device *dev, struct device_attribute *attr,
89 const char *buf, size_t count) 89 const char *buf, size_t count)
90{ 90{
91 ssize_t ret;
92 struct pcmcia_socket *s = to_socket(dev); 91 struct pcmcia_socket *s = to_socket(dev);
93 92
94 if (!count) 93 if (!count)
95 return -EINVAL; 94 return -EINVAL;
96 95
97 ret = pcmcia_insert_card(s); 96 pcmcia_parse_uevents(s, PCMCIA_UEVENT_INSERT);
98 97
99 return ret ? ret : count; 98 return count;
100} 99}
101static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert); 100static DEVICE_ATTR(card_insert, 0200, NULL, pccard_store_insert);
102 101
@@ -113,18 +112,22 @@ static ssize_t pccard_store_card_pm_state(struct device *dev,
113 struct device_attribute *attr, 112 struct device_attribute *attr,
114 const char *buf, size_t count) 113 const char *buf, size_t count)
115{ 114{
116 ssize_t ret = -EINVAL;
117 struct pcmcia_socket *s = to_socket(dev); 115 struct pcmcia_socket *s = to_socket(dev);
116 ssize_t ret = count;
118 117
119 if (!count) 118 if (!count)
120 return -EINVAL; 119 return -EINVAL;
121 120
122 if (!(s->state & SOCKET_SUSPEND) && !strncmp(buf, "off", 3)) 121 if (!strncmp(buf, "off", 3))
123 ret = pcmcia_suspend_card(s); 122 pcmcia_parse_uevents(s, PCMCIA_UEVENT_SUSPEND);
124 else if ((s->state & SOCKET_SUSPEND) && !strncmp(buf, "on", 2)) 123 else {
125 ret = pcmcia_resume_card(s); 124 if (!strncmp(buf, "on", 2))
125 pcmcia_parse_uevents(s, PCMCIA_UEVENT_RESUME);
126 else
127 ret = -EINVAL;
128 }
126 129
127 return ret ? -ENODEV : count; 130 return ret;
128} 131}
129static DEVICE_ATTR(card_pm_state, 0644, pccard_show_card_pm_state, pccard_store_card_pm_state); 132static DEVICE_ATTR(card_pm_state, 0644, pccard_show_card_pm_state, pccard_store_card_pm_state);
130 133
@@ -132,15 +135,14 @@ static ssize_t pccard_store_eject(struct device *dev,
132 struct device_attribute *attr, 135 struct device_attribute *attr,
133 const char *buf, size_t count) 136 const char *buf, size_t count)
134{ 137{
135 ssize_t ret;
136 struct pcmcia_socket *s = to_socket(dev); 138 struct pcmcia_socket *s = to_socket(dev);
137 139
138 if (!count) 140 if (!count)
139 return -EINVAL; 141 return -EINVAL;
140 142
141 ret = pcmcia_eject_card(s); 143 pcmcia_parse_uevents(s, PCMCIA_UEVENT_EJECT);
142 144
143 return ret ? ret : count; 145 return count;
144} 146}
145static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject); 147static DEVICE_ATTR(card_eject, 0200, NULL, pccard_store_eject);
146 148
@@ -167,7 +169,9 @@ static ssize_t pccard_store_irq_mask(struct device *dev,
167 ret = sscanf(buf, "0x%x\n", &mask); 169 ret = sscanf(buf, "0x%x\n", &mask);
168 170
169 if (ret == 1) { 171 if (ret == 1) {
172 mutex_lock(&s->ops_mutex);
170 s->irq_mask &= mask; 173 s->irq_mask &= mask;
174 mutex_unlock(&s->ops_mutex);
171 ret = 0; 175 ret = 0;
172 } 176 }
173 177
@@ -187,163 +191,21 @@ static ssize_t pccard_store_resource(struct device *dev,
187 struct device_attribute *attr, 191 struct device_attribute *attr,
188 const char *buf, size_t count) 192 const char *buf, size_t count)
189{ 193{
190 unsigned long flags;
191 struct pcmcia_socket *s = to_socket(dev); 194 struct pcmcia_socket *s = to_socket(dev);
192 195
193 if (!count) 196 if (!count)
194 return -EINVAL; 197 return -EINVAL;
195 198
196 spin_lock_irqsave(&s->lock, flags); 199 mutex_lock(&s->ops_mutex);
197 if (!s->resource_setup_done) 200 if (!s->resource_setup_done)
198 s->resource_setup_done = 1; 201 s->resource_setup_done = 1;
199 spin_unlock_irqrestore(&s->lock, flags); 202 mutex_unlock(&s->ops_mutex);
200
201 mutex_lock(&s->skt_mutex);
202 if ((s->callback) &&
203 (s->state & SOCKET_PRESENT) &&
204 !(s->state & SOCKET_CARDBUS)) {
205 if (try_module_get(s->callback->owner)) {
206 s->callback->requery(s, 0);
207 module_put(s->callback->owner);
208 }
209 }
210 mutex_unlock(&s->skt_mutex);
211
212 return count;
213}
214static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
215 203
216 204 pcmcia_parse_uevents(s, PCMCIA_UEVENT_REQUERY);
217static ssize_t pccard_extract_cis(struct pcmcia_socket *s, char *buf, loff_t off, size_t count)
218{
219 tuple_t tuple;
220 int status, i;
221 loff_t pointer = 0;
222 ssize_t ret = 0;
223 u_char *tuplebuffer;
224 u_char *tempbuffer;
225
226 tuplebuffer = kmalloc(sizeof(u_char) * 256, GFP_KERNEL);
227 if (!tuplebuffer)
228 return -ENOMEM;
229
230 tempbuffer = kmalloc(sizeof(u_char) * 258, GFP_KERNEL);
231 if (!tempbuffer) {
232 ret = -ENOMEM;
233 goto free_tuple;
234 }
235
236 memset(&tuple, 0, sizeof(tuple_t));
237
238 tuple.Attributes = TUPLE_RETURN_LINK | TUPLE_RETURN_COMMON;
239 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
240 tuple.TupleOffset = 0;
241
242 status = pccard_get_first_tuple(s, BIND_FN_ALL, &tuple);
243 while (!status) {
244 tuple.TupleData = tuplebuffer;
245 tuple.TupleDataMax = 255;
246 memset(tuplebuffer, 0, sizeof(u_char) * 255);
247
248 status = pccard_get_tuple_data(s, &tuple);
249 if (status)
250 break;
251
252 if (off < (pointer + 2 + tuple.TupleDataLen)) {
253 tempbuffer[0] = tuple.TupleCode & 0xff;
254 tempbuffer[1] = tuple.TupleLink & 0xff;
255 for (i = 0; i < tuple.TupleDataLen; i++)
256 tempbuffer[i + 2] = tuplebuffer[i] & 0xff;
257
258 for (i = 0; i < (2 + tuple.TupleDataLen); i++) {
259 if (((i + pointer) >= off) &&
260 (i + pointer) < (off + count)) {
261 buf[ret] = tempbuffer[i];
262 ret++;
263 }
264 }
265 }
266
267 pointer += 2 + tuple.TupleDataLen;
268
269 if (pointer >= (off + count))
270 break;
271
272 if (tuple.TupleCode == CISTPL_END)
273 break;
274 status = pccard_get_next_tuple(s, BIND_FN_ALL, &tuple);
275 }
276
277 kfree(tempbuffer);
278 free_tuple:
279 kfree(tuplebuffer);
280
281 return ret;
282}
283
284static ssize_t pccard_show_cis(struct kobject *kobj,
285 struct bin_attribute *bin_attr,
286 char *buf, loff_t off, size_t count)
287{
288 unsigned int size = 0x200;
289
290 if (off >= size)
291 count = 0;
292 else {
293 struct pcmcia_socket *s;
294 unsigned int chains;
295
296 if (off + count > size)
297 count = size - off;
298
299 s = to_socket(container_of(kobj, struct device, kobj));
300
301 if (!(s->state & SOCKET_PRESENT))
302 return -ENODEV;
303 if (pccard_validate_cis(s, &chains))
304 return -EIO;
305 if (!chains)
306 return -ENODATA;
307
308 count = pccard_extract_cis(s, buf, off, count);
309 }
310
311 return count;
312}
313
314static ssize_t pccard_store_cis(struct kobject *kobj,
315 struct bin_attribute *bin_attr,
316 char *buf, loff_t off, size_t count)
317{
318 struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj));
319 int error;
320
321 if (off)
322 return -EINVAL;
323
324 if (count >= CISTPL_MAX_CIS_SIZE)
325 return -EINVAL;
326
327 if (!(s->state & SOCKET_PRESENT))
328 return -ENODEV;
329
330 error = pcmcia_replace_cis(s, buf, count);
331 if (error)
332 return -EIO;
333
334 mutex_lock(&s->skt_mutex);
335 if ((s->callback) && (s->state & SOCKET_PRESENT) &&
336 !(s->state & SOCKET_CARDBUS)) {
337 if (try_module_get(s->callback->owner)) {
338 s->callback->requery(s, 1);
339 module_put(s->callback->owner);
340 }
341 }
342 mutex_unlock(&s->skt_mutex);
343 205
344 return count; 206 return count;
345} 207}
346 208static DEVICE_ATTR(available_resources_setup_done, 0600, pccard_show_resource, pccard_store_resource);
347 209
348static struct attribute *pccard_socket_attributes[] = { 210static struct attribute *pccard_socket_attributes[] = {
349 &dev_attr_card_type.attr, 211 &dev_attr_card_type.attr,
@@ -362,28 +224,12 @@ static const struct attribute_group socket_attrs = {
362 .attrs = pccard_socket_attributes, 224 .attrs = pccard_socket_attributes,
363}; 225};
364 226
365static struct bin_attribute pccard_cis_attr = {
366 .attr = { .name = "cis", .mode = S_IRUGO | S_IWUSR },
367 .size = 0x200,
368 .read = pccard_show_cis,
369 .write = pccard_store_cis,
370};
371
372int pccard_sysfs_add_socket(struct device *dev) 227int pccard_sysfs_add_socket(struct device *dev)
373{ 228{
374 int ret = 0; 229 return sysfs_create_group(&dev->kobj, &socket_attrs);
375
376 ret = sysfs_create_group(&dev->kobj, &socket_attrs);
377 if (!ret) {
378 ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr);
379 if (ret)
380 sysfs_remove_group(&dev->kobj, &socket_attrs);
381 }
382 return ret;
383} 230}
384 231
385void pccard_sysfs_remove_socket(struct device *dev) 232void pccard_sysfs_remove_socket(struct device *dev)
386{ 233{
387 sysfs_remove_bin_file(&dev->kobj, &pccard_cis_attr);
388 sysfs_remove_group(&dev->kobj, &socket_attrs); 234 sysfs_remove_group(&dev->kobj, &socket_attrs);
389} 235}
diff --git a/drivers/pcmcia/xxs1500_ss.c b/drivers/pcmcia/xxs1500_ss.c
new file mode 100644
index 000000000000..61560cd6e287
--- /dev/null
+++ b/drivers/pcmcia/xxs1500_ss.c
@@ -0,0 +1,350 @@
1/*
2 * PCMCIA socket code for the MyCable XXS1500 system.
3 *
4 * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com>
5 *
6 */
7
8#include <linux/delay.h>
9#include <linux/gpio.h>
10#include <linux/interrupt.h>
11#include <linux/io.h>
12#include <linux/ioport.h>
13#include <linux/mm.h>
14#include <linux/platform_device.h>
15#include <linux/pm.h>
16#include <linux/resource.h>
17#include <linux/spinlock.h>
18
19#include <pcmcia/cs_types.h>
20#include <pcmcia/cs.h>
21#include <pcmcia/ss.h>
22#include <pcmcia/cistpl.h>
23
24#include <asm/irq.h>
25#include <asm/system.h>
26#include <asm/mach-au1x00/au1000.h>
27
28#define MEM_MAP_SIZE 0x400000
29#define IO_MAP_SIZE 0x1000
30
31
32/*
33 * 3.3V cards only; all interfacing is done via gpios:
34 *
35 * 0/1: carddetect (00 = card present, xx = huh)
36 * 4: card irq
37 * 204: reset (high-act)
38 * 205: buffer enable (low-act)
39 * 208/209: card voltage key (00,01,10,11)
40 * 210: battwarn
41 * 211: batdead
42 * 214: power (low-act)
43 */
44#define GPIO_CDA 0
45#define GPIO_CDB 1
46#define GPIO_CARDIRQ 4
47#define GPIO_RESET 204
48#define GPIO_OUTEN 205
49#define GPIO_VSL 208
50#define GPIO_VSH 209
51#define GPIO_BATTDEAD 210
52#define GPIO_BATTWARN 211
53#define GPIO_POWER 214
54
55struct xxs1500_pcmcia_sock {
56 struct pcmcia_socket socket;
57 void *virt_io;
58
59 phys_addr_t phys_io;
60 phys_addr_t phys_attr;
61 phys_addr_t phys_mem;
62
63 /* previous flags for set_socket() */
64 unsigned int old_flags;
65};
66
67#define to_xxs_socket(x) container_of(x, struct xxs1500_pcmcia_sock, socket)
68
69static irqreturn_t cdirq(int irq, void *data)
70{
71 struct xxs1500_pcmcia_sock *sock = data;
72
73 pcmcia_parse_events(&sock->socket, SS_DETECT);
74
75 return IRQ_HANDLED;
76}
77
78static int xxs1500_pcmcia_configure(struct pcmcia_socket *skt,
79 struct socket_state_t *state)
80{
81 struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt);
82 unsigned int changed;
83
84 /* power control */
85 switch (state->Vcc) {
86 case 0:
87 gpio_set_value(GPIO_POWER, 1); /* power off */
88 break;
89 case 33:
90 gpio_set_value(GPIO_POWER, 0); /* power on */
91 break;
92 case 50:
93 default:
94 return -EINVAL;
95 }
96
97 changed = state->flags ^ sock->old_flags;
98
99 if (changed & SS_RESET) {
100 if (state->flags & SS_RESET) {
101 gpio_set_value(GPIO_RESET, 1); /* assert reset */
102 gpio_set_value(GPIO_OUTEN, 1); /* buffers off */
103 } else {
104 gpio_set_value(GPIO_RESET, 0); /* deassert reset */
105 gpio_set_value(GPIO_OUTEN, 0); /* buffers on */
106 msleep(500);
107 }
108 }
109
110 sock->old_flags = state->flags;
111
112 return 0;
113}
114
115static int xxs1500_pcmcia_get_status(struct pcmcia_socket *skt,
116 unsigned int *value)
117{
118 unsigned int status;
119 int i;
120
121 status = 0;
122
123 /* check carddetects: GPIO[0:1] must both be low */
124 if (!gpio_get_value(GPIO_CDA) && !gpio_get_value(GPIO_CDB))
125 status |= SS_DETECT;
126
127 /* determine card voltage: GPIO[208:209] binary value */
128 i = (!!gpio_get_value(GPIO_VSL)) | ((!!gpio_get_value(GPIO_VSH)) << 1);
129
130 switch (i) {
131 case 0:
132 case 1:
133 case 2:
134 status |= SS_3VCARD; /* 3V card */
135 break;
136 case 3: /* 5V card, unsupported */
137 default:
138 status |= SS_XVCARD; /* treated as unsupported in core */
139 }
140
141 /* GPIO214: low active power switch */
142 status |= gpio_get_value(GPIO_POWER) ? 0 : SS_POWERON;
143
144 /* GPIO204: high-active reset line */
145 status |= gpio_get_value(GPIO_RESET) ? SS_RESET : SS_READY;
146
147 /* other stuff */
148 status |= gpio_get_value(GPIO_BATTDEAD) ? 0 : SS_BATDEAD;
149 status |= gpio_get_value(GPIO_BATTWARN) ? 0 : SS_BATWARN;
150
151 *value = status;
152
153 return 0;
154}
155
156static int xxs1500_pcmcia_sock_init(struct pcmcia_socket *skt)
157{
158 gpio_direction_input(GPIO_CDA);
159 gpio_direction_input(GPIO_CDB);
160 gpio_direction_input(GPIO_VSL);
161 gpio_direction_input(GPIO_VSH);
162 gpio_direction_input(GPIO_BATTDEAD);
163 gpio_direction_input(GPIO_BATTWARN);
164 gpio_direction_output(GPIO_RESET, 1); /* assert reset */
165 gpio_direction_output(GPIO_OUTEN, 1); /* disable buffers */
166 gpio_direction_output(GPIO_POWER, 1); /* power off */
167
168 return 0;
169}
170
171static int xxs1500_pcmcia_sock_suspend(struct pcmcia_socket *skt)
172{
173 return 0;
174}
175
176static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt,
177 struct pccard_io_map *map)
178{
179 struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt);
180
181 map->start = (u32)sock->virt_io;
182 map->stop = map->start + IO_MAP_SIZE;
183
184 return 0;
185}
186
187static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt,
188 struct pccard_mem_map *map)
189{
190 struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt);
191
192 if (map->flags & MAP_ATTRIB)
193 map->static_start = sock->phys_attr + map->card_start;
194 else
195 map->static_start = sock->phys_mem + map->card_start;
196
197 return 0;
198}
199
200static struct pccard_operations xxs1500_pcmcia_operations = {
201 .init = xxs1500_pcmcia_sock_init,
202 .suspend = xxs1500_pcmcia_sock_suspend,
203 .get_status = xxs1500_pcmcia_get_status,
204 .set_socket = xxs1500_pcmcia_configure,
205 .set_io_map = au1x00_pcmcia_set_io_map,
206 .set_mem_map = au1x00_pcmcia_set_mem_map,
207};
208
209static int __devinit xxs1500_pcmcia_probe(struct platform_device *pdev)
210{
211 struct xxs1500_pcmcia_sock *sock;
212 struct resource *r;
213 int ret, irq;
214
215 sock = kzalloc(sizeof(struct xxs1500_pcmcia_sock), GFP_KERNEL);
216 if (!sock)
217 return -ENOMEM;
218
219 ret = -ENODEV;
220
221 /*
222 * pseudo-attr: The 32bit address of the PCMCIA attribute space
223 * for this socket (usually the 36bit address shifted 4 to the
224 * right).
225 */
226 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr");
227 if (!r) {
228 dev_err(&pdev->dev, "missing 'pcmcia-attr' resource!\n");
229 goto out0;
230 }
231 sock->phys_attr = r->start;
232
233 /*
234 * pseudo-mem: The 32bit address of the PCMCIA memory space for
235 * this socket (usually the 36bit address shifted 4 to the right)
236 */
237 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem");
238 if (!r) {
239 dev_err(&pdev->dev, "missing 'pcmcia-mem' resource!\n");
240 goto out0;
241 }
242 sock->phys_mem = r->start;
243
244 /*
245 * pseudo-io: The 32bit address of the PCMCIA IO space for this
246 * socket (usually the 36bit address shifted 4 to the right).
247 */
248 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io");
249 if (!r) {
250 dev_err(&pdev->dev, "missing 'pcmcia-io' resource!\n");
251 goto out0;
252 }
253 sock->phys_io = r->start;
254
255
256 /*
257 * PCMCIA client drivers use the inb/outb macros to access
258 * the IO registers. Since mips_io_port_base is added
259 * to the access address of the mips implementation of
260 * inb/outb, we need to subtract it here because we want
261 * to access the I/O or MEM address directly, without
262 * going through this "mips_io_port_base" mechanism.
263 */
264 sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) -
265 mips_io_port_base);
266
267 if (!sock->virt_io) {
268 dev_err(&pdev->dev, "cannot remap IO area\n");
269 ret = -ENOMEM;
270 goto out0;
271 }
272
273 sock->socket.ops = &xxs1500_pcmcia_operations;
274 sock->socket.owner = THIS_MODULE;
275 sock->socket.pci_irq = gpio_to_irq(GPIO_CARDIRQ);
276 sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD;
277 sock->socket.map_size = MEM_MAP_SIZE;
278 sock->socket.io_offset = (unsigned long)sock->virt_io;
279 sock->socket.dev.parent = &pdev->dev;
280 sock->socket.resource_ops = &pccard_static_ops;
281
282 platform_set_drvdata(pdev, sock);
283
284 /* setup carddetect irq: use one of the 2 GPIOs as an
285 * edge detector.
286 */
287 irq = gpio_to_irq(GPIO_CDA);
288 set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);
289 ret = request_irq(irq, cdirq, 0, "pcmcia_carddetect", sock);
290 if (ret) {
291 dev_err(&pdev->dev, "cannot setup cd irq\n");
292 goto out1;
293 }
294
295 ret = pcmcia_register_socket(&sock->socket);
296 if (ret) {
297 dev_err(&pdev->dev, "failed to register\n");
298 goto out2;
299 }
300
301 printk(KERN_INFO "MyCable XXS1500 PCMCIA socket services\n");
302
303 return 0;
304
305out2:
306 free_irq(gpio_to_irq(GPIO_CDA), sock);
307out1:
308 iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
309out0:
310 kfree(sock);
311 return ret;
312}
313
314static int __devexit xxs1500_pcmcia_remove(struct platform_device *pdev)
315{
316 struct xxs1500_pcmcia_sock *sock = platform_get_drvdata(pdev);
317
318 pcmcia_unregister_socket(&sock->socket);
319 free_irq(gpio_to_irq(GPIO_CDA), sock);
320 iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
321 kfree(sock);
322
323 return 0;
324}
325
326static struct platform_driver xxs1500_pcmcia_socket_driver = {
327 .driver = {
328 .name = "xxs1500_pcmcia",
329 .owner = THIS_MODULE,
330 },
331 .probe = xxs1500_pcmcia_probe,
332 .remove = __devexit_p(xxs1500_pcmcia_remove),
333};
334
335int __init xxs1500_pcmcia_socket_load(void)
336{
337 return platform_driver_register(&xxs1500_pcmcia_socket_driver);
338}
339
340void __exit xxs1500_pcmcia_socket_unload(void)
341{
342 platform_driver_unregister(&xxs1500_pcmcia_socket_driver);
343}
344
345module_init(xxs1500_pcmcia_socket_load);
346module_exit(xxs1500_pcmcia_socket_unload);
347
348MODULE_LICENSE("GPL");
349MODULE_DESCRIPTION("PCMCIA Socket Services for MyCable XXS1500 systems");
350MODULE_AUTHOR("Manuel Lauss");
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index e4d12acdd525..b85375f87622 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -37,6 +37,11 @@ static int pwr_irqs_off;
37module_param(pwr_irqs_off, bool, 0644); 37module_param(pwr_irqs_off, bool, 0644);
38MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!"); 38MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!");
39 39
40static char o2_speedup[] = "default";
41module_param_string(o2_speedup, o2_speedup, sizeof(o2_speedup), 0444);
42MODULE_PARM_DESC(o2_speedup, "Use prefetch/burst for O2-bridges: 'on', 'off' "
43 "or 'default' (uses recommended behaviour for the detected bridge)");
44
40#define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args) 45#define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args)
41 46
42/* Don't ask.. */ 47/* Don't ask.. */
@@ -649,9 +654,10 @@ static int yenta_search_one_res(struct resource *root, struct resource *res,
649static int yenta_search_res(struct yenta_socket *socket, struct resource *res, 654static int yenta_search_res(struct yenta_socket *socket, struct resource *res,
650 u32 min) 655 u32 min)
651{ 656{
657 struct resource *root;
652 int i; 658 int i;
653 for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { 659
654 struct resource *root = socket->dev->bus->resource[i]; 660 pci_bus_for_each_resource(socket->dev->bus, root, i) {
655 if (!root) 661 if (!root)
656 continue; 662 continue;
657 663
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index f526e735c5ab..6848f213eb53 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -79,6 +79,7 @@ config DELL_LAPTOP
79 depends on BACKLIGHT_CLASS_DEVICE 79 depends on BACKLIGHT_CLASS_DEVICE
80 depends on RFKILL || RFKILL = n 80 depends on RFKILL || RFKILL = n
81 depends on POWER_SUPPLY 81 depends on POWER_SUPPLY
82 depends on SERIO_I8042
82 default n 83 default n
83 ---help--- 84 ---help---
84 This driver adds support for rfkill and backlight control to Dell 85 This driver adds support for rfkill and backlight control to Dell
diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index 07d14dfdf0b4..226b3e93498c 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -934,7 +934,7 @@ static int __devinit acer_backlight_init(struct device *dev)
934 acer_backlight_device = bd; 934 acer_backlight_device = bd;
935 935
936 bd->props.power = FB_BLANK_UNBLANK; 936 bd->props.power = FB_BLANK_UNBLANK;
937 bd->props.brightness = max_brightness; 937 bd->props.brightness = read_brightness(bd);
938 bd->props.max_brightness = max_brightness; 938 bd->props.max_brightness = max_brightness;
939 backlight_update_status(bd); 939 backlight_update_status(bd);
940 return 0; 940 return 0;
diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
index ed90082cdf1d..8cb20e45bad6 100644
--- a/drivers/platform/x86/classmate-laptop.c
+++ b/drivers/platform/x86/classmate-laptop.c
@@ -34,6 +34,11 @@ struct cmpc_accel {
34#define CMPC_ACCEL_SENSITIVITY_DEFAULT 5 34#define CMPC_ACCEL_SENSITIVITY_DEFAULT 5
35 35
36 36
37#define CMPC_ACCEL_HID "ACCE0000"
38#define CMPC_TABLET_HID "TBLT0000"
39#define CMPC_BL_HID "IPML200"
40#define CMPC_KEYS_HID "FnBT0000"
41
37/* 42/*
38 * Generic input device code. 43 * Generic input device code.
39 */ 44 */
@@ -282,10 +287,9 @@ static int cmpc_accel_remove(struct acpi_device *acpi, int type)
282} 287}
283 288
284static const struct acpi_device_id cmpc_accel_device_ids[] = { 289static const struct acpi_device_id cmpc_accel_device_ids[] = {
285 {"ACCE0000", 0}, 290 {CMPC_ACCEL_HID, 0},
286 {"", 0} 291 {"", 0}
287}; 292};
288MODULE_DEVICE_TABLE(acpi, cmpc_accel_device_ids);
289 293
290static struct acpi_driver cmpc_accel_acpi_driver = { 294static struct acpi_driver cmpc_accel_acpi_driver = {
291 .owner = THIS_MODULE, 295 .owner = THIS_MODULE,
@@ -366,10 +370,9 @@ static int cmpc_tablet_resume(struct acpi_device *acpi)
366} 370}
367 371
368static const struct acpi_device_id cmpc_tablet_device_ids[] = { 372static const struct acpi_device_id cmpc_tablet_device_ids[] = {
369 {"TBLT0000", 0}, 373 {CMPC_TABLET_HID, 0},
370 {"", 0} 374 {"", 0}
371}; 375};
372MODULE_DEVICE_TABLE(acpi, cmpc_tablet_device_ids);
373 376
374static struct acpi_driver cmpc_tablet_acpi_driver = { 377static struct acpi_driver cmpc_tablet_acpi_driver = {
375 .owner = THIS_MODULE, 378 .owner = THIS_MODULE,
@@ -477,17 +480,16 @@ static int cmpc_bl_remove(struct acpi_device *acpi, int type)
477 return 0; 480 return 0;
478} 481}
479 482
480static const struct acpi_device_id cmpc_device_ids[] = { 483static const struct acpi_device_id cmpc_bl_device_ids[] = {
481 {"IPML200", 0}, 484 {CMPC_BL_HID, 0},
482 {"", 0} 485 {"", 0}
483}; 486};
484MODULE_DEVICE_TABLE(acpi, cmpc_device_ids);
485 487
486static struct acpi_driver cmpc_bl_acpi_driver = { 488static struct acpi_driver cmpc_bl_acpi_driver = {
487 .owner = THIS_MODULE, 489 .owner = THIS_MODULE,
488 .name = "cmpc", 490 .name = "cmpc",
489 .class = "cmpc", 491 .class = "cmpc",
490 .ids = cmpc_device_ids, 492 .ids = cmpc_bl_device_ids,
491 .ops = { 493 .ops = {
492 .add = cmpc_bl_add, 494 .add = cmpc_bl_add,
493 .remove = cmpc_bl_remove 495 .remove = cmpc_bl_remove
@@ -540,10 +542,9 @@ static int cmpc_keys_remove(struct acpi_device *acpi, int type)
540} 542}
541 543
542static const struct acpi_device_id cmpc_keys_device_ids[] = { 544static const struct acpi_device_id cmpc_keys_device_ids[] = {
543 {"FnBT0000", 0}, 545 {CMPC_KEYS_HID, 0},
544 {"", 0} 546 {"", 0}
545}; 547};
546MODULE_DEVICE_TABLE(acpi, cmpc_keys_device_ids);
547 548
548static struct acpi_driver cmpc_keys_acpi_driver = { 549static struct acpi_driver cmpc_keys_acpi_driver = {
549 .owner = THIS_MODULE, 550 .owner = THIS_MODULE,
@@ -607,3 +608,13 @@ static void cmpc_exit(void)
607 608
608module_init(cmpc_init); 609module_init(cmpc_init);
609module_exit(cmpc_exit); 610module_exit(cmpc_exit);
611
612static const struct acpi_device_id cmpc_device_ids[] = {
613 {CMPC_ACCEL_HID, 0},
614 {CMPC_TABLET_HID, 0},
615 {CMPC_BL_HID, 0},
616 {CMPC_KEYS_HID, 0},
617 {"", 0}
618};
619
620MODULE_DEVICE_TABLE(acpi, cmpc_device_ids);
diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
index 1a387e79f719..2740b40aad9b 100644
--- a/drivers/platform/x86/compal-laptop.c
+++ b/drivers/platform/x86/compal-laptop.c
@@ -26,17 +26,8 @@
26/* 26/*
27 * comapl-laptop.c - Compal laptop support. 27 * comapl-laptop.c - Compal laptop support.
28 * 28 *
29 * This driver exports a few files in /sys/devices/platform/compal-laptop/: 29 * The driver registers itself with the rfkill subsystem and
30 * 30 * the Linux backlight control subsystem.
31 * wlan - wlan subsystem state: contains 0 or 1 (rw)
32 *
33 * bluetooth - Bluetooth subsystem state: contains 0 or 1 (rw)
34 *
35 * raw - raw value taken from embedded controller register (ro)
36 *
37 * In addition to these platform device attributes the driver
38 * registers itself in the Linux backlight control subsystem and is
39 * available to userspace under /sys/class/backlight/compal-laptop/.
40 * 31 *
41 * This driver might work on other laptops produced by Compal. If you 32 * This driver might work on other laptops produced by Compal. If you
42 * want to try it you can pass force=1 as argument to the module which 33 * want to try it you can pass force=1 as argument to the module which
@@ -51,6 +42,7 @@
51#include <linux/dmi.h> 42#include <linux/dmi.h>
52#include <linux/backlight.h> 43#include <linux/backlight.h>
53#include <linux/platform_device.h> 44#include <linux/platform_device.h>
45#include <linux/rfkill.h>
54 46
55#define COMPAL_DRIVER_VERSION "0.2.6" 47#define COMPAL_DRIVER_VERSION "0.2.6"
56 48
@@ -63,6 +55,10 @@
63#define WLAN_MASK 0x01 55#define WLAN_MASK 0x01
64#define BT_MASK 0x02 56#define BT_MASK 0x02
65 57
58static struct rfkill *wifi_rfkill;
59static struct rfkill *bt_rfkill;
60static struct platform_device *compal_device;
61
66static int force; 62static int force;
67module_param(force, bool, 0); 63module_param(force, bool, 0);
68MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); 64MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
@@ -88,65 +84,75 @@ static int get_lcd_level(void)
88 return (int) result; 84 return (int) result;
89} 85}
90 86
91static int set_wlan_state(int state) 87static int compal_rfkill_set(void *data, bool blocked)
92{ 88{
89 unsigned long radio = (unsigned long) data;
93 u8 result, value; 90 u8 result, value;
94 91
95 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); 92 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
96 93
97 if ((result & KILLSWITCH_MASK) == 0) 94 if (!blocked)
98 return -EINVAL; 95 value = (u8) (result | radio);
99 else { 96 else
100 if (state) 97 value = (u8) (result & ~radio);
101 value = (u8) (result | WLAN_MASK); 98 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
102 else
103 value = (u8) (result & ~WLAN_MASK);
104 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
105 }
106 99
107 return 0; 100 return 0;
108} 101}
109 102
110static int set_bluetooth_state(int state) 103static void compal_rfkill_poll(struct rfkill *rfkill, void *data)
111{ 104{
112 u8 result, value; 105 u8 result;
106 bool hw_blocked;
113 107
114 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); 108 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
115 109
116 if ((result & KILLSWITCH_MASK) == 0) 110 hw_blocked = !(result & KILLSWITCH_MASK);
117 return -EINVAL; 111 rfkill_set_hw_state(rfkill, hw_blocked);
118 else {
119 if (state)
120 value = (u8) (result | BT_MASK);
121 else
122 value = (u8) (result & ~BT_MASK);
123 ec_write(COMPAL_EC_COMMAND_WIRELESS, value);
124 }
125
126 return 0;
127} 112}
128 113
129static int get_wireless_state(int *wlan, int *bluetooth) 114static const struct rfkill_ops compal_rfkill_ops = {
115 .poll = compal_rfkill_poll,
116 .set_block = compal_rfkill_set,
117};
118
119static int setup_rfkill(void)
130{ 120{
131 u8 result; 121 int ret;
132 122
133 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); 123 wifi_rfkill = rfkill_alloc("compal-wifi", &compal_device->dev,
124 RFKILL_TYPE_WLAN, &compal_rfkill_ops,
125 (void *) WLAN_MASK);
126 if (!wifi_rfkill)
127 return -ENOMEM;
134 128
135 if (wlan) { 129 ret = rfkill_register(wifi_rfkill);
136 if ((result & KILLSWITCH_MASK) == 0) 130 if (ret)
137 *wlan = 0; 131 goto err_wifi;
138 else
139 *wlan = result & WLAN_MASK;
140 }
141 132
142 if (bluetooth) { 133 bt_rfkill = rfkill_alloc("compal-bluetooth", &compal_device->dev,
143 if ((result & KILLSWITCH_MASK) == 0) 134 RFKILL_TYPE_BLUETOOTH, &compal_rfkill_ops,
144 *bluetooth = 0; 135 (void *) BT_MASK);
145 else 136 if (!bt_rfkill) {
146 *bluetooth = (result & BT_MASK) >> 1; 137 ret = -ENOMEM;
138 goto err_allocate_bt;
147 } 139 }
140 ret = rfkill_register(bt_rfkill);
141 if (ret)
142 goto err_register_bt;
148 143
149 return 0; 144 return 0;
145
146err_register_bt:
147 rfkill_destroy(bt_rfkill);
148
149err_allocate_bt:
150 rfkill_unregister(wifi_rfkill);
151
152err_wifi:
153 rfkill_destroy(wifi_rfkill);
154
155 return ret;
150} 156}
151 157
152/* Backlight device stuff */ 158/* Backlight device stuff */
@@ -169,86 +175,6 @@ static struct backlight_ops compalbl_ops = {
169 175
170static struct backlight_device *compalbl_device; 176static struct backlight_device *compalbl_device;
171 177
172/* Platform device */
173
174static ssize_t show_wlan(struct device *dev,
175 struct device_attribute *attr, char *buf)
176{
177 int ret, enabled;
178
179 ret = get_wireless_state(&enabled, NULL);
180 if (ret < 0)
181 return ret;
182
183 return sprintf(buf, "%i\n", enabled);
184}
185
186static ssize_t show_raw(struct device *dev,
187 struct device_attribute *attr, char *buf)
188{
189 u8 result;
190
191 ec_read(COMPAL_EC_COMMAND_WIRELESS, &result);
192
193 return sprintf(buf, "%i\n", result);
194}
195
196static ssize_t show_bluetooth(struct device *dev,
197 struct device_attribute *attr, char *buf)
198{
199 int ret, enabled;
200
201 ret = get_wireless_state(NULL, &enabled);
202 if (ret < 0)
203 return ret;
204
205 return sprintf(buf, "%i\n", enabled);
206}
207
208static ssize_t store_wlan_state(struct device *dev,
209 struct device_attribute *attr, const char *buf, size_t count)
210{
211 int state, ret;
212
213 if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
214 return -EINVAL;
215
216 ret = set_wlan_state(state);
217 if (ret < 0)
218 return ret;
219
220 return count;
221}
222
223static ssize_t store_bluetooth_state(struct device *dev,
224 struct device_attribute *attr, const char *buf, size_t count)
225{
226 int state, ret;
227
228 if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
229 return -EINVAL;
230
231 ret = set_bluetooth_state(state);
232 if (ret < 0)
233 return ret;
234
235 return count;
236}
237
238static DEVICE_ATTR(bluetooth, 0644, show_bluetooth, store_bluetooth_state);
239static DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan_state);
240static DEVICE_ATTR(raw, 0444, show_raw, NULL);
241
242static struct attribute *compal_attributes[] = {
243 &dev_attr_bluetooth.attr,
244 &dev_attr_wlan.attr,
245 &dev_attr_raw.attr,
246 NULL
247};
248
249static struct attribute_group compal_attribute_group = {
250 .attrs = compal_attributes
251};
252 178
253static struct platform_driver compal_driver = { 179static struct platform_driver compal_driver = {
254 .driver = { 180 .driver = {
@@ -257,8 +183,6 @@ static struct platform_driver compal_driver = {
257 } 183 }
258}; 184};
259 185
260static struct platform_device *compal_device;
261
262/* Initialization */ 186/* Initialization */
263 187
264static int dmi_check_cb(const struct dmi_system_id *id) 188static int dmi_check_cb(const struct dmi_system_id *id)
@@ -310,6 +234,47 @@ static struct dmi_system_id __initdata compal_dmi_table[] = {
310 }, 234 },
311 .callback = dmi_check_cb 235 .callback = dmi_check_cb
312 }, 236 },
237 {
238 .ident = "Dell Mini 9",
239 .matches = {
240 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
241 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
242 },
243 .callback = dmi_check_cb
244 },
245 {
246 .ident = "Dell Mini 10",
247 .matches = {
248 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
249 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
250 },
251 .callback = dmi_check_cb
252 },
253 {
254 .ident = "Dell Mini 10v",
255 .matches = {
256 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
257 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
258 },
259 .callback = dmi_check_cb
260 },
261 {
262 .ident = "Dell Inspiron 11z",
263 .matches = {
264 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
265 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
266 },
267 .callback = dmi_check_cb
268 },
269 {
270 .ident = "Dell Mini 12",
271 .matches = {
272 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
273 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
274 },
275 .callback = dmi_check_cb
276 },
277
313 { } 278 { }
314}; 279};
315 280
@@ -348,23 +313,21 @@ static int __init compal_init(void)
348 313
349 ret = platform_device_add(compal_device); 314 ret = platform_device_add(compal_device);
350 if (ret) 315 if (ret)
351 goto fail_platform_device1; 316 goto fail_platform_device;
352 317
353 ret = sysfs_create_group(&compal_device->dev.kobj, 318 ret = setup_rfkill();
354 &compal_attribute_group);
355 if (ret) 319 if (ret)
356 goto fail_platform_device2; 320 goto fail_rfkill;
357 321
358 printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION 322 printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION
359 " successfully loaded.\n"); 323 " successfully loaded.\n");
360 324
361 return 0; 325 return 0;
362 326
363fail_platform_device2: 327fail_rfkill:
364
365 platform_device_del(compal_device); 328 platform_device_del(compal_device);
366 329
367fail_platform_device1: 330fail_platform_device:
368 331
369 platform_device_put(compal_device); 332 platform_device_put(compal_device);
370 333
@@ -382,10 +345,13 @@ fail_backlight:
382static void __exit compal_cleanup(void) 345static void __exit compal_cleanup(void)
383{ 346{
384 347
385 sysfs_remove_group(&compal_device->dev.kobj, &compal_attribute_group);
386 platform_device_unregister(compal_device); 348 platform_device_unregister(compal_device);
387 platform_driver_unregister(&compal_driver); 349 platform_driver_unregister(&compal_driver);
388 backlight_device_unregister(compalbl_device); 350 backlight_device_unregister(compalbl_device);
351 rfkill_unregister(wifi_rfkill);
352 rfkill_destroy(wifi_rfkill);
353 rfkill_unregister(bt_rfkill);
354 rfkill_destroy(bt_rfkill);
389 355
390 printk(KERN_INFO "compal-laptop: driver unloaded.\n"); 356 printk(KERN_INFO "compal-laptop: driver unloaded.\n");
391} 357}
@@ -403,3 +369,8 @@ MODULE_ALIAS("dmi:*:rnIFL90:rvrREFERENCE:*");
403MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*"); 369MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*");
404MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*"); 370MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*");
405MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*"); 371MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*");
372MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron910:*");
373MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1010:*");
374MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1011:*");
375MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1110:*");
376MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1210:*");
diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index 3780994dc8f2..b7f4d2705916 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -22,6 +22,8 @@
22#include <linux/rfkill.h> 22#include <linux/rfkill.h>
23#include <linux/power_supply.h> 23#include <linux/power_supply.h>
24#include <linux/acpi.h> 24#include <linux/acpi.h>
25#include <linux/mm.h>
26#include <linux/i8042.h>
25#include "../../firmware/dcdbas.h" 27#include "../../firmware/dcdbas.h"
26 28
27#define BRIGHTNESS_TOKEN 0x7d 29#define BRIGHTNESS_TOKEN 0x7d
@@ -79,9 +81,73 @@ static const struct dmi_system_id __initdata dell_device_table[] = {
79 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), 81 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
80 }, 82 },
81 }, 83 },
84 {
85 .ident = "Dell Computer Corporation",
86 .matches = {
87 DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
88 DMI_MATCH(DMI_CHASSIS_TYPE, "8"),
89 },
90 },
82 { } 91 { }
83}; 92};
84 93
94static struct dmi_system_id __devinitdata dell_blacklist[] = {
95 /* Supported by compal-laptop */
96 {
97 .ident = "Dell Mini 9",
98 .matches = {
99 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
100 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"),
101 },
102 },
103 {
104 .ident = "Dell Mini 10",
105 .matches = {
106 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
107 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"),
108 },
109 },
110 {
111 .ident = "Dell Mini 10v",
112 .matches = {
113 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
114 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"),
115 },
116 },
117 {
118 .ident = "Dell Inspiron 11z",
119 .matches = {
120 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
121 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"),
122 },
123 },
124 {
125 .ident = "Dell Mini 12",
126 .matches = {
127 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
128 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"),
129 },
130 },
131 {}
132};
133
134static struct calling_interface_buffer *buffer;
135struct page *bufferpage;
136DEFINE_MUTEX(buffer_mutex);
137
138static int hwswitch_state;
139
140static void get_buffer(void)
141{
142 mutex_lock(&buffer_mutex);
143 memset(buffer, 0, sizeof(struct calling_interface_buffer));
144}
145
146static void release_buffer(void)
147{
148 mutex_unlock(&buffer_mutex);
149}
150
85static void __init parse_da_table(const struct dmi_header *dm) 151static void __init parse_da_table(const struct dmi_header *dm)
86{ 152{
87 /* Final token is a terminator, so we don't want to copy it */ 153 /* Final token is a terminator, so we don't want to copy it */
@@ -160,6 +226,8 @@ dell_send_request(struct calling_interface_buffer *buffer, int class,
160/* Derived from information in DellWirelessCtl.cpp: 226/* Derived from information in DellWirelessCtl.cpp:
161 Class 17, select 11 is radio control. It returns an array of 32-bit values. 227 Class 17, select 11 is radio control. It returns an array of 32-bit values.
162 228
229 Input byte 0 = 0: Wireless information
230
163 result[0]: return code 231 result[0]: return code
164 result[1]: 232 result[1]:
165 Bit 0: Hardware switch supported 233 Bit 0: Hardware switch supported
@@ -180,33 +248,62 @@ dell_send_request(struct calling_interface_buffer *buffer, int class,
180 Bits 20-31: Reserved 248 Bits 20-31: Reserved
181 result[2]: NVRAM size in bytes 249 result[2]: NVRAM size in bytes
182 result[3]: NVRAM format version number 250 result[3]: NVRAM format version number
251
252 Input byte 0 = 2: Wireless switch configuration
253 result[0]: return code
254 result[1]:
255 Bit 0: Wifi controlled by switch
256 Bit 1: Bluetooth controlled by switch
257 Bit 2: WWAN controlled by switch
258 Bits 3-6: Reserved
259 Bit 7: Wireless switch config locked
260 Bit 8: Wifi locator enabled
261 Bits 9-14: Reserved
262 Bit 15: Wifi locator setting locked
263 Bits 16-31: Reserved
183*/ 264*/
184 265
185static int dell_rfkill_set(void *data, bool blocked) 266static int dell_rfkill_set(void *data, bool blocked)
186{ 267{
187 struct calling_interface_buffer buffer;
188 int disable = blocked ? 1 : 0; 268 int disable = blocked ? 1 : 0;
189 unsigned long radio = (unsigned long)data; 269 unsigned long radio = (unsigned long)data;
270 int hwswitch_bit = (unsigned long)data - 1;
271 int ret = 0;
272
273 get_buffer();
274 dell_send_request(buffer, 17, 11);
275
276 /* If the hardware switch controls this radio, and the hardware
277 switch is disabled, don't allow changing the software state */
278 if ((hwswitch_state & BIT(hwswitch_bit)) &&
279 !(buffer->output[1] & BIT(16))) {
280 ret = -EINVAL;
281 goto out;
282 }
190 283
191 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 284 buffer->input[0] = (1 | (radio<<8) | (disable << 16));
192 buffer.input[0] = (1 | (radio<<8) | (disable << 16)); 285 dell_send_request(buffer, 17, 11);
193 dell_send_request(&buffer, 17, 11);
194 286
195 return 0; 287out:
288 release_buffer();
289 return ret;
196} 290}
197 291
198static void dell_rfkill_query(struct rfkill *rfkill, void *data) 292static void dell_rfkill_query(struct rfkill *rfkill, void *data)
199{ 293{
200 struct calling_interface_buffer buffer;
201 int status; 294 int status;
202 int bit = (unsigned long)data + 16; 295 int bit = (unsigned long)data + 16;
296 int hwswitch_bit = (unsigned long)data - 1;
203 297
204 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 298 get_buffer();
205 dell_send_request(&buffer, 17, 11); 299 dell_send_request(buffer, 17, 11);
206 status = buffer.output[1]; 300 status = buffer->output[1];
301 release_buffer();
207 302
208 rfkill_set_sw_state(rfkill, !!(status & BIT(bit))); 303 rfkill_set_sw_state(rfkill, !!(status & BIT(bit)));
209 rfkill_set_hw_state(rfkill, !(status & BIT(16))); 304
305 if (hwswitch_state & (BIT(hwswitch_bit)))
306 rfkill_set_hw_state(rfkill, !(status & BIT(16)));
210} 307}
211 308
212static const struct rfkill_ops dell_rfkill_ops = { 309static const struct rfkill_ops dell_rfkill_ops = {
@@ -214,15 +311,36 @@ static const struct rfkill_ops dell_rfkill_ops = {
214 .query = dell_rfkill_query, 311 .query = dell_rfkill_query,
215}; 312};
216 313
314static void dell_update_rfkill(struct work_struct *ignored)
315{
316 if (wifi_rfkill)
317 dell_rfkill_query(wifi_rfkill, (void *)1);
318 if (bluetooth_rfkill)
319 dell_rfkill_query(bluetooth_rfkill, (void *)2);
320 if (wwan_rfkill)
321 dell_rfkill_query(wwan_rfkill, (void *)3);
322}
323static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill);
324
325
217static int __init dell_setup_rfkill(void) 326static int __init dell_setup_rfkill(void)
218{ 327{
219 struct calling_interface_buffer buffer;
220 int status; 328 int status;
221 int ret; 329 int ret;
222 330
223 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 331 if (dmi_check_system(dell_blacklist)) {
224 dell_send_request(&buffer, 17, 11); 332 printk(KERN_INFO "dell-laptop: Blacklisted hardware detected - "
225 status = buffer.output[1]; 333 "not enabling rfkill\n");
334 return 0;
335 }
336
337 get_buffer();
338 dell_send_request(buffer, 17, 11);
339 status = buffer->output[1];
340 buffer->input[0] = 0x2;
341 dell_send_request(buffer, 17, 11);
342 hwswitch_state = buffer->output[1];
343 release_buffer();
226 344
227 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { 345 if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) {
228 wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, 346 wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev,
@@ -298,39 +416,49 @@ static void dell_cleanup_rfkill(void)
298 416
299static int dell_send_intensity(struct backlight_device *bd) 417static int dell_send_intensity(struct backlight_device *bd)
300{ 418{
301 struct calling_interface_buffer buffer; 419 int ret = 0;
302 420
303 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 421 get_buffer();
304 buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); 422 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
305 buffer.input[1] = bd->props.brightness; 423 buffer->input[1] = bd->props.brightness;
306 424
307 if (buffer.input[0] == -1) 425 if (buffer->input[0] == -1) {
308 return -ENODEV; 426 ret = -ENODEV;
427 goto out;
428 }
309 429
310 if (power_supply_is_system_supplied() > 0) 430 if (power_supply_is_system_supplied() > 0)
311 dell_send_request(&buffer, 1, 2); 431 dell_send_request(buffer, 1, 2);
312 else 432 else
313 dell_send_request(&buffer, 1, 1); 433 dell_send_request(buffer, 1, 1);
314 434
435out:
436 release_buffer();
315 return 0; 437 return 0;
316} 438}
317 439
318static int dell_get_intensity(struct backlight_device *bd) 440static int dell_get_intensity(struct backlight_device *bd)
319{ 441{
320 struct calling_interface_buffer buffer; 442 int ret = 0;
321 443
322 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 444 get_buffer();
323 buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); 445 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
324 446
325 if (buffer.input[0] == -1) 447 if (buffer->input[0] == -1) {
326 return -ENODEV; 448 ret = -ENODEV;
449 goto out;
450 }
327 451
328 if (power_supply_is_system_supplied() > 0) 452 if (power_supply_is_system_supplied() > 0)
329 dell_send_request(&buffer, 0, 2); 453 dell_send_request(buffer, 0, 2);
330 else 454 else
331 dell_send_request(&buffer, 0, 1); 455 dell_send_request(buffer, 0, 1);
332 456
333 return buffer.output[1]; 457out:
458 release_buffer();
459 if (ret)
460 return ret;
461 return buffer->output[1];
334} 462}
335 463
336static struct backlight_ops dell_ops = { 464static struct backlight_ops dell_ops = {
@@ -338,9 +466,32 @@ static struct backlight_ops dell_ops = {
338 .update_status = dell_send_intensity, 466 .update_status = dell_send_intensity,
339}; 467};
340 468
469bool dell_laptop_i8042_filter(unsigned char data, unsigned char str,
470 struct serio *port)
471{
472 static bool extended;
473
474 if (str & 0x20)
475 return false;
476
477 if (unlikely(data == 0xe0)) {
478 extended = true;
479 return false;
480 } else if (unlikely(extended)) {
481 switch (data) {
482 case 0x8:
483 schedule_delayed_work(&dell_rfkill_work,
484 round_jiffies_relative(HZ));
485 break;
486 }
487 extended = false;
488 }
489
490 return false;
491}
492
341static int __init dell_init(void) 493static int __init dell_init(void)
342{ 494{
343 struct calling_interface_buffer buffer;
344 int max_intensity = 0; 495 int max_intensity = 0;
345 int ret; 496 int ret;
346 497
@@ -366,6 +517,17 @@ static int __init dell_init(void)
366 if (ret) 517 if (ret)
367 goto fail_platform_device2; 518 goto fail_platform_device2;
368 519
520 /*
521 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
522 * is passed to SMI handler.
523 */
524 bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32);
525
526 if (!bufferpage)
527 goto fail_buffer;
528 buffer = page_address(bufferpage);
529 mutex_init(&buffer_mutex);
530
369 ret = dell_setup_rfkill(); 531 ret = dell_setup_rfkill();
370 532
371 if (ret) { 533 if (ret) {
@@ -373,6 +535,13 @@ static int __init dell_init(void)
373 goto fail_rfkill; 535 goto fail_rfkill;
374 } 536 }
375 537
538 ret = i8042_install_filter(dell_laptop_i8042_filter);
539 if (ret) {
540 printk(KERN_WARNING
541 "dell-laptop: Unable to install key filter\n");
542 goto fail_filter;
543 }
544
376#ifdef CONFIG_ACPI 545#ifdef CONFIG_ACPI
377 /* In the event of an ACPI backlight being available, don't 546 /* In the event of an ACPI backlight being available, don't
378 * register the platform controller. 547 * register the platform controller.
@@ -381,13 +550,13 @@ static int __init dell_init(void)
381 return 0; 550 return 0;
382#endif 551#endif
383 552
384 memset(&buffer, 0, sizeof(struct calling_interface_buffer)); 553 get_buffer();
385 buffer.input[0] = find_token_location(BRIGHTNESS_TOKEN); 554 buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN);
386 555 if (buffer->input[0] != -1) {
387 if (buffer.input[0] != -1) { 556 dell_send_request(buffer, 0, 2);
388 dell_send_request(&buffer, 0, 2); 557 max_intensity = buffer->output[3];
389 max_intensity = buffer.output[3];
390 } 558 }
559 release_buffer();
391 560
392 if (max_intensity) { 561 if (max_intensity) {
393 dell_backlight_device = backlight_device_register( 562 dell_backlight_device = backlight_device_register(
@@ -410,8 +579,12 @@ static int __init dell_init(void)
410 return 0; 579 return 0;
411 580
412fail_backlight: 581fail_backlight:
582 i8042_remove_filter(dell_laptop_i8042_filter);
583fail_filter:
413 dell_cleanup_rfkill(); 584 dell_cleanup_rfkill();
414fail_rfkill: 585fail_rfkill:
586 free_page((unsigned long)bufferpage);
587fail_buffer:
415 platform_device_del(platform_device); 588 platform_device_del(platform_device);
416fail_platform_device2: 589fail_platform_device2:
417 platform_device_put(platform_device); 590 platform_device_put(platform_device);
@@ -424,8 +597,16 @@ fail_platform_driver:
424 597
425static void __exit dell_exit(void) 598static void __exit dell_exit(void)
426{ 599{
600 cancel_delayed_work_sync(&dell_rfkill_work);
601 i8042_remove_filter(dell_laptop_i8042_filter);
427 backlight_device_unregister(dell_backlight_device); 602 backlight_device_unregister(dell_backlight_device);
428 dell_cleanup_rfkill(); 603 dell_cleanup_rfkill();
604 if (platform_device) {
605 platform_device_del(platform_device);
606 platform_driver_unregister(&platform_driver);
607 }
608 kfree(da_tokens);
609 free_page((unsigned long)buffer);
429} 610}
430 611
431module_init(dell_init); 612module_init(dell_init);
@@ -435,3 +616,4 @@ MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
435MODULE_DESCRIPTION("Dell laptop driver"); 616MODULE_DESCRIPTION("Dell laptop driver");
436MODULE_LICENSE("GPL"); 617MODULE_LICENSE("GPL");
437MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*"); 618MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*");
619MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*");
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index ad4c414dbfbc..3aa57da8b43b 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -89,6 +89,7 @@ static struct key_entry hp_wmi_keymap[] = {
89 {KE_KEY, 0x20e6, KEY_PROG1}, 89 {KE_KEY, 0x20e6, KEY_PROG1},
90 {KE_KEY, 0x2142, KEY_MEDIA}, 90 {KE_KEY, 0x2142, KEY_MEDIA},
91 {KE_KEY, 0x213b, KEY_INFO}, 91 {KE_KEY, 0x213b, KEY_INFO},
92 {KE_KEY, 0x2169, KEY_DIRECTION},
92 {KE_KEY, 0x231b, KEY_HELP}, 93 {KE_KEY, 0x231b, KEY_HELP},
93 {KE_END, 0} 94 {KE_END, 0}
94}; 95};
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index e67e4feb35cb..eb603f1d55ca 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -5771,7 +5771,7 @@ static void thermal_exit(void)
5771 case TPACPI_THERMAL_ACPI_TMP07: 5771 case TPACPI_THERMAL_ACPI_TMP07:
5772 case TPACPI_THERMAL_ACPI_UPDT: 5772 case TPACPI_THERMAL_ACPI_UPDT:
5773 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, 5773 sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
5774 &thermal_temp_input16_group); 5774 &thermal_temp_input8_group);
5775 break; 5775 break;
5776 case TPACPI_THERMAL_NONE: 5776 case TPACPI_THERMAL_NONE:
5777 default: 5777 default:
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index 77bf5d8f893a..26c211724acf 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -46,6 +46,7 @@
46#include <linux/backlight.h> 46#include <linux/backlight.h>
47#include <linux/platform_device.h> 47#include <linux/platform_device.h>
48#include <linux/rfkill.h> 48#include <linux/rfkill.h>
49#include <linux/input.h>
49 50
50#include <asm/uaccess.h> 51#include <asm/uaccess.h>
51 52
@@ -62,9 +63,10 @@ MODULE_LICENSE("GPL");
62 63
63/* Toshiba ACPI method paths */ 64/* Toshiba ACPI method paths */
64#define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM" 65#define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
65#define METHOD_HCI_1 "\\_SB_.VALD.GHCI" 66#define TOSH_INTERFACE_1 "\\_SB_.VALD"
66#define METHOD_HCI_2 "\\_SB_.VALZ.GHCI" 67#define TOSH_INTERFACE_2 "\\_SB_.VALZ"
67#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" 68#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
69#define GHCI_METHOD ".GHCI"
68 70
69/* Toshiba HCI interface definitions 71/* Toshiba HCI interface definitions
70 * 72 *
@@ -116,6 +118,36 @@ static const struct acpi_device_id toshiba_device_ids[] = {
116}; 118};
117MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); 119MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
118 120
121struct key_entry {
122 char type;
123 u16 code;
124 u16 keycode;
125};
126
127enum {KE_KEY, KE_END};
128
129static struct key_entry toshiba_acpi_keymap[] = {
130 {KE_KEY, 0x101, KEY_MUTE},
131 {KE_KEY, 0x13b, KEY_COFFEE},
132 {KE_KEY, 0x13c, KEY_BATTERY},
133 {KE_KEY, 0x13d, KEY_SLEEP},
134 {KE_KEY, 0x13e, KEY_SUSPEND},
135 {KE_KEY, 0x13f, KEY_SWITCHVIDEOMODE},
136 {KE_KEY, 0x140, KEY_BRIGHTNESSDOWN},
137 {KE_KEY, 0x141, KEY_BRIGHTNESSUP},
138 {KE_KEY, 0x142, KEY_WLAN},
139 {KE_KEY, 0x143, KEY_PROG1},
140 {KE_KEY, 0xb05, KEY_PROG2},
141 {KE_KEY, 0xb06, KEY_WWW},
142 {KE_KEY, 0xb07, KEY_MAIL},
143 {KE_KEY, 0xb30, KEY_STOP},
144 {KE_KEY, 0xb31, KEY_PREVIOUSSONG},
145 {KE_KEY, 0xb32, KEY_NEXTSONG},
146 {KE_KEY, 0xb33, KEY_PLAYPAUSE},
147 {KE_KEY, 0xb5a, KEY_MEDIA},
148 {KE_END, 0, 0},
149};
150
119/* utility 151/* utility
120 */ 152 */
121 153
@@ -251,6 +283,8 @@ static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
251struct toshiba_acpi_dev { 283struct toshiba_acpi_dev {
252 struct platform_device *p_dev; 284 struct platform_device *p_dev;
253 struct rfkill *bt_rfk; 285 struct rfkill *bt_rfk;
286 struct input_dev *hotkey_dev;
287 acpi_handle handle;
254 288
255 const char *bt_name; 289 const char *bt_name;
256 290
@@ -711,8 +745,159 @@ static struct backlight_ops toshiba_backlight_data = {
711 .update_status = set_lcd_status, 745 .update_status = set_lcd_status,
712}; 746};
713 747
748static struct key_entry *toshiba_acpi_get_entry_by_scancode(int code)
749{
750 struct key_entry *key;
751
752 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
753 if (code == key->code)
754 return key;
755
756 return NULL;
757}
758
759static struct key_entry *toshiba_acpi_get_entry_by_keycode(int code)
760{
761 struct key_entry *key;
762
763 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
764 if (code == key->keycode && key->type == KE_KEY)
765 return key;
766
767 return NULL;
768}
769
770static int toshiba_acpi_getkeycode(struct input_dev *dev, int scancode,
771 int *keycode)
772{
773 struct key_entry *key = toshiba_acpi_get_entry_by_scancode(scancode);
774
775 if (key && key->type == KE_KEY) {
776 *keycode = key->keycode;
777 return 0;
778 }
779
780 return -EINVAL;
781}
782
783static int toshiba_acpi_setkeycode(struct input_dev *dev, int scancode,
784 int keycode)
785{
786 struct key_entry *key;
787 int old_keycode;
788
789 if (keycode < 0 || keycode > KEY_MAX)
790 return -EINVAL;
791
792 key = toshiba_acpi_get_entry_by_scancode(scancode);
793 if (key && key->type == KE_KEY) {
794 old_keycode = key->keycode;
795 key->keycode = keycode;
796 set_bit(keycode, dev->keybit);
797 if (!toshiba_acpi_get_entry_by_keycode(old_keycode))
798 clear_bit(old_keycode, dev->keybit);
799 return 0;
800 }
801
802 return -EINVAL;
803}
804
805static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
806{
807 u32 hci_result, value;
808 struct key_entry *key;
809
810 if (event != 0x80)
811 return;
812 do {
813 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
814 if (hci_result == HCI_SUCCESS) {
815 if (value == 0x100)
816 continue;
817 else if (value & 0x80) {
818 key = toshiba_acpi_get_entry_by_scancode
819 (value & ~0x80);
820 if (!key) {
821 printk(MY_INFO "Unknown key %x\n",
822 value & ~0x80);
823 continue;
824 }
825 input_report_key(toshiba_acpi.hotkey_dev,
826 key->keycode, 1);
827 input_sync(toshiba_acpi.hotkey_dev);
828 input_report_key(toshiba_acpi.hotkey_dev,
829 key->keycode, 0);
830 input_sync(toshiba_acpi.hotkey_dev);
831 }
832 } else if (hci_result == HCI_NOT_SUPPORTED) {
833 /* This is a workaround for an unresolved issue on
834 * some machines where system events sporadically
835 * become disabled. */
836 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
837 printk(MY_NOTICE "Re-enabled hotkeys\n");
838 }
839 } while (hci_result != HCI_EMPTY);
840}
841
842static int toshiba_acpi_setup_keyboard(char *device)
843{
844 acpi_status status;
845 acpi_handle handle;
846 int result;
847 const struct key_entry *key;
848
849 status = acpi_get_handle(NULL, device, &handle);
850 if (ACPI_FAILURE(status)) {
851 printk(MY_INFO "Unable to get notification device\n");
852 return -ENODEV;
853 }
854
855 toshiba_acpi.handle = handle;
856
857 status = acpi_evaluate_object(handle, "ENAB", NULL, NULL);
858 if (ACPI_FAILURE(status)) {
859 printk(MY_INFO "Unable to enable hotkeys\n");
860 return -ENODEV;
861 }
862
863 status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY,
864 toshiba_acpi_notify, NULL);
865 if (ACPI_FAILURE(status)) {
866 printk(MY_INFO "Unable to install hotkey notification\n");
867 return -ENODEV;
868 }
869
870 toshiba_acpi.hotkey_dev = input_allocate_device();
871 if (!toshiba_acpi.hotkey_dev) {
872 printk(MY_INFO "Unable to register input device\n");
873 return -ENOMEM;
874 }
875
876 toshiba_acpi.hotkey_dev->name = "Toshiba input device";
877 toshiba_acpi.hotkey_dev->phys = device;
878 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
879 toshiba_acpi.hotkey_dev->getkeycode = toshiba_acpi_getkeycode;
880 toshiba_acpi.hotkey_dev->setkeycode = toshiba_acpi_setkeycode;
881
882 for (key = toshiba_acpi_keymap; key->type != KE_END; key++) {
883 set_bit(EV_KEY, toshiba_acpi.hotkey_dev->evbit);
884 set_bit(key->keycode, toshiba_acpi.hotkey_dev->keybit);
885 }
886
887 result = input_register_device(toshiba_acpi.hotkey_dev);
888 if (result) {
889 printk(MY_INFO "Unable to register input device\n");
890 return result;
891 }
892
893 return 0;
894}
895
714static void toshiba_acpi_exit(void) 896static void toshiba_acpi_exit(void)
715{ 897{
898 if (toshiba_acpi.hotkey_dev)
899 input_unregister_device(toshiba_acpi.hotkey_dev);
900
716 if (toshiba_acpi.bt_rfk) { 901 if (toshiba_acpi.bt_rfk) {
717 rfkill_unregister(toshiba_acpi.bt_rfk); 902 rfkill_unregister(toshiba_acpi.bt_rfk);
718 rfkill_destroy(toshiba_acpi.bt_rfk); 903 rfkill_destroy(toshiba_acpi.bt_rfk);
@@ -726,6 +911,9 @@ static void toshiba_acpi_exit(void)
726 if (toshiba_proc_dir) 911 if (toshiba_proc_dir)
727 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 912 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
728 913
914 acpi_remove_notify_handler(toshiba_acpi.handle, ACPI_DEVICE_NOTIFY,
915 toshiba_acpi_notify);
916
729 platform_device_unregister(toshiba_acpi.p_dev); 917 platform_device_unregister(toshiba_acpi.p_dev);
730 918
731 return; 919 return;
@@ -742,11 +930,15 @@ static int __init toshiba_acpi_init(void)
742 return -ENODEV; 930 return -ENODEV;
743 931
744 /* simple device detection: look for HCI method */ 932 /* simple device detection: look for HCI method */
745 if (is_valid_acpi_path(METHOD_HCI_1)) 933 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
746 method_hci = METHOD_HCI_1; 934 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
747 else if (is_valid_acpi_path(METHOD_HCI_2)) 935 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
748 method_hci = METHOD_HCI_2; 936 printk(MY_INFO "Unable to activate hotkeys\n");
749 else 937 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
938 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
939 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
940 printk(MY_INFO "Unable to activate hotkeys\n");
941 } else
750 return -ENODEV; 942 return -ENODEV;
751 943
752 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n", 944 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
diff --git a/drivers/ps3/ps3av.c b/drivers/ps3/ps3av.c
index e82d8c9c6cda..95a689befc84 100644
--- a/drivers/ps3/ps3av.c
+++ b/drivers/ps3/ps3av.c
@@ -532,7 +532,7 @@ static void ps3av_set_videomode_packet(u32 id)
532 res = ps3av_cmd_avb_param(&avb_param, len); 532 res = ps3av_cmd_avb_param(&avb_param, len);
533 if (res == PS3AV_STATUS_NO_SYNC_HEAD) 533 if (res == PS3AV_STATUS_NO_SYNC_HEAD)
534 printk(KERN_WARNING 534 printk(KERN_WARNING
535 "%s: Command failed. Please try your request again. \n", 535 "%s: Command failed. Please try your request again.\n",
536 __func__); 536 __func__);
537 else if (res) 537 else if (res)
538 dev_dbg(&ps3av->dev->core, "ps3av_cmd_avb_param failed\n"); 538 dev_dbg(&ps3av->dev->core, "ps3av_cmd_avb_param failed\n");
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 8167e9e6827a..2bb8a8b7ffaf 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -868,4 +868,14 @@ config RTC_DRV_MC13783
868 help 868 help
869 This enables support for the Freescale MC13783 PMIC RTC 869 This enables support for the Freescale MC13783 PMIC RTC
870 870
871config RTC_DRV_MPC5121
872 tristate "Freescale MPC5121 built-in RTC"
873 depends on PPC_MPC512x && RTC_CLASS
874 help
875 If you say yes here you will get support for the
876 built-in RTC MPC5121.
877
878 This driver can also be built as a module. If so, the module
879 will be called rtc-mpc5121.
880
871endif # RTC_CLASS 881endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index e5160fddc446..b7148afb8f55 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o
55obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 55obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
56obj-$(CONFIG_RTC_DRV_MC13783) += rtc-mc13783.o 56obj-$(CONFIG_RTC_DRV_MC13783) += rtc-mc13783.o
57obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o 57obj-$(CONFIG_RTC_DRV_MSM6242) += rtc-msm6242.o
58obj-$(CONFIG_RTC_DRV_MPC5121) += rtc-mpc5121.o
58obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o 59obj-$(CONFIG_RTC_DRV_MV) += rtc-mv.o
59obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o 60obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o
60obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o 61obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
new file mode 100644
index 000000000000..4313ca03a96d
--- /dev/null
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -0,0 +1,387 @@
1/*
2 * Real-time clock driver for MPC5121
3 *
4 * Copyright 2007, Domen Puncer <domen.puncer@telargo.com>
5 * Copyright 2008, Freescale Semiconductor, Inc. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/rtc.h>
15#include <linux/of_device.h>
16#include <linux/of_platform.h>
17#include <linux/io.h>
18
19struct mpc5121_rtc_regs {
20 u8 set_time; /* RTC + 0x00 */
21 u8 hour_set; /* RTC + 0x01 */
22 u8 minute_set; /* RTC + 0x02 */
23 u8 second_set; /* RTC + 0x03 */
24
25 u8 set_date; /* RTC + 0x04 */
26 u8 month_set; /* RTC + 0x05 */
27 u8 weekday_set; /* RTC + 0x06 */
28 u8 date_set; /* RTC + 0x07 */
29
30 u8 write_sw; /* RTC + 0x08 */
31 u8 sw_set; /* RTC + 0x09 */
32 u16 year_set; /* RTC + 0x0a */
33
34 u8 alm_enable; /* RTC + 0x0c */
35 u8 alm_hour_set; /* RTC + 0x0d */
36 u8 alm_min_set; /* RTC + 0x0e */
37 u8 int_enable; /* RTC + 0x0f */
38
39 u8 reserved1;
40 u8 hour; /* RTC + 0x11 */
41 u8 minute; /* RTC + 0x12 */
42 u8 second; /* RTC + 0x13 */
43
44 u8 month; /* RTC + 0x14 */
45 u8 wday_mday; /* RTC + 0x15 */
46 u16 year; /* RTC + 0x16 */
47
48 u8 int_alm; /* RTC + 0x18 */
49 u8 int_sw; /* RTC + 0x19 */
50 u8 alm_status; /* RTC + 0x1a */
51 u8 sw_minute; /* RTC + 0x1b */
52
53 u8 bus_error_1; /* RTC + 0x1c */
54 u8 int_day; /* RTC + 0x1d */
55 u8 int_min; /* RTC + 0x1e */
56 u8 int_sec; /* RTC + 0x1f */
57
58 /*
59 * target_time:
60 * intended to be used for hibernation but hibernation
61 * does not work on silicon rev 1.5 so use it for non-volatile
62 * storage of offset between the actual_time register and linux
63 * time
64 */
65 u32 target_time; /* RTC + 0x20 */
66 /*
67 * actual_time:
68 * readonly time since VBAT_RTC was last connected
69 */
70 u32 actual_time; /* RTC + 0x24 */
71 u32 keep_alive; /* RTC + 0x28 */
72};
73
74struct mpc5121_rtc_data {
75 unsigned irq;
76 unsigned irq_periodic;
77 struct mpc5121_rtc_regs __iomem *regs;
78 struct rtc_device *rtc;
79 struct rtc_wkalrm wkalarm;
80};
81
82/*
83 * Update second/minute/hour registers.
84 *
85 * This is just so alarm will work.
86 */
87static void mpc5121_rtc_update_smh(struct mpc5121_rtc_regs __iomem *regs,
88 struct rtc_time *tm)
89{
90 out_8(&regs->second_set, tm->tm_sec);
91 out_8(&regs->minute_set, tm->tm_min);
92 out_8(&regs->hour_set, tm->tm_hour);
93
94 /* set time sequence */
95 out_8(&regs->set_time, 0x1);
96 out_8(&regs->set_time, 0x3);
97 out_8(&regs->set_time, 0x1);
98 out_8(&regs->set_time, 0x0);
99}
100
101static int mpc5121_rtc_read_time(struct device *dev, struct rtc_time *tm)
102{
103 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
104 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
105 unsigned long now;
106
107 /*
108 * linux time is actual_time plus the offset saved in target_time
109 */
110 now = in_be32(&regs->actual_time) + in_be32(&regs->target_time);
111
112 rtc_time_to_tm(now, tm);
113
114 /*
115 * update second minute hour registers
116 * so alarms will work
117 */
118 mpc5121_rtc_update_smh(regs, tm);
119
120 return rtc_valid_tm(tm);
121}
122
123static int mpc5121_rtc_set_time(struct device *dev, struct rtc_time *tm)
124{
125 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
126 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
127 int ret;
128 unsigned long now;
129
130 /*
131 * The actual_time register is read only so we write the offset
132 * between it and linux time to the target_time register.
133 */
134 ret = rtc_tm_to_time(tm, &now);
135 if (ret == 0)
136 out_be32(&regs->target_time, now - in_be32(&regs->actual_time));
137
138 /*
139 * update second minute hour registers
140 * so alarms will work
141 */
142 mpc5121_rtc_update_smh(regs, tm);
143
144 return 0;
145}
146
147static int mpc5121_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
148{
149 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
150 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
151
152 *alarm = rtc->wkalarm;
153
154 alarm->pending = in_8(&regs->alm_status);
155
156 return 0;
157}
158
159static int mpc5121_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
160{
161 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
162 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
163
164 /*
165 * the alarm has no seconds so deal with it
166 */
167 if (alarm->time.tm_sec) {
168 alarm->time.tm_sec = 0;
169 alarm->time.tm_min++;
170 if (alarm->time.tm_min >= 60) {
171 alarm->time.tm_min = 0;
172 alarm->time.tm_hour++;
173 if (alarm->time.tm_hour >= 24)
174 alarm->time.tm_hour = 0;
175 }
176 }
177
178 alarm->time.tm_mday = -1;
179 alarm->time.tm_mon = -1;
180 alarm->time.tm_year = -1;
181
182 out_8(&regs->alm_min_set, alarm->time.tm_min);
183 out_8(&regs->alm_hour_set, alarm->time.tm_hour);
184
185 out_8(&regs->alm_enable, alarm->enabled);
186
187 rtc->wkalarm = *alarm;
188 return 0;
189}
190
191static irqreturn_t mpc5121_rtc_handler(int irq, void *dev)
192{
193 struct mpc5121_rtc_data *rtc = dev_get_drvdata((struct device *)dev);
194 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
195
196 if (in_8(&regs->int_alm)) {
197 /* acknowledge and clear status */
198 out_8(&regs->int_alm, 1);
199 out_8(&regs->alm_status, 1);
200
201 rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_AF);
202 return IRQ_HANDLED;
203 }
204
205 return IRQ_NONE;
206}
207
208static irqreturn_t mpc5121_rtc_handler_upd(int irq, void *dev)
209{
210 struct mpc5121_rtc_data *rtc = dev_get_drvdata((struct device *)dev);
211 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
212
213 if (in_8(&regs->int_sec) && (in_8(&regs->int_enable) & 0x1)) {
214 /* acknowledge */
215 out_8(&regs->int_sec, 1);
216
217 rtc_update_irq(rtc->rtc, 1, RTC_IRQF | RTC_UF);
218 return IRQ_HANDLED;
219 }
220
221 return IRQ_NONE;
222}
223
224static int mpc5121_rtc_alarm_irq_enable(struct device *dev,
225 unsigned int enabled)
226{
227 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
228 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
229 int val;
230
231 if (enabled)
232 val = 1;
233 else
234 val = 0;
235
236 out_8(&regs->alm_enable, val);
237 rtc->wkalarm.enabled = val;
238
239 return 0;
240}
241
242static int mpc5121_rtc_update_irq_enable(struct device *dev,
243 unsigned int enabled)
244{
245 struct mpc5121_rtc_data *rtc = dev_get_drvdata(dev);
246 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
247 int val;
248
249 val = in_8(&regs->int_enable);
250
251 if (enabled)
252 val = (val & ~0x8) | 0x1;
253 else
254 val &= ~0x1;
255
256 out_8(&regs->int_enable, val);
257
258 return 0;
259}
260
261static const struct rtc_class_ops mpc5121_rtc_ops = {
262 .read_time = mpc5121_rtc_read_time,
263 .set_time = mpc5121_rtc_set_time,
264 .read_alarm = mpc5121_rtc_read_alarm,
265 .set_alarm = mpc5121_rtc_set_alarm,
266 .alarm_irq_enable = mpc5121_rtc_alarm_irq_enable,
267 .update_irq_enable = mpc5121_rtc_update_irq_enable,
268};
269
270static int __devinit mpc5121_rtc_probe(struct of_device *op,
271 const struct of_device_id *match)
272{
273 struct mpc5121_rtc_data *rtc;
274 int err = 0;
275 u32 ka;
276
277 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
278 if (!rtc)
279 return -ENOMEM;
280
281 rtc->regs = of_iomap(op->node, 0);
282 if (!rtc->regs) {
283 dev_err(&op->dev, "%s: couldn't map io space\n", __func__);
284 err = -ENOSYS;
285 goto out_free;
286 }
287
288 device_init_wakeup(&op->dev, 1);
289
290 dev_set_drvdata(&op->dev, rtc);
291
292 rtc->irq = irq_of_parse_and_map(op->node, 1);
293 err = request_irq(rtc->irq, mpc5121_rtc_handler, IRQF_DISABLED,
294 "mpc5121-rtc", &op->dev);
295 if (err) {
296 dev_err(&op->dev, "%s: could not request irq: %i\n",
297 __func__, rtc->irq);
298 goto out_dispose;
299 }
300
301 rtc->irq_periodic = irq_of_parse_and_map(op->node, 0);
302 err = request_irq(rtc->irq_periodic, mpc5121_rtc_handler_upd,
303 IRQF_DISABLED, "mpc5121-rtc_upd", &op->dev);
304 if (err) {
305 dev_err(&op->dev, "%s: could not request irq: %i\n",
306 __func__, rtc->irq_periodic);
307 goto out_dispose2;
308 }
309
310 ka = in_be32(&rtc->regs->keep_alive);
311 if (ka & 0x02) {
312 dev_warn(&op->dev,
313 "mpc5121-rtc: Battery or oscillator failure!\n");
314 out_be32(&rtc->regs->keep_alive, ka);
315 }
316
317 rtc->rtc = rtc_device_register("mpc5121-rtc", &op->dev,
318 &mpc5121_rtc_ops, THIS_MODULE);
319 if (IS_ERR(rtc->rtc)) {
320 err = PTR_ERR(rtc->rtc);
321 goto out_free_irq;
322 }
323
324 return 0;
325
326out_free_irq:
327 free_irq(rtc->irq_periodic, &op->dev);
328out_dispose2:
329 irq_dispose_mapping(rtc->irq_periodic);
330 free_irq(rtc->irq, &op->dev);
331out_dispose:
332 irq_dispose_mapping(rtc->irq);
333 iounmap(rtc->regs);
334out_free:
335 kfree(rtc);
336
337 return err;
338}
339
340static int __devexit mpc5121_rtc_remove(struct of_device *op)
341{
342 struct mpc5121_rtc_data *rtc = dev_get_drvdata(&op->dev);
343 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
344
345 /* disable interrupt, so there are no nasty surprises */
346 out_8(&regs->alm_enable, 0);
347 out_8(&regs->int_enable, in_8(&regs->int_enable) & ~0x1);
348
349 rtc_device_unregister(rtc->rtc);
350 iounmap(rtc->regs);
351 free_irq(rtc->irq, &op->dev);
352 free_irq(rtc->irq_periodic, &op->dev);
353 irq_dispose_mapping(rtc->irq);
354 irq_dispose_mapping(rtc->irq_periodic);
355 dev_set_drvdata(&op->dev, NULL);
356 kfree(rtc);
357
358 return 0;
359}
360
361static struct of_device_id mpc5121_rtc_match[] __devinitdata = {
362 { .compatible = "fsl,mpc5121-rtc", },
363 {},
364};
365
366static struct of_platform_driver mpc5121_rtc_driver = {
367 .owner = THIS_MODULE,
368 .name = "mpc5121-rtc",
369 .match_table = mpc5121_rtc_match,
370 .probe = mpc5121_rtc_probe,
371 .remove = __devexit_p(mpc5121_rtc_remove),
372};
373
374static int __init mpc5121_rtc_init(void)
375{
376 return of_register_platform_driver(&mpc5121_rtc_driver);
377}
378module_init(mpc5121_rtc_init);
379
380static void __exit mpc5121_rtc_exit(void)
381{
382 of_unregister_platform_driver(&mpc5121_rtc_driver);
383}
384module_exit(mpc5121_rtc_exit);
385
386MODULE_LICENSE("GPL");
387MODULE_AUTHOR("John Rigby <jcrigby@gmail.com>");
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 5905936c7c60..9ab1ae40565f 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -20,6 +20,7 @@
20#include <linux/buffer_head.h> 20#include <linux/buffer_head.h>
21#include <linux/hdreg.h> 21#include <linux/hdreg.h>
22#include <linux/async.h> 22#include <linux/async.h>
23#include <linux/mutex.h>
23 24
24#include <asm/ccwdev.h> 25#include <asm/ccwdev.h>
25#include <asm/ebcdic.h> 26#include <asm/ebcdic.h>
@@ -112,6 +113,7 @@ struct dasd_device *dasd_alloc_device(void)
112 INIT_WORK(&device->restore_device, do_restore_device); 113 INIT_WORK(&device->restore_device, do_restore_device);
113 device->state = DASD_STATE_NEW; 114 device->state = DASD_STATE_NEW;
114 device->target = DASD_STATE_NEW; 115 device->target = DASD_STATE_NEW;
116 mutex_init(&device->state_mutex);
115 117
116 return device; 118 return device;
117} 119}
@@ -321,8 +323,8 @@ static int dasd_state_ready_to_basic(struct dasd_device *device)
321 device->state = DASD_STATE_READY; 323 device->state = DASD_STATE_READY;
322 return rc; 324 return rc;
323 } 325 }
324 dasd_destroy_partitions(block);
325 dasd_flush_request_queue(block); 326 dasd_flush_request_queue(block);
327 dasd_destroy_partitions(block);
326 block->blocks = 0; 328 block->blocks = 0;
327 block->bp_block = 0; 329 block->bp_block = 0;
328 block->s2b_shift = 0; 330 block->s2b_shift = 0;
@@ -484,10 +486,8 @@ static void dasd_change_state(struct dasd_device *device)
484 if (rc) 486 if (rc)
485 device->target = device->state; 487 device->target = device->state;
486 488
487 if (device->state == device->target) { 489 if (device->state == device->target)
488 wake_up(&dasd_init_waitq); 490 wake_up(&dasd_init_waitq);
489 dasd_put_device(device);
490 }
491 491
492 /* let user-space know that the device status changed */ 492 /* let user-space know that the device status changed */
493 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE); 493 kobject_uevent(&device->cdev->dev.kobj, KOBJ_CHANGE);
@@ -502,7 +502,9 @@ static void dasd_change_state(struct dasd_device *device)
502static void do_kick_device(struct work_struct *work) 502static void do_kick_device(struct work_struct *work)
503{ 503{
504 struct dasd_device *device = container_of(work, struct dasd_device, kick_work); 504 struct dasd_device *device = container_of(work, struct dasd_device, kick_work);
505 mutex_lock(&device->state_mutex);
505 dasd_change_state(device); 506 dasd_change_state(device);
507 mutex_unlock(&device->state_mutex);
506 dasd_schedule_device_bh(device); 508 dasd_schedule_device_bh(device);
507 dasd_put_device(device); 509 dasd_put_device(device);
508} 510}
@@ -539,18 +541,19 @@ void dasd_restore_device(struct dasd_device *device)
539void dasd_set_target_state(struct dasd_device *device, int target) 541void dasd_set_target_state(struct dasd_device *device, int target)
540{ 542{
541 dasd_get_device(device); 543 dasd_get_device(device);
544 mutex_lock(&device->state_mutex);
542 /* If we are in probeonly mode stop at DASD_STATE_READY. */ 545 /* If we are in probeonly mode stop at DASD_STATE_READY. */
543 if (dasd_probeonly && target > DASD_STATE_READY) 546 if (dasd_probeonly && target > DASD_STATE_READY)
544 target = DASD_STATE_READY; 547 target = DASD_STATE_READY;
545 if (device->target != target) { 548 if (device->target != target) {
546 if (device->state == target) { 549 if (device->state == target)
547 wake_up(&dasd_init_waitq); 550 wake_up(&dasd_init_waitq);
548 dasd_put_device(device);
549 }
550 device->target = target; 551 device->target = target;
551 } 552 }
552 if (device->state != device->target) 553 if (device->state != device->target)
553 dasd_change_state(device); 554 dasd_change_state(device);
555 mutex_unlock(&device->state_mutex);
556 dasd_put_device(device);
554} 557}
555 558
556/* 559/*
@@ -1000,12 +1003,20 @@ static void dasd_handle_killed_request(struct ccw_device *cdev,
1000 return; 1003 return;
1001 } 1004 }
1002 1005
1003 device = (struct dasd_device *) cqr->startdev; 1006 device = dasd_device_from_cdev_locked(cdev);
1004 if (device == NULL || 1007 if (IS_ERR(device)) {
1005 device != dasd_device_from_cdev_locked(cdev) || 1008 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1006 strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { 1009 "unable to get device from cdev");
1010 return;
1011 }
1012
1013 if (!cqr->startdev ||
1014 device != cqr->startdev ||
1015 strncmp(cqr->startdev->discipline->ebcname,
1016 (char *) &cqr->magic, 4)) {
1007 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s", 1017 DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
1008 "invalid device in request"); 1018 "invalid device in request");
1019 dasd_put_device(device);
1009 return; 1020 return;
1010 } 1021 }
1011 1022
@@ -1692,7 +1703,6 @@ int dasd_cancel_req(struct dasd_ccw_req *cqr)
1692 cqr, rc); 1703 cqr, rc);
1693 } else { 1704 } else {
1694 cqr->stopclk = get_clock(); 1705 cqr->stopclk = get_clock();
1695 rc = 1;
1696 } 1706 }
1697 break; 1707 break;
1698 default: /* already finished or clear pending - do nothing */ 1708 default: /* already finished or clear pending - do nothing */
@@ -2170,9 +2180,13 @@ static void dasd_flush_request_queue(struct dasd_block *block)
2170static int dasd_open(struct block_device *bdev, fmode_t mode) 2180static int dasd_open(struct block_device *bdev, fmode_t mode)
2171{ 2181{
2172 struct dasd_block *block = bdev->bd_disk->private_data; 2182 struct dasd_block *block = bdev->bd_disk->private_data;
2173 struct dasd_device *base = block->base; 2183 struct dasd_device *base;
2174 int rc; 2184 int rc;
2175 2185
2186 if (!block)
2187 return -ENODEV;
2188
2189 base = block->base;
2176 atomic_inc(&block->open_count); 2190 atomic_inc(&block->open_count);
2177 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) { 2191 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
2178 rc = -ENODEV; 2192 rc = -ENODEV;
@@ -2285,11 +2299,6 @@ static void dasd_generic_auto_online(void *data, async_cookie_t cookie)
2285 if (ret) 2299 if (ret)
2286 pr_warning("%s: Setting the DASD online failed with rc=%d\n", 2300 pr_warning("%s: Setting the DASD online failed with rc=%d\n",
2287 dev_name(&cdev->dev), ret); 2301 dev_name(&cdev->dev), ret);
2288 else {
2289 struct dasd_device *device = dasd_device_from_cdev(cdev);
2290 wait_event(dasd_init_waitq, _wait_for_device(device));
2291 dasd_put_device(device);
2292 }
2293} 2302}
2294 2303
2295/* 2304/*
@@ -2424,6 +2433,9 @@ int dasd_generic_set_online(struct ccw_device *cdev,
2424 } else 2433 } else
2425 pr_debug("dasd_generic device %s found\n", 2434 pr_debug("dasd_generic device %s found\n",
2426 dev_name(&cdev->dev)); 2435 dev_name(&cdev->dev));
2436
2437 wait_event(dasd_init_waitq, _wait_for_device(device));
2438
2427 dasd_put_device(device); 2439 dasd_put_device(device);
2428 return rc; 2440 return rc;
2429} 2441}
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index 4cac5b54f26a..d49766f3b940 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -874,12 +874,19 @@ dasd_discipline_show(struct device *dev, struct device_attribute *attr,
874 ssize_t len; 874 ssize_t len;
875 875
876 device = dasd_device_from_cdev(to_ccwdev(dev)); 876 device = dasd_device_from_cdev(to_ccwdev(dev));
877 if (!IS_ERR(device) && device->discipline) { 877 if (IS_ERR(device))
878 goto out;
879 else if (!device->discipline) {
880 dasd_put_device(device);
881 goto out;
882 } else {
878 len = snprintf(buf, PAGE_SIZE, "%s\n", 883 len = snprintf(buf, PAGE_SIZE, "%s\n",
879 device->discipline->name); 884 device->discipline->name);
880 dasd_put_device(device); 885 dasd_put_device(device);
881 } else 886 return len;
882 len = snprintf(buf, PAGE_SIZE, "none\n"); 887 }
888out:
889 len = snprintf(buf, PAGE_SIZE, "none\n");
883 return len; 890 return len;
884} 891}
885 892
diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c
index d3198303b93c..94f92a1247f2 100644
--- a/drivers/s390/block/dasd_genhd.c
+++ b/drivers/s390/block/dasd_genhd.c
@@ -88,6 +88,7 @@ void dasd_gendisk_free(struct dasd_block *block)
88 if (block->gdp) { 88 if (block->gdp) {
89 del_gendisk(block->gdp); 89 del_gendisk(block->gdp);
90 block->gdp->queue = NULL; 90 block->gdp->queue = NULL;
91 block->gdp->private_data = NULL;
91 put_disk(block->gdp); 92 put_disk(block->gdp);
92 block->gdp = NULL; 93 block->gdp = NULL;
93 } 94 }
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index e4c2143dabf6..ed73ce550822 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -368,6 +368,7 @@ struct dasd_device {
368 368
369 /* Device state and target state. */ 369 /* Device state and target state. */
370 int state, target; 370 int state, target;
371 struct mutex state_mutex;
371 int stopped; /* device (ccw_device_start) was stopped */ 372 int stopped; /* device (ccw_device_start) was stopped */
372 373
373 /* reference count. */ 374 /* reference count. */
diff --git a/drivers/s390/block/dasd_proc.c b/drivers/s390/block/dasd_proc.c
index 71f95f54866f..f13a0bdd148c 100644
--- a/drivers/s390/block/dasd_proc.c
+++ b/drivers/s390/block/dasd_proc.c
@@ -165,51 +165,32 @@ static const struct file_operations dasd_devices_file_ops = {
165 .release = seq_release, 165 .release = seq_release,
166}; 166};
167 167
168static int
169dasd_calc_metrics(char *page, char **start, off_t off,
170 int count, int *eof, int len)
171{
172 len = (len > off) ? len - off : 0;
173 if (len > count)
174 len = count;
175 if (len < count)
176 *eof = 1;
177 *start = page + off;
178 return len;
179}
180
181#ifdef CONFIG_DASD_PROFILE 168#ifdef CONFIG_DASD_PROFILE
182static char * 169static void dasd_statistics_array(struct seq_file *m, unsigned int *array, int factor)
183dasd_statistics_array(char *str, unsigned int *array, int factor)
184{ 170{
185 int i; 171 int i;
186 172
187 for (i = 0; i < 32; i++) { 173 for (i = 0; i < 32; i++) {
188 str += sprintf(str, "%7d ", array[i] / factor); 174 seq_printf(m, "%7d ", array[i] / factor);
189 if (i == 15) 175 if (i == 15)
190 str += sprintf(str, "\n"); 176 seq_putc(m, '\n');
191 } 177 }
192 str += sprintf(str,"\n"); 178 seq_putc(m, '\n');
193 return str;
194} 179}
195#endif /* CONFIG_DASD_PROFILE */ 180#endif /* CONFIG_DASD_PROFILE */
196 181
197static int 182static int dasd_stats_proc_show(struct seq_file *m, void *v)
198dasd_statistics_read(char *page, char **start, off_t off,
199 int count, int *eof, void *data)
200{ 183{
201 unsigned long len;
202#ifdef CONFIG_DASD_PROFILE 184#ifdef CONFIG_DASD_PROFILE
203 struct dasd_profile_info_t *prof; 185 struct dasd_profile_info_t *prof;
204 char *str;
205 int factor; 186 int factor;
206 187
207 /* check for active profiling */ 188 /* check for active profiling */
208 if (dasd_profile_level == DASD_PROFILE_OFF) { 189 if (dasd_profile_level == DASD_PROFILE_OFF) {
209 len = sprintf(page, "Statistics are off - they might be " 190 seq_printf(m, "Statistics are off - they might be "
210 "switched on using 'echo set on > " 191 "switched on using 'echo set on > "
211 "/proc/dasd/statistics'\n"); 192 "/proc/dasd/statistics'\n");
212 return dasd_calc_metrics(page, start, off, count, eof, len); 193 return 0;
213 } 194 }
214 195
215 prof = &dasd_global_profile; 196 prof = &dasd_global_profile;
@@ -217,47 +198,49 @@ dasd_statistics_read(char *page, char **start, off_t off,
217 for (factor = 1; (prof->dasd_io_reqs / factor) > 9999999; 198 for (factor = 1; (prof->dasd_io_reqs / factor) > 9999999;
218 factor *= 10); 199 factor *= 10);
219 200
220 str = page; 201 seq_printf(m, "%d dasd I/O requests\n", prof->dasd_io_reqs);
221 str += sprintf(str, "%d dasd I/O requests\n", prof->dasd_io_reqs); 202 seq_printf(m, "with %u sectors(512B each)\n",
222 str += sprintf(str, "with %u sectors(512B each)\n",
223 prof->dasd_io_sects); 203 prof->dasd_io_sects);
224 str += sprintf(str, "Scale Factor is %d\n", factor); 204 seq_printf(m, "Scale Factor is %d\n", factor);
225 str += sprintf(str, 205 seq_printf(m,
226 " __<4 ___8 __16 __32 __64 _128 " 206 " __<4 ___8 __16 __32 __64 _128 "
227 " _256 _512 __1k __2k __4k __8k " 207 " _256 _512 __1k __2k __4k __8k "
228 " _16k _32k _64k 128k\n"); 208 " _16k _32k _64k 128k\n");
229 str += sprintf(str, 209 seq_printf(m,
230 " _256 _512 __1M __2M __4M __8M " 210 " _256 _512 __1M __2M __4M __8M "
231 " _16M _32M _64M 128M 256M 512M " 211 " _16M _32M _64M 128M 256M 512M "
232 " __1G __2G __4G " " _>4G\n"); 212 " __1G __2G __4G " " _>4G\n");
233 213
234 str += sprintf(str, "Histogram of sizes (512B secs)\n"); 214 seq_printf(m, "Histogram of sizes (512B secs)\n");
235 str = dasd_statistics_array(str, prof->dasd_io_secs, factor); 215 dasd_statistics_array(m, prof->dasd_io_secs, factor);
236 str += sprintf(str, "Histogram of I/O times (microseconds)\n"); 216 seq_printf(m, "Histogram of I/O times (microseconds)\n");
237 str = dasd_statistics_array(str, prof->dasd_io_times, factor); 217 dasd_statistics_array(m, prof->dasd_io_times, factor);
238 str += sprintf(str, "Histogram of I/O times per sector\n"); 218 seq_printf(m, "Histogram of I/O times per sector\n");
239 str = dasd_statistics_array(str, prof->dasd_io_timps, factor); 219 dasd_statistics_array(m, prof->dasd_io_timps, factor);
240 str += sprintf(str, "Histogram of I/O time till ssch\n"); 220 seq_printf(m, "Histogram of I/O time till ssch\n");
241 str = dasd_statistics_array(str, prof->dasd_io_time1, factor); 221 dasd_statistics_array(m, prof->dasd_io_time1, factor);
242 str += sprintf(str, "Histogram of I/O time between ssch and irq\n"); 222 seq_printf(m, "Histogram of I/O time between ssch and irq\n");
243 str = dasd_statistics_array(str, prof->dasd_io_time2, factor); 223 dasd_statistics_array(m, prof->dasd_io_time2, factor);
244 str += sprintf(str, "Histogram of I/O time between ssch " 224 seq_printf(m, "Histogram of I/O time between ssch "
245 "and irq per sector\n"); 225 "and irq per sector\n");
246 str = dasd_statistics_array(str, prof->dasd_io_time2ps, factor); 226 dasd_statistics_array(m, prof->dasd_io_time2ps, factor);
247 str += sprintf(str, "Histogram of I/O time between irq and end\n"); 227 seq_printf(m, "Histogram of I/O time between irq and end\n");
248 str = dasd_statistics_array(str, prof->dasd_io_time3, factor); 228 dasd_statistics_array(m, prof->dasd_io_time3, factor);
249 str += sprintf(str, "# of req in chanq at enqueuing (1..32) \n"); 229 seq_printf(m, "# of req in chanq at enqueuing (1..32) \n");
250 str = dasd_statistics_array(str, prof->dasd_io_nr_req, factor); 230 dasd_statistics_array(m, prof->dasd_io_nr_req, factor);
251 len = str - page;
252#else 231#else
253 len = sprintf(page, "Statistics are not activated in this kernel\n"); 232 seq_printf(m, "Statistics are not activated in this kernel\n");
254#endif 233#endif
255 return dasd_calc_metrics(page, start, off, count, eof, len); 234 return 0;
256} 235}
257 236
258static int 237static int dasd_stats_proc_open(struct inode *inode, struct file *file)
259dasd_statistics_write(struct file *file, const char __user *user_buf, 238{
260 unsigned long user_len, void *data) 239 return single_open(file, dasd_stats_proc_show, NULL);
240}
241
242static ssize_t dasd_stats_proc_write(struct file *file,
243 const char __user *user_buf, size_t user_len, loff_t *pos)
261{ 244{
262#ifdef CONFIG_DASD_PROFILE 245#ifdef CONFIG_DASD_PROFILE
263 char *buffer, *str; 246 char *buffer, *str;
@@ -308,6 +291,15 @@ out_error:
308#endif /* CONFIG_DASD_PROFILE */ 291#endif /* CONFIG_DASD_PROFILE */
309} 292}
310 293
294static const struct file_operations dasd_stats_proc_fops = {
295 .owner = THIS_MODULE,
296 .open = dasd_stats_proc_open,
297 .read = seq_read,
298 .llseek = seq_lseek,
299 .release = single_release,
300 .write = dasd_stats_proc_write,
301};
302
311/* 303/*
312 * Create dasd proc-fs entries. 304 * Create dasd proc-fs entries.
313 * In case creation failed, cleanup and return -ENOENT. 305 * In case creation failed, cleanup and return -ENOENT.
@@ -324,13 +316,12 @@ dasd_proc_init(void)
324 &dasd_devices_file_ops); 316 &dasd_devices_file_ops);
325 if (!dasd_devices_entry) 317 if (!dasd_devices_entry)
326 goto out_nodevices; 318 goto out_nodevices;
327 dasd_statistics_entry = create_proc_entry("statistics", 319 dasd_statistics_entry = proc_create("statistics",
328 S_IFREG | S_IRUGO | S_IWUSR, 320 S_IFREG | S_IRUGO | S_IWUSR,
329 dasd_proc_root_entry); 321 dasd_proc_root_entry,
322 &dasd_stats_proc_fops);
330 if (!dasd_statistics_entry) 323 if (!dasd_statistics_entry)
331 goto out_nostatistics; 324 goto out_nostatistics;
332 dasd_statistics_entry->read_proc = dasd_statistics_read;
333 dasd_statistics_entry->write_proc = dasd_statistics_write;
334 return 0; 325 return 0;
335 326
336 out_nostatistics: 327 out_nostatistics:
diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c
index 82daa3c1dc9c..3438658b66b7 100644
--- a/drivers/s390/char/zcore.c
+++ b/drivers/s390/char/zcore.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/miscdevice.h> 16#include <linux/miscdevice.h>
17#include <linux/debugfs.h> 17#include <linux/debugfs.h>
18#include <asm/asm-offsets.h>
18#include <asm/ipl.h> 19#include <asm/ipl.h>
19#include <asm/sclp.h> 20#include <asm/sclp.h>
20#include <asm/setup.h> 21#include <asm/setup.h>
@@ -40,12 +41,12 @@ enum arch_id {
40/* dump system info */ 41/* dump system info */
41 42
42struct sys_info { 43struct sys_info {
43 enum arch_id arch; 44 enum arch_id arch;
44 unsigned long sa_base; 45 unsigned long sa_base;
45 u32 sa_size; 46 u32 sa_size;
46 int cpu_map[NR_CPUS]; 47 int cpu_map[NR_CPUS];
47 unsigned long mem_size; 48 unsigned long mem_size;
48 union save_area lc_mask; 49 struct save_area lc_mask;
49}; 50};
50 51
51struct ipib_info { 52struct ipib_info {
@@ -183,52 +184,9 @@ static int memcpy_real_user(void __user *dest, unsigned long src, size_t count)
183 return 0; 184 return 0;
184} 185}
185 186
186#ifdef __s390x__
187/*
188 * Convert s390x (64 bit) cpu info to s390 (32 bit) cpu info
189 */
190static void __init s390x_to_s390_regs(union save_area *out, union save_area *in,
191 int cpu)
192{
193 int i;
194
195 for (i = 0; i < 16; i++) {
196 out->s390.gp_regs[i] = in->s390x.gp_regs[i] & 0x00000000ffffffff;
197 out->s390.acc_regs[i] = in->s390x.acc_regs[i];
198 out->s390.ctrl_regs[i] =
199 in->s390x.ctrl_regs[i] & 0x00000000ffffffff;
200 }
201 /* locore for 31 bit has only space for fpregs 0,2,4,6 */
202 out->s390.fp_regs[0] = in->s390x.fp_regs[0];
203 out->s390.fp_regs[1] = in->s390x.fp_regs[2];
204 out->s390.fp_regs[2] = in->s390x.fp_regs[4];
205 out->s390.fp_regs[3] = in->s390x.fp_regs[6];
206 memcpy(&(out->s390.psw[0]), &(in->s390x.psw[0]), 4);
207 out->s390.psw[1] |= 0x8; /* set bit 12 */
208 memcpy(&(out->s390.psw[4]),&(in->s390x.psw[12]), 4);
209 out->s390.psw[4] |= 0x80; /* set (31bit) addressing bit */
210 out->s390.pref_reg = in->s390x.pref_reg;
211 out->s390.timer = in->s390x.timer;
212 out->s390.clk_cmp = in->s390x.clk_cmp;
213}
214
215static void __init s390x_to_s390_save_areas(void)
216{
217 int i = 1;
218 static union save_area tmp;
219
220 while (zfcpdump_save_areas[i]) {
221 s390x_to_s390_regs(&tmp, zfcpdump_save_areas[i], i);
222 memcpy(zfcpdump_save_areas[i], &tmp, sizeof(tmp));
223 i++;
224 }
225}
226
227#endif /* __s390x__ */
228
229static int __init init_cpu_info(enum arch_id arch) 187static int __init init_cpu_info(enum arch_id arch)
230{ 188{
231 union save_area *sa; 189 struct save_area *sa;
232 190
233 /* get info for boot cpu from lowcore, stored in the HSA */ 191 /* get info for boot cpu from lowcore, stored in the HSA */
234 192
@@ -241,20 +199,12 @@ static int __init init_cpu_info(enum arch_id arch)
241 return -EIO; 199 return -EIO;
242 } 200 }
243 zfcpdump_save_areas[0] = sa; 201 zfcpdump_save_areas[0] = sa;
244
245#ifdef __s390x__
246 /* convert s390x regs to s390, if we are dumping an s390 Linux */
247
248 if (arch == ARCH_S390)
249 s390x_to_s390_save_areas();
250#endif
251
252 return 0; 202 return 0;
253} 203}
254 204
255static DEFINE_MUTEX(zcore_mutex); 205static DEFINE_MUTEX(zcore_mutex);
256 206
257#define DUMP_VERSION 0x3 207#define DUMP_VERSION 0x5
258#define DUMP_MAGIC 0xa8190173618f23fdULL 208#define DUMP_MAGIC 0xa8190173618f23fdULL
259#define DUMP_ARCH_S390X 2 209#define DUMP_ARCH_S390X 2
260#define DUMP_ARCH_S390 1 210#define DUMP_ARCH_S390 1
@@ -279,7 +229,14 @@ struct zcore_header {
279 u32 volnr; 229 u32 volnr;
280 u32 build_arch; 230 u32 build_arch;
281 u64 rmem_size; 231 u64 rmem_size;
282 char pad2[4016]; 232 u8 mvdump;
233 u16 cpu_cnt;
234 u16 real_cpu_cnt;
235 u8 end_pad1[0x200-0x061];
236 u64 mvdump_sign;
237 u64 mvdump_zipl_time;
238 u8 end_pad2[0x800-0x210];
239 u32 lc_vec[512];
283} __attribute__((packed,__aligned__(16))); 240} __attribute__((packed,__aligned__(16)));
284 241
285static struct zcore_header zcore_header = { 242static struct zcore_header zcore_header = {
@@ -289,7 +246,7 @@ static struct zcore_header zcore_header = {
289 .dump_level = 0, 246 .dump_level = 0,
290 .page_size = PAGE_SIZE, 247 .page_size = PAGE_SIZE,
291 .mem_start = 0, 248 .mem_start = 0,
292#ifdef __s390x__ 249#ifdef CONFIG_64BIT
293 .build_arch = DUMP_ARCH_S390X, 250 .build_arch = DUMP_ARCH_S390X,
294#else 251#else
295 .build_arch = DUMP_ARCH_S390, 252 .build_arch = DUMP_ARCH_S390,
@@ -340,11 +297,7 @@ static int zcore_add_lc(char __user *buf, unsigned long start, size_t count)
340 unsigned long prefix; 297 unsigned long prefix;
341 unsigned long sa_off, len, buf_off; 298 unsigned long sa_off, len, buf_off;
342 299
343 if (sys_info.arch == ARCH_S390) 300 prefix = zfcpdump_save_areas[i]->pref_reg;
344 prefix = zfcpdump_save_areas[i]->s390.pref_reg;
345 else
346 prefix = zfcpdump_save_areas[i]->s390x.pref_reg;
347
348 sa_start = prefix + sys_info.sa_base; 301 sa_start = prefix + sys_info.sa_base;
349 sa_end = prefix + sys_info.sa_base + sys_info.sa_size; 302 sa_end = prefix + sys_info.sa_base + sys_info.sa_size;
350 303
@@ -561,34 +514,39 @@ static const struct file_operations zcore_reipl_fops = {
561 .release = zcore_reipl_release, 514 .release = zcore_reipl_release,
562}; 515};
563 516
517#ifdef CONFIG_32BIT
564 518
565static void __init set_s390_lc_mask(union save_area *map) 519static void __init set_lc_mask(struct save_area *map)
566{ 520{
567 memset(&map->s390.ext_save, 0xff, sizeof(map->s390.ext_save)); 521 memset(&map->ext_save, 0xff, sizeof(map->ext_save));
568 memset(&map->s390.timer, 0xff, sizeof(map->s390.timer)); 522 memset(&map->timer, 0xff, sizeof(map->timer));
569 memset(&map->s390.clk_cmp, 0xff, sizeof(map->s390.clk_cmp)); 523 memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
570 memset(&map->s390.psw, 0xff, sizeof(map->s390.psw)); 524 memset(&map->psw, 0xff, sizeof(map->psw));
571 memset(&map->s390.pref_reg, 0xff, sizeof(map->s390.pref_reg)); 525 memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
572 memset(&map->s390.acc_regs, 0xff, sizeof(map->s390.acc_regs)); 526 memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
573 memset(&map->s390.fp_regs, 0xff, sizeof(map->s390.fp_regs)); 527 memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
574 memset(&map->s390.gp_regs, 0xff, sizeof(map->s390.gp_regs)); 528 memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
575 memset(&map->s390.ctrl_regs, 0xff, sizeof(map->s390.ctrl_regs)); 529 memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
576} 530}
577 531
578static void __init set_s390x_lc_mask(union save_area *map) 532#else /* CONFIG_32BIT */
533
534static void __init set_lc_mask(struct save_area *map)
579{ 535{
580 memset(&map->s390x.fp_regs, 0xff, sizeof(map->s390x.fp_regs)); 536 memset(&map->fp_regs, 0xff, sizeof(map->fp_regs));
581 memset(&map->s390x.gp_regs, 0xff, sizeof(map->s390x.gp_regs)); 537 memset(&map->gp_regs, 0xff, sizeof(map->gp_regs));
582 memset(&map->s390x.psw, 0xff, sizeof(map->s390x.psw)); 538 memset(&map->psw, 0xff, sizeof(map->psw));
583 memset(&map->s390x.pref_reg, 0xff, sizeof(map->s390x.pref_reg)); 539 memset(&map->pref_reg, 0xff, sizeof(map->pref_reg));
584 memset(&map->s390x.fp_ctrl_reg, 0xff, sizeof(map->s390x.fp_ctrl_reg)); 540 memset(&map->fp_ctrl_reg, 0xff, sizeof(map->fp_ctrl_reg));
585 memset(&map->s390x.tod_reg, 0xff, sizeof(map->s390x.tod_reg)); 541 memset(&map->tod_reg, 0xff, sizeof(map->tod_reg));
586 memset(&map->s390x.timer, 0xff, sizeof(map->s390x.timer)); 542 memset(&map->timer, 0xff, sizeof(map->timer));
587 memset(&map->s390x.clk_cmp, 0xff, sizeof(map->s390x.clk_cmp)); 543 memset(&map->clk_cmp, 0xff, sizeof(map->clk_cmp));
588 memset(&map->s390x.acc_regs, 0xff, sizeof(map->s390x.acc_regs)); 544 memset(&map->acc_regs, 0xff, sizeof(map->acc_regs));
589 memset(&map->s390x.ctrl_regs, 0xff, sizeof(map->s390x.ctrl_regs)); 545 memset(&map->ctrl_regs, 0xff, sizeof(map->ctrl_regs));
590} 546}
591 547
548#endif /* CONFIG_32BIT */
549
592/* 550/*
593 * Initialize dump globals for a given architecture 551 * Initialize dump globals for a given architecture
594 */ 552 */
@@ -599,21 +557,18 @@ static int __init sys_info_init(enum arch_id arch)
599 switch (arch) { 557 switch (arch) {
600 case ARCH_S390X: 558 case ARCH_S390X:
601 pr_alert("DETECTED 'S390X (64 bit) OS'\n"); 559 pr_alert("DETECTED 'S390X (64 bit) OS'\n");
602 sys_info.sa_base = SAVE_AREA_BASE_S390X;
603 sys_info.sa_size = sizeof(struct save_area_s390x);
604 set_s390x_lc_mask(&sys_info.lc_mask);
605 break; 560 break;
606 case ARCH_S390: 561 case ARCH_S390:
607 pr_alert("DETECTED 'S390 (32 bit) OS'\n"); 562 pr_alert("DETECTED 'S390 (32 bit) OS'\n");
608 sys_info.sa_base = SAVE_AREA_BASE_S390;
609 sys_info.sa_size = sizeof(struct save_area_s390);
610 set_s390_lc_mask(&sys_info.lc_mask);
611 break; 563 break;
612 default: 564 default:
613 pr_alert("0x%x is an unknown architecture.\n",arch); 565 pr_alert("0x%x is an unknown architecture.\n",arch);
614 return -EINVAL; 566 return -EINVAL;
615 } 567 }
568 sys_info.sa_base = SAVE_AREA_BASE;
569 sys_info.sa_size = sizeof(struct save_area);
616 sys_info.arch = arch; 570 sys_info.arch = arch;
571 set_lc_mask(&sys_info.lc_mask);
617 rc = init_cpu_info(arch); 572 rc = init_cpu_info(arch);
618 if (rc) 573 if (rc)
619 return rc; 574 return rc;
@@ -660,8 +615,9 @@ static int __init get_mem_size(unsigned long *mem)
660 615
661static int __init zcore_header_init(int arch, struct zcore_header *hdr) 616static int __init zcore_header_init(int arch, struct zcore_header *hdr)
662{ 617{
663 int rc; 618 int rc, i;
664 unsigned long memory = 0; 619 unsigned long memory = 0;
620 u32 prefix;
665 621
666 if (arch == ARCH_S390X) 622 if (arch == ARCH_S390X)
667 hdr->arch_id = DUMP_ARCH_S390X; 623 hdr->arch_id = DUMP_ARCH_S390X;
@@ -676,6 +632,14 @@ static int __init zcore_header_init(int arch, struct zcore_header *hdr)
676 hdr->num_pages = memory / PAGE_SIZE; 632 hdr->num_pages = memory / PAGE_SIZE;
677 hdr->tod = get_clock(); 633 hdr->tod = get_clock();
678 get_cpu_id(&hdr->cpu_id); 634 get_cpu_id(&hdr->cpu_id);
635 for (i = 0; zfcpdump_save_areas[i]; i++) {
636 prefix = zfcpdump_save_areas[i]->pref_reg;
637 hdr->real_cpu_cnt++;
638 if (!prefix)
639 continue;
640 hdr->lc_vec[hdr->cpu_cnt] = prefix;
641 hdr->cpu_cnt++;
642 }
679 return 0; 643 return 0;
680} 644}
681 645
@@ -741,14 +705,21 @@ static int __init zcore_init(void)
741 if (rc) 705 if (rc)
742 goto fail; 706 goto fail;
743 707
744#ifndef __s390x__ 708#ifdef CONFIG_64BIT
709 if (arch == ARCH_S390) {
710 pr_alert("The 64-bit dump tool cannot be used for a "
711 "32-bit system\n");
712 rc = -EINVAL;
713 goto fail;
714 }
715#else /* CONFIG_64BIT */
745 if (arch == ARCH_S390X) { 716 if (arch == ARCH_S390X) {
746 pr_alert("The 32-bit dump tool cannot be used for a " 717 pr_alert("The 32-bit dump tool cannot be used for a "
747 "64-bit system\n"); 718 "64-bit system\n");
748 rc = -EINVAL; 719 rc = -EINVAL;
749 goto fail; 720 goto fail;
750 } 721 }
751#endif 722#endif /* CONFIG_64BIT */
752 723
753 rc = sys_info_init(arch); 724 rc = sys_info_init(arch);
754 if (rc) 725 if (rc)
diff --git a/drivers/s390/cio/ccwreq.c b/drivers/s390/cio/ccwreq.c
index 7a28a3029a3f..37df42af05ec 100644
--- a/drivers/s390/cio/ccwreq.c
+++ b/drivers/s390/cio/ccwreq.c
@@ -224,8 +224,8 @@ static void ccwreq_log_status(struct ccw_device *cdev, enum io_status status)
224 */ 224 */
225void ccw_request_handler(struct ccw_device *cdev) 225void ccw_request_handler(struct ccw_device *cdev)
226{ 226{
227 struct irb *irb = (struct irb *)&S390_lowcore.irb;
227 struct ccw_request *req = &cdev->private->req; 228 struct ccw_request *req = &cdev->private->req;
228 struct irb *irb = (struct irb *) __LC_IRB;
229 enum io_status status; 229 enum io_status status;
230 int rc = -EOPNOTSUPP; 230 int rc = -EOPNOTSUPP;
231 231
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index 1ecd3e567648..4038f5b4f144 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -574,7 +574,7 @@ int __chsc_do_secm(struct channel_subsystem *css, int enable, void *page)
574 secm_area->request.length = 0x0050; 574 secm_area->request.length = 0x0050;
575 secm_area->request.code = 0x0016; 575 secm_area->request.code = 0x0016;
576 576
577 secm_area->key = PAGE_DEFAULT_KEY; 577 secm_area->key = PAGE_DEFAULT_KEY >> 4;
578 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1; 578 secm_area->cub_addr1 = (u64)(unsigned long)css->cub_addr1;
579 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2; 579 secm_area->cub_addr2 = (u64)(unsigned long)css->cub_addr2;
580 580
diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c
index c84ac9443079..852612f5dba0 100644
--- a/drivers/s390/cio/chsc_sch.c
+++ b/drivers/s390/cio/chsc_sch.c
@@ -51,7 +51,7 @@ static void chsc_subchannel_irq(struct subchannel *sch)
51{ 51{
52 struct chsc_private *private = sch->private; 52 struct chsc_private *private = sch->private;
53 struct chsc_request *request = private->request; 53 struct chsc_request *request = private->request;
54 struct irb *irb = (struct irb *)__LC_IRB; 54 struct irb *irb = (struct irb *)&S390_lowcore.irb;
55 55
56 CHSC_LOG(4, "irb"); 56 CHSC_LOG(4, "irb");
57 CHSC_LOG_HEX(4, irb, sizeof(*irb)); 57 CHSC_LOG_HEX(4, irb, sizeof(*irb));
@@ -237,7 +237,7 @@ static int chsc_async(struct chsc_async_area *chsc_area,
237 int ret = -ENODEV; 237 int ret = -ENODEV;
238 char dbf[10]; 238 char dbf[10];
239 239
240 chsc_area->header.key = PAGE_DEFAULT_KEY; 240 chsc_area->header.key = PAGE_DEFAULT_KEY >> 4;
241 while ((sch = chsc_get_next_subchannel(sch))) { 241 while ((sch = chsc_get_next_subchannel(sch))) {
242 spin_lock(sch->lock); 242 spin_lock(sch->lock);
243 private = sch->private; 243 private = sch->private;
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 126f240715a4..f736cdcf08ad 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -625,8 +625,8 @@ void __irq_entry do_IRQ(struct pt_regs *regs)
625 /* 625 /*
626 * Get interrupt information from lowcore 626 * Get interrupt information from lowcore
627 */ 627 */
628 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID; 628 tpi_info = (struct tpi_info *)&S390_lowcore.subchannel_id;
629 irb = (struct irb *) __LC_IRB; 629 irb = (struct irb *)&S390_lowcore.irb;
630 do { 630 do {
631 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++; 631 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
632 /* 632 /*
@@ -661,7 +661,7 @@ void __irq_entry do_IRQ(struct pt_regs *regs)
661 * We don't do this for VM because a tpi drops the cpu 661 * We don't do this for VM because a tpi drops the cpu
662 * out of the sie which costs more cycles than it saves. 662 * out of the sie which costs more cycles than it saves.
663 */ 663 */
664 } while (!MACHINE_IS_VM && tpi (NULL) != 0); 664 } while (MACHINE_IS_LPAR && tpi(NULL) != 0);
665 irq_exit(); 665 irq_exit();
666 set_irq_regs(old_regs); 666 set_irq_regs(old_regs);
667} 667}
@@ -682,10 +682,10 @@ static int cio_tpi(void)
682 struct irb *irb; 682 struct irb *irb;
683 int irq_context; 683 int irq_context;
684 684
685 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID; 685 tpi_info = (struct tpi_info *)&S390_lowcore.subchannel_id;
686 if (tpi(NULL) != 1) 686 if (tpi(NULL) != 1)
687 return 0; 687 return 0;
688 irb = (struct irb *) __LC_IRB; 688 irb = (struct irb *)&S390_lowcore.irb;
689 /* Store interrupt response block to lowcore. */ 689 /* Store interrupt response block to lowcore. */
690 if (tsch(tpi_info->schid, irb) != 0) 690 if (tsch(tpi_info->schid, irb) != 0)
691 /* Not status pending or not operational. */ 691 /* Not status pending or not operational. */
@@ -885,7 +885,7 @@ __clear_io_subchannel_easy(struct subchannel_id schid)
885 struct tpi_info ti; 885 struct tpi_info ti;
886 886
887 if (tpi(&ti)) { 887 if (tpi(&ti)) {
888 tsch(ti.schid, (struct irb *)__LC_IRB); 888 tsch(ti.schid, (struct irb *)&S390_lowcore.irb);
889 if (schid_equal(&ti.schid, &schid)) 889 if (schid_equal(&ti.schid, &schid))
890 return 0; 890 return 0;
891 } 891 }
@@ -1083,7 +1083,7 @@ int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
1083 struct subchannel_id schid; 1083 struct subchannel_id schid;
1084 struct schib schib; 1084 struct schib schib;
1085 1085
1086 schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID; 1086 schid = *(struct subchannel_id *)&S390_lowcore.subchannel_id;
1087 if (!schid.one) 1087 if (!schid.one)
1088 return -ENODEV; 1088 return -ENODEV;
1089 if (stsch(schid, &schib)) 1089 if (stsch(schid, &schib))
diff --git a/drivers/s390/cio/crw.c b/drivers/s390/cio/crw.c
index d157665d0e76..425f741a280c 100644
--- a/drivers/s390/cio/crw.c
+++ b/drivers/s390/cio/crw.c
@@ -8,15 +8,16 @@
8 * Heiko Carstens <heiko.carstens@de.ibm.com>, 8 * Heiko Carstens <heiko.carstens@de.ibm.com>,
9 */ 9 */
10 10
11#include <linux/semaphore.h>
12#include <linux/mutex.h> 11#include <linux/mutex.h>
13#include <linux/kthread.h> 12#include <linux/kthread.h>
14#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/wait.h>
15#include <asm/crw.h> 15#include <asm/crw.h>
16 16
17static struct semaphore crw_semaphore;
18static DEFINE_MUTEX(crw_handler_mutex); 17static DEFINE_MUTEX(crw_handler_mutex);
19static crw_handler_t crw_handlers[NR_RSCS]; 18static crw_handler_t crw_handlers[NR_RSCS];
19static atomic_t crw_nr_req = ATOMIC_INIT(0);
20static DECLARE_WAIT_QUEUE_HEAD(crw_handler_wait_q);
20 21
21/** 22/**
22 * crw_register_handler() - register a channel report word handler 23 * crw_register_handler() - register a channel report word handler
@@ -59,12 +60,14 @@ void crw_unregister_handler(int rsc)
59static int crw_collect_info(void *unused) 60static int crw_collect_info(void *unused)
60{ 61{
61 struct crw crw[2]; 62 struct crw crw[2];
62 int ccode; 63 int ccode, signal;
63 unsigned int chain; 64 unsigned int chain;
64 int ignore;
65 65
66repeat: 66repeat:
67 ignore = down_interruptible(&crw_semaphore); 67 signal = wait_event_interruptible(crw_handler_wait_q,
68 atomic_read(&crw_nr_req) > 0);
69 if (unlikely(signal))
70 atomic_inc(&crw_nr_req);
68 chain = 0; 71 chain = 0;
69 while (1) { 72 while (1) {
70 crw_handler_t handler; 73 crw_handler_t handler;
@@ -122,25 +125,23 @@ repeat:
122 /* chain is always 0 or 1 here. */ 125 /* chain is always 0 or 1 here. */
123 chain = crw[chain].chn ? chain + 1 : 0; 126 chain = crw[chain].chn ? chain + 1 : 0;
124 } 127 }
128 if (atomic_dec_and_test(&crw_nr_req))
129 wake_up(&crw_handler_wait_q);
125 goto repeat; 130 goto repeat;
126 return 0; 131 return 0;
127} 132}
128 133
129void crw_handle_channel_report(void) 134void crw_handle_channel_report(void)
130{ 135{
131 up(&crw_semaphore); 136 atomic_inc(&crw_nr_req);
137 wake_up(&crw_handler_wait_q);
132} 138}
133 139
134/* 140void crw_wait_for_channel_report(void)
135 * Separate initcall needed for semaphore initialization since
136 * crw_handle_channel_report might be called before crw_machine_check_init.
137 */
138static int __init crw_init_semaphore(void)
139{ 141{
140 init_MUTEX_LOCKED(&crw_semaphore); 142 crw_handle_channel_report();
141 return 0; 143 wait_event(crw_handler_wait_q, atomic_read(&crw_nr_req) == 0);
142} 144}
143pure_initcall(crw_init_semaphore);
144 145
145/* 146/*
146 * Machine checks for the channel subsystem must be enabled 147 * Machine checks for the channel subsystem must be enabled
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 7679aee6fa14..2769da54f2b9 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -18,6 +18,7 @@
18#include <linux/list.h> 18#include <linux/list.h>
19#include <linux/reboot.h> 19#include <linux/reboot.h>
20#include <linux/suspend.h> 20#include <linux/suspend.h>
21#include <linux/proc_fs.h>
21#include <asm/isc.h> 22#include <asm/isc.h>
22#include <asm/crw.h> 23#include <asm/crw.h>
23 24
@@ -232,7 +233,7 @@ void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo)
232 if (!get_device(&sch->dev)) 233 if (!get_device(&sch->dev))
233 return; 234 return;
234 sch->todo = todo; 235 sch->todo = todo;
235 if (!queue_work(slow_path_wq, &sch->todo_work)) { 236 if (!queue_work(cio_work_q, &sch->todo_work)) {
236 /* Already queued, release workqueue ref. */ 237 /* Already queued, release workqueue ref. */
237 put_device(&sch->dev); 238 put_device(&sch->dev);
238 } 239 }
@@ -543,7 +544,7 @@ static void css_slow_path_func(struct work_struct *unused)
543} 544}
544 545
545static DECLARE_WORK(slow_path_work, css_slow_path_func); 546static DECLARE_WORK(slow_path_work, css_slow_path_func);
546struct workqueue_struct *slow_path_wq; 547struct workqueue_struct *cio_work_q;
547 548
548void css_schedule_eval(struct subchannel_id schid) 549void css_schedule_eval(struct subchannel_id schid)
549{ 550{
@@ -552,7 +553,7 @@ void css_schedule_eval(struct subchannel_id schid)
552 spin_lock_irqsave(&slow_subchannel_lock, flags); 553 spin_lock_irqsave(&slow_subchannel_lock, flags);
553 idset_sch_add(slow_subchannel_set, schid); 554 idset_sch_add(slow_subchannel_set, schid);
554 atomic_set(&css_eval_scheduled, 1); 555 atomic_set(&css_eval_scheduled, 1);
555 queue_work(slow_path_wq, &slow_path_work); 556 queue_work(cio_work_q, &slow_path_work);
556 spin_unlock_irqrestore(&slow_subchannel_lock, flags); 557 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
557} 558}
558 559
@@ -563,7 +564,7 @@ void css_schedule_eval_all(void)
563 spin_lock_irqsave(&slow_subchannel_lock, flags); 564 spin_lock_irqsave(&slow_subchannel_lock, flags);
564 idset_fill(slow_subchannel_set); 565 idset_fill(slow_subchannel_set);
565 atomic_set(&css_eval_scheduled, 1); 566 atomic_set(&css_eval_scheduled, 1);
566 queue_work(slow_path_wq, &slow_path_work); 567 queue_work(cio_work_q, &slow_path_work);
567 spin_unlock_irqrestore(&slow_subchannel_lock, flags); 568 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
568} 569}
569 570
@@ -594,14 +595,14 @@ void css_schedule_eval_all_unreg(void)
594 spin_lock_irqsave(&slow_subchannel_lock, flags); 595 spin_lock_irqsave(&slow_subchannel_lock, flags);
595 idset_add_set(slow_subchannel_set, unreg_set); 596 idset_add_set(slow_subchannel_set, unreg_set);
596 atomic_set(&css_eval_scheduled, 1); 597 atomic_set(&css_eval_scheduled, 1);
597 queue_work(slow_path_wq, &slow_path_work); 598 queue_work(cio_work_q, &slow_path_work);
598 spin_unlock_irqrestore(&slow_subchannel_lock, flags); 599 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
599 idset_free(unreg_set); 600 idset_free(unreg_set);
600} 601}
601 602
602void css_wait_for_slow_path(void) 603void css_wait_for_slow_path(void)
603{ 604{
604 flush_workqueue(slow_path_wq); 605 flush_workqueue(cio_work_q);
605} 606}
606 607
607/* Schedule reprobing of all unregistered subchannels. */ 608/* Schedule reprobing of all unregistered subchannels. */
@@ -992,12 +993,21 @@ static int __init channel_subsystem_init(void)
992 ret = css_bus_init(); 993 ret = css_bus_init();
993 if (ret) 994 if (ret)
994 return ret; 995 return ret;
995 996 cio_work_q = create_singlethread_workqueue("cio");
997 if (!cio_work_q) {
998 ret = -ENOMEM;
999 goto out_bus;
1000 }
996 ret = io_subchannel_init(); 1001 ret = io_subchannel_init();
997 if (ret) 1002 if (ret)
998 css_bus_cleanup(); 1003 goto out_wq;
999 1004
1000 return ret; 1005 return ret;
1006out_wq:
1007 destroy_workqueue(cio_work_q);
1008out_bus:
1009 css_bus_cleanup();
1010 return ret;
1001} 1011}
1002subsys_initcall(channel_subsystem_init); 1012subsys_initcall(channel_subsystem_init);
1003 1013
@@ -1006,10 +1016,25 @@ static int css_settle(struct device_driver *drv, void *unused)
1006 struct css_driver *cssdrv = to_cssdriver(drv); 1016 struct css_driver *cssdrv = to_cssdriver(drv);
1007 1017
1008 if (cssdrv->settle) 1018 if (cssdrv->settle)
1009 cssdrv->settle(); 1019 return cssdrv->settle();
1010 return 0; 1020 return 0;
1011} 1021}
1012 1022
1023int css_complete_work(void)
1024{
1025 int ret;
1026
1027 /* Wait for the evaluation of subchannels to finish. */
1028 ret = wait_event_interruptible(css_eval_wq,
1029 atomic_read(&css_eval_scheduled) == 0);
1030 if (ret)
1031 return -EINTR;
1032 flush_workqueue(cio_work_q);
1033 /* Wait for the subchannel type specific initialization to finish */
1034 return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle);
1035}
1036
1037
1013/* 1038/*
1014 * Wait for the initialization of devices to finish, to make sure we are 1039 * Wait for the initialization of devices to finish, to make sure we are
1015 * done with our setup if the search for the root device starts. 1040 * done with our setup if the search for the root device starts.
@@ -1018,13 +1043,41 @@ static int __init channel_subsystem_init_sync(void)
1018{ 1043{
1019 /* Start initial subchannel evaluation. */ 1044 /* Start initial subchannel evaluation. */
1020 css_schedule_eval_all(); 1045 css_schedule_eval_all();
1021 /* Wait for the evaluation of subchannels to finish. */ 1046 css_complete_work();
1022 wait_event(css_eval_wq, atomic_read(&css_eval_scheduled) == 0); 1047 return 0;
1023 /* Wait for the subchannel type specific initialization to finish */
1024 return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle);
1025} 1048}
1026subsys_initcall_sync(channel_subsystem_init_sync); 1049subsys_initcall_sync(channel_subsystem_init_sync);
1027 1050
1051#ifdef CONFIG_PROC_FS
1052static ssize_t cio_settle_write(struct file *file, const char __user *buf,
1053 size_t count, loff_t *ppos)
1054{
1055 int ret;
1056
1057 /* Handle pending CRW's. */
1058 crw_wait_for_channel_report();
1059 ret = css_complete_work();
1060
1061 return ret ? ret : count;
1062}
1063
1064static const struct file_operations cio_settle_proc_fops = {
1065 .write = cio_settle_write,
1066};
1067
1068static int __init cio_settle_init(void)
1069{
1070 struct proc_dir_entry *entry;
1071
1072 entry = proc_create("cio_settle", S_IWUSR, NULL,
1073 &cio_settle_proc_fops);
1074 if (!entry)
1075 return -ENOMEM;
1076 return 0;
1077}
1078device_initcall(cio_settle_init);
1079#endif /*CONFIG_PROC_FS*/
1080
1028int sch_is_pseudo_sch(struct subchannel *sch) 1081int sch_is_pseudo_sch(struct subchannel *sch)
1029{ 1082{
1030 return sch == to_css(sch->dev.parent)->pseudo_subchannel; 1083 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h
index fe84b92cde60..7e37886de231 100644
--- a/drivers/s390/cio/css.h
+++ b/drivers/s390/cio/css.h
@@ -95,7 +95,7 @@ struct css_driver {
95 int (*freeze)(struct subchannel *); 95 int (*freeze)(struct subchannel *);
96 int (*thaw) (struct subchannel *); 96 int (*thaw) (struct subchannel *);
97 int (*restore)(struct subchannel *); 97 int (*restore)(struct subchannel *);
98 void (*settle)(void); 98 int (*settle)(void);
99 const char *name; 99 const char *name;
100}; 100};
101 101
@@ -146,12 +146,13 @@ extern struct channel_subsystem *channel_subsystems[];
146/* Helper functions to build lists for the slow path. */ 146/* Helper functions to build lists for the slow path. */
147void css_schedule_eval(struct subchannel_id schid); 147void css_schedule_eval(struct subchannel_id schid);
148void css_schedule_eval_all(void); 148void css_schedule_eval_all(void);
149int css_complete_work(void);
149 150
150int sch_is_pseudo_sch(struct subchannel *); 151int sch_is_pseudo_sch(struct subchannel *);
151struct schib; 152struct schib;
152int css_sch_is_valid(struct schib *); 153int css_sch_is_valid(struct schib *);
153 154
154extern struct workqueue_struct *slow_path_wq; 155extern struct workqueue_struct *cio_work_q;
155void css_wait_for_slow_path(void); 156void css_wait_for_slow_path(void);
156void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo); 157void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo);
157#endif 158#endif
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index a6c7d5426fb2..c6abb75c4615 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -136,7 +136,6 @@ static int io_subchannel_sch_event(struct subchannel *, int);
136static int io_subchannel_chp_event(struct subchannel *, struct chp_link *, 136static int io_subchannel_chp_event(struct subchannel *, struct chp_link *,
137 int); 137 int);
138static void recovery_func(unsigned long data); 138static void recovery_func(unsigned long data);
139struct workqueue_struct *ccw_device_work;
140wait_queue_head_t ccw_device_init_wq; 139wait_queue_head_t ccw_device_init_wq;
141atomic_t ccw_device_init_count; 140atomic_t ccw_device_init_count;
142 141
@@ -159,11 +158,16 @@ static int io_subchannel_prepare(struct subchannel *sch)
159 return 0; 158 return 0;
160} 159}
161 160
162static void io_subchannel_settle(void) 161static int io_subchannel_settle(void)
163{ 162{
164 wait_event(ccw_device_init_wq, 163 int ret;
165 atomic_read(&ccw_device_init_count) == 0); 164
166 flush_workqueue(ccw_device_work); 165 ret = wait_event_interruptible(ccw_device_init_wq,
166 atomic_read(&ccw_device_init_count) == 0);
167 if (ret)
168 return -EINTR;
169 flush_workqueue(cio_work_q);
170 return 0;
167} 171}
168 172
169static struct css_driver io_subchannel_driver = { 173static struct css_driver io_subchannel_driver = {
@@ -188,27 +192,13 @@ int __init io_subchannel_init(void)
188 atomic_set(&ccw_device_init_count, 0); 192 atomic_set(&ccw_device_init_count, 0);
189 setup_timer(&recovery_timer, recovery_func, 0); 193 setup_timer(&recovery_timer, recovery_func, 0);
190 194
191 ccw_device_work = create_singlethread_workqueue("cio"); 195 ret = bus_register(&ccw_bus_type);
192 if (!ccw_device_work) 196 if (ret)
193 return -ENOMEM; 197 return ret;
194 slow_path_wq = create_singlethread_workqueue("kslowcrw");
195 if (!slow_path_wq) {
196 ret = -ENOMEM;
197 goto out_err;
198 }
199 if ((ret = bus_register (&ccw_bus_type)))
200 goto out_err;
201
202 ret = css_driver_register(&io_subchannel_driver); 198 ret = css_driver_register(&io_subchannel_driver);
203 if (ret) 199 if (ret)
204 goto out_err; 200 bus_unregister(&ccw_bus_type);
205 201
206 return 0;
207out_err:
208 if (ccw_device_work)
209 destroy_workqueue(ccw_device_work);
210 if (slow_path_wq)
211 destroy_workqueue(slow_path_wq);
212 return ret; 202 return ret;
213} 203}
214 204
@@ -1348,7 +1338,7 @@ static enum io_sch_action sch_get_action(struct subchannel *sch)
1348 /* Not operational. */ 1338 /* Not operational. */
1349 if (!cdev) 1339 if (!cdev)
1350 return IO_SCH_UNREG; 1340 return IO_SCH_UNREG;
1351 if (!ccw_device_notify(cdev, CIO_GONE)) 1341 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
1352 return IO_SCH_UNREG; 1342 return IO_SCH_UNREG;
1353 return IO_SCH_ORPH_UNREG; 1343 return IO_SCH_ORPH_UNREG;
1354 } 1344 }
@@ -1356,12 +1346,12 @@ static enum io_sch_action sch_get_action(struct subchannel *sch)
1356 if (!cdev) 1346 if (!cdev)
1357 return IO_SCH_ATTACH; 1347 return IO_SCH_ATTACH;
1358 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) { 1348 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
1359 if (!ccw_device_notify(cdev, CIO_GONE)) 1349 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
1360 return IO_SCH_UNREG_ATTACH; 1350 return IO_SCH_UNREG_ATTACH;
1361 return IO_SCH_ORPH_ATTACH; 1351 return IO_SCH_ORPH_ATTACH;
1362 } 1352 }
1363 if ((sch->schib.pmcw.pam & sch->opm) == 0) { 1353 if ((sch->schib.pmcw.pam & sch->opm) == 0) {
1364 if (!ccw_device_notify(cdev, CIO_NO_PATH)) 1354 if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK)
1365 return IO_SCH_UNREG; 1355 return IO_SCH_UNREG;
1366 return IO_SCH_DISC; 1356 return IO_SCH_DISC;
1367 } 1357 }
@@ -1410,6 +1400,12 @@ static int io_subchannel_sch_event(struct subchannel *sch, int process)
1410 rc = 0; 1400 rc = 0;
1411 goto out_unlock; 1401 goto out_unlock;
1412 case IO_SCH_VERIFY: 1402 case IO_SCH_VERIFY:
1403 if (cdev->private->flags.resuming == 1) {
1404 if (cio_enable_subchannel(sch, (u32)(addr_t)sch)) {
1405 ccw_device_set_notoper(cdev);
1406 break;
1407 }
1408 }
1413 /* Trigger path verification. */ 1409 /* Trigger path verification. */
1414 io_subchannel_verify(sch); 1410 io_subchannel_verify(sch);
1415 rc = 0; 1411 rc = 0;
@@ -1448,7 +1444,8 @@ static int io_subchannel_sch_event(struct subchannel *sch, int process)
1448 break; 1444 break;
1449 case IO_SCH_UNREG_ATTACH: 1445 case IO_SCH_UNREG_ATTACH:
1450 /* Unregister ccw device. */ 1446 /* Unregister ccw device. */
1451 ccw_device_unregister(cdev); 1447 if (!cdev->private->flags.resuming)
1448 ccw_device_unregister(cdev);
1452 break; 1449 break;
1453 default: 1450 default:
1454 break; 1451 break;
@@ -1457,7 +1454,8 @@ static int io_subchannel_sch_event(struct subchannel *sch, int process)
1457 switch (action) { 1454 switch (action) {
1458 case IO_SCH_ORPH_UNREG: 1455 case IO_SCH_ORPH_UNREG:
1459 case IO_SCH_UNREG: 1456 case IO_SCH_UNREG:
1460 css_sch_device_unregister(sch); 1457 if (!cdev || !cdev->private->flags.resuming)
1458 css_sch_device_unregister(sch);
1461 break; 1459 break;
1462 case IO_SCH_ORPH_ATTACH: 1460 case IO_SCH_ORPH_ATTACH:
1463 case IO_SCH_UNREG_ATTACH: 1461 case IO_SCH_UNREG_ATTACH:
@@ -1779,26 +1777,42 @@ static void __ccw_device_pm_restore(struct ccw_device *cdev)
1779{ 1777{
1780 struct subchannel *sch = to_subchannel(cdev->dev.parent); 1778 struct subchannel *sch = to_subchannel(cdev->dev.parent);
1781 1779
1782 if (cio_is_console(sch->schid)) 1780 spin_lock_irq(sch->lock);
1783 goto out; 1781 if (cio_is_console(sch->schid)) {
1782 cio_enable_subchannel(sch, (u32)(addr_t)sch);
1783 goto out_unlock;
1784 }
1784 /* 1785 /*
1785 * While we were sleeping, devices may have gone or become 1786 * While we were sleeping, devices may have gone or become
1786 * available again. Kick re-detection. 1787 * available again. Kick re-detection.
1787 */ 1788 */
1788 spin_lock_irq(sch->lock);
1789 cdev->private->flags.resuming = 1; 1789 cdev->private->flags.resuming = 1;
1790 css_schedule_eval(sch->schid);
1791 spin_unlock_irq(sch->lock);
1792 css_complete_work();
1793
1794 /* cdev may have been moved to a different subchannel. */
1795 sch = to_subchannel(cdev->dev.parent);
1796 spin_lock_irq(sch->lock);
1797 if (cdev->private->state != DEV_STATE_ONLINE &&
1798 cdev->private->state != DEV_STATE_OFFLINE)
1799 goto out_unlock;
1800
1790 ccw_device_recognition(cdev); 1801 ccw_device_recognition(cdev);
1791 spin_unlock_irq(sch->lock); 1802 spin_unlock_irq(sch->lock);
1792 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) || 1803 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) ||
1793 cdev->private->state == DEV_STATE_DISCONNECTED); 1804 cdev->private->state == DEV_STATE_DISCONNECTED);
1794out: 1805 spin_lock_irq(sch->lock);
1806
1807out_unlock:
1795 cdev->private->flags.resuming = 0; 1808 cdev->private->flags.resuming = 0;
1809 spin_unlock_irq(sch->lock);
1796} 1810}
1797 1811
1798static int resume_handle_boxed(struct ccw_device *cdev) 1812static int resume_handle_boxed(struct ccw_device *cdev)
1799{ 1813{
1800 cdev->private->state = DEV_STATE_BOXED; 1814 cdev->private->state = DEV_STATE_BOXED;
1801 if (ccw_device_notify(cdev, CIO_BOXED)) 1815 if (ccw_device_notify(cdev, CIO_BOXED) == NOTIFY_OK)
1802 return 0; 1816 return 0;
1803 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); 1817 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
1804 return -ENODEV; 1818 return -ENODEV;
@@ -1807,7 +1821,7 @@ static int resume_handle_boxed(struct ccw_device *cdev)
1807static int resume_handle_disc(struct ccw_device *cdev) 1821static int resume_handle_disc(struct ccw_device *cdev)
1808{ 1822{
1809 cdev->private->state = DEV_STATE_DISCONNECTED; 1823 cdev->private->state = DEV_STATE_DISCONNECTED;
1810 if (ccw_device_notify(cdev, CIO_GONE)) 1824 if (ccw_device_notify(cdev, CIO_GONE) == NOTIFY_OK)
1811 return 0; 1825 return 0;
1812 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); 1826 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
1813 return -ENODEV; 1827 return -ENODEV;
@@ -1816,40 +1830,31 @@ static int resume_handle_disc(struct ccw_device *cdev)
1816static int ccw_device_pm_restore(struct device *dev) 1830static int ccw_device_pm_restore(struct device *dev)
1817{ 1831{
1818 struct ccw_device *cdev = to_ccwdev(dev); 1832 struct ccw_device *cdev = to_ccwdev(dev);
1819 struct subchannel *sch = to_subchannel(cdev->dev.parent); 1833 struct subchannel *sch;
1820 int ret = 0, cm_enabled; 1834 int ret = 0;
1821 1835
1822 __ccw_device_pm_restore(cdev); 1836 __ccw_device_pm_restore(cdev);
1837 sch = to_subchannel(cdev->dev.parent);
1823 spin_lock_irq(sch->lock); 1838 spin_lock_irq(sch->lock);
1824 if (cio_is_console(sch->schid)) { 1839 if (cio_is_console(sch->schid))
1825 cio_enable_subchannel(sch, (u32)(addr_t)sch);
1826 spin_unlock_irq(sch->lock);
1827 goto out_restore; 1840 goto out_restore;
1828 } 1841
1829 cdev->private->flags.donotify = 0;
1830 /* check recognition results */ 1842 /* check recognition results */
1831 switch (cdev->private->state) { 1843 switch (cdev->private->state) {
1832 case DEV_STATE_OFFLINE: 1844 case DEV_STATE_OFFLINE:
1845 case DEV_STATE_ONLINE:
1846 cdev->private->flags.donotify = 0;
1833 break; 1847 break;
1834 case DEV_STATE_BOXED: 1848 case DEV_STATE_BOXED:
1835 ret = resume_handle_boxed(cdev); 1849 ret = resume_handle_boxed(cdev);
1836 spin_unlock_irq(sch->lock);
1837 if (ret) 1850 if (ret)
1838 goto out; 1851 goto out_unlock;
1839 goto out_restore; 1852 goto out_restore;
1840 case DEV_STATE_DISCONNECTED:
1841 goto out_disc_unlock;
1842 default: 1853 default:
1843 goto out_unreg_unlock; 1854 ret = resume_handle_disc(cdev);
1844 } 1855 if (ret)
1845 /* check if the device id has changed */ 1856 goto out_unlock;
1846 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) { 1857 goto out_restore;
1847 CIO_MSG_EVENT(0, "resume: sch 0.%x.%04x: failed (devno "
1848 "changed from %04x to %04x)\n",
1849 sch->schid.ssid, sch->schid.sch_no,
1850 cdev->private->dev_id.devno,
1851 sch->schib.pmcw.dev);
1852 goto out_unreg_unlock;
1853 } 1858 }
1854 /* check if the device type has changed */ 1859 /* check if the device type has changed */
1855 if (!ccw_device_test_sense_data(cdev)) { 1860 if (!ccw_device_test_sense_data(cdev)) {
@@ -1858,24 +1863,30 @@ static int ccw_device_pm_restore(struct device *dev)
1858 ret = -ENODEV; 1863 ret = -ENODEV;
1859 goto out_unlock; 1864 goto out_unlock;
1860 } 1865 }
1861 if (!cdev->online) { 1866 if (!cdev->online)
1862 ret = 0;
1863 goto out_unlock; 1867 goto out_unlock;
1864 }
1865 ret = ccw_device_online(cdev);
1866 if (ret)
1867 goto out_disc_unlock;
1868 1868
1869 cm_enabled = cdev->private->cmb != NULL; 1869 if (ccw_device_online(cdev)) {
1870 ret = resume_handle_disc(cdev);
1871 if (ret)
1872 goto out_unlock;
1873 goto out_restore;
1874 }
1870 spin_unlock_irq(sch->lock); 1875 spin_unlock_irq(sch->lock);
1871
1872 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); 1876 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1873 if (cdev->private->state != DEV_STATE_ONLINE) { 1877 spin_lock_irq(sch->lock);
1874 spin_lock_irq(sch->lock); 1878
1875 goto out_disc_unlock; 1879 if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_BAD) {
1880 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
1881 ret = -ENODEV;
1882 goto out_unlock;
1876 } 1883 }
1877 if (cm_enabled) { 1884
1885 /* reenable cmf, if needed */
1886 if (cdev->private->cmb) {
1887 spin_unlock_irq(sch->lock);
1878 ret = ccw_set_cmf(cdev, 1); 1888 ret = ccw_set_cmf(cdev, 1);
1889 spin_lock_irq(sch->lock);
1879 if (ret) { 1890 if (ret) {
1880 CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed " 1891 CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed "
1881 "(rc=%d)\n", cdev->private->dev_id.ssid, 1892 "(rc=%d)\n", cdev->private->dev_id.ssid,
@@ -1885,21 +1896,11 @@ static int ccw_device_pm_restore(struct device *dev)
1885 } 1896 }
1886 1897
1887out_restore: 1898out_restore:
1899 spin_unlock_irq(sch->lock);
1888 if (cdev->online && cdev->drv && cdev->drv->restore) 1900 if (cdev->online && cdev->drv && cdev->drv->restore)
1889 ret = cdev->drv->restore(cdev); 1901 ret = cdev->drv->restore(cdev);
1890out:
1891 return ret; 1902 return ret;
1892 1903
1893out_disc_unlock:
1894 ret = resume_handle_disc(cdev);
1895 spin_unlock_irq(sch->lock);
1896 if (ret)
1897 return ret;
1898 goto out_restore;
1899
1900out_unreg_unlock:
1901 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG_EVAL);
1902 ret = -ENODEV;
1903out_unlock: 1904out_unlock:
1904 spin_unlock_irq(sch->lock); 1905 spin_unlock_irq(sch->lock);
1905 return ret; 1906 return ret;
@@ -2028,7 +2029,7 @@ void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo)
2028 /* Get workqueue ref. */ 2029 /* Get workqueue ref. */
2029 if (!get_device(&cdev->dev)) 2030 if (!get_device(&cdev->dev))
2030 return; 2031 return;
2031 if (!queue_work(slow_path_wq, &cdev->private->todo_work)) { 2032 if (!queue_work(cio_work_q, &cdev->private->todo_work)) {
2032 /* Already queued, release workqueue ref. */ 2033 /* Already queued, release workqueue ref. */
2033 put_device(&cdev->dev); 2034 put_device(&cdev->dev);
2034 } 2035 }
@@ -2041,5 +2042,4 @@ EXPORT_SYMBOL(ccw_driver_register);
2041EXPORT_SYMBOL(ccw_driver_unregister); 2042EXPORT_SYMBOL(ccw_driver_unregister);
2042EXPORT_SYMBOL(get_ccwdev_by_busid); 2043EXPORT_SYMBOL(get_ccwdev_by_busid);
2043EXPORT_SYMBOL(ccw_bus_type); 2044EXPORT_SYMBOL(ccw_bus_type);
2044EXPORT_SYMBOL(ccw_device_work);
2045EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id); 2045EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);
diff --git a/drivers/s390/cio/device.h b/drivers/s390/cio/device.h
index bcfe13e42638..379de2d1ec49 100644
--- a/drivers/s390/cio/device.h
+++ b/drivers/s390/cio/device.h
@@ -4,7 +4,7 @@
4#include <asm/ccwdev.h> 4#include <asm/ccwdev.h>
5#include <asm/atomic.h> 5#include <asm/atomic.h>
6#include <linux/wait.h> 6#include <linux/wait.h>
7 7#include <linux/notifier.h>
8#include "io_sch.h" 8#include "io_sch.h"
9 9
10/* 10/*
@@ -71,7 +71,6 @@ dev_fsm_final_state(struct ccw_device *cdev)
71 cdev->private->state == DEV_STATE_BOXED); 71 cdev->private->state == DEV_STATE_BOXED);
72} 72}
73 73
74extern struct workqueue_struct *ccw_device_work;
75extern wait_queue_head_t ccw_device_init_wq; 74extern wait_queue_head_t ccw_device_init_wq;
76extern atomic_t ccw_device_init_count; 75extern atomic_t ccw_device_init_count;
77int __init io_subchannel_init(void); 76int __init io_subchannel_init(void);
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index ae760658a131..c56ab94612f9 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -313,21 +313,43 @@ ccw_device_sense_id_done(struct ccw_device *cdev, int err)
313 } 313 }
314} 314}
315 315
316/**
317 * ccw_device_notify() - inform the device's driver about an event
318 * @cdev: device for which an event occured
319 * @event: event that occurred
320 *
321 * Returns:
322 * -%EINVAL if the device is offline or has no driver.
323 * -%EOPNOTSUPP if the device's driver has no notifier registered.
324 * %NOTIFY_OK if the driver wants to keep the device.
325 * %NOTIFY_BAD if the driver doesn't want to keep the device.
326 */
316int ccw_device_notify(struct ccw_device *cdev, int event) 327int ccw_device_notify(struct ccw_device *cdev, int event)
317{ 328{
329 int ret = -EINVAL;
330
318 if (!cdev->drv) 331 if (!cdev->drv)
319 return 0; 332 goto out;
320 if (!cdev->online) 333 if (!cdev->online)
321 return 0; 334 goto out;
322 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n", 335 CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
323 cdev->private->dev_id.ssid, cdev->private->dev_id.devno, 336 cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
324 event); 337 event);
325 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0; 338 if (!cdev->drv->notify) {
339 ret = -EOPNOTSUPP;
340 goto out;
341 }
342 if (cdev->drv->notify(cdev, event))
343 ret = NOTIFY_OK;
344 else
345 ret = NOTIFY_BAD;
346out:
347 return ret;
326} 348}
327 349
328static void ccw_device_oper_notify(struct ccw_device *cdev) 350static void ccw_device_oper_notify(struct ccw_device *cdev)
329{ 351{
330 if (ccw_device_notify(cdev, CIO_OPER)) { 352 if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_OK) {
331 /* Reenable channel measurements, if needed. */ 353 /* Reenable channel measurements, if needed. */
332 ccw_device_sched_todo(cdev, CDEV_TODO_ENABLE_CMF); 354 ccw_device_sched_todo(cdev, CDEV_TODO_ENABLE_CMF);
333 return; 355 return;
@@ -361,14 +383,15 @@ ccw_device_done(struct ccw_device *cdev, int state)
361 case DEV_STATE_BOXED: 383 case DEV_STATE_BOXED:
362 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n", 384 CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
363 cdev->private->dev_id.devno, sch->schid.sch_no); 385 cdev->private->dev_id.devno, sch->schid.sch_no);
364 if (cdev->online && !ccw_device_notify(cdev, CIO_BOXED)) 386 if (cdev->online &&
387 ccw_device_notify(cdev, CIO_BOXED) != NOTIFY_OK)
365 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); 388 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
366 cdev->private->flags.donotify = 0; 389 cdev->private->flags.donotify = 0;
367 break; 390 break;
368 case DEV_STATE_NOT_OPER: 391 case DEV_STATE_NOT_OPER:
369 CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n", 392 CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n",
370 cdev->private->dev_id.devno, sch->schid.sch_no); 393 cdev->private->dev_id.devno, sch->schid.sch_no);
371 if (!ccw_device_notify(cdev, CIO_GONE)) 394 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
372 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); 395 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
373 else 396 else
374 ccw_device_set_disconnected(cdev); 397 ccw_device_set_disconnected(cdev);
@@ -378,7 +401,7 @@ ccw_device_done(struct ccw_device *cdev, int state)
378 CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel " 401 CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel "
379 "%04x\n", cdev->private->dev_id.devno, 402 "%04x\n", cdev->private->dev_id.devno,
380 sch->schid.sch_no); 403 sch->schid.sch_no);
381 if (!ccw_device_notify(cdev, CIO_NO_PATH)) 404 if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK)
382 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); 405 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
383 else 406 else
384 ccw_device_set_disconnected(cdev); 407 ccw_device_set_disconnected(cdev);
@@ -586,7 +609,7 @@ ccw_device_offline(struct ccw_device *cdev)
586static void ccw_device_generic_notoper(struct ccw_device *cdev, 609static void ccw_device_generic_notoper(struct ccw_device *cdev,
587 enum dev_event dev_event) 610 enum dev_event dev_event)
588{ 611{
589 if (!ccw_device_notify(cdev, CIO_GONE)) 612 if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
590 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); 613 ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
591 else 614 else
592 ccw_device_set_disconnected(cdev); 615 ccw_device_set_disconnected(cdev);
@@ -667,7 +690,7 @@ ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
667 struct irb *irb; 690 struct irb *irb;
668 int is_cmd; 691 int is_cmd;
669 692
670 irb = (struct irb *) __LC_IRB; 693 irb = (struct irb *)&S390_lowcore.irb;
671 is_cmd = !scsw_is_tm(&irb->scsw); 694 is_cmd = !scsw_is_tm(&irb->scsw);
672 /* Check for unsolicited interrupt. */ 695 /* Check for unsolicited interrupt. */
673 if (!scsw_is_solicited(&irb->scsw)) { 696 if (!scsw_is_solicited(&irb->scsw)) {
@@ -732,7 +755,7 @@ ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
732{ 755{
733 struct irb *irb; 756 struct irb *irb;
734 757
735 irb = (struct irb *) __LC_IRB; 758 irb = (struct irb *)&S390_lowcore.irb;
736 /* Check for unsolicited interrupt. */ 759 /* Check for unsolicited interrupt. */
737 if (scsw_stctl(&irb->scsw) == 760 if (scsw_stctl(&irb->scsw) ==
738 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { 761 (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
diff --git a/drivers/s390/cio/qdio.h b/drivers/s390/cio/qdio.h
index 44f2f6a97f33..48aa0647432b 100644
--- a/drivers/s390/cio/qdio.h
+++ b/drivers/s390/cio/qdio.h
@@ -208,18 +208,27 @@ struct qdio_dev_perf_stat {
208 unsigned int eqbs_partial; 208 unsigned int eqbs_partial;
209 unsigned int sqbs; 209 unsigned int sqbs;
210 unsigned int sqbs_partial; 210 unsigned int sqbs_partial;
211} ____cacheline_aligned;
212
213struct qdio_queue_perf_stat {
214 /*
215 * Sorted into order-2 buckets: 1, 2-3, 4-7, ... 64-127, 128.
216 * Since max. 127 SBALs are scanned reuse entry for 128 as queue full
217 * aka 127 SBALs found.
218 */
219 unsigned int nr_sbals[8];
220 unsigned int nr_sbal_error;
221 unsigned int nr_sbal_nop;
222 unsigned int nr_sbal_total;
211}; 223};
212 224
213struct qdio_input_q { 225struct qdio_input_q {
214 /* input buffer acknowledgement flag */ 226 /* input buffer acknowledgement flag */
215 int polling; 227 int polling;
216
217 /* first ACK'ed buffer */ 228 /* first ACK'ed buffer */
218 int ack_start; 229 int ack_start;
219
220 /* how much sbals are acknowledged with qebsm */ 230 /* how much sbals are acknowledged with qebsm */
221 int ack_count; 231 int ack_count;
222
223 /* last time of noticing incoming data */ 232 /* last time of noticing incoming data */
224 u64 timestamp; 233 u64 timestamp;
225}; 234};
@@ -227,40 +236,27 @@ struct qdio_input_q {
227struct qdio_output_q { 236struct qdio_output_q {
228 /* PCIs are enabled for the queue */ 237 /* PCIs are enabled for the queue */
229 int pci_out_enabled; 238 int pci_out_enabled;
230
231 /* IQDIO: output multiple buffers (enhanced SIGA) */ 239 /* IQDIO: output multiple buffers (enhanced SIGA) */
232 int use_enh_siga; 240 int use_enh_siga;
233
234 /* timer to check for more outbound work */ 241 /* timer to check for more outbound work */
235 struct timer_list timer; 242 struct timer_list timer;
236}; 243};
237 244
245/*
246 * Note on cache alignment: grouped slsb and write mostly data at the beginning
247 * sbal[] is read-only and starts on a new cacheline followed by read mostly.
248 */
238struct qdio_q { 249struct qdio_q {
239 struct slsb slsb; 250 struct slsb slsb;
251
240 union { 252 union {
241 struct qdio_input_q in; 253 struct qdio_input_q in;
242 struct qdio_output_q out; 254 struct qdio_output_q out;
243 } u; 255 } u;
244 256
245 /* queue number */
246 int nr;
247
248 /* bitmask of queue number */
249 int mask;
250
251 /* input or output queue */
252 int is_input_q;
253
254 /* list of thinint input queues */
255 struct list_head entry;
256
257 /* upper-layer program handler */
258 qdio_handler_t (*handler);
259
260 /* 257 /*
261 * inbound: next buffer the program should check for 258 * inbound: next buffer the program should check for
262 * outbound: next buffer to check for having been processed 259 * outbound: next buffer to check if adapter processed it
263 * by the card
264 */ 260 */
265 int first_to_check; 261 int first_to_check;
266 262
@@ -273,16 +269,32 @@ struct qdio_q {
273 /* number of buffers in use by the adapter */ 269 /* number of buffers in use by the adapter */
274 atomic_t nr_buf_used; 270 atomic_t nr_buf_used;
275 271
276 struct qdio_irq *irq_ptr;
277 struct dentry *debugfs_q;
278 struct tasklet_struct tasklet;
279
280 /* error condition during a data transfer */ 272 /* error condition during a data transfer */
281 unsigned int qdio_error; 273 unsigned int qdio_error;
282 274
283 struct sl *sl; 275 struct tasklet_struct tasklet;
284 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q]; 276 struct qdio_queue_perf_stat q_stats;
277
278 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q] ____cacheline_aligned;
279
280 /* queue number */
281 int nr;
282
283 /* bitmask of queue number */
284 int mask;
285
286 /* input or output queue */
287 int is_input_q;
288
289 /* list of thinint input queues */
290 struct list_head entry;
285 291
292 /* upper-layer program handler */
293 qdio_handler_t (*handler);
294
295 struct dentry *debugfs_q;
296 struct qdio_irq *irq_ptr;
297 struct sl *sl;
286 /* 298 /*
287 * Warning: Leave this member at the end so it won't be cleared in 299 * Warning: Leave this member at the end so it won't be cleared in
288 * qdio_fill_qs. A page is allocated under this pointer and used for 300 * qdio_fill_qs. A page is allocated under this pointer and used for
@@ -317,12 +329,8 @@ struct qdio_irq {
317 struct qdio_ssqd_desc ssqd_desc; 329 struct qdio_ssqd_desc ssqd_desc;
318 void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *); 330 void (*orig_handler) (struct ccw_device *, unsigned long, struct irb *);
319 331
320 struct qdio_dev_perf_stat perf_stat;
321 int perf_stat_enabled; 332 int perf_stat_enabled;
322 /* 333
323 * Warning: Leave these members together at the end so they won't be
324 * cleared in qdio_setup_irq.
325 */
326 struct qdr *qdr; 334 struct qdr *qdr;
327 unsigned long chsc_page; 335 unsigned long chsc_page;
328 336
@@ -331,6 +339,7 @@ struct qdio_irq {
331 339
332 debug_info_t *debug_area; 340 debug_info_t *debug_area;
333 struct mutex setup_mutex; 341 struct mutex setup_mutex;
342 struct qdio_dev_perf_stat perf_stat;
334}; 343};
335 344
336/* helper functions */ 345/* helper functions */
@@ -341,9 +350,20 @@ struct qdio_irq {
341 (irq->qib.qfmt == QDIO_IQDIO_QFMT || \ 350 (irq->qib.qfmt == QDIO_IQDIO_QFMT || \
342 css_general_characteristics.aif_osa) 351 css_general_characteristics.aif_osa)
343 352
344#define qperf(qdev,attr) qdev->perf_stat.attr 353#define qperf(__qdev, __attr) ((__qdev)->perf_stat.(__attr))
345#define qperf_inc(q,attr) if (q->irq_ptr->perf_stat_enabled) \ 354
346 q->irq_ptr->perf_stat.attr++ 355#define qperf_inc(__q, __attr) \
356({ \
357 struct qdio_irq *qdev = (__q)->irq_ptr; \
358 if (qdev->perf_stat_enabled) \
359 (qdev->perf_stat.__attr)++; \
360})
361
362static inline void account_sbals_error(struct qdio_q *q, int count)
363{
364 q->q_stats.nr_sbal_error += count;
365 q->q_stats.nr_sbal_total += count;
366}
347 367
348/* the highest iqdio queue is used for multicast */ 368/* the highest iqdio queue is used for multicast */
349static inline int multicast_outbound(struct qdio_q *q) 369static inline int multicast_outbound(struct qdio_q *q)
diff --git a/drivers/s390/cio/qdio_debug.c b/drivers/s390/cio/qdio_debug.c
index f49761ff9a00..c94eb2a0fa2e 100644
--- a/drivers/s390/cio/qdio_debug.c
+++ b/drivers/s390/cio/qdio_debug.c
@@ -60,7 +60,7 @@ static int qstat_show(struct seq_file *m, void *v)
60 seq_printf(m, "ftc: %d last_move: %d\n", q->first_to_check, q->last_move); 60 seq_printf(m, "ftc: %d last_move: %d\n", q->first_to_check, q->last_move);
61 seq_printf(m, "polling: %d ack start: %d ack count: %d\n", 61 seq_printf(m, "polling: %d ack start: %d ack count: %d\n",
62 q->u.in.polling, q->u.in.ack_start, q->u.in.ack_count); 62 q->u.in.polling, q->u.in.ack_start, q->u.in.ack_count);
63 seq_printf(m, "slsb buffer states:\n"); 63 seq_printf(m, "SBAL states:\n");
64 seq_printf(m, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n"); 64 seq_printf(m, "|0 |8 |16 |24 |32 |40 |48 |56 63|\n");
65 65
66 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) { 66 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
@@ -97,6 +97,20 @@ static int qstat_show(struct seq_file *m, void *v)
97 } 97 }
98 seq_printf(m, "\n"); 98 seq_printf(m, "\n");
99 seq_printf(m, "|64 |72 |80 |88 |96 |104 |112 | 127|\n"); 99 seq_printf(m, "|64 |72 |80 |88 |96 |104 |112 | 127|\n");
100
101 seq_printf(m, "\nSBAL statistics:");
102 if (!q->irq_ptr->perf_stat_enabled) {
103 seq_printf(m, " disabled\n");
104 return 0;
105 }
106
107 seq_printf(m, "\n1 2.. 4.. 8.. "
108 "16.. 32.. 64.. 127\n");
109 for (i = 0; i < ARRAY_SIZE(q->q_stats.nr_sbals); i++)
110 seq_printf(m, "%-10u ", q->q_stats.nr_sbals[i]);
111 seq_printf(m, "\nError NOP Total\n%-10u %-10u %-10u\n\n",
112 q->q_stats.nr_sbal_error, q->q_stats.nr_sbal_nop,
113 q->q_stats.nr_sbal_total);
100 return 0; 114 return 0;
101} 115}
102 116
@@ -181,9 +195,10 @@ static ssize_t qperf_seq_write(struct file *file, const char __user *ubuf,
181{ 195{
182 struct seq_file *seq = file->private_data; 196 struct seq_file *seq = file->private_data;
183 struct qdio_irq *irq_ptr = seq->private; 197 struct qdio_irq *irq_ptr = seq->private;
198 struct qdio_q *q;
184 unsigned long val; 199 unsigned long val;
185 char buf[8]; 200 char buf[8];
186 int ret; 201 int ret, i;
187 202
188 if (!irq_ptr) 203 if (!irq_ptr)
189 return 0; 204 return 0;
@@ -201,6 +216,10 @@ static ssize_t qperf_seq_write(struct file *file, const char __user *ubuf,
201 case 0: 216 case 0:
202 irq_ptr->perf_stat_enabled = 0; 217 irq_ptr->perf_stat_enabled = 0;
203 memset(&irq_ptr->perf_stat, 0, sizeof(irq_ptr->perf_stat)); 218 memset(&irq_ptr->perf_stat, 0, sizeof(irq_ptr->perf_stat));
219 for_each_input_queue(irq_ptr, q, i)
220 memset(&q->q_stats, 0, sizeof(q->q_stats));
221 for_each_output_queue(irq_ptr, q, i)
222 memset(&q->q_stats, 0, sizeof(q->q_stats));
204 break; 223 break;
205 case 1: 224 case 1:
206 irq_ptr->perf_stat_enabled = 1; 225 irq_ptr->perf_stat_enabled = 1;
diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c
index 62b654af9237..232ef047ba34 100644
--- a/drivers/s390/cio/qdio_main.c
+++ b/drivers/s390/cio/qdio_main.c
@@ -392,6 +392,20 @@ static inline void qdio_stop_polling(struct qdio_q *q)
392 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT); 392 set_buf_state(q, q->u.in.ack_start, SLSB_P_INPUT_NOT_INIT);
393} 393}
394 394
395static inline void account_sbals(struct qdio_q *q, int count)
396{
397 int pos = 0;
398
399 q->q_stats.nr_sbal_total += count;
400 if (count == QDIO_MAX_BUFFERS_MASK) {
401 q->q_stats.nr_sbals[7]++;
402 return;
403 }
404 while (count >>= 1)
405 pos++;
406 q->q_stats.nr_sbals[pos]++;
407}
408
395static void announce_buffer_error(struct qdio_q *q, int count) 409static void announce_buffer_error(struct qdio_q *q, int count)
396{ 410{
397 q->qdio_error |= QDIO_ERROR_SLSB_STATE; 411 q->qdio_error |= QDIO_ERROR_SLSB_STATE;
@@ -487,16 +501,22 @@ static int get_inbound_buffer_frontier(struct qdio_q *q)
487 q->first_to_check = add_buf(q->first_to_check, count); 501 q->first_to_check = add_buf(q->first_to_check, count);
488 if (atomic_sub(count, &q->nr_buf_used) == 0) 502 if (atomic_sub(count, &q->nr_buf_used) == 0)
489 qperf_inc(q, inbound_queue_full); 503 qperf_inc(q, inbound_queue_full);
504 if (q->irq_ptr->perf_stat_enabled)
505 account_sbals(q, count);
490 break; 506 break;
491 case SLSB_P_INPUT_ERROR: 507 case SLSB_P_INPUT_ERROR:
492 announce_buffer_error(q, count); 508 announce_buffer_error(q, count);
493 /* process the buffer, the upper layer will take care of it */ 509 /* process the buffer, the upper layer will take care of it */
494 q->first_to_check = add_buf(q->first_to_check, count); 510 q->first_to_check = add_buf(q->first_to_check, count);
495 atomic_sub(count, &q->nr_buf_used); 511 atomic_sub(count, &q->nr_buf_used);
512 if (q->irq_ptr->perf_stat_enabled)
513 account_sbals_error(q, count);
496 break; 514 break;
497 case SLSB_CU_INPUT_EMPTY: 515 case SLSB_CU_INPUT_EMPTY:
498 case SLSB_P_INPUT_NOT_INIT: 516 case SLSB_P_INPUT_NOT_INIT:
499 case SLSB_P_INPUT_ACK: 517 case SLSB_P_INPUT_ACK:
518 if (q->irq_ptr->perf_stat_enabled)
519 q->q_stats.nr_sbal_nop++;
500 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop"); 520 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in nop");
501 break; 521 break;
502 default: 522 default:
@@ -514,7 +534,7 @@ static int qdio_inbound_q_moved(struct qdio_q *q)
514 534
515 if ((bufnr != q->last_move) || q->qdio_error) { 535 if ((bufnr != q->last_move) || q->qdio_error) {
516 q->last_move = bufnr; 536 q->last_move = bufnr;
517 if (!is_thinint_irq(q->irq_ptr) && !MACHINE_IS_VM) 537 if (!is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
518 q->u.in.timestamp = get_usecs(); 538 q->u.in.timestamp = get_usecs();
519 return 1; 539 return 1;
520 } else 540 } else
@@ -643,15 +663,21 @@ static int get_outbound_buffer_frontier(struct qdio_q *q)
643 663
644 atomic_sub(count, &q->nr_buf_used); 664 atomic_sub(count, &q->nr_buf_used);
645 q->first_to_check = add_buf(q->first_to_check, count); 665 q->first_to_check = add_buf(q->first_to_check, count);
666 if (q->irq_ptr->perf_stat_enabled)
667 account_sbals(q, count);
646 break; 668 break;
647 case SLSB_P_OUTPUT_ERROR: 669 case SLSB_P_OUTPUT_ERROR:
648 announce_buffer_error(q, count); 670 announce_buffer_error(q, count);
649 /* process the buffer, the upper layer will take care of it */ 671 /* process the buffer, the upper layer will take care of it */
650 q->first_to_check = add_buf(q->first_to_check, count); 672 q->first_to_check = add_buf(q->first_to_check, count);
651 atomic_sub(count, &q->nr_buf_used); 673 atomic_sub(count, &q->nr_buf_used);
674 if (q->irq_ptr->perf_stat_enabled)
675 account_sbals_error(q, count);
652 break; 676 break;
653 case SLSB_CU_OUTPUT_PRIMED: 677 case SLSB_CU_OUTPUT_PRIMED:
654 /* the adapter has not fetched the output yet */ 678 /* the adapter has not fetched the output yet */
679 if (q->irq_ptr->perf_stat_enabled)
680 q->q_stats.nr_sbal_nop++;
655 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d", q->nr); 681 DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "out primed:%1d", q->nr);
656 break; 682 break;
657 case SLSB_P_OUTPUT_NOT_INIT: 683 case SLSB_P_OUTPUT_NOT_INIT:
diff --git a/drivers/s390/cio/qdio_setup.c b/drivers/s390/cio/qdio_setup.c
index 8c2dea5fa2b4..7f4a75465140 100644
--- a/drivers/s390/cio/qdio_setup.c
+++ b/drivers/s390/cio/qdio_setup.c
@@ -333,10 +333,10 @@ static void __qdio_allocate_fill_qdr(struct qdio_irq *irq_ptr,
333 irq_ptr->qdr->qdf0[i + nr].slsba = 333 irq_ptr->qdr->qdf0[i + nr].slsba =
334 (unsigned long)&irq_ptr_qs[i]->slsb.val[0]; 334 (unsigned long)&irq_ptr_qs[i]->slsb.val[0];
335 335
336 irq_ptr->qdr->qdf0[i + nr].akey = PAGE_DEFAULT_KEY; 336 irq_ptr->qdr->qdf0[i + nr].akey = PAGE_DEFAULT_KEY >> 4;
337 irq_ptr->qdr->qdf0[i + nr].bkey = PAGE_DEFAULT_KEY; 337 irq_ptr->qdr->qdf0[i + nr].bkey = PAGE_DEFAULT_KEY >> 4;
338 irq_ptr->qdr->qdf0[i + nr].ckey = PAGE_DEFAULT_KEY; 338 irq_ptr->qdr->qdf0[i + nr].ckey = PAGE_DEFAULT_KEY >> 4;
339 irq_ptr->qdr->qdf0[i + nr].dkey = PAGE_DEFAULT_KEY; 339 irq_ptr->qdr->qdf0[i + nr].dkey = PAGE_DEFAULT_KEY >> 4;
340} 340}
341 341
342static void setup_qdr(struct qdio_irq *irq_ptr, 342static void setup_qdr(struct qdio_irq *irq_ptr,
@@ -350,7 +350,7 @@ static void setup_qdr(struct qdio_irq *irq_ptr,
350 irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4; /* size in words */ 350 irq_ptr->qdr->iqdsz = sizeof(struct qdesfmt0) / 4; /* size in words */
351 irq_ptr->qdr->oqdsz = sizeof(struct qdesfmt0) / 4; 351 irq_ptr->qdr->oqdsz = sizeof(struct qdesfmt0) / 4;
352 irq_ptr->qdr->qiba = (unsigned long)&irq_ptr->qib; 352 irq_ptr->qdr->qiba = (unsigned long)&irq_ptr->qib;
353 irq_ptr->qdr->qkey = PAGE_DEFAULT_KEY; 353 irq_ptr->qdr->qkey = PAGE_DEFAULT_KEY >> 4;
354 354
355 for (i = 0; i < qdio_init->no_input_qs; i++) 355 for (i = 0; i < qdio_init->no_input_qs; i++)
356 __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->input_qs, i, 0); 356 __qdio_allocate_fill_qdr(irq_ptr, irq_ptr->input_qs, i, 0);
@@ -382,7 +382,15 @@ int qdio_setup_irq(struct qdio_initialize *init_data)
382 struct qdio_irq *irq_ptr = init_data->cdev->private->qdio_data; 382 struct qdio_irq *irq_ptr = init_data->cdev->private->qdio_data;
383 int rc; 383 int rc;
384 384
385 memset(irq_ptr, 0, ((char *)&irq_ptr->qdr) - ((char *)irq_ptr)); 385 memset(&irq_ptr->qib, 0, sizeof(irq_ptr->qib));
386 memset(&irq_ptr->siga_flag, 0, sizeof(irq_ptr->siga_flag));
387 memset(&irq_ptr->ccw, 0, sizeof(irq_ptr->ccw));
388 memset(&irq_ptr->ssqd_desc, 0, sizeof(irq_ptr->ssqd_desc));
389 memset(&irq_ptr->perf_stat, 0, sizeof(irq_ptr->perf_stat));
390
391 irq_ptr->debugfs_dev = irq_ptr->debugfs_perf = NULL;
392 irq_ptr->sch_token = irq_ptr->state = irq_ptr->perf_stat_enabled = 0;
393
386 /* wipes qib.ac, required by ar7063 */ 394 /* wipes qib.ac, required by ar7063 */
387 memset(irq_ptr->qdr, 0, sizeof(struct qdr)); 395 memset(irq_ptr->qdr, 0, sizeof(struct qdr));
388 396
diff --git a/drivers/s390/cio/qdio_thinint.c b/drivers/s390/cio/qdio_thinint.c
index 091d904d3182..9942c1031b25 100644
--- a/drivers/s390/cio/qdio_thinint.c
+++ b/drivers/s390/cio/qdio_thinint.c
@@ -198,8 +198,8 @@ static int set_subchannel_ind(struct qdio_irq *irq_ptr, int reset)
198 .code = 0x0021, 198 .code = 0x0021,
199 }; 199 };
200 scssc_area->operation_code = 0; 200 scssc_area->operation_code = 0;
201 scssc_area->ks = PAGE_DEFAULT_KEY; 201 scssc_area->ks = PAGE_DEFAULT_KEY >> 4;
202 scssc_area->kc = PAGE_DEFAULT_KEY; 202 scssc_area->kc = PAGE_DEFAULT_KEY >> 4;
203 scssc_area->isc = QDIO_AIRQ_ISC; 203 scssc_area->isc = QDIO_AIRQ_ISC;
204 scssc_area->schid = irq_ptr->schid; 204 scssc_area->schid = irq_ptr->schid;
205 205
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index c68be24e27d9..ba50fe02e572 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -33,6 +33,7 @@
33#include <linux/miscdevice.h> 33#include <linux/miscdevice.h>
34#include <linux/fs.h> 34#include <linux/fs.h>
35#include <linux/proc_fs.h> 35#include <linux/proc_fs.h>
36#include <linux/seq_file.h>
36#include <linux/compat.h> 37#include <linux/compat.h>
37#include <linux/smp_lock.h> 38#include <linux/smp_lock.h>
38#include <asm/atomic.h> 39#include <asm/atomic.h>
@@ -912,126 +913,105 @@ static struct miscdevice zcrypt_misc_device = {
912 */ 913 */
913static struct proc_dir_entry *zcrypt_entry; 914static struct proc_dir_entry *zcrypt_entry;
914 915
915static int sprintcl(unsigned char *outaddr, unsigned char *addr, 916static void sprintcl(struct seq_file *m, unsigned char *addr, unsigned int len)
916 unsigned int len)
917{ 917{
918 int hl, i; 918 int i;
919 919
920 hl = 0;
921 for (i = 0; i < len; i++) 920 for (i = 0; i < len; i++)
922 hl += sprintf(outaddr+hl, "%01x", (unsigned int) addr[i]); 921 seq_printf(m, "%01x", (unsigned int) addr[i]);
923 hl += sprintf(outaddr+hl, " "); 922 seq_putc(m, ' ');
924 return hl;
925} 923}
926 924
927static int sprintrw(unsigned char *outaddr, unsigned char *addr, 925static void sprintrw(struct seq_file *m, unsigned char *addr, unsigned int len)
928 unsigned int len)
929{ 926{
930 int hl, inl, c, cx; 927 int inl, c, cx;
931 928
932 hl = sprintf(outaddr, " "); 929 seq_printf(m, " ");
933 inl = 0; 930 inl = 0;
934 for (c = 0; c < (len / 16); c++) { 931 for (c = 0; c < (len / 16); c++) {
935 hl += sprintcl(outaddr+hl, addr+inl, 16); 932 sprintcl(m, addr+inl, 16);
936 inl += 16; 933 inl += 16;
937 } 934 }
938 cx = len%16; 935 cx = len%16;
939 if (cx) { 936 if (cx) {
940 hl += sprintcl(outaddr+hl, addr+inl, cx); 937 sprintcl(m, addr+inl, cx);
941 inl += cx; 938 inl += cx;
942 } 939 }
943 hl += sprintf(outaddr+hl, "\n"); 940 seq_putc(m, '\n');
944 return hl;
945} 941}
946 942
947static int sprinthx(unsigned char *title, unsigned char *outaddr, 943static void sprinthx(unsigned char *title, struct seq_file *m,
948 unsigned char *addr, unsigned int len) 944 unsigned char *addr, unsigned int len)
949{ 945{
950 int hl, inl, r, rx; 946 int inl, r, rx;
951 947
952 hl = sprintf(outaddr, "\n%s\n", title); 948 seq_printf(m, "\n%s\n", title);
953 inl = 0; 949 inl = 0;
954 for (r = 0; r < (len / 64); r++) { 950 for (r = 0; r < (len / 64); r++) {
955 hl += sprintrw(outaddr+hl, addr+inl, 64); 951 sprintrw(m, addr+inl, 64);
956 inl += 64; 952 inl += 64;
957 } 953 }
958 rx = len % 64; 954 rx = len % 64;
959 if (rx) { 955 if (rx) {
960 hl += sprintrw(outaddr+hl, addr+inl, rx); 956 sprintrw(m, addr+inl, rx);
961 inl += rx; 957 inl += rx;
962 } 958 }
963 hl += sprintf(outaddr+hl, "\n"); 959 seq_putc(m, '\n');
964 return hl;
965} 960}
966 961
967static int sprinthx4(unsigned char *title, unsigned char *outaddr, 962static void sprinthx4(unsigned char *title, struct seq_file *m,
968 unsigned int *array, unsigned int len) 963 unsigned int *array, unsigned int len)
969{ 964{
970 int hl, r; 965 int r;
971 966
972 hl = sprintf(outaddr, "\n%s\n", title); 967 seq_printf(m, "\n%s\n", title);
973 for (r = 0; r < len; r++) { 968 for (r = 0; r < len; r++) {
974 if ((r % 8) == 0) 969 if ((r % 8) == 0)
975 hl += sprintf(outaddr+hl, " "); 970 seq_printf(m, " ");
976 hl += sprintf(outaddr+hl, "%08X ", array[r]); 971 seq_printf(m, "%08X ", array[r]);
977 if ((r % 8) == 7) 972 if ((r % 8) == 7)
978 hl += sprintf(outaddr+hl, "\n"); 973 seq_putc(m, '\n');
979 } 974 }
980 hl += sprintf(outaddr+hl, "\n"); 975 seq_putc(m, '\n');
981 return hl;
982} 976}
983 977
984static int zcrypt_status_read(char *resp_buff, char **start, off_t offset, 978static int zcrypt_proc_show(struct seq_file *m, void *v)
985 int count, int *eof, void *data)
986{ 979{
987 unsigned char *workarea; 980 char workarea[sizeof(int) * AP_DEVICES];
988 int len; 981
989 982 seq_printf(m, "\nzcrypt version: %d.%d.%d\n",
990 len = 0; 983 ZCRYPT_VERSION, ZCRYPT_RELEASE, ZCRYPT_VARIANT);
991 984 seq_printf(m, "Cryptographic domain: %d\n", ap_domain_index);
992 /* resp_buff is a page. Use the right half for a work area */ 985 seq_printf(m, "Total device count: %d\n", zcrypt_device_count);
993 workarea = resp_buff + 2000; 986 seq_printf(m, "PCICA count: %d\n", zcrypt_count_type(ZCRYPT_PCICA));
994 len += sprintf(resp_buff + len, "\nzcrypt version: %d.%d.%d\n", 987 seq_printf(m, "PCICC count: %d\n", zcrypt_count_type(ZCRYPT_PCICC));
995 ZCRYPT_VERSION, ZCRYPT_RELEASE, ZCRYPT_VARIANT); 988 seq_printf(m, "PCIXCC MCL2 count: %d\n",
996 len += sprintf(resp_buff + len, "Cryptographic domain: %d\n", 989 zcrypt_count_type(ZCRYPT_PCIXCC_MCL2));
997 ap_domain_index); 990 seq_printf(m, "PCIXCC MCL3 count: %d\n",
998 len += sprintf(resp_buff + len, "Total device count: %d\n", 991 zcrypt_count_type(ZCRYPT_PCIXCC_MCL3));
999 zcrypt_device_count); 992 seq_printf(m, "CEX2C count: %d\n", zcrypt_count_type(ZCRYPT_CEX2C));
1000 len += sprintf(resp_buff + len, "PCICA count: %d\n", 993 seq_printf(m, "CEX2A count: %d\n", zcrypt_count_type(ZCRYPT_CEX2A));
1001 zcrypt_count_type(ZCRYPT_PCICA)); 994 seq_printf(m, "CEX3C count: %d\n", zcrypt_count_type(ZCRYPT_CEX3C));
1002 len += sprintf(resp_buff + len, "PCICC count: %d\n", 995 seq_printf(m, "CEX3A count: %d\n", zcrypt_count_type(ZCRYPT_CEX3A));
1003 zcrypt_count_type(ZCRYPT_PCICC)); 996 seq_printf(m, "requestq count: %d\n", zcrypt_requestq_count());
1004 len += sprintf(resp_buff + len, "PCIXCC MCL2 count: %d\n", 997 seq_printf(m, "pendingq count: %d\n", zcrypt_pendingq_count());
1005 zcrypt_count_type(ZCRYPT_PCIXCC_MCL2)); 998 seq_printf(m, "Total open handles: %d\n\n",
1006 len += sprintf(resp_buff + len, "PCIXCC MCL3 count: %d\n", 999 atomic_read(&zcrypt_open_count));
1007 zcrypt_count_type(ZCRYPT_PCIXCC_MCL3));
1008 len += sprintf(resp_buff + len, "CEX2C count: %d\n",
1009 zcrypt_count_type(ZCRYPT_CEX2C));
1010 len += sprintf(resp_buff + len, "CEX2A count: %d\n",
1011 zcrypt_count_type(ZCRYPT_CEX2A));
1012 len += sprintf(resp_buff + len, "CEX3C count: %d\n",
1013 zcrypt_count_type(ZCRYPT_CEX3C));
1014 len += sprintf(resp_buff + len, "CEX3A count: %d\n",
1015 zcrypt_count_type(ZCRYPT_CEX3A));
1016 len += sprintf(resp_buff + len, "requestq count: %d\n",
1017 zcrypt_requestq_count());
1018 len += sprintf(resp_buff + len, "pendingq count: %d\n",
1019 zcrypt_pendingq_count());
1020 len += sprintf(resp_buff + len, "Total open handles: %d\n\n",
1021 atomic_read(&zcrypt_open_count));
1022 zcrypt_status_mask(workarea); 1000 zcrypt_status_mask(workarea);
1023 len += sprinthx("Online devices: 1=PCICA 2=PCICC 3=PCIXCC(MCL2) " 1001 sprinthx("Online devices: 1=PCICA 2=PCICC 3=PCIXCC(MCL2) "
1024 "4=PCIXCC(MCL3) 5=CEX2C 6=CEX2A 7=CEX3C 8=CEX3A", 1002 "4=PCIXCC(MCL3) 5=CEX2C 6=CEX2A 7=CEX3C 8=CEX3A",
1025 resp_buff+len, workarea, AP_DEVICES); 1003 m, workarea, AP_DEVICES);
1026 zcrypt_qdepth_mask(workarea); 1004 zcrypt_qdepth_mask(workarea);
1027 len += sprinthx("Waiting work element counts", 1005 sprinthx("Waiting work element counts", m, workarea, AP_DEVICES);
1028 resp_buff+len, workarea, AP_DEVICES);
1029 zcrypt_perdev_reqcnt((int *) workarea); 1006 zcrypt_perdev_reqcnt((int *) workarea);
1030 len += sprinthx4("Per-device successfully completed request counts", 1007 sprinthx4("Per-device successfully completed request counts",
1031 resp_buff+len,(unsigned int *) workarea, AP_DEVICES); 1008 m, (unsigned int *) workarea, AP_DEVICES);
1032 *eof = 1; 1009 return 0;
1033 memset((void *) workarea, 0x00, AP_DEVICES * sizeof(unsigned int)); 1010}
1034 return len; 1011
1012static int zcrypt_proc_open(struct inode *inode, struct file *file)
1013{
1014 return single_open(file, zcrypt_proc_show, NULL);
1035} 1015}
1036 1016
1037static void zcrypt_disable_card(int index) 1017static void zcrypt_disable_card(int index)
@@ -1061,11 +1041,11 @@ static void zcrypt_enable_card(int index)
1061 spin_unlock_bh(&zcrypt_device_lock); 1041 spin_unlock_bh(&zcrypt_device_lock);
1062} 1042}
1063 1043
1064static int zcrypt_status_write(struct file *file, const char __user *buffer, 1044static ssize_t zcrypt_proc_write(struct file *file, const char __user *buffer,
1065 unsigned long count, void *data) 1045 size_t count, loff_t *pos)
1066{ 1046{
1067 unsigned char *lbuf, *ptr; 1047 unsigned char *lbuf, *ptr;
1068 unsigned long local_count; 1048 size_t local_count;
1069 int j; 1049 int j;
1070 1050
1071 if (count <= 0) 1051 if (count <= 0)
@@ -1115,6 +1095,15 @@ out:
1115 return count; 1095 return count;
1116} 1096}
1117 1097
1098static const struct file_operations zcrypt_proc_fops = {
1099 .owner = THIS_MODULE,
1100 .open = zcrypt_proc_open,
1101 .read = seq_read,
1102 .llseek = seq_lseek,
1103 .release = single_release,
1104 .write = zcrypt_proc_write,
1105};
1106
1118static int zcrypt_rng_device_count; 1107static int zcrypt_rng_device_count;
1119static u32 *zcrypt_rng_buffer; 1108static u32 *zcrypt_rng_buffer;
1120static int zcrypt_rng_buffer_index; 1109static int zcrypt_rng_buffer_index;
@@ -1197,14 +1186,11 @@ int __init zcrypt_api_init(void)
1197 goto out; 1186 goto out;
1198 1187
1199 /* Set up the proc file system */ 1188 /* Set up the proc file system */
1200 zcrypt_entry = create_proc_entry("driver/z90crypt", 0644, NULL); 1189 zcrypt_entry = proc_create("driver/z90crypt", 0644, NULL, &zcrypt_proc_fops);
1201 if (!zcrypt_entry) { 1190 if (!zcrypt_entry) {
1202 rc = -ENOMEM; 1191 rc = -ENOMEM;
1203 goto out_misc; 1192 goto out_misc;
1204 } 1193 }
1205 zcrypt_entry->data = NULL;
1206 zcrypt_entry->read_proc = zcrypt_status_read;
1207 zcrypt_entry->write_proc = zcrypt_status_write;
1208 1194
1209 return 0; 1195 return 0;
1210 1196
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 2930fc763ac5..b2fc4fd63f7f 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -340,11 +340,11 @@ static void kvm_extint_handler(u16 code)
340 return; 340 return;
341 341
342 /* The LSB might be overloaded, we have to mask it */ 342 /* The LSB might be overloaded, we have to mask it */
343 vq = (struct virtqueue *) ((*(long *) __LC_PFAULT_INTPARM) & ~1UL); 343 vq = (struct virtqueue *)(S390_lowcore.ext_params2 & ~1UL);
344 344
345 /* We use the LSB of extparam, to decide, if this interrupt is a config 345 /* We use the LSB of extparam, to decide, if this interrupt is a config
346 * change or a "standard" interrupt */ 346 * change or a "standard" interrupt */
347 config_changed = (*(int *) __LC_EXT_PARAMS & 1); 347 config_changed = S390_lowcore.ext_params & 1;
348 348
349 if (config_changed) { 349 if (config_changed) {
350 struct virtio_driver *drv; 350 struct virtio_driver *drv;
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 9d0c941b7d33..66d6c01fcf3e 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Module interface and handling of zfcp data structures. 4 * Module interface and handling of zfcp data structures.
5 * 5 *
6 * Copyright IBM Corporation 2002, 2009 6 * Copyright IBM Corporation 2002, 2010
7 */ 7 */
8 8
9/* 9/*
@@ -32,6 +32,7 @@
32#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#include "zfcp_ext.h" 33#include "zfcp_ext.h"
34#include "zfcp_fc.h" 34#include "zfcp_fc.h"
35#include "zfcp_reqlist.h"
35 36
36#define ZFCP_BUS_ID_SIZE 20 37#define ZFCP_BUS_ID_SIZE 20
37 38
@@ -49,36 +50,6 @@ static struct kmem_cache *zfcp_cache_hw_align(const char *name,
49 return kmem_cache_create(name, size, roundup_pow_of_two(size), 0, NULL); 50 return kmem_cache_create(name, size, roundup_pow_of_two(size), 0, NULL);
50} 51}
51 52
52static int zfcp_reqlist_alloc(struct zfcp_adapter *adapter)
53{
54 int idx;
55
56 adapter->req_list = kcalloc(REQUEST_LIST_SIZE, sizeof(struct list_head),
57 GFP_KERNEL);
58 if (!adapter->req_list)
59 return -ENOMEM;
60
61 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++)
62 INIT_LIST_HEAD(&adapter->req_list[idx]);
63 return 0;
64}
65
66/**
67 * zfcp_reqlist_isempty - is the request list empty
68 * @adapter: pointer to struct zfcp_adapter
69 *
70 * Returns: true if list is empty, false otherwise
71 */
72int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
73{
74 unsigned int idx;
75
76 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++)
77 if (!list_empty(&adapter->req_list[idx]))
78 return 0;
79 return 1;
80}
81
82static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun) 53static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun)
83{ 54{
84 struct ccw_device *cdev; 55 struct ccw_device *cdev;
@@ -110,7 +81,7 @@ static void __init zfcp_init_device_configure(char *busid, u64 wwpn, u64 lun)
110 flush_work(&unit->scsi_work); 81 flush_work(&unit->scsi_work);
111 82
112out_unit: 83out_unit:
113 put_device(&port->sysfs_device); 84 put_device(&port->dev);
114out_port: 85out_port:
115 zfcp_ccw_adapter_put(adapter); 86 zfcp_ccw_adapter_put(adapter);
116out_ccw_device: 87out_ccw_device:
@@ -255,7 +226,7 @@ struct zfcp_unit *zfcp_get_unit_by_lun(struct zfcp_port *port, u64 fcp_lun)
255 read_lock_irqsave(&port->unit_list_lock, flags); 226 read_lock_irqsave(&port->unit_list_lock, flags);
256 list_for_each_entry(unit, &port->unit_list, list) 227 list_for_each_entry(unit, &port->unit_list, list)
257 if (unit->fcp_lun == fcp_lun) { 228 if (unit->fcp_lun == fcp_lun) {
258 if (!get_device(&unit->sysfs_device)) 229 if (!get_device(&unit->dev))
259 unit = NULL; 230 unit = NULL;
260 read_unlock_irqrestore(&port->unit_list_lock, flags); 231 read_unlock_irqrestore(&port->unit_list_lock, flags);
261 return unit; 232 return unit;
@@ -280,7 +251,7 @@ struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
280 read_lock_irqsave(&adapter->port_list_lock, flags); 251 read_lock_irqsave(&adapter->port_list_lock, flags);
281 list_for_each_entry(port, &adapter->port_list, list) 252 list_for_each_entry(port, &adapter->port_list, list)
282 if (port->wwpn == wwpn) { 253 if (port->wwpn == wwpn) {
283 if (!get_device(&port->sysfs_device)) 254 if (!get_device(&port->dev))
284 port = NULL; 255 port = NULL;
285 read_unlock_irqrestore(&adapter->port_list_lock, flags); 256 read_unlock_irqrestore(&adapter->port_list_lock, flags);
286 return port; 257 return port;
@@ -298,10 +269,9 @@ struct zfcp_port *zfcp_get_port_by_wwpn(struct zfcp_adapter *adapter,
298 */ 269 */
299static void zfcp_unit_release(struct device *dev) 270static void zfcp_unit_release(struct device *dev)
300{ 271{
301 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, 272 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
302 sysfs_device);
303 273
304 put_device(&unit->port->sysfs_device); 274 put_device(&unit->port->dev);
305 kfree(unit); 275 kfree(unit);
306} 276}
307 277
@@ -318,11 +288,11 @@ struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun)
318 struct zfcp_unit *unit; 288 struct zfcp_unit *unit;
319 int retval = -ENOMEM; 289 int retval = -ENOMEM;
320 290
321 get_device(&port->sysfs_device); 291 get_device(&port->dev);
322 292
323 unit = zfcp_get_unit_by_lun(port, fcp_lun); 293 unit = zfcp_get_unit_by_lun(port, fcp_lun);
324 if (unit) { 294 if (unit) {
325 put_device(&unit->sysfs_device); 295 put_device(&unit->dev);
326 retval = -EEXIST; 296 retval = -EEXIST;
327 goto err_out; 297 goto err_out;
328 } 298 }
@@ -333,10 +303,10 @@ struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun)
333 303
334 unit->port = port; 304 unit->port = port;
335 unit->fcp_lun = fcp_lun; 305 unit->fcp_lun = fcp_lun;
336 unit->sysfs_device.parent = &port->sysfs_device; 306 unit->dev.parent = &port->dev;
337 unit->sysfs_device.release = zfcp_unit_release; 307 unit->dev.release = zfcp_unit_release;
338 308
339 if (dev_set_name(&unit->sysfs_device, "0x%016llx", 309 if (dev_set_name(&unit->dev, "0x%016llx",
340 (unsigned long long) fcp_lun)) { 310 (unsigned long long) fcp_lun)) {
341 kfree(unit); 311 kfree(unit);
342 goto err_out; 312 goto err_out;
@@ -353,13 +323,12 @@ struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun)
353 unit->latencies.cmd.channel.min = 0xFFFFFFFF; 323 unit->latencies.cmd.channel.min = 0xFFFFFFFF;
354 unit->latencies.cmd.fabric.min = 0xFFFFFFFF; 324 unit->latencies.cmd.fabric.min = 0xFFFFFFFF;
355 325
356 if (device_register(&unit->sysfs_device)) { 326 if (device_register(&unit->dev)) {
357 put_device(&unit->sysfs_device); 327 put_device(&unit->dev);
358 goto err_out; 328 goto err_out;
359 } 329 }
360 330
361 if (sysfs_create_group(&unit->sysfs_device.kobj, 331 if (sysfs_create_group(&unit->dev.kobj, &zfcp_sysfs_unit_attrs))
362 &zfcp_sysfs_unit_attrs))
363 goto err_out_put; 332 goto err_out_put;
364 333
365 write_lock_irq(&port->unit_list_lock); 334 write_lock_irq(&port->unit_list_lock);
@@ -371,9 +340,9 @@ struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *port, u64 fcp_lun)
371 return unit; 340 return unit;
372 341
373err_out_put: 342err_out_put:
374 device_unregister(&unit->sysfs_device); 343 device_unregister(&unit->dev);
375err_out: 344err_out:
376 put_device(&port->sysfs_device); 345 put_device(&port->dev);
377 return ERR_PTR(retval); 346 return ERR_PTR(retval);
378} 347}
379 348
@@ -539,7 +508,8 @@ struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)
539 if (zfcp_allocate_low_mem_buffers(adapter)) 508 if (zfcp_allocate_low_mem_buffers(adapter))
540 goto failed; 509 goto failed;
541 510
542 if (zfcp_reqlist_alloc(adapter)) 511 adapter->req_list = zfcp_reqlist_alloc();
512 if (!adapter->req_list)
543 goto failed; 513 goto failed;
544 514
545 if (zfcp_dbf_adapter_register(adapter)) 515 if (zfcp_dbf_adapter_register(adapter))
@@ -560,8 +530,6 @@ struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)
560 INIT_LIST_HEAD(&adapter->erp_ready_head); 530 INIT_LIST_HEAD(&adapter->erp_ready_head);
561 INIT_LIST_HEAD(&adapter->erp_running_head); 531 INIT_LIST_HEAD(&adapter->erp_running_head);
562 532
563 spin_lock_init(&adapter->req_list_lock);
564
565 rwlock_init(&adapter->erp_lock); 533 rwlock_init(&adapter->erp_lock);
566 rwlock_init(&adapter->abort_lock); 534 rwlock_init(&adapter->abort_lock);
567 535
@@ -640,8 +608,7 @@ void zfcp_device_unregister(struct device *dev,
640 608
641static void zfcp_port_release(struct device *dev) 609static void zfcp_port_release(struct device *dev)
642{ 610{
643 struct zfcp_port *port = container_of(dev, struct zfcp_port, 611 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
644 sysfs_device);
645 612
646 zfcp_ccw_adapter_put(port->adapter); 613 zfcp_ccw_adapter_put(port->adapter);
647 kfree(port); 614 kfree(port);
@@ -669,7 +636,7 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
669 636
670 port = zfcp_get_port_by_wwpn(adapter, wwpn); 637 port = zfcp_get_port_by_wwpn(adapter, wwpn);
671 if (port) { 638 if (port) {
672 put_device(&port->sysfs_device); 639 put_device(&port->dev);
673 retval = -EEXIST; 640 retval = -EEXIST;
674 goto err_out; 641 goto err_out;
675 } 642 }
@@ -689,22 +656,21 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
689 port->d_id = d_id; 656 port->d_id = d_id;
690 port->wwpn = wwpn; 657 port->wwpn = wwpn;
691 port->rport_task = RPORT_NONE; 658 port->rport_task = RPORT_NONE;
692 port->sysfs_device.parent = &adapter->ccw_device->dev; 659 port->dev.parent = &adapter->ccw_device->dev;
693 port->sysfs_device.release = zfcp_port_release; 660 port->dev.release = zfcp_port_release;
694 661
695 if (dev_set_name(&port->sysfs_device, "0x%016llx", 662 if (dev_set_name(&port->dev, "0x%016llx", (unsigned long long)wwpn)) {
696 (unsigned long long)wwpn)) {
697 kfree(port); 663 kfree(port);
698 goto err_out; 664 goto err_out;
699 } 665 }
700 retval = -EINVAL; 666 retval = -EINVAL;
701 667
702 if (device_register(&port->sysfs_device)) { 668 if (device_register(&port->dev)) {
703 put_device(&port->sysfs_device); 669 put_device(&port->dev);
704 goto err_out; 670 goto err_out;
705 } 671 }
706 672
707 if (sysfs_create_group(&port->sysfs_device.kobj, 673 if (sysfs_create_group(&port->dev.kobj,
708 &zfcp_sysfs_port_attrs)) 674 &zfcp_sysfs_port_attrs))
709 goto err_out_put; 675 goto err_out_put;
710 676
@@ -717,7 +683,7 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
717 return port; 683 return port;
718 684
719err_out_put: 685err_out_put:
720 device_unregister(&port->sysfs_device); 686 device_unregister(&port->dev);
721err_out: 687err_out:
722 zfcp_ccw_adapter_put(adapter); 688 zfcp_ccw_adapter_put(adapter);
723 return ERR_PTR(retval); 689 return ERR_PTR(retval);
diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
index c22cb72a5ae8..ce1cc7a11fb4 100644
--- a/drivers/s390/scsi/zfcp_ccw.c
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -3,13 +3,14 @@
3 * 3 *
4 * Registration and callback for the s390 common I/O layer. 4 * Registration and callback for the s390 common I/O layer.
5 * 5 *
6 * Copyright IBM Corporation 2002, 2009 6 * Copyright IBM Corporation 2002, 2010
7 */ 7 */
8 8
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 11
12#include "zfcp_ext.h" 12#include "zfcp_ext.h"
13#include "zfcp_reqlist.h"
13 14
14#define ZFCP_MODEL_PRIV 0x4 15#define ZFCP_MODEL_PRIV 0x4
15 16
@@ -122,12 +123,10 @@ static void zfcp_ccw_remove(struct ccw_device *cdev)
122 zfcp_ccw_adapter_put(adapter); /* put from zfcp_ccw_adapter_by_cdev */ 123 zfcp_ccw_adapter_put(adapter); /* put from zfcp_ccw_adapter_by_cdev */
123 124
124 list_for_each_entry_safe(unit, u, &unit_remove_lh, list) 125 list_for_each_entry_safe(unit, u, &unit_remove_lh, list)
125 zfcp_device_unregister(&unit->sysfs_device, 126 zfcp_device_unregister(&unit->dev, &zfcp_sysfs_unit_attrs);
126 &zfcp_sysfs_unit_attrs);
127 127
128 list_for_each_entry_safe(port, p, &port_remove_lh, list) 128 list_for_each_entry_safe(port, p, &port_remove_lh, list)
129 zfcp_device_unregister(&port->sysfs_device, 129 zfcp_device_unregister(&port->dev, &zfcp_sysfs_port_attrs);
130 &zfcp_sysfs_port_attrs);
131 130
132 zfcp_adapter_unregister(adapter); 131 zfcp_adapter_unregister(adapter);
133} 132}
@@ -162,7 +161,7 @@ static int zfcp_ccw_set_online(struct ccw_device *cdev)
162 } 161 }
163 162
164 /* initialize request counter */ 163 /* initialize request counter */
165 BUG_ON(!zfcp_reqlist_isempty(adapter)); 164 BUG_ON(!zfcp_reqlist_isempty(adapter->req_list));
166 adapter->req_no = 0; 165 adapter->req_no = 0;
167 166
168 zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL, 167 zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL,
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
index 7369c8911bcf..7a149fd85f6d 100644
--- a/drivers/s390/scsi/zfcp_dbf.c
+++ b/drivers/s390/scsi/zfcp_dbf.c
@@ -140,9 +140,9 @@ void _zfcp_dbf_hba_fsf_response(const char *tag2, int level,
140 memcpy(response->fsf_status_qual, 140 memcpy(response->fsf_status_qual,
141 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE); 141 fsf_status_qual, FSF_STATUS_QUALIFIER_SIZE);
142 response->fsf_req_status = fsf_req->status; 142 response->fsf_req_status = fsf_req->status;
143 response->sbal_first = fsf_req->queue_req.sbal_first; 143 response->sbal_first = fsf_req->qdio_req.sbal_first;
144 response->sbal_last = fsf_req->queue_req.sbal_last; 144 response->sbal_last = fsf_req->qdio_req.sbal_last;
145 response->sbal_response = fsf_req->queue_req.sbal_response; 145 response->sbal_response = fsf_req->qdio_req.sbal_response;
146 response->pool = fsf_req->pool != NULL; 146 response->pool = fsf_req->pool != NULL;
147 response->erp_action = (unsigned long)fsf_req->erp_action; 147 response->erp_action = (unsigned long)fsf_req->erp_action;
148 148
@@ -576,7 +576,8 @@ void zfcp_dbf_rec_adapter(char *id, void *ref, struct zfcp_dbf *dbf)
576 struct zfcp_adapter *adapter = dbf->adapter; 576 struct zfcp_adapter *adapter = dbf->adapter;
577 577
578 zfcp_dbf_rec_target(id, ref, dbf, &adapter->status, 578 zfcp_dbf_rec_target(id, ref, dbf, &adapter->status,
579 &adapter->erp_counter, 0, 0, 0); 579 &adapter->erp_counter, 0, 0,
580 ZFCP_DBF_INVALID_LUN);
580} 581}
581 582
582/** 583/**
@@ -590,8 +591,8 @@ void zfcp_dbf_rec_port(char *id, void *ref, struct zfcp_port *port)
590 struct zfcp_dbf *dbf = port->adapter->dbf; 591 struct zfcp_dbf *dbf = port->adapter->dbf;
591 592
592 zfcp_dbf_rec_target(id, ref, dbf, &port->status, 593 zfcp_dbf_rec_target(id, ref, dbf, &port->status,
593 &port->erp_counter, port->wwpn, port->d_id, 594 &port->erp_counter, port->wwpn, port->d_id,
594 0); 595 ZFCP_DBF_INVALID_LUN);
595} 596}
596 597
597/** 598/**
@@ -642,10 +643,9 @@ void zfcp_dbf_rec_trigger(char *id2, void *ref, u8 want, u8 need, void *action,
642 r->u.trigger.ps = atomic_read(&port->status); 643 r->u.trigger.ps = atomic_read(&port->status);
643 r->u.trigger.wwpn = port->wwpn; 644 r->u.trigger.wwpn = port->wwpn;
644 } 645 }
645 if (unit) { 646 if (unit)
646 r->u.trigger.us = atomic_read(&unit->status); 647 r->u.trigger.us = atomic_read(&unit->status);
647 r->u.trigger.fcp_lun = unit->fcp_lun; 648 r->u.trigger.fcp_lun = unit ? unit->fcp_lun : ZFCP_DBF_INVALID_LUN;
648 }
649 debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r)); 649 debug_event(dbf->rec, action ? 1 : 4, r, sizeof(*r));
650 spin_unlock_irqrestore(&dbf->rec_lock, flags); 650 spin_unlock_irqrestore(&dbf->rec_lock, flags);
651} 651}
@@ -668,7 +668,7 @@ void zfcp_dbf_rec_action(char *id2, struct zfcp_erp_action *erp_action)
668 r->u.action.action = (unsigned long)erp_action; 668 r->u.action.action = (unsigned long)erp_action;
669 r->u.action.status = erp_action->status; 669 r->u.action.status = erp_action->status;
670 r->u.action.step = erp_action->step; 670 r->u.action.step = erp_action->step;
671 r->u.action.fsf_req = (unsigned long)erp_action->fsf_req; 671 r->u.action.fsf_req = erp_action->fsf_req_id;
672 debug_event(dbf->rec, 5, r, sizeof(*r)); 672 debug_event(dbf->rec, 5, r, sizeof(*r));
673 spin_unlock_irqrestore(&dbf->rec_lock, flags); 673 spin_unlock_irqrestore(&dbf->rec_lock, flags);
674} 674}
diff --git a/drivers/s390/scsi/zfcp_dbf.h b/drivers/s390/scsi/zfcp_dbf.h
index 8b7fd9a1033e..457e046f2d28 100644
--- a/drivers/s390/scsi/zfcp_dbf.h
+++ b/drivers/s390/scsi/zfcp_dbf.h
@@ -30,6 +30,8 @@
30#define ZFCP_DBF_TAG_SIZE 4 30#define ZFCP_DBF_TAG_SIZE 4
31#define ZFCP_DBF_ID_SIZE 7 31#define ZFCP_DBF_ID_SIZE 7
32 32
33#define ZFCP_DBF_INVALID_LUN 0xFFFFFFFFFFFFFFFFull
34
33struct zfcp_dbf_dump { 35struct zfcp_dbf_dump {
34 u8 tag[ZFCP_DBF_TAG_SIZE]; 36 u8 tag[ZFCP_DBF_TAG_SIZE];
35 u32 total_size; /* size of total dump data */ 37 u32 total_size; /* size of total dump data */
@@ -192,10 +194,10 @@ struct zfcp_dbf_san_record {
192 struct zfcp_dbf_san_record_ct_response ct_resp; 194 struct zfcp_dbf_san_record_ct_response ct_resp;
193 struct zfcp_dbf_san_record_els els; 195 struct zfcp_dbf_san_record_els els;
194 } u; 196 } u;
195#define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
196 u8 payload[32];
197} __attribute__ ((packed)); 197} __attribute__ ((packed));
198 198
199#define ZFCP_DBF_SAN_MAX_PAYLOAD 1024
200
199struct zfcp_dbf_scsi_record { 201struct zfcp_dbf_scsi_record {
200 u8 tag[ZFCP_DBF_TAG_SIZE]; 202 u8 tag[ZFCP_DBF_TAG_SIZE];
201 u8 tag2[ZFCP_DBF_TAG_SIZE]; 203 u8 tag2[ZFCP_DBF_TAG_SIZE];
@@ -301,17 +303,31 @@ void zfcp_dbf_scsi(const char *tag, const char *tag2, int level,
301 303
302/** 304/**
303 * zfcp_dbf_scsi_result - trace event for SCSI command completion 305 * zfcp_dbf_scsi_result - trace event for SCSI command completion
304 * @tag: tag indicating success or failure of SCSI command 306 * @dbf: adapter dbf trace
305 * @level: trace level applicable for this event 307 * @scmd: SCSI command pointer
306 * @adapter: adapter that has been used to issue the SCSI command 308 * @req: FSF request used to issue SCSI command
309 */
310static inline
311void zfcp_dbf_scsi_result(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd,
312 struct zfcp_fsf_req *req)
313{
314 if (scmd->result != 0)
315 zfcp_dbf_scsi("rslt", "erro", 3, dbf, scmd, req, 0);
316 else if (scmd->retries > 0)
317 zfcp_dbf_scsi("rslt", "retr", 4, dbf, scmd, req, 0);
318 else
319 zfcp_dbf_scsi("rslt", "norm", 6, dbf, scmd, req, 0);
320}
321
322/**
323 * zfcp_dbf_scsi_fail_send - trace event for failure to send SCSI command
324 * @dbf: adapter dbf trace
307 * @scmd: SCSI command pointer 325 * @scmd: SCSI command pointer
308 * @fsf_req: request used to issue SCSI command (might be NULL)
309 */ 326 */
310static inline 327static inline
311void zfcp_dbf_scsi_result(const char *tag, int level, struct zfcp_dbf *dbf, 328void zfcp_dbf_scsi_fail_send(struct zfcp_dbf *dbf, struct scsi_cmnd *scmd)
312 struct scsi_cmnd *scmd, struct zfcp_fsf_req *fsf_req)
313{ 329{
314 zfcp_dbf_scsi("rslt", tag, level, dbf, scmd, fsf_req, 0); 330 zfcp_dbf_scsi("rslt", "fail", 4, dbf, scmd, NULL, 0);
315} 331}
316 332
317/** 333/**
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index e1b5b88e2ddb..7131c7db1f04 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * Global definitions for the zfcp device driver. 4 * Global definitions for the zfcp device driver.
5 * 5 *
6 * Copyright IBM Corporation 2002, 2009 6 * Copyright IBM Corporation 2002, 2010
7 */ 7 */
8 8
9#ifndef ZFCP_DEF_H 9#ifndef ZFCP_DEF_H
@@ -33,15 +33,13 @@
33#include <scsi/scsi_transport_fc.h> 33#include <scsi/scsi_transport_fc.h>
34#include <scsi/scsi_bsg_fc.h> 34#include <scsi/scsi_bsg_fc.h>
35#include <asm/ccwdev.h> 35#include <asm/ccwdev.h>
36#include <asm/qdio.h>
37#include <asm/debug.h> 36#include <asm/debug.h>
38#include <asm/ebcdic.h> 37#include <asm/ebcdic.h>
39#include <asm/sysinfo.h> 38#include <asm/sysinfo.h>
40#include "zfcp_fsf.h" 39#include "zfcp_fsf.h"
40#include "zfcp_qdio.h"
41 41
42/********************* GENERAL DEFINES *********************************/ 42struct zfcp_reqlist;
43
44#define REQUEST_LIST_SIZE 128
45 43
46/********************* SCSI SPECIFIC DEFINES *********************************/ 44/********************* SCSI SPECIFIC DEFINES *********************************/
47#define ZFCP_SCSI_ER_TIMEOUT (10*HZ) 45#define ZFCP_SCSI_ER_TIMEOUT (10*HZ)
@@ -129,12 +127,6 @@ struct zfcp_adapter_mempool {
129 mempool_t *qtcb_pool; 127 mempool_t *qtcb_pool;
130}; 128};
131 129
132struct zfcp_qdio_queue {
133 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
134 u8 first; /* index of next free bfr in queue */
135 atomic_t count; /* number of free buffers in queue */
136};
137
138struct zfcp_erp_action { 130struct zfcp_erp_action {
139 struct list_head list; 131 struct list_head list;
140 int action; /* requested action code */ 132 int action; /* requested action code */
@@ -143,8 +135,7 @@ struct zfcp_erp_action {
143 struct zfcp_unit *unit; 135 struct zfcp_unit *unit;
144 u32 status; /* recovery status */ 136 u32 status; /* recovery status */
145 u32 step; /* active step of this erp action */ 137 u32 step; /* active step of this erp action */
146 struct zfcp_fsf_req *fsf_req; /* fsf request currently pending 138 unsigned long fsf_req_id;
147 for this action */
148 struct timer_list timer; 139 struct timer_list timer;
149}; 140};
150 141
@@ -167,29 +158,6 @@ struct zfcp_latencies {
167 spinlock_t lock; 158 spinlock_t lock;
168}; 159};
169 160
170/** struct zfcp_qdio - basic QDIO data structure
171 * @resp_q: response queue
172 * @req_q: request queue
173 * @stat_lock: lock to protect req_q_util and req_q_time
174 * @req_q_lock; lock to serialize access to request queue
175 * @req_q_time: time of last fill level change
176 * @req_q_util: used for accounting
177 * @req_q_full: queue full incidents
178 * @req_q_wq: used to wait for SBAL availability
179 * @adapter: adapter used in conjunction with this QDIO structure
180 */
181struct zfcp_qdio {
182 struct zfcp_qdio_queue resp_q;
183 struct zfcp_qdio_queue req_q;
184 spinlock_t stat_lock;
185 spinlock_t req_q_lock;
186 unsigned long long req_q_time;
187 u64 req_q_util;
188 atomic_t req_q_full;
189 wait_queue_head_t req_q_wq;
190 struct zfcp_adapter *adapter;
191};
192
193struct zfcp_adapter { 161struct zfcp_adapter {
194 struct kref ref; 162 struct kref ref;
195 u64 peer_wwnn; /* P2P peer WWNN */ 163 u64 peer_wwnn; /* P2P peer WWNN */
@@ -207,8 +175,7 @@ struct zfcp_adapter {
207 struct list_head port_list; /* remote port list */ 175 struct list_head port_list; /* remote port list */
208 rwlock_t port_list_lock; /* port list lock */ 176 rwlock_t port_list_lock; /* port list lock */
209 unsigned long req_no; /* unique FSF req number */ 177 unsigned long req_no; /* unique FSF req number */
210 struct list_head *req_list; /* list of pending reqs */ 178 struct zfcp_reqlist *req_list;
211 spinlock_t req_list_lock; /* request list lock */
212 u32 fsf_req_seq_no; /* FSF cmnd seq number */ 179 u32 fsf_req_seq_no; /* FSF cmnd seq number */
213 rwlock_t abort_lock; /* Protects against SCSI 180 rwlock_t abort_lock; /* Protects against SCSI
214 stack abort/command 181 stack abort/command
@@ -241,7 +208,7 @@ struct zfcp_adapter {
241}; 208};
242 209
243struct zfcp_port { 210struct zfcp_port {
244 struct device sysfs_device; /* sysfs device */ 211 struct device dev;
245 struct fc_rport *rport; /* rport of fc transport class */ 212 struct fc_rport *rport; /* rport of fc transport class */
246 struct list_head list; /* list of remote ports */ 213 struct list_head list; /* list of remote ports */
247 struct zfcp_adapter *adapter; /* adapter used to access port */ 214 struct zfcp_adapter *adapter; /* adapter used to access port */
@@ -263,7 +230,7 @@ struct zfcp_port {
263}; 230};
264 231
265struct zfcp_unit { 232struct zfcp_unit {
266 struct device sysfs_device; /* sysfs device */ 233 struct device dev;
267 struct list_head list; /* list of logical units */ 234 struct list_head list; /* list of logical units */
268 struct zfcp_port *port; /* remote port of unit */ 235 struct zfcp_port *port; /* remote port of unit */
269 atomic_t status; /* status of this logical unit */ 236 atomic_t status; /* status of this logical unit */
@@ -277,33 +244,11 @@ struct zfcp_unit {
277}; 244};
278 245
279/** 246/**
280 * struct zfcp_queue_req - queue related values for a request
281 * @sbal_number: number of free SBALs
282 * @sbal_first: first SBAL for this request
283 * @sbal_last: last SBAL for this request
284 * @sbal_limit: last possible SBAL for this request
285 * @sbale_curr: current SBALE at creation of this request
286 * @sbal_response: SBAL used in interrupt
287 * @qdio_outb_usage: usage of outbound queue
288 * @qdio_inb_usage: usage of inbound queue
289 */
290struct zfcp_queue_req {
291 u8 sbal_number;
292 u8 sbal_first;
293 u8 sbal_last;
294 u8 sbal_limit;
295 u8 sbale_curr;
296 u8 sbal_response;
297 u16 qdio_outb_usage;
298 u16 qdio_inb_usage;
299};
300
301/**
302 * struct zfcp_fsf_req - basic FSF request structure 247 * struct zfcp_fsf_req - basic FSF request structure
303 * @list: list of FSF requests 248 * @list: list of FSF requests
304 * @req_id: unique request ID 249 * @req_id: unique request ID
305 * @adapter: adapter this request belongs to 250 * @adapter: adapter this request belongs to
306 * @queue_req: queue related values 251 * @qdio_req: qdio queue related values
307 * @completion: used to signal the completion of the request 252 * @completion: used to signal the completion of the request
308 * @status: status of the request 253 * @status: status of the request
309 * @fsf_command: FSF command issued 254 * @fsf_command: FSF command issued
@@ -321,7 +266,7 @@ struct zfcp_fsf_req {
321 struct list_head list; 266 struct list_head list;
322 unsigned long req_id; 267 unsigned long req_id;
323 struct zfcp_adapter *adapter; 268 struct zfcp_adapter *adapter;
324 struct zfcp_queue_req queue_req; 269 struct zfcp_qdio_req qdio_req;
325 struct completion completion; 270 struct completion completion;
326 u32 status; 271 u32 status;
327 u32 fsf_command; 272 u32 fsf_command;
@@ -352,45 +297,4 @@ struct zfcp_data {
352#define ZFCP_SET 0x00000100 297#define ZFCP_SET 0x00000100
353#define ZFCP_CLEAR 0x00000200 298#define ZFCP_CLEAR 0x00000200
354 299
355/*
356 * Helper functions for request ID management.
357 */
358static inline int zfcp_reqlist_hash(unsigned long req_id)
359{
360 return req_id % REQUEST_LIST_SIZE;
361}
362
363static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
364 struct zfcp_fsf_req *fsf_req)
365{
366 list_del(&fsf_req->list);
367}
368
369static inline struct zfcp_fsf_req *
370zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
371{
372 struct zfcp_fsf_req *request;
373 unsigned int idx;
374
375 idx = zfcp_reqlist_hash(req_id);
376 list_for_each_entry(request, &adapter->req_list[idx], list)
377 if (request->req_id == req_id)
378 return request;
379 return NULL;
380}
381
382static inline struct zfcp_fsf_req *
383zfcp_reqlist_find_safe(struct zfcp_adapter *adapter, struct zfcp_fsf_req *req)
384{
385 struct zfcp_fsf_req *request;
386 unsigned int idx;
387
388 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++) {
389 list_for_each_entry(request, &adapter->req_list[idx], list)
390 if (request == req)
391 return request;
392 }
393 return NULL;
394}
395
396#endif /* ZFCP_DEF_H */ 300#endif /* ZFCP_DEF_H */
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index b51a11a82e63..0be5e7ea2828 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Error Recovery Procedures (ERP). 4 * Error Recovery Procedures (ERP).
5 * 5 *
6 * Copyright IBM Corporation 2002, 2009 6 * Copyright IBM Corporation 2002, 2010
7 */ 7 */
8 8
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
@@ -11,6 +11,7 @@
11 11
12#include <linux/kthread.h> 12#include <linux/kthread.h>
13#include "zfcp_ext.h" 13#include "zfcp_ext.h"
14#include "zfcp_reqlist.h"
14 15
15#define ZFCP_MAX_ERPS 3 16#define ZFCP_MAX_ERPS 3
16 17
@@ -174,7 +175,7 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
174 175
175 switch (need) { 176 switch (need) {
176 case ZFCP_ERP_ACTION_REOPEN_UNIT: 177 case ZFCP_ERP_ACTION_REOPEN_UNIT:
177 if (!get_device(&unit->sysfs_device)) 178 if (!get_device(&unit->dev))
178 return NULL; 179 return NULL;
179 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status); 180 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
180 erp_action = &unit->erp_action; 181 erp_action = &unit->erp_action;
@@ -184,7 +185,7 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
184 185
185 case ZFCP_ERP_ACTION_REOPEN_PORT: 186 case ZFCP_ERP_ACTION_REOPEN_PORT:
186 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: 187 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
187 if (!get_device(&port->sysfs_device)) 188 if (!get_device(&port->dev))
188 return NULL; 189 return NULL;
189 zfcp_erp_action_dismiss_port(port); 190 zfcp_erp_action_dismiss_port(port);
190 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status); 191 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
@@ -478,26 +479,27 @@ static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
478static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act) 479static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
479{ 480{
480 struct zfcp_adapter *adapter = act->adapter; 481 struct zfcp_adapter *adapter = act->adapter;
482 struct zfcp_fsf_req *req;
481 483
482 if (!act->fsf_req) 484 if (!act->fsf_req_id)
483 return; 485 return;
484 486
485 spin_lock(&adapter->req_list_lock); 487 spin_lock(&adapter->req_list->lock);
486 if (zfcp_reqlist_find_safe(adapter, act->fsf_req) && 488 req = _zfcp_reqlist_find(adapter->req_list, act->fsf_req_id);
487 act->fsf_req->erp_action == act) { 489 if (req && req->erp_action == act) {
488 if (act->status & (ZFCP_STATUS_ERP_DISMISSED | 490 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
489 ZFCP_STATUS_ERP_TIMEDOUT)) { 491 ZFCP_STATUS_ERP_TIMEDOUT)) {
490 act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; 492 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
491 zfcp_dbf_rec_action("erscf_1", act); 493 zfcp_dbf_rec_action("erscf_1", act);
492 act->fsf_req->erp_action = NULL; 494 req->erp_action = NULL;
493 } 495 }
494 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT) 496 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
495 zfcp_dbf_rec_action("erscf_2", act); 497 zfcp_dbf_rec_action("erscf_2", act);
496 if (act->fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) 498 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
497 act->fsf_req = NULL; 499 act->fsf_req_id = 0;
498 } else 500 } else
499 act->fsf_req = NULL; 501 act->fsf_req_id = 0;
500 spin_unlock(&adapter->req_list_lock); 502 spin_unlock(&adapter->req_list->lock);
501} 503}
502 504
503/** 505/**
@@ -1179,19 +1181,19 @@ static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
1179 switch (act->action) { 1181 switch (act->action) {
1180 case ZFCP_ERP_ACTION_REOPEN_UNIT: 1182 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1181 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) { 1183 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
1182 get_device(&unit->sysfs_device); 1184 get_device(&unit->dev);
1183 if (scsi_queue_work(unit->port->adapter->scsi_host, 1185 if (scsi_queue_work(unit->port->adapter->scsi_host,
1184 &unit->scsi_work) <= 0) 1186 &unit->scsi_work) <= 0)
1185 put_device(&unit->sysfs_device); 1187 put_device(&unit->dev);
1186 } 1188 }
1187 put_device(&unit->sysfs_device); 1189 put_device(&unit->dev);
1188 break; 1190 break;
1189 1191
1190 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: 1192 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1191 case ZFCP_ERP_ACTION_REOPEN_PORT: 1193 case ZFCP_ERP_ACTION_REOPEN_PORT:
1192 if (result == ZFCP_ERP_SUCCEEDED) 1194 if (result == ZFCP_ERP_SUCCEEDED)
1193 zfcp_scsi_schedule_rport_register(port); 1195 zfcp_scsi_schedule_rport_register(port);
1194 put_device(&port->sysfs_device); 1196 put_device(&port->dev);
1195 break; 1197 break;
1196 1198
1197 case ZFCP_ERP_ACTION_REOPEN_ADAPTER: 1199 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index 66bdb34143cb..8786a79c7f8f 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -21,7 +21,6 @@ extern struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *);
21extern struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *, u64, u32, 21extern struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *, u64, u32,
22 u32); 22 u32);
23extern struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *, u64); 23extern struct zfcp_unit *zfcp_unit_enqueue(struct zfcp_port *, u64);
24extern int zfcp_reqlist_isempty(struct zfcp_adapter *);
25extern void zfcp_sg_free_table(struct scatterlist *, int); 24extern void zfcp_sg_free_table(struct scatterlist *, int);
26extern int zfcp_sg_setup_table(struct scatterlist *, int); 25extern int zfcp_sg_setup_table(struct scatterlist *, int);
27extern void zfcp_device_unregister(struct device *, 26extern void zfcp_device_unregister(struct device *,
@@ -144,13 +143,9 @@ extern void zfcp_fsf_reqid_check(struct zfcp_qdio *, int);
144/* zfcp_qdio.c */ 143/* zfcp_qdio.c */
145extern int zfcp_qdio_setup(struct zfcp_adapter *); 144extern int zfcp_qdio_setup(struct zfcp_adapter *);
146extern void zfcp_qdio_destroy(struct zfcp_qdio *); 145extern void zfcp_qdio_destroy(struct zfcp_qdio *);
147extern int zfcp_qdio_send(struct zfcp_qdio *, struct zfcp_queue_req *); 146extern int zfcp_qdio_send(struct zfcp_qdio *, struct zfcp_qdio_req *);
148extern struct qdio_buffer_element
149 *zfcp_qdio_sbale_req(struct zfcp_qdio *, struct zfcp_queue_req *);
150extern struct qdio_buffer_element
151 *zfcp_qdio_sbale_curr(struct zfcp_qdio *, struct zfcp_queue_req *);
152extern int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *, 147extern int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *,
153 struct zfcp_queue_req *, unsigned long, 148 struct zfcp_qdio_req *, unsigned long,
154 struct scatterlist *, int); 149 struct scatterlist *, int);
155extern int zfcp_qdio_open(struct zfcp_qdio *); 150extern int zfcp_qdio_open(struct zfcp_qdio *);
156extern void zfcp_qdio_close(struct zfcp_qdio *); 151extern void zfcp_qdio_close(struct zfcp_qdio *);
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index 271399f62f1b..5219670f0c99 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Fibre Channel related functions for the zfcp device driver. 4 * Fibre Channel related functions for the zfcp device driver.
5 * 5 *
6 * Copyright IBM Corporation 2008, 2009 6 * Copyright IBM Corporation 2008, 2010
7 */ 7 */
8 8
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
@@ -316,7 +316,7 @@ void zfcp_fc_port_did_lookup(struct work_struct *work)
316 316
317 zfcp_erp_port_reopen(port, 0, "fcgpn_3", NULL); 317 zfcp_erp_port_reopen(port, 0, "fcgpn_3", NULL);
318out: 318out:
319 put_device(&port->sysfs_device); 319 put_device(&port->dev);
320} 320}
321 321
322/** 322/**
@@ -325,9 +325,9 @@ out:
325 */ 325 */
326void zfcp_fc_trigger_did_lookup(struct zfcp_port *port) 326void zfcp_fc_trigger_did_lookup(struct zfcp_port *port)
327{ 327{
328 get_device(&port->sysfs_device); 328 get_device(&port->dev);
329 if (!queue_work(port->adapter->work_queue, &port->gid_pn_work)) 329 if (!queue_work(port->adapter->work_queue, &port->gid_pn_work))
330 put_device(&port->sysfs_device); 330 put_device(&port->dev);
331} 331}
332 332
333/** 333/**
@@ -389,7 +389,7 @@ static void zfcp_fc_adisc_handler(void *data)
389 zfcp_scsi_schedule_rport_register(port); 389 zfcp_scsi_schedule_rport_register(port);
390 out: 390 out:
391 atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status); 391 atomic_clear_mask(ZFCP_STATUS_PORT_LINK_TEST, &port->status);
392 put_device(&port->sysfs_device); 392 put_device(&port->dev);
393 kmem_cache_free(zfcp_data.adisc_cache, adisc); 393 kmem_cache_free(zfcp_data.adisc_cache, adisc);
394} 394}
395 395
@@ -436,7 +436,7 @@ void zfcp_fc_link_test_work(struct work_struct *work)
436 container_of(work, struct zfcp_port, test_link_work); 436 container_of(work, struct zfcp_port, test_link_work);
437 int retval; 437 int retval;
438 438
439 get_device(&port->sysfs_device); 439 get_device(&port->dev);
440 port->rport_task = RPORT_DEL; 440 port->rport_task = RPORT_DEL;
441 zfcp_scsi_rport_work(&port->rport_work); 441 zfcp_scsi_rport_work(&port->rport_work);
442 442
@@ -455,7 +455,7 @@ void zfcp_fc_link_test_work(struct work_struct *work)
455 zfcp_erp_port_forced_reopen(port, 0, "fcltwk1", NULL); 455 zfcp_erp_port_forced_reopen(port, 0, "fcltwk1", NULL);
456 456
457out: 457out:
458 put_device(&port->sysfs_device); 458 put_device(&port->dev);
459} 459}
460 460
461/** 461/**
@@ -468,9 +468,9 @@ out:
468 */ 468 */
469void zfcp_fc_test_link(struct zfcp_port *port) 469void zfcp_fc_test_link(struct zfcp_port *port)
470{ 470{
471 get_device(&port->sysfs_device); 471 get_device(&port->dev);
472 if (!queue_work(port->adapter->work_queue, &port->test_link_work)) 472 if (!queue_work(port->adapter->work_queue, &port->test_link_work))
473 put_device(&port->sysfs_device); 473 put_device(&port->dev);
474} 474}
475 475
476static void zfcp_free_sg_env(struct zfcp_fc_gpn_ft *gpn_ft, int buf_num) 476static void zfcp_free_sg_env(struct zfcp_fc_gpn_ft *gpn_ft, int buf_num)
@@ -617,8 +617,7 @@ static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_gpn_ft *gpn_ft,
617 617
618 list_for_each_entry_safe(port, tmp, &remove_lh, list) { 618 list_for_each_entry_safe(port, tmp, &remove_lh, list) {
619 zfcp_erp_port_shutdown(port, 0, "fcegpf2", NULL); 619 zfcp_erp_port_shutdown(port, 0, "fcegpf2", NULL);
620 zfcp_device_unregister(&port->sysfs_device, 620 zfcp_device_unregister(&port->dev, &zfcp_sysfs_port_attrs);
621 &zfcp_sysfs_port_attrs);
622 } 621 }
623 622
624 return ret; 623 return ret;
@@ -731,7 +730,7 @@ static int zfcp_fc_exec_els_job(struct fc_bsg_job *job,
731 return -EINVAL; 730 return -EINVAL;
732 731
733 d_id = port->d_id; 732 d_id = port->d_id;
734 put_device(&port->sysfs_device); 733 put_device(&port->dev);
735 } else 734 } else
736 d_id = ntoh24(job->request->rqst_data.h_els.port_id); 735 d_id = ntoh24(job->request->rqst_data.h_els.port_id);
737 736
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index e8fb4d9baa8b..6538742b421a 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Implementation of FSF commands. 4 * Implementation of FSF commands.
5 * 5 *
6 * Copyright IBM Corporation 2002, 2009 6 * Copyright IBM Corporation 2002, 2010
7 */ 7 */
8 8
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
@@ -14,6 +14,8 @@
14#include "zfcp_ext.h" 14#include "zfcp_ext.h"
15#include "zfcp_fc.h" 15#include "zfcp_fc.h"
16#include "zfcp_dbf.h" 16#include "zfcp_dbf.h"
17#include "zfcp_qdio.h"
18#include "zfcp_reqlist.h"
17 19
18static void zfcp_fsf_request_timeout_handler(unsigned long data) 20static void zfcp_fsf_request_timeout_handler(unsigned long data)
19{ 21{
@@ -393,7 +395,7 @@ static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
393 case FSF_PROT_LINK_DOWN: 395 case FSF_PROT_LINK_DOWN:
394 zfcp_fsf_link_down_info_eval(req, "fspse_5", 396 zfcp_fsf_link_down_info_eval(req, "fspse_5",
395 &psq->link_down_info); 397 &psq->link_down_info);
396 /* FIXME: reopening adapter now? better wait for link up */ 398 /* go through reopen to flush pending requests */
397 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req); 399 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
398 break; 400 break;
399 case FSF_PROT_REEST_QUEUE: 401 case FSF_PROT_REEST_QUEUE:
@@ -457,15 +459,10 @@ static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
457void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) 459void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
458{ 460{
459 struct zfcp_fsf_req *req, *tmp; 461 struct zfcp_fsf_req *req, *tmp;
460 unsigned long flags;
461 LIST_HEAD(remove_queue); 462 LIST_HEAD(remove_queue);
462 unsigned int i;
463 463
464 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP); 464 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
465 spin_lock_irqsave(&adapter->req_list_lock, flags); 465 zfcp_reqlist_move(adapter->req_list, &remove_queue);
466 for (i = 0; i < REQUEST_LIST_SIZE; i++)
467 list_splice_init(&adapter->req_list[i], &remove_queue);
468 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
469 466
470 list_for_each_entry_safe(req, tmp, &remove_queue, list) { 467 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
471 list_del(&req->list); 468 list_del(&req->list);
@@ -495,8 +492,6 @@ static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
495 fc_host_port_id(shost) = ntoh24(bottom->s_id); 492 fc_host_port_id(shost) = ntoh24(bottom->s_id);
496 fc_host_speed(shost) = bottom->fc_link_speed; 493 fc_host_speed(shost) = bottom->fc_link_speed;
497 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; 494 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
498 fc_host_supported_fc4s(shost)[2] = 1; /* FCP */
499 fc_host_active_fc4s(shost)[2] = 1; /* FCP */
500 495
501 adapter->hydra_version = bottom->adapter_type; 496 adapter->hydra_version = bottom->adapter_type;
502 adapter->timer_ticks = bottom->timer_interval; 497 adapter->timer_ticks = bottom->timer_interval;
@@ -619,6 +614,10 @@ static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
619 fc_host_permanent_port_name(shost) = fc_host_port_name(shost); 614 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
620 fc_host_maxframe_size(shost) = bottom->maximum_frame_size; 615 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
621 fc_host_supported_speeds(shost) = bottom->supported_speed; 616 fc_host_supported_speeds(shost) = bottom->supported_speed;
617 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
618 FC_FC4_LIST_SIZE);
619 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
620 FC_FC4_LIST_SIZE);
622} 621}
623 622
624static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req) 623static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
@@ -725,12 +724,12 @@ static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
725 req->adapter = adapter; 724 req->adapter = adapter;
726 req->fsf_command = fsf_cmd; 725 req->fsf_command = fsf_cmd;
727 req->req_id = adapter->req_no; 726 req->req_id = adapter->req_no;
728 req->queue_req.sbal_number = 1; 727 req->qdio_req.sbal_number = 1;
729 req->queue_req.sbal_first = req_q->first; 728 req->qdio_req.sbal_first = req_q->first;
730 req->queue_req.sbal_last = req_q->first; 729 req->qdio_req.sbal_last = req_q->first;
731 req->queue_req.sbale_curr = 1; 730 req->qdio_req.sbale_curr = 1;
732 731
733 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 732 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
734 sbale[0].addr = (void *) req->req_id; 733 sbale[0].addr = (void *) req->req_id;
735 sbale[0].flags |= SBAL_FLAGS0_COMMAND; 734 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
736 735
@@ -745,6 +744,7 @@ static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
745 return ERR_PTR(-ENOMEM); 744 return ERR_PTR(-ENOMEM);
746 } 745 }
747 746
747 req->seq_no = adapter->fsf_req_seq_no;
748 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; 748 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
749 req->qtcb->prefix.req_id = req->req_id; 749 req->qtcb->prefix.req_id = req->req_id;
750 req->qtcb->prefix.ulp_info = 26; 750 req->qtcb->prefix.ulp_info = 26;
@@ -752,8 +752,6 @@ static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
752 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION; 752 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
753 req->qtcb->header.req_handle = req->req_id; 753 req->qtcb->header.req_handle = req->req_id;
754 req->qtcb->header.fsf_command = req->fsf_command; 754 req->qtcb->header.fsf_command = req->fsf_command;
755 req->seq_no = adapter->fsf_req_seq_no;
756 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
757 sbale[1].addr = (void *) req->qtcb; 755 sbale[1].addr = (void *) req->qtcb;
758 sbale[1].length = sizeof(struct fsf_qtcb); 756 sbale[1].length = sizeof(struct fsf_qtcb);
759 } 757 }
@@ -770,25 +768,17 @@ static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
770{ 768{
771 struct zfcp_adapter *adapter = req->adapter; 769 struct zfcp_adapter *adapter = req->adapter;
772 struct zfcp_qdio *qdio = adapter->qdio; 770 struct zfcp_qdio *qdio = adapter->qdio;
773 unsigned long flags; 771 int with_qtcb = (req->qtcb != NULL);
774 int idx; 772 int req_id = req->req_id;
775 int with_qtcb = (req->qtcb != NULL);
776 773
777 /* put allocated FSF request into hash table */ 774 zfcp_reqlist_add(adapter->req_list, req);
778 spin_lock_irqsave(&adapter->req_list_lock, flags);
779 idx = zfcp_reqlist_hash(req->req_id);
780 list_add_tail(&req->list, &adapter->req_list[idx]);
781 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
782 775
783 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count); 776 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
784 req->issued = get_clock(); 777 req->issued = get_clock();
785 if (zfcp_qdio_send(qdio, &req->queue_req)) { 778 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
786 del_timer(&req->timer); 779 del_timer(&req->timer);
787 spin_lock_irqsave(&adapter->req_list_lock, flags);
788 /* lookup request again, list might have changed */ 780 /* lookup request again, list might have changed */
789 if (zfcp_reqlist_find_safe(adapter, req)) 781 zfcp_reqlist_find_rm(adapter->req_list, req_id);
790 zfcp_reqlist_remove(adapter, req);
791 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
792 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req); 782 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
793 return -EIO; 783 return -EIO;
794 } 784 }
@@ -826,9 +816,9 @@ int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
826 goto out; 816 goto out;
827 } 817 }
828 818
829 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 819 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
830 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY; 820 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
831 req->queue_req.sbale_curr = 2; 821 req->qdio_req.sbale_curr = 2;
832 822
833 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC); 823 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
834 if (!sr_buf) { 824 if (!sr_buf) {
@@ -837,7 +827,7 @@ int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
837 } 827 }
838 memset(sr_buf, 0, sizeof(*sr_buf)); 828 memset(sr_buf, 0, sizeof(*sr_buf));
839 req->data = sr_buf; 829 req->data = sr_buf;
840 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req); 830 sbale = zfcp_qdio_sbale_curr(qdio, &req->qdio_req);
841 sbale->addr = (void *) sr_buf; 831 sbale->addr = (void *) sr_buf;
842 sbale->length = sizeof(*sr_buf); 832 sbale->length = sizeof(*sr_buf);
843 833
@@ -934,7 +924,7 @@ struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
934 ZFCP_STATUS_COMMON_UNBLOCKED))) 924 ZFCP_STATUS_COMMON_UNBLOCKED)))
935 goto out_error_free; 925 goto out_error_free;
936 926
937 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 927 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
938 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 928 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
939 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 929 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
940 930
@@ -1029,7 +1019,7 @@ static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1029{ 1019{
1030 struct zfcp_adapter *adapter = req->adapter; 1020 struct zfcp_adapter *adapter = req->adapter;
1031 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio, 1021 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
1032 &req->queue_req); 1022 &req->qdio_req);
1033 u32 feat = adapter->adapter_features; 1023 u32 feat = adapter->adapter_features;
1034 int bytes; 1024 int bytes;
1035 1025
@@ -1047,15 +1037,15 @@ static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1047 return 0; 1037 return 0;
1048 } 1038 }
1049 1039
1050 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req, 1040 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
1051 SBAL_FLAGS0_TYPE_WRITE_READ, 1041 SBAL_FLAGS0_TYPE_WRITE_READ,
1052 sg_req, max_sbals); 1042 sg_req, max_sbals);
1053 if (bytes <= 0) 1043 if (bytes <= 0)
1054 return -EIO; 1044 return -EIO;
1055 req->qtcb->bottom.support.req_buf_length = bytes; 1045 req->qtcb->bottom.support.req_buf_length = bytes;
1056 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; 1046 req->qdio_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1057 1047
1058 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req, 1048 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
1059 SBAL_FLAGS0_TYPE_WRITE_READ, 1049 SBAL_FLAGS0_TYPE_WRITE_READ,
1060 sg_resp, max_sbals); 1050 sg_resp, max_sbals);
1061 req->qtcb->bottom.support.resp_buf_length = bytes; 1051 req->qtcb->bottom.support.resp_buf_length = bytes;
@@ -1251,7 +1241,7 @@ int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1251 } 1241 }
1252 1242
1253 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 1243 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1254 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1244 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1255 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1245 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1256 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1246 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1257 1247
@@ -1262,13 +1252,13 @@ int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1262 FSF_FEATURE_UPDATE_ALERT; 1252 FSF_FEATURE_UPDATE_ALERT;
1263 req->erp_action = erp_action; 1253 req->erp_action = erp_action;
1264 req->handler = zfcp_fsf_exchange_config_data_handler; 1254 req->handler = zfcp_fsf_exchange_config_data_handler;
1265 erp_action->fsf_req = req; 1255 erp_action->fsf_req_id = req->req_id;
1266 1256
1267 zfcp_fsf_start_erp_timer(req); 1257 zfcp_fsf_start_erp_timer(req);
1268 retval = zfcp_fsf_req_send(req); 1258 retval = zfcp_fsf_req_send(req);
1269 if (retval) { 1259 if (retval) {
1270 zfcp_fsf_req_free(req); 1260 zfcp_fsf_req_free(req);
1271 erp_action->fsf_req = NULL; 1261 erp_action->fsf_req_id = 0;
1272 } 1262 }
1273out: 1263out:
1274 spin_unlock_bh(&qdio->req_q_lock); 1264 spin_unlock_bh(&qdio->req_q_lock);
@@ -1293,7 +1283,7 @@ int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1293 goto out_unlock; 1283 goto out_unlock;
1294 } 1284 }
1295 1285
1296 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1286 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1297 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1287 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1298 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1288 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1299 req->handler = zfcp_fsf_exchange_config_data_handler; 1289 req->handler = zfcp_fsf_exchange_config_data_handler;
@@ -1349,19 +1339,19 @@ int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1349 } 1339 }
1350 1340
1351 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 1341 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1352 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1342 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1353 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1343 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1354 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1344 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1355 1345
1356 req->handler = zfcp_fsf_exchange_port_data_handler; 1346 req->handler = zfcp_fsf_exchange_port_data_handler;
1357 req->erp_action = erp_action; 1347 req->erp_action = erp_action;
1358 erp_action->fsf_req = req; 1348 erp_action->fsf_req_id = req->req_id;
1359 1349
1360 zfcp_fsf_start_erp_timer(req); 1350 zfcp_fsf_start_erp_timer(req);
1361 retval = zfcp_fsf_req_send(req); 1351 retval = zfcp_fsf_req_send(req);
1362 if (retval) { 1352 if (retval) {
1363 zfcp_fsf_req_free(req); 1353 zfcp_fsf_req_free(req);
1364 erp_action->fsf_req = NULL; 1354 erp_action->fsf_req_id = 0;
1365 } 1355 }
1366out: 1356out:
1367 spin_unlock_bh(&qdio->req_q_lock); 1357 spin_unlock_bh(&qdio->req_q_lock);
@@ -1398,7 +1388,7 @@ int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1398 if (data) 1388 if (data)
1399 req->data = data; 1389 req->data = data;
1400 1390
1401 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1391 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1402 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1392 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1403 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1393 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1404 1394
@@ -1484,7 +1474,7 @@ static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1484 } 1474 }
1485 1475
1486out: 1476out:
1487 put_device(&port->sysfs_device); 1477 put_device(&port->dev);
1488} 1478}
1489 1479
1490/** 1480/**
@@ -1513,7 +1503,7 @@ int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1513 } 1503 }
1514 1504
1515 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 1505 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1516 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1506 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1517 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1507 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1518 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1508 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1519 1509
@@ -1521,15 +1511,15 @@ int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1521 hton24(req->qtcb->bottom.support.d_id, port->d_id); 1511 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1522 req->data = port; 1512 req->data = port;
1523 req->erp_action = erp_action; 1513 req->erp_action = erp_action;
1524 erp_action->fsf_req = req; 1514 erp_action->fsf_req_id = req->req_id;
1525 get_device(&port->sysfs_device); 1515 get_device(&port->dev);
1526 1516
1527 zfcp_fsf_start_erp_timer(req); 1517 zfcp_fsf_start_erp_timer(req);
1528 retval = zfcp_fsf_req_send(req); 1518 retval = zfcp_fsf_req_send(req);
1529 if (retval) { 1519 if (retval) {
1530 zfcp_fsf_req_free(req); 1520 zfcp_fsf_req_free(req);
1531 erp_action->fsf_req = NULL; 1521 erp_action->fsf_req_id = 0;
1532 put_device(&port->sysfs_device); 1522 put_device(&port->dev);
1533 } 1523 }
1534out: 1524out:
1535 spin_unlock_bh(&qdio->req_q_lock); 1525 spin_unlock_bh(&qdio->req_q_lock);
@@ -1583,7 +1573,7 @@ int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1583 } 1573 }
1584 1574
1585 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 1575 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1586 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1576 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1587 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1577 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1588 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1578 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1589 1579
@@ -1591,13 +1581,13 @@ int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1591 req->data = erp_action->port; 1581 req->data = erp_action->port;
1592 req->erp_action = erp_action; 1582 req->erp_action = erp_action;
1593 req->qtcb->header.port_handle = erp_action->port->handle; 1583 req->qtcb->header.port_handle = erp_action->port->handle;
1594 erp_action->fsf_req = req; 1584 erp_action->fsf_req_id = req->req_id;
1595 1585
1596 zfcp_fsf_start_erp_timer(req); 1586 zfcp_fsf_start_erp_timer(req);
1597 retval = zfcp_fsf_req_send(req); 1587 retval = zfcp_fsf_req_send(req);
1598 if (retval) { 1588 if (retval) {
1599 zfcp_fsf_req_free(req); 1589 zfcp_fsf_req_free(req);
1600 erp_action->fsf_req = NULL; 1590 erp_action->fsf_req_id = 0;
1601 } 1591 }
1602out: 1592out:
1603 spin_unlock_bh(&qdio->req_q_lock); 1593 spin_unlock_bh(&qdio->req_q_lock);
@@ -1660,7 +1650,7 @@ int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1660 } 1650 }
1661 1651
1662 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 1652 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1663 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1653 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1664 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1654 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1665 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1655 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1666 1656
@@ -1715,7 +1705,7 @@ int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1715 } 1705 }
1716 1706
1717 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 1707 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1718 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1708 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1719 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1709 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1720 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1710 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1721 1711
@@ -1809,7 +1799,7 @@ int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1809 } 1799 }
1810 1800
1811 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 1801 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1812 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1802 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1813 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1803 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1814 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1804 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1815 1805
@@ -1817,13 +1807,13 @@ int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1817 req->qtcb->header.port_handle = erp_action->port->handle; 1807 req->qtcb->header.port_handle = erp_action->port->handle;
1818 req->erp_action = erp_action; 1808 req->erp_action = erp_action;
1819 req->handler = zfcp_fsf_close_physical_port_handler; 1809 req->handler = zfcp_fsf_close_physical_port_handler;
1820 erp_action->fsf_req = req; 1810 erp_action->fsf_req_id = req->req_id;
1821 1811
1822 zfcp_fsf_start_erp_timer(req); 1812 zfcp_fsf_start_erp_timer(req);
1823 retval = zfcp_fsf_req_send(req); 1813 retval = zfcp_fsf_req_send(req);
1824 if (retval) { 1814 if (retval) {
1825 zfcp_fsf_req_free(req); 1815 zfcp_fsf_req_free(req);
1826 erp_action->fsf_req = NULL; 1816 erp_action->fsf_req_id = 0;
1827 } 1817 }
1828out: 1818out:
1829 spin_unlock_bh(&qdio->req_q_lock); 1819 spin_unlock_bh(&qdio->req_q_lock);
@@ -1982,7 +1972,7 @@ int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1982 } 1972 }
1983 1973
1984 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 1974 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1985 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 1975 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
1986 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 1976 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1987 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 1977 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1988 1978
@@ -1991,7 +1981,7 @@ int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1991 req->handler = zfcp_fsf_open_unit_handler; 1981 req->handler = zfcp_fsf_open_unit_handler;
1992 req->data = erp_action->unit; 1982 req->data = erp_action->unit;
1993 req->erp_action = erp_action; 1983 req->erp_action = erp_action;
1994 erp_action->fsf_req = req; 1984 erp_action->fsf_req_id = req->req_id;
1995 1985
1996 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE)) 1986 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1997 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING; 1987 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
@@ -2000,7 +1990,7 @@ int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2000 retval = zfcp_fsf_req_send(req); 1990 retval = zfcp_fsf_req_send(req);
2001 if (retval) { 1991 if (retval) {
2002 zfcp_fsf_req_free(req); 1992 zfcp_fsf_req_free(req);
2003 erp_action->fsf_req = NULL; 1993 erp_action->fsf_req_id = 0;
2004 } 1994 }
2005out: 1995out:
2006 spin_unlock_bh(&qdio->req_q_lock); 1996 spin_unlock_bh(&qdio->req_q_lock);
@@ -2068,7 +2058,7 @@ int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2068 } 2058 }
2069 2059
2070 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 2060 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2071 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 2061 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
2072 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; 2062 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2073 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 2063 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2074 2064
@@ -2077,13 +2067,13 @@ int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2077 req->handler = zfcp_fsf_close_unit_handler; 2067 req->handler = zfcp_fsf_close_unit_handler;
2078 req->data = erp_action->unit; 2068 req->data = erp_action->unit;
2079 req->erp_action = erp_action; 2069 req->erp_action = erp_action;
2080 erp_action->fsf_req = req; 2070 erp_action->fsf_req_id = req->req_id;
2081 2071
2082 zfcp_fsf_start_erp_timer(req); 2072 zfcp_fsf_start_erp_timer(req);
2083 retval = zfcp_fsf_req_send(req); 2073 retval = zfcp_fsf_req_send(req);
2084 if (retval) { 2074 if (retval) {
2085 zfcp_fsf_req_free(req); 2075 zfcp_fsf_req_free(req);
2086 erp_action->fsf_req = NULL; 2076 erp_action->fsf_req_id = 0;
2087 } 2077 }
2088out: 2078out:
2089 spin_unlock_bh(&qdio->req_q_lock); 2079 spin_unlock_bh(&qdio->req_q_lock);
@@ -2111,8 +2101,8 @@ static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2111 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC; 2101 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2112 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) 2102 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2113 blktrc.flags |= ZFCP_BLK_REQ_ERROR; 2103 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2114 blktrc.inb_usage = req->queue_req.qdio_inb_usage; 2104 blktrc.inb_usage = req->qdio_req.qdio_inb_usage;
2115 blktrc.outb_usage = req->queue_req.qdio_outb_usage; 2105 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
2116 2106
2117 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) { 2107 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2118 blktrc.flags |= ZFCP_BLK_LAT_VALID; 2108 blktrc.flags |= ZFCP_BLK_LAT_VALID;
@@ -2169,12 +2159,7 @@ static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2169 zfcp_fsf_req_trace(req, scpnt); 2159 zfcp_fsf_req_trace(req, scpnt);
2170 2160
2171skip_fsfstatus: 2161skip_fsfstatus:
2172 if (scpnt->result != 0) 2162 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
2173 zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
2174 else if (scpnt->retries > 0)
2175 zfcp_dbf_scsi_result("retr", 4, req->adapter->dbf, scpnt, req);
2176 else
2177 zfcp_dbf_scsi_result("norm", 6, req->adapter->dbf, scpnt, req);
2178 2163
2179 scpnt->host_scribble = NULL; 2164 scpnt->host_scribble = NULL;
2180 (scpnt->scsi_done) (scpnt); 2165 (scpnt->scsi_done) (scpnt);
@@ -2274,7 +2259,7 @@ skip_fsfstatus:
2274 else { 2259 else {
2275 zfcp_fsf_send_fcp_command_task_handler(req); 2260 zfcp_fsf_send_fcp_command_task_handler(req);
2276 req->unit = NULL; 2261 req->unit = NULL;
2277 put_device(&unit->sysfs_device); 2262 put_device(&unit->dev);
2278 } 2263 }
2279} 2264}
2280 2265
@@ -2312,7 +2297,7 @@ int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2312 } 2297 }
2313 2298
2314 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; 2299 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2315 get_device(&unit->sysfs_device); 2300 get_device(&unit->dev);
2316 req->unit = unit; 2301 req->unit = unit;
2317 req->data = scsi_cmnd; 2302 req->data = scsi_cmnd;
2318 req->handler = zfcp_fsf_send_fcp_command_handler; 2303 req->handler = zfcp_fsf_send_fcp_command_handler;
@@ -2346,11 +2331,11 @@ int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2346 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd; 2331 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2347 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd); 2332 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2348 2333
2349 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype, 2334 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sbtype,
2350 scsi_sglist(scsi_cmnd), 2335 scsi_sglist(scsi_cmnd),
2351 FSF_MAX_SBALS_PER_REQ); 2336 FSF_MAX_SBALS_PER_REQ);
2352 if (unlikely(real_bytes < 0)) { 2337 if (unlikely(real_bytes < 0)) {
2353 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) { 2338 if (req->qdio_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
2354 dev_err(&adapter->ccw_device->dev, 2339 dev_err(&adapter->ccw_device->dev,
2355 "Oversize data package, unit 0x%016Lx " 2340 "Oversize data package, unit 0x%016Lx "
2356 "on port 0x%016Lx closed\n", 2341 "on port 0x%016Lx closed\n",
@@ -2369,7 +2354,7 @@ int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2369 goto out; 2354 goto out;
2370 2355
2371failed_scsi_cmnd: 2356failed_scsi_cmnd:
2372 put_device(&unit->sysfs_device); 2357 put_device(&unit->dev);
2373 zfcp_fsf_req_free(req); 2358 zfcp_fsf_req_free(req);
2374 scsi_cmnd->host_scribble = NULL; 2359 scsi_cmnd->host_scribble = NULL;
2375out: 2360out:
@@ -2415,7 +2400,7 @@ struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2415 req->qtcb->bottom.io.service_class = FSF_CLASS_3; 2400 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2416 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN; 2401 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2417 2402
2418 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 2403 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
2419 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; 2404 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2420 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; 2405 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2421 2406
@@ -2478,14 +2463,14 @@ struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2478 2463
2479 req->handler = zfcp_fsf_control_file_handler; 2464 req->handler = zfcp_fsf_control_file_handler;
2480 2465
2481 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req); 2466 sbale = zfcp_qdio_sbale_req(qdio, &req->qdio_req);
2482 sbale[0].flags |= direction; 2467 sbale[0].flags |= direction;
2483 2468
2484 bottom = &req->qtcb->bottom.support; 2469 bottom = &req->qtcb->bottom.support;
2485 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; 2470 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2486 bottom->option = fsf_cfdc->option; 2471 bottom->option = fsf_cfdc->option;
2487 2472
2488 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, 2473 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2489 direction, fsf_cfdc->sg, 2474 direction, fsf_cfdc->sg,
2490 FSF_MAX_SBALS_PER_REQ); 2475 FSF_MAX_SBALS_PER_REQ);
2491 if (bytes != ZFCP_CFDC_MAX_SIZE) { 2476 if (bytes != ZFCP_CFDC_MAX_SIZE) {
@@ -2516,15 +2501,14 @@ void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2516 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx]; 2501 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
2517 struct qdio_buffer_element *sbale; 2502 struct qdio_buffer_element *sbale;
2518 struct zfcp_fsf_req *fsf_req; 2503 struct zfcp_fsf_req *fsf_req;
2519 unsigned long flags, req_id; 2504 unsigned long req_id;
2520 int idx; 2505 int idx;
2521 2506
2522 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) { 2507 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2523 2508
2524 sbale = &sbal->element[idx]; 2509 sbale = &sbal->element[idx];
2525 req_id = (unsigned long) sbale->addr; 2510 req_id = (unsigned long) sbale->addr;
2526 spin_lock_irqsave(&adapter->req_list_lock, flags); 2511 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2527 fsf_req = zfcp_reqlist_find(adapter, req_id);
2528 2512
2529 if (!fsf_req) 2513 if (!fsf_req)
2530 /* 2514 /*
@@ -2534,11 +2518,8 @@ void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2534 panic("error: unknown req_id (%lx) on adapter %s.\n", 2518 panic("error: unknown req_id (%lx) on adapter %s.\n",
2535 req_id, dev_name(&adapter->ccw_device->dev)); 2519 req_id, dev_name(&adapter->ccw_device->dev));
2536 2520
2537 list_del(&fsf_req->list); 2521 fsf_req->qdio_req.sbal_response = sbal_idx;
2538 spin_unlock_irqrestore(&adapter->req_list_lock, flags); 2522 fsf_req->qdio_req.qdio_inb_usage =
2539
2540 fsf_req->queue_req.sbal_response = sbal_idx;
2541 fsf_req->queue_req.qdio_inb_usage =
2542 atomic_read(&qdio->resp_q.count); 2523 atomic_read(&qdio->resp_q.count);
2543 zfcp_fsf_req_complete(fsf_req); 2524 zfcp_fsf_req_complete(fsf_req);
2544 2525
diff --git a/drivers/s390/scsi/zfcp_qdio.c b/drivers/s390/scsi/zfcp_qdio.c
index 6c5228b627fc..71b97ff77cf0 100644
--- a/drivers/s390/scsi/zfcp_qdio.c
+++ b/drivers/s390/scsi/zfcp_qdio.c
@@ -10,6 +10,7 @@
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 11
12#include "zfcp_ext.h" 12#include "zfcp_ext.h"
13#include "zfcp_qdio.h"
13 14
14#define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer)) 15#define QBUFF_PER_PAGE (PAGE_SIZE / sizeof(struct qdio_buffer))
15 16
@@ -28,12 +29,6 @@ static int zfcp_qdio_buffers_enqueue(struct qdio_buffer **sbal)
28 return 0; 29 return 0;
29} 30}
30 31
31static struct qdio_buffer_element *
32zfcp_qdio_sbale(struct zfcp_qdio_queue *q, int sbal_idx, int sbale_idx)
33{
34 return &q->sbal[sbal_idx]->element[sbale_idx];
35}
36
37static void zfcp_qdio_handler_error(struct zfcp_qdio *qdio, char *id) 32static void zfcp_qdio_handler_error(struct zfcp_qdio *qdio, char *id)
38{ 33{
39 struct zfcp_adapter *adapter = qdio->adapter; 34 struct zfcp_adapter *adapter = qdio->adapter;
@@ -106,7 +101,7 @@ static void zfcp_qdio_resp_put_back(struct zfcp_qdio *qdio, int processed)
106 101
107 if (unlikely(retval)) { 102 if (unlikely(retval)) {
108 atomic_set(&queue->count, count); 103 atomic_set(&queue->count, count);
109 /* FIXME: Recover this with an adapter reopen? */ 104 zfcp_erp_adapter_reopen(qdio->adapter, 0, "qdrpb_1", NULL);
110 } else { 105 } else {
111 queue->first += count; 106 queue->first += count;
112 queue->first %= QDIO_MAX_BUFFERS_PER_Q; 107 queue->first %= QDIO_MAX_BUFFERS_PER_Q;
@@ -145,32 +140,8 @@ static void zfcp_qdio_int_resp(struct ccw_device *cdev, unsigned int qdio_err,
145 zfcp_qdio_resp_put_back(qdio, count); 140 zfcp_qdio_resp_put_back(qdio, count);
146} 141}
147 142
148/**
149 * zfcp_qdio_sbale_req - return ptr to SBALE of req_q for a struct zfcp_fsf_req
150 * @qdio: pointer to struct zfcp_qdio
151 * @q_rec: pointer to struct zfcp_queue_rec
152 * Returns: pointer to qdio_buffer_element (SBALE) structure
153 */
154struct qdio_buffer_element *zfcp_qdio_sbale_req(struct zfcp_qdio *qdio,
155 struct zfcp_queue_req *q_req)
156{
157 return zfcp_qdio_sbale(&qdio->req_q, q_req->sbal_last, 0);
158}
159
160/**
161 * zfcp_qdio_sbale_curr - return curr SBALE on req_q for a struct zfcp_fsf_req
162 * @fsf_req: pointer to struct fsf_req
163 * Returns: pointer to qdio_buffer_element (SBALE) structure
164 */
165struct qdio_buffer_element *zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio,
166 struct zfcp_queue_req *q_req)
167{
168 return zfcp_qdio_sbale(&qdio->req_q, q_req->sbal_last,
169 q_req->sbale_curr);
170}
171
172static void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio, 143static void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio,
173 struct zfcp_queue_req *q_req, int max_sbals) 144 struct zfcp_qdio_req *q_req, int max_sbals)
174{ 145{
175 int count = atomic_read(&qdio->req_q.count); 146 int count = atomic_read(&qdio->req_q.count);
176 count = min(count, max_sbals); 147 count = min(count, max_sbals);
@@ -179,7 +150,7 @@ static void zfcp_qdio_sbal_limit(struct zfcp_qdio *qdio,
179} 150}
180 151
181static struct qdio_buffer_element * 152static struct qdio_buffer_element *
182zfcp_qdio_sbal_chain(struct zfcp_qdio *qdio, struct zfcp_queue_req *q_req, 153zfcp_qdio_sbal_chain(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
183 unsigned long sbtype) 154 unsigned long sbtype)
184{ 155{
185 struct qdio_buffer_element *sbale; 156 struct qdio_buffer_element *sbale;
@@ -214,7 +185,7 @@ zfcp_qdio_sbal_chain(struct zfcp_qdio *qdio, struct zfcp_queue_req *q_req,
214} 185}
215 186
216static struct qdio_buffer_element * 187static struct qdio_buffer_element *
217zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_queue_req *q_req, 188zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
218 unsigned int sbtype) 189 unsigned int sbtype)
219{ 190{
220 if (q_req->sbale_curr == ZFCP_LAST_SBALE_PER_SBAL) 191 if (q_req->sbale_curr == ZFCP_LAST_SBALE_PER_SBAL)
@@ -224,7 +195,7 @@ zfcp_qdio_sbale_next(struct zfcp_qdio *qdio, struct zfcp_queue_req *q_req,
224} 195}
225 196
226static void zfcp_qdio_undo_sbals(struct zfcp_qdio *qdio, 197static void zfcp_qdio_undo_sbals(struct zfcp_qdio *qdio,
227 struct zfcp_queue_req *q_req) 198 struct zfcp_qdio_req *q_req)
228{ 199{
229 struct qdio_buffer **sbal = qdio->req_q.sbal; 200 struct qdio_buffer **sbal = qdio->req_q.sbal;
230 int first = q_req->sbal_first; 201 int first = q_req->sbal_first;
@@ -235,7 +206,7 @@ static void zfcp_qdio_undo_sbals(struct zfcp_qdio *qdio,
235} 206}
236 207
237static int zfcp_qdio_fill_sbals(struct zfcp_qdio *qdio, 208static int zfcp_qdio_fill_sbals(struct zfcp_qdio *qdio,
238 struct zfcp_queue_req *q_req, 209 struct zfcp_qdio_req *q_req,
239 unsigned int sbtype, void *start_addr, 210 unsigned int sbtype, void *start_addr,
240 unsigned int total_length) 211 unsigned int total_length)
241{ 212{
@@ -271,8 +242,7 @@ static int zfcp_qdio_fill_sbals(struct zfcp_qdio *qdio,
271 * @max_sbals: upper bound for number of SBALs to be used 242 * @max_sbals: upper bound for number of SBALs to be used
272 * Returns: number of bytes, or error (negativ) 243 * Returns: number of bytes, or error (negativ)
273 */ 244 */
274int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio, 245int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req,
275 struct zfcp_queue_req *q_req,
276 unsigned long sbtype, struct scatterlist *sg, 246 unsigned long sbtype, struct scatterlist *sg,
277 int max_sbals) 247 int max_sbals)
278{ 248{
@@ -304,10 +274,10 @@ int zfcp_qdio_sbals_from_sg(struct zfcp_qdio *qdio,
304/** 274/**
305 * zfcp_qdio_send - set PCI flag in first SBALE and send req to QDIO 275 * zfcp_qdio_send - set PCI flag in first SBALE and send req to QDIO
306 * @qdio: pointer to struct zfcp_qdio 276 * @qdio: pointer to struct zfcp_qdio
307 * @q_req: pointer to struct zfcp_queue_req 277 * @q_req: pointer to struct zfcp_qdio_req
308 * Returns: 0 on success, error otherwise 278 * Returns: 0 on success, error otherwise
309 */ 279 */
310int zfcp_qdio_send(struct zfcp_qdio *qdio, struct zfcp_queue_req *q_req) 280int zfcp_qdio_send(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
311{ 281{
312 struct zfcp_qdio_queue *req_q = &qdio->req_q; 282 struct zfcp_qdio_queue *req_q = &qdio->req_q;
313 int first = q_req->sbal_first; 283 int first = q_req->sbal_first;
diff --git a/drivers/s390/scsi/zfcp_qdio.h b/drivers/s390/scsi/zfcp_qdio.h
new file mode 100644
index 000000000000..8cca54631e1e
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_qdio.h
@@ -0,0 +1,109 @@
1/*
2 * zfcp device driver
3 *
4 * Header file for zfcp qdio interface
5 *
6 * Copyright IBM Corporation 2010
7 */
8
9#ifndef ZFCP_QDIO_H
10#define ZFCP_QDIO_H
11
12#include <asm/qdio.h>
13
14/**
15 * struct zfcp_qdio_queue - qdio queue buffer, zfcp index and free count
16 * @sbal: qdio buffers
17 * @first: index of next free buffer in queue
18 * @count: number of free buffers in queue
19 */
20struct zfcp_qdio_queue {
21 struct qdio_buffer *sbal[QDIO_MAX_BUFFERS_PER_Q];
22 u8 first;
23 atomic_t count;
24};
25
26/**
27 * struct zfcp_qdio - basic qdio data structure
28 * @resp_q: response queue
29 * @req_q: request queue
30 * @stat_lock: lock to protect req_q_util and req_q_time
31 * @req_q_lock: lock to serialize access to request queue
32 * @req_q_time: time of last fill level change
33 * @req_q_util: used for accounting
34 * @req_q_full: queue full incidents
35 * @req_q_wq: used to wait for SBAL availability
36 * @adapter: adapter used in conjunction with this qdio structure
37 */
38struct zfcp_qdio {
39 struct zfcp_qdio_queue resp_q;
40 struct zfcp_qdio_queue req_q;
41 spinlock_t stat_lock;
42 spinlock_t req_q_lock;
43 unsigned long long req_q_time;
44 u64 req_q_util;
45 atomic_t req_q_full;
46 wait_queue_head_t req_q_wq;
47 struct zfcp_adapter *adapter;
48};
49
50/**
51 * struct zfcp_qdio_req - qdio queue related values for a request
52 * @sbal_number: number of free sbals
53 * @sbal_first: first sbal for this request
54 * @sbal_last: last sbal for this request
55 * @sbal_limit: last possible sbal for this request
56 * @sbale_curr: current sbale at creation of this request
57 * @sbal_response: sbal used in interrupt
58 * @qdio_outb_usage: usage of outbound queue
59 * @qdio_inb_usage: usage of inbound queue
60 */
61struct zfcp_qdio_req {
62 u8 sbal_number;
63 u8 sbal_first;
64 u8 sbal_last;
65 u8 sbal_limit;
66 u8 sbale_curr;
67 u8 sbal_response;
68 u16 qdio_outb_usage;
69 u16 qdio_inb_usage;
70};
71
72/**
73 * zfcp_qdio_sbale - return pointer to sbale in qdio queue
74 * @q: queue where to find sbal
75 * @sbal_idx: sbal index in queue
76 * @sbale_idx: sbale index in sbal
77 */
78static inline struct qdio_buffer_element *
79zfcp_qdio_sbale(struct zfcp_qdio_queue *q, int sbal_idx, int sbale_idx)
80{
81 return &q->sbal[sbal_idx]->element[sbale_idx];
82}
83
84/**
85 * zfcp_qdio_sbale_req - return pointer to sbale on req_q for a request
86 * @qdio: pointer to struct zfcp_qdio
87 * @q_rec: pointer to struct zfcp_qdio_req
88 * Returns: pointer to qdio_buffer_element (sbale) structure
89 */
90static inline struct qdio_buffer_element *
91zfcp_qdio_sbale_req(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
92{
93 return zfcp_qdio_sbale(&qdio->req_q, q_req->sbal_last, 0);
94}
95
96/**
97 * zfcp_qdio_sbale_curr - return current sbale on req_q for a request
98 * @qdio: pointer to struct zfcp_qdio
99 * @fsf_req: pointer to struct zfcp_fsf_req
100 * Returns: pointer to qdio_buffer_element (sbale) structure
101 */
102static inline struct qdio_buffer_element *
103zfcp_qdio_sbale_curr(struct zfcp_qdio *qdio, struct zfcp_qdio_req *q_req)
104{
105 return zfcp_qdio_sbale(&qdio->req_q, q_req->sbal_last,
106 q_req->sbale_curr);
107}
108
109#endif /* ZFCP_QDIO_H */
diff --git a/drivers/s390/scsi/zfcp_reqlist.h b/drivers/s390/scsi/zfcp_reqlist.h
new file mode 100644
index 000000000000..a72d1b730aba
--- /dev/null
+++ b/drivers/s390/scsi/zfcp_reqlist.h
@@ -0,0 +1,183 @@
1/*
2 * zfcp device driver
3 *
4 * Data structure and helper functions for tracking pending FSF
5 * requests.
6 *
7 * Copyright IBM Corporation 2009
8 */
9
10#ifndef ZFCP_REQLIST_H
11#define ZFCP_REQLIST_H
12
13/* number of hash buckets */
14#define ZFCP_REQ_LIST_BUCKETS 128
15
16/**
17 * struct zfcp_reqlist - Container for request list (reqlist)
18 * @lock: Spinlock for protecting the hash list
19 * @list: Array of hashbuckets, each is a list of requests in this bucket
20 */
21struct zfcp_reqlist {
22 spinlock_t lock;
23 struct list_head buckets[ZFCP_REQ_LIST_BUCKETS];
24};
25
26static inline int zfcp_reqlist_hash(unsigned long req_id)
27{
28 return req_id % ZFCP_REQ_LIST_BUCKETS;
29}
30
31/**
32 * zfcp_reqlist_alloc - Allocate and initialize reqlist
33 *
34 * Returns pointer to allocated reqlist on success, or NULL on
35 * allocation failure.
36 */
37static inline struct zfcp_reqlist *zfcp_reqlist_alloc(void)
38{
39 unsigned int i;
40 struct zfcp_reqlist *rl;
41
42 rl = kzalloc(sizeof(struct zfcp_reqlist), GFP_KERNEL);
43 if (!rl)
44 return NULL;
45
46 spin_lock_init(&rl->lock);
47
48 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
49 INIT_LIST_HEAD(&rl->buckets[i]);
50
51 return rl;
52}
53
54/**
55 * zfcp_reqlist_isempty - Check whether the request list empty
56 * @rl: pointer to reqlist
57 *
58 * Returns: 1 if list is empty, 0 if not
59 */
60static inline int zfcp_reqlist_isempty(struct zfcp_reqlist *rl)
61{
62 unsigned int i;
63
64 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
65 if (!list_empty(&rl->buckets[i]))
66 return 0;
67 return 1;
68}
69
70/**
71 * zfcp_reqlist_free - Free allocated memory for reqlist
72 * @rl: The reqlist where to free memory
73 */
74static inline void zfcp_reqlist_free(struct zfcp_reqlist *rl)
75{
76 /* sanity check */
77 BUG_ON(!zfcp_reqlist_isempty(rl));
78
79 kfree(rl);
80}
81
82static inline struct zfcp_fsf_req *
83_zfcp_reqlist_find(struct zfcp_reqlist *rl, unsigned long req_id)
84{
85 struct zfcp_fsf_req *req;
86 unsigned int i;
87
88 i = zfcp_reqlist_hash(req_id);
89 list_for_each_entry(req, &rl->buckets[i], list)
90 if (req->req_id == req_id)
91 return req;
92 return NULL;
93}
94
95/**
96 * zfcp_reqlist_find - Lookup FSF request by its request id
97 * @rl: The reqlist where to lookup the FSF request
98 * @req_id: The request id to look for
99 *
100 * Returns a pointer to the FSF request with the specified request id
101 * or NULL if there is no known FSF request with this id.
102 */
103static inline struct zfcp_fsf_req *
104zfcp_reqlist_find(struct zfcp_reqlist *rl, unsigned long req_id)
105{
106 unsigned long flags;
107 struct zfcp_fsf_req *req;
108
109 spin_lock_irqsave(&rl->lock, flags);
110 req = _zfcp_reqlist_find(rl, req_id);
111 spin_unlock_irqrestore(&rl->lock, flags);
112
113 return req;
114}
115
116/**
117 * zfcp_reqlist_find_rm - Lookup request by id and remove it from reqlist
118 * @rl: reqlist where to search and remove entry
119 * @req_id: The request id of the request to look for
120 *
121 * This functions tries to find the FSF request with the specified
122 * id and then removes it from the reqlist. The reqlist lock is held
123 * during both steps of the operation.
124 *
125 * Returns: Pointer to the FSF request if the request has been found,
126 * NULL if it has not been found.
127 */
128static inline struct zfcp_fsf_req *
129zfcp_reqlist_find_rm(struct zfcp_reqlist *rl, unsigned long req_id)
130{
131 unsigned long flags;
132 struct zfcp_fsf_req *req;
133
134 spin_lock_irqsave(&rl->lock, flags);
135 req = _zfcp_reqlist_find(rl, req_id);
136 if (req)
137 list_del(&req->list);
138 spin_unlock_irqrestore(&rl->lock, flags);
139
140 return req;
141}
142
143/**
144 * zfcp_reqlist_add - Add entry to reqlist
145 * @rl: reqlist where to add the entry
146 * @req: The entry to add
147 *
148 * The request id always increases. As an optimization new requests
149 * are added here with list_add_tail at the end of the bucket lists
150 * while old requests are looked up starting at the beginning of the
151 * lists.
152 */
153static inline void zfcp_reqlist_add(struct zfcp_reqlist *rl,
154 struct zfcp_fsf_req *req)
155{
156 unsigned int i;
157 unsigned long flags;
158
159 i = zfcp_reqlist_hash(req->req_id);
160
161 spin_lock_irqsave(&rl->lock, flags);
162 list_add_tail(&req->list, &rl->buckets[i]);
163 spin_unlock_irqrestore(&rl->lock, flags);
164}
165
166/**
167 * zfcp_reqlist_move - Move all entries from reqlist to simple list
168 * @rl: The zfcp_reqlist where to remove all entries
169 * @list: The list where to move all entries
170 */
171static inline void zfcp_reqlist_move(struct zfcp_reqlist *rl,
172 struct list_head *list)
173{
174 unsigned int i;
175 unsigned long flags;
176
177 spin_lock_irqsave(&rl->lock, flags);
178 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
179 list_splice_init(&rl->buckets[i], list);
180 spin_unlock_irqrestore(&rl->lock, flags);
181}
182
183#endif /* ZFCP_REQLIST_H */
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 8e6fc68d6bd4..c3c4178888af 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Interface to Linux SCSI midlayer. 4 * Interface to Linux SCSI midlayer.
5 * 5 *
6 * Copyright IBM Corporation 2002, 2009 6 * Copyright IBM Corporation 2002, 2010
7 */ 7 */
8 8
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
@@ -15,6 +15,7 @@
15#include "zfcp_ext.h" 15#include "zfcp_ext.h"
16#include "zfcp_dbf.h" 16#include "zfcp_dbf.h"
17#include "zfcp_fc.h" 17#include "zfcp_fc.h"
18#include "zfcp_reqlist.h"
18 19
19static unsigned int default_depth = 32; 20static unsigned int default_depth = 32;
20module_param_named(queue_depth, default_depth, uint, 0600); 21module_param_named(queue_depth, default_depth, uint, 0600);
@@ -43,7 +44,7 @@ static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
43{ 44{
44 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata; 45 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
45 unit->device = NULL; 46 unit->device = NULL;
46 put_device(&unit->sysfs_device); 47 put_device(&unit->dev);
47} 48}
48 49
49static int zfcp_scsi_slave_configure(struct scsi_device *sdp) 50static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
@@ -59,10 +60,9 @@ static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
59{ 60{
60 struct zfcp_adapter *adapter = 61 struct zfcp_adapter *adapter =
61 (struct zfcp_adapter *) scpnt->device->host->hostdata[0]; 62 (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
63
62 set_host_byte(scpnt, result); 64 set_host_byte(scpnt, result);
63 if ((scpnt->device != NULL) && (scpnt->device->host != NULL)) 65 zfcp_dbf_scsi_fail_send(adapter->dbf, scpnt);
64 zfcp_dbf_scsi_result("fail", 4, adapter->dbf, scpnt, NULL);
65 /* return directly */
66 scpnt->scsi_done(scpnt); 66 scpnt->scsi_done(scpnt);
67} 67}
68 68
@@ -86,18 +86,10 @@ static int zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt,
86 adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0]; 86 adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0];
87 unit = scpnt->device->hostdata; 87 unit = scpnt->device->hostdata;
88 88
89 BUG_ON(!adapter || (adapter != unit->port->adapter));
90 BUG_ON(!scpnt->scsi_done);
91
92 if (unlikely(!unit)) {
93 zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT);
94 return 0;
95 }
96
97 scsi_result = fc_remote_port_chkready(rport); 89 scsi_result = fc_remote_port_chkready(rport);
98 if (unlikely(scsi_result)) { 90 if (unlikely(scsi_result)) {
99 scpnt->result = scsi_result; 91 scpnt->result = scsi_result;
100 zfcp_dbf_scsi_result("fail", 4, adapter->dbf, scpnt, NULL); 92 zfcp_dbf_scsi_fail_send(adapter->dbf, scpnt);
101 scpnt->scsi_done(scpnt); 93 scpnt->scsi_done(scpnt);
102 return 0; 94 return 0;
103 } 95 }
@@ -189,9 +181,7 @@ static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
189 /* avoid race condition between late normal completion and abort */ 181 /* avoid race condition between late normal completion and abort */
190 write_lock_irqsave(&adapter->abort_lock, flags); 182 write_lock_irqsave(&adapter->abort_lock, flags);
191 183
192 spin_lock(&adapter->req_list_lock); 184 old_req = zfcp_reqlist_find(adapter->req_list, old_reqid);
193 old_req = zfcp_reqlist_find(adapter, old_reqid);
194 spin_unlock(&adapter->req_list_lock);
195 if (!old_req) { 185 if (!old_req) {
196 write_unlock_irqrestore(&adapter->abort_lock, flags); 186 write_unlock_irqrestore(&adapter->abort_lock, flags);
197 zfcp_dbf_scsi_abort("lte1", adapter->dbf, scpnt, NULL, 187 zfcp_dbf_scsi_abort("lte1", adapter->dbf, scpnt, NULL,
@@ -521,7 +511,7 @@ static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
521 511
522 if (port) { 512 if (port) {
523 zfcp_erp_port_reopen(port, 0, "sctrpi1", NULL); 513 zfcp_erp_port_reopen(port, 0, "sctrpi1", NULL);
524 put_device(&port->sysfs_device); 514 put_device(&port->dev);
525 } 515 }
526} 516}
527 517
@@ -563,23 +553,23 @@ static void zfcp_scsi_rport_block(struct zfcp_port *port)
563 553
564void zfcp_scsi_schedule_rport_register(struct zfcp_port *port) 554void zfcp_scsi_schedule_rport_register(struct zfcp_port *port)
565{ 555{
566 get_device(&port->sysfs_device); 556 get_device(&port->dev);
567 port->rport_task = RPORT_ADD; 557 port->rport_task = RPORT_ADD;
568 558
569 if (!queue_work(port->adapter->work_queue, &port->rport_work)) 559 if (!queue_work(port->adapter->work_queue, &port->rport_work))
570 put_device(&port->sysfs_device); 560 put_device(&port->dev);
571} 561}
572 562
573void zfcp_scsi_schedule_rport_block(struct zfcp_port *port) 563void zfcp_scsi_schedule_rport_block(struct zfcp_port *port)
574{ 564{
575 get_device(&port->sysfs_device); 565 get_device(&port->dev);
576 port->rport_task = RPORT_DEL; 566 port->rport_task = RPORT_DEL;
577 567
578 if (port->rport && queue_work(port->adapter->work_queue, 568 if (port->rport && queue_work(port->adapter->work_queue,
579 &port->rport_work)) 569 &port->rport_work))
580 return; 570 return;
581 571
582 put_device(&port->sysfs_device); 572 put_device(&port->dev);
583} 573}
584 574
585void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter) 575void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter)
@@ -608,7 +598,7 @@ void zfcp_scsi_rport_work(struct work_struct *work)
608 } 598 }
609 } 599 }
610 600
611 put_device(&port->sysfs_device); 601 put_device(&port->dev);
612} 602}
613 603
614 604
@@ -626,7 +616,7 @@ void zfcp_scsi_scan(struct work_struct *work)
626 scsilun_to_int((struct scsi_lun *) 616 scsilun_to_int((struct scsi_lun *)
627 &unit->fcp_lun), 0); 617 &unit->fcp_lun), 0);
628 618
629 put_device(&unit->sysfs_device); 619 put_device(&unit->dev);
630} 620}
631 621
632struct fc_function_template zfcp_transport_functions = { 622struct fc_function_template zfcp_transport_functions = {
diff --git a/drivers/s390/scsi/zfcp_sysfs.c b/drivers/s390/scsi/zfcp_sysfs.c
index f539e006683c..a43035d4bd70 100644
--- a/drivers/s390/scsi/zfcp_sysfs.c
+++ b/drivers/s390/scsi/zfcp_sysfs.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * sysfs attributes. 4 * sysfs attributes.
5 * 5 *
6 * Copyright IBM Corporation 2008, 2009 6 * Copyright IBM Corporation 2008, 2010
7 */ 7 */
8 8
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
@@ -19,8 +19,7 @@ static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
19 struct device_attribute *at,\ 19 struct device_attribute *at,\
20 char *buf) \ 20 char *buf) \
21{ \ 21{ \
22 struct _feat_def *_feat = container_of(dev, struct _feat_def, \ 22 struct _feat_def *_feat = container_of(dev, struct _feat_def, dev); \
23 sysfs_device); \
24 \ 23 \
25 return sprintf(buf, _format, _value); \ 24 return sprintf(buf, _format, _value); \
26} \ 25} \
@@ -87,8 +86,7 @@ static ssize_t zfcp_sysfs_##_feat##_failed_show(struct device *dev, \
87 struct device_attribute *attr, \ 86 struct device_attribute *attr, \
88 char *buf) \ 87 char *buf) \
89{ \ 88{ \
90 struct _feat_def *_feat = container_of(dev, struct _feat_def, \ 89 struct _feat_def *_feat = container_of(dev, struct _feat_def, dev); \
91 sysfs_device); \
92 \ 90 \
93 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_ERP_FAILED) \ 91 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_ERP_FAILED) \
94 return sprintf(buf, "1\n"); \ 92 return sprintf(buf, "1\n"); \
@@ -99,12 +97,11 @@ static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \
99 struct device_attribute *attr,\ 97 struct device_attribute *attr,\
100 const char *buf, size_t count)\ 98 const char *buf, size_t count)\
101{ \ 99{ \
102 struct _feat_def *_feat = container_of(dev, struct _feat_def, \ 100 struct _feat_def *_feat = container_of(dev, struct _feat_def, dev); \
103 sysfs_device); \
104 unsigned long val; \ 101 unsigned long val; \
105 int retval = 0; \ 102 int retval = 0; \
106 \ 103 \
107 if (!(_feat && get_device(&_feat->sysfs_device))) \ 104 if (!(_feat && get_device(&_feat->dev))) \
108 return -EBUSY; \ 105 return -EBUSY; \
109 \ 106 \
110 if (strict_strtoul(buf, 0, &val) || val != 0) { \ 107 if (strict_strtoul(buf, 0, &val) || val != 0) { \
@@ -118,7 +115,7 @@ static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \
118 _reopen_id, NULL); \ 115 _reopen_id, NULL); \
119 zfcp_erp_wait(_adapter); \ 116 zfcp_erp_wait(_adapter); \
120out: \ 117out: \
121 put_device(&_feat->sysfs_device); \ 118 put_device(&_feat->dev); \
122 return retval ? retval : (ssize_t) count; \ 119 return retval ? retval : (ssize_t) count; \
123} \ 120} \
124static ZFCP_DEV_ATTR(_feat, failed, S_IWUSR | S_IRUGO, \ 121static ZFCP_DEV_ATTR(_feat, failed, S_IWUSR | S_IRUGO, \
@@ -224,10 +221,10 @@ static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
224 list_del(&port->list); 221 list_del(&port->list);
225 write_unlock_irq(&adapter->port_list_lock); 222 write_unlock_irq(&adapter->port_list_lock);
226 223
227 put_device(&port->sysfs_device); 224 put_device(&port->dev);
228 225
229 zfcp_erp_port_shutdown(port, 0, "syprs_1", NULL); 226 zfcp_erp_port_shutdown(port, 0, "syprs_1", NULL);
230 zfcp_device_unregister(&port->sysfs_device, &zfcp_sysfs_port_attrs); 227 zfcp_device_unregister(&port->dev, &zfcp_sysfs_port_attrs);
231 out: 228 out:
232 zfcp_ccw_adapter_put(adapter); 229 zfcp_ccw_adapter_put(adapter);
233 return retval ? retval : (ssize_t) count; 230 return retval ? retval : (ssize_t) count;
@@ -258,13 +255,12 @@ static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
258 struct device_attribute *attr, 255 struct device_attribute *attr,
259 const char *buf, size_t count) 256 const char *buf, size_t count)
260{ 257{
261 struct zfcp_port *port = container_of(dev, struct zfcp_port, 258 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
262 sysfs_device);
263 struct zfcp_unit *unit; 259 struct zfcp_unit *unit;
264 u64 fcp_lun; 260 u64 fcp_lun;
265 int retval = -EINVAL; 261 int retval = -EINVAL;
266 262
267 if (!(port && get_device(&port->sysfs_device))) 263 if (!(port && get_device(&port->dev)))
268 return -EBUSY; 264 return -EBUSY;
269 265
270 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) 266 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
@@ -280,7 +276,7 @@ static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
280 zfcp_erp_wait(unit->port->adapter); 276 zfcp_erp_wait(unit->port->adapter);
281 flush_work(&unit->scsi_work); 277 flush_work(&unit->scsi_work);
282out: 278out:
283 put_device(&port->sysfs_device); 279 put_device(&port->dev);
284 return retval ? retval : (ssize_t) count; 280 return retval ? retval : (ssize_t) count;
285} 281}
286static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store); 282static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
@@ -289,13 +285,12 @@ static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
289 struct device_attribute *attr, 285 struct device_attribute *attr,
290 const char *buf, size_t count) 286 const char *buf, size_t count)
291{ 287{
292 struct zfcp_port *port = container_of(dev, struct zfcp_port, 288 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
293 sysfs_device);
294 struct zfcp_unit *unit; 289 struct zfcp_unit *unit;
295 u64 fcp_lun; 290 u64 fcp_lun;
296 int retval = -EINVAL; 291 int retval = -EINVAL;
297 292
298 if (!(port && get_device(&port->sysfs_device))) 293 if (!(port && get_device(&port->dev)))
299 return -EBUSY; 294 return -EBUSY;
300 295
301 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun)) 296 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
@@ -314,12 +309,12 @@ static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
314 list_del(&unit->list); 309 list_del(&unit->list);
315 write_unlock_irq(&port->unit_list_lock); 310 write_unlock_irq(&port->unit_list_lock);
316 311
317 put_device(&unit->sysfs_device); 312 put_device(&unit->dev);
318 313
319 zfcp_erp_unit_shutdown(unit, 0, "syurs_1", NULL); 314 zfcp_erp_unit_shutdown(unit, 0, "syurs_1", NULL);
320 zfcp_device_unregister(&unit->sysfs_device, &zfcp_sysfs_unit_attrs); 315 zfcp_device_unregister(&unit->dev, &zfcp_sysfs_unit_attrs);
321out: 316out:
322 put_device(&port->sysfs_device); 317 put_device(&port->dev);
323 return retval ? retval : (ssize_t) count; 318 return retval ? retval : (ssize_t) count;
324} 319}
325static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store); 320static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index 75ac19b1192f..fc2f676e984d 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -233,7 +233,7 @@ static int opromnext(void __user *argp, unsigned int cmd, struct device_node *dp
233 233
234 ph = 0; 234 ph = 0;
235 if (dp) 235 if (dp)
236 ph = dp->node; 236 ph = dp->phandle;
237 237
238 data->current_node = dp; 238 data->current_node = dp;
239 *((int *) op->oprom_array) = ph; 239 *((int *) op->oprom_array) = ph;
@@ -256,7 +256,7 @@ static int oprompci2node(void __user *argp, struct device_node *dp, struct openp
256 256
257 dp = pci_device_to_OF_node(pdev); 257 dp = pci_device_to_OF_node(pdev);
258 data->current_node = dp; 258 data->current_node = dp;
259 *((int *)op->oprom_array) = dp->node; 259 *((int *)op->oprom_array) = dp->phandle;
260 op->oprom_size = sizeof(int); 260 op->oprom_size = sizeof(int);
261 err = copyout(argp, op, bufsize + sizeof(int)); 261 err = copyout(argp, op, bufsize + sizeof(int));
262 262
@@ -273,7 +273,7 @@ static int oprompath2node(void __user *argp, struct device_node *dp, struct open
273 273
274 dp = of_find_node_by_path(op->oprom_array); 274 dp = of_find_node_by_path(op->oprom_array);
275 if (dp) 275 if (dp)
276 ph = dp->node; 276 ph = dp->phandle;
277 data->current_node = dp; 277 data->current_node = dp;
278 *((int *)op->oprom_array) = ph; 278 *((int *)op->oprom_array) = ph;
279 op->oprom_size = sizeof(int); 279 op->oprom_size = sizeof(int);
@@ -540,7 +540,7 @@ static int opiocgetnext(unsigned int cmd, void __user *argp)
540 } 540 }
541 } 541 }
542 if (dp) 542 if (dp)
543 nd = dp->node; 543 nd = dp->phandle;
544 if (copy_to_user(argp, &nd, sizeof(phandle))) 544 if (copy_to_user(argp, &nd, sizeof(phandle)))
545 return -EFAULT; 545 return -EFAULT;
546 546
@@ -570,7 +570,7 @@ static int openprom_bsd_ioctl(struct inode * inode, struct file * file,
570 case OPIOCGETOPTNODE: 570 case OPIOCGETOPTNODE:
571 BUILD_BUG_ON(sizeof(phandle) != sizeof(int)); 571 BUILD_BUG_ON(sizeof(phandle) != sizeof(int));
572 572
573 if (copy_to_user(argp, &options_node->node, sizeof(phandle))) 573 if (copy_to_user(argp, &options_node->phandle, sizeof(phandle)))
574 return -EFAULT; 574 return -EFAULT;
575 575
576 return 0; 576 return 0;
diff --git a/drivers/scsi/FlashPoint.c b/drivers/scsi/FlashPoint.c
index b898d382b7b0..e40cdfb7541f 100644
--- a/drivers/scsi/FlashPoint.c
+++ b/drivers/scsi/FlashPoint.c
@@ -3924,7 +3924,7 @@ static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card)
3924{ 3924{
3925 struct sccb_mgr_tar_info *currTar_Info; 3925 struct sccb_mgr_tar_info *currTar_Info;
3926 3926
3927 if ((p_sccb->TargID > MAX_SCSI_TAR) || (p_sccb->Lun > MAX_LUN)) { 3927 if ((p_sccb->TargID >= MAX_SCSI_TAR) || (p_sccb->Lun >= MAX_LUN)) {
3928 return; 3928 return;
3929 } 3929 }
3930 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID]; 3930 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 477542602284..9e71ac611146 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2516,7 +2516,7 @@ int fas216_eh_device_reset(struct scsi_cmnd *SCpnt)
2516 if (info->scsi.phase == PHASE_IDLE) 2516 if (info->scsi.phase == PHASE_IDLE)
2517 fas216_kick(info); 2517 fas216_kick(info);
2518 2518
2519 mod_timer(&info->eh_timer, 30 * HZ); 2519 mod_timer(&info->eh_timer, jiffies + 30 * HZ);
2520 spin_unlock_irqrestore(&info->host_lock, flags); 2520 spin_unlock_irqrestore(&info->host_lock, flags);
2521 2521
2522 /* 2522 /*
diff --git a/drivers/scsi/be2iscsi/be.h b/drivers/scsi/be2iscsi/be.h
index a93a5040f087..136b49cea791 100644
--- a/drivers/scsi/be2iscsi/be.h
+++ b/drivers/scsi/be2iscsi/be.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -24,6 +24,10 @@
24#define FW_VER_LEN 32 24#define FW_VER_LEN 32
25#define MCC_Q_LEN 128 25#define MCC_Q_LEN 128
26#define MCC_CQ_LEN 256 26#define MCC_CQ_LEN 256
27#define MAX_MCC_CMD 16
28/* BladeEngine Generation numbers */
29#define BE_GEN2 2
30#define BE_GEN3 3
27 31
28struct be_dma_mem { 32struct be_dma_mem {
29 void *va; 33 void *va;
@@ -57,6 +61,11 @@ static inline void *queue_head_node(struct be_queue_info *q)
57 return q->dma_mem.va + q->head * q->entry_size; 61 return q->dma_mem.va + q->head * q->entry_size;
58} 62}
59 63
64static inline void *queue_get_wrb(struct be_queue_info *q, unsigned int wrb_num)
65{
66 return q->dma_mem.va + wrb_num * q->entry_size;
67}
68
60static inline void *queue_tail_node(struct be_queue_info *q) 69static inline void *queue_tail_node(struct be_queue_info *q)
61{ 70{
62 return q->dma_mem.va + q->tail * q->entry_size; 71 return q->dma_mem.va + q->tail * q->entry_size;
@@ -104,15 +113,19 @@ struct be_ctrl_info {
104 spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */ 113 spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */
105 spinlock_t mcc_cq_lock; 114 spinlock_t mcc_cq_lock;
106 115
107 /* MCC Async callback */ 116 wait_queue_head_t mcc_wait[MAX_MCC_CMD + 1];
108 void (*async_cb) (void *adapter, bool link_up); 117 unsigned int mcc_tag[MAX_MCC_CMD];
109 void *adapter_ctxt; 118 unsigned int mcc_numtag[MAX_MCC_CMD + 1];
119 unsigned short mcc_alloc_index;
120 unsigned short mcc_free_index;
121 unsigned int mcc_tag_available;
110}; 122};
111 123
112#include "be_cmds.h" 124#include "be_cmds.h"
113 125
114#define PAGE_SHIFT_4K 12 126#define PAGE_SHIFT_4K 12
115#define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K) 127#define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K)
128#define mcc_timeout 120000 /* 5s timeout */
116 129
117/* Returns number of pages spanned by the data starting at the given addr */ 130/* Returns number of pages spanned by the data starting at the given addr */
118#define PAGES_4K_SPANNED(_address, size) \ 131#define PAGES_4K_SPANNED(_address, size) \
diff --git a/drivers/scsi/be2iscsi/be_cmds.c b/drivers/scsi/be2iscsi/be_cmds.c
index f008708f1b08..67098578fba4 100644
--- a/drivers/scsi/be2iscsi/be_cmds.c
+++ b/drivers/scsi/be2iscsi/be_cmds.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -19,7 +19,7 @@
19#include "be_mgmt.h" 19#include "be_mgmt.h"
20#include "be_main.h" 20#include "be_main.h"
21 21
22static void be_mcc_notify(struct beiscsi_hba *phba) 22void be_mcc_notify(struct beiscsi_hba *phba)
23{ 23{
24 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; 24 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
25 u32 val = 0; 25 u32 val = 0;
@@ -29,6 +29,52 @@ static void be_mcc_notify(struct beiscsi_hba *phba)
29 iowrite32(val, phba->db_va + DB_MCCQ_OFFSET); 29 iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
30} 30}
31 31
32unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
33{
34 unsigned int tag = 0;
35 unsigned int num = 0;
36
37mcc_tag_rdy:
38 if (phba->ctrl.mcc_tag_available) {
39 tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
40 phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
41 phba->ctrl.mcc_numtag[tag] = 0;
42 } else {
43 udelay(100);
44 num++;
45 if (num < mcc_timeout)
46 goto mcc_tag_rdy;
47 }
48 if (tag) {
49 phba->ctrl.mcc_tag_available--;
50 if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
51 phba->ctrl.mcc_alloc_index = 0;
52 else
53 phba->ctrl.mcc_alloc_index++;
54 }
55 return tag;
56}
57
58void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
59{
60 spin_lock(&ctrl->mbox_lock);
61 tag = tag & 0x000000FF;
62 ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
63 if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
64 ctrl->mcc_free_index = 0;
65 else
66 ctrl->mcc_free_index++;
67 ctrl->mcc_tag_available++;
68 spin_unlock(&ctrl->mbox_lock);
69}
70
71bool is_link_state_evt(u32 trailer)
72{
73 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
74 ASYNC_TRAILER_EVENT_CODE_MASK) ==
75 ASYNC_EVENT_CODE_LINK_STATE);
76}
77
32static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl) 78static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
33{ 79{
34 if (compl->flags != 0) { 80 if (compl->flags != 0) {
@@ -64,12 +110,30 @@ static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
64 return 0; 110 return 0;
65} 111}
66 112
67 113int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
68static inline bool is_link_state_evt(u32 trailer) 114 struct be_mcc_compl *compl)
69{ 115{
70 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) & 116 u16 compl_status, extd_status;
71 ASYNC_TRAILER_EVENT_CODE_MASK) == 117 unsigned short tag;
72 ASYNC_EVENT_CODE_LINK_STATE); 118
119 be_dws_le_to_cpu(compl, 4);
120
121 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
122 CQE_STATUS_COMPL_MASK;
123 /* The ctrl.mcc_numtag[tag] is filled with
124 * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
125 * [7:0] = compl_status
126 */
127 tag = (compl->tag0 & 0x000000FF);
128 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
129 CQE_STATUS_EXTD_MASK;
130
131 ctrl->mcc_numtag[tag] = 0x80000000;
132 ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
133 ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
134 ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
135 wake_up_interruptible(&ctrl->mcc_wait[tag]);
136 return 0;
73} 137}
74 138
75static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba) 139static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
@@ -89,7 +153,7 @@ static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
89 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED); 153 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
90} 154}
91 155
92static void beiscsi_async_link_state_process(struct beiscsi_hba *phba, 156void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
93 struct be_async_event_link_state *evt) 157 struct be_async_event_link_state *evt)
94{ 158{
95 switch (evt->port_link_status) { 159 switch (evt->port_link_status) {
@@ -97,13 +161,13 @@ static void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
97 SE_DEBUG(DBG_LVL_1, "Link Down on Physical Port %d \n", 161 SE_DEBUG(DBG_LVL_1, "Link Down on Physical Port %d \n",
98 evt->physical_port); 162 evt->physical_port);
99 phba->state |= BE_ADAPTER_LINK_DOWN; 163 phba->state |= BE_ADAPTER_LINK_DOWN;
164 iscsi_host_for_each_session(phba->shost,
165 be2iscsi_fail_session);
100 break; 166 break;
101 case ASYNC_EVENT_LINK_UP: 167 case ASYNC_EVENT_LINK_UP:
102 phba->state = BE_ADAPTER_UP; 168 phba->state = BE_ADAPTER_UP;
103 SE_DEBUG(DBG_LVL_1, "Link UP on Physical Port %d \n", 169 SE_DEBUG(DBG_LVL_1, "Link UP on Physical Port %d \n",
104 evt->physical_port); 170 evt->physical_port);
105 iscsi_host_for_each_session(phba->shost,
106 be2iscsi_fail_session);
107 break; 171 break;
108 default: 172 default:
109 SE_DEBUG(DBG_LVL_1, "Unexpected Async Notification %d on" 173 SE_DEBUG(DBG_LVL_1, "Unexpected Async Notification %d on"
@@ -162,7 +226,6 @@ int beiscsi_process_mcc(struct beiscsi_hba *phba)
162/* Wait till no more pending mcc requests are present */ 226/* Wait till no more pending mcc requests are present */
163static int be_mcc_wait_compl(struct beiscsi_hba *phba) 227static int be_mcc_wait_compl(struct beiscsi_hba *phba)
164{ 228{
165#define mcc_timeout 120000 /* 5s timeout */
166 int i, status; 229 int i, status;
167 for (i = 0; i < mcc_timeout; i++) { 230 for (i = 0; i < mcc_timeout; i++) {
168 status = beiscsi_process_mcc(phba); 231 status = beiscsi_process_mcc(phba);
@@ -372,9 +435,10 @@ struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
372 435
373 BUG_ON(atomic_read(&mccq->used) >= mccq->len); 436 BUG_ON(atomic_read(&mccq->used) >= mccq->len);
374 wrb = queue_head_node(mccq); 437 wrb = queue_head_node(mccq);
438 memset(wrb, 0, sizeof(*wrb));
439 wrb->tag0 = (mccq->head & 0x000000FF) << 16;
375 queue_head_inc(mccq); 440 queue_head_inc(mccq);
376 atomic_inc(&mccq->used); 441 atomic_inc(&mccq->used);
377 memset(wrb, 0, sizeof(*wrb));
378 return wrb; 442 return wrb;
379} 443}
380 444
diff --git a/drivers/scsi/be2iscsi/be_cmds.h b/drivers/scsi/be2iscsi/be_cmds.h
index 5de8acb924cb..49fcc787ee8b 100644
--- a/drivers/scsi/be2iscsi/be_cmds.h
+++ b/drivers/scsi/be2iscsi/be_cmds.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -425,14 +425,20 @@ int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
425int be_poll_mcc(struct be_ctrl_info *ctrl); 425int be_poll_mcc(struct be_ctrl_info *ctrl);
426unsigned char mgmt_check_supported_fw(struct be_ctrl_info *ctrl, 426unsigned char mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
427 struct beiscsi_hba *phba); 427 struct beiscsi_hba *phba);
428int be_cmd_get_mac_addr(struct beiscsi_hba *phba, u8 *mac_addr); 428unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba);
429 429void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag);
430/*ISCSI Functuions */ 430/*ISCSI Functuions */
431int be_cmd_fw_initialize(struct be_ctrl_info *ctrl); 431int be_cmd_fw_initialize(struct be_ctrl_info *ctrl);
432 432
433struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem); 433struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem);
434struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba); 434struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba);
435int be_mcc_notify_wait(struct beiscsi_hba *phba); 435int be_mcc_notify_wait(struct beiscsi_hba *phba);
436void be_mcc_notify(struct beiscsi_hba *phba);
437unsigned int alloc_mcc_tag(struct beiscsi_hba *phba);
438void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
439 struct be_async_event_link_state *evt);
440int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
441 struct be_mcc_compl *compl);
436 442
437int be_mbox_notify(struct be_ctrl_info *ctrl); 443int be_mbox_notify(struct be_ctrl_info *ctrl);
438 444
@@ -448,6 +454,8 @@ int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
448int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem, 454int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
449 struct be_queue_info *wrbq); 455 struct be_queue_info *wrbq);
450 456
457bool is_link_state_evt(u32 trailer);
458
451struct be_default_pdu_context { 459struct be_default_pdu_context {
452 u32 dw[4]; 460 u32 dw[4];
453} __packed; 461} __packed;
diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c
index d587b0362f18..29a3aaf35f9f 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.c
+++ b/drivers/scsi/be2iscsi/be_iscsi.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -101,6 +101,7 @@ void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
101 struct iscsi_session *sess = cls_session->dd_data; 101 struct iscsi_session *sess = cls_session->dd_data;
102 struct beiscsi_session *beiscsi_sess = sess->dd_data; 102 struct beiscsi_session *beiscsi_sess = sess->dd_data;
103 103
104 SE_DEBUG(DBG_LVL_8, "In beiscsi_session_destroy\n");
104 pci_pool_destroy(beiscsi_sess->bhs_pool); 105 pci_pool_destroy(beiscsi_sess->bhs_pool);
105 iscsi_session_teardown(cls_session); 106 iscsi_session_teardown(cls_session);
106} 107}
@@ -224,6 +225,7 @@ int beiscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
224 struct beiscsi_conn *beiscsi_conn = conn->dd_data; 225 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
225 int len = 0; 226 int len = 0;
226 227
228 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_param, param= %d\n", param);
227 beiscsi_ep = beiscsi_conn->ep; 229 beiscsi_ep = beiscsi_conn->ep;
228 if (!beiscsi_ep) { 230 if (!beiscsi_ep) {
229 SE_DEBUG(DBG_LVL_1, 231 SE_DEBUG(DBG_LVL_1,
@@ -254,6 +256,7 @@ int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
254 struct iscsi_session *session = conn->session; 256 struct iscsi_session *session = conn->session;
255 int ret; 257 int ret;
256 258
259 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_set_param, param= %d\n", param);
257 ret = iscsi_set_param(cls_conn, param, buf, buflen); 260 ret = iscsi_set_param(cls_conn, param, buf, buflen);
258 if (ret) 261 if (ret)
259 return ret; 262 return ret;
@@ -271,8 +274,8 @@ int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
271 conn->max_recv_dlength = 65536; 274 conn->max_recv_dlength = 65536;
272 break; 275 break;
273 case ISCSI_PARAM_MAX_BURST: 276 case ISCSI_PARAM_MAX_BURST:
274 if (session->first_burst > 262144) 277 if (session->max_burst > 262144)
275 session->first_burst = 262144; 278 session->max_burst = 262144;
276 break; 279 break;
277 default: 280 default:
278 return 0; 281 return 0;
@@ -293,12 +296,41 @@ int beiscsi_get_host_param(struct Scsi_Host *shost,
293 enum iscsi_host_param param, char *buf) 296 enum iscsi_host_param param, char *buf)
294{ 297{
295 struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost); 298 struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost);
299 struct be_cmd_resp_get_mac_addr *resp;
300 struct be_mcc_wrb *wrb;
301 unsigned int tag, wrb_num;
296 int len = 0; 302 int len = 0;
303 unsigned short status, extd_status;
304 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
297 305
306 SE_DEBUG(DBG_LVL_8, "In beiscsi_get_host_param, param= %d\n", param);
298 switch (param) { 307 switch (param) {
299 case ISCSI_HOST_PARAM_HWADDRESS: 308 case ISCSI_HOST_PARAM_HWADDRESS:
300 be_cmd_get_mac_addr(phba, phba->mac_address); 309 tag = be_cmd_get_mac_addr(phba);
301 len = sysfs_format_mac(buf, phba->mac_address, ETH_ALEN); 310 if (!tag) {
311 SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed \n");
312 return -1;
313 } else
314 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
315 phba->ctrl.mcc_numtag[tag]);
316
317 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
318 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
319 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
320 if (status || extd_status) {
321 SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed"
322 " status = %d extd_status = %d \n",
323 status, extd_status);
324 free_mcc_tag(&phba->ctrl, tag);
325 return -1;
326 } else {
327 wrb = queue_get_wrb(mccq, wrb_num);
328 free_mcc_tag(&phba->ctrl, tag);
329 resp = embedded_payload(wrb);
330 memcpy(phba->mac_address, resp->mac_address, ETH_ALEN);
331 len = sysfs_format_mac(buf, phba->mac_address,
332 ETH_ALEN);
333 }
302 break; 334 break;
303 default: 335 default:
304 return iscsi_host_get_param(shost, param, buf); 336 return iscsi_host_get_param(shost, param, buf);
@@ -378,6 +410,7 @@ int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
378 struct beiscsi_endpoint *beiscsi_ep; 410 struct beiscsi_endpoint *beiscsi_ep;
379 struct beiscsi_offload_params params; 411 struct beiscsi_offload_params params;
380 412
413 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_start\n");
381 memset(&params, 0, sizeof(struct beiscsi_offload_params)); 414 memset(&params, 0, sizeof(struct beiscsi_offload_params));
382 beiscsi_ep = beiscsi_conn->ep; 415 beiscsi_ep = beiscsi_conn->ep;
383 if (!beiscsi_ep) 416 if (!beiscsi_ep)
@@ -422,8 +455,14 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
422{ 455{
423 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; 456 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
424 struct beiscsi_hba *phba = beiscsi_ep->phba; 457 struct beiscsi_hba *phba = beiscsi_ep->phba;
458 struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
459 struct be_mcc_wrb *wrb;
460 struct tcp_connect_and_offload_out *ptcpcnct_out;
461 unsigned short status, extd_status;
462 unsigned int tag, wrb_num;
425 int ret = -1; 463 int ret = -1;
426 464
465 SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn\n");
427 beiscsi_ep->ep_cid = beiscsi_get_cid(phba); 466 beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
428 if (beiscsi_ep->ep_cid == 0xFFFF) { 467 if (beiscsi_ep->ep_cid == 0xFFFF) {
429 SE_DEBUG(DBG_LVL_1, "No free cid available\n"); 468 SE_DEBUG(DBG_LVL_1, "No free cid available\n");
@@ -431,15 +470,44 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
431 } 470 }
432 SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn, ep_cid=%d ", 471 SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn, ep_cid=%d ",
433 beiscsi_ep->ep_cid); 472 beiscsi_ep->ep_cid);
434 phba->ep_array[beiscsi_ep->ep_cid] = ep; 473 phba->ep_array[beiscsi_ep->ep_cid -
435 if (beiscsi_ep->ep_cid > 474 phba->fw_config.iscsi_cid_start] = ep;
436 (phba->fw_config.iscsi_cid_start + phba->params.cxns_per_ctrl)) { 475 if (beiscsi_ep->ep_cid > (phba->fw_config.iscsi_cid_start +
476 phba->params.cxns_per_ctrl * 2)) {
437 SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n"); 477 SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n");
438 return ret; 478 return ret;
439 } 479 }
440 480
441 beiscsi_ep->cid_vld = 0; 481 beiscsi_ep->cid_vld = 0;
442 return mgmt_open_connection(phba, dst_addr, beiscsi_ep); 482 tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep);
483 if (!tag) {
484 SE_DEBUG(DBG_LVL_1,
485 "mgmt_invalidate_connection Failed for cid=%d \n",
486 beiscsi_ep->ep_cid);
487 } else {
488 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
489 phba->ctrl.mcc_numtag[tag]);
490 }
491 wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
492 extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
493 status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
494 if (status || extd_status) {
495 SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed"
496 " status = %d extd_status = %d \n",
497 status, extd_status);
498 free_mcc_tag(&phba->ctrl, tag);
499 return -1;
500 } else {
501 wrb = queue_get_wrb(mccq, wrb_num);
502 free_mcc_tag(&phba->ctrl, tag);
503
504 ptcpcnct_out = embedded_payload(wrb);
505 beiscsi_ep = ep->dd_data;
506 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
507 beiscsi_ep->cid_vld = 1;
508 SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
509 }
510 return 0;
443} 511}
444 512
445/** 513/**
@@ -459,14 +527,12 @@ static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
459 * beiscsi_free_ep - free endpoint 527 * beiscsi_free_ep - free endpoint
460 * @ep: pointer to iscsi endpoint structure 528 * @ep: pointer to iscsi endpoint structure
461 */ 529 */
462static void beiscsi_free_ep(struct iscsi_endpoint *ep) 530static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
463{ 531{
464 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
465 struct beiscsi_hba *phba = beiscsi_ep->phba; 532 struct beiscsi_hba *phba = beiscsi_ep->phba;
466 533
467 beiscsi_put_cid(phba, beiscsi_ep->ep_cid); 534 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
468 beiscsi_ep->phba = NULL; 535 beiscsi_ep->phba = NULL;
469 iscsi_destroy_endpoint(ep);
470} 536}
471 537
472/** 538/**
@@ -495,9 +561,9 @@ beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
495 return ERR_PTR(ret); 561 return ERR_PTR(ret);
496 } 562 }
497 563
498 if (phba->state) { 564 if (phba->state != BE_ADAPTER_UP) {
499 ret = -EBUSY; 565 ret = -EBUSY;
500 SE_DEBUG(DBG_LVL_1, "The Adapet state is Not UP \n"); 566 SE_DEBUG(DBG_LVL_1, "The Adapter state is Not UP \n");
501 return ERR_PTR(ret); 567 return ERR_PTR(ret);
502 } 568 }
503 569
@@ -509,9 +575,9 @@ beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
509 575
510 beiscsi_ep = ep->dd_data; 576 beiscsi_ep = ep->dd_data;
511 beiscsi_ep->phba = phba; 577 beiscsi_ep->phba = phba;
512 578 beiscsi_ep->openiscsi_ep = ep;
513 if (beiscsi_open_conn(ep, NULL, dst_addr, non_blocking)) { 579 if (beiscsi_open_conn(ep, NULL, dst_addr, non_blocking)) {
514 SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n"); 580 SE_DEBUG(DBG_LVL_1, "Failed in beiscsi_open_conn \n");
515 ret = -ENOMEM; 581 ret = -ENOMEM;
516 goto free_ep; 582 goto free_ep;
517 } 583 }
@@ -519,7 +585,7 @@ beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
519 return ep; 585 return ep;
520 586
521free_ep: 587free_ep:
522 beiscsi_free_ep(ep); 588 beiscsi_free_ep(beiscsi_ep);
523 return ERR_PTR(ret); 589 return ERR_PTR(ret);
524} 590}
525 591
@@ -546,20 +612,22 @@ int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
546 * @ep: The iscsi endpoint 612 * @ep: The iscsi endpoint
547 * @flag: The type of connection closure 613 * @flag: The type of connection closure
548 */ 614 */
549static int beiscsi_close_conn(struct iscsi_endpoint *ep, int flag) 615static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
550{ 616{
551 int ret = 0; 617 int ret = 0;
552 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; 618 unsigned int tag;
553 struct beiscsi_hba *phba = beiscsi_ep->phba; 619 struct beiscsi_hba *phba = beiscsi_ep->phba;
554 620
555 if (MGMT_STATUS_SUCCESS != 621 tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
556 mgmt_upload_connection(phba, beiscsi_ep->ep_cid, 622 if (!tag) {
557 CONNECTION_UPLOAD_GRACEFUL)) {
558 SE_DEBUG(DBG_LVL_8, "upload failed for cid 0x%x", 623 SE_DEBUG(DBG_LVL_8, "upload failed for cid 0x%x",
559 beiscsi_ep->ep_cid); 624 beiscsi_ep->ep_cid);
560 ret = -1; 625 ret = -1;
626 } else {
627 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
628 phba->ctrl.mcc_numtag[tag]);
629 free_mcc_tag(&phba->ctrl, tag);
561 } 630 }
562
563 return ret; 631 return ret;
564} 632}
565 633
@@ -574,19 +642,17 @@ void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
574 struct beiscsi_conn *beiscsi_conn; 642 struct beiscsi_conn *beiscsi_conn;
575 struct beiscsi_endpoint *beiscsi_ep; 643 struct beiscsi_endpoint *beiscsi_ep;
576 struct beiscsi_hba *phba; 644 struct beiscsi_hba *phba;
577 int flag = 0;
578 645
579 beiscsi_ep = ep->dd_data; 646 beiscsi_ep = ep->dd_data;
580 phba = beiscsi_ep->phba; 647 phba = beiscsi_ep->phba;
581 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect\n"); 648 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect for ep_cid = %d\n",
649 beiscsi_ep->ep_cid);
582 650
583 if (beiscsi_ep->conn) { 651 if (beiscsi_ep->conn) {
584 beiscsi_conn = beiscsi_ep->conn; 652 beiscsi_conn = beiscsi_ep->conn;
585 iscsi_suspend_queue(beiscsi_conn->conn); 653 iscsi_suspend_queue(beiscsi_conn->conn);
586 beiscsi_close_conn(ep, flag);
587 } 654 }
588 655
589 beiscsi_free_ep(ep);
590} 656}
591 657
592/** 658/**
@@ -619,23 +685,31 @@ void beiscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
619 struct iscsi_session *session = conn->session; 685 struct iscsi_session *session = conn->session;
620 struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session); 686 struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session);
621 struct beiscsi_hba *phba = iscsi_host_priv(shost); 687 struct beiscsi_hba *phba = iscsi_host_priv(shost);
622 unsigned int status; 688 unsigned int tag;
623 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH; 689 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
624 690
625 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop\n");
626 beiscsi_ep = beiscsi_conn->ep; 691 beiscsi_ep = beiscsi_conn->ep;
627 if (!beiscsi_ep) { 692 if (!beiscsi_ep) {
628 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop , no beiscsi_ep\n"); 693 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop , no beiscsi_ep\n");
629 return; 694 return;
630 } 695 }
631 status = mgmt_invalidate_connection(phba, beiscsi_ep, 696 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop ep_cid = %d\n",
697 beiscsi_ep->ep_cid);
698 tag = mgmt_invalidate_connection(phba, beiscsi_ep,
632 beiscsi_ep->ep_cid, 1, 699 beiscsi_ep->ep_cid, 1,
633 savecfg_flag); 700 savecfg_flag);
634 if (status != MGMT_STATUS_SUCCESS) { 701 if (!tag) {
635 SE_DEBUG(DBG_LVL_1, 702 SE_DEBUG(DBG_LVL_1,
636 "mgmt_invalidate_connection Failed for cid=%d \n", 703 "mgmt_invalidate_connection Failed for cid=%d \n",
637 beiscsi_ep->ep_cid); 704 beiscsi_ep->ep_cid);
705 } else {
706 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
707 phba->ctrl.mcc_numtag[tag]);
708 free_mcc_tag(&phba->ctrl, tag);
638 } 709 }
710 beiscsi_close_conn(beiscsi_ep, CONNECTION_UPLOAD_GRACEFUL);
711 beiscsi_free_ep(beiscsi_ep);
712 iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
639 beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid); 713 beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
640 iscsi_conn_stop(cls_conn, flag); 714 iscsi_conn_stop(cls_conn, flag);
641} 715}
diff --git a/drivers/scsi/be2iscsi/be_iscsi.h b/drivers/scsi/be2iscsi/be_iscsi.h
index f92ffc5349fb..1f512c28cbf9 100644
--- a/drivers/scsi/be2iscsi/be_iscsi.h
+++ b/drivers/scsi/be2iscsi/be_iscsi.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 1a557fa77888..7c22616ab141 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -40,7 +40,6 @@
40static unsigned int be_iopoll_budget = 10; 40static unsigned int be_iopoll_budget = 10;
41static unsigned int be_max_phys_size = 64; 41static unsigned int be_max_phys_size = 64;
42static unsigned int enable_msix = 1; 42static unsigned int enable_msix = 1;
43static unsigned int ring_mode;
44 43
45MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); 44MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
46MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR); 45MODULE_DESCRIPTION(DRV_DESC " " BUILD_STR);
@@ -62,10 +61,10 @@ static int beiscsi_slave_configure(struct scsi_device *sdev)
62/*------------------- PCI Driver operations and data ----------------- */ 61/*------------------- PCI Driver operations and data ----------------- */
63static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = { 62static DEFINE_PCI_DEVICE_TABLE(beiscsi_pci_id_table) = {
64 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) }, 63 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
64 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
65 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) }, 65 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
66 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) }, 66 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
67 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) }, 67 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID3) },
68 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID4) },
69 { 0 } 68 { 0 }
70}; 69};
71MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table); 70MODULE_DEVICE_TABLE(pci, beiscsi_pci_id_table);
@@ -112,6 +111,7 @@ static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev)
112 memset(phba, 0, sizeof(*phba)); 111 memset(phba, 0, sizeof(*phba));
113 phba->shost = shost; 112 phba->shost = shost;
114 phba->pcidev = pci_dev_get(pcidev); 113 phba->pcidev = pci_dev_get(pcidev);
114 pci_set_drvdata(pcidev, phba);
115 115
116 if (iscsi_host_add(shost, &phba->pcidev->dev)) 116 if (iscsi_host_add(shost, &phba->pcidev->dev))
117 goto free_devices; 117 goto free_devices;
@@ -143,6 +143,7 @@ static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
143 struct pci_dev *pcidev) 143 struct pci_dev *pcidev)
144{ 144{
145 u8 __iomem *addr; 145 u8 __iomem *addr;
146 int pcicfg_reg;
146 147
147 addr = ioremap_nocache(pci_resource_start(pcidev, 2), 148 addr = ioremap_nocache(pci_resource_start(pcidev, 2),
148 pci_resource_len(pcidev, 2)); 149 pci_resource_len(pcidev, 2));
@@ -159,13 +160,19 @@ static int beiscsi_map_pci_bars(struct beiscsi_hba *phba,
159 phba->db_va = addr; 160 phba->db_va = addr;
160 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4); 161 phba->db_pa.u.a64.address = pci_resource_start(pcidev, 4);
161 162
162 addr = ioremap_nocache(pci_resource_start(pcidev, 1), 163 if (phba->generation == BE_GEN2)
163 pci_resource_len(pcidev, 1)); 164 pcicfg_reg = 1;
165 else
166 pcicfg_reg = 0;
167
168 addr = ioremap_nocache(pci_resource_start(pcidev, pcicfg_reg),
169 pci_resource_len(pcidev, pcicfg_reg));
170
164 if (addr == NULL) 171 if (addr == NULL)
165 goto pci_map_err; 172 goto pci_map_err;
166 phba->ctrl.pcicfg = addr; 173 phba->ctrl.pcicfg = addr;
167 phba->pci_va = addr; 174 phba->pci_va = addr;
168 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, 1); 175 phba->pci_pa.u.a64.address = pci_resource_start(pcidev, pcicfg_reg);
169 return 0; 176 return 0;
170 177
171pci_map_err: 178pci_map_err:
@@ -230,29 +237,27 @@ static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
230 237
231static void beiscsi_get_params(struct beiscsi_hba *phba) 238static void beiscsi_get_params(struct beiscsi_hba *phba)
232{ 239{
233 phba->params.ios_per_ctrl = BE2_IO_DEPTH; 240 phba->params.ios_per_ctrl = (phba->fw_config.iscsi_icd_count
234 phba->params.cxns_per_ctrl = BE2_MAX_SESSIONS; 241 - (phba->fw_config.iscsi_cid_count
235 phba->params.asyncpdus_per_ctrl = BE2_ASYNCPDUS; 242 + BE2_TMFS
236 phba->params.icds_per_ctrl = BE2_MAX_ICDS / 2; 243 + BE2_NOPOUT_REQ));
244 phba->params.cxns_per_ctrl = phba->fw_config.iscsi_cid_count;
245 phba->params.asyncpdus_per_ctrl = phba->fw_config.iscsi_cid_count;;
246 phba->params.icds_per_ctrl = phba->fw_config.iscsi_icd_count;;
237 phba->params.num_sge_per_io = BE2_SGE; 247 phba->params.num_sge_per_io = BE2_SGE;
238 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ; 248 phba->params.defpdu_hdr_sz = BE2_DEFPDU_HDR_SZ;
239 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ; 249 phba->params.defpdu_data_sz = BE2_DEFPDU_DATA_SZ;
240 phba->params.eq_timer = 64; 250 phba->params.eq_timer = 64;
241 phba->params.num_eq_entries = 251 phba->params.num_eq_entries =
242 (((BE2_CMDS_PER_CXN * 2 + BE2_LOGOUTS + BE2_TMFS + BE2_ASYNCPDUS) / 252 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
243 512) + 1) * 512; 253 + BE2_TMFS) / 512) + 1) * 512;
244 phba->params.num_eq_entries = (phba->params.num_eq_entries < 1024) 254 phba->params.num_eq_entries = (phba->params.num_eq_entries < 1024)
245 ? 1024 : phba->params.num_eq_entries; 255 ? 1024 : phba->params.num_eq_entries;
246 SE_DEBUG(DBG_LVL_8, "phba->params.num_eq_entries=%d \n", 256 SE_DEBUG(DBG_LVL_8, "phba->params.num_eq_entries=%d \n",
247 phba->params.num_eq_entries); 257 phba->params.num_eq_entries);
248 phba->params.num_cq_entries = 258 phba->params.num_cq_entries =
249 (((BE2_CMDS_PER_CXN * 2 + BE2_LOGOUTS + BE2_TMFS + BE2_ASYNCPDUS) / 259 (((BE2_CMDS_PER_CXN * 2 + phba->fw_config.iscsi_cid_count * 2
250 512) + 1) * 512; 260 + BE2_TMFS) / 512) + 1) * 512;
251 SE_DEBUG(DBG_LVL_8,
252 "phba->params.num_cq_entries=%d BE2_CMDS_PER_CXN=%d"
253 "BE2_LOGOUTS=%d BE2_TMFS=%d BE2_ASYNCPDUS=%d \n",
254 phba->params.num_cq_entries, BE2_CMDS_PER_CXN,
255 BE2_LOGOUTS, BE2_TMFS, BE2_ASYNCPDUS);
256 phba->params.wrbs_per_cxn = 256; 261 phba->params.wrbs_per_cxn = 256;
257} 262}
258 263
@@ -443,7 +448,7 @@ static irqreturn_t be_isr(int irq, void *dev_id)
443 if (phba->todo_mcc_cq) 448 if (phba->todo_mcc_cq)
444 queue_work(phba->wq, &phba->work_cqs); 449 queue_work(phba->wq, &phba->work_cqs);
445 450
446 if ((num_mcceq_processed) && (!num_ioeq_processed)) 451 if ((num_mcceq_processed) && (!num_ioeq_processed))
447 hwi_ring_eq_db(phba, eq->id, 0, 452 hwi_ring_eq_db(phba, eq->id, 0,
448 (num_ioeq_processed + 453 (num_ioeq_processed +
449 num_mcceq_processed) , 1, 1); 454 num_mcceq_processed) , 1, 1);
@@ -561,6 +566,7 @@ beiscsi_process_async_pdu(struct beiscsi_conn *beiscsi_conn,
561 SE_DEBUG(DBG_LVL_1, "In ISCSI_OP_REJECT\n"); 566 SE_DEBUG(DBG_LVL_1, "In ISCSI_OP_REJECT\n");
562 break; 567 break;
563 case ISCSI_OP_LOGIN_RSP: 568 case ISCSI_OP_LOGIN_RSP:
569 case ISCSI_OP_TEXT_RSP:
564 task = conn->login_task; 570 task = conn->login_task;
565 io_task = task->dd_data; 571 io_task = task->dd_data;
566 login_hdr = (struct iscsi_hdr *)ppdu; 572 login_hdr = (struct iscsi_hdr *)ppdu;
@@ -631,29 +637,29 @@ free_io_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle)
631 * alloc_wrb_handle - To allocate a wrb handle 637 * alloc_wrb_handle - To allocate a wrb handle
632 * @phba: The hba pointer 638 * @phba: The hba pointer
633 * @cid: The cid to use for allocation 639 * @cid: The cid to use for allocation
634 * @index: index allocation and wrb index
635 * 640 *
636 * This happens under session_lock until submission to chip 641 * This happens under session_lock until submission to chip
637 */ 642 */
638struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid, 643struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid)
639 int index)
640{ 644{
641 struct hwi_wrb_context *pwrb_context; 645 struct hwi_wrb_context *pwrb_context;
642 struct hwi_controller *phwi_ctrlr; 646 struct hwi_controller *phwi_ctrlr;
643 struct wrb_handle *pwrb_handle; 647 struct wrb_handle *pwrb_handle, *pwrb_handle_tmp;
644 648
645 phwi_ctrlr = phba->phwi_ctrlr; 649 phwi_ctrlr = phba->phwi_ctrlr;
646 pwrb_context = &phwi_ctrlr->wrb_context[cid]; 650 pwrb_context = &phwi_ctrlr->wrb_context[cid];
647 if (pwrb_context->wrb_handles_available) { 651 if (pwrb_context->wrb_handles_available >= 2) {
648 pwrb_handle = pwrb_context->pwrb_handle_base[ 652 pwrb_handle = pwrb_context->pwrb_handle_base[
649 pwrb_context->alloc_index]; 653 pwrb_context->alloc_index];
650 pwrb_context->wrb_handles_available--; 654 pwrb_context->wrb_handles_available--;
651 pwrb_handle->nxt_wrb_index = pwrb_handle->wrb_index;
652 if (pwrb_context->alloc_index == 655 if (pwrb_context->alloc_index ==
653 (phba->params.wrbs_per_cxn - 1)) 656 (phba->params.wrbs_per_cxn - 1))
654 pwrb_context->alloc_index = 0; 657 pwrb_context->alloc_index = 0;
655 else 658 else
656 pwrb_context->alloc_index++; 659 pwrb_context->alloc_index++;
660 pwrb_handle_tmp = pwrb_context->pwrb_handle_base[
661 pwrb_context->alloc_index];
662 pwrb_handle->nxt_wrb_index = pwrb_handle_tmp->wrb_index;
657 } else 663 } else
658 pwrb_handle = NULL; 664 pwrb_handle = NULL;
659 return pwrb_handle; 665 return pwrb_handle;
@@ -671,9 +677,7 @@ static void
671free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context, 677free_wrb_handle(struct beiscsi_hba *phba, struct hwi_wrb_context *pwrb_context,
672 struct wrb_handle *pwrb_handle) 678 struct wrb_handle *pwrb_handle)
673{ 679{
674 if (!ring_mode) 680 pwrb_context->pwrb_handle_base[pwrb_context->free_index] = pwrb_handle;
675 pwrb_context->pwrb_handle_base[pwrb_context->free_index] =
676 pwrb_handle;
677 pwrb_context->wrb_handles_available++; 681 pwrb_context->wrb_handles_available++;
678 if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1)) 682 if (pwrb_context->free_index == (phba->params.wrbs_per_cxn - 1))
679 pwrb_context->free_index = 0; 683 pwrb_context->free_index = 0;
@@ -790,6 +794,7 @@ be_complete_io(struct beiscsi_conn *beiscsi_conn,
790 memcpy(task->sc->sense_buffer, sense, 794 memcpy(task->sc->sense_buffer, sense,
791 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE)); 795 min_t(u16, sense_len, SCSI_SENSE_BUFFERSIZE));
792 } 796 }
797
793 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) { 798 if (io_task->cmd_bhs->iscsi_hdr.flags & ISCSI_FLAG_CMD_READ) {
794 if (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32] 799 if (psol->dw[offsetof(struct amap_sol_cqe, i_res_cnt) / 32]
795 & SOL_RES_CNT_MASK) 800 & SOL_RES_CNT_MASK)
@@ -811,6 +816,7 @@ be_complete_logout(struct beiscsi_conn *beiscsi_conn,
811 struct iscsi_conn *conn = beiscsi_conn->conn; 816 struct iscsi_conn *conn = beiscsi_conn->conn;
812 817
813 hdr = (struct iscsi_logout_rsp *)task->hdr; 818 hdr = (struct iscsi_logout_rsp *)task->hdr;
819 hdr->opcode = ISCSI_OP_LOGOUT_RSP;
814 hdr->t2wait = 5; 820 hdr->t2wait = 5;
815 hdr->t2retain = 0; 821 hdr->t2retain = 0;
816 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32] 822 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
@@ -825,6 +831,9 @@ be_complete_logout(struct beiscsi_conn *beiscsi_conn,
825 & SOL_EXP_CMD_SN_MASK) + 831 & SOL_EXP_CMD_SN_MASK) +
826 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd) 832 ((psol->dw[offsetof(struct amap_sol_cqe, i_cmd_wnd)
827 / 32] & SOL_CMD_WND_MASK) >> 24) - 1); 833 / 32] & SOL_CMD_WND_MASK) >> 24) - 1);
834 hdr->dlength[0] = 0;
835 hdr->dlength[1] = 0;
836 hdr->dlength[2] = 0;
828 hdr->hlength = 0; 837 hdr->hlength = 0;
829 hdr->itt = io_task->libiscsi_itt; 838 hdr->itt = io_task->libiscsi_itt;
830 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0); 839 __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
@@ -839,6 +848,7 @@ be_complete_tmf(struct beiscsi_conn *beiscsi_conn,
839 struct beiscsi_io_task *io_task = task->dd_data; 848 struct beiscsi_io_task *io_task = task->dd_data;
840 849
841 hdr = (struct iscsi_tm_rsp *)task->hdr; 850 hdr = (struct iscsi_tm_rsp *)task->hdr;
851 hdr->opcode = ISCSI_OP_SCSI_TMFUNC_RSP;
842 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32] 852 hdr->flags = ((psol->dw[offsetof(struct amap_sol_cqe, i_flags) / 32]
843 & SOL_FLAGS_MASK) >> 24) | 0x80; 853 & SOL_FLAGS_MASK) >> 24) | 0x80;
844 hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) / 854 hdr->response = (psol->dw[offsetof(struct amap_sol_cqe, i_resp) /
@@ -859,7 +869,6 @@ hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
859{ 869{
860 struct hwi_wrb_context *pwrb_context; 870 struct hwi_wrb_context *pwrb_context;
861 struct wrb_handle *pwrb_handle = NULL; 871 struct wrb_handle *pwrb_handle = NULL;
862 struct sgl_handle *psgl_handle = NULL;
863 struct hwi_controller *phwi_ctrlr; 872 struct hwi_controller *phwi_ctrlr;
864 struct iscsi_task *task; 873 struct iscsi_task *task;
865 struct beiscsi_io_task *io_task; 874 struct beiscsi_io_task *io_task;
@@ -867,22 +876,14 @@ hwi_complete_drvr_msgs(struct beiscsi_conn *beiscsi_conn,
867 struct iscsi_session *session = conn->session; 876 struct iscsi_session *session = conn->session;
868 877
869 phwi_ctrlr = phba->phwi_ctrlr; 878 phwi_ctrlr = phba->phwi_ctrlr;
870 if (ring_mode) { 879 pwrb_context = &phwi_ctrlr->wrb_context[((psol->
871 psgl_handle = phba->sgl_hndl_array[((psol->
872 dw[offsetof(struct amap_sol_cqe_ring, icd_index) /
873 32] & SOL_ICD_INDEX_MASK) >> 6)];
874 pwrb_context = &phwi_ctrlr->wrb_context[psgl_handle->cid];
875 task = psgl_handle->task;
876 pwrb_handle = NULL;
877 } else {
878 pwrb_context = &phwi_ctrlr->wrb_context[((psol->
879 dw[offsetof(struct amap_sol_cqe, cid) / 32] & 880 dw[offsetof(struct amap_sol_cqe, cid) / 32] &
880 SOL_CID_MASK) >> 6)]; 881 SOL_CID_MASK) >> 6) -
881 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol-> 882 phba->fw_config.iscsi_cid_start];
883 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
882 dw[offsetof(struct amap_sol_cqe, wrb_index) / 884 dw[offsetof(struct amap_sol_cqe, wrb_index) /
883 32] & SOL_WRB_INDEX_MASK) >> 16)]; 885 32] & SOL_WRB_INDEX_MASK) >> 16)];
884 task = pwrb_handle->pio_handle; 886 task = pwrb_handle->pio_handle;
885 }
886 887
887 io_task = task->dd_data; 888 io_task = task->dd_data;
888 spin_lock(&phba->mgmt_sgl_lock); 889 spin_lock(&phba->mgmt_sgl_lock);
@@ -923,31 +924,23 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
923 struct iscsi_wrb *pwrb = NULL; 924 struct iscsi_wrb *pwrb = NULL;
924 struct hwi_controller *phwi_ctrlr; 925 struct hwi_controller *phwi_ctrlr;
925 struct iscsi_task *task; 926 struct iscsi_task *task;
926 struct sgl_handle *psgl_handle = NULL;
927 unsigned int type; 927 unsigned int type;
928 struct iscsi_conn *conn = beiscsi_conn->conn; 928 struct iscsi_conn *conn = beiscsi_conn->conn;
929 struct iscsi_session *session = conn->session; 929 struct iscsi_session *session = conn->session;
930 930
931 phwi_ctrlr = phba->phwi_ctrlr; 931 phwi_ctrlr = phba->phwi_ctrlr;
932 if (ring_mode) { 932 pwrb_context = &phwi_ctrlr->wrb_context[((psol->dw[offsetof
933 psgl_handle = phba->sgl_hndl_array[((psol->
934 dw[offsetof(struct amap_sol_cqe_ring, icd_index) /
935 32] & SOL_ICD_INDEX_MASK) >> 6)];
936 task = psgl_handle->task;
937 type = psgl_handle->type;
938 } else {
939 pwrb_context = &phwi_ctrlr->
940 wrb_context[((psol->dw[offsetof
941 (struct amap_sol_cqe, cid) / 32] 933 (struct amap_sol_cqe, cid) / 32]
942 & SOL_CID_MASK) >> 6)]; 934 & SOL_CID_MASK) >> 6) -
943 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol-> 935 phba->fw_config.iscsi_cid_start];
936 pwrb_handle = pwrb_context->pwrb_handle_basestd[((psol->
944 dw[offsetof(struct amap_sol_cqe, wrb_index) / 937 dw[offsetof(struct amap_sol_cqe, wrb_index) /
945 32] & SOL_WRB_INDEX_MASK) >> 16)]; 938 32] & SOL_WRB_INDEX_MASK) >> 16)];
946 task = pwrb_handle->pio_handle; 939 task = pwrb_handle->pio_handle;
947 pwrb = pwrb_handle->pwrb; 940 pwrb = pwrb_handle->pwrb;
948 type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] & 941 type = (pwrb->dw[offsetof(struct amap_iscsi_wrb, type) / 32] &
949 WRB_TYPE_MASK) >> 28; 942 WRB_TYPE_MASK) >> 28;
950 } 943
951 spin_lock_bh(&session->lock); 944 spin_lock_bh(&session->lock);
952 switch (type) { 945 switch (type) {
953 case HWH_TYPE_IO: 946 case HWH_TYPE_IO:
@@ -978,15 +971,7 @@ static void hwi_complete_cmd(struct beiscsi_conn *beiscsi_conn,
978 break; 971 break;
979 972
980 default: 973 default:
981 if (ring_mode) 974 shost_printk(KERN_WARNING, phba->shost,
982 shost_printk(KERN_WARNING, phba->shost,
983 "In hwi_complete_cmd, unknown type = %d"
984 "icd_index 0x%x CID 0x%x\n", type,
985 ((psol->dw[offsetof(struct amap_sol_cqe_ring,
986 icd_index) / 32] & SOL_ICD_INDEX_MASK) >> 6),
987 psgl_handle->cid);
988 else
989 shost_printk(KERN_WARNING, phba->shost,
990 "In hwi_complete_cmd, unknown type = %d" 975 "In hwi_complete_cmd, unknown type = %d"
991 "wrb_index 0x%x CID 0x%x\n", type, 976 "wrb_index 0x%x CID 0x%x\n", type,
992 ((psol->dw[offsetof(struct amap_iscsi_wrb, 977 ((psol->dw[offsetof(struct amap_iscsi_wrb,
@@ -1077,7 +1062,8 @@ hwi_get_async_handle(struct beiscsi_hba *phba,
1077 1062
1078 WARN_ON(!pasync_handle); 1063 WARN_ON(!pasync_handle);
1079 1064
1080 pasync_handle->cri = (unsigned short)beiscsi_conn->beiscsi_conn_cid; 1065 pasync_handle->cri = (unsigned short)beiscsi_conn->beiscsi_conn_cid -
1066 phba->fw_config.iscsi_cid_start;
1081 pasync_handle->is_header = is_header; 1067 pasync_handle->is_header = is_header;
1082 pasync_handle->buffer_len = ((pdpdu_cqe-> 1068 pasync_handle->buffer_len = ((pdpdu_cqe->
1083 dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32] 1069 dw[offsetof(struct amap_i_t_dpdu_cqe, dpl) / 32]
@@ -1327,9 +1313,10 @@ hwi_fwd_async_msg(struct beiscsi_conn *beiscsi_conn,
1327 } 1313 }
1328 1314
1329 status = beiscsi_process_async_pdu(beiscsi_conn, phba, 1315 status = beiscsi_process_async_pdu(beiscsi_conn, phba,
1330 beiscsi_conn->beiscsi_conn_cid, 1316 (beiscsi_conn->beiscsi_conn_cid -
1331 phdr, hdr_len, pfirst_buffer, 1317 phba->fw_config.iscsi_cid_start),
1332 buf_len); 1318 phdr, hdr_len, pfirst_buffer,
1319 buf_len);
1333 1320
1334 if (status == 0) 1321 if (status == 0)
1335 hwi_free_async_msg(phba, cri); 1322 hwi_free_async_msg(phba, cri);
@@ -1422,6 +1409,48 @@ static void hwi_process_default_pdu_ring(struct beiscsi_conn *beiscsi_conn,
1422 hwi_post_async_buffers(phba, pasync_handle->is_header); 1409 hwi_post_async_buffers(phba, pasync_handle->is_header);
1423} 1410}
1424 1411
1412static void beiscsi_process_mcc_isr(struct beiscsi_hba *phba)
1413{
1414 struct be_queue_info *mcc_cq;
1415 struct be_mcc_compl *mcc_compl;
1416 unsigned int num_processed = 0;
1417
1418 mcc_cq = &phba->ctrl.mcc_obj.cq;
1419 mcc_compl = queue_tail_node(mcc_cq);
1420 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1421 while (mcc_compl->flags & CQE_FLAGS_VALID_MASK) {
1422
1423 if (num_processed >= 32) {
1424 hwi_ring_cq_db(phba, mcc_cq->id,
1425 num_processed, 0, 0);
1426 num_processed = 0;
1427 }
1428 if (mcc_compl->flags & CQE_FLAGS_ASYNC_MASK) {
1429 /* Interpret flags as an async trailer */
1430 if (is_link_state_evt(mcc_compl->flags))
1431 /* Interpret compl as a async link evt */
1432 beiscsi_async_link_state_process(phba,
1433 (struct be_async_event_link_state *) mcc_compl);
1434 else
1435 SE_DEBUG(DBG_LVL_1,
1436 " Unsupported Async Event, flags"
1437 " = 0x%08x \n", mcc_compl->flags);
1438 } else if (mcc_compl->flags & CQE_FLAGS_COMPLETED_MASK) {
1439 be_mcc_compl_process_isr(&phba->ctrl, mcc_compl);
1440 atomic_dec(&phba->ctrl.mcc_obj.q.used);
1441 }
1442
1443 mcc_compl->flags = 0;
1444 queue_tail_inc(mcc_cq);
1445 mcc_compl = queue_tail_node(mcc_cq);
1446 mcc_compl->flags = le32_to_cpu(mcc_compl->flags);
1447 num_processed++;
1448 }
1449
1450 if (num_processed > 0)
1451 hwi_ring_cq_db(phba, mcc_cq->id, num_processed, 1, 0);
1452
1453}
1425 1454
1426static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq) 1455static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1427{ 1456{
@@ -1431,7 +1460,8 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1431 unsigned int num_processed = 0; 1460 unsigned int num_processed = 0;
1432 unsigned int tot_nump = 0; 1461 unsigned int tot_nump = 0;
1433 struct beiscsi_conn *beiscsi_conn; 1462 struct beiscsi_conn *beiscsi_conn;
1434 struct sgl_handle *psgl_handle = NULL; 1463 struct beiscsi_endpoint *beiscsi_ep;
1464 struct iscsi_endpoint *ep;
1435 struct beiscsi_hba *phba; 1465 struct beiscsi_hba *phba;
1436 1466
1437 cq = pbe_eq->cq; 1467 cq = pbe_eq->cq;
@@ -1442,32 +1472,13 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1442 CQE_VALID_MASK) { 1472 CQE_VALID_MASK) {
1443 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe)); 1473 be_dws_le_to_cpu(sol, sizeof(struct sol_cqe));
1444 1474
1445 if (ring_mode) { 1475 ep = phba->ep_array[(u32) ((sol->
1446 psgl_handle = phba->sgl_hndl_array[((sol-> 1476 dw[offsetof(struct amap_sol_cqe, cid) / 32] &
1447 dw[offsetof(struct amap_sol_cqe_ring, 1477 SOL_CID_MASK) >> 6) -
1448 icd_index) / 32] & SOL_ICD_INDEX_MASK) 1478 phba->fw_config.iscsi_cid_start];
1449 >> 6)];
1450 beiscsi_conn = phba->conn_table[psgl_handle->cid];
1451 if (!beiscsi_conn || !beiscsi_conn->ep) {
1452 shost_printk(KERN_WARNING, phba->shost,
1453 "Connection table empty for cid = %d\n",
1454 psgl_handle->cid);
1455 return 0;
1456 }
1457 1479
1458 } else { 1480 beiscsi_ep = ep->dd_data;
1459 beiscsi_conn = phba->conn_table[(u32) (sol-> 1481 beiscsi_conn = beiscsi_ep->conn;
1460 dw[offsetof(struct amap_sol_cqe, cid) / 32] &
1461 SOL_CID_MASK) >> 6];
1462
1463 if (!beiscsi_conn || !beiscsi_conn->ep) {
1464 shost_printk(KERN_WARNING, phba->shost,
1465 "Connection table empty for cid = %d\n",
1466 (u32)(sol->dw[offsetof(struct amap_sol_cqe,
1467 cid) / 32] & SOL_CID_MASK) >> 6);
1468 return 0;
1469 }
1470 }
1471 1482
1472 if (num_processed >= 32) { 1483 if (num_processed >= 32) {
1473 hwi_ring_cq_db(phba, cq->id, 1484 hwi_ring_cq_db(phba, cq->id,
@@ -1511,21 +1522,13 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1511 case CMD_CXN_KILLED_ITT_INVALID: 1522 case CMD_CXN_KILLED_ITT_INVALID:
1512 case CMD_CXN_KILLED_SEQ_OUTOFORDER: 1523 case CMD_CXN_KILLED_SEQ_OUTOFORDER:
1513 case CMD_CXN_KILLED_INVALID_DATASN_RCVD: 1524 case CMD_CXN_KILLED_INVALID_DATASN_RCVD:
1514 if (ring_mode) { 1525 SE_DEBUG(DBG_LVL_1,
1515 SE_DEBUG(DBG_LVL_1,
1516 "CQ Error notification for cmd.. "
1517 "code %d cid 0x%x\n",
1518 sol->dw[offsetof(struct amap_sol_cqe, code) /
1519 32] & CQE_CODE_MASK, psgl_handle->cid);
1520 } else {
1521 SE_DEBUG(DBG_LVL_1,
1522 "CQ Error notification for cmd.. " 1526 "CQ Error notification for cmd.. "
1523 "code %d cid 0x%x\n", 1527 "code %d cid 0x%x\n",
1524 sol->dw[offsetof(struct amap_sol_cqe, code) / 1528 sol->dw[offsetof(struct amap_sol_cqe, code) /
1525 32] & CQE_CODE_MASK, 1529 32] & CQE_CODE_MASK,
1526 (sol->dw[offsetof(struct amap_sol_cqe, cid) / 1530 (sol->dw[offsetof(struct amap_sol_cqe, cid) /
1527 32] & SOL_CID_MASK)); 1531 32] & SOL_CID_MASK));
1528 }
1529 break; 1532 break;
1530 case UNSOL_DATA_DIGEST_ERROR_NOTIFY: 1533 case UNSOL_DATA_DIGEST_ERROR_NOTIFY:
1531 SE_DEBUG(DBG_LVL_1, 1534 SE_DEBUG(DBG_LVL_1,
@@ -1547,37 +1550,23 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1547 case CXN_KILLED_OVER_RUN_RESIDUAL: 1550 case CXN_KILLED_OVER_RUN_RESIDUAL:
1548 case CXN_KILLED_UNDER_RUN_RESIDUAL: 1551 case CXN_KILLED_UNDER_RUN_RESIDUAL:
1549 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN: 1552 case CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN:
1550 if (ring_mode) { 1553 SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset CID "
1551 SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset CID "
1552 "0x%x...\n",
1553 sol->dw[offsetof(struct amap_sol_cqe, code) /
1554 32] & CQE_CODE_MASK, psgl_handle->cid);
1555 } else {
1556 SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset CID "
1557 "0x%x...\n", 1554 "0x%x...\n",
1558 sol->dw[offsetof(struct amap_sol_cqe, code) / 1555 sol->dw[offsetof(struct amap_sol_cqe, code) /
1559 32] & CQE_CODE_MASK, 1556 32] & CQE_CODE_MASK,
1560 sol->dw[offsetof(struct amap_sol_cqe, cid) / 1557 (sol->dw[offsetof(struct amap_sol_cqe, cid) /
1561 32] & CQE_CID_MASK); 1558 32] & CQE_CID_MASK));
1562 }
1563 iscsi_conn_failure(beiscsi_conn->conn, 1559 iscsi_conn_failure(beiscsi_conn->conn,
1564 ISCSI_ERR_CONN_FAILED); 1560 ISCSI_ERR_CONN_FAILED);
1565 break; 1561 break;
1566 case CXN_KILLED_RST_SENT: 1562 case CXN_KILLED_RST_SENT:
1567 case CXN_KILLED_RST_RCVD: 1563 case CXN_KILLED_RST_RCVD:
1568 if (ring_mode) { 1564 SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset"
1569 SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset"
1570 "received/sent on CID 0x%x...\n",
1571 sol->dw[offsetof(struct amap_sol_cqe, code) /
1572 32] & CQE_CODE_MASK, psgl_handle->cid);
1573 } else {
1574 SE_DEBUG(DBG_LVL_1, "CQ Error %d, reset"
1575 "received/sent on CID 0x%x...\n", 1565 "received/sent on CID 0x%x...\n",
1576 sol->dw[offsetof(struct amap_sol_cqe, code) / 1566 sol->dw[offsetof(struct amap_sol_cqe, code) /
1577 32] & CQE_CODE_MASK, 1567 32] & CQE_CODE_MASK,
1578 sol->dw[offsetof(struct amap_sol_cqe, cid) / 1568 (sol->dw[offsetof(struct amap_sol_cqe, cid) /
1579 32] & CQE_CID_MASK); 1569 32] & CQE_CID_MASK));
1580 }
1581 iscsi_conn_failure(beiscsi_conn->conn, 1570 iscsi_conn_failure(beiscsi_conn->conn,
1582 ISCSI_ERR_CONN_FAILED); 1571 ISCSI_ERR_CONN_FAILED);
1583 break; 1572 break;
@@ -1586,8 +1575,8 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1586 "received on CID 0x%x...\n", 1575 "received on CID 0x%x...\n",
1587 sol->dw[offsetof(struct amap_sol_cqe, code) / 1576 sol->dw[offsetof(struct amap_sol_cqe, code) /
1588 32] & CQE_CODE_MASK, 1577 32] & CQE_CODE_MASK,
1589 sol->dw[offsetof(struct amap_sol_cqe, cid) / 1578 (sol->dw[offsetof(struct amap_sol_cqe, cid) /
1590 32] & CQE_CID_MASK); 1579 32] & CQE_CID_MASK));
1591 break; 1580 break;
1592 } 1581 }
1593 1582
@@ -1604,7 +1593,7 @@ static unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq)
1604 return tot_nump; 1593 return tot_nump;
1605} 1594}
1606 1595
1607static void beiscsi_process_all_cqs(struct work_struct *work) 1596void beiscsi_process_all_cqs(struct work_struct *work)
1608{ 1597{
1609 unsigned long flags; 1598 unsigned long flags;
1610 struct hwi_controller *phwi_ctrlr; 1599 struct hwi_controller *phwi_ctrlr;
@@ -1624,6 +1613,7 @@ static void beiscsi_process_all_cqs(struct work_struct *work)
1624 spin_lock_irqsave(&phba->isr_lock, flags); 1613 spin_lock_irqsave(&phba->isr_lock, flags);
1625 phba->todo_mcc_cq = 0; 1614 phba->todo_mcc_cq = 0;
1626 spin_unlock_irqrestore(&phba->isr_lock, flags); 1615 spin_unlock_irqrestore(&phba->isr_lock, flags);
1616 beiscsi_process_mcc_isr(phba);
1627 } 1617 }
1628 1618
1629 if (phba->todo_cq) { 1619 if (phba->todo_cq) {
@@ -1668,7 +1658,8 @@ hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
1668 io_task->bhs_pa.u.a32.address_hi); 1658 io_task->bhs_pa.u.a32.address_hi);
1669 1659
1670 l_sg = sg; 1660 l_sg = sg;
1671 for (index = 0; (index < num_sg) && (index < 2); index++, sg_next(sg)) { 1661 for (index = 0; (index < num_sg) && (index < 2); index++,
1662 sg = sg_next(sg)) {
1672 if (index == 0) { 1663 if (index == 0) {
1673 sg_len = sg_dma_len(sg); 1664 sg_len = sg_dma_len(sg);
1674 addr = (u64) sg_dma_address(sg); 1665 addr = (u64) sg_dma_address(sg);
@@ -1679,11 +1670,7 @@ hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
1679 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb, 1670 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_len, pwrb,
1680 sg_len); 1671 sg_len);
1681 sge_len = sg_len; 1672 sge_len = sg_len;
1682 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
1683 1);
1684 } else { 1673 } else {
1685 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
1686 0);
1687 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset, 1674 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_r2t_offset,
1688 pwrb, sge_len); 1675 pwrb, sge_len);
1689 sg_len = sg_dma_len(sg); 1676 sg_len = sg_dma_len(sg);
@@ -1706,13 +1693,27 @@ hwi_write_sgl(struct iscsi_wrb *pwrb, struct scatterlist *sg,
1706 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 1693 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
1707 io_task->bhs_pa.u.a32.address_lo); 1694 io_task->bhs_pa.u.a32.address_lo);
1708 1695
1709 if (num_sg == 2) 1696 if (num_sg == 1) {
1710 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb, 1); 1697 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
1698 1);
1699 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
1700 0);
1701 } else if (num_sg == 2) {
1702 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
1703 0);
1704 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
1705 1);
1706 } else {
1707 AMAP_SET_BITS(struct amap_iscsi_wrb, sge0_last, pwrb,
1708 0);
1709 AMAP_SET_BITS(struct amap_iscsi_wrb, sge1_last, pwrb,
1710 0);
1711 }
1711 sg = l_sg; 1712 sg = l_sg;
1712 psgl++; 1713 psgl++;
1713 psgl++; 1714 psgl++;
1714 offset = 0; 1715 offset = 0;
1715 for (index = 0; index < num_sg; index++, sg_next(sg), psgl++) { 1716 for (index = 0; index < num_sg; index++, sg = sg_next(sg), psgl++) {
1716 sg_len = sg_dma_len(sg); 1717 sg_len = sg_dma_len(sg);
1717 addr = (u64) sg_dma_address(sg); 1718 addr = (u64) sg_dma_address(sg);
1718 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl, 1719 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, psgl,
@@ -2048,10 +2049,9 @@ static void beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
2048 } 2049 }
2049 idx = 0; 2050 idx = 0;
2050 pwrb = mem_descr_wrb->mem_array[idx].virtual_address; 2051 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2051 num_cxn_wrb = 2052 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2052 ((mem_descr_wrb->mem_array[idx].size) / (sizeof(struct iscsi_wrb)) * 2053 ((sizeof(struct iscsi_wrb) *
2053 phba->params.wrbs_per_cxn); 2054 phba->params.wrbs_per_cxn));
2054
2055 for (index = 0; index < phba->params.cxns_per_ctrl; index += 2) { 2055 for (index = 0; index < phba->params.cxns_per_ctrl; index += 2) {
2056 pwrb_context = &phwi_ctrlr->wrb_context[index]; 2056 pwrb_context = &phwi_ctrlr->wrb_context[index];
2057 if (num_cxn_wrb) { 2057 if (num_cxn_wrb) {
@@ -2064,9 +2064,9 @@ static void beiscsi_init_wrb_handle(struct beiscsi_hba *phba)
2064 } else { 2064 } else {
2065 idx++; 2065 idx++;
2066 pwrb = mem_descr_wrb->mem_array[idx].virtual_address; 2066 pwrb = mem_descr_wrb->mem_array[idx].virtual_address;
2067 num_cxn_wrb = ((mem_descr_wrb->mem_array[idx].size) / 2067 num_cxn_wrb = (mem_descr_wrb->mem_array[idx].size) /
2068 (sizeof(struct iscsi_wrb)) * 2068 ((sizeof(struct iscsi_wrb) *
2069 phba->params.wrbs_per_cxn); 2069 phba->params.wrbs_per_cxn));
2070 for (j = 0; j < phba->params.wrbs_per_cxn; j++) { 2070 for (j = 0; j < phba->params.wrbs_per_cxn; j++) {
2071 pwrb_handle = pwrb_context->pwrb_handle_base[j]; 2071 pwrb_handle = pwrb_context->pwrb_handle_base[j];
2072 pwrb_handle->pwrb = pwrb; 2072 pwrb_handle->pwrb = pwrb;
@@ -2383,7 +2383,7 @@ static int beiscsi_create_cqs(struct beiscsi_hba *phba,
2383 &paddr); 2383 &paddr);
2384 if (!cq_vaddress) 2384 if (!cq_vaddress)
2385 goto create_cq_error; 2385 goto create_cq_error;
2386 ret = be_fill_queue(cq, phba->params.icds_per_ctrl / 2, 2386 ret = be_fill_queue(cq, phba->params.num_cq_entries,
2387 sizeof(struct sol_cqe), cq_vaddress); 2387 sizeof(struct sol_cqe), cq_vaddress);
2388 if (ret) { 2388 if (ret) {
2389 shost_printk(KERN_ERR, phba->shost, 2389 shost_printk(KERN_ERR, phba->shost,
@@ -2634,7 +2634,8 @@ beiscsi_create_wrb_rings(struct beiscsi_hba *phba,
2634 "wrbq create failed."); 2634 "wrbq create failed.");
2635 return status; 2635 return status;
2636 } 2636 }
2637 phwi_ctrlr->wrb_context[i].cid = phwi_context->be_wrbq[i].id; 2637 phwi_ctrlr->wrb_context[i * 2].cid = phwi_context->be_wrbq[i].
2638 id;
2638 } 2639 }
2639 kfree(pwrb_arr); 2640 kfree(pwrb_arr);
2640 return 0; 2641 return 0;
@@ -2803,17 +2804,6 @@ static int hwi_init_port(struct beiscsi_hba *phba)
2803 goto error; 2804 goto error;
2804 } 2805 }
2805 2806
2806 if (phba->fw_config.iscsi_features == 0x1)
2807 ring_mode = 1;
2808 else
2809 ring_mode = 0;
2810 status = mgmt_get_fw_config(ctrl, phba);
2811 if (status != 0) {
2812 shost_printk(KERN_ERR, phba->shost,
2813 "Error getting fw config\n");
2814 goto error;
2815 }
2816
2817 status = beiscsi_create_cqs(phba, phwi_context); 2807 status = beiscsi_create_cqs(phba, phwi_context);
2818 if (status != 0) { 2808 if (status != 0) {
2819 shost_printk(KERN_ERR, phba->shost, "CQ not created\n"); 2809 shost_printk(KERN_ERR, phba->shost, "CQ not created\n");
@@ -2941,17 +2931,6 @@ static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
2941 phba->io_sgl_hndl_avbl = 0; 2931 phba->io_sgl_hndl_avbl = 0;
2942 phba->eh_sgl_hndl_avbl = 0; 2932 phba->eh_sgl_hndl_avbl = 0;
2943 2933
2944 if (ring_mode) {
2945 phba->sgl_hndl_array = kzalloc(sizeof(struct sgl_handle *) *
2946 phba->params.icds_per_ctrl,
2947 GFP_KERNEL);
2948 if (!phba->sgl_hndl_array) {
2949 shost_printk(KERN_ERR, phba->shost,
2950 "Mem Alloc Failed. Failing to load\n");
2951 return -ENOMEM;
2952 }
2953 }
2954
2955 mem_descr_sglh = phba->init_mem; 2934 mem_descr_sglh = phba->init_mem;
2956 mem_descr_sglh += HWI_MEM_SGLH; 2935 mem_descr_sglh += HWI_MEM_SGLH;
2957 if (1 == mem_descr_sglh->num_elements) { 2936 if (1 == mem_descr_sglh->num_elements) {
@@ -2959,8 +2938,6 @@ static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
2959 phba->params.ios_per_ctrl, 2938 phba->params.ios_per_ctrl,
2960 GFP_KERNEL); 2939 GFP_KERNEL);
2961 if (!phba->io_sgl_hndl_base) { 2940 if (!phba->io_sgl_hndl_base) {
2962 if (ring_mode)
2963 kfree(phba->sgl_hndl_array);
2964 shost_printk(KERN_ERR, phba->shost, 2941 shost_printk(KERN_ERR, phba->shost,
2965 "Mem Alloc Failed. Failing to load\n"); 2942 "Mem Alloc Failed. Failing to load\n");
2966 return -ENOMEM; 2943 return -ENOMEM;
@@ -3032,7 +3009,7 @@ static int beiscsi_init_sgl_handle(struct beiscsi_hba *phba)
3032 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0); 3009 AMAP_SET_BITS(struct amap_iscsi_sge, addr_lo, pfrag, 0);
3033 pfrag += phba->params.num_sge_per_io; 3010 pfrag += phba->params.num_sge_per_io;
3034 psgl_handle->sgl_index = 3011 psgl_handle->sgl_index =
3035 phba->fw_config.iscsi_cid_start + arr_index++; 3012 phba->fw_config.iscsi_icd_start + arr_index++;
3036 } 3013 }
3037 idx++; 3014 idx++;
3038 } 3015 }
@@ -3047,7 +3024,7 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
3047{ 3024{
3048 int i, new_cid; 3025 int i, new_cid;
3049 3026
3050 phba->cid_array = kmalloc(sizeof(void *) * phba->params.cxns_per_ctrl, 3027 phba->cid_array = kzalloc(sizeof(void *) * phba->params.cxns_per_ctrl,
3051 GFP_KERNEL); 3028 GFP_KERNEL);
3052 if (!phba->cid_array) { 3029 if (!phba->cid_array) {
3053 shost_printk(KERN_ERR, phba->shost, 3030 shost_printk(KERN_ERR, phba->shost,
@@ -3055,7 +3032,7 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
3055 "hba_setup_cid_tbls\n"); 3032 "hba_setup_cid_tbls\n");
3056 return -ENOMEM; 3033 return -ENOMEM;
3057 } 3034 }
3058 phba->ep_array = kmalloc(sizeof(struct iscsi_endpoint *) * 3035 phba->ep_array = kzalloc(sizeof(struct iscsi_endpoint *) *
3059 phba->params.cxns_per_ctrl * 2, GFP_KERNEL); 3036 phba->params.cxns_per_ctrl * 2, GFP_KERNEL);
3060 if (!phba->ep_array) { 3037 if (!phba->ep_array) {
3061 shost_printk(KERN_ERR, phba->shost, 3038 shost_printk(KERN_ERR, phba->shost,
@@ -3064,7 +3041,7 @@ static int hba_setup_cid_tbls(struct beiscsi_hba *phba)
3064 kfree(phba->cid_array); 3041 kfree(phba->cid_array);
3065 return -ENOMEM; 3042 return -ENOMEM;
3066 } 3043 }
3067 new_cid = phba->fw_config.iscsi_icd_start; 3044 new_cid = phba->fw_config.iscsi_cid_start;
3068 for (i = 0; i < phba->params.cxns_per_ctrl; i++) { 3045 for (i = 0; i < phba->params.cxns_per_ctrl; i++) {
3069 phba->cid_array[i] = new_cid; 3046 phba->cid_array[i] = new_cid;
3070 new_cid += 2; 3047 new_cid += 2;
@@ -3145,8 +3122,6 @@ static int beiscsi_init_port(struct beiscsi_hba *phba)
3145 if (hba_setup_cid_tbls(phba)) { 3122 if (hba_setup_cid_tbls(phba)) {
3146 shost_printk(KERN_ERR, phba->shost, 3123 shost_printk(KERN_ERR, phba->shost,
3147 "Failed in hba_setup_cid_tbls\n"); 3124 "Failed in hba_setup_cid_tbls\n");
3148 if (ring_mode)
3149 kfree(phba->sgl_hndl_array);
3150 kfree(phba->io_sgl_hndl_base); 3125 kfree(phba->io_sgl_hndl_base);
3151 kfree(phba->eh_sgl_hndl_base); 3126 kfree(phba->eh_sgl_hndl_base);
3152 goto do_cleanup_ctrlr; 3127 goto do_cleanup_ctrlr;
@@ -3166,6 +3141,7 @@ static void hwi_purge_eq(struct beiscsi_hba *phba)
3166 struct be_queue_info *eq; 3141 struct be_queue_info *eq;
3167 struct be_eq_entry *eqe = NULL; 3142 struct be_eq_entry *eqe = NULL;
3168 int i, eq_msix; 3143 int i, eq_msix;
3144 unsigned int num_processed;
3169 3145
3170 phwi_ctrlr = phba->phwi_ctrlr; 3146 phwi_ctrlr = phba->phwi_ctrlr;
3171 phwi_context = phwi_ctrlr->phwi_ctxt; 3147 phwi_context = phwi_ctrlr->phwi_ctxt;
@@ -3177,13 +3153,17 @@ static void hwi_purge_eq(struct beiscsi_hba *phba)
3177 for (i = 0; i < (phba->num_cpus + eq_msix); i++) { 3153 for (i = 0; i < (phba->num_cpus + eq_msix); i++) {
3178 eq = &phwi_context->be_eq[i].q; 3154 eq = &phwi_context->be_eq[i].q;
3179 eqe = queue_tail_node(eq); 3155 eqe = queue_tail_node(eq);
3180 3156 num_processed = 0;
3181 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32] 3157 while (eqe->dw[offsetof(struct amap_eq_entry, valid) / 32]
3182 & EQE_VALID_MASK) { 3158 & EQE_VALID_MASK) {
3183 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0); 3159 AMAP_SET_BITS(struct amap_eq_entry, valid, eqe, 0);
3184 queue_tail_inc(eq); 3160 queue_tail_inc(eq);
3185 eqe = queue_tail_node(eq); 3161 eqe = queue_tail_node(eq);
3162 num_processed++;
3186 } 3163 }
3164
3165 if (num_processed)
3166 hwi_ring_eq_db(phba, eq->id, 1, num_processed, 1, 1);
3187 } 3167 }
3188} 3168}
3189 3169
@@ -3195,10 +3175,9 @@ static void beiscsi_clean_port(struct beiscsi_hba *phba)
3195 if (mgmt_status) 3175 if (mgmt_status)
3196 shost_printk(KERN_WARNING, phba->shost, 3176 shost_printk(KERN_WARNING, phba->shost,
3197 "mgmt_epfw_cleanup FAILED \n"); 3177 "mgmt_epfw_cleanup FAILED \n");
3198 hwi_cleanup(phba); 3178
3199 hwi_purge_eq(phba); 3179 hwi_purge_eq(phba);
3200 if (ring_mode) 3180 hwi_cleanup(phba);
3201 kfree(phba->sgl_hndl_array);
3202 kfree(phba->io_sgl_hndl_base); 3181 kfree(phba->io_sgl_hndl_base);
3203 kfree(phba->eh_sgl_hndl_base); 3182 kfree(phba->eh_sgl_hndl_base);
3204 kfree(phba->cid_array); 3183 kfree(phba->cid_array);
@@ -3219,7 +3198,8 @@ beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
3219 * We can always use 0 here because it is reserved by libiscsi for 3198 * We can always use 0 here because it is reserved by libiscsi for
3220 * login/startup related tasks. 3199 * login/startup related tasks.
3221 */ 3200 */
3222 pwrb_handle = alloc_wrb_handle(phba, beiscsi_conn->beiscsi_conn_cid, 0); 3201 pwrb_handle = alloc_wrb_handle(phba, (beiscsi_conn->beiscsi_conn_cid -
3202 phba->fw_config.iscsi_cid_start));
3223 pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb; 3203 pwrb = (struct iscsi_target_context_update_wrb *)pwrb_handle->pwrb;
3224 memset(pwrb, 0, sizeof(*pwrb)); 3204 memset(pwrb, 0, sizeof(*pwrb));
3225 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, 3205 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
@@ -3283,8 +3263,7 @@ beiscsi_offload_connection(struct beiscsi_conn *beiscsi_conn,
3283 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb)); 3263 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_target_context_update_wrb));
3284 3264
3285 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; 3265 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
3286 if (!ring_mode) 3266 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
3287 doorbell |= (pwrb_handle->wrb_index & DB_DEF_PDU_WRB_INDEX_MASK)
3288 << DB_DEF_PDU_WRB_INDEX_SHIFT; 3267 << DB_DEF_PDU_WRB_INDEX_SHIFT;
3289 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; 3268 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
3290 3269
@@ -3328,8 +3307,9 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3328 io_task->bhs_pa.u.a64.address = paddr; 3307 io_task->bhs_pa.u.a64.address = paddr;
3329 io_task->libiscsi_itt = (itt_t)task->itt; 3308 io_task->libiscsi_itt = (itt_t)task->itt;
3330 io_task->pwrb_handle = alloc_wrb_handle(phba, 3309 io_task->pwrb_handle = alloc_wrb_handle(phba,
3331 beiscsi_conn->beiscsi_conn_cid, 3310 beiscsi_conn->beiscsi_conn_cid -
3332 task->itt); 3311 phba->fw_config.iscsi_cid_start
3312 );
3333 io_task->conn = beiscsi_conn; 3313 io_task->conn = beiscsi_conn;
3334 3314
3335 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr; 3315 task->hdr = (struct iscsi_hdr *)&io_task->cmd_bhs->iscsi_hdr;
@@ -3343,7 +3323,7 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3343 goto free_hndls; 3323 goto free_hndls;
3344 } else { 3324 } else {
3345 io_task->scsi_cmnd = NULL; 3325 io_task->scsi_cmnd = NULL;
3346 if ((task->hdr->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) { 3326 if ((opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_LOGIN) {
3347 if (!beiscsi_conn->login_in_progress) { 3327 if (!beiscsi_conn->login_in_progress) {
3348 spin_lock(&phba->mgmt_sgl_lock); 3328 spin_lock(&phba->mgmt_sgl_lock);
3349 io_task->psgl_handle = (struct sgl_handle *) 3329 io_task->psgl_handle = (struct sgl_handle *)
@@ -3370,21 +3350,16 @@ static int beiscsi_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
3370 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle-> 3350 itt = (itt_t) cpu_to_be32(((unsigned int)io_task->pwrb_handle->
3371 wrb_index << 16) | (unsigned int) 3351 wrb_index << 16) | (unsigned int)
3372 (io_task->psgl_handle->sgl_index)); 3352 (io_task->psgl_handle->sgl_index));
3373 if (ring_mode) { 3353 io_task->pwrb_handle->pio_handle = task;
3374 phba->sgl_hndl_array[io_task->psgl_handle->sgl_index -
3375 phba->fw_config.iscsi_cid_start] =
3376 io_task->psgl_handle;
3377 io_task->psgl_handle->task = task;
3378 io_task->psgl_handle->cid = beiscsi_conn->beiscsi_conn_cid;
3379 } else
3380 io_task->pwrb_handle->pio_handle = task;
3381 3354
3382 io_task->cmd_bhs->iscsi_hdr.itt = itt; 3355 io_task->cmd_bhs->iscsi_hdr.itt = itt;
3383 return 0; 3356 return 0;
3384 3357
3385free_hndls: 3358free_hndls:
3386 phwi_ctrlr = phba->phwi_ctrlr; 3359 phwi_ctrlr = phba->phwi_ctrlr;
3387 pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid]; 3360 pwrb_context = &phwi_ctrlr->wrb_context[
3361 beiscsi_conn->beiscsi_conn_cid -
3362 phba->fw_config.iscsi_cid_start];
3388 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); 3363 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
3389 io_task->pwrb_handle = NULL; 3364 io_task->pwrb_handle = NULL;
3390 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs, 3365 pci_pool_free(beiscsi_sess->bhs_pool, io_task->cmd_bhs,
@@ -3404,7 +3379,8 @@ static void beiscsi_cleanup_task(struct iscsi_task *task)
3404 struct hwi_controller *phwi_ctrlr; 3379 struct hwi_controller *phwi_ctrlr;
3405 3380
3406 phwi_ctrlr = phba->phwi_ctrlr; 3381 phwi_ctrlr = phba->phwi_ctrlr;
3407 pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid]; 3382 pwrb_context = &phwi_ctrlr->wrb_context[beiscsi_conn->beiscsi_conn_cid
3383 - phba->fw_config.iscsi_cid_start];
3408 if (io_task->pwrb_handle) { 3384 if (io_task->pwrb_handle) {
3409 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle); 3385 free_wrb_handle(phba, pwrb_context, io_task->pwrb_handle);
3410 io_task->pwrb_handle = NULL; 3386 io_task->pwrb_handle = NULL;
@@ -3460,18 +3436,12 @@ static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
3460 ISCSI_OPCODE_SCSI_DATA_OUT); 3436 ISCSI_OPCODE_SCSI_DATA_OUT);
3461 AMAP_SET_BITS(struct amap_pdu_data_out, final_bit, 3437 AMAP_SET_BITS(struct amap_pdu_data_out, final_bit,
3462 &io_task->cmd_bhs->iscsi_data_pdu, 1); 3438 &io_task->cmd_bhs->iscsi_data_pdu, 1);
3463 if (ring_mode) 3439 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3464 io_task->psgl_handle->type = INI_WR_CMD; 3440 INI_WR_CMD);
3465 else
3466 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3467 INI_WR_CMD);
3468 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1); 3441 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
3469 } else { 3442 } else {
3470 if (ring_mode) 3443 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3471 io_task->psgl_handle->type = INI_RD_CMD; 3444 INI_RD_CMD);
3472 else
3473 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3474 INI_RD_CMD);
3475 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0); 3445 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 0);
3476 } 3446 }
3477 memcpy(&io_task->cmd_bhs->iscsi_data_pdu. 3447 memcpy(&io_task->cmd_bhs->iscsi_data_pdu.
@@ -3496,8 +3466,7 @@ static int beiscsi_iotask(struct iscsi_task *task, struct scatterlist *sg,
3496 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); 3466 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
3497 3467
3498 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK; 3468 doorbell |= beiscsi_conn->beiscsi_conn_cid & DB_WRB_POST_CID_MASK;
3499 if (!ring_mode) 3469 doorbell |= (io_task->pwrb_handle->wrb_index &
3500 doorbell |= (io_task->pwrb_handle->wrb_index &
3501 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; 3470 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
3502 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; 3471 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
3503 3472
@@ -3519,49 +3488,46 @@ static int beiscsi_mtask(struct iscsi_task *task)
3519 unsigned int doorbell = 0; 3488 unsigned int doorbell = 0;
3520 unsigned int i, cid; 3489 unsigned int i, cid;
3521 struct iscsi_task *aborted_task; 3490 struct iscsi_task *aborted_task;
3491 unsigned int tag;
3522 3492
3523 cid = beiscsi_conn->beiscsi_conn_cid; 3493 cid = beiscsi_conn->beiscsi_conn_cid;
3524 pwrb = io_task->pwrb_handle->pwrb; 3494 pwrb = io_task->pwrb_handle->pwrb;
3495 memset(pwrb, 0, sizeof(*pwrb));
3525 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 3496 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb,
3526 be32_to_cpu(task->cmdsn)); 3497 be32_to_cpu(task->cmdsn));
3527 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb, 3498 AMAP_SET_BITS(struct amap_iscsi_wrb, wrb_idx, pwrb,
3528 io_task->pwrb_handle->wrb_index); 3499 io_task->pwrb_handle->wrb_index);
3529 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb, 3500 AMAP_SET_BITS(struct amap_iscsi_wrb, sgl_icd_idx, pwrb,
3530 io_task->psgl_handle->sgl_index); 3501 io_task->psgl_handle->sgl_index);
3531
3532 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) { 3502 switch (task->hdr->opcode & ISCSI_OPCODE_MASK) {
3533 case ISCSI_OP_LOGIN: 3503 case ISCSI_OP_LOGIN:
3534 if (ring_mode) 3504 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3535 io_task->psgl_handle->type = TGT_DM_CMD; 3505 TGT_DM_CMD);
3536 else
3537 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3538 TGT_DM_CMD);
3539 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0); 3506 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
3540 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1); 3507 AMAP_SET_BITS(struct amap_iscsi_wrb, cmdsn_itt, pwrb, 1);
3541 hwi_write_buffer(pwrb, task); 3508 hwi_write_buffer(pwrb, task);
3542 break; 3509 break;
3543 case ISCSI_OP_NOOP_OUT: 3510 case ISCSI_OP_NOOP_OUT:
3544 if (ring_mode) 3511 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3545 io_task->psgl_handle->type = INI_RD_CMD; 3512 INI_RD_CMD);
3513 if (task->hdr->ttt == ISCSI_RESERVED_TAG)
3514 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
3546 else 3515 else
3547 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, 3516 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 1);
3548 INI_RD_CMD);
3549 hwi_write_buffer(pwrb, task); 3517 hwi_write_buffer(pwrb, task);
3550 break; 3518 break;
3551 case ISCSI_OP_TEXT: 3519 case ISCSI_OP_TEXT:
3552 if (ring_mode) 3520 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3553 io_task->psgl_handle->type = INI_WR_CMD; 3521 TGT_DM_CMD);
3554 else 3522 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
3555 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3556 INI_WR_CMD);
3557 AMAP_SET_BITS(struct amap_iscsi_wrb, dsp, pwrb, 1);
3558 hwi_write_buffer(pwrb, task); 3523 hwi_write_buffer(pwrb, task);
3559 break; 3524 break;
3560 case ISCSI_OP_SCSI_TMFUNC: 3525 case ISCSI_OP_SCSI_TMFUNC:
3561 session = conn->session; 3526 session = conn->session;
3562 i = ((struct iscsi_tm *)task->hdr)->rtt; 3527 i = ((struct iscsi_tm *)task->hdr)->rtt;
3563 phwi_ctrlr = phba->phwi_ctrlr; 3528 phwi_ctrlr = phba->phwi_ctrlr;
3564 pwrb_context = &phwi_ctrlr->wrb_context[cid]; 3529 pwrb_context = &phwi_ctrlr->wrb_context[cid -
3530 phba->fw_config.iscsi_cid_start];
3565 pwrb_handle = pwrb_context->pwrb_handle_basestd[be32_to_cpu(i) 3531 pwrb_handle = pwrb_context->pwrb_handle_basestd[be32_to_cpu(i)
3566 >> 16]; 3532 >> 16];
3567 aborted_task = pwrb_handle->pio_handle; 3533 aborted_task = pwrb_handle->pio_handle;
@@ -3572,22 +3538,25 @@ static int beiscsi_mtask(struct iscsi_task *task)
3572 if (!aborted_io_task->scsi_cmnd) 3538 if (!aborted_io_task->scsi_cmnd)
3573 return 0; 3539 return 0;
3574 3540
3575 mgmt_invalidate_icds(phba, 3541 tag = mgmt_invalidate_icds(phba,
3576 aborted_io_task->psgl_handle->sgl_index, 3542 aborted_io_task->psgl_handle->sgl_index,
3577 cid); 3543 cid);
3578 if (ring_mode) 3544 if (!tag) {
3579 io_task->psgl_handle->type = INI_TMF_CMD; 3545 shost_printk(KERN_WARNING, phba->shost,
3580 else 3546 "mgmt_invalidate_icds could not be"
3581 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, 3547 " submitted\n");
3582 INI_TMF_CMD); 3548 } else {
3549 wait_event_interruptible(phba->ctrl.mcc_wait[tag],
3550 phba->ctrl.mcc_numtag[tag]);
3551 free_mcc_tag(&phba->ctrl, tag);
3552 }
3553 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3554 INI_TMF_CMD);
3583 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0); 3555 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
3584 hwi_write_buffer(pwrb, task); 3556 hwi_write_buffer(pwrb, task);
3585 break; 3557 break;
3586 case ISCSI_OP_LOGOUT: 3558 case ISCSI_OP_LOGOUT:
3587 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0); 3559 AMAP_SET_BITS(struct amap_iscsi_wrb, dmsg, pwrb, 0);
3588 if (ring_mode)
3589 io_task->psgl_handle->type = HWH_TYPE_LOGOUT;
3590 else
3591 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb, 3560 AMAP_SET_BITS(struct amap_iscsi_wrb, type, pwrb,
3592 HWH_TYPE_LOGOUT); 3561 HWH_TYPE_LOGOUT);
3593 hwi_write_buffer(pwrb, task); 3562 hwi_write_buffer(pwrb, task);
@@ -3600,14 +3569,13 @@ static int beiscsi_mtask(struct iscsi_task *task)
3600 } 3569 }
3601 3570
3602 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb, 3571 AMAP_SET_BITS(struct amap_iscsi_wrb, r2t_exp_dtl, pwrb,
3603 be32_to_cpu(task->data_count)); 3572 task->data_count);
3604 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb, 3573 AMAP_SET_BITS(struct amap_iscsi_wrb, ptr2nextwrb, pwrb,
3605 io_task->pwrb_handle->nxt_wrb_index); 3574 io_task->pwrb_handle->nxt_wrb_index);
3606 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb)); 3575 be_dws_le_to_cpu(pwrb, sizeof(struct iscsi_wrb));
3607 3576
3608 doorbell |= cid & DB_WRB_POST_CID_MASK; 3577 doorbell |= cid & DB_WRB_POST_CID_MASK;
3609 if (!ring_mode) 3578 doorbell |= (io_task->pwrb_handle->wrb_index &
3610 doorbell |= (io_task->pwrb_handle->wrb_index &
3611 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT; 3579 DB_DEF_PDU_WRB_INDEX_MASK) << DB_DEF_PDU_WRB_INDEX_SHIFT;
3612 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT; 3580 doorbell |= 1 << DB_DEF_PDU_NUM_POSTED_SHIFT;
3613 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET); 3581 iowrite32(doorbell, phba->db_va + DB_TXULP0_OFFSET);
@@ -3649,7 +3617,6 @@ static int beiscsi_task_xmit(struct iscsi_task *task)
3649 return beiscsi_iotask(task, sg, num_sg, xferlen, writedir); 3617 return beiscsi_iotask(task, sg, num_sg, xferlen, writedir);
3650} 3618}
3651 3619
3652
3653static void beiscsi_remove(struct pci_dev *pcidev) 3620static void beiscsi_remove(struct pci_dev *pcidev)
3654{ 3621{
3655 struct beiscsi_hba *phba = NULL; 3622 struct beiscsi_hba *phba = NULL;
@@ -3734,7 +3701,20 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
3734 } 3701 }
3735 SE_DEBUG(DBG_LVL_8, " phba = %p \n", phba); 3702 SE_DEBUG(DBG_LVL_8, " phba = %p \n", phba);
3736 3703
3737 pci_set_drvdata(pcidev, phba); 3704 switch (pcidev->device) {
3705 case BE_DEVICE_ID1:
3706 case OC_DEVICE_ID1:
3707 case OC_DEVICE_ID2:
3708 phba->generation = BE_GEN2;
3709 break;
3710 case BE_DEVICE_ID2:
3711 case OC_DEVICE_ID3:
3712 phba->generation = BE_GEN3;
3713 break;
3714 default:
3715 phba->generation = 0;
3716 }
3717
3738 if (enable_msix) 3718 if (enable_msix)
3739 num_cpus = find_num_cpus(); 3719 num_cpus = find_num_cpus();
3740 else 3720 else
@@ -3754,7 +3734,15 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
3754 spin_lock_init(&phba->io_sgl_lock); 3734 spin_lock_init(&phba->io_sgl_lock);
3755 spin_lock_init(&phba->mgmt_sgl_lock); 3735 spin_lock_init(&phba->mgmt_sgl_lock);
3756 spin_lock_init(&phba->isr_lock); 3736 spin_lock_init(&phba->isr_lock);
3737 ret = mgmt_get_fw_config(&phba->ctrl, phba);
3738 if (ret != 0) {
3739 shost_printk(KERN_ERR, phba->shost,
3740 "Error getting fw config\n");
3741 goto free_port;
3742 }
3743 phba->shost->max_id = phba->fw_config.iscsi_cid_count;
3757 beiscsi_get_params(phba); 3744 beiscsi_get_params(phba);
3745 phba->shost->can_queue = phba->params.ios_per_ctrl;
3758 ret = beiscsi_init_port(phba); 3746 ret = beiscsi_init_port(phba);
3759 if (ret < 0) { 3747 if (ret < 0) {
3760 shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-" 3748 shost_printk(KERN_ERR, phba->shost, "beiscsi_dev_probe-"
@@ -3762,6 +3750,15 @@ static int __devinit beiscsi_dev_probe(struct pci_dev *pcidev,
3762 goto free_port; 3750 goto free_port;
3763 } 3751 }
3764 3752
3753 for (i = 0; i < MAX_MCC_CMD ; i++) {
3754 init_waitqueue_head(&phba->ctrl.mcc_wait[i + 1]);
3755 phba->ctrl.mcc_tag[i] = i + 1;
3756 phba->ctrl.mcc_numtag[i + 1] = 0;
3757 phba->ctrl.mcc_tag_available++;
3758 }
3759
3760 phba->ctrl.mcc_alloc_index = phba->ctrl.mcc_free_index = 0;
3761
3765 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_q_irq%u", 3762 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_q_irq%u",
3766 phba->shost->host_no); 3763 phba->shost->host_no);
3767 phba->wq = create_workqueue(phba->wq_name); 3764 phba->wq = create_workqueue(phba->wq_name);
@@ -3836,7 +3833,7 @@ disable_pci:
3836struct iscsi_transport beiscsi_iscsi_transport = { 3833struct iscsi_transport beiscsi_iscsi_transport = {
3837 .owner = THIS_MODULE, 3834 .owner = THIS_MODULE,
3838 .name = DRV_NAME, 3835 .name = DRV_NAME,
3839 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | 3836 .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_TEXT_NEGO |
3840 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD, 3837 CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD,
3841 .param_mask = ISCSI_MAX_RECV_DLENGTH | 3838 .param_mask = ISCSI_MAX_RECV_DLENGTH |
3842 ISCSI_MAX_XMIT_DLENGTH | 3839 ISCSI_MAX_XMIT_DLENGTH |
@@ -3859,7 +3856,7 @@ struct iscsi_transport beiscsi_iscsi_transport = {
3859 ISCSI_USERNAME | ISCSI_PASSWORD | 3856 ISCSI_USERNAME | ISCSI_PASSWORD |
3860 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN | 3857 ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
3861 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO | 3858 ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
3862 ISCSI_LU_RESET_TMO | ISCSI_TGT_RESET_TMO | 3859 ISCSI_LU_RESET_TMO |
3863 ISCSI_PING_TMO | ISCSI_RECV_TMO | 3860 ISCSI_PING_TMO | ISCSI_RECV_TMO |
3864 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME, 3861 ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
3865 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS | 3862 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
@@ -3905,7 +3902,7 @@ static int __init beiscsi_module_init(void)
3905 SE_DEBUG(DBG_LVL_1, 3902 SE_DEBUG(DBG_LVL_1,
3906 "beiscsi_module_init - Unable to register beiscsi" 3903 "beiscsi_module_init - Unable to register beiscsi"
3907 "transport.\n"); 3904 "transport.\n");
3908 ret = -ENOMEM; 3905 return -ENOMEM;
3909 } 3906 }
3910 SE_DEBUG(DBG_LVL_8, "In beiscsi_module_init, tt=%p \n", 3907 SE_DEBUG(DBG_LVL_8, "In beiscsi_module_init, tt=%p \n",
3911 &beiscsi_iscsi_transport); 3908 &beiscsi_iscsi_transport);
@@ -3917,7 +3914,6 @@ static int __init beiscsi_module_init(void)
3917 "beiscsi pci driver.\n"); 3914 "beiscsi pci driver.\n");
3918 goto unregister_iscsi_transport; 3915 goto unregister_iscsi_transport;
3919 } 3916 }
3920 ring_mode = 0;
3921 return 0; 3917 return 0;
3922 3918
3923unregister_iscsi_transport: 3919unregister_iscsi_transport:
diff --git a/drivers/scsi/be2iscsi/be_main.h b/drivers/scsi/be2iscsi/be_main.h
index 25e6b208b771..c53a80ab796c 100644
--- a/drivers/scsi/be2iscsi/be_main.h
+++ b/drivers/scsi/be2iscsi/be_main.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -40,31 +40,29 @@
40#define DRV_DESC BE_NAME " " "Driver" 40#define DRV_DESC BE_NAME " " "Driver"
41 41
42#define BE_VENDOR_ID 0x19A2 42#define BE_VENDOR_ID 0x19A2
43/* DEVICE ID's for BE2 */
43#define BE_DEVICE_ID1 0x212 44#define BE_DEVICE_ID1 0x212
44#define OC_DEVICE_ID1 0x702 45#define OC_DEVICE_ID1 0x702
45#define OC_DEVICE_ID2 0x703 46#define OC_DEVICE_ID2 0x703
47
48/* DEVICE ID's for BE3 */
49#define BE_DEVICE_ID2 0x222
46#define OC_DEVICE_ID3 0x712 50#define OC_DEVICE_ID3 0x712
47#define OC_DEVICE_ID4 0x222
48 51
49#define BE2_MAX_SESSIONS 64 52#define BE2_IO_DEPTH 1024
53#define BE2_MAX_SESSIONS 256
50#define BE2_CMDS_PER_CXN 128 54#define BE2_CMDS_PER_CXN 128
51#define BE2_LOGOUTS BE2_MAX_SESSIONS
52#define BE2_TMFS 16 55#define BE2_TMFS 16
53#define BE2_NOPOUT_REQ 16 56#define BE2_NOPOUT_REQ 16
54#define BE2_ASYNCPDUS BE2_MAX_SESSIONS
55#define BE2_MAX_ICDS 2048
56#define BE2_SGE 32 57#define BE2_SGE 32
57#define BE2_DEFPDU_HDR_SZ 64 58#define BE2_DEFPDU_HDR_SZ 64
58#define BE2_DEFPDU_DATA_SZ 8192 59#define BE2_DEFPDU_DATA_SZ 8192
59#define BE2_IO_DEPTH \
60 (BE2_MAX_ICDS / 2 - (BE2_LOGOUTS + BE2_TMFS + BE2_NOPOUT_REQ))
61 60
62#define MAX_CPUS 31 61#define MAX_CPUS 31
63#define BEISCSI_SGLIST_ELEMENTS BE2_SGE 62#define BEISCSI_SGLIST_ELEMENTS 30
64 63
65#define BEISCSI_MAX_CMNDS 1024 /* Max IO's per Ctrlr sht->can_queue */
66#define BEISCSI_CMD_PER_LUN 128 /* scsi_host->cmd_per_lun */ 64#define BEISCSI_CMD_PER_LUN 128 /* scsi_host->cmd_per_lun */
67#define BEISCSI_MAX_SECTORS 2048 /* scsi_host->max_sectors */ 65#define BEISCSI_MAX_SECTORS 256 /* scsi_host->max_sectors */
68 66
69#define BEISCSI_MAX_CMD_LEN 16 /* scsi_host->max_cmd_len */ 67#define BEISCSI_MAX_CMD_LEN 16 /* scsi_host->max_cmd_len */
70#define BEISCSI_NUM_MAX_LUN 256 /* scsi_host->max_lun */ 68#define BEISCSI_NUM_MAX_LUN 256 /* scsi_host->max_lun */
@@ -330,6 +328,7 @@ struct beiscsi_hba {
330 struct workqueue_struct *wq; /* The actuak work queue */ 328 struct workqueue_struct *wq; /* The actuak work queue */
331 struct work_struct work_cqs; /* The work being queued */ 329 struct work_struct work_cqs; /* The work being queued */
332 struct be_ctrl_info ctrl; 330 struct be_ctrl_info ctrl;
331 unsigned int generation;
333}; 332};
334 333
335struct beiscsi_session { 334struct beiscsi_session {
@@ -656,11 +655,12 @@ struct amap_iscsi_wrb {
656 655
657} __packed; 656} __packed;
658 657
659struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid, 658struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid);
660 int index);
661void 659void
662free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle); 660free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle);
663 661
662void beiscsi_process_all_cqs(struct work_struct *work);
663
664struct pdu_nop_out { 664struct pdu_nop_out {
665 u32 dw[12]; 665 u32 dw[12];
666}; 666};
@@ -802,7 +802,6 @@ struct hwi_controller {
802 struct be_ring default_pdu_hdr; 802 struct be_ring default_pdu_hdr;
803 struct be_ring default_pdu_data; 803 struct be_ring default_pdu_data;
804 struct hwi_context_memory *phwi_ctxt; 804 struct hwi_context_memory *phwi_ctxt;
805 unsigned short cq_errors[CXN_KILLED_CMND_DATA_NOT_ON_SAME_CONN];
806}; 805};
807 806
808enum hwh_type_enum { 807enum hwh_type_enum {
diff --git a/drivers/scsi/be2iscsi/be_mgmt.c b/drivers/scsi/be2iscsi/be_mgmt.c
index 79c2bd525a84..317bcd042ced 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.c
+++ b/drivers/scsi/be2iscsi/be_mgmt.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -48,6 +48,14 @@ unsigned char mgmt_get_fw_config(struct be_ctrl_info *ctrl,
48 pfw_cfg->ulp[0].sq_base; 48 pfw_cfg->ulp[0].sq_base;
49 phba->fw_config.iscsi_cid_count = 49 phba->fw_config.iscsi_cid_count =
50 pfw_cfg->ulp[0].sq_count; 50 pfw_cfg->ulp[0].sq_count;
51 if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) {
52 SE_DEBUG(DBG_LVL_8,
53 "FW reported MAX CXNS as %d \t"
54 "Max Supported = %d.\n",
55 phba->fw_config.iscsi_cid_count,
56 BE2_MAX_SESSIONS);
57 phba->fw_config.iscsi_cid_count = BE2_MAX_SESSIONS / 2;
58 }
51 } else { 59 } else {
52 shost_printk(KERN_WARNING, phba->shost, 60 shost_printk(KERN_WARNING, phba->shost,
53 "Failed in mgmt_get_fw_config \n"); 61 "Failed in mgmt_get_fw_config \n");
@@ -77,6 +85,7 @@ unsigned char mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
77 } 85 }
78 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes); 86 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
79 req = nonemb_cmd.va; 87 req = nonemb_cmd.va;
88 memset(req, 0, sizeof(*req));
80 spin_lock(&ctrl->mbox_lock); 89 spin_lock(&ctrl->mbox_lock);
81 memset(wrb, 0, sizeof(*wrb)); 90 memset(wrb, 0, sizeof(*wrb));
82 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1); 91 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
@@ -140,10 +149,17 @@ unsigned char mgmt_invalidate_icds(struct beiscsi_hba *phba,
140{ 149{
141 struct be_dma_mem nonemb_cmd; 150 struct be_dma_mem nonemb_cmd;
142 struct be_ctrl_info *ctrl = &phba->ctrl; 151 struct be_ctrl_info *ctrl = &phba->ctrl;
143 struct be_mcc_wrb *wrb = wrb_from_mccq(phba); 152 struct be_mcc_wrb *wrb;
144 struct be_sge *sge = nonembedded_sgl(wrb); 153 struct be_sge *sge;
145 struct invalidate_commands_params_in *req; 154 struct invalidate_commands_params_in *req;
146 int status = 0; 155 unsigned int tag = 0;
156
157 spin_lock(&ctrl->mbox_lock);
158 tag = alloc_mcc_tag(phba);
159 if (!tag) {
160 spin_unlock(&ctrl->mbox_lock);
161 return tag;
162 }
147 163
148 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev, 164 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
149 sizeof(struct invalidate_commands_params_in), 165 sizeof(struct invalidate_commands_params_in),
@@ -156,8 +172,10 @@ unsigned char mgmt_invalidate_icds(struct beiscsi_hba *phba,
156 } 172 }
157 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in); 173 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
158 req = nonemb_cmd.va; 174 req = nonemb_cmd.va;
159 spin_lock(&ctrl->mbox_lock); 175 memset(req, 0, sizeof(*req));
160 memset(wrb, 0, sizeof(*wrb)); 176 wrb = wrb_from_mccq(phba);
177 sge = nonembedded_sgl(wrb);
178 wrb->tag0 |= tag;
161 179
162 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1); 180 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
163 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 181 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
@@ -172,14 +190,12 @@ unsigned char mgmt_invalidate_icds(struct beiscsi_hba *phba,
172 sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF); 190 sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
173 sge->len = cpu_to_le32(nonemb_cmd.size); 191 sge->len = cpu_to_le32(nonemb_cmd.size);
174 192
175 status = be_mcc_notify_wait(phba); 193 be_mcc_notify(phba);
176 if (status)
177 SE_DEBUG(DBG_LVL_1, "ICDS Invalidation Failed\n");
178 spin_unlock(&ctrl->mbox_lock); 194 spin_unlock(&ctrl->mbox_lock);
179 if (nonemb_cmd.va) 195 if (nonemb_cmd.va)
180 pci_free_consistent(ctrl->pdev, nonemb_cmd.size, 196 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
181 nonemb_cmd.va, nonemb_cmd.dma); 197 nonemb_cmd.va, nonemb_cmd.dma);
182 return status; 198 return tag;
183} 199}
184 200
185unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba, 201unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba,
@@ -189,13 +205,19 @@ unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba,
189 unsigned short savecfg_flag) 205 unsigned short savecfg_flag)
190{ 206{
191 struct be_ctrl_info *ctrl = &phba->ctrl; 207 struct be_ctrl_info *ctrl = &phba->ctrl;
192 struct be_mcc_wrb *wrb = wrb_from_mccq(phba); 208 struct be_mcc_wrb *wrb;
193 struct iscsi_invalidate_connection_params_in *req = 209 struct iscsi_invalidate_connection_params_in *req;
194 embedded_payload(wrb); 210 unsigned int tag = 0;
195 int status = 0;
196 211
197 spin_lock(&ctrl->mbox_lock); 212 spin_lock(&ctrl->mbox_lock);
198 memset(wrb, 0, sizeof(*wrb)); 213 tag = alloc_mcc_tag(phba);
214 if (!tag) {
215 spin_unlock(&ctrl->mbox_lock);
216 return tag;
217 }
218 wrb = wrb_from_mccq(phba);
219 wrb->tag0 |= tag;
220 req = embedded_payload(wrb);
199 221
200 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 222 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
201 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI, 223 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
@@ -208,35 +230,37 @@ unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba,
208 else 230 else
209 req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE; 231 req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
210 req->save_cfg = savecfg_flag; 232 req->save_cfg = savecfg_flag;
211 status = be_mcc_notify_wait(phba); 233 be_mcc_notify(phba);
212 if (status)
213 SE_DEBUG(DBG_LVL_1, "Invalidation Failed\n");
214
215 spin_unlock(&ctrl->mbox_lock); 234 spin_unlock(&ctrl->mbox_lock);
216 return status; 235 return tag;
217} 236}
218 237
219unsigned char mgmt_upload_connection(struct beiscsi_hba *phba, 238unsigned char mgmt_upload_connection(struct beiscsi_hba *phba,
220 unsigned short cid, unsigned int upload_flag) 239 unsigned short cid, unsigned int upload_flag)
221{ 240{
222 struct be_ctrl_info *ctrl = &phba->ctrl; 241 struct be_ctrl_info *ctrl = &phba->ctrl;
223 struct be_mcc_wrb *wrb = wrb_from_mccq(phba); 242 struct be_mcc_wrb *wrb;
224 struct tcp_upload_params_in *req = embedded_payload(wrb); 243 struct tcp_upload_params_in *req;
225 int status = 0; 244 unsigned int tag = 0;
226 245
227 spin_lock(&ctrl->mbox_lock); 246 spin_lock(&ctrl->mbox_lock);
228 memset(wrb, 0, sizeof(*wrb)); 247 tag = alloc_mcc_tag(phba);
248 if (!tag) {
249 spin_unlock(&ctrl->mbox_lock);
250 return tag;
251 }
252 wrb = wrb_from_mccq(phba);
253 req = embedded_payload(wrb);
254 wrb->tag0 |= tag;
229 255
230 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 256 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
231 be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD, 257 be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
232 OPCODE_COMMON_TCP_UPLOAD, sizeof(*req)); 258 OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
233 req->id = (unsigned short)cid; 259 req->id = (unsigned short)cid;
234 req->upload_type = (unsigned char)upload_flag; 260 req->upload_type = (unsigned char)upload_flag;
235 status = be_mcc_notify_wait(phba); 261 be_mcc_notify(phba);
236 if (status)
237 SE_DEBUG(DBG_LVL_1, "mgmt_upload_connection Failed\n");
238 spin_unlock(&ctrl->mbox_lock); 262 spin_unlock(&ctrl->mbox_lock);
239 return status; 263 return tag;
240} 264}
241 265
242int mgmt_open_connection(struct beiscsi_hba *phba, 266int mgmt_open_connection(struct beiscsi_hba *phba,
@@ -248,13 +272,13 @@ int mgmt_open_connection(struct beiscsi_hba *phba,
248 struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr; 272 struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
249 struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr; 273 struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
250 struct be_ctrl_info *ctrl = &phba->ctrl; 274 struct be_ctrl_info *ctrl = &phba->ctrl;
251 struct be_mcc_wrb *wrb = wrb_from_mccq(phba); 275 struct be_mcc_wrb *wrb;
252 struct tcp_connect_and_offload_in *req = embedded_payload(wrb); 276 struct tcp_connect_and_offload_in *req;
253 unsigned short def_hdr_id; 277 unsigned short def_hdr_id;
254 unsigned short def_data_id; 278 unsigned short def_data_id;
255 struct phys_addr template_address = { 0, 0 }; 279 struct phys_addr template_address = { 0, 0 };
256 struct phys_addr *ptemplate_address; 280 struct phys_addr *ptemplate_address;
257 int status = 0; 281 unsigned int tag = 0;
258 unsigned int i; 282 unsigned int i;
259 unsigned short cid = beiscsi_ep->ep_cid; 283 unsigned short cid = beiscsi_ep->ep_cid;
260 284
@@ -266,7 +290,14 @@ int mgmt_open_connection(struct beiscsi_hba *phba,
266 ptemplate_address = &template_address; 290 ptemplate_address = &template_address;
267 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address); 291 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
268 spin_lock(&ctrl->mbox_lock); 292 spin_lock(&ctrl->mbox_lock);
269 memset(wrb, 0, sizeof(*wrb)); 293 tag = alloc_mcc_tag(phba);
294 if (!tag) {
295 spin_unlock(&ctrl->mbox_lock);
296 return tag;
297 }
298 wrb = wrb_from_mccq(phba);
299 req = embedded_payload(wrb);
300 wrb->tag0 |= tag;
270 301
271 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 302 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
272 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 303 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
@@ -311,46 +342,36 @@ int mgmt_open_connection(struct beiscsi_hba *phba,
311 req->do_offload = 1; 342 req->do_offload = 1;
312 req->dataout_template_pa.lo = ptemplate_address->lo; 343 req->dataout_template_pa.lo = ptemplate_address->lo;
313 req->dataout_template_pa.hi = ptemplate_address->hi; 344 req->dataout_template_pa.hi = ptemplate_address->hi;
314 status = be_mcc_notify_wait(phba); 345 be_mcc_notify(phba);
315 if (!status) {
316 struct iscsi_endpoint *ep;
317 struct tcp_connect_and_offload_out *ptcpcnct_out =
318 embedded_payload(wrb);
319
320 ep = phba->ep_array[ptcpcnct_out->cid];
321 beiscsi_ep = ep->dd_data;
322 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
323 beiscsi_ep->cid_vld = 1;
324 SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
325 } else
326 SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed\n");
327 spin_unlock(&ctrl->mbox_lock); 346 spin_unlock(&ctrl->mbox_lock);
328 return status; 347 return tag;
329} 348}
330 349
331int be_cmd_get_mac_addr(struct beiscsi_hba *phba, u8 *mac_addr) 350unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba)
332{ 351{
333 struct be_ctrl_info *ctrl = &phba->ctrl; 352 struct be_ctrl_info *ctrl = &phba->ctrl;
334 struct be_mcc_wrb *wrb = wrb_from_mccq(phba); 353 struct be_mcc_wrb *wrb;
335 struct be_cmd_req_get_mac_addr *req = embedded_payload(wrb); 354 struct be_cmd_req_get_mac_addr *req;
336 int status; 355 unsigned int tag = 0;
337 356
338 SE_DEBUG(DBG_LVL_8, "In be_cmd_get_mac_addr\n"); 357 SE_DEBUG(DBG_LVL_8, "In be_cmd_get_mac_addr\n");
339 spin_lock(&ctrl->mbox_lock); 358 spin_lock(&ctrl->mbox_lock);
340 memset(wrb, 0, sizeof(*wrb)); 359 tag = alloc_mcc_tag(phba);
360 if (!tag) {
361 spin_unlock(&ctrl->mbox_lock);
362 return tag;
363 }
364
365 wrb = wrb_from_mccq(phba);
366 req = embedded_payload(wrb);
367 wrb->tag0 |= tag;
341 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); 368 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
342 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, 369 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
343 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG, 370 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
344 sizeof(*req)); 371 sizeof(*req));
345 372
346 status = be_mcc_notify_wait(phba); 373 be_mcc_notify(phba);
347 if (!status) {
348 struct be_cmd_resp_get_mac_addr *resp = embedded_payload(wrb);
349
350 memcpy(mac_addr, resp->mac_address, ETH_ALEN);
351 }
352
353 spin_unlock(&ctrl->mbox_lock); 374 spin_unlock(&ctrl->mbox_lock);
354 return status; 375 return tag;
355} 376}
356 377
diff --git a/drivers/scsi/be2iscsi/be_mgmt.h b/drivers/scsi/be2iscsi/be_mgmt.h
index 24eaff923f85..ecead6a5aa56 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.h
+++ b/drivers/scsi/be2iscsi/be_mgmt.h
@@ -1,5 +1,5 @@
1/** 1/**
2 * Copyright (C) 2005 - 2009 ServerEngines 2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This program is free software; you can redistribute it and/or 5 * This program is free software; you can redistribute it and/or
@@ -231,6 +231,7 @@ struct beiscsi_endpoint {
231 struct beiscsi_hba *phba; 231 struct beiscsi_hba *phba;
232 struct beiscsi_sess *sess; 232 struct beiscsi_sess *sess;
233 struct beiscsi_conn *conn; 233 struct beiscsi_conn *conn;
234 struct iscsi_endpoint *openiscsi_ep;
234 unsigned short ip_type; 235 unsigned short ip_type;
235 char dst6_addr[ISCSI_ADDRESS_BUF_LEN]; 236 char dst6_addr[ISCSI_ADDRESS_BUF_LEN];
236 unsigned long dst_addr; 237 unsigned long dst_addr;
@@ -249,7 +250,4 @@ unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba,
249 unsigned short issue_reset, 250 unsigned short issue_reset,
250 unsigned short savecfg_flag); 251 unsigned short savecfg_flag);
251 252
252unsigned char mgmt_fw_cmd(struct be_ctrl_info *ctrl,
253 struct beiscsi_hba *phba,
254 char *buf, unsigned int len);
255#endif 253#endif
diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 33b2294625bb..1c4d1215769d 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -1426,8 +1426,8 @@ static int bnx2i_conn_get_param(struct iscsi_cls_conn *cls_conn,
1426 break; 1426 break;
1427 case ISCSI_PARAM_CONN_ADDRESS: 1427 case ISCSI_PARAM_CONN_ADDRESS:
1428 if (bnx2i_conn->ep) 1428 if (bnx2i_conn->ep)
1429 len = sprintf(buf, NIPQUAD_FMT "\n", 1429 len = sprintf(buf, "%pI4\n",
1430 NIPQUAD(bnx2i_conn->ep->cm_sk->dst_ip)); 1430 &bnx2i_conn->ep->cm_sk->dst_ip);
1431 break; 1431 break;
1432 default: 1432 default:
1433 return iscsi_conn_get_param(cls_conn, param, buf); 1433 return iscsi_conn_get_param(cls_conn, param, buf);
@@ -1990,6 +1990,7 @@ static struct scsi_host_template bnx2i_host_template = {
1990 .eh_abort_handler = iscsi_eh_abort, 1990 .eh_abort_handler = iscsi_eh_abort,
1991 .eh_device_reset_handler = iscsi_eh_device_reset, 1991 .eh_device_reset_handler = iscsi_eh_device_reset,
1992 .eh_target_reset_handler = iscsi_eh_target_reset, 1992 .eh_target_reset_handler = iscsi_eh_target_reset,
1993 .change_queue_depth = iscsi_change_queue_depth,
1993 .can_queue = 1024, 1994 .can_queue = 1024,
1994 .max_sectors = 127, 1995 .max_sectors = 127,
1995 .cmd_per_lun = 32, 1996 .cmd_per_lun = 32,
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 9129bcf117cf..cd05e049d5f6 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -219,18 +219,15 @@ static void print_opcode_name(unsigned char * cdbp, int cdb_len)
219 break; 219 break;
220 } 220 }
221 sa = (cdbp[8] << 8) + cdbp[9]; 221 sa = (cdbp[8] << 8) + cdbp[9];
222 name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa); 222 name = get_sa_name(variable_length_arr, VARIABLE_LENGTH_SZ, sa);
223 if (name) { 223 if (name)
224 printk("%s", name); 224 printk("%s", name);
225 if ((cdb_len > 0) && (len != cdb_len)) 225 else
226 printk(", in_cdb_len=%d, ext_len=%d",
227 len, cdb_len);
228 } else {
229 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa); 226 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
230 if ((cdb_len > 0) && (len != cdb_len)) 227
231 printk(", in_cdb_len=%d, ext_len=%d", 228 if ((cdb_len > 0) && (len != cdb_len))
232 len, cdb_len); 229 printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len);
233 } 230
234 break; 231 break;
235 case MAINTENANCE_IN: 232 case MAINTENANCE_IN:
236 sa = cdbp[1] & 0x1f; 233 sa = cdbp[1] & 0x1f;
@@ -349,6 +346,9 @@ void scsi_print_command(struct scsi_cmnd *cmd)
349{ 346{
350 int k; 347 int k;
351 348
349 if (cmd->cmnd == NULL)
350 return;
351
352 scmd_printk(KERN_INFO, cmd, "CDB: "); 352 scmd_printk(KERN_INFO, cmd, "CDB: ");
353 print_opcode_name(cmd->cmnd, cmd->cmd_len); 353 print_opcode_name(cmd->cmnd, cmd->cmd_len);
354 354
diff --git a/drivers/scsi/cxgb3i/cxgb3i_iscsi.c b/drivers/scsi/cxgb3i/cxgb3i_iscsi.c
index 969c83162cc4..412853c65372 100644
--- a/drivers/scsi/cxgb3i/cxgb3i_iscsi.c
+++ b/drivers/scsi/cxgb3i/cxgb3i_iscsi.c
@@ -591,8 +591,7 @@ static int cxgb3i_conn_bind(struct iscsi_cls_session *cls_session,
591 cxgb3i_conn_max_recv_dlength(conn); 591 cxgb3i_conn_max_recv_dlength(conn);
592 592
593 spin_lock_bh(&conn->session->lock); 593 spin_lock_bh(&conn->session->lock);
594 sprintf(conn->portal_address, NIPQUAD_FMT, 594 sprintf(conn->portal_address, "%pI4", &c3cn->daddr.sin_addr.s_addr);
595 NIPQUAD(c3cn->daddr.sin_addr.s_addr));
596 conn->portal_port = ntohs(c3cn->daddr.sin_port); 595 conn->portal_port = ntohs(c3cn->daddr.sin_port);
597 spin_unlock_bh(&conn->session->lock); 596 spin_unlock_bh(&conn->session->lock);
598 597
@@ -709,6 +708,12 @@ static int cxgb3i_host_set_param(struct Scsi_Host *shost,
709{ 708{
710 struct cxgb3i_hba *hba = iscsi_host_priv(shost); 709 struct cxgb3i_hba *hba = iscsi_host_priv(shost);
711 710
711 if (!hba->ndev) {
712 shost_printk(KERN_ERR, shost, "Could not set host param. "
713 "Netdev for host not set.\n");
714 return -ENODEV;
715 }
716
712 cxgb3i_api_debug("param %d, buf %s.\n", param, buf); 717 cxgb3i_api_debug("param %d, buf %s.\n", param, buf);
713 718
714 switch (param) { 719 switch (param) {
@@ -739,6 +744,12 @@ static int cxgb3i_host_get_param(struct Scsi_Host *shost,
739 struct cxgb3i_hba *hba = iscsi_host_priv(shost); 744 struct cxgb3i_hba *hba = iscsi_host_priv(shost);
740 int len = 0; 745 int len = 0;
741 746
747 if (!hba->ndev) {
748 shost_printk(KERN_ERR, shost, "Could not set host param. "
749 "Netdev for host not set.\n");
750 return -ENODEV;
751 }
752
742 cxgb3i_api_debug("hba %s, param %d.\n", hba->ndev->name, param); 753 cxgb3i_api_debug("hba %s, param %d.\n", hba->ndev->name, param);
743 754
744 switch (param) { 755 switch (param) {
@@ -753,7 +764,7 @@ static int cxgb3i_host_get_param(struct Scsi_Host *shost,
753 __be32 addr; 764 __be32 addr;
754 765
755 addr = cxgb3i_get_private_ipv4addr(hba->ndev); 766 addr = cxgb3i_get_private_ipv4addr(hba->ndev);
756 len = sprintf(buf, NIPQUAD_FMT, NIPQUAD(addr)); 767 len = sprintf(buf, "%pI4", &addr);
757 break; 768 break;
758 } 769 }
759 default: 770 default:
diff --git a/drivers/scsi/cxgb3i/cxgb3i_offload.c b/drivers/scsi/cxgb3i/cxgb3i_offload.c
index 15a00e8b7122..3e08c430ff29 100644
--- a/drivers/scsi/cxgb3i/cxgb3i_offload.c
+++ b/drivers/scsi/cxgb3i/cxgb3i_offload.c
@@ -1675,10 +1675,11 @@ int cxgb3i_c3cn_connect(struct net_device *dev, struct s3_conn *c3cn,
1675 } else 1675 } else
1676 c3cn->saddr.sin_addr.s_addr = sipv4; 1676 c3cn->saddr.sin_addr.s_addr = sipv4;
1677 1677
1678 c3cn_conn_debug("c3cn 0x%p, %u.%u.%u.%u,%u-%u.%u.%u.%u,%u SYN_SENT.\n", 1678 c3cn_conn_debug("c3cn 0x%p, %pI4,%u-%pI4,%u SYN_SENT.\n",
1679 c3cn, NIPQUAD(c3cn->saddr.sin_addr.s_addr), 1679 c3cn,
1680 &c3cn->saddr.sin_addr.s_addr,
1680 ntohs(c3cn->saddr.sin_port), 1681 ntohs(c3cn->saddr.sin_port),
1681 NIPQUAD(c3cn->daddr.sin_addr.s_addr), 1682 &c3cn->daddr.sin_addr.s_addr,
1682 ntohs(c3cn->daddr.sin_port)); 1683 ntohs(c3cn->daddr.sin_port));
1683 1684
1684 c3cn_set_state(c3cn, C3CN_STATE_CONNECTING); 1685 c3cn_set_state(c3cn, C3CN_STATE_CONNECTING);
diff --git a/drivers/scsi/cxgb3i/cxgb3i_pdu.c b/drivers/scsi/cxgb3i/cxgb3i_pdu.c
index 1fe3b0f1f3c9..9c38539557fc 100644
--- a/drivers/scsi/cxgb3i/cxgb3i_pdu.c
+++ b/drivers/scsi/cxgb3i/cxgb3i_pdu.c
@@ -461,10 +461,8 @@ void cxgb3i_conn_pdu_ready(struct s3_conn *c3cn)
461 skb = skb_peek(&c3cn->receive_queue); 461 skb = skb_peek(&c3cn->receive_queue);
462 } 462 }
463 read_unlock(&c3cn->callback_lock); 463 read_unlock(&c3cn->callback_lock);
464 if (c3cn) { 464 c3cn->copied_seq += read;
465 c3cn->copied_seq += read; 465 cxgb3i_c3cn_rx_credits(c3cn, read);
466 cxgb3i_c3cn_rx_credits(c3cn, read);
467 }
468 conn->rxdata_octets += read; 466 conn->rxdata_octets += read;
469 467
470 if (err) { 468 if (err) {
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 4f0d0138f48b..bc9e94f5915e 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -717,6 +717,8 @@ static const struct scsi_dh_devlist alua_dev_list[] = {
717 {"IBM", "2145" }, 717 {"IBM", "2145" },
718 {"Pillar", "Axiom" }, 718 {"Pillar", "Axiom" },
719 {"Intel", "Multi-Flex"}, 719 {"Intel", "Multi-Flex"},
720 {"NETAPP", "LUN"},
721 {"AIX", "NVDISK"},
720 {NULL, NULL} 722 {NULL, NULL}
721}; 723};
722 724
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index c7076ce25e21..3c5abf7cd762 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -1509,7 +1509,7 @@ static int option_setup(char *str)
1509 char *cur = str; 1509 char *cur = str;
1510 int i = 1; 1510 int i = 1;
1511 1511
1512 while (cur && isdigit(*cur) && i <= MAX_INT_PARAM) { 1512 while (cur && isdigit(*cur) && i < MAX_INT_PARAM) {
1513 ints[i++] = simple_strtoul(cur, NULL, 0); 1513 ints[i++] = simple_strtoul(cur, NULL, 0);
1514 1514
1515 if ((cur = strchr(cur, ',')) != NULL) 1515 if ((cur = strchr(cur, ',')) != NULL)
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index a680e18b5f3b..e2bc779f86c1 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -1449,9 +1449,6 @@ static void esp_msgin_sdtr(struct esp *esp, struct esp_target_data *tp)
1449 if (offset > 15) 1449 if (offset > 15)
1450 goto do_reject; 1450 goto do_reject;
1451 1451
1452 if (esp->flags & ESP_FLAG_DISABLE_SYNC)
1453 offset = 0;
1454
1455 if (offset) { 1452 if (offset) {
1456 int one_clock; 1453 int one_clock;
1457 1454
@@ -2405,12 +2402,6 @@ static int esp_slave_configure(struct scsi_device *dev)
2405 struct esp_target_data *tp = &esp->target[dev->id]; 2402 struct esp_target_data *tp = &esp->target[dev->id];
2406 int goal_tags, queue_depth; 2403 int goal_tags, queue_depth;
2407 2404
2408 if (esp->flags & ESP_FLAG_DISABLE_SYNC) {
2409 /* Bypass async domain validation */
2410 dev->ppr = 0;
2411 dev->sdtr = 0;
2412 }
2413
2414 goal_tags = 0; 2405 goal_tags = 0;
2415 2406
2416 if (dev->tagged_supported) { 2407 if (dev->tagged_supported) {
@@ -2660,7 +2651,10 @@ static void esp_set_offset(struct scsi_target *target, int offset)
2660 struct esp *esp = shost_priv(host); 2651 struct esp *esp = shost_priv(host);
2661 struct esp_target_data *tp = &esp->target[target->id]; 2652 struct esp_target_data *tp = &esp->target[target->id];
2662 2653
2663 tp->nego_goal_offset = offset; 2654 if (esp->flags & ESP_FLAG_DISABLE_SYNC)
2655 tp->nego_goal_offset = 0;
2656 else
2657 tp->nego_goal_offset = offset;
2664 tp->flags |= ESP_TGT_CHECK_NEGO; 2658 tp->flags |= ESP_TGT_CHECK_NEGO;
2665} 2659}
2666 2660
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 10be9f36a4cc..2f47ae7cce91 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -2009,6 +2009,8 @@ static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
2009 fcoe_interface_cleanup(fcoe); 2009 fcoe_interface_cleanup(fcoe);
2010 rtnl_unlock(); 2010 rtnl_unlock();
2011 fcoe_if_destroy(fcoe->ctlr.lp); 2011 fcoe_if_destroy(fcoe->ctlr.lp);
2012 module_put(THIS_MODULE);
2013
2012out_putdev: 2014out_putdev:
2013 dev_put(netdev); 2015 dev_put(netdev);
2014out_nodev: 2016out_nodev:
@@ -2059,6 +2061,11 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
2059 } 2061 }
2060#endif 2062#endif
2061 2063
2064 if (!try_module_get(THIS_MODULE)) {
2065 rc = -EINVAL;
2066 goto out_nomod;
2067 }
2068
2062 rtnl_lock(); 2069 rtnl_lock();
2063 netdev = fcoe_if_to_netdev(buffer); 2070 netdev = fcoe_if_to_netdev(buffer);
2064 if (!netdev) { 2071 if (!netdev) {
@@ -2099,17 +2106,24 @@ static int fcoe_create(const char *buffer, struct kernel_param *kp)
2099 if (!fcoe_link_ok(lport)) 2106 if (!fcoe_link_ok(lport))
2100 fcoe_ctlr_link_up(&fcoe->ctlr); 2107 fcoe_ctlr_link_up(&fcoe->ctlr);
2101 2108
2102 rc = 0;
2103out_free:
2104 /* 2109 /*
2105 * Release from init in fcoe_interface_create(), on success lport 2110 * Release from init in fcoe_interface_create(), on success lport
2106 * should be holding a reference taken in fcoe_if_create(). 2111 * should be holding a reference taken in fcoe_if_create().
2107 */ 2112 */
2108 fcoe_interface_put(fcoe); 2113 fcoe_interface_put(fcoe);
2114 dev_put(netdev);
2115 rtnl_unlock();
2116 mutex_unlock(&fcoe_config_mutex);
2117
2118 return 0;
2119out_free:
2120 fcoe_interface_put(fcoe);
2109out_putdev: 2121out_putdev:
2110 dev_put(netdev); 2122 dev_put(netdev);
2111out_nodev: 2123out_nodev:
2112 rtnl_unlock(); 2124 rtnl_unlock();
2125 module_put(THIS_MODULE);
2126out_nomod:
2113 mutex_unlock(&fcoe_config_mutex); 2127 mutex_unlock(&fcoe_config_mutex);
2114 return rc; 2128 return rc;
2115} 2129}
diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
index 9823291395ad..511cb6b371ee 100644
--- a/drivers/scsi/fcoe/libfcoe.c
+++ b/drivers/scsi/fcoe/libfcoe.c
@@ -1187,7 +1187,7 @@ static void fcoe_ctlr_timeout(unsigned long arg)
1187 next_timer = fip->ctlr_ka_time; 1187 next_timer = fip->ctlr_ka_time;
1188 1188
1189 if (time_after_eq(jiffies, fip->port_ka_time)) { 1189 if (time_after_eq(jiffies, fip->port_ka_time)) {
1190 fip->port_ka_time += jiffies + 1190 fip->port_ka_time = jiffies +
1191 msecs_to_jiffies(FIP_VN_KA_PERIOD); 1191 msecs_to_jiffies(FIP_VN_KA_PERIOD);
1192 fip->send_port_ka = 1; 1192 fip->send_port_ka = 1;
1193 } 1193 }
diff --git a/drivers/scsi/fnic/fnic.h b/drivers/scsi/fnic/fnic.h
index bb208a6091e7..3966c71d0095 100644
--- a/drivers/scsi/fnic/fnic.h
+++ b/drivers/scsi/fnic/fnic.h
@@ -36,7 +36,7 @@
36 36
37#define DRV_NAME "fnic" 37#define DRV_NAME "fnic"
38#define DRV_DESCRIPTION "Cisco FCoE HBA Driver" 38#define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
39#define DRV_VERSION "1.0.0.1121" 39#define DRV_VERSION "1.4.0.98"
40#define PFX DRV_NAME ": " 40#define PFX DRV_NAME ": "
41#define DFX DRV_NAME "%d: " 41#define DFX DRV_NAME "%d: "
42 42
diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
index fe1b1031f7ab..507e26c1c29f 100644
--- a/drivers/scsi/fnic/fnic_main.c
+++ b/drivers/scsi/fnic/fnic_main.c
@@ -620,6 +620,8 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
620 if (fnic->config.flags & VFCF_FIP_CAPABLE) { 620 if (fnic->config.flags & VFCF_FIP_CAPABLE) {
621 shost_printk(KERN_INFO, fnic->lport->host, 621 shost_printk(KERN_INFO, fnic->lport->host,
622 "firmware supports FIP\n"); 622 "firmware supports FIP\n");
623 /* enable directed and multicast */
624 vnic_dev_packet_filter(fnic->vdev, 1, 1, 0, 0, 0);
623 vnic_dev_add_addr(fnic->vdev, FIP_ALL_ENODE_MACS); 625 vnic_dev_add_addr(fnic->vdev, FIP_ALL_ENODE_MACS);
624 vnic_dev_add_addr(fnic->vdev, fnic->ctlr.ctl_src_addr); 626 vnic_dev_add_addr(fnic->vdev, fnic->ctlr.ctl_src_addr);
625 } else { 627 } else {
@@ -698,6 +700,8 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
698 goto err_out_remove_scsi_host; 700 goto err_out_remove_scsi_host;
699 } 701 }
700 702
703 fc_lport_init_stats(lp);
704
701 fc_lport_config(lp); 705 fc_lport_config(lp);
702 706
703 if (fc_set_mfs(lp, fnic->config.maxdatafieldsize + 707 if (fc_set_mfs(lp, fnic->config.maxdatafieldsize +
diff --git a/drivers/scsi/fnic/vnic_devcmd.h b/drivers/scsi/fnic/vnic_devcmd.h
index d62b9061bf12..7c9ccbd4134b 100644
--- a/drivers/scsi/fnic/vnic_devcmd.h
+++ b/drivers/scsi/fnic/vnic_devcmd.h
@@ -94,7 +94,7 @@ enum vnic_devcmd_cmd {
94 CMD_STATS_DUMP = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 4), 94 CMD_STATS_DUMP = _CMDC(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 4),
95 95
96 /* set Rx packet filter: (u32)a0=filters (see CMD_PFILTER_*) */ 96 /* set Rx packet filter: (u32)a0=filters (see CMD_PFILTER_*) */
97 CMD_PACKET_FILTER = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ENET, 7), 97 CMD_PACKET_FILTER = _CMDCNW(_CMD_DIR_WRITE, _CMD_VTYPE_ALL, 7),
98 98
99 /* hang detection notification */ 99 /* hang detection notification */
100 CMD_HANG_NOTIFY = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 8), 100 CMD_HANG_NOTIFY = _CMDC(_CMD_DIR_NONE, _CMD_VTYPE_ALL, 8),
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 9e8fce0f0c1b..ba3c94c9c25f 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -140,40 +140,40 @@
140#include "gdth.h" 140#include "gdth.h"
141 141
142static void gdth_delay(int milliseconds); 142static void gdth_delay(int milliseconds);
143static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs); 143static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs);
144static irqreturn_t gdth_interrupt(int irq, void *dev_id); 144static irqreturn_t gdth_interrupt(int irq, void *dev_id);
145static irqreturn_t __gdth_interrupt(gdth_ha_str *ha, 145static irqreturn_t __gdth_interrupt(gdth_ha_str *ha,
146 int gdth_from_wait, int* pIndex); 146 int gdth_from_wait, int* pIndex);
147static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index, 147static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
148 Scsi_Cmnd *scp); 148 Scsi_Cmnd *scp);
149static int gdth_async_event(gdth_ha_str *ha); 149static int gdth_async_event(gdth_ha_str *ha);
150static void gdth_log_event(gdth_evt_data *dvr, char *buffer); 150static void gdth_log_event(gdth_evt_data *dvr, char *buffer);
151 151
152static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority); 152static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, u8 priority);
153static void gdth_next(gdth_ha_str *ha); 153static void gdth_next(gdth_ha_str *ha);
154static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b); 154static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, u8 b);
155static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp); 155static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp);
156static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source, 156static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, u16 source,
157 ushort idx, gdth_evt_data *evt); 157 u16 idx, gdth_evt_data *evt);
158static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr); 158static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr);
159static void gdth_readapp_event(gdth_ha_str *ha, unchar application, 159static void gdth_readapp_event(gdth_ha_str *ha, u8 application,
160 gdth_evt_str *estr); 160 gdth_evt_str *estr);
161static void gdth_clear_events(void); 161static void gdth_clear_events(void);
162 162
163static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp, 163static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
164 char *buffer, ushort count); 164 char *buffer, u16 count);
165static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp); 165static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp);
166static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive); 166static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, u16 hdrive);
167 167
168static void gdth_enable_int(gdth_ha_str *ha); 168static void gdth_enable_int(gdth_ha_str *ha);
169static int gdth_test_busy(gdth_ha_str *ha); 169static int gdth_test_busy(gdth_ha_str *ha);
170static int gdth_get_cmd_index(gdth_ha_str *ha); 170static int gdth_get_cmd_index(gdth_ha_str *ha);
171static void gdth_release_event(gdth_ha_str *ha); 171static void gdth_release_event(gdth_ha_str *ha);
172static int gdth_wait(gdth_ha_str *ha, int index,ulong32 time); 172static int gdth_wait(gdth_ha_str *ha, int index,u32 time);
173static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode, 173static int gdth_internal_cmd(gdth_ha_str *ha, u8 service, u16 opcode,
174 ulong32 p1, ulong64 p2,ulong64 p3); 174 u32 p1, u64 p2,u64 p3);
175static int gdth_search_drives(gdth_ha_str *ha); 175static int gdth_search_drives(gdth_ha_str *ha);
176static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive); 176static int gdth_analyse_hdrive(gdth_ha_str *ha, u16 hdrive);
177 177
178static const char *gdth_ctr_name(gdth_ha_str *ha); 178static const char *gdth_ctr_name(gdth_ha_str *ha);
179 179
@@ -189,7 +189,7 @@ static int __gdth_queuecommand(gdth_ha_str *ha, struct scsi_cmnd *scp,
189static void gdth_scsi_done(struct scsi_cmnd *scp); 189static void gdth_scsi_done(struct scsi_cmnd *scp);
190 190
191#ifdef DEBUG_GDTH 191#ifdef DEBUG_GDTH
192static unchar DebugState = DEBUG_GDTH; 192static u8 DebugState = DEBUG_GDTH;
193 193
194#ifdef __SERIAL__ 194#ifdef __SERIAL__
195#define MAX_SERBUF 160 195#define MAX_SERBUF 160
@@ -270,30 +270,30 @@ static int ser_printk(const char *fmt, ...)
270#endif 270#endif
271 271
272#ifdef GDTH_STATISTICS 272#ifdef GDTH_STATISTICS
273static ulong32 max_rq=0, max_index=0, max_sg=0; 273static u32 max_rq=0, max_index=0, max_sg=0;
274#ifdef INT_COAL 274#ifdef INT_COAL
275static ulong32 max_int_coal=0; 275static u32 max_int_coal=0;
276#endif 276#endif
277static ulong32 act_ints=0, act_ios=0, act_stats=0, act_rq=0; 277static u32 act_ints=0, act_ios=0, act_stats=0, act_rq=0;
278static struct timer_list gdth_timer; 278static struct timer_list gdth_timer;
279#endif 279#endif
280 280
281#define PTR2USHORT(a) (ushort)(ulong)(a) 281#define PTR2USHORT(a) (u16)(unsigned long)(a)
282#define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b) 282#define GDTOFFSOF(a,b) (size_t)&(((a*)0)->b)
283#define INDEX_OK(i,t) ((i)<ARRAY_SIZE(t)) 283#define INDEX_OK(i,t) ((i)<ARRAY_SIZE(t))
284 284
285#define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b)) 285#define BUS_L2P(a,b) ((b)>(a)->virt_bus ? (b-1):(b))
286 286
287#ifdef CONFIG_ISA 287#ifdef CONFIG_ISA
288static unchar gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */ 288static u8 gdth_drq_tab[4] = {5,6,7,7}; /* DRQ table */
289#endif 289#endif
290#if defined(CONFIG_EISA) || defined(CONFIG_ISA) 290#if defined(CONFIG_EISA) || defined(CONFIG_ISA)
291static unchar gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */ 291static u8 gdth_irq_tab[6] = {0,10,11,12,14,0}; /* IRQ table */
292#endif 292#endif
293static unchar gdth_polling; /* polling if TRUE */ 293static u8 gdth_polling; /* polling if TRUE */
294static int gdth_ctr_count = 0; /* controller count */ 294static int gdth_ctr_count = 0; /* controller count */
295static LIST_HEAD(gdth_instances); /* controller list */ 295static LIST_HEAD(gdth_instances); /* controller list */
296static unchar gdth_write_through = FALSE; /* write through */ 296static u8 gdth_write_through = FALSE; /* write through */
297static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */ 297static gdth_evt_str ebuffer[MAX_EVENTS]; /* event buffer */
298static int elastidx; 298static int elastidx;
299static int eoldidx; 299static int eoldidx;
@@ -303,7 +303,7 @@ static int major;
303#define DOU 2 /* OUT data direction */ 303#define DOU 2 /* OUT data direction */
304#define DNO DIN /* no data transfer */ 304#define DNO DIN /* no data transfer */
305#define DUN DIN /* unknown data direction */ 305#define DUN DIN /* unknown data direction */
306static unchar gdth_direction_tab[0x100] = { 306static u8 gdth_direction_tab[0x100] = {
307 DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN, 307 DNO,DNO,DIN,DIN,DOU,DIN,DIN,DOU,DIN,DUN,DOU,DOU,DUN,DUN,DUN,DIN,
308 DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN, 308 DNO,DIN,DIN,DOU,DIN,DOU,DNO,DNO,DOU,DNO,DIN,DNO,DIN,DOU,DNO,DUN,
309 DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU, 309 DIN,DUN,DIN,DUN,DOU,DIN,DUN,DUN,DIN,DIN,DOU,DNO,DUN,DIN,DOU,DOU,
@@ -390,7 +390,7 @@ static gdth_ha_str *gdth_find_ha(int hanum)
390static struct gdth_cmndinfo *gdth_get_cmndinfo(gdth_ha_str *ha) 390static struct gdth_cmndinfo *gdth_get_cmndinfo(gdth_ha_str *ha)
391{ 391{
392 struct gdth_cmndinfo *priv = NULL; 392 struct gdth_cmndinfo *priv = NULL;
393 ulong flags; 393 unsigned long flags;
394 int i; 394 int i;
395 395
396 spin_lock_irqsave(&ha->smp_lock, flags); 396 spin_lock_irqsave(&ha->smp_lock, flags);
@@ -493,7 +493,7 @@ int gdth_execute(struct Scsi_Host *shost, gdth_cmd_str *gdtcmd, char *cmnd,
493 return rval; 493 return rval;
494} 494}
495 495
496static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs) 496static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs)
497{ 497{
498 *cyls = size /HEADS/SECS; 498 *cyls = size /HEADS/SECS;
499 if (*cyls <= MAXCYLS) { 499 if (*cyls <= MAXCYLS) {
@@ -514,9 +514,9 @@ static void gdth_eval_mapping(ulong32 size, ulong32 *cyls, int *heads, int *secs
514 514
515/* controller search and initialization functions */ 515/* controller search and initialization functions */
516#ifdef CONFIG_EISA 516#ifdef CONFIG_EISA
517static int __init gdth_search_eisa(ushort eisa_adr) 517static int __init gdth_search_eisa(u16 eisa_adr)
518{ 518{
519 ulong32 id; 519 u32 id;
520 520
521 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr)); 521 TRACE(("gdth_search_eisa() adr. %x\n",eisa_adr));
522 id = inl(eisa_adr+ID0REG); 522 id = inl(eisa_adr+ID0REG);
@@ -533,13 +533,13 @@ static int __init gdth_search_eisa(ushort eisa_adr)
533#endif /* CONFIG_EISA */ 533#endif /* CONFIG_EISA */
534 534
535#ifdef CONFIG_ISA 535#ifdef CONFIG_ISA
536static int __init gdth_search_isa(ulong32 bios_adr) 536static int __init gdth_search_isa(u32 bios_adr)
537{ 537{
538 void __iomem *addr; 538 void __iomem *addr;
539 ulong32 id; 539 u32 id;
540 540
541 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr)); 541 TRACE(("gdth_search_isa() bios adr. %x\n",bios_adr));
542 if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(ulong32))) != NULL) { 542 if ((addr = ioremap(bios_adr+BIOS_ID_OFFS, sizeof(u32))) != NULL) {
543 id = readl(addr); 543 id = readl(addr);
544 iounmap(addr); 544 iounmap(addr);
545 if (id == GDT2_ID) /* GDT2000 */ 545 if (id == GDT2_ID) /* GDT2000 */
@@ -551,7 +551,7 @@ static int __init gdth_search_isa(ulong32 bios_adr)
551 551
552#ifdef CONFIG_PCI 552#ifdef CONFIG_PCI
553 553
554static bool gdth_search_vortex(ushort device) 554static bool gdth_search_vortex(u16 device)
555{ 555{
556 if (device <= PCI_DEVICE_ID_VORTEX_GDT6555) 556 if (device <= PCI_DEVICE_ID_VORTEX_GDT6555)
557 return true; 557 return true;
@@ -603,9 +603,9 @@ static void __devexit gdth_pci_remove_one(struct pci_dev *pdev)
603static int __devinit gdth_pci_init_one(struct pci_dev *pdev, 603static int __devinit gdth_pci_init_one(struct pci_dev *pdev,
604 const struct pci_device_id *ent) 604 const struct pci_device_id *ent)
605{ 605{
606 ushort vendor = pdev->vendor; 606 u16 vendor = pdev->vendor;
607 ushort device = pdev->device; 607 u16 device = pdev->device;
608 ulong base0, base1, base2; 608 unsigned long base0, base1, base2;
609 int rc; 609 int rc;
610 gdth_pci_str gdth_pcistr; 610 gdth_pci_str gdth_pcistr;
611 gdth_ha_str *ha = NULL; 611 gdth_ha_str *ha = NULL;
@@ -658,10 +658,10 @@ static int __devinit gdth_pci_init_one(struct pci_dev *pdev,
658#endif /* CONFIG_PCI */ 658#endif /* CONFIG_PCI */
659 659
660#ifdef CONFIG_EISA 660#ifdef CONFIG_EISA
661static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha) 661static int __init gdth_init_eisa(u16 eisa_adr,gdth_ha_str *ha)
662{ 662{
663 ulong32 retries,id; 663 u32 retries,id;
664 unchar prot_ver,eisacf,i,irq_found; 664 u8 prot_ver,eisacf,i,irq_found;
665 665
666 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr)); 666 TRACE(("gdth_init_eisa() adr. %x\n",eisa_adr));
667 667
@@ -688,7 +688,7 @@ static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
688 return 0; 688 return 0;
689 } 689 }
690 ha->bmic = eisa_adr; 690 ha->bmic = eisa_adr;
691 ha->brd_phys = (ulong32)eisa_adr >> 12; 691 ha->brd_phys = (u32)eisa_adr >> 12;
692 692
693 outl(0,eisa_adr+MAILBOXREG); 693 outl(0,eisa_adr+MAILBOXREG);
694 outl(0,eisa_adr+MAILBOXREG+4); 694 outl(0,eisa_adr+MAILBOXREG+4);
@@ -752,12 +752,12 @@ static int __init gdth_init_eisa(ushort eisa_adr,gdth_ha_str *ha)
752#endif /* CONFIG_EISA */ 752#endif /* CONFIG_EISA */
753 753
754#ifdef CONFIG_ISA 754#ifdef CONFIG_ISA
755static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha) 755static int __init gdth_init_isa(u32 bios_adr,gdth_ha_str *ha)
756{ 756{
757 register gdt2_dpram_str __iomem *dp2_ptr; 757 register gdt2_dpram_str __iomem *dp2_ptr;
758 int i; 758 int i;
759 unchar irq_drq,prot_ver; 759 u8 irq_drq,prot_ver;
760 ulong32 retries; 760 u32 retries;
761 761
762 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr)); 762 TRACE(("gdth_init_isa() bios adr. %x\n",bios_adr));
763 763
@@ -812,7 +812,7 @@ static int __init gdth_init_isa(ulong32 bios_adr,gdth_ha_str *ha)
812 } 812 }
813 gdth_delay(1); 813 gdth_delay(1);
814 } 814 }
815 prot_ver = (unchar)readl(&dp2_ptr->u.ic.S_Info[0]); 815 prot_ver = (u8)readl(&dp2_ptr->u.ic.S_Info[0]);
816 writeb(0, &dp2_ptr->u.ic.Status); 816 writeb(0, &dp2_ptr->u.ic.Status);
817 writeb(0xff, &dp2_ptr->io.irqdel); 817 writeb(0xff, &dp2_ptr->io.irqdel);
818 if (prot_ver != PROTOCOL_VERSION) { 818 if (prot_ver != PROTOCOL_VERSION) {
@@ -859,9 +859,9 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
859 register gdt6_dpram_str __iomem *dp6_ptr; 859 register gdt6_dpram_str __iomem *dp6_ptr;
860 register gdt6c_dpram_str __iomem *dp6c_ptr; 860 register gdt6c_dpram_str __iomem *dp6c_ptr;
861 register gdt6m_dpram_str __iomem *dp6m_ptr; 861 register gdt6m_dpram_str __iomem *dp6m_ptr;
862 ulong32 retries; 862 u32 retries;
863 unchar prot_ver; 863 u8 prot_ver;
864 ushort command; 864 u16 command;
865 int i, found = FALSE; 865 int i, found = FALSE;
866 866
867 TRACE(("gdth_init_pci()\n")); 867 TRACE(("gdth_init_pci()\n"));
@@ -871,7 +871,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
871 else 871 else
872 ha->oem_id = OEM_ID_ICP; 872 ha->oem_id = OEM_ID_ICP;
873 ha->brd_phys = (pdev->bus->number << 8) | (pdev->devfn & 0xf8); 873 ha->brd_phys = (pdev->bus->number << 8) | (pdev->devfn & 0xf8);
874 ha->stype = (ulong32)pdev->device; 874 ha->stype = (u32)pdev->device;
875 ha->irq = pdev->irq; 875 ha->irq = pdev->irq;
876 ha->pdev = pdev; 876 ha->pdev = pdev;
877 877
@@ -891,7 +891,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
891 found = FALSE; 891 found = FALSE;
892 for (i = 0xC8000; i < 0xE8000; i += 0x4000) { 892 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
893 iounmap(ha->brd); 893 iounmap(ha->brd);
894 ha->brd = ioremap(i, sizeof(ushort)); 894 ha->brd = ioremap(i, sizeof(u16));
895 if (ha->brd == NULL) { 895 if (ha->brd == NULL) {
896 printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); 896 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
897 return 0; 897 return 0;
@@ -947,7 +947,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
947 } 947 }
948 gdth_delay(1); 948 gdth_delay(1);
949 } 949 }
950 prot_ver = (unchar)readl(&dp6_ptr->u.ic.S_Info[0]); 950 prot_ver = (u8)readl(&dp6_ptr->u.ic.S_Info[0]);
951 writeb(0, &dp6_ptr->u.ic.S_Status); 951 writeb(0, &dp6_ptr->u.ic.S_Status);
952 writeb(0xff, &dp6_ptr->io.irqdel); 952 writeb(0xff, &dp6_ptr->io.irqdel);
953 if (prot_ver != PROTOCOL_VERSION) { 953 if (prot_ver != PROTOCOL_VERSION) {
@@ -1000,7 +1000,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
1000 found = FALSE; 1000 found = FALSE;
1001 for (i = 0xC8000; i < 0xE8000; i += 0x4000) { 1001 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1002 iounmap(ha->brd); 1002 iounmap(ha->brd);
1003 ha->brd = ioremap(i, sizeof(ushort)); 1003 ha->brd = ioremap(i, sizeof(u16));
1004 if (ha->brd == NULL) { 1004 if (ha->brd == NULL) {
1005 printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); 1005 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1006 return 0; 1006 return 0;
@@ -1059,7 +1059,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
1059 } 1059 }
1060 gdth_delay(1); 1060 gdth_delay(1);
1061 } 1061 }
1062 prot_ver = (unchar)readl(&dp6c_ptr->u.ic.S_Info[0]); 1062 prot_ver = (u8)readl(&dp6c_ptr->u.ic.S_Info[0]);
1063 writeb(0, &dp6c_ptr->u.ic.Status); 1063 writeb(0, &dp6c_ptr->u.ic.Status);
1064 if (prot_ver != PROTOCOL_VERSION) { 1064 if (prot_ver != PROTOCOL_VERSION) {
1065 printk("GDT-PCI: Illegal protocol version\n"); 1065 printk("GDT-PCI: Illegal protocol version\n");
@@ -1128,7 +1128,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
1128 found = FALSE; 1128 found = FALSE;
1129 for (i = 0xC8000; i < 0xE8000; i += 0x4000) { 1129 for (i = 0xC8000; i < 0xE8000; i += 0x4000) {
1130 iounmap(ha->brd); 1130 iounmap(ha->brd);
1131 ha->brd = ioremap(i, sizeof(ushort)); 1131 ha->brd = ioremap(i, sizeof(u16));
1132 if (ha->brd == NULL) { 1132 if (ha->brd == NULL) {
1133 printk("GDT-PCI: Initialization error (DPMEM remap error)\n"); 1133 printk("GDT-PCI: Initialization error (DPMEM remap error)\n");
1134 return 0; 1134 return 0;
@@ -1180,7 +1180,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
1180 } 1180 }
1181 gdth_delay(1); 1181 gdth_delay(1);
1182 } 1182 }
1183 prot_ver = (unchar)readl(&dp6m_ptr->u.ic.S_Info[0]); 1183 prot_ver = (u8)readl(&dp6m_ptr->u.ic.S_Info[0]);
1184 writeb(0, &dp6m_ptr->u.ic.S_Status); 1184 writeb(0, &dp6m_ptr->u.ic.S_Status);
1185 if (prot_ver != PROTOCOL_VERSION) { 1185 if (prot_ver != PROTOCOL_VERSION) {
1186 printk("GDT-PCI: Illegal protocol version\n"); 1186 printk("GDT-PCI: Illegal protocol version\n");
@@ -1223,7 +1223,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
1223 } 1223 }
1224 gdth_delay(1); 1224 gdth_delay(1);
1225 } 1225 }
1226 prot_ver = (unchar)(readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16); 1226 prot_ver = (u8)(readl(&dp6m_ptr->u.ic.S_Info[0]) >> 16);
1227 writeb(0, &dp6m_ptr->u.ic.S_Status); 1227 writeb(0, &dp6m_ptr->u.ic.S_Status);
1228 if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */ 1228 if (prot_ver < 0x2b) /* FW < x.43: no 64-bit DMA support */
1229 ha->dma64_support = 0; 1229 ha->dma64_support = 0;
@@ -1239,7 +1239,7 @@ static int __devinit gdth_init_pci(struct pci_dev *pdev, gdth_pci_str *pcistr,
1239 1239
1240static void __devinit gdth_enable_int(gdth_ha_str *ha) 1240static void __devinit gdth_enable_int(gdth_ha_str *ha)
1241{ 1241{
1242 ulong flags; 1242 unsigned long flags;
1243 gdt2_dpram_str __iomem *dp2_ptr; 1243 gdt2_dpram_str __iomem *dp2_ptr;
1244 gdt6_dpram_str __iomem *dp6_ptr; 1244 gdt6_dpram_str __iomem *dp6_ptr;
1245 gdt6m_dpram_str __iomem *dp6m_ptr; 1245 gdt6m_dpram_str __iomem *dp6m_ptr;
@@ -1274,14 +1274,14 @@ static void __devinit gdth_enable_int(gdth_ha_str *ha)
1274} 1274}
1275 1275
1276/* return IStatus if interrupt was from this card else 0 */ 1276/* return IStatus if interrupt was from this card else 0 */
1277static unchar gdth_get_status(gdth_ha_str *ha) 1277static u8 gdth_get_status(gdth_ha_str *ha)
1278{ 1278{
1279 unchar IStatus = 0; 1279 u8 IStatus = 0;
1280 1280
1281 TRACE(("gdth_get_status() irq %d ctr_count %d\n", ha->irq, gdth_ctr_count)); 1281 TRACE(("gdth_get_status() irq %d ctr_count %d\n", ha->irq, gdth_ctr_count));
1282 1282
1283 if (ha->type == GDT_EISA) 1283 if (ha->type == GDT_EISA)
1284 IStatus = inb((ushort)ha->bmic + EDOORREG); 1284 IStatus = inb((u16)ha->bmic + EDOORREG);
1285 else if (ha->type == GDT_ISA) 1285 else if (ha->type == GDT_ISA)
1286 IStatus = 1286 IStatus =
1287 readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index); 1287 readb(&((gdt2_dpram_str __iomem *)ha->brd)->u.ic.Cmd_Index);
@@ -1329,7 +1329,7 @@ static int gdth_get_cmd_index(gdth_ha_str *ha)
1329 if (ha->cmd_tab[i].cmnd == UNUSED_CMND) { 1329 if (ha->cmd_tab[i].cmnd == UNUSED_CMND) {
1330 ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer; 1330 ha->cmd_tab[i].cmnd = ha->pccb->RequestBuffer;
1331 ha->cmd_tab[i].service = ha->pccb->Service; 1331 ha->cmd_tab[i].service = ha->pccb->Service;
1332 ha->pccb->CommandIndex = (ulong32)i+2; 1332 ha->pccb->CommandIndex = (u32)i+2;
1333 return (i+2); 1333 return (i+2);
1334 } 1334 }
1335 } 1335 }
@@ -1362,7 +1362,7 @@ static void gdth_copy_command(gdth_ha_str *ha)
1362 register gdt6c_dpram_str __iomem *dp6c_ptr; 1362 register gdt6c_dpram_str __iomem *dp6c_ptr;
1363 gdt6_dpram_str __iomem *dp6_ptr; 1363 gdt6_dpram_str __iomem *dp6_ptr;
1364 gdt2_dpram_str __iomem *dp2_ptr; 1364 gdt2_dpram_str __iomem *dp2_ptr;
1365 ushort cp_count,dp_offset,cmd_no; 1365 u16 cp_count,dp_offset,cmd_no;
1366 1366
1367 TRACE(("gdth_copy_command() hanum %d\n", ha->hanum)); 1367 TRACE(("gdth_copy_command() hanum %d\n", ha->hanum));
1368 1368
@@ -1386,28 +1386,28 @@ static void gdth_copy_command(gdth_ha_str *ha)
1386 dp2_ptr = ha->brd; 1386 dp2_ptr = ha->brd;
1387 writew(dp_offset + DPMEM_COMMAND_OFFSET, 1387 writew(dp_offset + DPMEM_COMMAND_OFFSET,
1388 &dp2_ptr->u.ic.comm_queue[cmd_no].offset); 1388 &dp2_ptr->u.ic.comm_queue[cmd_no].offset);
1389 writew((ushort)cmd_ptr->Service, 1389 writew((u16)cmd_ptr->Service,
1390 &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id); 1390 &dp2_ptr->u.ic.comm_queue[cmd_no].serv_id);
1391 memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); 1391 memcpy_toio(&dp2_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1392 } else if (ha->type == GDT_PCI) { 1392 } else if (ha->type == GDT_PCI) {
1393 dp6_ptr = ha->brd; 1393 dp6_ptr = ha->brd;
1394 writew(dp_offset + DPMEM_COMMAND_OFFSET, 1394 writew(dp_offset + DPMEM_COMMAND_OFFSET,
1395 &dp6_ptr->u.ic.comm_queue[cmd_no].offset); 1395 &dp6_ptr->u.ic.comm_queue[cmd_no].offset);
1396 writew((ushort)cmd_ptr->Service, 1396 writew((u16)cmd_ptr->Service,
1397 &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id); 1397 &dp6_ptr->u.ic.comm_queue[cmd_no].serv_id);
1398 memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); 1398 memcpy_toio(&dp6_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1399 } else if (ha->type == GDT_PCINEW) { 1399 } else if (ha->type == GDT_PCINEW) {
1400 dp6c_ptr = ha->brd; 1400 dp6c_ptr = ha->brd;
1401 writew(dp_offset + DPMEM_COMMAND_OFFSET, 1401 writew(dp_offset + DPMEM_COMMAND_OFFSET,
1402 &dp6c_ptr->u.ic.comm_queue[cmd_no].offset); 1402 &dp6c_ptr->u.ic.comm_queue[cmd_no].offset);
1403 writew((ushort)cmd_ptr->Service, 1403 writew((u16)cmd_ptr->Service,
1404 &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id); 1404 &dp6c_ptr->u.ic.comm_queue[cmd_no].serv_id);
1405 memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); 1405 memcpy_toio(&dp6c_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1406 } else if (ha->type == GDT_PCIMPR) { 1406 } else if (ha->type == GDT_PCIMPR) {
1407 dp6m_ptr = ha->brd; 1407 dp6m_ptr = ha->brd;
1408 writew(dp_offset + DPMEM_COMMAND_OFFSET, 1408 writew(dp_offset + DPMEM_COMMAND_OFFSET,
1409 &dp6m_ptr->u.ic.comm_queue[cmd_no].offset); 1409 &dp6m_ptr->u.ic.comm_queue[cmd_no].offset);
1410 writew((ushort)cmd_ptr->Service, 1410 writew((u16)cmd_ptr->Service,
1411 &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id); 1411 &dp6m_ptr->u.ic.comm_queue[cmd_no].serv_id);
1412 memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count); 1412 memcpy_toio(&dp6m_ptr->u.ic.gdt_dpr_cmd[dp_offset],cmd_ptr,cp_count);
1413 } 1413 }
@@ -1420,14 +1420,14 @@ static void gdth_release_event(gdth_ha_str *ha)
1420 1420
1421#ifdef GDTH_STATISTICS 1421#ifdef GDTH_STATISTICS
1422 { 1422 {
1423 ulong32 i,j; 1423 u32 i,j;
1424 for (i=0,j=0; j<GDTH_MAXCMDS; ++j) { 1424 for (i=0,j=0; j<GDTH_MAXCMDS; ++j) {
1425 if (ha->cmd_tab[j].cmnd != UNUSED_CMND) 1425 if (ha->cmd_tab[j].cmnd != UNUSED_CMND)
1426 ++i; 1426 ++i;
1427 } 1427 }
1428 if (max_index < i) { 1428 if (max_index < i) {
1429 max_index = i; 1429 max_index = i;
1430 TRACE3(("GDT: max_index = %d\n",(ushort)i)); 1430 TRACE3(("GDT: max_index = %d\n",(u16)i));
1431 } 1431 }
1432 } 1432 }
1433#endif 1433#endif
@@ -1450,7 +1450,7 @@ static void gdth_release_event(gdth_ha_str *ha)
1450 } 1450 }
1451} 1451}
1452 1452
1453static int gdth_wait(gdth_ha_str *ha, int index, ulong32 time) 1453static int gdth_wait(gdth_ha_str *ha, int index, u32 time)
1454{ 1454{
1455 int answer_found = FALSE; 1455 int answer_found = FALSE;
1456 int wait_index = 0; 1456 int wait_index = 0;
@@ -1476,8 +1476,8 @@ static int gdth_wait(gdth_ha_str *ha, int index, ulong32 time)
1476} 1476}
1477 1477
1478 1478
1479static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode, 1479static int gdth_internal_cmd(gdth_ha_str *ha, u8 service, u16 opcode,
1480 ulong32 p1, ulong64 p2, ulong64 p3) 1480 u32 p1, u64 p2, u64 p3)
1481{ 1481{
1482 register gdth_cmd_str *cmd_ptr; 1482 register gdth_cmd_str *cmd_ptr;
1483 int retries,index; 1483 int retries,index;
@@ -1501,35 +1501,35 @@ static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode,
1501 if (service == CACHESERVICE) { 1501 if (service == CACHESERVICE) {
1502 if (opcode == GDT_IOCTL) { 1502 if (opcode == GDT_IOCTL) {
1503 cmd_ptr->u.ioctl.subfunc = p1; 1503 cmd_ptr->u.ioctl.subfunc = p1;
1504 cmd_ptr->u.ioctl.channel = (ulong32)p2; 1504 cmd_ptr->u.ioctl.channel = (u32)p2;
1505 cmd_ptr->u.ioctl.param_size = (ushort)p3; 1505 cmd_ptr->u.ioctl.param_size = (u16)p3;
1506 cmd_ptr->u.ioctl.p_param = ha->scratch_phys; 1506 cmd_ptr->u.ioctl.p_param = ha->scratch_phys;
1507 } else { 1507 } else {
1508 if (ha->cache_feat & GDT_64BIT) { 1508 if (ha->cache_feat & GDT_64BIT) {
1509 cmd_ptr->u.cache64.DeviceNo = (ushort)p1; 1509 cmd_ptr->u.cache64.DeviceNo = (u16)p1;
1510 cmd_ptr->u.cache64.BlockNo = p2; 1510 cmd_ptr->u.cache64.BlockNo = p2;
1511 } else { 1511 } else {
1512 cmd_ptr->u.cache.DeviceNo = (ushort)p1; 1512 cmd_ptr->u.cache.DeviceNo = (u16)p1;
1513 cmd_ptr->u.cache.BlockNo = (ulong32)p2; 1513 cmd_ptr->u.cache.BlockNo = (u32)p2;
1514 } 1514 }
1515 } 1515 }
1516 } else if (service == SCSIRAWSERVICE) { 1516 } else if (service == SCSIRAWSERVICE) {
1517 if (ha->raw_feat & GDT_64BIT) { 1517 if (ha->raw_feat & GDT_64BIT) {
1518 cmd_ptr->u.raw64.direction = p1; 1518 cmd_ptr->u.raw64.direction = p1;
1519 cmd_ptr->u.raw64.bus = (unchar)p2; 1519 cmd_ptr->u.raw64.bus = (u8)p2;
1520 cmd_ptr->u.raw64.target = (unchar)p3; 1520 cmd_ptr->u.raw64.target = (u8)p3;
1521 cmd_ptr->u.raw64.lun = (unchar)(p3 >> 8); 1521 cmd_ptr->u.raw64.lun = (u8)(p3 >> 8);
1522 } else { 1522 } else {
1523 cmd_ptr->u.raw.direction = p1; 1523 cmd_ptr->u.raw.direction = p1;
1524 cmd_ptr->u.raw.bus = (unchar)p2; 1524 cmd_ptr->u.raw.bus = (u8)p2;
1525 cmd_ptr->u.raw.target = (unchar)p3; 1525 cmd_ptr->u.raw.target = (u8)p3;
1526 cmd_ptr->u.raw.lun = (unchar)(p3 >> 8); 1526 cmd_ptr->u.raw.lun = (u8)(p3 >> 8);
1527 } 1527 }
1528 } else if (service == SCREENSERVICE) { 1528 } else if (service == SCREENSERVICE) {
1529 if (opcode == GDT_REALTIME) { 1529 if (opcode == GDT_REALTIME) {
1530 *(ulong32 *)&cmd_ptr->u.screen.su.data[0] = p1; 1530 *(u32 *)&cmd_ptr->u.screen.su.data[0] = p1;
1531 *(ulong32 *)&cmd_ptr->u.screen.su.data[4] = (ulong32)p2; 1531 *(u32 *)&cmd_ptr->u.screen.su.data[4] = (u32)p2;
1532 *(ulong32 *)&cmd_ptr->u.screen.su.data[8] = (ulong32)p3; 1532 *(u32 *)&cmd_ptr->u.screen.su.data[8] = (u32)p3;
1533 } 1533 }
1534 } 1534 }
1535 ha->cmd_len = sizeof(gdth_cmd_str); 1535 ha->cmd_len = sizeof(gdth_cmd_str);
@@ -1555,9 +1555,9 @@ static int gdth_internal_cmd(gdth_ha_str *ha, unchar service, ushort opcode,
1555 1555
1556static int __devinit gdth_search_drives(gdth_ha_str *ha) 1556static int __devinit gdth_search_drives(gdth_ha_str *ha)
1557{ 1557{
1558 ushort cdev_cnt, i; 1558 u16 cdev_cnt, i;
1559 int ok; 1559 int ok;
1560 ulong32 bus_no, drv_cnt, drv_no, j; 1560 u32 bus_no, drv_cnt, drv_no, j;
1561 gdth_getch_str *chn; 1561 gdth_getch_str *chn;
1562 gdth_drlist_str *drl; 1562 gdth_drlist_str *drl;
1563 gdth_iochan_str *ioc; 1563 gdth_iochan_str *ioc;
@@ -1570,8 +1570,8 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1570#endif 1570#endif
1571 1571
1572#ifdef GDTH_RTC 1572#ifdef GDTH_RTC
1573 unchar rtc[12]; 1573 u8 rtc[12];
1574 ulong flags; 1574 unsigned long flags;
1575#endif 1575#endif
1576 1576
1577 TRACE(("gdth_search_drives() hanum %d\n", ha->hanum)); 1577 TRACE(("gdth_search_drives() hanum %d\n", ha->hanum));
@@ -1584,7 +1584,7 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1584 if (ok) 1584 if (ok)
1585 ha->screen_feat = GDT_64BIT; 1585 ha->screen_feat = GDT_64BIT;
1586 } 1586 }
1587 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC)) 1587 if (force_dma32 || (!ok && ha->status == (u16)S_NOFUNC))
1588 ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_INIT, 0, 0, 0); 1588 ok = gdth_internal_cmd(ha, SCREENSERVICE, GDT_INIT, 0, 0, 0);
1589 if (!ok) { 1589 if (!ok) {
1590 printk("GDT-HA %d: Initialization error screen service (code %d)\n", 1590 printk("GDT-HA %d: Initialization error screen service (code %d)\n",
@@ -1609,11 +1609,11 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1609 rtc[j] = CMOS_READ(j); 1609 rtc[j] = CMOS_READ(j);
1610 } while (rtc[0] != CMOS_READ(0)); 1610 } while (rtc[0] != CMOS_READ(0));
1611 spin_unlock_irqrestore(&rtc_lock, flags); 1611 spin_unlock_irqrestore(&rtc_lock, flags);
1612 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(ulong32 *)&rtc[0], 1612 TRACE2(("gdth_search_drives(): RTC: %x/%x/%x\n",*(u32 *)&rtc[0],
1613 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8])); 1613 *(u32 *)&rtc[4], *(u32 *)&rtc[8]));
1614 /* 3. send to controller firmware */ 1614 /* 3. send to controller firmware */
1615 gdth_internal_cmd(ha, SCREENSERVICE, GDT_REALTIME, *(ulong32 *)&rtc[0], 1615 gdth_internal_cmd(ha, SCREENSERVICE, GDT_REALTIME, *(u32 *)&rtc[0],
1616 *(ulong32 *)&rtc[4], *(ulong32 *)&rtc[8]); 1616 *(u32 *)&rtc[4], *(u32 *)&rtc[8]);
1617#endif 1617#endif
1618 1618
1619 /* unfreeze all IOs */ 1619 /* unfreeze all IOs */
@@ -1627,7 +1627,7 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1627 if (ok) 1627 if (ok)
1628 ha->cache_feat = GDT_64BIT; 1628 ha->cache_feat = GDT_64BIT;
1629 } 1629 }
1630 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC)) 1630 if (force_dma32 || (!ok && ha->status == (u16)S_NOFUNC))
1631 ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_INIT, LINUX_OS, 0, 0); 1631 ok = gdth_internal_cmd(ha, CACHESERVICE, GDT_INIT, LINUX_OS, 0, 0);
1632 if (!ok) { 1632 if (!ok) {
1633 printk("GDT-HA %d: Initialization error cache service (code %d)\n", 1633 printk("GDT-HA %d: Initialization error cache service (code %d)\n",
@@ -1635,7 +1635,7 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1635 return 0; 1635 return 0;
1636 } 1636 }
1637 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n")); 1637 TRACE2(("gdth_search_drives(): CACHESERVICE initialized\n"));
1638 cdev_cnt = (ushort)ha->info; 1638 cdev_cnt = (u16)ha->info;
1639 ha->fw_vers = ha->service; 1639 ha->fw_vers = ha->service;
1640 1640
1641#ifdef INT_COAL 1641#ifdef INT_COAL
@@ -1644,7 +1644,7 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1644 pmod = (gdth_perf_modes *)ha->pscratch; 1644 pmod = (gdth_perf_modes *)ha->pscratch;
1645 pmod->version = 1; 1645 pmod->version = 1;
1646 pmod->st_mode = 1; /* enable one status buffer */ 1646 pmod->st_mode = 1; /* enable one status buffer */
1647 *((ulong64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys; 1647 *((u64 *)&pmod->st_buff_addr1) = ha->coal_stat_phys;
1648 pmod->st_buff_indx1 = COALINDEX; 1648 pmod->st_buff_indx1 = COALINDEX;
1649 pmod->st_buff_addr2 = 0; 1649 pmod->st_buff_addr2 = 0;
1650 pmod->st_buff_u_addr2 = 0; 1650 pmod->st_buff_u_addr2 = 0;
@@ -1705,7 +1705,7 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1705 else 1705 else
1706 ha->bus_id[bus_no] = 0xff; 1706 ha->bus_id[bus_no] = 0xff;
1707 } 1707 }
1708 ha->bus_cnt = (unchar)bus_no; 1708 ha->bus_cnt = (u8)bus_no;
1709 } 1709 }
1710 TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt)); 1710 TRACE2(("gdth_search_drives() %d channels\n",ha->bus_cnt));
1711 1711
@@ -1789,12 +1789,12 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1789 1789
1790 /* logical drives */ 1790 /* logical drives */
1791 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_CNT, 1791 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_CNT,
1792 INVALID_CHANNEL,sizeof(ulong32))) { 1792 INVALID_CHANNEL,sizeof(u32))) {
1793 drv_cnt = *(ulong32 *)ha->pscratch; 1793 drv_cnt = *(u32 *)ha->pscratch;
1794 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_LIST, 1794 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_IOCTL, CACHE_DRV_LIST,
1795 INVALID_CHANNEL,drv_cnt * sizeof(ulong32))) { 1795 INVALID_CHANNEL,drv_cnt * sizeof(u32))) {
1796 for (j = 0; j < drv_cnt; ++j) { 1796 for (j = 0; j < drv_cnt; ++j) {
1797 drv_no = ((ulong32 *)ha->pscratch)[j]; 1797 drv_no = ((u32 *)ha->pscratch)[j];
1798 if (drv_no < MAX_LDRIVES) { 1798 if (drv_no < MAX_LDRIVES) {
1799 ha->hdr[drv_no].is_logdrv = TRUE; 1799 ha->hdr[drv_no].is_logdrv = TRUE;
1800 TRACE2(("Drive %d is log. drive\n",drv_no)); 1800 TRACE2(("Drive %d is log. drive\n",drv_no));
@@ -1838,7 +1838,7 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1838 if (ok) 1838 if (ok)
1839 ha->raw_feat = GDT_64BIT; 1839 ha->raw_feat = GDT_64BIT;
1840 } 1840 }
1841 if (force_dma32 || (!ok && ha->status == (ushort)S_NOFUNC)) 1841 if (force_dma32 || (!ok && ha->status == (u16)S_NOFUNC))
1842 ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_INIT, 0, 0, 0); 1842 ok = gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_INIT, 0, 0, 0);
1843 if (!ok) { 1843 if (!ok) {
1844 printk("GDT-HA %d: Initialization error raw service (code %d)\n", 1844 printk("GDT-HA %d: Initialization error raw service (code %d)\n",
@@ -1854,7 +1854,7 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1854 if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_GET_FEAT, 0, 0, 0)) { 1854 if (gdth_internal_cmd(ha, SCSIRAWSERVICE, GDT_GET_FEAT, 0, 0, 0)) {
1855 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n", 1855 TRACE2(("gdth_search_dr(): get feat RAWSERVICE %d\n",
1856 ha->info)); 1856 ha->info));
1857 ha->raw_feat |= (ushort)ha->info; 1857 ha->raw_feat |= (u16)ha->info;
1858 } 1858 }
1859 } 1859 }
1860 1860
@@ -1865,7 +1865,7 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1865 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_GET_FEAT, 0, 0, 0)) { 1865 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_GET_FEAT, 0, 0, 0)) {
1866 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n", 1866 TRACE2(("gdth_search_dr(): get feat CACHESERV. %d\n",
1867 ha->info)); 1867 ha->info));
1868 ha->cache_feat |= (ushort)ha->info; 1868 ha->cache_feat |= (u16)ha->info;
1869 } 1869 }
1870 } 1870 }
1871 1871
@@ -1923,9 +1923,9 @@ static int __devinit gdth_search_drives(gdth_ha_str *ha)
1923 return 1; 1923 return 1;
1924} 1924}
1925 1925
1926static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive) 1926static int gdth_analyse_hdrive(gdth_ha_str *ha, u16 hdrive)
1927{ 1927{
1928 ulong32 drv_cyls; 1928 u32 drv_cyls;
1929 int drv_hds, drv_secs; 1929 int drv_hds, drv_secs;
1930 1930
1931 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n", ha->hanum, hdrive)); 1931 TRACE(("gdth_analyse_hdrive() hanum %d drive %d\n", ha->hanum, hdrive));
@@ -1944,17 +1944,17 @@ static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive)
1944 } else { 1944 } else {
1945 drv_hds = ha->info2 & 0xff; 1945 drv_hds = ha->info2 & 0xff;
1946 drv_secs = (ha->info2 >> 8) & 0xff; 1946 drv_secs = (ha->info2 >> 8) & 0xff;
1947 drv_cyls = (ulong32)ha->hdr[hdrive].size / drv_hds / drv_secs; 1947 drv_cyls = (u32)ha->hdr[hdrive].size / drv_hds / drv_secs;
1948 } 1948 }
1949 ha->hdr[hdrive].heads = (unchar)drv_hds; 1949 ha->hdr[hdrive].heads = (u8)drv_hds;
1950 ha->hdr[hdrive].secs = (unchar)drv_secs; 1950 ha->hdr[hdrive].secs = (u8)drv_secs;
1951 /* round size */ 1951 /* round size */
1952 ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs; 1952 ha->hdr[hdrive].size = drv_cyls * drv_hds * drv_secs;
1953 1953
1954 if (ha->cache_feat & GDT_64BIT) { 1954 if (ha->cache_feat & GDT_64BIT) {
1955 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INFO, hdrive, 0, 0) 1955 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_X_INFO, hdrive, 0, 0)
1956 && ha->info2 != 0) { 1956 && ha->info2 != 0) {
1957 ha->hdr[hdrive].size = ((ulong64)ha->info2 << 32) | ha->info; 1957 ha->hdr[hdrive].size = ((u64)ha->info2 << 32) | ha->info;
1958 } 1958 }
1959 } 1959 }
1960 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n", 1960 TRACE2(("gdth_search_dr() cdr. %d size %d hds %d scs %d\n",
@@ -1964,7 +1964,7 @@ static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive)
1964 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_DEVTYPE, hdrive, 0, 0)) { 1964 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_DEVTYPE, hdrive, 0, 0)) {
1965 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n", 1965 TRACE2(("gdth_search_dr() cache drive %d devtype %d\n",
1966 hdrive,ha->info)); 1966 hdrive,ha->info));
1967 ha->hdr[hdrive].devtype = (ushort)ha->info; 1967 ha->hdr[hdrive].devtype = (u16)ha->info;
1968 } 1968 }
1969 1969
1970 /* cluster info */ 1970 /* cluster info */
@@ -1972,14 +1972,14 @@ static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive)
1972 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n", 1972 TRACE2(("gdth_search_dr() cache drive %d cluster info %d\n",
1973 hdrive,ha->info)); 1973 hdrive,ha->info));
1974 if (!shared_access) 1974 if (!shared_access)
1975 ha->hdr[hdrive].cluster_type = (unchar)ha->info; 1975 ha->hdr[hdrive].cluster_type = (u8)ha->info;
1976 } 1976 }
1977 1977
1978 /* R/W attributes */ 1978 /* R/W attributes */
1979 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_RW_ATTRIBS, hdrive, 0, 0)) { 1979 if (gdth_internal_cmd(ha, CACHESERVICE, GDT_RW_ATTRIBS, hdrive, 0, 0)) {
1980 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n", 1980 TRACE2(("gdth_search_dr() cache drive %d r/w attrib. %d\n",
1981 hdrive,ha->info)); 1981 hdrive,ha->info));
1982 ha->hdr[hdrive].rw_attribs = (unchar)ha->info; 1982 ha->hdr[hdrive].rw_attribs = (u8)ha->info;
1983 } 1983 }
1984 1984
1985 return 1; 1985 return 1;
@@ -1988,12 +1988,12 @@ static int gdth_analyse_hdrive(gdth_ha_str *ha, ushort hdrive)
1988 1988
1989/* command queueing/sending functions */ 1989/* command queueing/sending functions */
1990 1990
1991static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority) 1991static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, u8 priority)
1992{ 1992{
1993 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); 1993 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
1994 register Scsi_Cmnd *pscp; 1994 register Scsi_Cmnd *pscp;
1995 register Scsi_Cmnd *nscp; 1995 register Scsi_Cmnd *nscp;
1996 ulong flags; 1996 unsigned long flags;
1997 1997
1998 TRACE(("gdth_putq() priority %d\n",priority)); 1998 TRACE(("gdth_putq() priority %d\n",priority));
1999 spin_lock_irqsave(&ha->smp_lock, flags); 1999 spin_lock_irqsave(&ha->smp_lock, flags);
@@ -2023,7 +2023,7 @@ static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority)
2023 ++flags; 2023 ++flags;
2024 if (max_rq < flags) { 2024 if (max_rq < flags) {
2025 max_rq = flags; 2025 max_rq = flags;
2026 TRACE3(("GDT: max_rq = %d\n",(ushort)max_rq)); 2026 TRACE3(("GDT: max_rq = %d\n",(u16)max_rq));
2027 } 2027 }
2028#endif 2028#endif
2029} 2029}
@@ -2032,9 +2032,9 @@ static void gdth_next(gdth_ha_str *ha)
2032{ 2032{
2033 register Scsi_Cmnd *pscp; 2033 register Scsi_Cmnd *pscp;
2034 register Scsi_Cmnd *nscp; 2034 register Scsi_Cmnd *nscp;
2035 unchar b, t, l, firsttime; 2035 u8 b, t, l, firsttime;
2036 unchar this_cmd, next_cmd; 2036 u8 this_cmd, next_cmd;
2037 ulong flags = 0; 2037 unsigned long flags = 0;
2038 int cmd_index; 2038 int cmd_index;
2039 2039
2040 TRACE(("gdth_next() hanum %d\n", ha->hanum)); 2040 TRACE(("gdth_next() hanum %d\n", ha->hanum));
@@ -2282,20 +2282,20 @@ static void gdth_next(gdth_ha_str *ha)
2282 * buffers, kmap_atomic() as needed. 2282 * buffers, kmap_atomic() as needed.
2283 */ 2283 */
2284static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp, 2284static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
2285 char *buffer, ushort count) 2285 char *buffer, u16 count)
2286{ 2286{
2287 ushort cpcount,i, max_sg = scsi_sg_count(scp); 2287 u16 cpcount,i, max_sg = scsi_sg_count(scp);
2288 ushort cpsum,cpnow; 2288 u16 cpsum,cpnow;
2289 struct scatterlist *sl; 2289 struct scatterlist *sl;
2290 char *address; 2290 char *address;
2291 2291
2292 cpcount = min_t(ushort, count, scsi_bufflen(scp)); 2292 cpcount = min_t(u16, count, scsi_bufflen(scp));
2293 2293
2294 if (cpcount) { 2294 if (cpcount) {
2295 cpsum=0; 2295 cpsum=0;
2296 scsi_for_each_sg(scp, sl, max_sg, i) { 2296 scsi_for_each_sg(scp, sl, max_sg, i) {
2297 unsigned long flags; 2297 unsigned long flags;
2298 cpnow = (ushort)sl->length; 2298 cpnow = (u16)sl->length;
2299 TRACE(("copy_internal() now %d sum %d count %d %d\n", 2299 TRACE(("copy_internal() now %d sum %d count %d %d\n",
2300 cpnow, cpsum, cpcount, scsi_bufflen(scp))); 2300 cpnow, cpsum, cpcount, scsi_bufflen(scp)));
2301 if (cpsum+cpnow > cpcount) 2301 if (cpsum+cpnow > cpcount)
@@ -2325,7 +2325,7 @@ static void gdth_copy_internal_data(gdth_ha_str *ha, Scsi_Cmnd *scp,
2325 2325
2326static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp) 2326static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2327{ 2327{
2328 unchar t; 2328 u8 t;
2329 gdth_inq_data inq; 2329 gdth_inq_data inq;
2330 gdth_rdcap_data rdc; 2330 gdth_rdcap_data rdc;
2331 gdth_sense_data sd; 2331 gdth_sense_data sd;
@@ -2389,7 +2389,7 @@ static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2389 2389
2390 case READ_CAPACITY: 2390 case READ_CAPACITY:
2391 TRACE2(("Read capacity hdrive %d\n",t)); 2391 TRACE2(("Read capacity hdrive %d\n",t));
2392 if (ha->hdr[t].size > (ulong64)0xffffffff) 2392 if (ha->hdr[t].size > (u64)0xffffffff)
2393 rdc.last_block_no = 0xffffffff; 2393 rdc.last_block_no = 0xffffffff;
2394 else 2394 else
2395 rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1); 2395 rdc.last_block_no = cpu_to_be32(ha->hdr[t].size-1);
@@ -2425,12 +2425,12 @@ static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2425 return 0; 2425 return 0;
2426} 2426}
2427 2427
2428static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive) 2428static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, u16 hdrive)
2429{ 2429{
2430 register gdth_cmd_str *cmdp; 2430 register gdth_cmd_str *cmdp;
2431 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); 2431 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
2432 ulong32 cnt, blockcnt; 2432 u32 cnt, blockcnt;
2433 ulong64 no, blockno; 2433 u64 no, blockno;
2434 int i, cmd_index, read_write, sgcnt, mode64; 2434 int i, cmd_index, read_write, sgcnt, mode64;
2435 2435
2436 cmdp = ha->pccb; 2436 cmdp = ha->pccb;
@@ -2498,17 +2498,17 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
2498 2498
2499 if (read_write) { 2499 if (read_write) {
2500 if (scp->cmd_len == 16) { 2500 if (scp->cmd_len == 16) {
2501 memcpy(&no, &scp->cmnd[2], sizeof(ulong64)); 2501 memcpy(&no, &scp->cmnd[2], sizeof(u64));
2502 blockno = be64_to_cpu(no); 2502 blockno = be64_to_cpu(no);
2503 memcpy(&cnt, &scp->cmnd[10], sizeof(ulong32)); 2503 memcpy(&cnt, &scp->cmnd[10], sizeof(u32));
2504 blockcnt = be32_to_cpu(cnt); 2504 blockcnt = be32_to_cpu(cnt);
2505 } else if (scp->cmd_len == 10) { 2505 } else if (scp->cmd_len == 10) {
2506 memcpy(&no, &scp->cmnd[2], sizeof(ulong32)); 2506 memcpy(&no, &scp->cmnd[2], sizeof(u32));
2507 blockno = be32_to_cpu(no); 2507 blockno = be32_to_cpu(no);
2508 memcpy(&cnt, &scp->cmnd[7], sizeof(ushort)); 2508 memcpy(&cnt, &scp->cmnd[7], sizeof(u16));
2509 blockcnt = be16_to_cpu(cnt); 2509 blockcnt = be16_to_cpu(cnt);
2510 } else { 2510 } else {
2511 memcpy(&no, &scp->cmnd[0], sizeof(ulong32)); 2511 memcpy(&no, &scp->cmnd[0], sizeof(u32));
2512 blockno = be32_to_cpu(no) & 0x001fffffUL; 2512 blockno = be32_to_cpu(no) & 0x001fffffUL;
2513 blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4]; 2513 blockcnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
2514 } 2514 }
@@ -2516,7 +2516,7 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
2516 cmdp->u.cache64.BlockNo = blockno; 2516 cmdp->u.cache64.BlockNo = blockno;
2517 cmdp->u.cache64.BlockCnt = blockcnt; 2517 cmdp->u.cache64.BlockCnt = blockcnt;
2518 } else { 2518 } else {
2519 cmdp->u.cache.BlockNo = (ulong32)blockno; 2519 cmdp->u.cache.BlockNo = (u32)blockno;
2520 cmdp->u.cache.BlockCnt = blockcnt; 2520 cmdp->u.cache.BlockCnt = blockcnt;
2521 } 2521 }
2522 2522
@@ -2528,12 +2528,12 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
2528 if (mode64) { 2528 if (mode64) {
2529 struct scatterlist *sl; 2529 struct scatterlist *sl;
2530 2530
2531 cmdp->u.cache64.DestAddr= (ulong64)-1; 2531 cmdp->u.cache64.DestAddr= (u64)-1;
2532 cmdp->u.cache64.sg_canz = sgcnt; 2532 cmdp->u.cache64.sg_canz = sgcnt;
2533 scsi_for_each_sg(scp, sl, sgcnt, i) { 2533 scsi_for_each_sg(scp, sl, sgcnt, i) {
2534 cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl); 2534 cmdp->u.cache64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2535#ifdef GDTH_DMA_STATISTICS 2535#ifdef GDTH_DMA_STATISTICS
2536 if (cmdp->u.cache64.sg_lst[i].sg_ptr > (ulong64)0xffffffff) 2536 if (cmdp->u.cache64.sg_lst[i].sg_ptr > (u64)0xffffffff)
2537 ha->dma64_cnt++; 2537 ha->dma64_cnt++;
2538 else 2538 else
2539 ha->dma32_cnt++; 2539 ha->dma32_cnt++;
@@ -2555,8 +2555,8 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
2555 } 2555 }
2556 2556
2557#ifdef GDTH_STATISTICS 2557#ifdef GDTH_STATISTICS
2558 if (max_sg < (ulong32)sgcnt) { 2558 if (max_sg < (u32)sgcnt) {
2559 max_sg = (ulong32)sgcnt; 2559 max_sg = (u32)sgcnt;
2560 TRACE3(("GDT: max_sg = %d\n",max_sg)); 2560 TRACE3(("GDT: max_sg = %d\n",max_sg));
2561 } 2561 }
2562#endif 2562#endif
@@ -2572,7 +2572,7 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
2572 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n", 2572 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2573 cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt)); 2573 cmdp->OpCode,cmdp->u.cache64.BlockNo,cmdp->u.cache64.BlockCnt));
2574 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) + 2574 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache64.sg_lst) +
2575 (ushort)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str); 2575 (u16)cmdp->u.cache64.sg_canz * sizeof(gdth_sg64_str);
2576 } else { 2576 } else {
2577 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", 2577 TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2578 cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz, 2578 cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
@@ -2581,7 +2581,7 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
2581 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n", 2581 TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %d\n",
2582 cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt)); 2582 cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
2583 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + 2583 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
2584 (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str); 2584 (u16)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
2585 } 2585 }
2586 if (ha->cmd_len & 3) 2586 if (ha->cmd_len & 3)
2587 ha->cmd_len += (4 - (ha->cmd_len & 3)); 2587 ha->cmd_len += (4 - (ha->cmd_len & 3));
@@ -2600,15 +2600,15 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, ushort hdrive)
2600 return cmd_index; 2600 return cmd_index;
2601} 2601}
2602 2602
2603static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b) 2603static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, u8 b)
2604{ 2604{
2605 register gdth_cmd_str *cmdp; 2605 register gdth_cmd_str *cmdp;
2606 ushort i; 2606 u16 i;
2607 dma_addr_t sense_paddr; 2607 dma_addr_t sense_paddr;
2608 int cmd_index, sgcnt, mode64; 2608 int cmd_index, sgcnt, mode64;
2609 unchar t,l; 2609 u8 t,l;
2610 struct page *page; 2610 struct page *page;
2611 ulong offset; 2611 unsigned long offset;
2612 struct gdth_cmndinfo *cmndinfo; 2612 struct gdth_cmndinfo *cmndinfo;
2613 2613
2614 t = scp->device->id; 2614 t = scp->device->id;
@@ -2654,7 +2654,7 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
2654 2654
2655 } else { 2655 } else {
2656 page = virt_to_page(scp->sense_buffer); 2656 page = virt_to_page(scp->sense_buffer);
2657 offset = (ulong)scp->sense_buffer & ~PAGE_MASK; 2657 offset = (unsigned long)scp->sense_buffer & ~PAGE_MASK;
2658 sense_paddr = pci_map_page(ha->pdev,page,offset, 2658 sense_paddr = pci_map_page(ha->pdev,page,offset,
2659 16,PCI_DMA_FROMDEVICE); 2659 16,PCI_DMA_FROMDEVICE);
2660 2660
@@ -2703,12 +2703,12 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
2703 if (mode64) { 2703 if (mode64) {
2704 struct scatterlist *sl; 2704 struct scatterlist *sl;
2705 2705
2706 cmdp->u.raw64.sdata = (ulong64)-1; 2706 cmdp->u.raw64.sdata = (u64)-1;
2707 cmdp->u.raw64.sg_ranz = sgcnt; 2707 cmdp->u.raw64.sg_ranz = sgcnt;
2708 scsi_for_each_sg(scp, sl, sgcnt, i) { 2708 scsi_for_each_sg(scp, sl, sgcnt, i) {
2709 cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl); 2709 cmdp->u.raw64.sg_lst[i].sg_ptr = sg_dma_address(sl);
2710#ifdef GDTH_DMA_STATISTICS 2710#ifdef GDTH_DMA_STATISTICS
2711 if (cmdp->u.raw64.sg_lst[i].sg_ptr > (ulong64)0xffffffff) 2711 if (cmdp->u.raw64.sg_lst[i].sg_ptr > (u64)0xffffffff)
2712 ha->dma64_cnt++; 2712 ha->dma64_cnt++;
2713 else 2713 else
2714 ha->dma32_cnt++; 2714 ha->dma32_cnt++;
@@ -2744,7 +2744,7 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
2744 cmdp->u.raw64.sg_lst[0].sg_len)); 2744 cmdp->u.raw64.sg_lst[0].sg_len));
2745 /* evaluate command size */ 2745 /* evaluate command size */
2746 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) + 2746 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw64.sg_lst) +
2747 (ushort)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str); 2747 (u16)cmdp->u.raw64.sg_ranz * sizeof(gdth_sg64_str);
2748 } else { 2748 } else {
2749 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n", 2749 TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %x\n",
2750 cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz, 2750 cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
@@ -2752,7 +2752,7 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar b)
2752 cmdp->u.raw.sg_lst[0].sg_len)); 2752 cmdp->u.raw.sg_lst[0].sg_len));
2753 /* evaluate command size */ 2753 /* evaluate command size */
2754 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + 2754 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
2755 (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str); 2755 (u16)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
2756 } 2756 }
2757 } 2757 }
2758 /* check space */ 2758 /* check space */
@@ -2802,7 +2802,7 @@ static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2802 if (cmdp->OpCode == GDT_IOCTL) { 2802 if (cmdp->OpCode == GDT_IOCTL) {
2803 TRACE2(("IOCTL\n")); 2803 TRACE2(("IOCTL\n"));
2804 ha->cmd_len = 2804 ha->cmd_len =
2805 GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong64); 2805 GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(u64);
2806 } else if (cmdp->Service == CACHESERVICE) { 2806 } else if (cmdp->Service == CACHESERVICE) {
2807 TRACE2(("cache command %d\n",cmdp->OpCode)); 2807 TRACE2(("cache command %d\n",cmdp->OpCode));
2808 if (ha->cache_feat & GDT_64BIT) 2808 if (ha->cache_feat & GDT_64BIT)
@@ -2840,8 +2840,8 @@ static int gdth_special_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2840 2840
2841 2841
2842/* Controller event handling functions */ 2842/* Controller event handling functions */
2843static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source, 2843static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, u16 source,
2844 ushort idx, gdth_evt_data *evt) 2844 u16 idx, gdth_evt_data *evt)
2845{ 2845{
2846 gdth_evt_str *e; 2846 gdth_evt_str *e;
2847 struct timeval tv; 2847 struct timeval tv;
@@ -2890,7 +2890,7 @@ static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
2890{ 2890{
2891 gdth_evt_str *e; 2891 gdth_evt_str *e;
2892 int eindex; 2892 int eindex;
2893 ulong flags; 2893 unsigned long flags;
2894 2894
2895 TRACE2(("gdth_read_event() handle %d\n", handle)); 2895 TRACE2(("gdth_read_event() handle %d\n", handle));
2896 spin_lock_irqsave(&ha->smp_lock, flags); 2896 spin_lock_irqsave(&ha->smp_lock, flags);
@@ -2919,12 +2919,12 @@ static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
2919} 2919}
2920 2920
2921static void gdth_readapp_event(gdth_ha_str *ha, 2921static void gdth_readapp_event(gdth_ha_str *ha,
2922 unchar application, gdth_evt_str *estr) 2922 u8 application, gdth_evt_str *estr)
2923{ 2923{
2924 gdth_evt_str *e; 2924 gdth_evt_str *e;
2925 int eindex; 2925 int eindex;
2926 ulong flags; 2926 unsigned long flags;
2927 unchar found = FALSE; 2927 u8 found = FALSE;
2928 2928
2929 TRACE2(("gdth_readapp_event() app. %d\n", application)); 2929 TRACE2(("gdth_readapp_event() app. %d\n", application));
2930 spin_lock_irqsave(&ha->smp_lock, flags); 2930 spin_lock_irqsave(&ha->smp_lock, flags);
@@ -2969,9 +2969,9 @@ static irqreturn_t __gdth_interrupt(gdth_ha_str *ha,
2969 gdt2_dpram_str __iomem *dp2_ptr; 2969 gdt2_dpram_str __iomem *dp2_ptr;
2970 Scsi_Cmnd *scp; 2970 Scsi_Cmnd *scp;
2971 int rval, i; 2971 int rval, i;
2972 unchar IStatus; 2972 u8 IStatus;
2973 ushort Service; 2973 u16 Service;
2974 ulong flags = 0; 2974 unsigned long flags = 0;
2975#ifdef INT_COAL 2975#ifdef INT_COAL
2976 int coalesced = FALSE; 2976 int coalesced = FALSE;
2977 int next = FALSE; 2977 int next = FALSE;
@@ -3018,7 +3018,7 @@ static irqreturn_t __gdth_interrupt(gdth_ha_str *ha,
3018 if (coalesced) { 3018 if (coalesced) {
3019 /* For coalesced requests all status 3019 /* For coalesced requests all status
3020 information is found in the status buffer */ 3020 information is found in the status buffer */
3021 IStatus = (unchar)(pcs->status & 0xff); 3021 IStatus = (u8)(pcs->status & 0xff);
3022 } 3022 }
3023#endif 3023#endif
3024 3024
@@ -3197,7 +3197,7 @@ static irqreturn_t __gdth_interrupt(gdth_ha_str *ha,
3197 ++act_int_coal; 3197 ++act_int_coal;
3198 if (act_int_coal > max_int_coal) { 3198 if (act_int_coal > max_int_coal) {
3199 max_int_coal = act_int_coal; 3199 max_int_coal = act_int_coal;
3200 printk("GDT: max_int_coal = %d\n",(ushort)max_int_coal); 3200 printk("GDT: max_int_coal = %d\n",(u16)max_int_coal);
3201 } 3201 }
3202#endif 3202#endif
3203 /* see if there is another status */ 3203 /* see if there is another status */
@@ -3225,12 +3225,12 @@ static irqreturn_t gdth_interrupt(int irq, void *dev_id)
3225 return __gdth_interrupt(ha, false, NULL); 3225 return __gdth_interrupt(ha, false, NULL);
3226} 3226}
3227 3227
3228static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index, 3228static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
3229 Scsi_Cmnd *scp) 3229 Scsi_Cmnd *scp)
3230{ 3230{
3231 gdth_msg_str *msg; 3231 gdth_msg_str *msg;
3232 gdth_cmd_str *cmdp; 3232 gdth_cmd_str *cmdp;
3233 unchar b, t; 3233 u8 b, t;
3234 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); 3234 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
3235 3235
3236 cmdp = ha->pccb; 3236 cmdp = ha->pccb;
@@ -3263,7 +3263,7 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index,
3263 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; 3263 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3264 ha->cmd_offs_dpmem = 0; 3264 ha->cmd_offs_dpmem = 0;
3265 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) 3265 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3266 + sizeof(ulong64); 3266 + sizeof(u64);
3267 ha->cmd_cnt = 0; 3267 ha->cmd_cnt = 0;
3268 gdth_copy_command(ha); 3268 gdth_copy_command(ha);
3269 gdth_release_event(ha); 3269 gdth_release_event(ha);
@@ -3297,7 +3297,7 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index,
3297 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; 3297 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3298 ha->cmd_offs_dpmem = 0; 3298 ha->cmd_offs_dpmem = 0;
3299 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) 3299 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3300 + sizeof(ulong64); 3300 + sizeof(u64);
3301 ha->cmd_cnt = 0; 3301 ha->cmd_cnt = 0;
3302 gdth_copy_command(ha); 3302 gdth_copy_command(ha);
3303 gdth_release_event(ha); 3303 gdth_release_event(ha);
@@ -3335,7 +3335,7 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index,
3335 cmndinfo->OpCode)); 3335 cmndinfo->OpCode));
3336 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */ 3336 /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
3337 if (cmndinfo->OpCode == GDT_CLUST_INFO) { 3337 if (cmndinfo->OpCode == GDT_CLUST_INFO) {
3338 ha->hdr[t].cluster_type = (unchar)ha->info; 3338 ha->hdr[t].cluster_type = (u8)ha->info;
3339 if (!(ha->hdr[t].cluster_type & 3339 if (!(ha->hdr[t].cluster_type &
3340 CLUSTER_MOUNTED)) { 3340 CLUSTER_MOUNTED)) {
3341 /* NOT MOUNTED -> MOUNT */ 3341 /* NOT MOUNTED -> MOUNT */
@@ -3397,7 +3397,7 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, unchar index,
3397 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED; 3397 ha->hdr[t].cluster_type &= ~CLUSTER_RESERVED;
3398 } 3398 }
3399 memset((char*)scp->sense_buffer,0,16); 3399 memset((char*)scp->sense_buffer,0,16);
3400 if (ha->status == (ushort)S_CACHE_RESERV) { 3400 if (ha->status == (u16)S_CACHE_RESERV) {
3401 scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1); 3401 scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
3402 } else { 3402 } else {
3403 scp->sense_buffer[0] = 0x70; 3403 scp->sense_buffer[0] = 0x70;
@@ -3614,16 +3614,16 @@ static int gdth_async_event(gdth_ha_str *ha)
3614 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys; 3614 cmdp->u.screen.su.msg.msg_addr = ha->msg_phys;
3615 ha->cmd_offs_dpmem = 0; 3615 ha->cmd_offs_dpmem = 0;
3616 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr) 3616 ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
3617 + sizeof(ulong64); 3617 + sizeof(u64);
3618 ha->cmd_cnt = 0; 3618 ha->cmd_cnt = 0;
3619 gdth_copy_command(ha); 3619 gdth_copy_command(ha);
3620 if (ha->type == GDT_EISA) 3620 if (ha->type == GDT_EISA)
3621 printk("[EISA slot %d] ",(ushort)ha->brd_phys); 3621 printk("[EISA slot %d] ",(u16)ha->brd_phys);
3622 else if (ha->type == GDT_ISA) 3622 else if (ha->type == GDT_ISA)
3623 printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys); 3623 printk("[DPMEM 0x%4X] ",(u16)ha->brd_phys);
3624 else 3624 else
3625 printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8), 3625 printk("[PCI %d/%d] ",(u16)(ha->brd_phys>>8),
3626 (ushort)((ha->brd_phys>>3)&0x1f)); 3626 (u16)((ha->brd_phys>>3)&0x1f));
3627 gdth_release_event(ha); 3627 gdth_release_event(ha);
3628 } 3628 }
3629 3629
@@ -3640,7 +3640,7 @@ static int gdth_async_event(gdth_ha_str *ha)
3640 ha->dvr.eu.async.service = ha->service; 3640 ha->dvr.eu.async.service = ha->service;
3641 ha->dvr.eu.async.status = ha->status; 3641 ha->dvr.eu.async.status = ha->status;
3642 ha->dvr.eu.async.info = ha->info; 3642 ha->dvr.eu.async.info = ha->info;
3643 *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2; 3643 *(u32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
3644 } 3644 }
3645 gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr ); 3645 gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
3646 gdth_log_event( &ha->dvr, NULL ); 3646 gdth_log_event( &ha->dvr, NULL );
@@ -3648,8 +3648,8 @@ static int gdth_async_event(gdth_ha_str *ha)
3648 /* new host drive from expand? */ 3648 /* new host drive from expand? */
3649 if (ha->service == CACHESERVICE && ha->status == 56) { 3649 if (ha->service == CACHESERVICE && ha->status == 56) {
3650 TRACE2(("gdth_async_event(): new host drive %d created\n", 3650 TRACE2(("gdth_async_event(): new host drive %d created\n",
3651 (ushort)ha->info)); 3651 (u16)ha->info));
3652 /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */ 3652 /* gdth_analyse_hdrive(hanum, (u16)ha->info); */
3653 } 3653 }
3654 } 3654 }
3655 return 1; 3655 return 1;
@@ -3680,13 +3680,13 @@ static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
3680 for (j=0,i=1; i < f[0]; i+=2) { 3680 for (j=0,i=1; i < f[0]; i+=2) {
3681 switch (f[i+1]) { 3681 switch (f[i+1]) {
3682 case 4: 3682 case 4:
3683 stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]]; 3683 stack.b[j++] = *(u32*)&dvr->eu.stream[(int)f[i]];
3684 break; 3684 break;
3685 case 2: 3685 case 2:
3686 stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]]; 3686 stack.b[j++] = *(u16*)&dvr->eu.stream[(int)f[i]];
3687 break; 3687 break;
3688 case 1: 3688 case 1:
3689 stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]]; 3689 stack.b[j++] = *(u8*)&dvr->eu.stream[(int)f[i]];
3690 break; 3690 break;
3691 default: 3691 default:
3692 break; 3692 break;
@@ -3712,14 +3712,14 @@ static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
3712} 3712}
3713 3713
3714#ifdef GDTH_STATISTICS 3714#ifdef GDTH_STATISTICS
3715static unchar gdth_timer_running; 3715static u8 gdth_timer_running;
3716 3716
3717static void gdth_timeout(ulong data) 3717static void gdth_timeout(unsigned long data)
3718{ 3718{
3719 ulong32 i; 3719 u32 i;
3720 Scsi_Cmnd *nscp; 3720 Scsi_Cmnd *nscp;
3721 gdth_ha_str *ha; 3721 gdth_ha_str *ha;
3722 ulong flags; 3722 unsigned long flags;
3723 3723
3724 if(unlikely(list_empty(&gdth_instances))) { 3724 if(unlikely(list_empty(&gdth_instances))) {
3725 gdth_timer_running = 0; 3725 gdth_timer_running = 0;
@@ -3891,8 +3891,8 @@ static enum blk_eh_timer_return gdth_timed_out(struct scsi_cmnd *scp)
3891{ 3891{
3892 gdth_ha_str *ha = shost_priv(scp->device->host); 3892 gdth_ha_str *ha = shost_priv(scp->device->host);
3893 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp); 3893 struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
3894 unchar b, t; 3894 u8 b, t;
3895 ulong flags; 3895 unsigned long flags;
3896 enum blk_eh_timer_return retval = BLK_EH_NOT_HANDLED; 3896 enum blk_eh_timer_return retval = BLK_EH_NOT_HANDLED;
3897 3897
3898 TRACE(("%s() cmd 0x%x\n", scp->cmnd[0], __func__)); 3898 TRACE(("%s() cmd 0x%x\n", scp->cmnd[0], __func__));
@@ -3924,9 +3924,9 @@ static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
3924{ 3924{
3925 gdth_ha_str *ha = shost_priv(scp->device->host); 3925 gdth_ha_str *ha = shost_priv(scp->device->host);
3926 int i; 3926 int i;
3927 ulong flags; 3927 unsigned long flags;
3928 Scsi_Cmnd *cmnd; 3928 Scsi_Cmnd *cmnd;
3929 unchar b; 3929 u8 b;
3930 3930
3931 TRACE2(("gdth_eh_bus_reset()\n")); 3931 TRACE2(("gdth_eh_bus_reset()\n"));
3932 3932
@@ -3974,7 +3974,7 @@ static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
3974 3974
3975static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip) 3975static int gdth_bios_param(struct scsi_device *sdev,struct block_device *bdev,sector_t cap,int *ip)
3976{ 3976{
3977 unchar b, t; 3977 u8 b, t;
3978 gdth_ha_str *ha = shost_priv(sdev->host); 3978 gdth_ha_str *ha = shost_priv(sdev->host);
3979 struct scsi_device *sd; 3979 struct scsi_device *sd;
3980 unsigned capacity; 3980 unsigned capacity;
@@ -4062,7 +4062,7 @@ static int ioc_event(void __user *arg)
4062{ 4062{
4063 gdth_ioctl_event evt; 4063 gdth_ioctl_event evt;
4064 gdth_ha_str *ha; 4064 gdth_ha_str *ha;
4065 ulong flags; 4065 unsigned long flags;
4066 4066
4067 if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event))) 4067 if (copy_from_user(&evt, arg, sizeof(gdth_ioctl_event)))
4068 return -EFAULT; 4068 return -EFAULT;
@@ -4098,8 +4098,8 @@ static int ioc_event(void __user *arg)
4098static int ioc_lockdrv(void __user *arg) 4098static int ioc_lockdrv(void __user *arg)
4099{ 4099{
4100 gdth_ioctl_lockdrv ldrv; 4100 gdth_ioctl_lockdrv ldrv;
4101 unchar i, j; 4101 u8 i, j;
4102 ulong flags; 4102 unsigned long flags;
4103 gdth_ha_str *ha; 4103 gdth_ha_str *ha;
4104 4104
4105 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv))) 4105 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
@@ -4165,7 +4165,7 @@ static int ioc_general(void __user *arg, char *cmnd)
4165{ 4165{
4166 gdth_ioctl_general gen; 4166 gdth_ioctl_general gen;
4167 char *buf = NULL; 4167 char *buf = NULL;
4168 ulong64 paddr; 4168 u64 paddr;
4169 gdth_ha_str *ha; 4169 gdth_ha_str *ha;
4170 int rval; 4170 int rval;
4171 4171
@@ -4194,7 +4194,7 @@ static int ioc_general(void __user *arg, char *cmnd)
4194 gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo; 4194 gen.command.u.cache64.DeviceNo = gen.command.u.cache.DeviceNo;
4195 /* addresses */ 4195 /* addresses */
4196 if (ha->cache_feat & SCATTER_GATHER) { 4196 if (ha->cache_feat & SCATTER_GATHER) {
4197 gen.command.u.cache64.DestAddr = (ulong64)-1; 4197 gen.command.u.cache64.DestAddr = (u64)-1;
4198 gen.command.u.cache64.sg_canz = 1; 4198 gen.command.u.cache64.sg_canz = 1;
4199 gen.command.u.cache64.sg_lst[0].sg_ptr = paddr; 4199 gen.command.u.cache64.sg_lst[0].sg_ptr = paddr;
4200 gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len; 4200 gen.command.u.cache64.sg_lst[0].sg_len = gen.data_len;
@@ -4207,7 +4207,7 @@ static int ioc_general(void __user *arg, char *cmnd)
4207 if (ha->cache_feat & SCATTER_GATHER) { 4207 if (ha->cache_feat & SCATTER_GATHER) {
4208 gen.command.u.cache.DestAddr = 0xffffffff; 4208 gen.command.u.cache.DestAddr = 0xffffffff;
4209 gen.command.u.cache.sg_canz = 1; 4209 gen.command.u.cache.sg_canz = 1;
4210 gen.command.u.cache.sg_lst[0].sg_ptr = (ulong32)paddr; 4210 gen.command.u.cache.sg_lst[0].sg_ptr = (u32)paddr;
4211 gen.command.u.cache.sg_lst[0].sg_len = gen.data_len; 4211 gen.command.u.cache.sg_lst[0].sg_len = gen.data_len;
4212 gen.command.u.cache.sg_lst[1].sg_len = 0; 4212 gen.command.u.cache.sg_lst[1].sg_len = 0;
4213 } else { 4213 } else {
@@ -4230,7 +4230,7 @@ static int ioc_general(void __user *arg, char *cmnd)
4230 gen.command.u.raw64.direction = gen.command.u.raw.direction; 4230 gen.command.u.raw64.direction = gen.command.u.raw.direction;
4231 /* addresses */ 4231 /* addresses */
4232 if (ha->raw_feat & SCATTER_GATHER) { 4232 if (ha->raw_feat & SCATTER_GATHER) {
4233 gen.command.u.raw64.sdata = (ulong64)-1; 4233 gen.command.u.raw64.sdata = (u64)-1;
4234 gen.command.u.raw64.sg_ranz = 1; 4234 gen.command.u.raw64.sg_ranz = 1;
4235 gen.command.u.raw64.sg_lst[0].sg_ptr = paddr; 4235 gen.command.u.raw64.sg_lst[0].sg_ptr = paddr;
4236 gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len; 4236 gen.command.u.raw64.sg_lst[0].sg_len = gen.data_len;
@@ -4244,14 +4244,14 @@ static int ioc_general(void __user *arg, char *cmnd)
4244 if (ha->raw_feat & SCATTER_GATHER) { 4244 if (ha->raw_feat & SCATTER_GATHER) {
4245 gen.command.u.raw.sdata = 0xffffffff; 4245 gen.command.u.raw.sdata = 0xffffffff;
4246 gen.command.u.raw.sg_ranz = 1; 4246 gen.command.u.raw.sg_ranz = 1;
4247 gen.command.u.raw.sg_lst[0].sg_ptr = (ulong32)paddr; 4247 gen.command.u.raw.sg_lst[0].sg_ptr = (u32)paddr;
4248 gen.command.u.raw.sg_lst[0].sg_len = gen.data_len; 4248 gen.command.u.raw.sg_lst[0].sg_len = gen.data_len;
4249 gen.command.u.raw.sg_lst[1].sg_len = 0; 4249 gen.command.u.raw.sg_lst[1].sg_len = 0;
4250 } else { 4250 } else {
4251 gen.command.u.raw.sdata = paddr; 4251 gen.command.u.raw.sdata = paddr;
4252 gen.command.u.raw.sg_ranz = 0; 4252 gen.command.u.raw.sg_ranz = 0;
4253 } 4253 }
4254 gen.command.u.raw.sense_data = (ulong32)paddr + gen.data_len; 4254 gen.command.u.raw.sense_data = (u32)paddr + gen.data_len;
4255 } 4255 }
4256 } else { 4256 } else {
4257 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr); 4257 gdth_ioctl_free(ha, gen.data_len+gen.sense_len, buf, paddr);
@@ -4283,7 +4283,7 @@ static int ioc_hdrlist(void __user *arg, char *cmnd)
4283 gdth_ioctl_rescan *rsc; 4283 gdth_ioctl_rescan *rsc;
4284 gdth_cmd_str *cmd; 4284 gdth_cmd_str *cmd;
4285 gdth_ha_str *ha; 4285 gdth_ha_str *ha;
4286 unchar i; 4286 u8 i;
4287 int rc = -ENOMEM; 4287 int rc = -ENOMEM;
4288 u32 cluster_type = 0; 4288 u32 cluster_type = 0;
4289 4289
@@ -4335,11 +4335,11 @@ static int ioc_rescan(void __user *arg, char *cmnd)
4335{ 4335{
4336 gdth_ioctl_rescan *rsc; 4336 gdth_ioctl_rescan *rsc;
4337 gdth_cmd_str *cmd; 4337 gdth_cmd_str *cmd;
4338 ushort i, status, hdr_cnt; 4338 u16 i, status, hdr_cnt;
4339 ulong32 info; 4339 u32 info;
4340 int cyls, hds, secs; 4340 int cyls, hds, secs;
4341 int rc = -ENOMEM; 4341 int rc = -ENOMEM;
4342 ulong flags; 4342 unsigned long flags;
4343 gdth_ha_str *ha; 4343 gdth_ha_str *ha;
4344 4344
4345 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL); 4345 rsc = kmalloc(sizeof(*rsc), GFP_KERNEL);
@@ -4367,7 +4367,7 @@ static int ioc_rescan(void __user *arg, char *cmnd)
4367 4367
4368 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); 4368 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4369 i = 0; 4369 i = 0;
4370 hdr_cnt = (status == S_OK ? (ushort)info : 0); 4370 hdr_cnt = (status == S_OK ? (u16)info : 0);
4371 } else { 4371 } else {
4372 i = rsc->hdr_no; 4372 i = rsc->hdr_no;
4373 hdr_cnt = i + 1; 4373 hdr_cnt = i + 1;
@@ -4418,7 +4418,7 @@ static int ioc_rescan(void __user *arg, char *cmnd)
4418 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); 4418 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4419 4419
4420 spin_lock_irqsave(&ha->smp_lock, flags); 4420 spin_lock_irqsave(&ha->smp_lock, flags);
4421 ha->hdr[i].devtype = (status == S_OK ? (ushort)info : 0); 4421 ha->hdr[i].devtype = (status == S_OK ? (u16)info : 0);
4422 spin_unlock_irqrestore(&ha->smp_lock, flags); 4422 spin_unlock_irqrestore(&ha->smp_lock, flags);
4423 4423
4424 cmd->Service = CACHESERVICE; 4424 cmd->Service = CACHESERVICE;
@@ -4432,7 +4432,7 @@ static int ioc_rescan(void __user *arg, char *cmnd)
4432 4432
4433 spin_lock_irqsave(&ha->smp_lock, flags); 4433 spin_lock_irqsave(&ha->smp_lock, flags);
4434 ha->hdr[i].cluster_type = 4434 ha->hdr[i].cluster_type =
4435 ((status == S_OK && !shared_access) ? (ushort)info : 0); 4435 ((status == S_OK && !shared_access) ? (u16)info : 0);
4436 spin_unlock_irqrestore(&ha->smp_lock, flags); 4436 spin_unlock_irqrestore(&ha->smp_lock, flags);
4437 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type; 4437 rsc->hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
4438 4438
@@ -4446,7 +4446,7 @@ static int ioc_rescan(void __user *arg, char *cmnd)
4446 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info); 4446 status = __gdth_execute(ha->sdev, cmd, cmnd, 30, &info);
4447 4447
4448 spin_lock_irqsave(&ha->smp_lock, flags); 4448 spin_lock_irqsave(&ha->smp_lock, flags);
4449 ha->hdr[i].rw_attribs = (status == S_OK ? (ushort)info : 0); 4449 ha->hdr[i].rw_attribs = (status == S_OK ? (u16)info : 0);
4450 spin_unlock_irqrestore(&ha->smp_lock, flags); 4450 spin_unlock_irqrestore(&ha->smp_lock, flags);
4451 } 4451 }
4452 4452
@@ -4466,7 +4466,7 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
4466{ 4466{
4467 gdth_ha_str *ha; 4467 gdth_ha_str *ha;
4468 Scsi_Cmnd *scp; 4468 Scsi_Cmnd *scp;
4469 ulong flags; 4469 unsigned long flags;
4470 char cmnd[MAX_COMMAND_SIZE]; 4470 char cmnd[MAX_COMMAND_SIZE];
4471 void __user *argp = (void __user *)arg; 4471 void __user *argp = (void __user *)arg;
4472 4472
@@ -4495,9 +4495,9 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
4495 { 4495 {
4496 gdth_ioctl_osvers osv; 4496 gdth_ioctl_osvers osv;
4497 4497
4498 osv.version = (unchar)(LINUX_VERSION_CODE >> 16); 4498 osv.version = (u8)(LINUX_VERSION_CODE >> 16);
4499 osv.subversion = (unchar)(LINUX_VERSION_CODE >> 8); 4499 osv.subversion = (u8)(LINUX_VERSION_CODE >> 8);
4500 osv.revision = (ushort)(LINUX_VERSION_CODE & 0xff); 4500 osv.revision = (u16)(LINUX_VERSION_CODE & 0xff);
4501 if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers))) 4501 if (copy_to_user(argp, &osv, sizeof(gdth_ioctl_osvers)))
4502 return -EFAULT; 4502 return -EFAULT;
4503 break; 4503 break;
@@ -4512,10 +4512,10 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
4512 return -EFAULT; 4512 return -EFAULT;
4513 4513
4514 if (ha->type == GDT_ISA || ha->type == GDT_EISA) { 4514 if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
4515 ctrt.type = (unchar)((ha->stype>>20) - 0x10); 4515 ctrt.type = (u8)((ha->stype>>20) - 0x10);
4516 } else { 4516 } else {
4517 if (ha->type != GDT_PCIMPR) { 4517 if (ha->type != GDT_PCIMPR) {
4518 ctrt.type = (unchar)((ha->stype<<4) + 6); 4518 ctrt.type = (u8)((ha->stype<<4) + 6);
4519 } else { 4519 } else {
4520 ctrt.type = 4520 ctrt.type =
4521 (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe); 4521 (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe);
@@ -4546,7 +4546,7 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
4546 case GDTIOCTL_LOCKCHN: 4546 case GDTIOCTL_LOCKCHN:
4547 { 4547 {
4548 gdth_ioctl_lockchn lchn; 4548 gdth_ioctl_lockchn lchn;
4549 unchar i, j; 4549 u8 i, j;
4550 4550
4551 if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) || 4551 if (copy_from_user(&lchn, argp, sizeof(gdth_ioctl_lockchn)) ||
4552 (NULL == (ha = gdth_find_ha(lchn.ionode)))) 4552 (NULL == (ha = gdth_find_ha(lchn.ionode))))
@@ -4670,7 +4670,7 @@ static struct scsi_host_template gdth_template = {
4670}; 4670};
4671 4671
4672#ifdef CONFIG_ISA 4672#ifdef CONFIG_ISA
4673static int __init gdth_isa_probe_one(ulong32 isa_bios) 4673static int __init gdth_isa_probe_one(u32 isa_bios)
4674{ 4674{
4675 struct Scsi_Host *shp; 4675 struct Scsi_Host *shp;
4676 gdth_ha_str *ha; 4676 gdth_ha_str *ha;
@@ -4802,7 +4802,7 @@ static int __init gdth_isa_probe_one(ulong32 isa_bios)
4802#endif /* CONFIG_ISA */ 4802#endif /* CONFIG_ISA */
4803 4803
4804#ifdef CONFIG_EISA 4804#ifdef CONFIG_EISA
4805static int __init gdth_eisa_probe_one(ushort eisa_slot) 4805static int __init gdth_eisa_probe_one(u16 eisa_slot)
4806{ 4806{
4807 struct Scsi_Host *shp; 4807 struct Scsi_Host *shp;
4808 gdth_ha_str *ha; 4808 gdth_ha_str *ha;
@@ -5120,7 +5120,7 @@ static void gdth_remove_one(gdth_ha_str *ha)
5120 scsi_host_put(shp); 5120 scsi_host_put(shp);
5121} 5121}
5122 5122
5123static int gdth_halt(struct notifier_block *nb, ulong event, void *buf) 5123static int gdth_halt(struct notifier_block *nb, unsigned long event, void *buf)
5124{ 5124{
5125 gdth_ha_str *ha; 5125 gdth_ha_str *ha;
5126 5126
@@ -5158,14 +5158,14 @@ static int __init gdth_init(void)
5158 if (probe_eisa_isa) { 5158 if (probe_eisa_isa) {
5159 /* scanning for controllers, at first: ISA controller */ 5159 /* scanning for controllers, at first: ISA controller */
5160#ifdef CONFIG_ISA 5160#ifdef CONFIG_ISA
5161 ulong32 isa_bios; 5161 u32 isa_bios;
5162 for (isa_bios = 0xc8000UL; isa_bios <= 0xd8000UL; 5162 for (isa_bios = 0xc8000UL; isa_bios <= 0xd8000UL;
5163 isa_bios += 0x8000UL) 5163 isa_bios += 0x8000UL)
5164 gdth_isa_probe_one(isa_bios); 5164 gdth_isa_probe_one(isa_bios);
5165#endif 5165#endif
5166#ifdef CONFIG_EISA 5166#ifdef CONFIG_EISA
5167 { 5167 {
5168 ushort eisa_slot; 5168 u16 eisa_slot;
5169 for (eisa_slot = 0x1000; eisa_slot <= 0x8000; 5169 for (eisa_slot = 0x1000; eisa_slot <= 0x8000;
5170 eisa_slot += 0x1000) 5170 eisa_slot += 0x1000)
5171 gdth_eisa_probe_one(eisa_slot); 5171 gdth_eisa_probe_one(eisa_slot);
diff --git a/drivers/scsi/gdth.h b/drivers/scsi/gdth.h
index 1646444e9bd5..120a0625a7b5 100644
--- a/drivers/scsi/gdth.h
+++ b/drivers/scsi/gdth.h
@@ -321,524 +321,524 @@
321 321
322/* screenservice message */ 322/* screenservice message */
323typedef struct { 323typedef struct {
324 ulong32 msg_handle; /* message handle */ 324 u32 msg_handle; /* message handle */
325 ulong32 msg_len; /* size of message */ 325 u32 msg_len; /* size of message */
326 ulong32 msg_alen; /* answer length */ 326 u32 msg_alen; /* answer length */
327 unchar msg_answer; /* answer flag */ 327 u8 msg_answer; /* answer flag */
328 unchar msg_ext; /* more messages */ 328 u8 msg_ext; /* more messages */
329 unchar msg_reserved[2]; 329 u8 msg_reserved[2];
330 char msg_text[MSGLEN+2]; /* the message text */ 330 char msg_text[MSGLEN+2]; /* the message text */
331} PACKED gdth_msg_str; 331} __attribute__((packed)) gdth_msg_str;
332 332
333 333
334/* IOCTL data structures */ 334/* IOCTL data structures */
335 335
336/* Status coalescing buffer for returning multiple requests per interrupt */ 336/* Status coalescing buffer for returning multiple requests per interrupt */
337typedef struct { 337typedef struct {
338 ulong32 status; 338 u32 status;
339 ulong32 ext_status; 339 u32 ext_status;
340 ulong32 info0; 340 u32 info0;
341 ulong32 info1; 341 u32 info1;
342} PACKED gdth_coal_status; 342} __attribute__((packed)) gdth_coal_status;
343 343
344/* performance mode data structure */ 344/* performance mode data structure */
345typedef struct { 345typedef struct {
346 ulong32 version; /* The version of this IOCTL structure. */ 346 u32 version; /* The version of this IOCTL structure. */
347 ulong32 st_mode; /* 0=dis., 1=st_buf_addr1 valid, 2=both */ 347 u32 st_mode; /* 0=dis., 1=st_buf_addr1 valid, 2=both */
348 ulong32 st_buff_addr1; /* physical address of status buffer 1 */ 348 u32 st_buff_addr1; /* physical address of status buffer 1 */
349 ulong32 st_buff_u_addr1; /* reserved for 64 bit addressing */ 349 u32 st_buff_u_addr1; /* reserved for 64 bit addressing */
350 ulong32 st_buff_indx1; /* reserved command idx. for this buffer */ 350 u32 st_buff_indx1; /* reserved command idx. for this buffer */
351 ulong32 st_buff_addr2; /* physical address of status buffer 1 */ 351 u32 st_buff_addr2; /* physical address of status buffer 1 */
352 ulong32 st_buff_u_addr2; /* reserved for 64 bit addressing */ 352 u32 st_buff_u_addr2; /* reserved for 64 bit addressing */
353 ulong32 st_buff_indx2; /* reserved command idx. for this buffer */ 353 u32 st_buff_indx2; /* reserved command idx. for this buffer */
354 ulong32 st_buff_size; /* size of each buffer in bytes */ 354 u32 st_buff_size; /* size of each buffer in bytes */
355 ulong32 cmd_mode; /* 0 = mode disabled, 1 = cmd_buff_addr1 */ 355 u32 cmd_mode; /* 0 = mode disabled, 1 = cmd_buff_addr1 */
356 ulong32 cmd_buff_addr1; /* physical address of cmd buffer 1 */ 356 u32 cmd_buff_addr1; /* physical address of cmd buffer 1 */
357 ulong32 cmd_buff_u_addr1; /* reserved for 64 bit addressing */ 357 u32 cmd_buff_u_addr1; /* reserved for 64 bit addressing */
358 ulong32 cmd_buff_indx1; /* cmd buf addr1 unique identifier */ 358 u32 cmd_buff_indx1; /* cmd buf addr1 unique identifier */
359 ulong32 cmd_buff_addr2; /* physical address of cmd buffer 1 */ 359 u32 cmd_buff_addr2; /* physical address of cmd buffer 1 */
360 ulong32 cmd_buff_u_addr2; /* reserved for 64 bit addressing */ 360 u32 cmd_buff_u_addr2; /* reserved for 64 bit addressing */
361 ulong32 cmd_buff_indx2; /* cmd buf addr1 unique identifier */ 361 u32 cmd_buff_indx2; /* cmd buf addr1 unique identifier */
362 ulong32 cmd_buff_size; /* size of each cmd bufer in bytes */ 362 u32 cmd_buff_size; /* size of each cmd bufer in bytes */
363 ulong32 reserved1; 363 u32 reserved1;
364 ulong32 reserved2; 364 u32 reserved2;
365} PACKED gdth_perf_modes; 365} __attribute__((packed)) gdth_perf_modes;
366 366
367/* SCSI drive info */ 367/* SCSI drive info */
368typedef struct { 368typedef struct {
369 unchar vendor[8]; /* vendor string */ 369 u8 vendor[8]; /* vendor string */
370 unchar product[16]; /* product string */ 370 u8 product[16]; /* product string */
371 unchar revision[4]; /* revision */ 371 u8 revision[4]; /* revision */
372 ulong32 sy_rate; /* current rate for sync. tr. */ 372 u32 sy_rate; /* current rate for sync. tr. */
373 ulong32 sy_max_rate; /* max. rate for sync. tr. */ 373 u32 sy_max_rate; /* max. rate for sync. tr. */
374 ulong32 no_ldrive; /* belongs to this log. drv.*/ 374 u32 no_ldrive; /* belongs to this log. drv.*/
375 ulong32 blkcnt; /* number of blocks */ 375 u32 blkcnt; /* number of blocks */
376 ushort blksize; /* size of block in bytes */ 376 u16 blksize; /* size of block in bytes */
377 unchar available; /* flag: access is available */ 377 u8 available; /* flag: access is available */
378 unchar init; /* medium is initialized */ 378 u8 init; /* medium is initialized */
379 unchar devtype; /* SCSI devicetype */ 379 u8 devtype; /* SCSI devicetype */
380 unchar rm_medium; /* medium is removable */ 380 u8 rm_medium; /* medium is removable */
381 unchar wp_medium; /* medium is write protected */ 381 u8 wp_medium; /* medium is write protected */
382 unchar ansi; /* SCSI I/II or III? */ 382 u8 ansi; /* SCSI I/II or III? */
383 unchar protocol; /* same as ansi */ 383 u8 protocol; /* same as ansi */
384 unchar sync; /* flag: sync. transfer enab. */ 384 u8 sync; /* flag: sync. transfer enab. */
385 unchar disc; /* flag: disconnect enabled */ 385 u8 disc; /* flag: disconnect enabled */
386 unchar queueing; /* flag: command queing enab. */ 386 u8 queueing; /* flag: command queing enab. */
387 unchar cached; /* flag: caching enabled */ 387 u8 cached; /* flag: caching enabled */
388 unchar target_id; /* target ID of device */ 388 u8 target_id; /* target ID of device */
389 unchar lun; /* LUN id of device */ 389 u8 lun; /* LUN id of device */
390 unchar orphan; /* flag: drive fragment */ 390 u8 orphan; /* flag: drive fragment */
391 ulong32 last_error; /* sense key or drive state */ 391 u32 last_error; /* sense key or drive state */
392 ulong32 last_result; /* result of last command */ 392 u32 last_result; /* result of last command */
393 ulong32 check_errors; /* err. in last surface check */ 393 u32 check_errors; /* err. in last surface check */
394 unchar percent; /* progress for surface check */ 394 u8 percent; /* progress for surface check */
395 unchar last_check; /* IOCTRL operation */ 395 u8 last_check; /* IOCTRL operation */
396 unchar res[2]; 396 u8 res[2];
397 ulong32 flags; /* from 1.19/2.19: raw reserv.*/ 397 u32 flags; /* from 1.19/2.19: raw reserv.*/
398 unchar multi_bus; /* multi bus dev? (fibre ch.) */ 398 u8 multi_bus; /* multi bus dev? (fibre ch.) */
399 unchar mb_status; /* status: available? */ 399 u8 mb_status; /* status: available? */
400 unchar res2[2]; 400 u8 res2[2];
401 unchar mb_alt_status; /* status on second bus */ 401 u8 mb_alt_status; /* status on second bus */
402 unchar mb_alt_bid; /* number of second bus */ 402 u8 mb_alt_bid; /* number of second bus */
403 unchar mb_alt_tid; /* target id on second bus */ 403 u8 mb_alt_tid; /* target id on second bus */
404 unchar res3; 404 u8 res3;
405 unchar fc_flag; /* from 1.22/2.22: info valid?*/ 405 u8 fc_flag; /* from 1.22/2.22: info valid?*/
406 unchar res4; 406 u8 res4;
407 ushort fc_frame_size; /* frame size (bytes) */ 407 u16 fc_frame_size; /* frame size (bytes) */
408 char wwn[8]; /* world wide name */ 408 char wwn[8]; /* world wide name */
409} PACKED gdth_diskinfo_str; 409} __attribute__((packed)) gdth_diskinfo_str;
410 410
411/* get SCSI channel count */ 411/* get SCSI channel count */
412typedef struct { 412typedef struct {
413 ulong32 channel_no; /* number of channel */ 413 u32 channel_no; /* number of channel */
414 ulong32 drive_cnt; /* drive count */ 414 u32 drive_cnt; /* drive count */
415 unchar siop_id; /* SCSI processor ID */ 415 u8 siop_id; /* SCSI processor ID */
416 unchar siop_state; /* SCSI processor state */ 416 u8 siop_state; /* SCSI processor state */
417} PACKED gdth_getch_str; 417} __attribute__((packed)) gdth_getch_str;
418 418
419/* get SCSI drive numbers */ 419/* get SCSI drive numbers */
420typedef struct { 420typedef struct {
421 ulong32 sc_no; /* SCSI channel */ 421 u32 sc_no; /* SCSI channel */
422 ulong32 sc_cnt; /* sc_list[] elements */ 422 u32 sc_cnt; /* sc_list[] elements */
423 ulong32 sc_list[MAXID]; /* minor device numbers */ 423 u32 sc_list[MAXID]; /* minor device numbers */
424} PACKED gdth_drlist_str; 424} __attribute__((packed)) gdth_drlist_str;
425 425
426/* get grown/primary defect count */ 426/* get grown/primary defect count */
427typedef struct { 427typedef struct {
428 unchar sddc_type; /* 0x08: grown, 0x10: prim. */ 428 u8 sddc_type; /* 0x08: grown, 0x10: prim. */
429 unchar sddc_format; /* list entry format */ 429 u8 sddc_format; /* list entry format */
430 unchar sddc_len; /* list entry length */ 430 u8 sddc_len; /* list entry length */
431 unchar sddc_res; 431 u8 sddc_res;
432 ulong32 sddc_cnt; /* entry count */ 432 u32 sddc_cnt; /* entry count */
433} PACKED gdth_defcnt_str; 433} __attribute__((packed)) gdth_defcnt_str;
434 434
435/* disk statistics */ 435/* disk statistics */
436typedef struct { 436typedef struct {
437 ulong32 bid; /* SCSI channel */ 437 u32 bid; /* SCSI channel */
438 ulong32 first; /* first SCSI disk */ 438 u32 first; /* first SCSI disk */
439 ulong32 entries; /* number of elements */ 439 u32 entries; /* number of elements */
440 ulong32 count; /* (R) number of init. el. */ 440 u32 count; /* (R) number of init. el. */
441 ulong32 mon_time; /* time stamp */ 441 u32 mon_time; /* time stamp */
442 struct { 442 struct {
443 unchar tid; /* target ID */ 443 u8 tid; /* target ID */
444 unchar lun; /* LUN */ 444 u8 lun; /* LUN */
445 unchar res[2]; 445 u8 res[2];
446 ulong32 blk_size; /* block size in bytes */ 446 u32 blk_size; /* block size in bytes */
447 ulong32 rd_count; /* bytes read */ 447 u32 rd_count; /* bytes read */
448 ulong32 wr_count; /* bytes written */ 448 u32 wr_count; /* bytes written */
449 ulong32 rd_blk_count; /* blocks read */ 449 u32 rd_blk_count; /* blocks read */
450 ulong32 wr_blk_count; /* blocks written */ 450 u32 wr_blk_count; /* blocks written */
451 ulong32 retries; /* retries */ 451 u32 retries; /* retries */
452 ulong32 reassigns; /* reassigns */ 452 u32 reassigns; /* reassigns */
453 } PACKED list[1]; 453 } __attribute__((packed)) list[1];
454} PACKED gdth_dskstat_str; 454} __attribute__((packed)) gdth_dskstat_str;
455 455
456/* IO channel header */ 456/* IO channel header */
457typedef struct { 457typedef struct {
458 ulong32 version; /* version (-1UL: newest) */ 458 u32 version; /* version (-1UL: newest) */
459 unchar list_entries; /* list entry count */ 459 u8 list_entries; /* list entry count */
460 unchar first_chan; /* first channel number */ 460 u8 first_chan; /* first channel number */
461 unchar last_chan; /* last channel number */ 461 u8 last_chan; /* last channel number */
462 unchar chan_count; /* (R) channel count */ 462 u8 chan_count; /* (R) channel count */
463 ulong32 list_offset; /* offset of list[0] */ 463 u32 list_offset; /* offset of list[0] */
464} PACKED gdth_iochan_header; 464} __attribute__((packed)) gdth_iochan_header;
465 465
466/* get IO channel description */ 466/* get IO channel description */
467typedef struct { 467typedef struct {
468 gdth_iochan_header hdr; 468 gdth_iochan_header hdr;
469 struct { 469 struct {
470 ulong32 address; /* channel address */ 470 u32 address; /* channel address */
471 unchar type; /* type (SCSI, FCAL) */ 471 u8 type; /* type (SCSI, FCAL) */
472 unchar local_no; /* local number */ 472 u8 local_no; /* local number */
473 ushort features; /* channel features */ 473 u16 features; /* channel features */
474 } PACKED list[MAXBUS]; 474 } __attribute__((packed)) list[MAXBUS];
475} PACKED gdth_iochan_str; 475} __attribute__((packed)) gdth_iochan_str;
476 476
477/* get raw IO channel description */ 477/* get raw IO channel description */
478typedef struct { 478typedef struct {
479 gdth_iochan_header hdr; 479 gdth_iochan_header hdr;
480 struct { 480 struct {
481 unchar proc_id; /* processor id */ 481 u8 proc_id; /* processor id */
482 unchar proc_defect; /* defect ? */ 482 u8 proc_defect; /* defect ? */
483 unchar reserved[2]; 483 u8 reserved[2];
484 } PACKED list[MAXBUS]; 484 } __attribute__((packed)) list[MAXBUS];
485} PACKED gdth_raw_iochan_str; 485} __attribute__((packed)) gdth_raw_iochan_str;
486 486
487/* array drive component */ 487/* array drive component */
488typedef struct { 488typedef struct {
489 ulong32 al_controller; /* controller ID */ 489 u32 al_controller; /* controller ID */
490 unchar al_cache_drive; /* cache drive number */ 490 u8 al_cache_drive; /* cache drive number */
491 unchar al_status; /* cache drive state */ 491 u8 al_status; /* cache drive state */
492 unchar al_res[2]; 492 u8 al_res[2];
493} PACKED gdth_arraycomp_str; 493} __attribute__((packed)) gdth_arraycomp_str;
494 494
495/* array drive information */ 495/* array drive information */
496typedef struct { 496typedef struct {
497 unchar ai_type; /* array type (RAID0,4,5) */ 497 u8 ai_type; /* array type (RAID0,4,5) */
498 unchar ai_cache_drive_cnt; /* active cachedrives */ 498 u8 ai_cache_drive_cnt; /* active cachedrives */
499 unchar ai_state; /* array drive state */ 499 u8 ai_state; /* array drive state */
500 unchar ai_master_cd; /* master cachedrive */ 500 u8 ai_master_cd; /* master cachedrive */
501 ulong32 ai_master_controller; /* ID of master controller */ 501 u32 ai_master_controller; /* ID of master controller */
502 ulong32 ai_size; /* user capacity [sectors] */ 502 u32 ai_size; /* user capacity [sectors] */
503 ulong32 ai_striping_size; /* striping size [sectors] */ 503 u32 ai_striping_size; /* striping size [sectors] */
504 ulong32 ai_secsize; /* sector size [bytes] */ 504 u32 ai_secsize; /* sector size [bytes] */
505 ulong32 ai_err_info; /* failed cache drive */ 505 u32 ai_err_info; /* failed cache drive */
506 unchar ai_name[8]; /* name of the array drive */ 506 u8 ai_name[8]; /* name of the array drive */
507 unchar ai_controller_cnt; /* number of controllers */ 507 u8 ai_controller_cnt; /* number of controllers */
508 unchar ai_removable; /* flag: removable */ 508 u8 ai_removable; /* flag: removable */
509 unchar ai_write_protected; /* flag: write protected */ 509 u8 ai_write_protected; /* flag: write protected */
510 unchar ai_devtype; /* type: always direct access */ 510 u8 ai_devtype; /* type: always direct access */
511 gdth_arraycomp_str ai_drives[35]; /* drive components: */ 511 gdth_arraycomp_str ai_drives[35]; /* drive components: */
512 unchar ai_drive_entries; /* number of drive components */ 512 u8 ai_drive_entries; /* number of drive components */
513 unchar ai_protected; /* protection flag */ 513 u8 ai_protected; /* protection flag */
514 unchar ai_verify_state; /* state of a parity verify */ 514 u8 ai_verify_state; /* state of a parity verify */
515 unchar ai_ext_state; /* extended array drive state */ 515 u8 ai_ext_state; /* extended array drive state */
516 unchar ai_expand_state; /* array expand state (>=2.18)*/ 516 u8 ai_expand_state; /* array expand state (>=2.18)*/
517 unchar ai_reserved[3]; 517 u8 ai_reserved[3];
518} PACKED gdth_arrayinf_str; 518} __attribute__((packed)) gdth_arrayinf_str;
519 519
520/* get array drive list */ 520/* get array drive list */
521typedef struct { 521typedef struct {
522 ulong32 controller_no; /* controller no. */ 522 u32 controller_no; /* controller no. */
523 unchar cd_handle; /* master cachedrive */ 523 u8 cd_handle; /* master cachedrive */
524 unchar is_arrayd; /* Flag: is array drive? */ 524 u8 is_arrayd; /* Flag: is array drive? */
525 unchar is_master; /* Flag: is array master? */ 525 u8 is_master; /* Flag: is array master? */
526 unchar is_parity; /* Flag: is parity drive? */ 526 u8 is_parity; /* Flag: is parity drive? */
527 unchar is_hotfix; /* Flag: is hotfix drive? */ 527 u8 is_hotfix; /* Flag: is hotfix drive? */
528 unchar res[3]; 528 u8 res[3];
529} PACKED gdth_alist_str; 529} __attribute__((packed)) gdth_alist_str;
530 530
531typedef struct { 531typedef struct {
532 ulong32 entries_avail; /* allocated entries */ 532 u32 entries_avail; /* allocated entries */
533 ulong32 entries_init; /* returned entries */ 533 u32 entries_init; /* returned entries */
534 ulong32 first_entry; /* first entry number */ 534 u32 first_entry; /* first entry number */
535 ulong32 list_offset; /* offset of following list */ 535 u32 list_offset; /* offset of following list */
536 gdth_alist_str list[1]; /* list */ 536 gdth_alist_str list[1]; /* list */
537} PACKED gdth_arcdl_str; 537} __attribute__((packed)) gdth_arcdl_str;
538 538
539/* cache info/config IOCTL */ 539/* cache info/config IOCTL */
540typedef struct { 540typedef struct {
541 ulong32 version; /* firmware version */ 541 u32 version; /* firmware version */
542 ushort state; /* cache state (on/off) */ 542 u16 state; /* cache state (on/off) */
543 ushort strategy; /* cache strategy */ 543 u16 strategy; /* cache strategy */
544 ushort write_back; /* write back state (on/off) */ 544 u16 write_back; /* write back state (on/off) */
545 ushort block_size; /* cache block size */ 545 u16 block_size; /* cache block size */
546} PACKED gdth_cpar_str; 546} __attribute__((packed)) gdth_cpar_str;
547 547
548typedef struct { 548typedef struct {
549 ulong32 csize; /* cache size */ 549 u32 csize; /* cache size */
550 ulong32 read_cnt; /* read/write counter */ 550 u32 read_cnt; /* read/write counter */
551 ulong32 write_cnt; 551 u32 write_cnt;
552 ulong32 tr_hits; /* hits */ 552 u32 tr_hits; /* hits */
553 ulong32 sec_hits; 553 u32 sec_hits;
554 ulong32 sec_miss; /* misses */ 554 u32 sec_miss; /* misses */
555} PACKED gdth_cstat_str; 555} __attribute__((packed)) gdth_cstat_str;
556 556
557typedef struct { 557typedef struct {
558 gdth_cpar_str cpar; 558 gdth_cpar_str cpar;
559 gdth_cstat_str cstat; 559 gdth_cstat_str cstat;
560} PACKED gdth_cinfo_str; 560} __attribute__((packed)) gdth_cinfo_str;
561 561
562/* cache drive info */ 562/* cache drive info */
563typedef struct { 563typedef struct {
564 unchar cd_name[8]; /* cache drive name */ 564 u8 cd_name[8]; /* cache drive name */
565 ulong32 cd_devtype; /* SCSI devicetype */ 565 u32 cd_devtype; /* SCSI devicetype */
566 ulong32 cd_ldcnt; /* number of log. drives */ 566 u32 cd_ldcnt; /* number of log. drives */
567 ulong32 cd_last_error; /* last error */ 567 u32 cd_last_error; /* last error */
568 unchar cd_initialized; /* drive is initialized */ 568 u8 cd_initialized; /* drive is initialized */
569 unchar cd_removable; /* media is removable */ 569 u8 cd_removable; /* media is removable */
570 unchar cd_write_protected; /* write protected */ 570 u8 cd_write_protected; /* write protected */
571 unchar cd_flags; /* Pool Hot Fix? */ 571 u8 cd_flags; /* Pool Hot Fix? */
572 ulong32 ld_blkcnt; /* number of blocks */ 572 u32 ld_blkcnt; /* number of blocks */
573 ulong32 ld_blksize; /* blocksize */ 573 u32 ld_blksize; /* blocksize */
574 ulong32 ld_dcnt; /* number of disks */ 574 u32 ld_dcnt; /* number of disks */
575 ulong32 ld_slave; /* log. drive index */ 575 u32 ld_slave; /* log. drive index */
576 ulong32 ld_dtype; /* type of logical drive */ 576 u32 ld_dtype; /* type of logical drive */
577 ulong32 ld_last_error; /* last error */ 577 u32 ld_last_error; /* last error */
578 unchar ld_name[8]; /* log. drive name */ 578 u8 ld_name[8]; /* log. drive name */
579 unchar ld_error; /* error */ 579 u8 ld_error; /* error */
580} PACKED gdth_cdrinfo_str; 580} __attribute__((packed)) gdth_cdrinfo_str;
581 581
582/* OEM string */ 582/* OEM string */
583typedef struct { 583typedef struct {
584 ulong32 ctl_version; 584 u32 ctl_version;
585 ulong32 file_major_version; 585 u32 file_major_version;
586 ulong32 file_minor_version; 586 u32 file_minor_version;
587 ulong32 buffer_size; 587 u32 buffer_size;
588 ulong32 cpy_count; 588 u32 cpy_count;
589 ulong32 ext_error; 589 u32 ext_error;
590 ulong32 oem_id; 590 u32 oem_id;
591 ulong32 board_id; 591 u32 board_id;
592} PACKED gdth_oem_str_params; 592} __attribute__((packed)) gdth_oem_str_params;
593 593
594typedef struct { 594typedef struct {
595 unchar product_0_1_name[16]; 595 u8 product_0_1_name[16];
596 unchar product_4_5_name[16]; 596 u8 product_4_5_name[16];
597 unchar product_cluster_name[16]; 597 u8 product_cluster_name[16];
598 unchar product_reserved[16]; 598 u8 product_reserved[16];
599 unchar scsi_cluster_target_vendor_id[16]; 599 u8 scsi_cluster_target_vendor_id[16];
600 unchar cluster_raid_fw_name[16]; 600 u8 cluster_raid_fw_name[16];
601 unchar oem_brand_name[16]; 601 u8 oem_brand_name[16];
602 unchar oem_raid_type[16]; 602 u8 oem_raid_type[16];
603 unchar bios_type[13]; 603 u8 bios_type[13];
604 unchar bios_title[50]; 604 u8 bios_title[50];
605 unchar oem_company_name[37]; 605 u8 oem_company_name[37];
606 ulong32 pci_id_1; 606 u32 pci_id_1;
607 ulong32 pci_id_2; 607 u32 pci_id_2;
608 unchar validation_status[80]; 608 u8 validation_status[80];
609 unchar reserved_1[4]; 609 u8 reserved_1[4];
610 unchar scsi_host_drive_inquiry_vendor_id[16]; 610 u8 scsi_host_drive_inquiry_vendor_id[16];
611 unchar library_file_template[16]; 611 u8 library_file_template[16];
612 unchar reserved_2[16]; 612 u8 reserved_2[16];
613 unchar tool_name_1[32]; 613 u8 tool_name_1[32];
614 unchar tool_name_2[32]; 614 u8 tool_name_2[32];
615 unchar tool_name_3[32]; 615 u8 tool_name_3[32];
616 unchar oem_contact_1[84]; 616 u8 oem_contact_1[84];
617 unchar oem_contact_2[84]; 617 u8 oem_contact_2[84];
618 unchar oem_contact_3[84]; 618 u8 oem_contact_3[84];
619} PACKED gdth_oem_str; 619} __attribute__((packed)) gdth_oem_str;
620 620
621typedef struct { 621typedef struct {
622 gdth_oem_str_params params; 622 gdth_oem_str_params params;
623 gdth_oem_str text; 623 gdth_oem_str text;
624} PACKED gdth_oem_str_ioctl; 624} __attribute__((packed)) gdth_oem_str_ioctl;
625 625
626/* board features */ 626/* board features */
627typedef struct { 627typedef struct {
628 unchar chaining; /* Chaining supported */ 628 u8 chaining; /* Chaining supported */
629 unchar striping; /* Striping (RAID-0) supp. */ 629 u8 striping; /* Striping (RAID-0) supp. */
630 unchar mirroring; /* Mirroring (RAID-1) supp. */ 630 u8 mirroring; /* Mirroring (RAID-1) supp. */
631 unchar raid; /* RAID-4/5/10 supported */ 631 u8 raid; /* RAID-4/5/10 supported */
632} PACKED gdth_bfeat_str; 632} __attribute__((packed)) gdth_bfeat_str;
633 633
634/* board info IOCTL */ 634/* board info IOCTL */
635typedef struct { 635typedef struct {
636 ulong32 ser_no; /* serial no. */ 636 u32 ser_no; /* serial no. */
637 unchar oem_id[2]; /* OEM ID */ 637 u8 oem_id[2]; /* OEM ID */
638 ushort ep_flags; /* eprom flags */ 638 u16 ep_flags; /* eprom flags */
639 ulong32 proc_id; /* processor ID */ 639 u32 proc_id; /* processor ID */
640 ulong32 memsize; /* memory size (bytes) */ 640 u32 memsize; /* memory size (bytes) */
641 unchar mem_banks; /* memory banks */ 641 u8 mem_banks; /* memory banks */
642 unchar chan_type; /* channel type */ 642 u8 chan_type; /* channel type */
643 unchar chan_count; /* channel count */ 643 u8 chan_count; /* channel count */
644 unchar rdongle_pres; /* dongle present? */ 644 u8 rdongle_pres; /* dongle present? */
645 ulong32 epr_fw_ver; /* (eprom) firmware version */ 645 u32 epr_fw_ver; /* (eprom) firmware version */
646 ulong32 upd_fw_ver; /* (update) firmware version */ 646 u32 upd_fw_ver; /* (update) firmware version */
647 ulong32 upd_revision; /* update revision */ 647 u32 upd_revision; /* update revision */
648 char type_string[16]; /* controller name */ 648 char type_string[16]; /* controller name */
649 char raid_string[16]; /* RAID firmware name */ 649 char raid_string[16]; /* RAID firmware name */
650 unchar update_pres; /* update present? */ 650 u8 update_pres; /* update present? */
651 unchar xor_pres; /* XOR engine present? */ 651 u8 xor_pres; /* XOR engine present? */
652 unchar prom_type; /* ROM type (eprom/flash) */ 652 u8 prom_type; /* ROM type (eprom/flash) */
653 unchar prom_count; /* number of ROM devices */ 653 u8 prom_count; /* number of ROM devices */
654 ulong32 dup_pres; /* duplexing module present? */ 654 u32 dup_pres; /* duplexing module present? */
655 ulong32 chan_pres; /* number of expansion chn. */ 655 u32 chan_pres; /* number of expansion chn. */
656 ulong32 mem_pres; /* memory expansion inst. ? */ 656 u32 mem_pres; /* memory expansion inst. ? */
657 unchar ft_bus_system; /* fault bus supported? */ 657 u8 ft_bus_system; /* fault bus supported? */
658 unchar subtype_valid; /* board_subtype valid? */ 658 u8 subtype_valid; /* board_subtype valid? */
659 unchar board_subtype; /* subtype/hardware level */ 659 u8 board_subtype; /* subtype/hardware level */
660 unchar ramparity_pres; /* RAM parity check hardware? */ 660 u8 ramparity_pres; /* RAM parity check hardware? */
661} PACKED gdth_binfo_str; 661} __attribute__((packed)) gdth_binfo_str;
662 662
663/* get host drive info */ 663/* get host drive info */
664typedef struct { 664typedef struct {
665 char name[8]; /* host drive name */ 665 char name[8]; /* host drive name */
666 ulong32 size; /* size (sectors) */ 666 u32 size; /* size (sectors) */
667 unchar host_drive; /* host drive number */ 667 u8 host_drive; /* host drive number */
668 unchar log_drive; /* log. drive (master) */ 668 u8 log_drive; /* log. drive (master) */
669 unchar reserved; 669 u8 reserved;
670 unchar rw_attribs; /* r/w attribs */ 670 u8 rw_attribs; /* r/w attribs */
671 ulong32 start_sec; /* start sector */ 671 u32 start_sec; /* start sector */
672} PACKED gdth_hentry_str; 672} __attribute__((packed)) gdth_hentry_str;
673 673
674typedef struct { 674typedef struct {
675 ulong32 entries; /* entry count */ 675 u32 entries; /* entry count */
676 ulong32 offset; /* offset of entries */ 676 u32 offset; /* offset of entries */
677 unchar secs_p_head; /* sectors/head */ 677 u8 secs_p_head; /* sectors/head */
678 unchar heads_p_cyl; /* heads/cylinder */ 678 u8 heads_p_cyl; /* heads/cylinder */
679 unchar reserved; 679 u8 reserved;
680 unchar clust_drvtype; /* cluster drive type */ 680 u8 clust_drvtype; /* cluster drive type */
681 ulong32 location; /* controller number */ 681 u32 location; /* controller number */
682 gdth_hentry_str entry[MAX_HDRIVES]; /* entries */ 682 gdth_hentry_str entry[MAX_HDRIVES]; /* entries */
683} PACKED gdth_hget_str; 683} __attribute__((packed)) gdth_hget_str;
684 684
685 685
686/* DPRAM structures */ 686/* DPRAM structures */
687 687
688/* interface area ISA/PCI */ 688/* interface area ISA/PCI */
689typedef struct { 689typedef struct {
690 unchar S_Cmd_Indx; /* special command */ 690 u8 S_Cmd_Indx; /* special command */
691 unchar volatile S_Status; /* status special command */ 691 u8 volatile S_Status; /* status special command */
692 ushort reserved1; 692 u16 reserved1;
693 ulong32 S_Info[4]; /* add. info special command */ 693 u32 S_Info[4]; /* add. info special command */
694 unchar volatile Sema0; /* command semaphore */ 694 u8 volatile Sema0; /* command semaphore */
695 unchar reserved2[3]; 695 u8 reserved2[3];
696 unchar Cmd_Index; /* command number */ 696 u8 Cmd_Index; /* command number */
697 unchar reserved3[3]; 697 u8 reserved3[3];
698 ushort volatile Status; /* command status */ 698 u16 volatile Status; /* command status */
699 ushort Service; /* service(for async.events) */ 699 u16 Service; /* service(for async.events) */
700 ulong32 Info[2]; /* additional info */ 700 u32 Info[2]; /* additional info */
701 struct { 701 struct {
702 ushort offset; /* command offs. in the DPRAM*/ 702 u16 offset; /* command offs. in the DPRAM*/
703 ushort serv_id; /* service */ 703 u16 serv_id; /* service */
704 } PACKED comm_queue[MAXOFFSETS]; /* command queue */ 704 } __attribute__((packed)) comm_queue[MAXOFFSETS]; /* command queue */
705 ulong32 bios_reserved[2]; 705 u32 bios_reserved[2];
706 unchar gdt_dpr_cmd[1]; /* commands */ 706 u8 gdt_dpr_cmd[1]; /* commands */
707} PACKED gdt_dpr_if; 707} __attribute__((packed)) gdt_dpr_if;
708 708
709/* SRAM structure PCI controllers */ 709/* SRAM structure PCI controllers */
710typedef struct { 710typedef struct {
711 ulong32 magic; /* controller ID from BIOS */ 711 u32 magic; /* controller ID from BIOS */
712 ushort need_deinit; /* switch betw. BIOS/driver */ 712 u16 need_deinit; /* switch betw. BIOS/driver */
713 unchar switch_support; /* see need_deinit */ 713 u8 switch_support; /* see need_deinit */
714 unchar padding[9]; 714 u8 padding[9];
715 unchar os_used[16]; /* OS code per service */ 715 u8 os_used[16]; /* OS code per service */
716 unchar unused[28]; 716 u8 unused[28];
717 unchar fw_magic; /* contr. ID from firmware */ 717 u8 fw_magic; /* contr. ID from firmware */
718} PACKED gdt_pci_sram; 718} __attribute__((packed)) gdt_pci_sram;
719 719
720/* SRAM structure EISA controllers (but NOT GDT3000/3020) */ 720/* SRAM structure EISA controllers (but NOT GDT3000/3020) */
721typedef struct { 721typedef struct {
722 unchar os_used[16]; /* OS code per service */ 722 u8 os_used[16]; /* OS code per service */
723 ushort need_deinit; /* switch betw. BIOS/driver */ 723 u16 need_deinit; /* switch betw. BIOS/driver */
724 unchar switch_support; /* see need_deinit */ 724 u8 switch_support; /* see need_deinit */
725 unchar padding; 725 u8 padding;
726} PACKED gdt_eisa_sram; 726} __attribute__((packed)) gdt_eisa_sram;
727 727
728 728
729/* DPRAM ISA controllers */ 729/* DPRAM ISA controllers */
730typedef struct { 730typedef struct {
731 union { 731 union {
732 struct { 732 struct {
733 unchar bios_used[0x3c00-32]; /* 15KB - 32Bytes BIOS */ 733 u8 bios_used[0x3c00-32]; /* 15KB - 32Bytes BIOS */
734 ulong32 magic; /* controller (EISA) ID */ 734 u32 magic; /* controller (EISA) ID */
735 ushort need_deinit; /* switch betw. BIOS/driver */ 735 u16 need_deinit; /* switch betw. BIOS/driver */
736 unchar switch_support; /* see need_deinit */ 736 u8 switch_support; /* see need_deinit */
737 unchar padding[9]; 737 u8 padding[9];
738 unchar os_used[16]; /* OS code per service */ 738 u8 os_used[16]; /* OS code per service */
739 } PACKED dp_sram; 739 } __attribute__((packed)) dp_sram;
740 unchar bios_area[0x4000]; /* 16KB reserved for BIOS */ 740 u8 bios_area[0x4000]; /* 16KB reserved for BIOS */
741 } bu; 741 } bu;
742 union { 742 union {
743 gdt_dpr_if ic; /* interface area */ 743 gdt_dpr_if ic; /* interface area */
744 unchar if_area[0x3000]; /* 12KB for interface */ 744 u8 if_area[0x3000]; /* 12KB for interface */
745 } u; 745 } u;
746 struct { 746 struct {
747 unchar memlock; /* write protection DPRAM */ 747 u8 memlock; /* write protection DPRAM */
748 unchar event; /* release event */ 748 u8 event; /* release event */
749 unchar irqen; /* board interrupts enable */ 749 u8 irqen; /* board interrupts enable */
750 unchar irqdel; /* acknowledge board int. */ 750 u8 irqdel; /* acknowledge board int. */
751 unchar volatile Sema1; /* status semaphore */ 751 u8 volatile Sema1; /* status semaphore */
752 unchar rq; /* IRQ/DRQ configuration */ 752 u8 rq; /* IRQ/DRQ configuration */
753 } PACKED io; 753 } __attribute__((packed)) io;
754} PACKED gdt2_dpram_str; 754} __attribute__((packed)) gdt2_dpram_str;
755 755
756/* DPRAM PCI controllers */ 756/* DPRAM PCI controllers */
757typedef struct { 757typedef struct {
758 union { 758 union {
759 gdt_dpr_if ic; /* interface area */ 759 gdt_dpr_if ic; /* interface area */
760 unchar if_area[0xff0-sizeof(gdt_pci_sram)]; 760 u8 if_area[0xff0-sizeof(gdt_pci_sram)];
761 } u; 761 } u;
762 gdt_pci_sram gdt6sr; /* SRAM structure */ 762 gdt_pci_sram gdt6sr; /* SRAM structure */
763 struct { 763 struct {
764 unchar unused0[1]; 764 u8 unused0[1];
765 unchar volatile Sema1; /* command semaphore */ 765 u8 volatile Sema1; /* command semaphore */
766 unchar unused1[3]; 766 u8 unused1[3];
767 unchar irqen; /* board interrupts enable */ 767 u8 irqen; /* board interrupts enable */
768 unchar unused2[2]; 768 u8 unused2[2];
769 unchar event; /* release event */ 769 u8 event; /* release event */
770 unchar unused3[3]; 770 u8 unused3[3];
771 unchar irqdel; /* acknowledge board int. */ 771 u8 irqdel; /* acknowledge board int. */
772 unchar unused4[3]; 772 u8 unused4[3];
773 } PACKED io; 773 } __attribute__((packed)) io;
774} PACKED gdt6_dpram_str; 774} __attribute__((packed)) gdt6_dpram_str;
775 775
776/* PLX register structure (new PCI controllers) */ 776/* PLX register structure (new PCI controllers) */
777typedef struct { 777typedef struct {
778 unchar cfg_reg; /* DPRAM cfg.(2:below 1MB,0:anywhere)*/ 778 u8 cfg_reg; /* DPRAM cfg.(2:below 1MB,0:anywhere)*/
779 unchar unused1[0x3f]; 779 u8 unused1[0x3f];
780 unchar volatile sema0_reg; /* command semaphore */ 780 u8 volatile sema0_reg; /* command semaphore */
781 unchar volatile sema1_reg; /* status semaphore */ 781 u8 volatile sema1_reg; /* status semaphore */
782 unchar unused2[2]; 782 u8 unused2[2];
783 ushort volatile status; /* command status */ 783 u16 volatile status; /* command status */
784 ushort service; /* service */ 784 u16 service; /* service */
785 ulong32 info[2]; /* additional info */ 785 u32 info[2]; /* additional info */
786 unchar unused3[0x10]; 786 u8 unused3[0x10];
787 unchar ldoor_reg; /* PCI to local doorbell */ 787 u8 ldoor_reg; /* PCI to local doorbell */
788 unchar unused4[3]; 788 u8 unused4[3];
789 unchar volatile edoor_reg; /* local to PCI doorbell */ 789 u8 volatile edoor_reg; /* local to PCI doorbell */
790 unchar unused5[3]; 790 u8 unused5[3];
791 unchar control0; /* control0 register(unused) */ 791 u8 control0; /* control0 register(unused) */
792 unchar control1; /* board interrupts enable */ 792 u8 control1; /* board interrupts enable */
793 unchar unused6[0x16]; 793 u8 unused6[0x16];
794} PACKED gdt6c_plx_regs; 794} __attribute__((packed)) gdt6c_plx_regs;
795 795
796/* DPRAM new PCI controllers */ 796/* DPRAM new PCI controllers */
797typedef struct { 797typedef struct {
798 union { 798 union {
799 gdt_dpr_if ic; /* interface area */ 799 gdt_dpr_if ic; /* interface area */
800 unchar if_area[0x4000-sizeof(gdt_pci_sram)]; 800 u8 if_area[0x4000-sizeof(gdt_pci_sram)];
801 } u; 801 } u;
802 gdt_pci_sram gdt6sr; /* SRAM structure */ 802 gdt_pci_sram gdt6sr; /* SRAM structure */
803} PACKED gdt6c_dpram_str; 803} __attribute__((packed)) gdt6c_dpram_str;
804 804
805/* i960 register structure (PCI MPR controllers) */ 805/* i960 register structure (PCI MPR controllers) */
806typedef struct { 806typedef struct {
807 unchar unused1[16]; 807 u8 unused1[16];
808 unchar volatile sema0_reg; /* command semaphore */ 808 u8 volatile sema0_reg; /* command semaphore */
809 unchar unused2; 809 u8 unused2;
810 unchar volatile sema1_reg; /* status semaphore */ 810 u8 volatile sema1_reg; /* status semaphore */
811 unchar unused3; 811 u8 unused3;
812 ushort volatile status; /* command status */ 812 u16 volatile status; /* command status */
813 ushort service; /* service */ 813 u16 service; /* service */
814 ulong32 info[2]; /* additional info */ 814 u32 info[2]; /* additional info */
815 unchar ldoor_reg; /* PCI to local doorbell */ 815 u8 ldoor_reg; /* PCI to local doorbell */
816 unchar unused4[11]; 816 u8 unused4[11];
817 unchar volatile edoor_reg; /* local to PCI doorbell */ 817 u8 volatile edoor_reg; /* local to PCI doorbell */
818 unchar unused5[7]; 818 u8 unused5[7];
819 unchar edoor_en_reg; /* board interrupts enable */ 819 u8 edoor_en_reg; /* board interrupts enable */
820 unchar unused6[27]; 820 u8 unused6[27];
821 ulong32 unused7[939]; 821 u32 unused7[939];
822 ulong32 severity; 822 u32 severity;
823 char evt_str[256]; /* event string */ 823 char evt_str[256]; /* event string */
824} PACKED gdt6m_i960_regs; 824} __attribute__((packed)) gdt6m_i960_regs;
825 825
826/* DPRAM PCI MPR controllers */ 826/* DPRAM PCI MPR controllers */
827typedef struct { 827typedef struct {
828 gdt6m_i960_regs i960r; /* 4KB i960 registers */ 828 gdt6m_i960_regs i960r; /* 4KB i960 registers */
829 union { 829 union {
830 gdt_dpr_if ic; /* interface area */ 830 gdt_dpr_if ic; /* interface area */
831 unchar if_area[0x3000-sizeof(gdt_pci_sram)]; 831 u8 if_area[0x3000-sizeof(gdt_pci_sram)];
832 } u; 832 } u;
833 gdt_pci_sram gdt6sr; /* SRAM structure */ 833 gdt_pci_sram gdt6sr; /* SRAM structure */
834} PACKED gdt6m_dpram_str; 834} __attribute__((packed)) gdt6m_dpram_str;
835 835
836 836
837/* PCI resources */ 837/* PCI resources */
838typedef struct { 838typedef struct {
839 struct pci_dev *pdev; 839 struct pci_dev *pdev;
840 ulong dpmem; /* DPRAM address */ 840 unsigned long dpmem; /* DPRAM address */
841 ulong io; /* IO address */ 841 unsigned long io; /* IO address */
842} gdth_pci_str; 842} gdth_pci_str;
843 843
844 844
@@ -846,93 +846,93 @@ typedef struct {
846typedef struct { 846typedef struct {
847 struct Scsi_Host *shost; 847 struct Scsi_Host *shost;
848 struct list_head list; 848 struct list_head list;
849 ushort hanum; 849 u16 hanum;
850 ushort oem_id; /* OEM */ 850 u16 oem_id; /* OEM */
851 ushort type; /* controller class */ 851 u16 type; /* controller class */
852 ulong32 stype; /* subtype (PCI: device ID) */ 852 u32 stype; /* subtype (PCI: device ID) */
853 ushort fw_vers; /* firmware version */ 853 u16 fw_vers; /* firmware version */
854 ushort cache_feat; /* feat. cache serv. (s/g,..)*/ 854 u16 cache_feat; /* feat. cache serv. (s/g,..)*/
855 ushort raw_feat; /* feat. raw service (s/g,..)*/ 855 u16 raw_feat; /* feat. raw service (s/g,..)*/
856 ushort screen_feat; /* feat. raw service (s/g,..)*/ 856 u16 screen_feat; /* feat. raw service (s/g,..)*/
857 ushort bmic; /* BMIC address (EISA) */ 857 u16 bmic; /* BMIC address (EISA) */
858 void __iomem *brd; /* DPRAM address */ 858 void __iomem *brd; /* DPRAM address */
859 ulong32 brd_phys; /* slot number/BIOS address */ 859 u32 brd_phys; /* slot number/BIOS address */
860 gdt6c_plx_regs *plx; /* PLX regs (new PCI contr.) */ 860 gdt6c_plx_regs *plx; /* PLX regs (new PCI contr.) */
861 gdth_cmd_str cmdext; 861 gdth_cmd_str cmdext;
862 gdth_cmd_str *pccb; /* address command structure */ 862 gdth_cmd_str *pccb; /* address command structure */
863 ulong32 ccb_phys; /* phys. address */ 863 u32 ccb_phys; /* phys. address */
864#ifdef INT_COAL 864#ifdef INT_COAL
865 gdth_coal_status *coal_stat; /* buffer for coalescing int.*/ 865 gdth_coal_status *coal_stat; /* buffer for coalescing int.*/
866 ulong64 coal_stat_phys; /* phys. address */ 866 u64 coal_stat_phys; /* phys. address */
867#endif 867#endif
868 char *pscratch; /* scratch (DMA) buffer */ 868 char *pscratch; /* scratch (DMA) buffer */
869 ulong64 scratch_phys; /* phys. address */ 869 u64 scratch_phys; /* phys. address */
870 unchar scratch_busy; /* in use? */ 870 u8 scratch_busy; /* in use? */
871 unchar dma64_support; /* 64-bit DMA supported? */ 871 u8 dma64_support; /* 64-bit DMA supported? */
872 gdth_msg_str *pmsg; /* message buffer */ 872 gdth_msg_str *pmsg; /* message buffer */
873 ulong64 msg_phys; /* phys. address */ 873 u64 msg_phys; /* phys. address */
874 unchar scan_mode; /* current scan mode */ 874 u8 scan_mode; /* current scan mode */
875 unchar irq; /* IRQ */ 875 u8 irq; /* IRQ */
876 unchar drq; /* DRQ (ISA controllers) */ 876 u8 drq; /* DRQ (ISA controllers) */
877 ushort status; /* command status */ 877 u16 status; /* command status */
878 ushort service; /* service/firmware ver./.. */ 878 u16 service; /* service/firmware ver./.. */
879 ulong32 info; 879 u32 info;
880 ulong32 info2; /* additional info */ 880 u32 info2; /* additional info */
881 Scsi_Cmnd *req_first; /* top of request queue */ 881 Scsi_Cmnd *req_first; /* top of request queue */
882 struct { 882 struct {
883 unchar present; /* Flag: host drive present? */ 883 u8 present; /* Flag: host drive present? */
884 unchar is_logdrv; /* Flag: log. drive (master)? */ 884 u8 is_logdrv; /* Flag: log. drive (master)? */
885 unchar is_arraydrv; /* Flag: array drive? */ 885 u8 is_arraydrv; /* Flag: array drive? */
886 unchar is_master; /* Flag: array drive master? */ 886 u8 is_master; /* Flag: array drive master? */
887 unchar is_parity; /* Flag: parity drive? */ 887 u8 is_parity; /* Flag: parity drive? */
888 unchar is_hotfix; /* Flag: hotfix drive? */ 888 u8 is_hotfix; /* Flag: hotfix drive? */
889 unchar master_no; /* number of master drive */ 889 u8 master_no; /* number of master drive */
890 unchar lock; /* drive locked? (hot plug) */ 890 u8 lock; /* drive locked? (hot plug) */
891 unchar heads; /* mapping */ 891 u8 heads; /* mapping */
892 unchar secs; 892 u8 secs;
893 ushort devtype; /* further information */ 893 u16 devtype; /* further information */
894 ulong64 size; /* capacity */ 894 u64 size; /* capacity */
895 unchar ldr_no; /* log. drive no. */ 895 u8 ldr_no; /* log. drive no. */
896 unchar rw_attribs; /* r/w attributes */ 896 u8 rw_attribs; /* r/w attributes */
897 unchar cluster_type; /* cluster properties */ 897 u8 cluster_type; /* cluster properties */
898 unchar media_changed; /* Flag:MOUNT/UNMOUNT occured */ 898 u8 media_changed; /* Flag:MOUNT/UNMOUNT occured */
899 ulong32 start_sec; /* start sector */ 899 u32 start_sec; /* start sector */
900 } hdr[MAX_LDRIVES]; /* host drives */ 900 } hdr[MAX_LDRIVES]; /* host drives */
901 struct { 901 struct {
902 unchar lock; /* channel locked? (hot plug) */ 902 u8 lock; /* channel locked? (hot plug) */
903 unchar pdev_cnt; /* physical device count */ 903 u8 pdev_cnt; /* physical device count */
904 unchar local_no; /* local channel number */ 904 u8 local_no; /* local channel number */
905 unchar io_cnt[MAXID]; /* current IO count */ 905 u8 io_cnt[MAXID]; /* current IO count */
906 ulong32 address; /* channel address */ 906 u32 address; /* channel address */
907 ulong32 id_list[MAXID]; /* IDs of the phys. devices */ 907 u32 id_list[MAXID]; /* IDs of the phys. devices */
908 } raw[MAXBUS]; /* SCSI channels */ 908 } raw[MAXBUS]; /* SCSI channels */
909 struct { 909 struct {
910 Scsi_Cmnd *cmnd; /* pending request */ 910 Scsi_Cmnd *cmnd; /* pending request */
911 ushort service; /* service */ 911 u16 service; /* service */
912 } cmd_tab[GDTH_MAXCMDS]; /* table of pend. requests */ 912 } cmd_tab[GDTH_MAXCMDS]; /* table of pend. requests */
913 struct gdth_cmndinfo { /* per-command private info */ 913 struct gdth_cmndinfo { /* per-command private info */
914 int index; 914 int index;
915 int internal_command; /* don't call scsi_done */ 915 int internal_command; /* don't call scsi_done */
916 gdth_cmd_str *internal_cmd_str; /* crier for internal messages*/ 916 gdth_cmd_str *internal_cmd_str; /* crier for internal messages*/
917 dma_addr_t sense_paddr; /* sense dma-addr */ 917 dma_addr_t sense_paddr; /* sense dma-addr */
918 unchar priority; 918 u8 priority;
919 int timeout_count; /* # of timeout calls */ 919 int timeout_count; /* # of timeout calls */
920 volatile int wait_for_completion; 920 volatile int wait_for_completion;
921 ushort status; 921 u16 status;
922 ulong32 info; 922 u32 info;
923 enum dma_data_direction dma_dir; 923 enum dma_data_direction dma_dir;
924 int phase; /* ???? */ 924 int phase; /* ???? */
925 int OpCode; 925 int OpCode;
926 } cmndinfo[GDTH_MAXCMDS]; /* index==0 is free */ 926 } cmndinfo[GDTH_MAXCMDS]; /* index==0 is free */
927 unchar bus_cnt; /* SCSI bus count */ 927 u8 bus_cnt; /* SCSI bus count */
928 unchar tid_cnt; /* Target ID count */ 928 u8 tid_cnt; /* Target ID count */
929 unchar bus_id[MAXBUS]; /* IOP IDs */ 929 u8 bus_id[MAXBUS]; /* IOP IDs */
930 unchar virt_bus; /* number of virtual bus */ 930 u8 virt_bus; /* number of virtual bus */
931 unchar more_proc; /* more /proc info supported */ 931 u8 more_proc; /* more /proc info supported */
932 ushort cmd_cnt; /* command count in DPRAM */ 932 u16 cmd_cnt; /* command count in DPRAM */
933 ushort cmd_len; /* length of actual command */ 933 u16 cmd_len; /* length of actual command */
934 ushort cmd_offs_dpmem; /* actual offset in DPRAM */ 934 u16 cmd_offs_dpmem; /* actual offset in DPRAM */
935 ushort ic_all_size; /* sizeof DPRAM interf. area */ 935 u16 ic_all_size; /* sizeof DPRAM interf. area */
936 gdth_cpar_str cpar; /* controller cache par. */ 936 gdth_cpar_str cpar; /* controller cache par. */
937 gdth_bfeat_str bfeat; /* controller features */ 937 gdth_bfeat_str bfeat; /* controller features */
938 gdth_binfo_str binfo; /* controller info */ 938 gdth_binfo_str binfo; /* controller info */
@@ -941,7 +941,7 @@ typedef struct {
941 struct pci_dev *pdev; 941 struct pci_dev *pdev;
942 char oem_name[8]; 942 char oem_name[8];
943#ifdef GDTH_DMA_STATISTICS 943#ifdef GDTH_DMA_STATISTICS
944 ulong dma32_cnt, dma64_cnt; /* statistics: DMA buffer */ 944 unsigned long dma32_cnt, dma64_cnt; /* statistics: DMA buffer */
945#endif 945#endif
946 struct scsi_device *sdev; 946 struct scsi_device *sdev;
947} gdth_ha_str; 947} gdth_ha_str;
@@ -953,65 +953,65 @@ static inline struct gdth_cmndinfo *gdth_cmnd_priv(struct scsi_cmnd* cmd)
953 953
954/* INQUIRY data format */ 954/* INQUIRY data format */
955typedef struct { 955typedef struct {
956 unchar type_qual; 956 u8 type_qual;
957 unchar modif_rmb; 957 u8 modif_rmb;
958 unchar version; 958 u8 version;
959 unchar resp_aenc; 959 u8 resp_aenc;
960 unchar add_length; 960 u8 add_length;
961 unchar reserved1; 961 u8 reserved1;
962 unchar reserved2; 962 u8 reserved2;
963 unchar misc; 963 u8 misc;
964 unchar vendor[8]; 964 u8 vendor[8];
965 unchar product[16]; 965 u8 product[16];
966 unchar revision[4]; 966 u8 revision[4];
967} PACKED gdth_inq_data; 967} __attribute__((packed)) gdth_inq_data;
968 968
969/* READ_CAPACITY data format */ 969/* READ_CAPACITY data format */
970typedef struct { 970typedef struct {
971 ulong32 last_block_no; 971 u32 last_block_no;
972 ulong32 block_length; 972 u32 block_length;
973} PACKED gdth_rdcap_data; 973} __attribute__((packed)) gdth_rdcap_data;
974 974
975/* READ_CAPACITY (16) data format */ 975/* READ_CAPACITY (16) data format */
976typedef struct { 976typedef struct {
977 ulong64 last_block_no; 977 u64 last_block_no;
978 ulong32 block_length; 978 u32 block_length;
979} PACKED gdth_rdcap16_data; 979} __attribute__((packed)) gdth_rdcap16_data;
980 980
981/* REQUEST_SENSE data format */ 981/* REQUEST_SENSE data format */
982typedef struct { 982typedef struct {
983 unchar errorcode; 983 u8 errorcode;
984 unchar segno; 984 u8 segno;
985 unchar key; 985 u8 key;
986 ulong32 info; 986 u32 info;
987 unchar add_length; 987 u8 add_length;
988 ulong32 cmd_info; 988 u32 cmd_info;
989 unchar adsc; 989 u8 adsc;
990 unchar adsq; 990 u8 adsq;
991 unchar fruc; 991 u8 fruc;
992 unchar key_spec[3]; 992 u8 key_spec[3];
993} PACKED gdth_sense_data; 993} __attribute__((packed)) gdth_sense_data;
994 994
995/* MODE_SENSE data format */ 995/* MODE_SENSE data format */
996typedef struct { 996typedef struct {
997 struct { 997 struct {
998 unchar data_length; 998 u8 data_length;
999 unchar med_type; 999 u8 med_type;
1000 unchar dev_par; 1000 u8 dev_par;
1001 unchar bd_length; 1001 u8 bd_length;
1002 } PACKED hd; 1002 } __attribute__((packed)) hd;
1003 struct { 1003 struct {
1004 unchar dens_code; 1004 u8 dens_code;
1005 unchar block_count[3]; 1005 u8 block_count[3];
1006 unchar reserved; 1006 u8 reserved;
1007 unchar block_length[3]; 1007 u8 block_length[3];
1008 } PACKED bd; 1008 } __attribute__((packed)) bd;
1009} PACKED gdth_modep_data; 1009} __attribute__((packed)) gdth_modep_data;
1010 1010
1011/* stack frame */ 1011/* stack frame */
1012typedef struct { 1012typedef struct {
1013 ulong b[10]; /* 32/64 bit compiler ! */ 1013 unsigned long b[10]; /* 32/64 bit compiler ! */
1014} PACKED gdth_stackframe; 1014} __attribute__((packed)) gdth_stackframe;
1015 1015
1016 1016
1017/* function prototyping */ 1017/* function prototyping */
diff --git a/drivers/scsi/gdth_ioctl.h b/drivers/scsi/gdth_ioctl.h
index 783fae737f17..b004c6165887 100644
--- a/drivers/scsi/gdth_ioctl.h
+++ b/drivers/scsi/gdth_ioctl.h
@@ -32,109 +32,101 @@
32#define MAX_HDRIVES MAX_LDRIVES /* max. host drive count */ 32#define MAX_HDRIVES MAX_LDRIVES /* max. host drive count */
33#endif 33#endif
34 34
35/* typedefs */
36#ifdef __KERNEL__
37typedef u32 ulong32;
38typedef u64 ulong64;
39#endif
40
41#define PACKED __attribute__((packed))
42
43/* scatter/gather element */ 35/* scatter/gather element */
44typedef struct { 36typedef struct {
45 ulong32 sg_ptr; /* address */ 37 u32 sg_ptr; /* address */
46 ulong32 sg_len; /* length */ 38 u32 sg_len; /* length */
47} PACKED gdth_sg_str; 39} __attribute__((packed)) gdth_sg_str;
48 40
49/* scatter/gather element - 64bit addresses */ 41/* scatter/gather element - 64bit addresses */
50typedef struct { 42typedef struct {
51 ulong64 sg_ptr; /* address */ 43 u64 sg_ptr; /* address */
52 ulong32 sg_len; /* length */ 44 u32 sg_len; /* length */
53} PACKED gdth_sg64_str; 45} __attribute__((packed)) gdth_sg64_str;
54 46
55/* command structure */ 47/* command structure */
56typedef struct { 48typedef struct {
57 ulong32 BoardNode; /* board node (always 0) */ 49 u32 BoardNode; /* board node (always 0) */
58 ulong32 CommandIndex; /* command number */ 50 u32 CommandIndex; /* command number */
59 ushort OpCode; /* the command (READ,..) */ 51 u16 OpCode; /* the command (READ,..) */
60 union { 52 union {
61 struct { 53 struct {
62 ushort DeviceNo; /* number of cache drive */ 54 u16 DeviceNo; /* number of cache drive */
63 ulong32 BlockNo; /* block number */ 55 u32 BlockNo; /* block number */
64 ulong32 BlockCnt; /* block count */ 56 u32 BlockCnt; /* block count */
65 ulong32 DestAddr; /* dest. addr. (if s/g: -1) */ 57 u32 DestAddr; /* dest. addr. (if s/g: -1) */
66 ulong32 sg_canz; /* s/g element count */ 58 u32 sg_canz; /* s/g element count */
67 gdth_sg_str sg_lst[GDTH_MAXSG]; /* s/g list */ 59 gdth_sg_str sg_lst[GDTH_MAXSG]; /* s/g list */
68 } PACKED cache; /* cache service cmd. str. */ 60 } __attribute__((packed)) cache; /* cache service cmd. str. */
69 struct { 61 struct {
70 ushort DeviceNo; /* number of cache drive */ 62 u16 DeviceNo; /* number of cache drive */
71 ulong64 BlockNo; /* block number */ 63 u64 BlockNo; /* block number */
72 ulong32 BlockCnt; /* block count */ 64 u32 BlockCnt; /* block count */
73 ulong64 DestAddr; /* dest. addr. (if s/g: -1) */ 65 u64 DestAddr; /* dest. addr. (if s/g: -1) */
74 ulong32 sg_canz; /* s/g element count */ 66 u32 sg_canz; /* s/g element count */
75 gdth_sg64_str sg_lst[GDTH_MAXSG]; /* s/g list */ 67 gdth_sg64_str sg_lst[GDTH_MAXSG]; /* s/g list */
76 } PACKED cache64; /* cache service cmd. str. */ 68 } __attribute__((packed)) cache64; /* cache service cmd. str. */
77 struct { 69 struct {
78 ushort param_size; /* size of p_param buffer */ 70 u16 param_size; /* size of p_param buffer */
79 ulong32 subfunc; /* IOCTL function */ 71 u32 subfunc; /* IOCTL function */
80 ulong32 channel; /* device */ 72 u32 channel; /* device */
81 ulong64 p_param; /* buffer */ 73 u64 p_param; /* buffer */
82 } PACKED ioctl; /* IOCTL command structure */ 74 } __attribute__((packed)) ioctl; /* IOCTL command structure */
83 struct { 75 struct {
84 ushort reserved; 76 u16 reserved;
85 union { 77 union {
86 struct { 78 struct {
87 ulong32 msg_handle; /* message handle */ 79 u32 msg_handle; /* message handle */
88 ulong64 msg_addr; /* message buffer address */ 80 u64 msg_addr; /* message buffer address */
89 } PACKED msg; 81 } __attribute__((packed)) msg;
90 unchar data[12]; /* buffer for rtc data, ... */ 82 u8 data[12]; /* buffer for rtc data, ... */
91 } su; 83 } su;
92 } PACKED screen; /* screen service cmd. str. */ 84 } __attribute__((packed)) screen; /* screen service cmd. str. */
93 struct { 85 struct {
94 ushort reserved; 86 u16 reserved;
95 ulong32 direction; /* data direction */ 87 u32 direction; /* data direction */
96 ulong32 mdisc_time; /* disc. time (0: no timeout)*/ 88 u32 mdisc_time; /* disc. time (0: no timeout)*/
97 ulong32 mcon_time; /* connect time(0: no to.) */ 89 u32 mcon_time; /* connect time(0: no to.) */
98 ulong32 sdata; /* dest. addr. (if s/g: -1) */ 90 u32 sdata; /* dest. addr. (if s/g: -1) */
99 ulong32 sdlen; /* data length (bytes) */ 91 u32 sdlen; /* data length (bytes) */
100 ulong32 clen; /* SCSI cmd. length(6,10,12) */ 92 u32 clen; /* SCSI cmd. length(6,10,12) */
101 unchar cmd[12]; /* SCSI command */ 93 u8 cmd[12]; /* SCSI command */
102 unchar target; /* target ID */ 94 u8 target; /* target ID */
103 unchar lun; /* LUN */ 95 u8 lun; /* LUN */
104 unchar bus; /* SCSI bus number */ 96 u8 bus; /* SCSI bus number */
105 unchar priority; /* only 0 used */ 97 u8 priority; /* only 0 used */
106 ulong32 sense_len; /* sense data length */ 98 u32 sense_len; /* sense data length */
107 ulong32 sense_data; /* sense data addr. */ 99 u32 sense_data; /* sense data addr. */
108 ulong32 link_p; /* linked cmds (not supp.) */ 100 u32 link_p; /* linked cmds (not supp.) */
109 ulong32 sg_ranz; /* s/g element count */ 101 u32 sg_ranz; /* s/g element count */
110 gdth_sg_str sg_lst[GDTH_MAXSG]; /* s/g list */ 102 gdth_sg_str sg_lst[GDTH_MAXSG]; /* s/g list */
111 } PACKED raw; /* raw service cmd. struct. */ 103 } __attribute__((packed)) raw; /* raw service cmd. struct. */
112 struct { 104 struct {
113 ushort reserved; 105 u16 reserved;
114 ulong32 direction; /* data direction */ 106 u32 direction; /* data direction */
115 ulong32 mdisc_time; /* disc. time (0: no timeout)*/ 107 u32 mdisc_time; /* disc. time (0: no timeout)*/
116 ulong32 mcon_time; /* connect time(0: no to.) */ 108 u32 mcon_time; /* connect time(0: no to.) */
117 ulong64 sdata; /* dest. addr. (if s/g: -1) */ 109 u64 sdata; /* dest. addr. (if s/g: -1) */
118 ulong32 sdlen; /* data length (bytes) */ 110 u32 sdlen; /* data length (bytes) */
119 ulong32 clen; /* SCSI cmd. length(6,..,16) */ 111 u32 clen; /* SCSI cmd. length(6,..,16) */
120 unchar cmd[16]; /* SCSI command */ 112 u8 cmd[16]; /* SCSI command */
121 unchar target; /* target ID */ 113 u8 target; /* target ID */
122 unchar lun; /* LUN */ 114 u8 lun; /* LUN */
123 unchar bus; /* SCSI bus number */ 115 u8 bus; /* SCSI bus number */
124 unchar priority; /* only 0 used */ 116 u8 priority; /* only 0 used */
125 ulong32 sense_len; /* sense data length */ 117 u32 sense_len; /* sense data length */
126 ulong64 sense_data; /* sense data addr. */ 118 u64 sense_data; /* sense data addr. */
127 ulong32 sg_ranz; /* s/g element count */ 119 u32 sg_ranz; /* s/g element count */
128 gdth_sg64_str sg_lst[GDTH_MAXSG]; /* s/g list */ 120 gdth_sg64_str sg_lst[GDTH_MAXSG]; /* s/g list */
129 } PACKED raw64; /* raw service cmd. struct. */ 121 } __attribute__((packed)) raw64; /* raw service cmd. struct. */
130 } u; 122 } u;
131 /* additional variables */ 123 /* additional variables */
132 unchar Service; /* controller service */ 124 u8 Service; /* controller service */
133 unchar reserved; 125 u8 reserved;
134 ushort Status; /* command result */ 126 u16 Status; /* command result */
135 ulong32 Info; /* additional information */ 127 u32 Info; /* additional information */
136 void *RequestBuffer; /* request buffer */ 128 void *RequestBuffer; /* request buffer */
137} PACKED gdth_cmd_str; 129} __attribute__((packed)) gdth_cmd_str;
138 130
139/* controller event structure */ 131/* controller event structure */
140#define ES_ASYNC 1 132#define ES_ASYNC 1
@@ -142,129 +134,129 @@ typedef struct {
142#define ES_TEST 3 134#define ES_TEST 3
143#define ES_SYNC 4 135#define ES_SYNC 4
144typedef struct { 136typedef struct {
145 ushort size; /* size of structure */ 137 u16 size; /* size of structure */
146 union { 138 union {
147 char stream[16]; 139 char stream[16];
148 struct { 140 struct {
149 ushort ionode; 141 u16 ionode;
150 ushort service; 142 u16 service;
151 ulong32 index; 143 u32 index;
152 } PACKED driver; 144 } __attribute__((packed)) driver;
153 struct { 145 struct {
154 ushort ionode; 146 u16 ionode;
155 ushort service; 147 u16 service;
156 ushort status; 148 u16 status;
157 ulong32 info; 149 u32 info;
158 unchar scsi_coord[3]; 150 u8 scsi_coord[3];
159 } PACKED async; 151 } __attribute__((packed)) async;
160 struct { 152 struct {
161 ushort ionode; 153 u16 ionode;
162 ushort service; 154 u16 service;
163 ushort status; 155 u16 status;
164 ulong32 info; 156 u32 info;
165 ushort hostdrive; 157 u16 hostdrive;
166 unchar scsi_coord[3]; 158 u8 scsi_coord[3];
167 unchar sense_key; 159 u8 sense_key;
168 } PACKED sync; 160 } __attribute__((packed)) sync;
169 struct { 161 struct {
170 ulong32 l1, l2, l3, l4; 162 u32 l1, l2, l3, l4;
171 } PACKED test; 163 } __attribute__((packed)) test;
172 } eu; 164 } eu;
173 ulong32 severity; 165 u32 severity;
174 unchar event_string[256]; 166 u8 event_string[256];
175} PACKED gdth_evt_data; 167} __attribute__((packed)) gdth_evt_data;
176 168
177typedef struct { 169typedef struct {
178 ulong32 first_stamp; 170 u32 first_stamp;
179 ulong32 last_stamp; 171 u32 last_stamp;
180 ushort same_count; 172 u16 same_count;
181 ushort event_source; 173 u16 event_source;
182 ushort event_idx; 174 u16 event_idx;
183 unchar application; 175 u8 application;
184 unchar reserved; 176 u8 reserved;
185 gdth_evt_data event_data; 177 gdth_evt_data event_data;
186} PACKED gdth_evt_str; 178} __attribute__((packed)) gdth_evt_str;
187 179
188 180
189#ifdef GDTH_IOCTL_PROC 181#ifdef GDTH_IOCTL_PROC
190/* IOCTL structure (write) */ 182/* IOCTL structure (write) */
191typedef struct { 183typedef struct {
192 ulong32 magic; /* IOCTL magic */ 184 u32 magic; /* IOCTL magic */
193 ushort ioctl; /* IOCTL */ 185 u16 ioctl; /* IOCTL */
194 ushort ionode; /* controller number */ 186 u16 ionode; /* controller number */
195 ushort service; /* controller service */ 187 u16 service; /* controller service */
196 ushort timeout; /* timeout */ 188 u16 timeout; /* timeout */
197 union { 189 union {
198 struct { 190 struct {
199 unchar command[512]; /* controller command */ 191 u8 command[512]; /* controller command */
200 unchar data[1]; /* add. data */ 192 u8 data[1]; /* add. data */
201 } general; 193 } general;
202 struct { 194 struct {
203 unchar lock; /* lock/unlock */ 195 u8 lock; /* lock/unlock */
204 unchar drive_cnt; /* drive count */ 196 u8 drive_cnt; /* drive count */
205 ushort drives[MAX_HDRIVES];/* drives */ 197 u16 drives[MAX_HDRIVES];/* drives */
206 } lockdrv; 198 } lockdrv;
207 struct { 199 struct {
208 unchar lock; /* lock/unlock */ 200 u8 lock; /* lock/unlock */
209 unchar channel; /* channel */ 201 u8 channel; /* channel */
210 } lockchn; 202 } lockchn;
211 struct { 203 struct {
212 int erase; /* erase event ? */ 204 int erase; /* erase event ? */
213 int handle; 205 int handle;
214 unchar evt[EVENT_SIZE]; /* event structure */ 206 u8 evt[EVENT_SIZE]; /* event structure */
215 } event; 207 } event;
216 struct { 208 struct {
217 unchar bus; /* SCSI bus */ 209 u8 bus; /* SCSI bus */
218 unchar target; /* target ID */ 210 u8 target; /* target ID */
219 unchar lun; /* LUN */ 211 u8 lun; /* LUN */
220 unchar cmd_len; /* command length */ 212 u8 cmd_len; /* command length */
221 unchar cmd[12]; /* SCSI command */ 213 u8 cmd[12]; /* SCSI command */
222 } scsi; 214 } scsi;
223 struct { 215 struct {
224 ushort hdr_no; /* host drive number */ 216 u16 hdr_no; /* host drive number */
225 unchar flag; /* old meth./add/remove */ 217 u8 flag; /* old meth./add/remove */
226 } rescan; 218 } rescan;
227 } iu; 219 } iu;
228} gdth_iowr_str; 220} gdth_iowr_str;
229 221
230/* IOCTL structure (read) */ 222/* IOCTL structure (read) */
231typedef struct { 223typedef struct {
232 ulong32 size; /* buffer size */ 224 u32 size; /* buffer size */
233 ulong32 status; /* IOCTL error code */ 225 u32 status; /* IOCTL error code */
234 union { 226 union {
235 struct { 227 struct {
236 unchar data[1]; /* data */ 228 u8 data[1]; /* data */
237 } general; 229 } general;
238 struct { 230 struct {
239 ushort version; /* driver version */ 231 u16 version; /* driver version */
240 } drvers; 232 } drvers;
241 struct { 233 struct {
242 unchar type; /* controller type */ 234 u8 type; /* controller type */
243 ushort info; /* slot etc. */ 235 u16 info; /* slot etc. */
244 ushort oem_id; /* OEM ID */ 236 u16 oem_id; /* OEM ID */
245 ushort bios_ver; /* not used */ 237 u16 bios_ver; /* not used */
246 ushort access; /* not used */ 238 u16 access; /* not used */
247 ushort ext_type; /* extended type */ 239 u16 ext_type; /* extended type */
248 ushort device_id; /* device ID */ 240 u16 device_id; /* device ID */
249 ushort sub_device_id; /* sub device ID */ 241 u16 sub_device_id; /* sub device ID */
250 } ctrtype; 242 } ctrtype;
251 struct { 243 struct {
252 unchar version; /* OS version */ 244 u8 version; /* OS version */
253 unchar subversion; /* OS subversion */ 245 u8 subversion; /* OS subversion */
254 ushort revision; /* revision */ 246 u16 revision; /* revision */
255 } osvers; 247 } osvers;
256 struct { 248 struct {
257 ushort count; /* controller count */ 249 u16 count; /* controller count */
258 } ctrcnt; 250 } ctrcnt;
259 struct { 251 struct {
260 int handle; 252 int handle;
261 unchar evt[EVENT_SIZE]; /* event structure */ 253 u8 evt[EVENT_SIZE]; /* event structure */
262 } event; 254 } event;
263 struct { 255 struct {
264 unchar bus; /* SCSI bus, 0xff: invalid */ 256 u8 bus; /* SCSI bus, 0xff: invalid */
265 unchar target; /* target ID */ 257 u8 target; /* target ID */
266 unchar lun; /* LUN */ 258 u8 lun; /* LUN */
267 unchar cluster_type; /* cluster properties */ 259 u8 cluster_type; /* cluster properties */
268 } hdr_list[MAX_HDRIVES]; /* index is host drive number */ 260 } hdr_list[MAX_HDRIVES]; /* index is host drive number */
269 } iu; 261 } iu;
270} gdth_iord_str; 262} gdth_iord_str;
@@ -272,53 +264,53 @@ typedef struct {
272 264
273/* GDTIOCTL_GENERAL */ 265/* GDTIOCTL_GENERAL */
274typedef struct { 266typedef struct {
275 ushort ionode; /* controller number */ 267 u16 ionode; /* controller number */
276 ushort timeout; /* timeout */ 268 u16 timeout; /* timeout */
277 ulong32 info; /* error info */ 269 u32 info; /* error info */
278 ushort status; /* status */ 270 u16 status; /* status */
279 ulong data_len; /* data buffer size */ 271 unsigned long data_len; /* data buffer size */
280 ulong sense_len; /* sense buffer size */ 272 unsigned long sense_len; /* sense buffer size */
281 gdth_cmd_str command; /* command */ 273 gdth_cmd_str command; /* command */
282} gdth_ioctl_general; 274} gdth_ioctl_general;
283 275
284/* GDTIOCTL_LOCKDRV */ 276/* GDTIOCTL_LOCKDRV */
285typedef struct { 277typedef struct {
286 ushort ionode; /* controller number */ 278 u16 ionode; /* controller number */
287 unchar lock; /* lock/unlock */ 279 u8 lock; /* lock/unlock */
288 unchar drive_cnt; /* drive count */ 280 u8 drive_cnt; /* drive count */
289 ushort drives[MAX_HDRIVES]; /* drives */ 281 u16 drives[MAX_HDRIVES]; /* drives */
290} gdth_ioctl_lockdrv; 282} gdth_ioctl_lockdrv;
291 283
292/* GDTIOCTL_LOCKCHN */ 284/* GDTIOCTL_LOCKCHN */
293typedef struct { 285typedef struct {
294 ushort ionode; /* controller number */ 286 u16 ionode; /* controller number */
295 unchar lock; /* lock/unlock */ 287 u8 lock; /* lock/unlock */
296 unchar channel; /* channel */ 288 u8 channel; /* channel */
297} gdth_ioctl_lockchn; 289} gdth_ioctl_lockchn;
298 290
299/* GDTIOCTL_OSVERS */ 291/* GDTIOCTL_OSVERS */
300typedef struct { 292typedef struct {
301 unchar version; /* OS version */ 293 u8 version; /* OS version */
302 unchar subversion; /* OS subversion */ 294 u8 subversion; /* OS subversion */
303 ushort revision; /* revision */ 295 u16 revision; /* revision */
304} gdth_ioctl_osvers; 296} gdth_ioctl_osvers;
305 297
306/* GDTIOCTL_CTRTYPE */ 298/* GDTIOCTL_CTRTYPE */
307typedef struct { 299typedef struct {
308 ushort ionode; /* controller number */ 300 u16 ionode; /* controller number */
309 unchar type; /* controller type */ 301 u8 type; /* controller type */
310 ushort info; /* slot etc. */ 302 u16 info; /* slot etc. */
311 ushort oem_id; /* OEM ID */ 303 u16 oem_id; /* OEM ID */
312 ushort bios_ver; /* not used */ 304 u16 bios_ver; /* not used */
313 ushort access; /* not used */ 305 u16 access; /* not used */
314 ushort ext_type; /* extended type */ 306 u16 ext_type; /* extended type */
315 ushort device_id; /* device ID */ 307 u16 device_id; /* device ID */
316 ushort sub_device_id; /* sub device ID */ 308 u16 sub_device_id; /* sub device ID */
317} gdth_ioctl_ctrtype; 309} gdth_ioctl_ctrtype;
318 310
319/* GDTIOCTL_EVENT */ 311/* GDTIOCTL_EVENT */
320typedef struct { 312typedef struct {
321 ushort ionode; 313 u16 ionode;
322 int erase; /* erase event? */ 314 int erase; /* erase event? */
323 int handle; /* event handle */ 315 int handle; /* event handle */
324 gdth_evt_str event; 316 gdth_evt_str event;
@@ -326,22 +318,22 @@ typedef struct {
326 318
327/* GDTIOCTL_RESCAN/GDTIOCTL_HDRLIST */ 319/* GDTIOCTL_RESCAN/GDTIOCTL_HDRLIST */
328typedef struct { 320typedef struct {
329 ushort ionode; /* controller number */ 321 u16 ionode; /* controller number */
330 unchar flag; /* add/remove */ 322 u8 flag; /* add/remove */
331 ushort hdr_no; /* drive no. */ 323 u16 hdr_no; /* drive no. */
332 struct { 324 struct {
333 unchar bus; /* SCSI bus */ 325 u8 bus; /* SCSI bus */
334 unchar target; /* target ID */ 326 u8 target; /* target ID */
335 unchar lun; /* LUN */ 327 u8 lun; /* LUN */
336 unchar cluster_type; /* cluster properties */ 328 u8 cluster_type; /* cluster properties */
337 } hdr_list[MAX_HDRIVES]; /* index is host drive number */ 329 } hdr_list[MAX_HDRIVES]; /* index is host drive number */
338} gdth_ioctl_rescan; 330} gdth_ioctl_rescan;
339 331
340/* GDTIOCTL_RESET_BUS/GDTIOCTL_RESET_DRV */ 332/* GDTIOCTL_RESET_BUS/GDTIOCTL_RESET_DRV */
341typedef struct { 333typedef struct {
342 ushort ionode; /* controller number */ 334 u16 ionode; /* controller number */
343 ushort number; /* bus/host drive number */ 335 u16 number; /* bus/host drive number */
344 ushort status; /* status */ 336 u16 status; /* status */
345} gdth_ioctl_reset; 337} gdth_ioctl_reset;
346 338
347#endif 339#endif
diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
index 1258da34fbc2..ffb2b21992ba 100644
--- a/drivers/scsi/gdth_proc.c
+++ b/drivers/scsi/gdth_proc.c
@@ -43,7 +43,7 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
43 int i, found; 43 int i, found;
44 gdth_cmd_str gdtcmd; 44 gdth_cmd_str gdtcmd;
45 gdth_cpar_str *pcpar; 45 gdth_cpar_str *pcpar;
46 ulong64 paddr; 46 u64 paddr;
47 47
48 char cmnd[MAX_COMMAND_SIZE]; 48 char cmnd[MAX_COMMAND_SIZE];
49 memset(cmnd, 0xff, 12); 49 memset(cmnd, 0xff, 12);
@@ -156,8 +156,8 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
156 off_t begin = 0,pos = 0; 156 off_t begin = 0,pos = 0;
157 int id, i, j, k, sec, flag; 157 int id, i, j, k, sec, flag;
158 int no_mdrv = 0, drv_no, is_mirr; 158 int no_mdrv = 0, drv_no, is_mirr;
159 ulong32 cnt; 159 u32 cnt;
160 ulong64 paddr; 160 u64 paddr;
161 int rc = -ENOMEM; 161 int rc = -ENOMEM;
162 162
163 gdth_cmd_str *gdtcmd; 163 gdth_cmd_str *gdtcmd;
@@ -220,14 +220,14 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
220 220
221 if (ha->more_proc) 221 if (ha->more_proc)
222 sprintf(hrec, "%d.%02d.%02d-%c%03X", 222 sprintf(hrec, "%d.%02d.%02d-%c%03X",
223 (unchar)(ha->binfo.upd_fw_ver>>24), 223 (u8)(ha->binfo.upd_fw_ver>>24),
224 (unchar)(ha->binfo.upd_fw_ver>>16), 224 (u8)(ha->binfo.upd_fw_ver>>16),
225 (unchar)(ha->binfo.upd_fw_ver), 225 (u8)(ha->binfo.upd_fw_ver),
226 ha->bfeat.raid ? 'R':'N', 226 ha->bfeat.raid ? 'R':'N',
227 ha->binfo.upd_revision); 227 ha->binfo.upd_revision);
228 else 228 else
229 sprintf(hrec, "%d.%02d", (unchar)(ha->cpar.version>>8), 229 sprintf(hrec, "%d.%02d", (u8)(ha->cpar.version>>8),
230 (unchar)(ha->cpar.version)); 230 (u8)(ha->cpar.version));
231 231
232 size = sprintf(buffer+len, 232 size = sprintf(buffer+len,
233 " Driver Ver.: \t%-10s\tFirmware Ver.: \t%s\n", 233 " Driver Ver.: \t%-10s\tFirmware Ver.: \t%s\n",
@@ -281,7 +281,7 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
281 pds->bid = ha->raw[i].local_no; 281 pds->bid = ha->raw[i].local_no;
282 pds->first = 0; 282 pds->first = 0;
283 pds->entries = ha->raw[i].pdev_cnt; 283 pds->entries = ha->raw[i].pdev_cnt;
284 cnt = (3*GDTH_SCRATCH/4 - 5 * sizeof(ulong32)) / 284 cnt = (3*GDTH_SCRATCH/4 - 5 * sizeof(u32)) /
285 sizeof(pds->list[0]); 285 sizeof(pds->list[0]);
286 if (pds->entries > cnt) 286 if (pds->entries > cnt)
287 pds->entries = cnt; 287 pds->entries = cnt;
@@ -604,7 +604,7 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
604 604
605 size = sprintf(buffer+len, 605 size = sprintf(buffer+len,
606 " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n", 606 " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n",
607 (ulong32)(ha->hdr[i].size/2048), ha->hdr[i].start_sec); 607 (u32)(ha->hdr[i].size/2048), ha->hdr[i].start_sec);
608 len += size; pos = begin + len; 608 len += size; pos = begin + len;
609 if (pos < offset) { 609 if (pos < offset) {
610 len = 0; 610 len = 0;
@@ -664,9 +664,9 @@ free_fail:
664} 664}
665 665
666static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch, 666static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
667 ulong64 *paddr) 667 u64 *paddr)
668{ 668{
669 ulong flags; 669 unsigned long flags;
670 char *ret_val; 670 char *ret_val;
671 671
672 if (size == 0) 672 if (size == 0)
@@ -691,9 +691,9 @@ static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
691 return ret_val; 691 return ret_val;
692} 692}
693 693
694static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, ulong64 paddr) 694static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr)
695{ 695{
696 ulong flags; 696 unsigned long flags;
697 697
698 if (buf == ha->pscratch) { 698 if (buf == ha->pscratch) {
699 spin_lock_irqsave(&ha->smp_lock, flags); 699 spin_lock_irqsave(&ha->smp_lock, flags);
@@ -705,16 +705,16 @@ static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, ulong64 paddr)
705} 705}
706 706
707#ifdef GDTH_IOCTL_PROC 707#ifdef GDTH_IOCTL_PROC
708static int gdth_ioctl_check_bin(gdth_ha_str *ha, ushort size) 708static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size)
709{ 709{
710 ulong flags; 710 unsigned long flags;
711 int ret_val; 711 int ret_val;
712 712
713 spin_lock_irqsave(&ha->smp_lock, flags); 713 spin_lock_irqsave(&ha->smp_lock, flags);
714 714
715 ret_val = FALSE; 715 ret_val = FALSE;
716 if (ha->scratch_busy) { 716 if (ha->scratch_busy) {
717 if (((gdth_iord_str *)ha->pscratch)->size == (ulong32)size) 717 if (((gdth_iord_str *)ha->pscratch)->size == (u32)size)
718 ret_val = TRUE; 718 ret_val = TRUE;
719 } 719 }
720 spin_unlock_irqrestore(&ha->smp_lock, flags); 720 spin_unlock_irqrestore(&ha->smp_lock, flags);
@@ -724,11 +724,11 @@ static int gdth_ioctl_check_bin(gdth_ha_str *ha, ushort size)
724 724
725static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id) 725static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
726{ 726{
727 ulong flags; 727 unsigned long flags;
728 int i; 728 int i;
729 Scsi_Cmnd *scp; 729 Scsi_Cmnd *scp;
730 struct gdth_cmndinfo *cmndinfo; 730 struct gdth_cmndinfo *cmndinfo;
731 unchar b, t; 731 u8 b, t;
732 732
733 spin_lock_irqsave(&ha->smp_lock, flags); 733 spin_lock_irqsave(&ha->smp_lock, flags);
734 734
@@ -738,8 +738,8 @@ static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
738 738
739 b = scp->device->channel; 739 b = scp->device->channel;
740 t = scp->device->id; 740 t = scp->device->id;
741 if (!SPECIAL_SCP(scp) && t == (unchar)id && 741 if (!SPECIAL_SCP(scp) && t == (u8)id &&
742 b == (unchar)busnum) { 742 b == (u8)busnum) {
743 cmndinfo->wait_for_completion = 0; 743 cmndinfo->wait_for_completion = 0;
744 spin_unlock_irqrestore(&ha->smp_lock, flags); 744 spin_unlock_irqrestore(&ha->smp_lock, flags);
745 while (!cmndinfo->wait_for_completion) 745 while (!cmndinfo->wait_for_completion)
diff --git a/drivers/scsi/gdth_proc.h b/drivers/scsi/gdth_proc.h
index 9b900cc9ebe8..dab15f59f2cc 100644
--- a/drivers/scsi/gdth_proc.h
+++ b/drivers/scsi/gdth_proc.h
@@ -17,8 +17,8 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
17 int length, gdth_ha_str *ha); 17 int length, gdth_ha_str *ha);
18 18
19static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch, 19static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
20 ulong64 *paddr); 20 u64 *paddr);
21static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, ulong64 paddr); 21static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr);
22static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id); 22static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id);
23 23
24#endif 24#endif
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 554626e18062..09dbcb847b73 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -215,6 +215,8 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
215 shost->shost_gendev.parent = dev ? dev : &platform_bus; 215 shost->shost_gendev.parent = dev ? dev : &platform_bus;
216 shost->dma_dev = dma_dev; 216 shost->dma_dev = dma_dev;
217 217
218 device_enable_async_suspend(&shost->shost_gendev);
219
218 error = device_add(&shost->shost_gendev); 220 error = device_add(&shost->shost_gendev);
219 if (error) 221 if (error)
220 goto out; 222 goto out;
@@ -222,6 +224,8 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
222 scsi_host_set_state(shost, SHOST_RUNNING); 224 scsi_host_set_state(shost, SHOST_RUNNING);
223 get_device(shost->shost_gendev.parent); 225 get_device(shost->shost_gendev.parent);
224 226
227 device_enable_async_suspend(&shost->shost_dev);
228
225 error = device_add(&shost->shost_dev); 229 error = device_add(&shost->shost_dev);
226 if (error) 230 if (error)
227 goto out_del_gendev; 231 goto out_del_gendev;
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index bb96fdd58e23..03697ba94251 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -52,7 +52,7 @@
52#include "hpsa.h" 52#include "hpsa.h"
53 53
54/* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */ 54/* HPSA_DRIVER_VERSION must be 3 byte values (0-255) separated by '.' */
55#define HPSA_DRIVER_VERSION "1.0.0" 55#define HPSA_DRIVER_VERSION "2.0.1-3"
56#define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")" 56#define DRIVER_NAME "HP HPSA Driver (v " HPSA_DRIVER_VERSION ")"
57 57
58/* How long to wait (in milliseconds) for board to go into simple mode */ 58/* How long to wait (in milliseconds) for board to go into simple mode */
@@ -77,9 +77,6 @@ MODULE_PARM_DESC(hpsa_allow_any,
77 77
78/* define the PCI info for the cards we can control */ 78/* define the PCI info for the cards we can control */
79static const struct pci_device_id hpsa_pci_device_id[] = { 79static const struct pci_device_id hpsa_pci_device_id[] = {
80 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x3223},
81 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x3234},
82 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSC, 0x103C, 0x323D},
83 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3241}, 80 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3241},
84 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3243}, 81 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3243},
85 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3245}, 82 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3245},
@@ -87,6 +84,9 @@ static const struct pci_device_id hpsa_pci_device_id[] = {
87 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249}, 84 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3249},
88 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324a}, 85 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324a},
89 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324b}, 86 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x324b},
87 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSE, 0x103C, 0x3233},
88#define PCI_DEVICE_ID_HP_CISSF 0x333f
89 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSF, 0x103C, 0x333F},
90 {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 90 {PCI_VENDOR_ID_HP, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
91 PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0}, 91 PCI_CLASS_STORAGE_RAID << 8, 0xffff << 8, 0},
92 {0,} 92 {0,}
@@ -99,9 +99,6 @@ MODULE_DEVICE_TABLE(pci, hpsa_pci_device_id);
99 * access = Address of the struct of function pointers 99 * access = Address of the struct of function pointers
100 */ 100 */
101static struct board_type products[] = { 101static struct board_type products[] = {
102 {0x3223103C, "Smart Array P800", &SA5_access},
103 {0x3234103C, "Smart Array P400", &SA5_access},
104 {0x323d103c, "Smart Array P700M", &SA5_access},
105 {0x3241103C, "Smart Array P212", &SA5_access}, 102 {0x3241103C, "Smart Array P212", &SA5_access},
106 {0x3243103C, "Smart Array P410", &SA5_access}, 103 {0x3243103C, "Smart Array P410", &SA5_access},
107 {0x3245103C, "Smart Array P410i", &SA5_access}, 104 {0x3245103C, "Smart Array P410i", &SA5_access},
@@ -109,6 +106,8 @@ static struct board_type products[] = {
109 {0x3249103C, "Smart Array P812", &SA5_access}, 106 {0x3249103C, "Smart Array P812", &SA5_access},
110 {0x324a103C, "Smart Array P712m", &SA5_access}, 107 {0x324a103C, "Smart Array P712m", &SA5_access},
111 {0x324b103C, "Smart Array P711m", &SA5_access}, 108 {0x324b103C, "Smart Array P711m", &SA5_access},
109 {0x3233103C, "StorageWorks P1210m", &SA5_access},
110 {0x333F103C, "StorageWorks P1210m", &SA5_access},
112 {0xFFFF103C, "Unknown Smart Array", &SA5_access}, 111 {0xFFFF103C, "Unknown Smart Array", &SA5_access},
113}; 112};
114 113
@@ -126,12 +125,15 @@ static void cmd_free(struct ctlr_info *h, struct CommandList *c);
126static void cmd_special_free(struct ctlr_info *h, struct CommandList *c); 125static void cmd_special_free(struct ctlr_info *h, struct CommandList *c);
127static struct CommandList *cmd_alloc(struct ctlr_info *h); 126static struct CommandList *cmd_alloc(struct ctlr_info *h);
128static struct CommandList *cmd_special_alloc(struct ctlr_info *h); 127static struct CommandList *cmd_special_alloc(struct ctlr_info *h);
129static void fill_cmd(struct CommandList *c, __u8 cmd, struct ctlr_info *h, 128static void fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
130 void *buff, size_t size, __u8 page_code, unsigned char *scsi3addr, 129 void *buff, size_t size, u8 page_code, unsigned char *scsi3addr,
131 int cmd_type); 130 int cmd_type);
132 131
133static int hpsa_scsi_queue_command(struct scsi_cmnd *cmd, 132static int hpsa_scsi_queue_command(struct scsi_cmnd *cmd,
134 void (*done)(struct scsi_cmnd *)); 133 void (*done)(struct scsi_cmnd *));
134static void hpsa_scan_start(struct Scsi_Host *);
135static int hpsa_scan_finished(struct Scsi_Host *sh,
136 unsigned long elapsed_time);
135 137
136static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd); 138static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd);
137static int hpsa_slave_alloc(struct scsi_device *sdev); 139static int hpsa_slave_alloc(struct scsi_device *sdev);
@@ -150,6 +152,11 @@ static int check_for_unit_attention(struct ctlr_info *h,
150 struct CommandList *c); 152 struct CommandList *c);
151static void check_ioctl_unit_attention(struct ctlr_info *h, 153static void check_ioctl_unit_attention(struct ctlr_info *h,
152 struct CommandList *c); 154 struct CommandList *c);
155/* performant mode helper functions */
156static void calc_bucket_map(int *bucket, int num_buckets,
157 int nsgs, int *bucket_map);
158static void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h);
159static inline u32 next_command(struct ctlr_info *h);
153 160
154static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL); 161static DEVICE_ATTR(raid_level, S_IRUGO, raid_level_show, NULL);
155static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL); 162static DEVICE_ATTR(lunid, S_IRUGO, lunid_show, NULL);
@@ -173,10 +180,10 @@ static struct scsi_host_template hpsa_driver_template = {
173 .name = "hpsa", 180 .name = "hpsa",
174 .proc_name = "hpsa", 181 .proc_name = "hpsa",
175 .queuecommand = hpsa_scsi_queue_command, 182 .queuecommand = hpsa_scsi_queue_command,
176 .can_queue = 512, 183 .scan_start = hpsa_scan_start,
184 .scan_finished = hpsa_scan_finished,
177 .this_id = -1, 185 .this_id = -1,
178 .sg_tablesize = MAXSGENTRIES, 186 .sg_tablesize = MAXSGENTRIES,
179 .cmd_per_lun = 512,
180 .use_clustering = ENABLE_CLUSTERING, 187 .use_clustering = ENABLE_CLUSTERING,
181 .eh_device_reset_handler = hpsa_eh_device_reset_handler, 188 .eh_device_reset_handler = hpsa_eh_device_reset_handler,
182 .ioctl = hpsa_ioctl, 189 .ioctl = hpsa_ioctl,
@@ -195,6 +202,12 @@ static inline struct ctlr_info *sdev_to_hba(struct scsi_device *sdev)
195 return (struct ctlr_info *) *priv; 202 return (struct ctlr_info *) *priv;
196} 203}
197 204
205static inline struct ctlr_info *shost_to_hba(struct Scsi_Host *sh)
206{
207 unsigned long *priv = shost_priv(sh);
208 return (struct ctlr_info *) *priv;
209}
210
198static struct task_struct *hpsa_scan_thread; 211static struct task_struct *hpsa_scan_thread;
199static DEFINE_MUTEX(hpsa_scan_mutex); 212static DEFINE_MUTEX(hpsa_scan_mutex);
200static LIST_HEAD(hpsa_scan_q); 213static LIST_HEAD(hpsa_scan_q);
@@ -312,7 +325,7 @@ static int hpsa_scan_func(__attribute__((unused)) void *data)
312 h->busy_scanning = 1; 325 h->busy_scanning = 1;
313 mutex_unlock(&hpsa_scan_mutex); 326 mutex_unlock(&hpsa_scan_mutex);
314 host_no = h->scsi_host ? h->scsi_host->host_no : -1; 327 host_no = h->scsi_host ? h->scsi_host->host_no : -1;
315 hpsa_update_scsi_devices(h, host_no); 328 hpsa_scan_start(h->scsi_host);
316 complete_all(&h->scan_wait); 329 complete_all(&h->scan_wait);
317 mutex_lock(&hpsa_scan_mutex); 330 mutex_lock(&hpsa_scan_mutex);
318 h->busy_scanning = 0; 331 h->busy_scanning = 0;
@@ -379,8 +392,7 @@ static ssize_t host_store_rescan(struct device *dev,
379{ 392{
380 struct ctlr_info *h; 393 struct ctlr_info *h;
381 struct Scsi_Host *shost = class_to_shost(dev); 394 struct Scsi_Host *shost = class_to_shost(dev);
382 unsigned long *priv = shost_priv(shost); 395 h = shost_to_hba(shost);
383 h = (struct ctlr_info *) *priv;
384 if (add_to_scan_list(h)) { 396 if (add_to_scan_list(h)) {
385 wake_up_process(hpsa_scan_thread); 397 wake_up_process(hpsa_scan_thread);
386 wait_for_completion_interruptible(&h->scan_wait); 398 wait_for_completion_interruptible(&h->scan_wait);
@@ -394,10 +406,44 @@ static inline void addQ(struct hlist_head *list, struct CommandList *c)
394 hlist_add_head(&c->list, list); 406 hlist_add_head(&c->list, list);
395} 407}
396 408
409static inline u32 next_command(struct ctlr_info *h)
410{
411 u32 a;
412
413 if (unlikely(h->transMethod != CFGTBL_Trans_Performant))
414 return h->access.command_completed(h);
415
416 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
417 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
418 (h->reply_pool_head)++;
419 h->commands_outstanding--;
420 } else {
421 a = FIFO_EMPTY;
422 }
423 /* Check for wraparound */
424 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
425 h->reply_pool_head = h->reply_pool;
426 h->reply_pool_wraparound ^= 1;
427 }
428 return a;
429}
430
431/* set_performant_mode: Modify the tag for cciss performant
432 * set bit 0 for pull model, bits 3-1 for block fetch
433 * register number
434 */
435static void set_performant_mode(struct ctlr_info *h, struct CommandList *c)
436{
437 if (likely(h->transMethod == CFGTBL_Trans_Performant))
438 c->busaddr |= 1 | (h->blockFetchTable[c->Header.SGList] << 1);
439}
440
397static void enqueue_cmd_and_start_io(struct ctlr_info *h, 441static void enqueue_cmd_and_start_io(struct ctlr_info *h,
398 struct CommandList *c) 442 struct CommandList *c)
399{ 443{
400 unsigned long flags; 444 unsigned long flags;
445
446 set_performant_mode(h, c);
401 spin_lock_irqsave(&h->lock, flags); 447 spin_lock_irqsave(&h->lock, flags);
402 addQ(&h->reqQ, c); 448 addQ(&h->reqQ, c);
403 h->Qdepth++; 449 h->Qdepth++;
@@ -422,6 +468,15 @@ static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[])
422 return (scsi3addr[3] & 0xC0) == 0x40; 468 return (scsi3addr[3] & 0xC0) == 0x40;
423} 469}
424 470
471static inline int is_scsi_rev_5(struct ctlr_info *h)
472{
473 if (!h->hba_inquiry_data)
474 return 0;
475 if ((h->hba_inquiry_data[2] & 0x07) == 5)
476 return 1;
477 return 0;
478}
479
425static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", 480static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG",
426 "UNKNOWN" 481 "UNKNOWN"
427}; 482};
@@ -431,7 +486,7 @@ static ssize_t raid_level_show(struct device *dev,
431 struct device_attribute *attr, char *buf) 486 struct device_attribute *attr, char *buf)
432{ 487{
433 ssize_t l = 0; 488 ssize_t l = 0;
434 int rlevel; 489 unsigned char rlevel;
435 struct ctlr_info *h; 490 struct ctlr_info *h;
436 struct scsi_device *sdev; 491 struct scsi_device *sdev;
437 struct hpsa_scsi_dev_t *hdev; 492 struct hpsa_scsi_dev_t *hdev;
@@ -455,7 +510,7 @@ static ssize_t raid_level_show(struct device *dev,
455 510
456 rlevel = hdev->raid_level; 511 rlevel = hdev->raid_level;
457 spin_unlock_irqrestore(&h->lock, flags); 512 spin_unlock_irqrestore(&h->lock, flags);
458 if (rlevel < 0 || rlevel > RAID_UNKNOWN) 513 if (rlevel > RAID_UNKNOWN)
459 rlevel = RAID_UNKNOWN; 514 rlevel = RAID_UNKNOWN;
460 l = snprintf(buf, PAGE_SIZE, "RAID %s\n", raid_label[rlevel]); 515 l = snprintf(buf, PAGE_SIZE, "RAID %s\n", raid_label[rlevel]);
461 return l; 516 return l;
@@ -620,6 +675,24 @@ lun_assigned:
620 return 0; 675 return 0;
621} 676}
622 677
678/* Replace an entry from h->dev[] array. */
679static void hpsa_scsi_replace_entry(struct ctlr_info *h, int hostno,
680 int entry, struct hpsa_scsi_dev_t *new_entry,
681 struct hpsa_scsi_dev_t *added[], int *nadded,
682 struct hpsa_scsi_dev_t *removed[], int *nremoved)
683{
684 /* assumes h->devlock is held */
685 BUG_ON(entry < 0 || entry >= HPSA_MAX_SCSI_DEVS_PER_HBA);
686 removed[*nremoved] = h->dev[entry];
687 (*nremoved)++;
688 h->dev[entry] = new_entry;
689 added[*nadded] = new_entry;
690 (*nadded)++;
691 dev_info(&h->pdev->dev, "%s device c%db%dt%dl%d changed.\n",
692 scsi_device_type(new_entry->devtype), hostno, new_entry->bus,
693 new_entry->target, new_entry->lun);
694}
695
623/* Remove an entry from h->dev[] array. */ 696/* Remove an entry from h->dev[] array. */
624static void hpsa_scsi_remove_entry(struct ctlr_info *h, int hostno, int entry, 697static void hpsa_scsi_remove_entry(struct ctlr_info *h, int hostno, int entry,
625 struct hpsa_scsi_dev_t *removed[], int *nremoved) 698 struct hpsa_scsi_dev_t *removed[], int *nremoved)
@@ -628,8 +701,7 @@ static void hpsa_scsi_remove_entry(struct ctlr_info *h, int hostno, int entry,
628 int i; 701 int i;
629 struct hpsa_scsi_dev_t *sd; 702 struct hpsa_scsi_dev_t *sd;
630 703
631 if (entry < 0 || entry >= HPSA_MAX_SCSI_DEVS_PER_HBA) 704 BUG_ON(entry < 0 || entry >= HPSA_MAX_SCSI_DEVS_PER_HBA);
632 BUG();
633 705
634 sd = h->dev[entry]; 706 sd = h->dev[entry];
635 removed[*nremoved] = h->dev[entry]; 707 removed[*nremoved] = h->dev[entry];
@@ -722,6 +794,8 @@ static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle,
722#define DEVICE_CHANGED 1 794#define DEVICE_CHANGED 1
723#define DEVICE_SAME 2 795#define DEVICE_SAME 2
724 for (i = 0; i < haystack_size; i++) { 796 for (i = 0; i < haystack_size; i++) {
797 if (haystack[i] == NULL) /* previously removed. */
798 continue;
725 if (SCSI3ADDR_EQ(needle->scsi3addr, haystack[i]->scsi3addr)) { 799 if (SCSI3ADDR_EQ(needle->scsi3addr, haystack[i]->scsi3addr)) {
726 *index = i; 800 *index = i;
727 if (device_is_the_same(needle, haystack[i])) 801 if (device_is_the_same(needle, haystack[i]))
@@ -734,7 +808,7 @@ static int hpsa_scsi_find_entry(struct hpsa_scsi_dev_t *needle,
734 return DEVICE_NOT_FOUND; 808 return DEVICE_NOT_FOUND;
735} 809}
736 810
737static int adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno, 811static void adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,
738 struct hpsa_scsi_dev_t *sd[], int nsds) 812 struct hpsa_scsi_dev_t *sd[], int nsds)
739{ 813{
740 /* sd contains scsi3 addresses and devtypes, and inquiry 814 /* sd contains scsi3 addresses and devtypes, and inquiry
@@ -779,12 +853,12 @@ static int adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,
779 continue; /* remove ^^^, hence i not incremented */ 853 continue; /* remove ^^^, hence i not incremented */
780 } else if (device_change == DEVICE_CHANGED) { 854 } else if (device_change == DEVICE_CHANGED) {
781 changes++; 855 changes++;
782 hpsa_scsi_remove_entry(h, hostno, i, 856 hpsa_scsi_replace_entry(h, hostno, i, sd[entry],
783 removed, &nremoved); 857 added, &nadded, removed, &nremoved);
784 (void) hpsa_scsi_add_entry(h, hostno, sd[entry], 858 /* Set it to NULL to prevent it from being freed
785 added, &nadded); 859 * at the bottom of hpsa_update_scsi_devices()
786 /* add can't fail, we just removed one. */ 860 */
787 sd[entry] = NULL; /* prevent it from being freed */ 861 sd[entry] = NULL;
788 } 862 }
789 i++; 863 i++;
790 } 864 }
@@ -860,7 +934,6 @@ static int adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,
860free_and_out: 934free_and_out:
861 kfree(added); 935 kfree(added);
862 kfree(removed); 936 kfree(removed);
863 return 0;
864} 937}
865 938
866/* 939/*
@@ -900,7 +973,7 @@ static int hpsa_slave_alloc(struct scsi_device *sdev)
900 973
901static void hpsa_slave_destroy(struct scsi_device *sdev) 974static void hpsa_slave_destroy(struct scsi_device *sdev)
902{ 975{
903 return; /* nothing to do. */ 976 /* nothing to do. */
904} 977}
905 978
906static void hpsa_scsi_setup(struct ctlr_info *h) 979static void hpsa_scsi_setup(struct ctlr_info *h)
@@ -908,11 +981,10 @@ static void hpsa_scsi_setup(struct ctlr_info *h)
908 h->ndevices = 0; 981 h->ndevices = 0;
909 h->scsi_host = NULL; 982 h->scsi_host = NULL;
910 spin_lock_init(&h->devlock); 983 spin_lock_init(&h->devlock);
911 return;
912} 984}
913 985
914static void complete_scsi_command(struct CommandList *cp, 986static void complete_scsi_command(struct CommandList *cp,
915 int timeout, __u32 tag) 987 int timeout, u32 tag)
916{ 988{
917 struct scsi_cmnd *cmd; 989 struct scsi_cmnd *cmd;
918 struct ctlr_info *h; 990 struct ctlr_info *h;
@@ -987,7 +1059,6 @@ static void complete_scsi_command(struct CommandList *cp,
987 * required 1059 * required
988 */ 1060 */
989 if ((asc == 0x04) && (ascq == 0x03)) { 1061 if ((asc == 0x04) && (ascq == 0x03)) {
990 cmd->result = DID_NO_CONNECT << 16;
991 dev_warn(&h->pdev->dev, "cp %p " 1062 dev_warn(&h->pdev->dev, "cp %p "
992 "has check condition: unit " 1063 "has check condition: unit "
993 "not ready, manual " 1064 "not ready, manual "
@@ -995,14 +1066,22 @@ static void complete_scsi_command(struct CommandList *cp,
995 break; 1066 break;
996 } 1067 }
997 } 1068 }
998 1069 if (sense_key == ABORTED_COMMAND) {
999 1070 /* Aborted command is retryable */
1071 dev_warn(&h->pdev->dev, "cp %p "
1072 "has check condition: aborted command: "
1073 "ASC: 0x%x, ASCQ: 0x%x\n",
1074 cp, asc, ascq);
1075 cmd->result = DID_SOFT_ERROR << 16;
1076 break;
1077 }
1000 /* Must be some other type of check condition */ 1078 /* Must be some other type of check condition */
1001 dev_warn(&h->pdev->dev, "cp %p has check condition: " 1079 dev_warn(&h->pdev->dev, "cp %p has check condition: "
1002 "unknown type: " 1080 "unknown type: "
1003 "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, " 1081 "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, "
1004 "Returning result: 0x%x, " 1082 "Returning result: 0x%x, "
1005 "cmd=[%02x %02x %02x %02x %02x " 1083 "cmd=[%02x %02x %02x %02x %02x "
1084 "%02x %02x %02x %02x %02x %02x "
1006 "%02x %02x %02x %02x %02x]\n", 1085 "%02x %02x %02x %02x %02x]\n",
1007 cp, sense_key, asc, ascq, 1086 cp, sense_key, asc, ascq,
1008 cmd->result, 1087 cmd->result,
@@ -1010,7 +1089,10 @@ static void complete_scsi_command(struct CommandList *cp,
1010 cmd->cmnd[2], cmd->cmnd[3], 1089 cmd->cmnd[2], cmd->cmnd[3],
1011 cmd->cmnd[4], cmd->cmnd[5], 1090 cmd->cmnd[4], cmd->cmnd[5],
1012 cmd->cmnd[6], cmd->cmnd[7], 1091 cmd->cmnd[6], cmd->cmnd[7],
1013 cmd->cmnd[8], cmd->cmnd[9]); 1092 cmd->cmnd[8], cmd->cmnd[9],
1093 cmd->cmnd[10], cmd->cmnd[11],
1094 cmd->cmnd[12], cmd->cmnd[13],
1095 cmd->cmnd[14], cmd->cmnd[15]);
1014 break; 1096 break;
1015 } 1097 }
1016 1098
@@ -1086,7 +1168,7 @@ static void complete_scsi_command(struct CommandList *cp,
1086 dev_warn(&h->pdev->dev, "cp %p reports abort failed\n", cp); 1168 dev_warn(&h->pdev->dev, "cp %p reports abort failed\n", cp);
1087 break; 1169 break;
1088 case CMD_UNSOLICITED_ABORT: 1170 case CMD_UNSOLICITED_ABORT:
1089 cmd->result = DID_ABORT << 16; 1171 cmd->result = DID_RESET << 16;
1090 dev_warn(&h->pdev->dev, "cp %p aborted do to an unsolicited " 1172 dev_warn(&h->pdev->dev, "cp %p aborted do to an unsolicited "
1091 "abort\n", cp); 1173 "abort\n", cp);
1092 break; 1174 break;
@@ -1119,9 +1201,11 @@ static int hpsa_scsi_detect(struct ctlr_info *h)
1119 sh->max_cmd_len = MAX_COMMAND_SIZE; 1201 sh->max_cmd_len = MAX_COMMAND_SIZE;
1120 sh->max_lun = HPSA_MAX_LUN; 1202 sh->max_lun = HPSA_MAX_LUN;
1121 sh->max_id = HPSA_MAX_LUN; 1203 sh->max_id = HPSA_MAX_LUN;
1204 sh->can_queue = h->nr_cmds;
1205 sh->cmd_per_lun = h->nr_cmds;
1122 h->scsi_host = sh; 1206 h->scsi_host = sh;
1123 sh->hostdata[0] = (unsigned long) h; 1207 sh->hostdata[0] = (unsigned long) h;
1124 sh->irq = h->intr[SIMPLE_MODE_INT]; 1208 sh->irq = h->intr[PERF_MODE_INT];
1125 sh->unique_id = sh->irq; 1209 sh->unique_id = sh->irq;
1126 error = scsi_add_host(sh, &h->pdev->dev); 1210 error = scsi_add_host(sh, &h->pdev->dev);
1127 if (error) 1211 if (error)
@@ -1133,11 +1217,11 @@ static int hpsa_scsi_detect(struct ctlr_info *h)
1133 dev_err(&h->pdev->dev, "hpsa_scsi_detect: scsi_add_host" 1217 dev_err(&h->pdev->dev, "hpsa_scsi_detect: scsi_add_host"
1134 " failed for controller %d\n", h->ctlr); 1218 " failed for controller %d\n", h->ctlr);
1135 scsi_host_put(sh); 1219 scsi_host_put(sh);
1136 return -1; 1220 return error;
1137 fail: 1221 fail:
1138 dev_err(&h->pdev->dev, "hpsa_scsi_detect: scsi_host_alloc" 1222 dev_err(&h->pdev->dev, "hpsa_scsi_detect: scsi_host_alloc"
1139 " failed for controller %d\n", h->ctlr); 1223 " failed for controller %d\n", h->ctlr);
1140 return -1; 1224 return -ENOMEM;
1141} 1225}
1142 1226
1143static void hpsa_pci_unmap(struct pci_dev *pdev, 1227static void hpsa_pci_unmap(struct pci_dev *pdev,
@@ -1160,7 +1244,7 @@ static void hpsa_map_one(struct pci_dev *pdev,
1160 size_t buflen, 1244 size_t buflen,
1161 int data_direction) 1245 int data_direction)
1162{ 1246{
1163 __u64 addr64; 1247 u64 addr64;
1164 1248
1165 if (buflen == 0 || data_direction == PCI_DMA_NONE) { 1249 if (buflen == 0 || data_direction == PCI_DMA_NONE) {
1166 cp->Header.SGList = 0; 1250 cp->Header.SGList = 0;
@@ -1168,14 +1252,14 @@ static void hpsa_map_one(struct pci_dev *pdev,
1168 return; 1252 return;
1169 } 1253 }
1170 1254
1171 addr64 = (__u64) pci_map_single(pdev, buf, buflen, data_direction); 1255 addr64 = (u64) pci_map_single(pdev, buf, buflen, data_direction);
1172 cp->SG[0].Addr.lower = 1256 cp->SG[0].Addr.lower =
1173 (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF); 1257 (u32) (addr64 & (u64) 0x00000000FFFFFFFF);
1174 cp->SG[0].Addr.upper = 1258 cp->SG[0].Addr.upper =
1175 (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF); 1259 (u32) ((addr64 >> 32) & (u64) 0x00000000FFFFFFFF);
1176 cp->SG[0].Len = buflen; 1260 cp->SG[0].Len = buflen;
1177 cp->Header.SGList = (__u8) 1; /* no. SGs contig in this cmd */ 1261 cp->Header.SGList = (u8) 1; /* no. SGs contig in this cmd */
1178 cp->Header.SGTotal = (__u16) 1; /* total sgs in this cmd list */ 1262 cp->Header.SGTotal = (u16) 1; /* total sgs in this cmd list */
1179} 1263}
1180 1264
1181static inline void hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h, 1265static inline void hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h,
@@ -1274,7 +1358,7 @@ static int hpsa_scsi_do_inquiry(struct ctlr_info *h, unsigned char *scsi3addr,
1274 1358
1275 if (c == NULL) { /* trouble... */ 1359 if (c == NULL) { /* trouble... */
1276 dev_warn(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); 1360 dev_warn(&h->pdev->dev, "cmd_special_alloc returned NULL!\n");
1277 return -1; 1361 return -ENOMEM;
1278 } 1362 }
1279 1363
1280 fill_cmd(c, HPSA_INQUIRY, h, buf, bufsize, page, scsi3addr, TYPE_CMD); 1364 fill_cmd(c, HPSA_INQUIRY, h, buf, bufsize, page, scsi3addr, TYPE_CMD);
@@ -1366,9 +1450,8 @@ static int hpsa_scsi_do_report_luns(struct ctlr_info *h, int logical,
1366 dev_err(&h->pdev->dev, "cmd_special_alloc returned NULL!\n"); 1450 dev_err(&h->pdev->dev, "cmd_special_alloc returned NULL!\n");
1367 return -1; 1451 return -1;
1368 } 1452 }
1369 1453 /* address the controller */
1370 memset(&scsi3addr[0], 0, 8); /* address the controller */ 1454 memset(scsi3addr, 0, sizeof(scsi3addr));
1371
1372 fill_cmd(c, logical ? HPSA_REPORT_LOG : HPSA_REPORT_PHYS, h, 1455 fill_cmd(c, logical ? HPSA_REPORT_LOG : HPSA_REPORT_PHYS, h,
1373 buf, bufsize, 0, scsi3addr, TYPE_CMD); 1456 buf, bufsize, 0, scsi3addr, TYPE_CMD);
1374 if (extended_response) 1457 if (extended_response)
@@ -1409,13 +1492,12 @@ static int hpsa_update_device_info(struct ctlr_info *h,
1409 unsigned char scsi3addr[], struct hpsa_scsi_dev_t *this_device) 1492 unsigned char scsi3addr[], struct hpsa_scsi_dev_t *this_device)
1410{ 1493{
1411#define OBDR_TAPE_INQ_SIZE 49 1494#define OBDR_TAPE_INQ_SIZE 49
1412 unsigned char *inq_buff = NULL; 1495 unsigned char *inq_buff;
1413 1496
1414 inq_buff = kmalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL); 1497 inq_buff = kzalloc(OBDR_TAPE_INQ_SIZE, GFP_KERNEL);
1415 if (!inq_buff) 1498 if (!inq_buff)
1416 goto bail_out; 1499 goto bail_out;
1417 1500
1418 memset(inq_buff, 0, OBDR_TAPE_INQ_SIZE);
1419 /* Do an inquiry to the device to see what it is. */ 1501 /* Do an inquiry to the device to see what it is. */
1420 if (hpsa_scsi_do_inquiry(h, scsi3addr, 0, inq_buff, 1502 if (hpsa_scsi_do_inquiry(h, scsi3addr, 0, inq_buff,
1421 (unsigned char) OBDR_TAPE_INQ_SIZE) != 0) { 1503 (unsigned char) OBDR_TAPE_INQ_SIZE) != 0) {
@@ -1485,32 +1567,51 @@ static int is_msa2xxx(struct ctlr_info *h, struct hpsa_scsi_dev_t *device)
1485 * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.) 1567 * in hpsa_find_target_lun, called by hpsa_scsi_add_entry.)
1486 */ 1568 */
1487static void figure_bus_target_lun(struct ctlr_info *h, 1569static void figure_bus_target_lun(struct ctlr_info *h,
1488 __u8 *lunaddrbytes, int *bus, int *target, int *lun, 1570 u8 *lunaddrbytes, int *bus, int *target, int *lun,
1489 struct hpsa_scsi_dev_t *device) 1571 struct hpsa_scsi_dev_t *device)
1490{ 1572{
1491 1573 u32 lunid;
1492 __u32 lunid;
1493 1574
1494 if (is_logical_dev_addr_mode(lunaddrbytes)) { 1575 if (is_logical_dev_addr_mode(lunaddrbytes)) {
1495 /* logical device */ 1576 /* logical device */
1496 memcpy(&lunid, lunaddrbytes, sizeof(lunid)); 1577 if (unlikely(is_scsi_rev_5(h))) {
1497 lunid = le32_to_cpu(lunid); 1578 /* p1210m, logical drives lun assignments
1498 1579 * match SCSI REPORT LUNS data.
1499 if (is_msa2xxx(h, device)) { 1580 */
1500 *bus = 1; 1581 lunid = le32_to_cpu(*((__le32 *) lunaddrbytes));
1501 *target = (lunid >> 16) & 0x3fff;
1502 *lun = lunid & 0x00ff;
1503 } else {
1504 *bus = 0; 1582 *bus = 0;
1505 *lun = 0; 1583 *target = 0;
1506 *target = lunid & 0x3fff; 1584 *lun = (lunid & 0x3fff) + 1;
1585 } else {
1586 /* not p1210m... */
1587 lunid = le32_to_cpu(*((__le32 *) lunaddrbytes));
1588 if (is_msa2xxx(h, device)) {
1589 /* msa2xxx way, put logicals on bus 1
1590 * and match target/lun numbers box
1591 * reports.
1592 */
1593 *bus = 1;
1594 *target = (lunid >> 16) & 0x3fff;
1595 *lun = lunid & 0x00ff;
1596 } else {
1597 /* Traditional smart array way. */
1598 *bus = 0;
1599 *lun = 0;
1600 *target = lunid & 0x3fff;
1601 }
1507 } 1602 }
1508 } else { 1603 } else {
1509 /* physical device */ 1604 /* physical device */
1510 if (is_hba_lunid(lunaddrbytes)) 1605 if (is_hba_lunid(lunaddrbytes))
1511 *bus = 3; 1606 if (unlikely(is_scsi_rev_5(h))) {
1607 *bus = 0; /* put p1210m ctlr at 0,0,0 */
1608 *target = 0;
1609 *lun = 0;
1610 return;
1611 } else
1612 *bus = 3; /* traditional smartarray */
1512 else 1613 else
1513 *bus = 2; 1614 *bus = 2; /* physical disk */
1514 *target = -1; 1615 *target = -1;
1515 *lun = -1; /* we will fill these in later. */ 1616 *lun = -1; /* we will fill these in later. */
1516 } 1617 }
@@ -1529,7 +1630,7 @@ static void figure_bus_target_lun(struct ctlr_info *h,
1529 */ 1630 */
1530static int add_msa2xxx_enclosure_device(struct ctlr_info *h, 1631static int add_msa2xxx_enclosure_device(struct ctlr_info *h,
1531 struct hpsa_scsi_dev_t *tmpdevice, 1632 struct hpsa_scsi_dev_t *tmpdevice,
1532 struct hpsa_scsi_dev_t *this_device, __u8 *lunaddrbytes, 1633 struct hpsa_scsi_dev_t *this_device, u8 *lunaddrbytes,
1533 int bus, int target, int lun, unsigned long lunzerobits[], 1634 int bus, int target, int lun, unsigned long lunzerobits[],
1534 int *nmsa2xxx_enclosures) 1635 int *nmsa2xxx_enclosures)
1535{ 1636{
@@ -1550,6 +1651,9 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,
1550 if (is_hba_lunid(scsi3addr)) 1651 if (is_hba_lunid(scsi3addr))
1551 return 0; /* Don't add the RAID controller here. */ 1652 return 0; /* Don't add the RAID controller here. */
1552 1653
1654 if (is_scsi_rev_5(h))
1655 return 0; /* p1210m doesn't need to do this. */
1656
1553#define MAX_MSA2XXX_ENCLOSURES 32 1657#define MAX_MSA2XXX_ENCLOSURES 32
1554 if (*nmsa2xxx_enclosures >= MAX_MSA2XXX_ENCLOSURES) { 1658 if (*nmsa2xxx_enclosures >= MAX_MSA2XXX_ENCLOSURES) {
1555 dev_warn(&h->pdev->dev, "Maximum number of MSA2XXX " 1659 dev_warn(&h->pdev->dev, "Maximum number of MSA2XXX "
@@ -1576,18 +1680,14 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,
1576 */ 1680 */
1577static int hpsa_gather_lun_info(struct ctlr_info *h, 1681static int hpsa_gather_lun_info(struct ctlr_info *h,
1578 int reportlunsize, 1682 int reportlunsize,
1579 struct ReportLUNdata *physdev, __u32 *nphysicals, 1683 struct ReportLUNdata *physdev, u32 *nphysicals,
1580 struct ReportLUNdata *logdev, __u32 *nlogicals) 1684 struct ReportLUNdata *logdev, u32 *nlogicals)
1581{ 1685{
1582 if (hpsa_scsi_do_report_phys_luns(h, physdev, reportlunsize, 0)) { 1686 if (hpsa_scsi_do_report_phys_luns(h, physdev, reportlunsize, 0)) {
1583 dev_err(&h->pdev->dev, "report physical LUNs failed.\n"); 1687 dev_err(&h->pdev->dev, "report physical LUNs failed.\n");
1584 return -1; 1688 return -1;
1585 } 1689 }
1586 memcpy(nphysicals, &physdev->LUNListLength[0], sizeof(*nphysicals)); 1690 *nphysicals = be32_to_cpu(*((__be32 *)physdev->LUNListLength)) / 8;
1587 *nphysicals = be32_to_cpu(*nphysicals) / 8;
1588#ifdef DEBUG
1589 dev_info(&h->pdev->dev, "number of physical luns is %d\n", *nphysicals);
1590#endif
1591 if (*nphysicals > HPSA_MAX_PHYS_LUN) { 1691 if (*nphysicals > HPSA_MAX_PHYS_LUN) {
1592 dev_warn(&h->pdev->dev, "maximum physical LUNs (%d) exceeded." 1692 dev_warn(&h->pdev->dev, "maximum physical LUNs (%d) exceeded."
1593 " %d LUNs ignored.\n", HPSA_MAX_PHYS_LUN, 1693 " %d LUNs ignored.\n", HPSA_MAX_PHYS_LUN,
@@ -1598,11 +1698,7 @@ static int hpsa_gather_lun_info(struct ctlr_info *h,
1598 dev_err(&h->pdev->dev, "report logical LUNs failed.\n"); 1698 dev_err(&h->pdev->dev, "report logical LUNs failed.\n");
1599 return -1; 1699 return -1;
1600 } 1700 }
1601 memcpy(nlogicals, &logdev->LUNListLength[0], sizeof(*nlogicals)); 1701 *nlogicals = be32_to_cpu(*((__be32 *) logdev->LUNListLength)) / 8;
1602 *nlogicals = be32_to_cpu(*nlogicals) / 8;
1603#ifdef DEBUG
1604 dev_info(&h->pdev->dev, "number of logical luns is %d\n", *nlogicals);
1605#endif
1606 /* Reject Logicals in excess of our max capability. */ 1702 /* Reject Logicals in excess of our max capability. */
1607 if (*nlogicals > HPSA_MAX_LUN) { 1703 if (*nlogicals > HPSA_MAX_LUN) {
1608 dev_warn(&h->pdev->dev, 1704 dev_warn(&h->pdev->dev,
@@ -1621,6 +1717,31 @@ static int hpsa_gather_lun_info(struct ctlr_info *h,
1621 return 0; 1717 return 0;
1622} 1718}
1623 1719
1720u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position, int i,
1721 int nphysicals, int nlogicals, struct ReportLUNdata *physdev_list,
1722 struct ReportLUNdata *logdev_list)
1723{
1724 /* Helper function, figure out where the LUN ID info is coming from
1725 * given index i, lists of physical and logical devices, where in
1726 * the list the raid controller is supposed to appear (first or last)
1727 */
1728
1729 int logicals_start = nphysicals + (raid_ctlr_position == 0);
1730 int last_device = nphysicals + nlogicals + (raid_ctlr_position == 0);
1731
1732 if (i == raid_ctlr_position)
1733 return RAID_CTLR_LUNID;
1734
1735 if (i < logicals_start)
1736 return &physdev_list->LUN[i - (raid_ctlr_position == 0)][0];
1737
1738 if (i < last_device)
1739 return &logdev_list->LUN[i - nphysicals -
1740 (raid_ctlr_position == 0)][0];
1741 BUG();
1742 return NULL;
1743}
1744
1624static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno) 1745static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1625{ 1746{
1626 /* the idea here is we could get notified 1747 /* the idea here is we could get notified
@@ -1636,14 +1757,15 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1636 struct ReportLUNdata *physdev_list = NULL; 1757 struct ReportLUNdata *physdev_list = NULL;
1637 struct ReportLUNdata *logdev_list = NULL; 1758 struct ReportLUNdata *logdev_list = NULL;
1638 unsigned char *inq_buff = NULL; 1759 unsigned char *inq_buff = NULL;
1639 __u32 nphysicals = 0; 1760 u32 nphysicals = 0;
1640 __u32 nlogicals = 0; 1761 u32 nlogicals = 0;
1641 __u32 ndev_allocated = 0; 1762 u32 ndev_allocated = 0;
1642 struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice; 1763 struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice;
1643 int ncurrent = 0; 1764 int ncurrent = 0;
1644 int reportlunsize = sizeof(*physdev_list) + HPSA_MAX_PHYS_LUN * 8; 1765 int reportlunsize = sizeof(*physdev_list) + HPSA_MAX_PHYS_LUN * 8;
1645 int i, nmsa2xxx_enclosures, ndevs_to_allocate; 1766 int i, nmsa2xxx_enclosures, ndevs_to_allocate;
1646 int bus, target, lun; 1767 int bus, target, lun;
1768 int raid_ctlr_position;
1647 DECLARE_BITMAP(lunzerobits, HPSA_MAX_TARGETS_PER_CTLR); 1769 DECLARE_BITMAP(lunzerobits, HPSA_MAX_TARGETS_PER_CTLR);
1648 1770
1649 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_SCSI_DEVS_PER_HBA, 1771 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_SCSI_DEVS_PER_HBA,
@@ -1681,23 +1803,22 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1681 ndev_allocated++; 1803 ndev_allocated++;
1682 } 1804 }
1683 1805
1806 if (unlikely(is_scsi_rev_5(h)))
1807 raid_ctlr_position = 0;
1808 else
1809 raid_ctlr_position = nphysicals + nlogicals;
1810
1684 /* adjust our table of devices */ 1811 /* adjust our table of devices */
1685 nmsa2xxx_enclosures = 0; 1812 nmsa2xxx_enclosures = 0;
1686 for (i = 0; i < nphysicals + nlogicals + 1; i++) { 1813 for (i = 0; i < nphysicals + nlogicals + 1; i++) {
1687 __u8 *lunaddrbytes; 1814 u8 *lunaddrbytes;
1688 1815
1689 /* Figure out where the LUN ID info is coming from */ 1816 /* Figure out where the LUN ID info is coming from */
1690 if (i < nphysicals) 1817 lunaddrbytes = figure_lunaddrbytes(h, raid_ctlr_position,
1691 lunaddrbytes = &physdev_list->LUN[i][0]; 1818 i, nphysicals, nlogicals, physdev_list, logdev_list);
1692 else
1693 if (i < nphysicals + nlogicals)
1694 lunaddrbytes =
1695 &logdev_list->LUN[i-nphysicals][0];
1696 else /* jam in the RAID controller at the end */
1697 lunaddrbytes = RAID_CTLR_LUNID;
1698
1699 /* skip masked physical devices. */ 1819 /* skip masked physical devices. */
1700 if (lunaddrbytes[3] & 0xC0 && i < nphysicals) 1820 if (lunaddrbytes[3] & 0xC0 &&
1821 i < nphysicals + (raid_ctlr_position == 0))
1701 continue; 1822 continue;
1702 1823
1703 /* Get device type, vendor, model, device id */ 1824 /* Get device type, vendor, model, device id */
@@ -1777,7 +1898,6 @@ out:
1777 kfree(inq_buff); 1898 kfree(inq_buff);
1778 kfree(physdev_list); 1899 kfree(physdev_list);
1779 kfree(logdev_list); 1900 kfree(logdev_list);
1780 return;
1781} 1901}
1782 1902
1783/* hpsa_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci 1903/* hpsa_scatter_gather takes a struct scsi_cmnd, (cmd), and does the pci
@@ -1790,7 +1910,7 @@ static int hpsa_scatter_gather(struct pci_dev *pdev,
1790{ 1910{
1791 unsigned int len; 1911 unsigned int len;
1792 struct scatterlist *sg; 1912 struct scatterlist *sg;
1793 __u64 addr64; 1913 u64 addr64;
1794 int use_sg, i; 1914 int use_sg, i;
1795 1915
1796 BUG_ON(scsi_sg_count(cmd) > MAXSGENTRIES); 1916 BUG_ON(scsi_sg_count(cmd) > MAXSGENTRIES);
@@ -1803,20 +1923,20 @@ static int hpsa_scatter_gather(struct pci_dev *pdev,
1803 goto sglist_finished; 1923 goto sglist_finished;
1804 1924
1805 scsi_for_each_sg(cmd, sg, use_sg, i) { 1925 scsi_for_each_sg(cmd, sg, use_sg, i) {
1806 addr64 = (__u64) sg_dma_address(sg); 1926 addr64 = (u64) sg_dma_address(sg);
1807 len = sg_dma_len(sg); 1927 len = sg_dma_len(sg);
1808 cp->SG[i].Addr.lower = 1928 cp->SG[i].Addr.lower =
1809 (__u32) (addr64 & (__u64) 0x00000000FFFFFFFF); 1929 (u32) (addr64 & (u64) 0x00000000FFFFFFFF);
1810 cp->SG[i].Addr.upper = 1930 cp->SG[i].Addr.upper =
1811 (__u32) ((addr64 >> 32) & (__u64) 0x00000000FFFFFFFF); 1931 (u32) ((addr64 >> 32) & (u64) 0x00000000FFFFFFFF);
1812 cp->SG[i].Len = len; 1932 cp->SG[i].Len = len;
1813 cp->SG[i].Ext = 0; /* we are not chaining */ 1933 cp->SG[i].Ext = 0; /* we are not chaining */
1814 } 1934 }
1815 1935
1816sglist_finished: 1936sglist_finished:
1817 1937
1818 cp->Header.SGList = (__u8) use_sg; /* no. SGs contig in this cmd */ 1938 cp->Header.SGList = (u8) use_sg; /* no. SGs contig in this cmd */
1819 cp->Header.SGTotal = (__u16) use_sg; /* total sgs in this cmd list */ 1939 cp->Header.SGTotal = (u16) use_sg; /* total sgs in this cmd list */
1820 return 0; 1940 return 0;
1821} 1941}
1822 1942
@@ -1860,7 +1980,8 @@ static int hpsa_scsi_queue_command(struct scsi_cmnd *cmd,
1860 c->scsi_cmd = cmd; 1980 c->scsi_cmd = cmd;
1861 c->Header.ReplyQueue = 0; /* unused in simple mode */ 1981 c->Header.ReplyQueue = 0; /* unused in simple mode */
1862 memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8); 1982 memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8);
1863 c->Header.Tag.lower = c->busaddr; /* Use k. address of cmd as tag */ 1983 c->Header.Tag.lower = (c->cmdindex << DIRECT_LOOKUP_SHIFT);
1984 c->Header.Tag.lower |= DIRECT_LOOKUP_BIT;
1864 1985
1865 /* Fill in the request block... */ 1986 /* Fill in the request block... */
1866 1987
@@ -1914,6 +2035,48 @@ static int hpsa_scsi_queue_command(struct scsi_cmnd *cmd,
1914 return 0; 2035 return 0;
1915} 2036}
1916 2037
2038static void hpsa_scan_start(struct Scsi_Host *sh)
2039{
2040 struct ctlr_info *h = shost_to_hba(sh);
2041 unsigned long flags;
2042
2043 /* wait until any scan already in progress is finished. */
2044 while (1) {
2045 spin_lock_irqsave(&h->scan_lock, flags);
2046 if (h->scan_finished)
2047 break;
2048 spin_unlock_irqrestore(&h->scan_lock, flags);
2049 wait_event(h->scan_wait_queue, h->scan_finished);
2050 /* Note: We don't need to worry about a race between this
2051 * thread and driver unload because the midlayer will
2052 * have incremented the reference count, so unload won't
2053 * happen if we're in here.
2054 */
2055 }
2056 h->scan_finished = 0; /* mark scan as in progress */
2057 spin_unlock_irqrestore(&h->scan_lock, flags);
2058
2059 hpsa_update_scsi_devices(h, h->scsi_host->host_no);
2060
2061 spin_lock_irqsave(&h->scan_lock, flags);
2062 h->scan_finished = 1; /* mark scan as finished. */
2063 wake_up_all(&h->scan_wait_queue);
2064 spin_unlock_irqrestore(&h->scan_lock, flags);
2065}
2066
2067static int hpsa_scan_finished(struct Scsi_Host *sh,
2068 unsigned long elapsed_time)
2069{
2070 struct ctlr_info *h = shost_to_hba(sh);
2071 unsigned long flags;
2072 int finished;
2073
2074 spin_lock_irqsave(&h->scan_lock, flags);
2075 finished = h->scan_finished;
2076 spin_unlock_irqrestore(&h->scan_lock, flags);
2077 return finished;
2078}
2079
1917static void hpsa_unregister_scsi(struct ctlr_info *h) 2080static void hpsa_unregister_scsi(struct ctlr_info *h)
1918{ 2081{
1919 /* we are being forcibly unloaded, and may not refuse. */ 2082 /* we are being forcibly unloaded, and may not refuse. */
@@ -1926,7 +2089,6 @@ static int hpsa_register_scsi(struct ctlr_info *h)
1926{ 2089{
1927 int rc; 2090 int rc;
1928 2091
1929 hpsa_update_scsi_devices(h, -1);
1930 rc = hpsa_scsi_detect(h); 2092 rc = hpsa_scsi_detect(h);
1931 if (rc != 0) 2093 if (rc != 0)
1932 dev_err(&h->pdev->dev, "hpsa_register_scsi: failed" 2094 dev_err(&h->pdev->dev, "hpsa_register_scsi: failed"
@@ -2003,14 +2165,14 @@ static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
2003 h = sdev_to_hba(scsicmd->device); 2165 h = sdev_to_hba(scsicmd->device);
2004 if (h == NULL) /* paranoia */ 2166 if (h == NULL) /* paranoia */
2005 return FAILED; 2167 return FAILED;
2006 dev_warn(&h->pdev->dev, "resetting drive\n");
2007
2008 dev = scsicmd->device->hostdata; 2168 dev = scsicmd->device->hostdata;
2009 if (!dev) { 2169 if (!dev) {
2010 dev_err(&h->pdev->dev, "hpsa_eh_device_reset_handler: " 2170 dev_err(&h->pdev->dev, "hpsa_eh_device_reset_handler: "
2011 "device lookup failed.\n"); 2171 "device lookup failed.\n");
2012 return FAILED; 2172 return FAILED;
2013 } 2173 }
2174 dev_warn(&h->pdev->dev, "resetting device %d:%d:%d:%d\n",
2175 h->scsi_host->host_no, dev->bus, dev->target, dev->lun);
2014 /* send a reset to the SCSI LUN which the command was sent to */ 2176 /* send a reset to the SCSI LUN which the command was sent to */
2015 rc = hpsa_send_reset(h, dev->scsi3addr); 2177 rc = hpsa_send_reset(h, dev->scsi3addr);
2016 if (rc == 0 && wait_for_device_to_become_ready(h, dev->scsi3addr) == 0) 2178 if (rc == 0 && wait_for_device_to_become_ready(h, dev->scsi3addr) == 0)
@@ -2053,8 +2215,8 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h)
2053 c->cmdindex = i; 2215 c->cmdindex = i;
2054 2216
2055 INIT_HLIST_NODE(&c->list); 2217 INIT_HLIST_NODE(&c->list);
2056 c->busaddr = (__u32) cmd_dma_handle; 2218 c->busaddr = (u32) cmd_dma_handle;
2057 temp64.val = (__u64) err_dma_handle; 2219 temp64.val = (u64) err_dma_handle;
2058 c->ErrDesc.Addr.lower = temp64.val32.lower; 2220 c->ErrDesc.Addr.lower = temp64.val32.lower;
2059 c->ErrDesc.Addr.upper = temp64.val32.upper; 2221 c->ErrDesc.Addr.upper = temp64.val32.upper;
2060 c->ErrDesc.Len = sizeof(*c->err_info); 2222 c->ErrDesc.Len = sizeof(*c->err_info);
@@ -2091,8 +2253,8 @@ static struct CommandList *cmd_special_alloc(struct ctlr_info *h)
2091 memset(c->err_info, 0, sizeof(*c->err_info)); 2253 memset(c->err_info, 0, sizeof(*c->err_info));
2092 2254
2093 INIT_HLIST_NODE(&c->list); 2255 INIT_HLIST_NODE(&c->list);
2094 c->busaddr = (__u32) cmd_dma_handle; 2256 c->busaddr = (u32) cmd_dma_handle;
2095 temp64.val = (__u64) err_dma_handle; 2257 temp64.val = (u64) err_dma_handle;
2096 c->ErrDesc.Addr.lower = temp64.val32.lower; 2258 c->ErrDesc.Addr.lower = temp64.val32.lower;
2097 c->ErrDesc.Addr.upper = temp64.val32.upper; 2259 c->ErrDesc.Addr.upper = temp64.val32.upper;
2098 c->ErrDesc.Len = sizeof(*c->err_info); 2260 c->ErrDesc.Len = sizeof(*c->err_info);
@@ -2125,50 +2287,6 @@ static void cmd_special_free(struct ctlr_info *h, struct CommandList *c)
2125 2287
2126#ifdef CONFIG_COMPAT 2288#ifdef CONFIG_COMPAT
2127 2289
2128static int do_ioctl(struct scsi_device *dev, int cmd, void *arg)
2129{
2130 int ret;
2131
2132 lock_kernel();
2133 ret = hpsa_ioctl(dev, cmd, arg);
2134 unlock_kernel();
2135 return ret;
2136}
2137
2138static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg);
2139static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
2140 int cmd, void *arg);
2141
2142static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void *arg)
2143{
2144 switch (cmd) {
2145 case CCISS_GETPCIINFO:
2146 case CCISS_GETINTINFO:
2147 case CCISS_SETINTINFO:
2148 case CCISS_GETNODENAME:
2149 case CCISS_SETNODENAME:
2150 case CCISS_GETHEARTBEAT:
2151 case CCISS_GETBUSTYPES:
2152 case CCISS_GETFIRMVER:
2153 case CCISS_GETDRIVVER:
2154 case CCISS_REVALIDVOLS:
2155 case CCISS_DEREGDISK:
2156 case CCISS_REGNEWDISK:
2157 case CCISS_REGNEWD:
2158 case CCISS_RESCANDISK:
2159 case CCISS_GETLUNINFO:
2160 return do_ioctl(dev, cmd, arg);
2161
2162 case CCISS_PASSTHRU32:
2163 return hpsa_ioctl32_passthru(dev, cmd, arg);
2164 case CCISS_BIG_PASSTHRU32:
2165 return hpsa_ioctl32_big_passthru(dev, cmd, arg);
2166
2167 default:
2168 return -ENOIOCTLCMD;
2169 }
2170}
2171
2172static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg) 2290static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg)
2173{ 2291{
2174 IOCTL32_Command_struct __user *arg32 = 2292 IOCTL32_Command_struct __user *arg32 =
@@ -2193,7 +2311,7 @@ static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg)
2193 if (err) 2311 if (err)
2194 return -EFAULT; 2312 return -EFAULT;
2195 2313
2196 err = do_ioctl(dev, CCISS_PASSTHRU, (void *)p); 2314 err = hpsa_ioctl(dev, CCISS_PASSTHRU, (void *)p);
2197 if (err) 2315 if (err)
2198 return err; 2316 return err;
2199 err |= copy_in_user(&arg32->error_info, &p->error_info, 2317 err |= copy_in_user(&arg32->error_info, &p->error_info,
@@ -2230,7 +2348,7 @@ static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
2230 if (err) 2348 if (err)
2231 return -EFAULT; 2349 return -EFAULT;
2232 2350
2233 err = do_ioctl(dev, CCISS_BIG_PASSTHRU, (void *)p); 2351 err = hpsa_ioctl(dev, CCISS_BIG_PASSTHRU, (void *)p);
2234 if (err) 2352 if (err)
2235 return err; 2353 return err;
2236 err |= copy_in_user(&arg32->error_info, &p->error_info, 2354 err |= copy_in_user(&arg32->error_info, &p->error_info,
@@ -2239,6 +2357,36 @@ static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
2239 return -EFAULT; 2357 return -EFAULT;
2240 return err; 2358 return err;
2241} 2359}
2360
2361static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void *arg)
2362{
2363 switch (cmd) {
2364 case CCISS_GETPCIINFO:
2365 case CCISS_GETINTINFO:
2366 case CCISS_SETINTINFO:
2367 case CCISS_GETNODENAME:
2368 case CCISS_SETNODENAME:
2369 case CCISS_GETHEARTBEAT:
2370 case CCISS_GETBUSTYPES:
2371 case CCISS_GETFIRMVER:
2372 case CCISS_GETDRIVVER:
2373 case CCISS_REVALIDVOLS:
2374 case CCISS_DEREGDISK:
2375 case CCISS_REGNEWDISK:
2376 case CCISS_REGNEWD:
2377 case CCISS_RESCANDISK:
2378 case CCISS_GETLUNINFO:
2379 return hpsa_ioctl(dev, cmd, arg);
2380
2381 case CCISS_PASSTHRU32:
2382 return hpsa_ioctl32_passthru(dev, cmd, arg);
2383 case CCISS_BIG_PASSTHRU32:
2384 return hpsa_ioctl32_big_passthru(dev, cmd, arg);
2385
2386 default:
2387 return -ENOIOCTLCMD;
2388 }
2389}
2242#endif 2390#endif
2243 2391
2244static int hpsa_getpciinfo_ioctl(struct ctlr_info *h, void __user *argp) 2392static int hpsa_getpciinfo_ioctl(struct ctlr_info *h, void __user *argp)
@@ -2378,8 +2526,8 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2378 BYTE sg_used = 0; 2526 BYTE sg_used = 0;
2379 int status = 0; 2527 int status = 0;
2380 int i; 2528 int i;
2381 __u32 left; 2529 u32 left;
2382 __u32 sz; 2530 u32 sz;
2383 BYTE __user *data_ptr; 2531 BYTE __user *data_ptr;
2384 2532
2385 if (!argp) 2533 if (!argp)
@@ -2527,7 +2675,7 @@ static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg)
2527 case CCISS_DEREGDISK: 2675 case CCISS_DEREGDISK:
2528 case CCISS_REGNEWDISK: 2676 case CCISS_REGNEWDISK:
2529 case CCISS_REGNEWD: 2677 case CCISS_REGNEWD:
2530 hpsa_update_scsi_devices(h, dev->host->host_no); 2678 hpsa_scan_start(h->scsi_host);
2531 return 0; 2679 return 0;
2532 case CCISS_GETPCIINFO: 2680 case CCISS_GETPCIINFO:
2533 return hpsa_getpciinfo_ioctl(h, argp); 2681 return hpsa_getpciinfo_ioctl(h, argp);
@@ -2542,8 +2690,8 @@ static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg)
2542 } 2690 }
2543} 2691}
2544 2692
2545static void fill_cmd(struct CommandList *c, __u8 cmd, struct ctlr_info *h, 2693static void fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
2546 void *buff, size_t size, __u8 page_code, unsigned char *scsi3addr, 2694 void *buff, size_t size, u8 page_code, unsigned char *scsi3addr,
2547 int cmd_type) 2695 int cmd_type)
2548{ 2696{
2549 int pci_dir = XFER_NONE; 2697 int pci_dir = XFER_NONE;
@@ -2710,19 +2858,20 @@ static inline unsigned long get_next_completion(struct ctlr_info *h)
2710 return h->access.command_completed(h); 2858 return h->access.command_completed(h);
2711} 2859}
2712 2860
2713static inline int interrupt_pending(struct ctlr_info *h) 2861static inline bool interrupt_pending(struct ctlr_info *h)
2714{ 2862{
2715 return h->access.intr_pending(h); 2863 return h->access.intr_pending(h);
2716} 2864}
2717 2865
2718static inline long interrupt_not_for_us(struct ctlr_info *h) 2866static inline long interrupt_not_for_us(struct ctlr_info *h)
2719{ 2867{
2720 return ((h->access.intr_pending(h) == 0) || 2868 return !(h->msi_vector || h->msix_vector) &&
2721 (h->interrupts_enabled == 0)); 2869 ((h->access.intr_pending(h) == 0) ||
2870 (h->interrupts_enabled == 0));
2722} 2871}
2723 2872
2724static inline int bad_tag(struct ctlr_info *h, __u32 tag_index, 2873static inline int bad_tag(struct ctlr_info *h, u32 tag_index,
2725 __u32 raw_tag) 2874 u32 raw_tag)
2726{ 2875{
2727 if (unlikely(tag_index >= h->nr_cmds)) { 2876 if (unlikely(tag_index >= h->nr_cmds)) {
2728 dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag); 2877 dev_warn(&h->pdev->dev, "bad tag 0x%08x ignored.\n", raw_tag);
@@ -2731,7 +2880,7 @@ static inline int bad_tag(struct ctlr_info *h, __u32 tag_index,
2731 return 0; 2880 return 0;
2732} 2881}
2733 2882
2734static inline void finish_cmd(struct CommandList *c, __u32 raw_tag) 2883static inline void finish_cmd(struct CommandList *c, u32 raw_tag)
2735{ 2884{
2736 removeQ(c); 2885 removeQ(c);
2737 if (likely(c->cmd_type == CMD_SCSI)) 2886 if (likely(c->cmd_type == CMD_SCSI))
@@ -2740,42 +2889,79 @@ static inline void finish_cmd(struct CommandList *c, __u32 raw_tag)
2740 complete(c->waiting); 2889 complete(c->waiting);
2741} 2890}
2742 2891
2892static inline u32 hpsa_tag_contains_index(u32 tag)
2893{
2894#define DIRECT_LOOKUP_BIT 0x10
2895 return tag & DIRECT_LOOKUP_BIT;
2896}
2897
2898static inline u32 hpsa_tag_to_index(u32 tag)
2899{
2900#define DIRECT_LOOKUP_SHIFT 5
2901 return tag >> DIRECT_LOOKUP_SHIFT;
2902}
2903
2904static inline u32 hpsa_tag_discard_error_bits(u32 tag)
2905{
2906#define HPSA_ERROR_BITS 0x03
2907 return tag & ~HPSA_ERROR_BITS;
2908}
2909
2910/* process completion of an indexed ("direct lookup") command */
2911static inline u32 process_indexed_cmd(struct ctlr_info *h,
2912 u32 raw_tag)
2913{
2914 u32 tag_index;
2915 struct CommandList *c;
2916
2917 tag_index = hpsa_tag_to_index(raw_tag);
2918 if (bad_tag(h, tag_index, raw_tag))
2919 return next_command(h);
2920 c = h->cmd_pool + tag_index;
2921 finish_cmd(c, raw_tag);
2922 return next_command(h);
2923}
2924
2925/* process completion of a non-indexed command */
2926static inline u32 process_nonindexed_cmd(struct ctlr_info *h,
2927 u32 raw_tag)
2928{
2929 u32 tag;
2930 struct CommandList *c = NULL;
2931 struct hlist_node *tmp;
2932
2933 tag = hpsa_tag_discard_error_bits(raw_tag);
2934 hlist_for_each_entry(c, tmp, &h->cmpQ, list) {
2935 if ((c->busaddr & 0xFFFFFFE0) == (tag & 0xFFFFFFE0)) {
2936 finish_cmd(c, raw_tag);
2937 return next_command(h);
2938 }
2939 }
2940 bad_tag(h, h->nr_cmds + 1, raw_tag);
2941 return next_command(h);
2942}
2943
2743static irqreturn_t do_hpsa_intr(int irq, void *dev_id) 2944static irqreturn_t do_hpsa_intr(int irq, void *dev_id)
2744{ 2945{
2745 struct ctlr_info *h = dev_id; 2946 struct ctlr_info *h = dev_id;
2746 struct CommandList *c;
2747 unsigned long flags; 2947 unsigned long flags;
2748 __u32 raw_tag, tag, tag_index; 2948 u32 raw_tag;
2749 struct hlist_node *tmp;
2750 2949
2751 if (interrupt_not_for_us(h)) 2950 if (interrupt_not_for_us(h))
2752 return IRQ_NONE; 2951 return IRQ_NONE;
2753 spin_lock_irqsave(&h->lock, flags); 2952 spin_lock_irqsave(&h->lock, flags);
2754 while (interrupt_pending(h)) { 2953 raw_tag = get_next_completion(h);
2755 while ((raw_tag = get_next_completion(h)) != FIFO_EMPTY) { 2954 while (raw_tag != FIFO_EMPTY) {
2756 if (likely(HPSA_TAG_CONTAINS_INDEX(raw_tag))) { 2955 if (hpsa_tag_contains_index(raw_tag))
2757 tag_index = HPSA_TAG_TO_INDEX(raw_tag); 2956 raw_tag = process_indexed_cmd(h, raw_tag);
2758 if (bad_tag(h, tag_index, raw_tag)) 2957 else
2759 return IRQ_HANDLED; 2958 raw_tag = process_nonindexed_cmd(h, raw_tag);
2760 c = h->cmd_pool + tag_index;
2761 finish_cmd(c, raw_tag);
2762 continue;
2763 }
2764 tag = HPSA_TAG_DISCARD_ERROR_BITS(raw_tag);
2765 c = NULL;
2766 hlist_for_each_entry(c, tmp, &h->cmpQ, list) {
2767 if (c->busaddr == tag) {
2768 finish_cmd(c, raw_tag);
2769 break;
2770 }
2771 }
2772 }
2773 } 2959 }
2774 spin_unlock_irqrestore(&h->lock, flags); 2960 spin_unlock_irqrestore(&h->lock, flags);
2775 return IRQ_HANDLED; 2961 return IRQ_HANDLED;
2776} 2962}
2777 2963
2778/* Send a message CDB to the firmware. */ 2964/* Send a message CDB to the firmwart. */
2779static __devinit int hpsa_message(struct pci_dev *pdev, unsigned char opcode, 2965static __devinit int hpsa_message(struct pci_dev *pdev, unsigned char opcode,
2780 unsigned char type) 2966 unsigned char type)
2781{ 2967{
@@ -2841,7 +3027,7 @@ static __devinit int hpsa_message(struct pci_dev *pdev, unsigned char opcode,
2841 3027
2842 for (i = 0; i < HPSA_MSG_SEND_RETRY_LIMIT; i++) { 3028 for (i = 0; i < HPSA_MSG_SEND_RETRY_LIMIT; i++) {
2843 tag = readl(vaddr + SA5_REPLY_PORT_OFFSET); 3029 tag = readl(vaddr + SA5_REPLY_PORT_OFFSET);
2844 if (HPSA_TAG_DISCARD_ERROR_BITS(tag) == paddr32) 3030 if (hpsa_tag_discard_error_bits(tag) == paddr32)
2845 break; 3031 break;
2846 msleep(HPSA_MSG_SEND_RETRY_INTERVAL_MSECS); 3032 msleep(HPSA_MSG_SEND_RETRY_INTERVAL_MSECS);
2847 } 3033 }
@@ -3063,7 +3249,7 @@ static int find_PCI_BAR_index(struct pci_dev *pdev, unsigned long pci_bar_addr)
3063 */ 3249 */
3064 3250
3065static void __devinit hpsa_interrupt_mode(struct ctlr_info *h, 3251static void __devinit hpsa_interrupt_mode(struct ctlr_info *h,
3066 struct pci_dev *pdev, __u32 board_id) 3252 struct pci_dev *pdev, u32 board_id)
3067{ 3253{
3068#ifdef CONFIG_PCI_MSI 3254#ifdef CONFIG_PCI_MSI
3069 int err; 3255 int err;
@@ -3107,22 +3293,22 @@ static void __devinit hpsa_interrupt_mode(struct ctlr_info *h,
3107default_int_mode: 3293default_int_mode:
3108#endif /* CONFIG_PCI_MSI */ 3294#endif /* CONFIG_PCI_MSI */
3109 /* if we get here we're going to use the default interrupt mode */ 3295 /* if we get here we're going to use the default interrupt mode */
3110 h->intr[SIMPLE_MODE_INT] = pdev->irq; 3296 h->intr[PERF_MODE_INT] = pdev->irq;
3111 return;
3112} 3297}
3113 3298
3114static int hpsa_pci_init(struct ctlr_info *h, struct pci_dev *pdev) 3299static int hpsa_pci_init(struct ctlr_info *h, struct pci_dev *pdev)
3115{ 3300{
3116 ushort subsystem_vendor_id, subsystem_device_id, command; 3301 ushort subsystem_vendor_id, subsystem_device_id, command;
3117 __u32 board_id, scratchpad = 0; 3302 u32 board_id, scratchpad = 0;
3118 __u64 cfg_offset; 3303 u64 cfg_offset;
3119 __u32 cfg_base_addr; 3304 u32 cfg_base_addr;
3120 __u64 cfg_base_addr_index; 3305 u64 cfg_base_addr_index;
3306 u32 trans_offset;
3121 int i, prod_index, err; 3307 int i, prod_index, err;
3122 3308
3123 subsystem_vendor_id = pdev->subsystem_vendor; 3309 subsystem_vendor_id = pdev->subsystem_vendor;
3124 subsystem_device_id = pdev->subsystem_device; 3310 subsystem_device_id = pdev->subsystem_device;
3125 board_id = (((__u32) (subsystem_device_id << 16) & 0xffff0000) | 3311 board_id = (((u32) (subsystem_device_id << 16) & 0xffff0000) |
3126 subsystem_vendor_id); 3312 subsystem_vendor_id);
3127 3313
3128 for (i = 0; i < ARRAY_SIZE(products); i++) 3314 for (i = 0; i < ARRAY_SIZE(products); i++)
@@ -3199,7 +3385,7 @@ static int hpsa_pci_init(struct ctlr_info *h, struct pci_dev *pdev)
3199 3385
3200 /* get the address index number */ 3386 /* get the address index number */
3201 cfg_base_addr = readl(h->vaddr + SA5_CTCFG_OFFSET); 3387 cfg_base_addr = readl(h->vaddr + SA5_CTCFG_OFFSET);
3202 cfg_base_addr &= (__u32) 0x0000ffff; 3388 cfg_base_addr &= (u32) 0x0000ffff;
3203 cfg_base_addr_index = find_PCI_BAR_index(pdev, cfg_base_addr); 3389 cfg_base_addr_index = find_PCI_BAR_index(pdev, cfg_base_addr);
3204 if (cfg_base_addr_index == -1) { 3390 if (cfg_base_addr_index == -1) {
3205 dev_warn(&pdev->dev, "cannot find cfg_base_addr_index\n"); 3391 dev_warn(&pdev->dev, "cannot find cfg_base_addr_index\n");
@@ -3211,11 +3397,14 @@ static int hpsa_pci_init(struct ctlr_info *h, struct pci_dev *pdev)
3211 h->cfgtable = remap_pci_mem(pci_resource_start(pdev, 3397 h->cfgtable = remap_pci_mem(pci_resource_start(pdev,
3212 cfg_base_addr_index) + cfg_offset, 3398 cfg_base_addr_index) + cfg_offset,
3213 sizeof(h->cfgtable)); 3399 sizeof(h->cfgtable));
3214 h->board_id = board_id; 3400 /* Find performant mode table. */
3215 3401 trans_offset = readl(&(h->cfgtable->TransMethodOffset));
3216 /* Query controller for max supported commands: */ 3402 h->transtable = remap_pci_mem(pci_resource_start(pdev,
3217 h->max_commands = readl(&(h->cfgtable->CmdsOutMax)); 3403 cfg_base_addr_index)+cfg_offset+trans_offset,
3404 sizeof(*h->transtable));
3218 3405
3406 h->board_id = board_id;
3407 h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands));
3219 h->product_name = products[prod_index].product_name; 3408 h->product_name = products[prod_index].product_name;
3220 h->access = *(products[prod_index].access); 3409 h->access = *(products[prod_index].access);
3221 /* Allow room for some ioctls */ 3410 /* Allow room for some ioctls */
@@ -3232,7 +3421,7 @@ static int hpsa_pci_init(struct ctlr_info *h, struct pci_dev *pdev)
3232#ifdef CONFIG_X86 3421#ifdef CONFIG_X86
3233 { 3422 {
3234 /* Need to enable prefetch in the SCSI core for 6400 in x86 */ 3423 /* Need to enable prefetch in the SCSI core for 6400 in x86 */
3235 __u32 prefetch; 3424 u32 prefetch;
3236 prefetch = readl(&(h->cfgtable->SCSI_Prefetch)); 3425 prefetch = readl(&(h->cfgtable->SCSI_Prefetch));
3237 prefetch |= 0x100; 3426 prefetch |= 0x100;
3238 writel(prefetch, &(h->cfgtable->SCSI_Prefetch)); 3427 writel(prefetch, &(h->cfgtable->SCSI_Prefetch));
@@ -3244,7 +3433,7 @@ static int hpsa_pci_init(struct ctlr_info *h, struct pci_dev *pdev)
3244 * physical memory. 3433 * physical memory.
3245 */ 3434 */
3246 if (board_id == 0x3225103C) { 3435 if (board_id == 0x3225103C) {
3247 __u32 dma_prefetch; 3436 u32 dma_prefetch;
3248 dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG); 3437 dma_prefetch = readl(h->vaddr + I2O_DMA1_CFG);
3249 dma_prefetch |= 0x8000; 3438 dma_prefetch |= 0x8000;
3250 writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG); 3439 writel(dma_prefetch, h->vaddr + I2O_DMA1_CFG);
@@ -3286,10 +3475,26 @@ err_out_free_res:
3286 return err; 3475 return err;
3287} 3476}
3288 3477
3478static void __devinit hpsa_hba_inquiry(struct ctlr_info *h)
3479{
3480 int rc;
3481
3482#define HBA_INQUIRY_BYTE_COUNT 64
3483 h->hba_inquiry_data = kmalloc(HBA_INQUIRY_BYTE_COUNT, GFP_KERNEL);
3484 if (!h->hba_inquiry_data)
3485 return;
3486 rc = hpsa_scsi_do_inquiry(h, RAID_CTLR_LUNID, 0,
3487 h->hba_inquiry_data, HBA_INQUIRY_BYTE_COUNT);
3488 if (rc != 0) {
3489 kfree(h->hba_inquiry_data);
3490 h->hba_inquiry_data = NULL;
3491 }
3492}
3493
3289static int __devinit hpsa_init_one(struct pci_dev *pdev, 3494static int __devinit hpsa_init_one(struct pci_dev *pdev,
3290 const struct pci_device_id *ent) 3495 const struct pci_device_id *ent)
3291{ 3496{
3292 int i; 3497 int i, rc;
3293 int dac; 3498 int dac;
3294 struct ctlr_info *h; 3499 struct ctlr_info *h;
3295 3500
@@ -3314,17 +3519,23 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
3314 } 3519 }
3315 } 3520 }
3316 3521
3317 BUILD_BUG_ON(sizeof(struct CommandList) % 8); 3522 /* Command structures must be aligned on a 32-byte boundary because
3523 * the 5 lower bits of the address are used by the hardware. and by
3524 * the driver. See comments in hpsa.h for more info.
3525 */
3526#define COMMANDLIST_ALIGNMENT 32
3527 BUILD_BUG_ON(sizeof(struct CommandList) % COMMANDLIST_ALIGNMENT);
3318 h = kzalloc(sizeof(*h), GFP_KERNEL); 3528 h = kzalloc(sizeof(*h), GFP_KERNEL);
3319 if (!h) 3529 if (!h)
3320 return -1; 3530 return -ENOMEM;
3321 3531
3322 h->busy_initializing = 1; 3532 h->busy_initializing = 1;
3323 INIT_HLIST_HEAD(&h->cmpQ); 3533 INIT_HLIST_HEAD(&h->cmpQ);
3324 INIT_HLIST_HEAD(&h->reqQ); 3534 INIT_HLIST_HEAD(&h->reqQ);
3325 mutex_init(&h->busy_shutting_down); 3535 mutex_init(&h->busy_shutting_down);
3326 init_completion(&h->scan_wait); 3536 init_completion(&h->scan_wait);
3327 if (hpsa_pci_init(h, pdev) != 0) 3537 rc = hpsa_pci_init(h, pdev);
3538 if (rc != 0)
3328 goto clean1; 3539 goto clean1;
3329 3540
3330 sprintf(h->devname, "hpsa%d", number_of_controllers); 3541 sprintf(h->devname, "hpsa%d", number_of_controllers);
@@ -3333,27 +3544,32 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
3333 h->pdev = pdev; 3544 h->pdev = pdev;
3334 3545
3335 /* configure PCI DMA stuff */ 3546 /* configure PCI DMA stuff */
3336 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) 3547 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
3548 if (rc == 0) {
3337 dac = 1; 3549 dac = 1;
3338 else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) 3550 } else {
3339 dac = 0; 3551 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
3340 else { 3552 if (rc == 0) {
3341 dev_err(&pdev->dev, "no suitable DMA available\n"); 3553 dac = 0;
3342 goto clean1; 3554 } else {
3555 dev_err(&pdev->dev, "no suitable DMA available\n");
3556 goto clean1;
3557 }
3343 } 3558 }
3344 3559
3345 /* make sure the board interrupts are off */ 3560 /* make sure the board interrupts are off */
3346 h->access.set_intr_mask(h, HPSA_INTR_OFF); 3561 h->access.set_intr_mask(h, HPSA_INTR_OFF);
3347 if (request_irq(h->intr[SIMPLE_MODE_INT], do_hpsa_intr, 3562 rc = request_irq(h->intr[PERF_MODE_INT], do_hpsa_intr,
3348 IRQF_DISABLED | IRQF_SHARED, h->devname, h)) { 3563 IRQF_DISABLED, h->devname, h);
3564 if (rc) {
3349 dev_err(&pdev->dev, "unable to get irq %d for %s\n", 3565 dev_err(&pdev->dev, "unable to get irq %d for %s\n",
3350 h->intr[SIMPLE_MODE_INT], h->devname); 3566 h->intr[PERF_MODE_INT], h->devname);
3351 goto clean2; 3567 goto clean2;
3352 } 3568 }
3353 3569
3354 dev_info(&pdev->dev, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n", 3570 dev_info(&pdev->dev, "%s: <0x%x> at IRQ %d%s using DAC\n",
3355 h->devname, pdev->device, pci_name(pdev), 3571 h->devname, pdev->device,
3356 h->intr[SIMPLE_MODE_INT], dac ? "" : " not"); 3572 h->intr[PERF_MODE_INT], dac ? "" : " not");
3357 3573
3358 h->cmd_pool_bits = 3574 h->cmd_pool_bits =
3359 kmalloc(((h->nr_cmds + BITS_PER_LONG - 3575 kmalloc(((h->nr_cmds + BITS_PER_LONG -
@@ -3368,9 +3584,13 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
3368 || (h->cmd_pool == NULL) 3584 || (h->cmd_pool == NULL)
3369 || (h->errinfo_pool == NULL)) { 3585 || (h->errinfo_pool == NULL)) {
3370 dev_err(&pdev->dev, "out of memory"); 3586 dev_err(&pdev->dev, "out of memory");
3587 rc = -ENOMEM;
3371 goto clean4; 3588 goto clean4;
3372 } 3589 }
3373 spin_lock_init(&h->lock); 3590 spin_lock_init(&h->lock);
3591 spin_lock_init(&h->scan_lock);
3592 init_waitqueue_head(&h->scan_wait_queue);
3593 h->scan_finished = 1; /* no scan currently in progress */
3374 3594
3375 pci_set_drvdata(pdev, h); 3595 pci_set_drvdata(pdev, h);
3376 memset(h->cmd_pool_bits, 0, 3596 memset(h->cmd_pool_bits, 0,
@@ -3382,6 +3602,8 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev,
3382 /* Turn the interrupts on so we can service requests */ 3602 /* Turn the interrupts on so we can service requests */
3383 h->access.set_intr_mask(h, HPSA_INTR_ON); 3603 h->access.set_intr_mask(h, HPSA_INTR_ON);
3384 3604
3605 hpsa_put_ctlr_into_performant_mode(h);
3606 hpsa_hba_inquiry(h);
3385 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */ 3607 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
3386 h->busy_initializing = 0; 3608 h->busy_initializing = 0;
3387 return 1; 3609 return 1;
@@ -3397,12 +3619,12 @@ clean4:
3397 h->nr_cmds * sizeof(struct ErrorInfo), 3619 h->nr_cmds * sizeof(struct ErrorInfo),
3398 h->errinfo_pool, 3620 h->errinfo_pool,
3399 h->errinfo_pool_dhandle); 3621 h->errinfo_pool_dhandle);
3400 free_irq(h->intr[SIMPLE_MODE_INT], h); 3622 free_irq(h->intr[PERF_MODE_INT], h);
3401clean2: 3623clean2:
3402clean1: 3624clean1:
3403 h->busy_initializing = 0; 3625 h->busy_initializing = 0;
3404 kfree(h); 3626 kfree(h);
3405 return -1; 3627 return rc;
3406} 3628}
3407 3629
3408static void hpsa_flush_cache(struct ctlr_info *h) 3630static void hpsa_flush_cache(struct ctlr_info *h)
@@ -3441,7 +3663,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
3441 */ 3663 */
3442 hpsa_flush_cache(h); 3664 hpsa_flush_cache(h);
3443 h->access.set_intr_mask(h, HPSA_INTR_OFF); 3665 h->access.set_intr_mask(h, HPSA_INTR_OFF);
3444 free_irq(h->intr[2], h); 3666 free_irq(h->intr[PERF_MODE_INT], h);
3445#ifdef CONFIG_PCI_MSI 3667#ifdef CONFIG_PCI_MSI
3446 if (h->msix_vector) 3668 if (h->msix_vector)
3447 pci_disable_msix(h->pdev); 3669 pci_disable_msix(h->pdev);
@@ -3470,7 +3692,11 @@ static void __devexit hpsa_remove_one(struct pci_dev *pdev)
3470 pci_free_consistent(h->pdev, 3692 pci_free_consistent(h->pdev,
3471 h->nr_cmds * sizeof(struct ErrorInfo), 3693 h->nr_cmds * sizeof(struct ErrorInfo),
3472 h->errinfo_pool, h->errinfo_pool_dhandle); 3694 h->errinfo_pool, h->errinfo_pool_dhandle);
3695 pci_free_consistent(h->pdev, h->reply_pool_size,
3696 h->reply_pool, h->reply_pool_dhandle);
3473 kfree(h->cmd_pool_bits); 3697 kfree(h->cmd_pool_bits);
3698 kfree(h->blockFetchTable);
3699 kfree(h->hba_inquiry_data);
3474 /* 3700 /*
3475 * Deliberately omit pci_disable_device(): it does something nasty to 3701 * Deliberately omit pci_disable_device(): it does something nasty to
3476 * Smart Array controllers that pci_enable_device does not undo 3702 * Smart Array controllers that pci_enable_device does not undo
@@ -3502,6 +3728,129 @@ static struct pci_driver hpsa_pci_driver = {
3502 .resume = hpsa_resume, 3728 .resume = hpsa_resume,
3503}; 3729};
3504 3730
3731/* Fill in bucket_map[], given nsgs (the max number of
3732 * scatter gather elements supported) and bucket[],
3733 * which is an array of 8 integers. The bucket[] array
3734 * contains 8 different DMA transfer sizes (in 16
3735 * byte increments) which the controller uses to fetch
3736 * commands. This function fills in bucket_map[], which
3737 * maps a given number of scatter gather elements to one of
3738 * the 8 DMA transfer sizes. The point of it is to allow the
3739 * controller to only do as much DMA as needed to fetch the
3740 * command, with the DMA transfer size encoded in the lower
3741 * bits of the command address.
3742 */
3743static void calc_bucket_map(int bucket[], int num_buckets,
3744 int nsgs, int *bucket_map)
3745{
3746 int i, j, b, size;
3747
3748 /* even a command with 0 SGs requires 4 blocks */
3749#define MINIMUM_TRANSFER_BLOCKS 4
3750#define NUM_BUCKETS 8
3751 /* Note, bucket_map must have nsgs+1 entries. */
3752 for (i = 0; i <= nsgs; i++) {
3753 /* Compute size of a command with i SG entries */
3754 size = i + MINIMUM_TRANSFER_BLOCKS;
3755 b = num_buckets; /* Assume the biggest bucket */
3756 /* Find the bucket that is just big enough */
3757 for (j = 0; j < 8; j++) {
3758 if (bucket[j] >= size) {
3759 b = j;
3760 break;
3761 }
3762 }
3763 /* for a command with i SG entries, use bucket b. */
3764 bucket_map[i] = b;
3765 }
3766}
3767
3768static void hpsa_put_ctlr_into_performant_mode(struct ctlr_info *h)
3769{
3770 u32 trans_support;
3771 u64 trans_offset;
3772 /* 5 = 1 s/g entry or 4k
3773 * 6 = 2 s/g entry or 8k
3774 * 8 = 4 s/g entry or 16k
3775 * 10 = 6 s/g entry or 24k
3776 */
3777 int bft[8] = {5, 6, 8, 10, 12, 20, 28, 35}; /* for scatter/gathers */
3778 int i = 0;
3779 int l = 0;
3780 unsigned long register_value;
3781
3782 trans_support = readl(&(h->cfgtable->TransportSupport));
3783 if (!(trans_support & PERFORMANT_MODE))
3784 return;
3785
3786 h->max_commands = readl(&(h->cfgtable->MaxPerformantModeCommands));
3787 h->max_sg_entries = 32;
3788 /* Performant mode ring buffer and supporting data structures */
3789 h->reply_pool_size = h->max_commands * sizeof(u64);
3790 h->reply_pool = pci_alloc_consistent(h->pdev, h->reply_pool_size,
3791 &(h->reply_pool_dhandle));
3792
3793 /* Need a block fetch table for performant mode */
3794 h->blockFetchTable = kmalloc(((h->max_sg_entries+1) *
3795 sizeof(u32)), GFP_KERNEL);
3796
3797 if ((h->reply_pool == NULL)
3798 || (h->blockFetchTable == NULL))
3799 goto clean_up;
3800
3801 h->reply_pool_wraparound = 1; /* spec: init to 1 */
3802
3803 /* Controller spec: zero out this buffer. */
3804 memset(h->reply_pool, 0, h->reply_pool_size);
3805 h->reply_pool_head = h->reply_pool;
3806
3807 trans_offset = readl(&(h->cfgtable->TransMethodOffset));
3808 bft[7] = h->max_sg_entries + 4;
3809 calc_bucket_map(bft, ARRAY_SIZE(bft), 32, h->blockFetchTable);
3810 for (i = 0; i < 8; i++)
3811 writel(bft[i], &h->transtable->BlockFetch[i]);
3812
3813 /* size of controller ring buffer */
3814 writel(h->max_commands, &h->transtable->RepQSize);
3815 writel(1, &h->transtable->RepQCount);
3816 writel(0, &h->transtable->RepQCtrAddrLow32);
3817 writel(0, &h->transtable->RepQCtrAddrHigh32);
3818 writel(h->reply_pool_dhandle, &h->transtable->RepQAddr0Low32);
3819 writel(0, &h->transtable->RepQAddr0High32);
3820 writel(CFGTBL_Trans_Performant,
3821 &(h->cfgtable->HostWrite.TransportRequest));
3822 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
3823 /* under certain very rare conditions, this can take awhile.
3824 * (e.g.: hot replace a failed 144GB drive in a RAID 5 set right
3825 * as we enter this code.) */
3826 for (l = 0; l < MAX_CONFIG_WAIT; l++) {
3827 register_value = readl(h->vaddr + SA5_DOORBELL);
3828 if (!(register_value & CFGTBL_ChangeReq))
3829 break;
3830 /* delay and try again */
3831 set_current_state(TASK_INTERRUPTIBLE);
3832 schedule_timeout(10);
3833 }
3834 register_value = readl(&(h->cfgtable->TransportActive));
3835 if (!(register_value & CFGTBL_Trans_Performant)) {
3836 dev_warn(&h->pdev->dev, "unable to get board into"
3837 " performant mode\n");
3838 return;
3839 }
3840
3841 /* Change the access methods to the performant access methods */
3842 h->access = SA5_performant_access;
3843 h->transMethod = CFGTBL_Trans_Performant;
3844
3845 return;
3846
3847clean_up:
3848 if (h->reply_pool)
3849 pci_free_consistent(h->pdev, h->reply_pool_size,
3850 h->reply_pool, h->reply_pool_dhandle);
3851 kfree(h->blockFetchTable);
3852}
3853
3505/* 3854/*
3506 * This is it. Register the PCI driver information for the cards we control 3855 * This is it. Register the PCI driver information for the cards we control
3507 * the OS will call our registered routines when it finds one of our cards. 3856 * the OS will call our registered routines when it finds one of our cards.
diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
index 6bd1949144b5..a0502b3ac17e 100644
--- a/drivers/scsi/hpsa.h
+++ b/drivers/scsi/hpsa.h
@@ -33,7 +33,7 @@ struct access_method {
33 struct CommandList *c); 33 struct CommandList *c);
34 void (*set_intr_mask)(struct ctlr_info *h, unsigned long val); 34 void (*set_intr_mask)(struct ctlr_info *h, unsigned long val);
35 unsigned long (*fifo_full)(struct ctlr_info *h); 35 unsigned long (*fifo_full)(struct ctlr_info *h);
36 unsigned long (*intr_pending)(struct ctlr_info *h); 36 bool (*intr_pending)(struct ctlr_info *h);
37 unsigned long (*command_completed)(struct ctlr_info *h); 37 unsigned long (*command_completed)(struct ctlr_info *h);
38}; 38};
39 39
@@ -55,19 +55,20 @@ struct ctlr_info {
55 char *product_name; 55 char *product_name;
56 char firm_ver[4]; /* Firmware version */ 56 char firm_ver[4]; /* Firmware version */
57 struct pci_dev *pdev; 57 struct pci_dev *pdev;
58 __u32 board_id; 58 u32 board_id;
59 void __iomem *vaddr; 59 void __iomem *vaddr;
60 unsigned long paddr; 60 unsigned long paddr;
61 int nr_cmds; /* Number of commands allowed on this controller */ 61 int nr_cmds; /* Number of commands allowed on this controller */
62 struct CfgTable __iomem *cfgtable; 62 struct CfgTable __iomem *cfgtable;
63 int max_sg_entries;
63 int interrupts_enabled; 64 int interrupts_enabled;
64 int major; 65 int major;
65 int max_commands; 66 int max_commands;
66 int commands_outstanding; 67 int commands_outstanding;
67 int max_outstanding; /* Debug */ 68 int max_outstanding; /* Debug */
68 int usage_count; /* number of opens all all minor devices */ 69 int usage_count; /* number of opens all all minor devices */
69# define DOORBELL_INT 0 70# define PERF_MODE_INT 0
70# define PERF_MODE_INT 1 71# define DOORBELL_INT 1
71# define SIMPLE_MODE_INT 2 72# define SIMPLE_MODE_INT 2
72# define MEMQ_MODE_INT 3 73# define MEMQ_MODE_INT 3
73 unsigned int intr[4]; 74 unsigned int intr[4];
@@ -93,6 +94,9 @@ struct ctlr_info {
93 int nr_frees; 94 int nr_frees;
94 int busy_initializing; 95 int busy_initializing;
95 int busy_scanning; 96 int busy_scanning;
97 int scan_finished;
98 spinlock_t scan_lock;
99 wait_queue_head_t scan_wait_queue;
96 struct mutex busy_shutting_down; 100 struct mutex busy_shutting_down;
97 struct list_head scan_list; 101 struct list_head scan_list;
98 struct completion scan_wait; 102 struct completion scan_wait;
@@ -102,6 +106,24 @@ struct ctlr_info {
102 int ndevices; /* number of used elements in .dev[] array. */ 106 int ndevices; /* number of used elements in .dev[] array. */
103#define HPSA_MAX_SCSI_DEVS_PER_HBA 256 107#define HPSA_MAX_SCSI_DEVS_PER_HBA 256
104 struct hpsa_scsi_dev_t *dev[HPSA_MAX_SCSI_DEVS_PER_HBA]; 108 struct hpsa_scsi_dev_t *dev[HPSA_MAX_SCSI_DEVS_PER_HBA];
109 /*
110 * Performant mode tables.
111 */
112 u32 trans_support;
113 u32 trans_offset;
114 struct TransTable_struct *transtable;
115 unsigned long transMethod;
116
117 /*
118 * Performant mode completion buffer
119 */
120 u64 *reply_pool;
121 dma_addr_t reply_pool_dhandle;
122 u64 *reply_pool_head;
123 size_t reply_pool_size;
124 unsigned char reply_pool_wraparound;
125 u32 *blockFetchTable;
126 unsigned char *hba_inquiry_data;
105}; 127};
106#define HPSA_ABORT_MSG 0 128#define HPSA_ABORT_MSG 0
107#define HPSA_DEVICE_RESET_MSG 1 129#define HPSA_DEVICE_RESET_MSG 1
@@ -164,9 +186,16 @@ struct ctlr_info {
164#define HPSA_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */ 186#define HPSA_FIRMWARE_READY 0xffff0000 /* value in scratchpad register */
165 187
166#define HPSA_ERROR_BIT 0x02 188#define HPSA_ERROR_BIT 0x02
167#define HPSA_TAG_CONTAINS_INDEX(tag) ((tag) & 0x04) 189
168#define HPSA_TAG_TO_INDEX(tag) ((tag) >> 3) 190/* Performant mode flags */
169#define HPSA_TAG_DISCARD_ERROR_BITS(tag) ((tag) & ~3) 191#define SA5_PERF_INTR_PENDING 0x04
192#define SA5_PERF_INTR_OFF 0x05
193#define SA5_OUTDB_STATUS_PERF_BIT 0x01
194#define SA5_OUTDB_CLEAR_PERF_BIT 0x01
195#define SA5_OUTDB_CLEAR 0xA0
196#define SA5_OUTDB_CLEAR_PERF_BIT 0x01
197#define SA5_OUTDB_STATUS 0x9C
198
170 199
171#define HPSA_INTR_ON 1 200#define HPSA_INTR_ON 1
172#define HPSA_INTR_OFF 0 201#define HPSA_INTR_OFF 0
@@ -176,10 +205,8 @@ struct ctlr_info {
176static void SA5_submit_command(struct ctlr_info *h, 205static void SA5_submit_command(struct ctlr_info *h,
177 struct CommandList *c) 206 struct CommandList *c)
178{ 207{
179#ifdef HPSA_DEBUG 208 dev_dbg(&h->pdev->dev, "Sending %x, tag = %x\n", c->busaddr,
180 printk(KERN_WARNING "hpsa: Sending %x - down to controller\n", 209 c->Header.Tag.lower);
181 c->busaddr);
182#endif /* HPSA_DEBUG */
183 writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET); 210 writel(c->busaddr, h->vaddr + SA5_REQUEST_PORT_OFFSET);
184 h->commands_outstanding++; 211 h->commands_outstanding++;
185 if (h->commands_outstanding > h->max_outstanding) 212 if (h->commands_outstanding > h->max_outstanding)
@@ -202,6 +229,52 @@ static void SA5_intr_mask(struct ctlr_info *h, unsigned long val)
202 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET); 229 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
203 } 230 }
204} 231}
232
233static void SA5_performant_intr_mask(struct ctlr_info *h, unsigned long val)
234{
235 if (val) { /* turn on interrupts */
236 h->interrupts_enabled = 1;
237 writel(0, h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
238 } else {
239 h->interrupts_enabled = 0;
240 writel(SA5_PERF_INTR_OFF,
241 h->vaddr + SA5_REPLY_INTR_MASK_OFFSET);
242 }
243}
244
245static unsigned long SA5_performant_completed(struct ctlr_info *h)
246{
247 unsigned long register_value = FIFO_EMPTY;
248
249 /* flush the controller write of the reply queue by reading
250 * outbound doorbell status register.
251 */
252 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
253 /* msi auto clears the interrupt pending bit. */
254 if (!(h->msi_vector || h->msix_vector)) {
255 writel(SA5_OUTDB_CLEAR_PERF_BIT, h->vaddr + SA5_OUTDB_CLEAR);
256 /* Do a read in order to flush the write to the controller
257 * (as per spec.)
258 */
259 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
260 }
261
262 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
263 register_value = *(h->reply_pool_head);
264 (h->reply_pool_head)++;
265 h->commands_outstanding--;
266 } else {
267 register_value = FIFO_EMPTY;
268 }
269 /* Check for wraparound */
270 if (h->reply_pool_head == (h->reply_pool + h->max_commands)) {
271 h->reply_pool_head = h->reply_pool;
272 h->reply_pool_wraparound ^= 1;
273 }
274
275 return register_value;
276}
277
205/* 278/*
206 * Returns true if fifo is full. 279 * Returns true if fifo is full.
207 * 280 *
@@ -228,10 +301,10 @@ static unsigned long SA5_completed(struct ctlr_info *h)
228 301
229#ifdef HPSA_DEBUG 302#ifdef HPSA_DEBUG
230 if (register_value != FIFO_EMPTY) 303 if (register_value != FIFO_EMPTY)
231 printk(KERN_INFO "hpsa: Read %lx back from board\n", 304 dev_dbg(&h->pdev->dev, "Read %lx back from board\n",
232 register_value); 305 register_value);
233 else 306 else
234 printk(KERN_INFO "hpsa: FIFO Empty read\n"); 307 dev_dbg(&h->pdev->dev, "hpsa: FIFO Empty read\n");
235#endif 308#endif
236 309
237 return register_value; 310 return register_value;
@@ -239,18 +312,28 @@ static unsigned long SA5_completed(struct ctlr_info *h)
239/* 312/*
240 * Returns true if an interrupt is pending.. 313 * Returns true if an interrupt is pending..
241 */ 314 */
242static unsigned long SA5_intr_pending(struct ctlr_info *h) 315static bool SA5_intr_pending(struct ctlr_info *h)
243{ 316{
244 unsigned long register_value = 317 unsigned long register_value =
245 readl(h->vaddr + SA5_INTR_STATUS); 318 readl(h->vaddr + SA5_INTR_STATUS);
246#ifdef HPSA_DEBUG 319 dev_dbg(&h->pdev->dev, "intr_pending %lx\n", register_value);
247 printk(KERN_INFO "hpsa: intr_pending %lx\n", register_value); 320 return register_value & SA5_INTR_PENDING;
248#endif /* HPSA_DEBUG */
249 if (register_value & SA5_INTR_PENDING)
250 return 1;
251 return 0 ;
252} 321}
253 322
323static bool SA5_performant_intr_pending(struct ctlr_info *h)
324{
325 unsigned long register_value = readl(h->vaddr + SA5_INTR_STATUS);
326
327 if (!register_value)
328 return false;
329
330 if (h->msi_vector || h->msix_vector)
331 return true;
332
333 /* Read outbound doorbell to flush */
334 register_value = readl(h->vaddr + SA5_OUTDB_STATUS);
335 return register_value & SA5_OUTDB_STATUS_PERF_BIT;
336}
254 337
255static struct access_method SA5_access = { 338static struct access_method SA5_access = {
256 SA5_submit_command, 339 SA5_submit_command,
@@ -260,14 +343,19 @@ static struct access_method SA5_access = {
260 SA5_completed, 343 SA5_completed,
261}; 344};
262 345
346static struct access_method SA5_performant_access = {
347 SA5_submit_command,
348 SA5_performant_intr_mask,
349 SA5_fifo_full,
350 SA5_performant_intr_pending,
351 SA5_performant_completed,
352};
353
263struct board_type { 354struct board_type {
264 __u32 board_id; 355 u32 board_id;
265 char *product_name; 356 char *product_name;
266 struct access_method *access; 357 struct access_method *access;
267}; 358};
268 359
269
270/* end of old hpsa_scsi.h file */
271
272#endif /* HPSA_H */ 360#endif /* HPSA_H */
273 361
diff --git a/drivers/scsi/hpsa_cmd.h b/drivers/scsi/hpsa_cmd.h
index 12d71387ed9a..3e0abdf76689 100644
--- a/drivers/scsi/hpsa_cmd.h
+++ b/drivers/scsi/hpsa_cmd.h
@@ -101,19 +101,20 @@
101#define CFGTBL_AccCmds 0x00000001l 101#define CFGTBL_AccCmds 0x00000001l
102 102
103#define CFGTBL_Trans_Simple 0x00000002l 103#define CFGTBL_Trans_Simple 0x00000002l
104#define CFGTBL_Trans_Performant 0x00000004l
104 105
105#define CFGTBL_BusType_Ultra2 0x00000001l 106#define CFGTBL_BusType_Ultra2 0x00000001l
106#define CFGTBL_BusType_Ultra3 0x00000002l 107#define CFGTBL_BusType_Ultra3 0x00000002l
107#define CFGTBL_BusType_Fibre1G 0x00000100l 108#define CFGTBL_BusType_Fibre1G 0x00000100l
108#define CFGTBL_BusType_Fibre2G 0x00000200l 109#define CFGTBL_BusType_Fibre2G 0x00000200l
109struct vals32 { 110struct vals32 {
110 __u32 lower; 111 u32 lower;
111 __u32 upper; 112 u32 upper;
112}; 113};
113 114
114union u64bit { 115union u64bit {
115 struct vals32 val32; 116 struct vals32 val32;
116 __u64 val; 117 u64 val;
117}; 118};
118 119
119/* FIXME this is a per controller value (barf!) */ 120/* FIXME this is a per controller value (barf!) */
@@ -126,34 +127,34 @@ union u64bit {
126 127
127#define HPSA_INQUIRY 0x12 128#define HPSA_INQUIRY 0x12
128struct InquiryData { 129struct InquiryData {
129 __u8 data_byte[36]; 130 u8 data_byte[36];
130}; 131};
131 132
132#define HPSA_REPORT_LOG 0xc2 /* Report Logical LUNs */ 133#define HPSA_REPORT_LOG 0xc2 /* Report Logical LUNs */
133#define HPSA_REPORT_PHYS 0xc3 /* Report Physical LUNs */ 134#define HPSA_REPORT_PHYS 0xc3 /* Report Physical LUNs */
134struct ReportLUNdata { 135struct ReportLUNdata {
135 __u8 LUNListLength[4]; 136 u8 LUNListLength[4];
136 __u32 reserved; 137 u32 reserved;
137 __u8 LUN[HPSA_MAX_LUN][8]; 138 u8 LUN[HPSA_MAX_LUN][8];
138}; 139};
139 140
140struct ReportExtendedLUNdata { 141struct ReportExtendedLUNdata {
141 __u8 LUNListLength[4]; 142 u8 LUNListLength[4];
142 __u8 extended_response_flag; 143 u8 extended_response_flag;
143 __u8 reserved[3]; 144 u8 reserved[3];
144 __u8 LUN[HPSA_MAX_LUN][24]; 145 u8 LUN[HPSA_MAX_LUN][24];
145}; 146};
146 147
147struct SenseSubsystem_info { 148struct SenseSubsystem_info {
148 __u8 reserved[36]; 149 u8 reserved[36];
149 __u8 portname[8]; 150 u8 portname[8];
150 __u8 reserved1[1108]; 151 u8 reserved1[1108];
151}; 152};
152 153
153#define HPSA_READ_CAPACITY 0x25 /* Read Capacity */ 154#define HPSA_READ_CAPACITY 0x25 /* Read Capacity */
154struct ReadCapdata { 155struct ReadCapdata {
155 __u8 total_size[4]; /* Total size in blocks */ 156 u8 total_size[4]; /* Total size in blocks */
156 __u8 block_size[4]; /* Size of blocks in bytes */ 157 u8 block_size[4]; /* Size of blocks in bytes */
157}; 158};
158 159
159#if 0 160#if 0
@@ -174,112 +175,131 @@ struct ReadCapdata {
174/* Command List Structure */ 175/* Command List Structure */
175union SCSI3Addr { 176union SCSI3Addr {
176 struct { 177 struct {
177 __u8 Dev; 178 u8 Dev;
178 __u8 Bus:6; 179 u8 Bus:6;
179 __u8 Mode:2; /* b00 */ 180 u8 Mode:2; /* b00 */
180 } PeripDev; 181 } PeripDev;
181 struct { 182 struct {
182 __u8 DevLSB; 183 u8 DevLSB;
183 __u8 DevMSB:6; 184 u8 DevMSB:6;
184 __u8 Mode:2; /* b01 */ 185 u8 Mode:2; /* b01 */
185 } LogDev; 186 } LogDev;
186 struct { 187 struct {
187 __u8 Dev:5; 188 u8 Dev:5;
188 __u8 Bus:3; 189 u8 Bus:3;
189 __u8 Targ:6; 190 u8 Targ:6;
190 __u8 Mode:2; /* b10 */ 191 u8 Mode:2; /* b10 */
191 } LogUnit; 192 } LogUnit;
192}; 193};
193 194
194struct PhysDevAddr { 195struct PhysDevAddr {
195 __u32 TargetId:24; 196 u32 TargetId:24;
196 __u32 Bus:6; 197 u32 Bus:6;
197 __u32 Mode:2; 198 u32 Mode:2;
198 /* 2 level target device addr */ 199 /* 2 level target device addr */
199 union SCSI3Addr Target[2]; 200 union SCSI3Addr Target[2];
200}; 201};
201 202
202struct LogDevAddr { 203struct LogDevAddr {
203 __u32 VolId:30; 204 u32 VolId:30;
204 __u32 Mode:2; 205 u32 Mode:2;
205 __u8 reserved[4]; 206 u8 reserved[4];
206}; 207};
207 208
208union LUNAddr { 209union LUNAddr {
209 __u8 LunAddrBytes[8]; 210 u8 LunAddrBytes[8];
210 union SCSI3Addr SCSI3Lun[4]; 211 union SCSI3Addr SCSI3Lun[4];
211 struct PhysDevAddr PhysDev; 212 struct PhysDevAddr PhysDev;
212 struct LogDevAddr LogDev; 213 struct LogDevAddr LogDev;
213}; 214};
214 215
215struct CommandListHeader { 216struct CommandListHeader {
216 __u8 ReplyQueue; 217 u8 ReplyQueue;
217 __u8 SGList; 218 u8 SGList;
218 __u16 SGTotal; 219 u16 SGTotal;
219 struct vals32 Tag; 220 struct vals32 Tag;
220 union LUNAddr LUN; 221 union LUNAddr LUN;
221}; 222};
222 223
223struct RequestBlock { 224struct RequestBlock {
224 __u8 CDBLen; 225 u8 CDBLen;
225 struct { 226 struct {
226 __u8 Type:3; 227 u8 Type:3;
227 __u8 Attribute:3; 228 u8 Attribute:3;
228 __u8 Direction:2; 229 u8 Direction:2;
229 } Type; 230 } Type;
230 __u16 Timeout; 231 u16 Timeout;
231 __u8 CDB[16]; 232 u8 CDB[16];
232}; 233};
233 234
234struct ErrDescriptor { 235struct ErrDescriptor {
235 struct vals32 Addr; 236 struct vals32 Addr;
236 __u32 Len; 237 u32 Len;
237}; 238};
238 239
239struct SGDescriptor { 240struct SGDescriptor {
240 struct vals32 Addr; 241 struct vals32 Addr;
241 __u32 Len; 242 u32 Len;
242 __u32 Ext; 243 u32 Ext;
243}; 244};
244 245
245union MoreErrInfo { 246union MoreErrInfo {
246 struct { 247 struct {
247 __u8 Reserved[3]; 248 u8 Reserved[3];
248 __u8 Type; 249 u8 Type;
249 __u32 ErrorInfo; 250 u32 ErrorInfo;
250 } Common_Info; 251 } Common_Info;
251 struct { 252 struct {
252 __u8 Reserved[2]; 253 u8 Reserved[2];
253 __u8 offense_size; /* size of offending entry */ 254 u8 offense_size; /* size of offending entry */
254 __u8 offense_num; /* byte # of offense 0-base */ 255 u8 offense_num; /* byte # of offense 0-base */
255 __u32 offense_value; 256 u32 offense_value;
256 } Invalid_Cmd; 257 } Invalid_Cmd;
257}; 258};
258struct ErrorInfo { 259struct ErrorInfo {
259 __u8 ScsiStatus; 260 u8 ScsiStatus;
260 __u8 SenseLen; 261 u8 SenseLen;
261 __u16 CommandStatus; 262 u16 CommandStatus;
262 __u32 ResidualCnt; 263 u32 ResidualCnt;
263 union MoreErrInfo MoreErrInfo; 264 union MoreErrInfo MoreErrInfo;
264 __u8 SenseInfo[SENSEINFOBYTES]; 265 u8 SenseInfo[SENSEINFOBYTES];
265}; 266};
266/* Command types */ 267/* Command types */
267#define CMD_IOCTL_PEND 0x01 268#define CMD_IOCTL_PEND 0x01
268#define CMD_SCSI 0x03 269#define CMD_SCSI 0x03
269 270
271/* This structure needs to be divisible by 32 for new
272 * indexing method and performant mode.
273 */
274#define PAD32 32
275#define PAD64DIFF 0
276#define USEEXTRA ((sizeof(void *) - 4)/4)
277#define PADSIZE (PAD32 + PAD64DIFF * USEEXTRA)
278
279#define DIRECT_LOOKUP_SHIFT 5
280#define DIRECT_LOOKUP_BIT 0x10
281
282#define HPSA_ERROR_BIT 0x02
270struct ctlr_info; /* defined in hpsa.h */ 283struct ctlr_info; /* defined in hpsa.h */
271/* The size of this structure needs to be divisible by 8 284/* The size of this structure needs to be divisible by 32
272 * od on all architectures, because the controller uses 2 285 * on all architectures because low 5 bits of the addresses
273 * lower bits of the address, and the driver uses 1 lower 286 * are used as follows:
274 * bit (3 bits total.) 287 *
288 * bit 0: to device, used to indicate "performant mode" command
289 * from device, indidcates error status.
290 * bit 1-3: to device, indicates block fetch table entry for
291 * reducing DMA in fetching commands from host memory.
292 * bit 4: used to indicate whether tag is "direct lookup" (index),
293 * or a bus address.
275 */ 294 */
295
276struct CommandList { 296struct CommandList {
277 struct CommandListHeader Header; 297 struct CommandListHeader Header;
278 struct RequestBlock Request; 298 struct RequestBlock Request;
279 struct ErrDescriptor ErrDesc; 299 struct ErrDescriptor ErrDesc;
280 struct SGDescriptor SG[MAXSGENTRIES]; 300 struct SGDescriptor SG[MAXSGENTRIES];
281 /* information associated with the command */ 301 /* information associated with the command */
282 __u32 busaddr; /* physical addr of this record */ 302 u32 busaddr; /* physical addr of this record */
283 struct ErrorInfo *err_info; /* pointer to the allocated mem */ 303 struct ErrorInfo *err_info; /* pointer to the allocated mem */
284 struct ctlr_info *h; 304 struct ctlr_info *h;
285 int cmd_type; 305 int cmd_type;
@@ -291,35 +311,63 @@ struct CommandList {
291 struct completion *waiting; 311 struct completion *waiting;
292 int retry_count; 312 int retry_count;
293 void *scsi_cmd; 313 void *scsi_cmd;
314
315/* on 64 bit architectures, to get this to be 32-byte-aligned
316 * it so happens we need no padding, on 32 bit systems,
317 * we need 8 bytes of padding. This does that.
318 */
319#define COMMANDLIST_PAD ((8 - sizeof(long))/4 * 8)
320 u8 pad[COMMANDLIST_PAD];
321
294}; 322};
295 323
296/* Configuration Table Structure */ 324/* Configuration Table Structure */
297struct HostWrite { 325struct HostWrite {
298 __u32 TransportRequest; 326 u32 TransportRequest;
299 __u32 Reserved; 327 u32 Reserved;
300 __u32 CoalIntDelay; 328 u32 CoalIntDelay;
301 __u32 CoalIntCount; 329 u32 CoalIntCount;
302}; 330};
303 331
332#define SIMPLE_MODE 0x02
333#define PERFORMANT_MODE 0x04
334#define MEMQ_MODE 0x08
335
304struct CfgTable { 336struct CfgTable {
305 __u8 Signature[4]; 337 u8 Signature[4];
306 __u32 SpecValence; 338 u32 SpecValence;
307 __u32 TransportSupport; 339 u32 TransportSupport;
308 __u32 TransportActive; 340 u32 TransportActive;
309 struct HostWrite HostWrite; 341 struct HostWrite HostWrite;
310 __u32 CmdsOutMax; 342 u32 CmdsOutMax;
311 __u32 BusTypes; 343 u32 BusTypes;
312 __u32 Reserved; 344 u32 TransMethodOffset;
313 __u8 ServerName[16]; 345 u8 ServerName[16];
314 __u32 HeartBeat; 346 u32 HeartBeat;
315 __u32 SCSI_Prefetch; 347 u32 SCSI_Prefetch;
348 u32 MaxScatterGatherElements;
349 u32 MaxLogicalUnits;
350 u32 MaxPhysicalDevices;
351 u32 MaxPhysicalDrivesPerLogicalUnit;
352 u32 MaxPerformantModeCommands;
353};
354
355#define NUM_BLOCKFETCH_ENTRIES 8
356struct TransTable_struct {
357 u32 BlockFetch[NUM_BLOCKFETCH_ENTRIES];
358 u32 RepQSize;
359 u32 RepQCount;
360 u32 RepQCtrAddrLow32;
361 u32 RepQCtrAddrHigh32;
362 u32 RepQAddr0Low32;
363 u32 RepQAddr0High32;
316}; 364};
317 365
318struct hpsa_pci_info { 366struct hpsa_pci_info {
319 unsigned char bus; 367 unsigned char bus;
320 unsigned char dev_fn; 368 unsigned char dev_fn;
321 unsigned short domain; 369 unsigned short domain;
322 __u32 board_id; 370 u32 board_id;
323}; 371};
324 372
325#pragma pack() 373#pragma pack()
diff --git a/drivers/scsi/ibmmca.c b/drivers/scsi/ibmmca.c
index 9c1e6a5b5af0..9a4b69d4f4eb 100644
--- a/drivers/scsi/ibmmca.c
+++ b/drivers/scsi/ibmmca.c
@@ -2336,7 +2336,7 @@ static int option_setup(char *str)
2336 char *cur = str; 2336 char *cur = str;
2337 int i = 1; 2337 int i = 1;
2338 2338
2339 while (cur && isdigit(*cur) && i <= IM_MAX_HOSTS) { 2339 while (cur && isdigit(*cur) && i < IM_MAX_HOSTS) {
2340 ints[i++] = simple_strtoul(cur, NULL, 0); 2340 ints[i++] = simple_strtoul(cur, NULL, 0);
2341 if ((cur = strchr(cur, ',')) != NULL) 2341 if ((cur = strchr(cur, ',')) != NULL)
2342 cur++; 2342 cur++;
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index e475b7957c2d..e3a18e0ef276 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -40,7 +40,7 @@
40 * (CRQ), which is just a buffer of 16 byte entries in the receiver's 40 * (CRQ), which is just a buffer of 16 byte entries in the receiver's
41 * Senders cannot access the buffer directly, but send messages by 41 * Senders cannot access the buffer directly, but send messages by
42 * making a hypervisor call and passing in the 16 bytes. The hypervisor 42 * making a hypervisor call and passing in the 16 bytes. The hypervisor
43 * puts the message in the next 16 byte space in round-robbin fashion, 43 * puts the message in the next 16 byte space in round-robin fashion,
44 * turns on the high order bit of the message (the valid bit), and 44 * turns on the high order bit of the message (the valid bit), and
45 * generates an interrupt to the receiver (if interrupts are turned on.) 45 * generates an interrupt to the receiver (if interrupts are turned on.)
46 * The receiver just turns off the valid bit when they have copied out 46 * The receiver just turns off the valid bit when they have copied out
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 517da3fd89d3..8a89ba900588 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -584,9 +584,10 @@ static void iscsi_sw_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
584 struct iscsi_conn *conn = cls_conn->dd_data; 584 struct iscsi_conn *conn = cls_conn->dd_data;
585 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 585 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
586 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data; 586 struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
587 struct socket *sock = tcp_sw_conn->sock;
587 588
588 /* userspace may have goofed up and not bound us */ 589 /* userspace may have goofed up and not bound us */
589 if (!tcp_sw_conn->sock) 590 if (!sock)
590 return; 591 return;
591 /* 592 /*
592 * Make sure our recv side is stopped. 593 * Make sure our recv side is stopped.
@@ -597,6 +598,11 @@ static void iscsi_sw_tcp_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
597 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx); 598 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
598 write_unlock_bh(&tcp_sw_conn->sock->sk->sk_callback_lock); 599 write_unlock_bh(&tcp_sw_conn->sock->sk->sk_callback_lock);
599 600
601 if (sock->sk->sk_sleep && waitqueue_active(sock->sk->sk_sleep)) {
602 sock->sk->sk_err = EIO;
603 wake_up_interruptible(sock->sk->sk_sleep);
604 }
605
600 iscsi_conn_stop(cls_conn, flag); 606 iscsi_conn_stop(cls_conn, flag);
601 iscsi_sw_tcp_release_conn(conn); 607 iscsi_sw_tcp_release_conn(conn);
602} 608}
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 19d711cb938c..7f4364770e4a 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -1890,7 +1890,7 @@ static struct fc_seq *fc_exch_seq_send(struct fc_lport *lport,
1890 fc_exch_setup_hdr(ep, fp, ep->f_ctl); 1890 fc_exch_setup_hdr(ep, fp, ep->f_ctl);
1891 sp->cnt++; 1891 sp->cnt++;
1892 1892
1893 if (ep->xid <= lport->lro_xid) 1893 if (ep->xid <= lport->lro_xid && fh->fh_r_ctl == FC_RCTL_DD_UNSOL_CMD)
1894 fc_fcp_ddp_setup(fr_fsp(fp), ep->xid); 1894 fc_fcp_ddp_setup(fr_fsp(fp), ep->xid);
1895 1895
1896 if (unlikely(lport->tt.frame_send(lport, fp))) 1896 if (unlikely(lport->tt.frame_send(lport, fp)))
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 881d5dfe8c74..6fde2fabfd9b 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -298,9 +298,6 @@ void fc_fcp_ddp_setup(struct fc_fcp_pkt *fsp, u16 xid)
298{ 298{
299 struct fc_lport *lport; 299 struct fc_lport *lport;
300 300
301 if (!fsp)
302 return;
303
304 lport = fsp->lp; 301 lport = fsp->lp;
305 if ((fsp->req_flags & FC_SRB_READ) && 302 if ((fsp->req_flags & FC_SRB_READ) &&
306 (lport->lro_enabled) && (lport->tt.ddp_setup)) { 303 (lport->lro_enabled) && (lport->tt.ddp_setup)) {
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 0b165024a219..7ec8ce75007c 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -1800,7 +1800,8 @@ int fc_lport_bsg_request(struct fc_bsg_job *job)
1800 u32 did; 1800 u32 did;
1801 1801
1802 job->reply->reply_payload_rcv_len = 0; 1802 job->reply->reply_payload_rcv_len = 0;
1803 rsp->resid_len = job->reply_payload.payload_len; 1803 if (rsp)
1804 rsp->resid_len = job->reply_payload.payload_len;
1804 1805
1805 mutex_lock(&lport->lp_mutex); 1806 mutex_lock(&lport->lp_mutex);
1806 1807
diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index 02300523b234..97923bb07765 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -623,7 +623,7 @@ static void fc_rport_plogi_resp(struct fc_seq *sp, struct fc_frame *fp,
623 623
624 tov = ntohl(plp->fl_csp.sp_e_d_tov); 624 tov = ntohl(plp->fl_csp.sp_e_d_tov);
625 if (ntohs(plp->fl_csp.sp_features) & FC_SP_FT_EDTR) 625 if (ntohs(plp->fl_csp.sp_features) & FC_SP_FT_EDTR)
626 tov /= 1000; 626 tov /= 1000000;
627 if (tov > rdata->e_d_tov) 627 if (tov > rdata->e_d_tov)
628 rdata->e_d_tov = tov; 628 rdata->e_d_tov = tov;
629 csp_seq = ntohs(plp->fl_csp.sp_tot_seq); 629 csp_seq = ntohs(plp->fl_csp.sp_tot_seq);
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index c28a712fd4db..703eb6a88790 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -1919,10 +1919,11 @@ static int iscsi_has_ping_timed_out(struct iscsi_conn *conn)
1919static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc) 1919static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
1920{ 1920{
1921 enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED; 1921 enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
1922 struct iscsi_task *task = NULL; 1922 struct iscsi_task *task = NULL, *running_task;
1923 struct iscsi_cls_session *cls_session; 1923 struct iscsi_cls_session *cls_session;
1924 struct iscsi_session *session; 1924 struct iscsi_session *session;
1925 struct iscsi_conn *conn; 1925 struct iscsi_conn *conn;
1926 int i;
1926 1927
1927 cls_session = starget_to_session(scsi_target(sc->device)); 1928 cls_session = starget_to_session(scsi_target(sc->device));
1928 session = cls_session->dd_data; 1929 session = cls_session->dd_data;
@@ -1947,8 +1948,15 @@ static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
1947 } 1948 }
1948 1949
1949 task = (struct iscsi_task *)sc->SCp.ptr; 1950 task = (struct iscsi_task *)sc->SCp.ptr;
1950 if (!task) 1951 if (!task) {
1952 /*
1953 * Raced with completion. Just reset timer, and let it
1954 * complete normally
1955 */
1956 rc = BLK_EH_RESET_TIMER;
1951 goto done; 1957 goto done;
1958 }
1959
1952 /* 1960 /*
1953 * If we have sent (at least queued to the network layer) a pdu or 1961 * If we have sent (at least queued to the network layer) a pdu or
1954 * recvd one for the task since the last timeout ask for 1962 * recvd one for the task since the last timeout ask for
@@ -1956,10 +1964,10 @@ static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
1956 * we can check if it is the task or connection when we send the 1964 * we can check if it is the task or connection when we send the
1957 * nop as a ping. 1965 * nop as a ping.
1958 */ 1966 */
1959 if (time_after_eq(task->last_xfer, task->last_timeout)) { 1967 if (time_after(task->last_xfer, task->last_timeout)) {
1960 ISCSI_DBG_EH(session, "Command making progress. Asking " 1968 ISCSI_DBG_EH(session, "Command making progress. Asking "
1961 "scsi-ml for more time to complete. " 1969 "scsi-ml for more time to complete. "
1962 "Last data recv at %lu. Last timeout was at " 1970 "Last data xfer at %lu. Last timeout was at "
1963 "%lu\n.", task->last_xfer, task->last_timeout); 1971 "%lu\n.", task->last_xfer, task->last_timeout);
1964 task->have_checked_conn = false; 1972 task->have_checked_conn = false;
1965 rc = BLK_EH_RESET_TIMER; 1973 rc = BLK_EH_RESET_TIMER;
@@ -1977,6 +1985,43 @@ static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
1977 goto done; 1985 goto done;
1978 } 1986 }
1979 1987
1988 for (i = 0; i < conn->session->cmds_max; i++) {
1989 running_task = conn->session->cmds[i];
1990 if (!running_task->sc || running_task == task ||
1991 running_task->state != ISCSI_TASK_RUNNING)
1992 continue;
1993
1994 /*
1995 * Only check if cmds started before this one have made
1996 * progress, or this could never fail
1997 */
1998 if (time_after(running_task->sc->jiffies_at_alloc,
1999 task->sc->jiffies_at_alloc))
2000 continue;
2001
2002 if (time_after(running_task->last_xfer, task->last_timeout)) {
2003 /*
2004 * This task has not made progress, but a task
2005 * started before us has transferred data since
2006 * we started/last-checked. We could be queueing
2007 * too many tasks or the LU is bad.
2008 *
2009 * If the device is bad the cmds ahead of us on
2010 * other devs will complete, and this loop will
2011 * eventually fail starting the scsi eh.
2012 */
2013 ISCSI_DBG_EH(session, "Command has not made progress "
2014 "but commands ahead of it have. "
2015 "Asking scsi-ml for more time to "
2016 "complete. Our last xfer vs running task "
2017 "last xfer %lu/%lu. Last check %lu.\n",
2018 task->last_xfer, running_task->last_xfer,
2019 task->last_timeout);
2020 rc = BLK_EH_RESET_TIMER;
2021 goto done;
2022 }
2023 }
2024
1980 /* Assumes nop timeout is shorter than scsi cmd timeout */ 2025 /* Assumes nop timeout is shorter than scsi cmd timeout */
1981 if (task->have_checked_conn) 2026 if (task->have_checked_conn)
1982 goto done; 2027 goto done;
diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c
index db6856c138fc..4ad87fd74ddd 100644
--- a/drivers/scsi/libiscsi_tcp.c
+++ b/drivers/scsi/libiscsi_tcp.c
@@ -992,12 +992,10 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct iscsi_task *task)
992 if (r2t == NULL) { 992 if (r2t == NULL) {
993 if (kfifo_out(&tcp_task->r2tqueue, 993 if (kfifo_out(&tcp_task->r2tqueue,
994 (void *)&tcp_task->r2t, sizeof(void *)) != 994 (void *)&tcp_task->r2t, sizeof(void *)) !=
995 sizeof(void *)) { 995 sizeof(void *))
996 WARN_ONCE(1, "unexpected fifo state");
997 r2t = NULL; 996 r2t = NULL;
998 } 997 else
999 998 r2t = tcp_task->r2t;
1000 r2t = tcp_task->r2t;
1001 } 999 }
1002 spin_unlock_bh(&session->lock); 1000 spin_unlock_bh(&session->lock);
1003 } 1001 }
diff --git a/drivers/scsi/libsrp.c b/drivers/scsi/libsrp.c
index ab19b3b4be52..22775165bf6a 100644
--- a/drivers/scsi/libsrp.c
+++ b/drivers/scsi/libsrp.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * SCSI RDAM Protocol lib functions 2 * SCSI RDMA Protocol lib functions
3 * 3 *
4 * Copyright (C) 2006 FUJITA Tomonori <tomof@acm.org> 4 * Copyright (C) 2006 FUJITA Tomonori <tomof@acm.org>
5 * 5 *
@@ -328,7 +328,7 @@ int srp_transfer_data(struct scsi_cmnd *sc, struct srp_cmd *cmd,
328 int offset, err = 0; 328 int offset, err = 0;
329 u8 format; 329 u8 format;
330 330
331 offset = cmd->add_cdb_len * 4; 331 offset = cmd->add_cdb_len & ~3;
332 332
333 dir = srp_cmd_direction(cmd); 333 dir = srp_cmd_direction(cmd);
334 if (dir == DMA_FROM_DEVICE) 334 if (dir == DMA_FROM_DEVICE)
@@ -366,7 +366,7 @@ static int vscsis_data_length(struct srp_cmd *cmd, enum dma_data_direction dir)
366{ 366{
367 struct srp_direct_buf *md; 367 struct srp_direct_buf *md;
368 struct srp_indirect_buf *id; 368 struct srp_indirect_buf *id;
369 int len = 0, offset = cmd->add_cdb_len * 4; 369 int len = 0, offset = cmd->add_cdb_len & ~3;
370 u8 fmt; 370 u8 fmt;
371 371
372 if (dir == DMA_TO_DEVICE) 372 if (dir == DMA_TO_DEVICE)
@@ -440,6 +440,6 @@ int srp_cmd_queue(struct Scsi_Host *shost, struct srp_cmd *cmd, void *info,
440} 440}
441EXPORT_SYMBOL_GPL(srp_cmd_queue); 441EXPORT_SYMBOL_GPL(srp_cmd_queue);
442 442
443MODULE_DESCRIPTION("SCSI RDAM Protocol lib functions"); 443MODULE_DESCRIPTION("SCSI RDMA Protocol lib functions");
444MODULE_AUTHOR("FUJITA Tomonori"); 444MODULE_AUTHOR("FUJITA Tomonori");
445MODULE_LICENSE("GPL"); 445MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index 1cc23a69db5e..84b696463a58 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -315,6 +315,9 @@ struct lpfc_vport {
315#define FC_VPORT_NEEDS_REG_VPI 0x80000 /* Needs to have its vpi registered */ 315#define FC_VPORT_NEEDS_REG_VPI 0x80000 /* Needs to have its vpi registered */
316#define FC_RSCN_DEFERRED 0x100000 /* A deferred RSCN being processed */ 316#define FC_RSCN_DEFERRED 0x100000 /* A deferred RSCN being processed */
317#define FC_VPORT_NEEDS_INIT_VPI 0x200000 /* Need to INIT_VPI before FDISC */ 317#define FC_VPORT_NEEDS_INIT_VPI 0x200000 /* Need to INIT_VPI before FDISC */
318#define FC_VPORT_CVL_RCVD 0x400000 /* VLink failed due to CVL */
319#define FC_VFI_REGISTERED 0x800000 /* VFI is registered */
320#define FC_FDISC_COMPLETED 0x1000000/* FDISC completed */
318 321
319 uint32_t ct_flags; 322 uint32_t ct_flags;
320#define FC_CT_RFF_ID 0x1 /* RFF_ID accepted by switch */ 323#define FC_CT_RFF_ID 0x1 /* RFF_ID accepted by switch */
@@ -448,6 +451,8 @@ struct unsol_rcv_ct_ctx {
448 uint32_t ctxt_id; 451 uint32_t ctxt_id;
449 uint32_t SID; 452 uint32_t SID;
450 uint32_t oxid; 453 uint32_t oxid;
454 uint32_t flags;
455#define UNSOL_VALID 0x00000001
451}; 456};
452 457
453struct lpfc_hba { 458struct lpfc_hba {
@@ -499,6 +504,10 @@ struct lpfc_hba {
499 (struct lpfc_hba *); 504 (struct lpfc_hba *);
500 void (*lpfc_stop_port) 505 void (*lpfc_stop_port)
501 (struct lpfc_hba *); 506 (struct lpfc_hba *);
507 int (*lpfc_hba_init_link)
508 (struct lpfc_hba *);
509 int (*lpfc_hba_down_link)
510 (struct lpfc_hba *);
502 511
503 512
504 /* SLI4 specific HBA data structure */ 513 /* SLI4 specific HBA data structure */
@@ -613,6 +622,7 @@ struct lpfc_hba {
613 uint32_t cfg_enable_bg; 622 uint32_t cfg_enable_bg;
614 uint32_t cfg_log_verbose; 623 uint32_t cfg_log_verbose;
615 uint32_t cfg_aer_support; 624 uint32_t cfg_aer_support;
625 uint32_t cfg_suppress_link_up;
616 626
617 lpfc_vpd_t vpd; /* vital product data */ 627 lpfc_vpd_t vpd; /* vital product data */
618 628
@@ -790,7 +800,7 @@ struct lpfc_hba {
790 uint16_t vlan_id; 800 uint16_t vlan_id;
791 struct list_head fcf_conn_rec_list; 801 struct list_head fcf_conn_rec_list;
792 802
793 struct mutex ct_event_mutex; /* synchronize access to ct_ev_waiters */ 803 spinlock_t ct_ev_lock; /* synchronize access to ct_ev_waiters */
794 struct list_head ct_ev_waiters; 804 struct list_head ct_ev_waiters;
795 struct unsol_rcv_ct_ctx ct_ctx[64]; 805 struct unsol_rcv_ct_ctx ct_ctx[64];
796 uint32_t ctx_idx; 806 uint32_t ctx_idx;
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 91542f786edf..c992e8328f9e 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -482,6 +482,41 @@ lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
482} 482}
483 483
484/** 484/**
485 * lpfc_link_state_store - Transition the link_state on an HBA port
486 * @dev: class device that is converted into a Scsi_host.
487 * @attr: device attribute, not used.
488 * @buf: one or more lpfc_polling_flags values.
489 * @count: not used.
490 *
491 * Returns:
492 * -EINVAL if the buffer is not "up" or "down"
493 * return from link state change function if non-zero
494 * length of the buf on success
495 **/
496static ssize_t
497lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
498 const char *buf, size_t count)
499{
500 struct Scsi_Host *shost = class_to_shost(dev);
501 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
502 struct lpfc_hba *phba = vport->phba;
503
504 int status = -EINVAL;
505
506 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
507 (phba->link_state == LPFC_LINK_DOWN))
508 status = phba->lpfc_hba_init_link(phba);
509 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
510 (phba->link_state >= LPFC_LINK_UP))
511 status = phba->lpfc_hba_down_link(phba);
512
513 if (status == 0)
514 return strlen(buf);
515 else
516 return status;
517}
518
519/**
485 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports 520 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
486 * @dev: class device that is converted into a Scsi_host. 521 * @dev: class device that is converted into a Scsi_host.
487 * @attr: device attribute, not used. 522 * @attr: device attribute, not used.
@@ -1219,7 +1254,7 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1219 struct Scsi_Host *shost = class_to_shost(dev);\ 1254 struct Scsi_Host *shost = class_to_shost(dev);\
1220 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1221 struct lpfc_hba *phba = vport->phba;\ 1256 struct lpfc_hba *phba = vport->phba;\
1222 int val = 0;\ 1257 uint val = 0;\
1223 val = phba->cfg_##attr;\ 1258 val = phba->cfg_##attr;\
1224 return snprintf(buf, PAGE_SIZE, "%d\n",\ 1259 return snprintf(buf, PAGE_SIZE, "%d\n",\
1225 phba->cfg_##attr);\ 1260 phba->cfg_##attr);\
@@ -1247,7 +1282,7 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1247 struct Scsi_Host *shost = class_to_shost(dev);\ 1282 struct Scsi_Host *shost = class_to_shost(dev);\
1248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1283 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1249 struct lpfc_hba *phba = vport->phba;\ 1284 struct lpfc_hba *phba = vport->phba;\
1250 int val = 0;\ 1285 uint val = 0;\
1251 val = phba->cfg_##attr;\ 1286 val = phba->cfg_##attr;\
1252 return snprintf(buf, PAGE_SIZE, "%#x\n",\ 1287 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1253 phba->cfg_##attr);\ 1288 phba->cfg_##attr);\
@@ -1274,7 +1309,7 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1274 **/ 1309 **/
1275#define lpfc_param_init(attr, default, minval, maxval) \ 1310#define lpfc_param_init(attr, default, minval, maxval) \
1276static int \ 1311static int \
1277lpfc_##attr##_init(struct lpfc_hba *phba, int val) \ 1312lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1278{ \ 1313{ \
1279 if (val >= minval && val <= maxval) {\ 1314 if (val >= minval && val <= maxval) {\
1280 phba->cfg_##attr = val;\ 1315 phba->cfg_##attr = val;\
@@ -1309,7 +1344,7 @@ lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
1309 **/ 1344 **/
1310#define lpfc_param_set(attr, default, minval, maxval) \ 1345#define lpfc_param_set(attr, default, minval, maxval) \
1311static int \ 1346static int \
1312lpfc_##attr##_set(struct lpfc_hba *phba, int val) \ 1347lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1313{ \ 1348{ \
1314 if (val >= minval && val <= maxval) {\ 1349 if (val >= minval && val <= maxval) {\
1315 phba->cfg_##attr = val;\ 1350 phba->cfg_##attr = val;\
@@ -1350,7 +1385,7 @@ lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1350 struct Scsi_Host *shost = class_to_shost(dev);\ 1385 struct Scsi_Host *shost = class_to_shost(dev);\
1351 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1352 struct lpfc_hba *phba = vport->phba;\ 1387 struct lpfc_hba *phba = vport->phba;\
1353 int val=0;\ 1388 uint val = 0;\
1354 if (!isdigit(buf[0]))\ 1389 if (!isdigit(buf[0]))\
1355 return -EINVAL;\ 1390 return -EINVAL;\
1356 if (sscanf(buf, "%i", &val) != 1)\ 1391 if (sscanf(buf, "%i", &val) != 1)\
@@ -1382,7 +1417,7 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1382{ \ 1417{ \
1383 struct Scsi_Host *shost = class_to_shost(dev);\ 1418 struct Scsi_Host *shost = class_to_shost(dev);\
1384 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1419 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1385 int val = 0;\ 1420 uint val = 0;\
1386 val = vport->cfg_##attr;\ 1421 val = vport->cfg_##attr;\
1387 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ 1422 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1388} 1423}
@@ -1409,7 +1444,7 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1409{ \ 1444{ \
1410 struct Scsi_Host *shost = class_to_shost(dev);\ 1445 struct Scsi_Host *shost = class_to_shost(dev);\
1411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1412 int val = 0;\ 1447 uint val = 0;\
1413 val = vport->cfg_##attr;\ 1448 val = vport->cfg_##attr;\
1414 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ 1449 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1415} 1450}
@@ -1434,7 +1469,7 @@ lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1434 **/ 1469 **/
1435#define lpfc_vport_param_init(attr, default, minval, maxval) \ 1470#define lpfc_vport_param_init(attr, default, minval, maxval) \
1436static int \ 1471static int \
1437lpfc_##attr##_init(struct lpfc_vport *vport, int val) \ 1472lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1438{ \ 1473{ \
1439 if (val >= minval && val <= maxval) {\ 1474 if (val >= minval && val <= maxval) {\
1440 vport->cfg_##attr = val;\ 1475 vport->cfg_##attr = val;\
@@ -1466,7 +1501,7 @@ lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
1466 **/ 1501 **/
1467#define lpfc_vport_param_set(attr, default, minval, maxval) \ 1502#define lpfc_vport_param_set(attr, default, minval, maxval) \
1468static int \ 1503static int \
1469lpfc_##attr##_set(struct lpfc_vport *vport, int val) \ 1504lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1470{ \ 1505{ \
1471 if (val >= minval && val <= maxval) {\ 1506 if (val >= minval && val <= maxval) {\
1472 vport->cfg_##attr = val;\ 1507 vport->cfg_##attr = val;\
@@ -1502,7 +1537,7 @@ lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1502{ \ 1537{ \
1503 struct Scsi_Host *shost = class_to_shost(dev);\ 1538 struct Scsi_Host *shost = class_to_shost(dev);\
1504 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ 1539 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1505 int val=0;\ 1540 uint val = 0;\
1506 if (!isdigit(buf[0]))\ 1541 if (!isdigit(buf[0]))\
1507 return -EINVAL;\ 1542 return -EINVAL;\
1508 if (sscanf(buf, "%i", &val) != 1)\ 1543 if (sscanf(buf, "%i", &val) != 1)\
@@ -1515,22 +1550,22 @@ lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1515 1550
1516 1551
1517#define LPFC_ATTR(name, defval, minval, maxval, desc) \ 1552#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1518static int lpfc_##name = defval;\ 1553static uint lpfc_##name = defval;\
1519module_param(lpfc_##name, int, 0);\ 1554module_param(lpfc_##name, uint, 0);\
1520MODULE_PARM_DESC(lpfc_##name, desc);\ 1555MODULE_PARM_DESC(lpfc_##name, desc);\
1521lpfc_param_init(name, defval, minval, maxval) 1556lpfc_param_init(name, defval, minval, maxval)
1522 1557
1523#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ 1558#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1524static int lpfc_##name = defval;\ 1559static uint lpfc_##name = defval;\
1525module_param(lpfc_##name, int, 0);\ 1560module_param(lpfc_##name, uint, 0);\
1526MODULE_PARM_DESC(lpfc_##name, desc);\ 1561MODULE_PARM_DESC(lpfc_##name, desc);\
1527lpfc_param_show(name)\ 1562lpfc_param_show(name)\
1528lpfc_param_init(name, defval, minval, maxval)\ 1563lpfc_param_init(name, defval, minval, maxval)\
1529static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 1564static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1530 1565
1531#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ 1566#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1532static int lpfc_##name = defval;\ 1567static uint lpfc_##name = defval;\
1533module_param(lpfc_##name, int, 0);\ 1568module_param(lpfc_##name, uint, 0);\
1534MODULE_PARM_DESC(lpfc_##name, desc);\ 1569MODULE_PARM_DESC(lpfc_##name, desc);\
1535lpfc_param_show(name)\ 1570lpfc_param_show(name)\
1536lpfc_param_init(name, defval, minval, maxval)\ 1571lpfc_param_init(name, defval, minval, maxval)\
@@ -1540,16 +1575,16 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1540 lpfc_##name##_show, lpfc_##name##_store) 1575 lpfc_##name##_show, lpfc_##name##_store)
1541 1576
1542#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ 1577#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1543static int lpfc_##name = defval;\ 1578static uint lpfc_##name = defval;\
1544module_param(lpfc_##name, int, 0);\ 1579module_param(lpfc_##name, uint, 0);\
1545MODULE_PARM_DESC(lpfc_##name, desc);\ 1580MODULE_PARM_DESC(lpfc_##name, desc);\
1546lpfc_param_hex_show(name)\ 1581lpfc_param_hex_show(name)\
1547lpfc_param_init(name, defval, minval, maxval)\ 1582lpfc_param_init(name, defval, minval, maxval)\
1548static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 1583static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1549 1584
1550#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ 1585#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1551static int lpfc_##name = defval;\ 1586static uint lpfc_##name = defval;\
1552module_param(lpfc_##name, int, 0);\ 1587module_param(lpfc_##name, uint, 0);\
1553MODULE_PARM_DESC(lpfc_##name, desc);\ 1588MODULE_PARM_DESC(lpfc_##name, desc);\
1554lpfc_param_hex_show(name)\ 1589lpfc_param_hex_show(name)\
1555lpfc_param_init(name, defval, minval, maxval)\ 1590lpfc_param_init(name, defval, minval, maxval)\
@@ -1559,22 +1594,22 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1559 lpfc_##name##_show, lpfc_##name##_store) 1594 lpfc_##name##_show, lpfc_##name##_store)
1560 1595
1561#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \ 1596#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1562static int lpfc_##name = defval;\ 1597static uint lpfc_##name = defval;\
1563module_param(lpfc_##name, int, 0);\ 1598module_param(lpfc_##name, uint, 0);\
1564MODULE_PARM_DESC(lpfc_##name, desc);\ 1599MODULE_PARM_DESC(lpfc_##name, desc);\
1565lpfc_vport_param_init(name, defval, minval, maxval) 1600lpfc_vport_param_init(name, defval, minval, maxval)
1566 1601
1567#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \ 1602#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1568static int lpfc_##name = defval;\ 1603static uint lpfc_##name = defval;\
1569module_param(lpfc_##name, int, 0);\ 1604module_param(lpfc_##name, uint, 0);\
1570MODULE_PARM_DESC(lpfc_##name, desc);\ 1605MODULE_PARM_DESC(lpfc_##name, desc);\
1571lpfc_vport_param_show(name)\ 1606lpfc_vport_param_show(name)\
1572lpfc_vport_param_init(name, defval, minval, maxval)\ 1607lpfc_vport_param_init(name, defval, minval, maxval)\
1573static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 1608static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1574 1609
1575#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \ 1610#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1576static int lpfc_##name = defval;\ 1611static uint lpfc_##name = defval;\
1577module_param(lpfc_##name, int, 0);\ 1612module_param(lpfc_##name, uint, 0);\
1578MODULE_PARM_DESC(lpfc_##name, desc);\ 1613MODULE_PARM_DESC(lpfc_##name, desc);\
1579lpfc_vport_param_show(name)\ 1614lpfc_vport_param_show(name)\
1580lpfc_vport_param_init(name, defval, minval, maxval)\ 1615lpfc_vport_param_init(name, defval, minval, maxval)\
@@ -1584,16 +1619,16 @@ static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1584 lpfc_##name##_show, lpfc_##name##_store) 1619 lpfc_##name##_show, lpfc_##name##_store)
1585 1620
1586#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \ 1621#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1587static int lpfc_##name = defval;\ 1622static uint lpfc_##name = defval;\
1588module_param(lpfc_##name, int, 0);\ 1623module_param(lpfc_##name, uint, 0);\
1589MODULE_PARM_DESC(lpfc_##name, desc);\ 1624MODULE_PARM_DESC(lpfc_##name, desc);\
1590lpfc_vport_param_hex_show(name)\ 1625lpfc_vport_param_hex_show(name)\
1591lpfc_vport_param_init(name, defval, minval, maxval)\ 1626lpfc_vport_param_init(name, defval, minval, maxval)\
1592static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) 1627static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1593 1628
1594#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ 1629#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1595static int lpfc_##name = defval;\ 1630static uint lpfc_##name = defval;\
1596module_param(lpfc_##name, int, 0);\ 1631module_param(lpfc_##name, uint, 0);\
1597MODULE_PARM_DESC(lpfc_##name, desc);\ 1632MODULE_PARM_DESC(lpfc_##name, desc);\
1598lpfc_vport_param_hex_show(name)\ 1633lpfc_vport_param_hex_show(name)\
1599lpfc_vport_param_init(name, defval, minval, maxval)\ 1634lpfc_vport_param_init(name, defval, minval, maxval)\
@@ -1614,7 +1649,8 @@ static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1614static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); 1649static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1615static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); 1650static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1616static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); 1651static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1617static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL); 1652static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1653 lpfc_link_state_store);
1618static DEVICE_ATTR(option_rom_version, S_IRUGO, 1654static DEVICE_ATTR(option_rom_version, S_IRUGO,
1619 lpfc_option_rom_version_show, NULL); 1655 lpfc_option_rom_version_show, NULL);
1620static DEVICE_ATTR(num_discovered_ports, S_IRUGO, 1656static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
@@ -1897,6 +1933,15 @@ static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1897 lpfc_enable_npiv_show, NULL); 1933 lpfc_enable_npiv_show, NULL);
1898 1934
1899/* 1935/*
1936# lpfc_suppress_link_up: Bring link up at initialization
1937# 0x0 = bring link up (issue MBX_INIT_LINK)
1938# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
1939# 0x2 = never bring up link
1940# Default value is 0.
1941*/
1942LPFC_ATTR_R(suppress_link_up, 0, 0, 2, "Suppress Link Up at initialization");
1943
1944/*
1900# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear 1945# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1901# until the timer expires. Value range is [0,255]. Default value is 30. 1946# until the timer expires. Value range is [0,255]. Default value is 30.
1902*/ 1947*/
@@ -3114,12 +3159,12 @@ LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3114/* 3159/*
3115# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that 3160# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3116# support this feature 3161# support this feature
3117# 0 = MSI disabled (default) 3162# 0 = MSI disabled
3118# 1 = MSI enabled 3163# 1 = MSI enabled
3119# 2 = MSI-X enabled 3164# 2 = MSI-X enabled (default)
3120# Value range is [0,2]. Default value is 0. 3165# Value range is [0,2]. Default value is 2.
3121*/ 3166*/
3122LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or " 3167LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3123 "MSI-X (2), if possible"); 3168 "MSI-X (2), if possible");
3124 3169
3125/* 3170/*
@@ -3278,6 +3323,7 @@ struct device_attribute *lpfc_hba_attrs[] = {
3278 &dev_attr_lpfc_prot_sg_seg_cnt, 3323 &dev_attr_lpfc_prot_sg_seg_cnt,
3279 &dev_attr_lpfc_aer_support, 3324 &dev_attr_lpfc_aer_support,
3280 &dev_attr_lpfc_aer_state_cleanup, 3325 &dev_attr_lpfc_aer_state_cleanup,
3326 &dev_attr_lpfc_suppress_link_up,
3281 NULL, 3327 NULL,
3282}; 3328};
3283 3329
@@ -4456,7 +4502,7 @@ lpfc_get_cfgparam(struct lpfc_hba *phba)
4456 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); 4502 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4457 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose); 4503 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4458 lpfc_aer_support_init(phba, lpfc_aer_support); 4504 lpfc_aer_support_init(phba, lpfc_aer_support);
4459 4505 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
4460 return; 4506 return;
4461} 4507}
4462 4508
diff --git a/drivers/scsi/lpfc/lpfc_bsg.c b/drivers/scsi/lpfc/lpfc_bsg.c
index a5d9048235d9..f3f1bf1a0a71 100644
--- a/drivers/scsi/lpfc/lpfc_bsg.c
+++ b/drivers/scsi/lpfc/lpfc_bsg.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2009 Emulex. All rights reserved. * 4 * Copyright (C) 2009-2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -21,6 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/mempool.h> 22#include <linux/mempool.h>
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/delay.h>
24 25
25#include <scsi/scsi.h> 26#include <scsi/scsi.h>
26#include <scsi/scsi_host.h> 27#include <scsi/scsi_host.h>
@@ -33,6 +34,7 @@
33#include "lpfc_sli.h" 34#include "lpfc_sli.h"
34#include "lpfc_sli4.h" 35#include "lpfc_sli4.h"
35#include "lpfc_nl.h" 36#include "lpfc_nl.h"
37#include "lpfc_bsg.h"
36#include "lpfc_disc.h" 38#include "lpfc_disc.h"
37#include "lpfc_scsi.h" 39#include "lpfc_scsi.h"
38#include "lpfc.h" 40#include "lpfc.h"
@@ -41,14 +43,183 @@
41#include "lpfc_vport.h" 43#include "lpfc_vport.h"
42#include "lpfc_version.h" 44#include "lpfc_version.h"
43 45
46struct lpfc_bsg_event {
47 struct list_head node;
48 struct kref kref;
49 wait_queue_head_t wq;
50
51 /* Event type and waiter identifiers */
52 uint32_t type_mask;
53 uint32_t req_id;
54 uint32_t reg_id;
55
56 /* next two flags are here for the auto-delete logic */
57 unsigned long wait_time_stamp;
58 int waiting;
59
60 /* seen and not seen events */
61 struct list_head events_to_get;
62 struct list_head events_to_see;
63
64 /* job waiting for this event to finish */
65 struct fc_bsg_job *set_job;
66};
67
68struct lpfc_bsg_iocb {
69 struct lpfc_iocbq *cmdiocbq;
70 struct lpfc_iocbq *rspiocbq;
71 struct lpfc_dmabuf *bmp;
72 struct lpfc_nodelist *ndlp;
73
74 /* job waiting for this iocb to finish */
75 struct fc_bsg_job *set_job;
76};
77
78struct lpfc_bsg_mbox {
79 LPFC_MBOXQ_t *pmboxq;
80 MAILBOX_t *mb;
81
82 /* job waiting for this mbox command to finish */
83 struct fc_bsg_job *set_job;
84};
85
86#define TYPE_EVT 1
87#define TYPE_IOCB 2
88#define TYPE_MBOX 3
89struct bsg_job_data {
90 uint32_t type;
91 union {
92 struct lpfc_bsg_event *evt;
93 struct lpfc_bsg_iocb iocb;
94 struct lpfc_bsg_mbox mbox;
95 } context_un;
96};
97
98struct event_data {
99 struct list_head node;
100 uint32_t type;
101 uint32_t immed_dat;
102 void *data;
103 uint32_t len;
104};
105
106#define BUF_SZ_4K 4096
107#define SLI_CT_ELX_LOOPBACK 0x10
108
109enum ELX_LOOPBACK_CMD {
110 ELX_LOOPBACK_XRI_SETUP,
111 ELX_LOOPBACK_DATA,
112};
113
114#define ELX_LOOPBACK_HEADER_SZ \
115 (size_t)(&((struct lpfc_sli_ct_request *)NULL)->un)
116
117struct lpfc_dmabufext {
118 struct lpfc_dmabuf dma;
119 uint32_t size;
120 uint32_t flag;
121};
122
123/**
124 * lpfc_bsg_send_mgmt_cmd_cmp - lpfc_bsg_send_mgmt_cmd's completion handler
125 * @phba: Pointer to HBA context object.
126 * @cmdiocbq: Pointer to command iocb.
127 * @rspiocbq: Pointer to response iocb.
128 *
129 * This function is the completion handler for iocbs issued using
130 * lpfc_bsg_send_mgmt_cmd function. This function is called by the
131 * ring event handler function without any lock held. This function
132 * can be called from both worker thread context and interrupt
133 * context. This function also can be called from another thread which
134 * cleans up the SLI layer objects.
135 * This function copies the contents of the response iocb to the
136 * response iocb memory object provided by the caller of
137 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
138 * sleeps for the iocb completion.
139 **/
140static void
141lpfc_bsg_send_mgmt_cmd_cmp(struct lpfc_hba *phba,
142 struct lpfc_iocbq *cmdiocbq,
143 struct lpfc_iocbq *rspiocbq)
144{
145 unsigned long iflags;
146 struct bsg_job_data *dd_data;
147 struct fc_bsg_job *job;
148 IOCB_t *rsp;
149 struct lpfc_dmabuf *bmp;
150 struct lpfc_nodelist *ndlp;
151 struct lpfc_bsg_iocb *iocb;
152 unsigned long flags;
153 int rc = 0;
154
155 spin_lock_irqsave(&phba->ct_ev_lock, flags);
156 dd_data = cmdiocbq->context1;
157 if (!dd_data) {
158 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
159 return;
160 }
161
162 iocb = &dd_data->context_un.iocb;
163 job = iocb->set_job;
164 job->dd_data = NULL; /* so timeout handler does not reply */
165
166 spin_lock_irqsave(&phba->hbalock, iflags);
167 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
168 if (cmdiocbq->context2 && rspiocbq)
169 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
170 &rspiocbq->iocb, sizeof(IOCB_t));
171 spin_unlock_irqrestore(&phba->hbalock, iflags);
172
173 bmp = iocb->bmp;
174 rspiocbq = iocb->rspiocbq;
175 rsp = &rspiocbq->iocb;
176 ndlp = iocb->ndlp;
177
178 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
179 job->request_payload.sg_cnt, DMA_TO_DEVICE);
180 pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
181 job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
182
183 if (rsp->ulpStatus) {
184 if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
185 switch (rsp->un.ulpWord[4] & 0xff) {
186 case IOERR_SEQUENCE_TIMEOUT:
187 rc = -ETIMEDOUT;
188 break;
189 case IOERR_INVALID_RPI:
190 rc = -EFAULT;
191 break;
192 default:
193 rc = -EACCES;
194 break;
195 }
196 } else
197 rc = -EACCES;
198 } else
199 job->reply->reply_payload_rcv_len =
200 rsp->un.genreq64.bdl.bdeSize;
201
202 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
203 lpfc_sli_release_iocbq(phba, rspiocbq);
204 lpfc_sli_release_iocbq(phba, cmdiocbq);
205 lpfc_nlp_put(ndlp);
206 kfree(bmp);
207 kfree(dd_data);
208 /* make error code available to userspace */
209 job->reply->result = rc;
210 /* complete the job back to userspace */
211 job->job_done(job);
212 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
213 return;
214}
215
44/** 216/**
45 * lpfc_bsg_rport_ct - send a CT command from a bsg request 217 * lpfc_bsg_send_mgmt_cmd - send a CT command from a bsg request
46 * @job: fc_bsg_job to handle 218 * @job: fc_bsg_job to handle
47 */ 219 **/
48static int 220static int
49lpfc_bsg_rport_ct(struct fc_bsg_job *job) 221lpfc_bsg_send_mgmt_cmd(struct fc_bsg_job *job)
50{ 222{
51 struct Scsi_Host *shost = job->shost;
52 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; 223 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
53 struct lpfc_hba *phba = vport->phba; 224 struct lpfc_hba *phba = vport->phba;
54 struct lpfc_rport_data *rdata = job->rport->dd_data; 225 struct lpfc_rport_data *rdata = job->rport->dd_data;
@@ -65,57 +236,60 @@ lpfc_bsg_rport_ct(struct fc_bsg_job *job)
65 struct scatterlist *sgel = NULL; 236 struct scatterlist *sgel = NULL;
66 int numbde; 237 int numbde;
67 dma_addr_t busaddr; 238 dma_addr_t busaddr;
239 struct bsg_job_data *dd_data;
240 uint32_t creg_val;
68 int rc = 0; 241 int rc = 0;
69 242
70 /* in case no data is transferred */ 243 /* in case no data is transferred */
71 job->reply->reply_payload_rcv_len = 0; 244 job->reply->reply_payload_rcv_len = 0;
72 245
246 /* allocate our bsg tracking structure */
247 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
248 if (!dd_data) {
249 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
250 "2733 Failed allocation of dd_data\n");
251 rc = -ENOMEM;
252 goto no_dd_data;
253 }
254
73 if (!lpfc_nlp_get(ndlp)) { 255 if (!lpfc_nlp_get(ndlp)) {
74 job->reply->result = -ENODEV; 256 rc = -ENODEV;
75 return 0; 257 goto no_ndlp;
258 }
259
260 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
261 if (!bmp) {
262 rc = -ENOMEM;
263 goto free_ndlp;
76 } 264 }
77 265
78 if (ndlp->nlp_flag & NLP_ELS_SND_MASK) { 266 if (ndlp->nlp_flag & NLP_ELS_SND_MASK) {
79 rc = -ENODEV; 267 rc = -ENODEV;
80 goto free_ndlp_exit; 268 goto free_bmp;
81 } 269 }
82 270
83 spin_lock_irq(shost->host_lock);
84 cmdiocbq = lpfc_sli_get_iocbq(phba); 271 cmdiocbq = lpfc_sli_get_iocbq(phba);
85 if (!cmdiocbq) { 272 if (!cmdiocbq) {
86 rc = -ENOMEM; 273 rc = -ENOMEM;
87 spin_unlock_irq(shost->host_lock); 274 goto free_bmp;
88 goto free_ndlp_exit;
89 } 275 }
90 cmd = &cmdiocbq->iocb;
91 276
277 cmd = &cmdiocbq->iocb;
92 rspiocbq = lpfc_sli_get_iocbq(phba); 278 rspiocbq = lpfc_sli_get_iocbq(phba);
93 if (!rspiocbq) { 279 if (!rspiocbq) {
94 rc = -ENOMEM; 280 rc = -ENOMEM;
95 goto free_cmdiocbq; 281 goto free_cmdiocbq;
96 } 282 }
97 spin_unlock_irq(shost->host_lock);
98 283
99 rsp = &rspiocbq->iocb; 284 rsp = &rspiocbq->iocb;
100
101 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
102 if (!bmp) {
103 rc = -ENOMEM;
104 spin_lock_irq(shost->host_lock);
105 goto free_rspiocbq;
106 }
107
108 spin_lock_irq(shost->host_lock);
109 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys); 285 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
110 if (!bmp->virt) { 286 if (!bmp->virt) {
111 rc = -ENOMEM; 287 rc = -ENOMEM;
112 goto free_bmp; 288 goto free_rspiocbq;
113 } 289 }
114 spin_unlock_irq(shost->host_lock);
115 290
116 INIT_LIST_HEAD(&bmp->list); 291 INIT_LIST_HEAD(&bmp->list);
117 bpl = (struct ulp_bde64 *) bmp->virt; 292 bpl = (struct ulp_bde64 *) bmp->virt;
118
119 request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, 293 request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list,
120 job->request_payload.sg_cnt, DMA_TO_DEVICE); 294 job->request_payload.sg_cnt, DMA_TO_DEVICE);
121 for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { 295 for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) {
@@ -157,78 +331,152 @@ lpfc_bsg_rport_ct(struct fc_bsg_job *job)
157 cmd->ulpContext = ndlp->nlp_rpi; 331 cmd->ulpContext = ndlp->nlp_rpi;
158 cmd->ulpOwner = OWN_CHIP; 332 cmd->ulpOwner = OWN_CHIP;
159 cmdiocbq->vport = phba->pport; 333 cmdiocbq->vport = phba->pport;
160 cmdiocbq->context1 = NULL; 334 cmdiocbq->context3 = bmp;
161 cmdiocbq->context2 = NULL;
162 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC; 335 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
163
164 timeout = phba->fc_ratov * 2; 336 timeout = phba->fc_ratov * 2;
165 job->dd_data = cmdiocbq; 337 cmd->ulpTimeout = timeout;
166 338
167 rc = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, rspiocbq, 339 cmdiocbq->iocb_cmpl = lpfc_bsg_send_mgmt_cmd_cmp;
168 timeout + LPFC_DRVR_TIMEOUT); 340 cmdiocbq->context1 = dd_data;
169 341 cmdiocbq->context2 = rspiocbq;
170 if (rc != IOCB_TIMEDOUT) { 342 dd_data->type = TYPE_IOCB;
171 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, 343 dd_data->context_un.iocb.cmdiocbq = cmdiocbq;
172 job->request_payload.sg_cnt, DMA_TO_DEVICE); 344 dd_data->context_un.iocb.rspiocbq = rspiocbq;
173 pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, 345 dd_data->context_un.iocb.set_job = job;
174 job->reply_payload.sg_cnt, DMA_FROM_DEVICE); 346 dd_data->context_un.iocb.bmp = bmp;
347 dd_data->context_un.iocb.ndlp = ndlp;
348
349 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
350 creg_val = readl(phba->HCregaddr);
351 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
352 writel(creg_val, phba->HCregaddr);
353 readl(phba->HCregaddr); /* flush */
175 } 354 }
176 355
177 if (rc == IOCB_TIMEDOUT) { 356 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
178 lpfc_sli_release_iocbq(phba, rspiocbq);
179 rc = -EACCES;
180 goto free_ndlp_exit;
181 }
182 357
183 if (rc != IOCB_SUCCESS) { 358 if (rc == IOCB_SUCCESS)
184 rc = -EACCES; 359 return 0; /* done for now */
185 goto free_outdmp;
186 }
187 360
188 if (rsp->ulpStatus) { 361 /* iocb failed so cleanup */
189 if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) { 362 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
190 switch (rsp->un.ulpWord[4] & 0xff) { 363 job->request_payload.sg_cnt, DMA_TO_DEVICE);
191 case IOERR_SEQUENCE_TIMEOUT: 364 pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
192 rc = -ETIMEDOUT; 365 job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
193 break;
194 case IOERR_INVALID_RPI:
195 rc = -EFAULT;
196 break;
197 default:
198 rc = -EACCES;
199 break;
200 }
201 goto free_outdmp;
202 }
203 } else
204 job->reply->reply_payload_rcv_len =
205 rsp->un.genreq64.bdl.bdeSize;
206 366
207free_outdmp:
208 spin_lock_irq(shost->host_lock);
209 lpfc_mbuf_free(phba, bmp->virt, bmp->phys); 367 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
210free_bmp: 368
211 kfree(bmp);
212free_rspiocbq: 369free_rspiocbq:
213 lpfc_sli_release_iocbq(phba, rspiocbq); 370 lpfc_sli_release_iocbq(phba, rspiocbq);
214free_cmdiocbq: 371free_cmdiocbq:
215 lpfc_sli_release_iocbq(phba, cmdiocbq); 372 lpfc_sli_release_iocbq(phba, cmdiocbq);
216 spin_unlock_irq(shost->host_lock); 373free_bmp:
217free_ndlp_exit: 374 kfree(bmp);
375free_ndlp:
218 lpfc_nlp_put(ndlp); 376 lpfc_nlp_put(ndlp);
377no_ndlp:
378 kfree(dd_data);
379no_dd_data:
380 /* make error code available to userspace */
381 job->reply->result = rc;
382 job->dd_data = NULL;
383 return rc;
384}
385
386/**
387 * lpfc_bsg_rport_els_cmp - lpfc_bsg_rport_els's completion handler
388 * @phba: Pointer to HBA context object.
389 * @cmdiocbq: Pointer to command iocb.
390 * @rspiocbq: Pointer to response iocb.
391 *
392 * This function is the completion handler for iocbs issued using
393 * lpfc_bsg_rport_els_cmp function. This function is called by the
394 * ring event handler function without any lock held. This function
395 * can be called from both worker thread context and interrupt
396 * context. This function also can be called from other thread which
397 * cleans up the SLI layer objects.
398 * This function copies the contents of the response iocb to the
399 * response iocb memory object provided by the caller of
400 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
401 * sleeps for the iocb completion.
402 **/
403static void
404lpfc_bsg_rport_els_cmp(struct lpfc_hba *phba,
405 struct lpfc_iocbq *cmdiocbq,
406 struct lpfc_iocbq *rspiocbq)
407{
408 struct bsg_job_data *dd_data;
409 struct fc_bsg_job *job;
410 IOCB_t *rsp;
411 struct lpfc_nodelist *ndlp;
412 struct lpfc_dmabuf *pbuflist = NULL;
413 struct fc_bsg_ctels_reply *els_reply;
414 uint8_t *rjt_data;
415 unsigned long flags;
416 int rc = 0;
417
418 spin_lock_irqsave(&phba->ct_ev_lock, flags);
419 dd_data = cmdiocbq->context1;
420 /* normal completion and timeout crossed paths, already done */
421 if (!dd_data) {
422 spin_unlock_irqrestore(&phba->hbalock, flags);
423 return;
424 }
425
426 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
427 if (cmdiocbq->context2 && rspiocbq)
428 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
429 &rspiocbq->iocb, sizeof(IOCB_t));
430
431 job = dd_data->context_un.iocb.set_job;
432 cmdiocbq = dd_data->context_un.iocb.cmdiocbq;
433 rspiocbq = dd_data->context_un.iocb.rspiocbq;
434 rsp = &rspiocbq->iocb;
435 ndlp = dd_data->context_un.iocb.ndlp;
436
437 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
438 job->request_payload.sg_cnt, DMA_TO_DEVICE);
439 pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
440 job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
219 441
442 if (job->reply->result == -EAGAIN)
443 rc = -EAGAIN;
444 else if (rsp->ulpStatus == IOSTAT_SUCCESS)
445 job->reply->reply_payload_rcv_len =
446 rsp->un.elsreq64.bdl.bdeSize;
447 else if (rsp->ulpStatus == IOSTAT_LS_RJT) {
448 job->reply->reply_payload_rcv_len =
449 sizeof(struct fc_bsg_ctels_reply);
450 /* LS_RJT data returned in word 4 */
451 rjt_data = (uint8_t *)&rsp->un.ulpWord[4];
452 els_reply = &job->reply->reply_data.ctels_reply;
453 els_reply->status = FC_CTELS_STATUS_REJECT;
454 els_reply->rjt_data.action = rjt_data[3];
455 els_reply->rjt_data.reason_code = rjt_data[2];
456 els_reply->rjt_data.reason_explanation = rjt_data[1];
457 els_reply->rjt_data.vendor_unique = rjt_data[0];
458 } else
459 rc = -EIO;
460
461 pbuflist = (struct lpfc_dmabuf *) cmdiocbq->context3;
462 lpfc_mbuf_free(phba, pbuflist->virt, pbuflist->phys);
463 lpfc_sli_release_iocbq(phba, rspiocbq);
464 lpfc_sli_release_iocbq(phba, cmdiocbq);
465 lpfc_nlp_put(ndlp);
466 kfree(dd_data);
220 /* make error code available to userspace */ 467 /* make error code available to userspace */
221 job->reply->result = rc; 468 job->reply->result = rc;
469 job->dd_data = NULL;
222 /* complete the job back to userspace */ 470 /* complete the job back to userspace */
223 job->job_done(job); 471 job->job_done(job);
224 472 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
225 return 0; 473 return;
226} 474}
227 475
228/** 476/**
229 * lpfc_bsg_rport_els - send an ELS command from a bsg request 477 * lpfc_bsg_rport_els - send an ELS command from a bsg request
230 * @job: fc_bsg_job to handle 478 * @job: fc_bsg_job to handle
231 */ 479 **/
232static int 480static int
233lpfc_bsg_rport_els(struct fc_bsg_job *job) 481lpfc_bsg_rport_els(struct fc_bsg_job *job)
234{ 482{
@@ -236,7 +484,6 @@ lpfc_bsg_rport_els(struct fc_bsg_job *job)
236 struct lpfc_hba *phba = vport->phba; 484 struct lpfc_hba *phba = vport->phba;
237 struct lpfc_rport_data *rdata = job->rport->dd_data; 485 struct lpfc_rport_data *rdata = job->rport->dd_data;
238 struct lpfc_nodelist *ndlp = rdata->pnode; 486 struct lpfc_nodelist *ndlp = rdata->pnode;
239
240 uint32_t elscmd; 487 uint32_t elscmd;
241 uint32_t cmdsize; 488 uint32_t cmdsize;
242 uint32_t rspsize; 489 uint32_t rspsize;
@@ -248,20 +495,30 @@ lpfc_bsg_rport_els(struct fc_bsg_job *job)
248 struct lpfc_dmabuf *prsp; 495 struct lpfc_dmabuf *prsp;
249 struct lpfc_dmabuf *pbuflist = NULL; 496 struct lpfc_dmabuf *pbuflist = NULL;
250 struct ulp_bde64 *bpl; 497 struct ulp_bde64 *bpl;
251 int iocb_status;
252 int request_nseg; 498 int request_nseg;
253 int reply_nseg; 499 int reply_nseg;
254 struct scatterlist *sgel = NULL; 500 struct scatterlist *sgel = NULL;
255 int numbde; 501 int numbde;
256 dma_addr_t busaddr; 502 dma_addr_t busaddr;
503 struct bsg_job_data *dd_data;
504 uint32_t creg_val;
257 int rc = 0; 505 int rc = 0;
258 506
259 /* in case no data is transferred */ 507 /* in case no data is transferred */
260 job->reply->reply_payload_rcv_len = 0; 508 job->reply->reply_payload_rcv_len = 0;
261 509
510 /* allocate our bsg tracking structure */
511 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
512 if (!dd_data) {
513 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
514 "2735 Failed allocation of dd_data\n");
515 rc = -ENOMEM;
516 goto no_dd_data;
517 }
518
262 if (!lpfc_nlp_get(ndlp)) { 519 if (!lpfc_nlp_get(ndlp)) {
263 rc = -ENODEV; 520 rc = -ENODEV;
264 goto out; 521 goto free_dd_data;
265 } 522 }
266 523
267 elscmd = job->request->rqst_data.r_els.els_code; 524 elscmd = job->request->rqst_data.r_els.els_code;
@@ -271,24 +528,24 @@ lpfc_bsg_rport_els(struct fc_bsg_job *job)
271 if (!rspiocbq) { 528 if (!rspiocbq) {
272 lpfc_nlp_put(ndlp); 529 lpfc_nlp_put(ndlp);
273 rc = -ENOMEM; 530 rc = -ENOMEM;
274 goto out; 531 goto free_dd_data;
275 } 532 }
276 533
277 rsp = &rspiocbq->iocb; 534 rsp = &rspiocbq->iocb;
278 rpi = ndlp->nlp_rpi; 535 rpi = ndlp->nlp_rpi;
279 536
280 cmdiocbq = lpfc_prep_els_iocb(phba->pport, 1, cmdsize, 0, ndlp, 537 cmdiocbq = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp,
281 ndlp->nlp_DID, elscmd); 538 ndlp->nlp_DID, elscmd);
282
283 if (!cmdiocbq) { 539 if (!cmdiocbq) {
284 lpfc_sli_release_iocbq(phba, rspiocbq); 540 rc = -EIO;
285 return -EIO; 541 goto free_rspiocbq;
286 } 542 }
287 543
288 job->dd_data = cmdiocbq; 544 /* prep els iocb set context1 to the ndlp, context2 to the command
545 * dmabuf, context3 holds the data dmabuf
546 */
289 pcmd = (struct lpfc_dmabuf *) cmdiocbq->context2; 547 pcmd = (struct lpfc_dmabuf *) cmdiocbq->context2;
290 prsp = (struct lpfc_dmabuf *) pcmd->list.next; 548 prsp = (struct lpfc_dmabuf *) pcmd->list.next;
291
292 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys); 549 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
293 kfree(pcmd); 550 kfree(pcmd);
294 lpfc_mbuf_free(phba, prsp->virt, prsp->phys); 551 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
@@ -300,7 +557,6 @@ lpfc_bsg_rport_els(struct fc_bsg_job *job)
300 557
301 request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list, 558 request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list,
302 job->request_payload.sg_cnt, DMA_TO_DEVICE); 559 job->request_payload.sg_cnt, DMA_TO_DEVICE);
303
304 for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) { 560 for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) {
305 busaddr = sg_dma_address(sgel); 561 busaddr = sg_dma_address(sgel);
306 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64; 562 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
@@ -322,7 +578,6 @@ lpfc_bsg_rport_els(struct fc_bsg_job *job)
322 bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr)); 578 bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
323 bpl++; 579 bpl++;
324 } 580 }
325
326 cmdiocbq->iocb.un.elsreq64.bdl.bdeSize = 581 cmdiocbq->iocb.un.elsreq64.bdl.bdeSize =
327 (request_nseg + reply_nseg) * sizeof(struct ulp_bde64); 582 (request_nseg + reply_nseg) * sizeof(struct ulp_bde64);
328 cmdiocbq->iocb.ulpContext = rpi; 583 cmdiocbq->iocb.ulpContext = rpi;
@@ -330,102 +585,62 @@ lpfc_bsg_rport_els(struct fc_bsg_job *job)
330 cmdiocbq->context1 = NULL; 585 cmdiocbq->context1 = NULL;
331 cmdiocbq->context2 = NULL; 586 cmdiocbq->context2 = NULL;
332 587
333 iocb_status = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, 588 cmdiocbq->iocb_cmpl = lpfc_bsg_rport_els_cmp;
334 rspiocbq, (phba->fc_ratov * 2) 589 cmdiocbq->context1 = dd_data;
335 + LPFC_DRVR_TIMEOUT); 590 cmdiocbq->context2 = rspiocbq;
336 591 dd_data->type = TYPE_IOCB;
337 /* release the new ndlp once the iocb completes */ 592 dd_data->context_un.iocb.cmdiocbq = cmdiocbq;
338 lpfc_nlp_put(ndlp); 593 dd_data->context_un.iocb.rspiocbq = rspiocbq;
339 if (iocb_status != IOCB_TIMEDOUT) { 594 dd_data->context_un.iocb.set_job = job;
340 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list, 595 dd_data->context_un.iocb.bmp = NULL;;
341 job->request_payload.sg_cnt, DMA_TO_DEVICE); 596 dd_data->context_un.iocb.ndlp = ndlp;
342 pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list, 597
343 job->reply_payload.sg_cnt, DMA_FROM_DEVICE); 598 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
599 creg_val = readl(phba->HCregaddr);
600 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
601 writel(creg_val, phba->HCregaddr);
602 readl(phba->HCregaddr); /* flush */
344 } 603 }
604 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
605 lpfc_nlp_put(ndlp);
606 if (rc == IOCB_SUCCESS)
607 return 0; /* done for now */
345 608
346 if (iocb_status == IOCB_SUCCESS) { 609 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
347 if (rsp->ulpStatus == IOSTAT_SUCCESS) { 610 job->request_payload.sg_cnt, DMA_TO_DEVICE);
348 job->reply->reply_payload_rcv_len = 611 pci_unmap_sg(phba->pcidev, job->reply_payload.sg_list,
349 rsp->un.elsreq64.bdl.bdeSize; 612 job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
350 rc = 0; 613
351 } else if (rsp->ulpStatus == IOSTAT_LS_RJT) { 614 lpfc_mbuf_free(phba, pbuflist->virt, pbuflist->phys);
352 struct fc_bsg_ctels_reply *els_reply;
353 /* LS_RJT data returned in word 4 */
354 uint8_t *rjt_data = (uint8_t *)&rsp->un.ulpWord[4];
355
356 els_reply = &job->reply->reply_data.ctels_reply;
357 job->reply->result = 0;
358 els_reply->status = FC_CTELS_STATUS_REJECT;
359 els_reply->rjt_data.action = rjt_data[0];
360 els_reply->rjt_data.reason_code = rjt_data[1];
361 els_reply->rjt_data.reason_explanation = rjt_data[2];
362 els_reply->rjt_data.vendor_unique = rjt_data[3];
363 } else
364 rc = -EIO;
365 } else
366 rc = -EIO;
367 615
368 if (iocb_status != IOCB_TIMEDOUT) 616 lpfc_sli_release_iocbq(phba, cmdiocbq);
369 lpfc_els_free_iocb(phba, cmdiocbq);
370 617
618free_rspiocbq:
371 lpfc_sli_release_iocbq(phba, rspiocbq); 619 lpfc_sli_release_iocbq(phba, rspiocbq);
372 620
373out: 621free_dd_data:
622 kfree(dd_data);
623
624no_dd_data:
374 /* make error code available to userspace */ 625 /* make error code available to userspace */
375 job->reply->result = rc; 626 job->reply->result = rc;
376 /* complete the job back to userspace */ 627 job->dd_data = NULL;
377 job->job_done(job); 628 return rc;
378
379 return 0;
380}
381
382struct lpfc_ct_event {
383 struct list_head node;
384 int ref;
385 wait_queue_head_t wq;
386
387 /* Event type and waiter identifiers */
388 uint32_t type_mask;
389 uint32_t req_id;
390 uint32_t reg_id;
391
392 /* next two flags are here for the auto-delete logic */
393 unsigned long wait_time_stamp;
394 int waiting;
395
396 /* seen and not seen events */
397 struct list_head events_to_get;
398 struct list_head events_to_see;
399};
400
401struct event_data {
402 struct list_head node;
403 uint32_t type;
404 uint32_t immed_dat;
405 void *data;
406 uint32_t len;
407};
408
409static struct lpfc_ct_event *
410lpfc_ct_event_new(int ev_reg_id, uint32_t ev_req_id)
411{
412 struct lpfc_ct_event *evt = kzalloc(sizeof(*evt), GFP_KERNEL);
413 if (!evt)
414 return NULL;
415
416 INIT_LIST_HEAD(&evt->events_to_get);
417 INIT_LIST_HEAD(&evt->events_to_see);
418 evt->req_id = ev_req_id;
419 evt->reg_id = ev_reg_id;
420 evt->wait_time_stamp = jiffies;
421 init_waitqueue_head(&evt->wq);
422
423 return evt;
424} 629}
425 630
631/**
632 * lpfc_bsg_event_free - frees an allocated event structure
633 * @kref: Pointer to a kref.
634 *
635 * Called from kref_put. Back cast the kref into an event structure address.
636 * Free any events to get, delete associated nodes, free any events to see,
637 * free any data then free the event itself.
638 **/
426static void 639static void
427lpfc_ct_event_free(struct lpfc_ct_event *evt) 640lpfc_bsg_event_free(struct kref *kref)
428{ 641{
642 struct lpfc_bsg_event *evt = container_of(kref, struct lpfc_bsg_event,
643 kref);
429 struct event_data *ed; 644 struct event_data *ed;
430 645
431 list_del(&evt->node); 646 list_del(&evt->node);
@@ -447,25 +662,82 @@ lpfc_ct_event_free(struct lpfc_ct_event *evt)
447 kfree(evt); 662 kfree(evt);
448} 663}
449 664
665/**
666 * lpfc_bsg_event_ref - increments the kref for an event
667 * @evt: Pointer to an event structure.
668 **/
450static inline void 669static inline void
451lpfc_ct_event_ref(struct lpfc_ct_event *evt) 670lpfc_bsg_event_ref(struct lpfc_bsg_event *evt)
452{ 671{
453 evt->ref++; 672 kref_get(&evt->kref);
454} 673}
455 674
675/**
676 * lpfc_bsg_event_unref - Uses kref_put to free an event structure
677 * @evt: Pointer to an event structure.
678 **/
456static inline void 679static inline void
457lpfc_ct_event_unref(struct lpfc_ct_event *evt) 680lpfc_bsg_event_unref(struct lpfc_bsg_event *evt)
458{ 681{
459 if (--evt->ref < 0) 682 kref_put(&evt->kref, lpfc_bsg_event_free);
460 lpfc_ct_event_free(evt);
461} 683}
462 684
463#define SLI_CT_ELX_LOOPBACK 0x10 685/**
686 * lpfc_bsg_event_new - allocate and initialize a event structure
687 * @ev_mask: Mask of events.
688 * @ev_reg_id: Event reg id.
689 * @ev_req_id: Event request id.
690 **/
691static struct lpfc_bsg_event *
692lpfc_bsg_event_new(uint32_t ev_mask, int ev_reg_id, uint32_t ev_req_id)
693{
694 struct lpfc_bsg_event *evt = kzalloc(sizeof(*evt), GFP_KERNEL);
464 695
465enum ELX_LOOPBACK_CMD { 696 if (!evt)
466 ELX_LOOPBACK_XRI_SETUP, 697 return NULL;
467 ELX_LOOPBACK_DATA, 698
468}; 699 INIT_LIST_HEAD(&evt->events_to_get);
700 INIT_LIST_HEAD(&evt->events_to_see);
701 evt->type_mask = ev_mask;
702 evt->req_id = ev_req_id;
703 evt->reg_id = ev_reg_id;
704 evt->wait_time_stamp = jiffies;
705 init_waitqueue_head(&evt->wq);
706 kref_init(&evt->kref);
707 return evt;
708}
709
710/**
711 * diag_cmd_data_free - Frees an lpfc dma buffer extension
712 * @phba: Pointer to HBA context object.
713 * @mlist: Pointer to an lpfc dma buffer extension.
714 **/
715static int
716diag_cmd_data_free(struct lpfc_hba *phba, struct lpfc_dmabufext *mlist)
717{
718 struct lpfc_dmabufext *mlast;
719 struct pci_dev *pcidev;
720 struct list_head head, *curr, *next;
721
722 if ((!mlist) || (!lpfc_is_link_up(phba) &&
723 (phba->link_flag & LS_LOOPBACK_MODE))) {
724 return 0;
725 }
726
727 pcidev = phba->pcidev;
728 list_add_tail(&head, &mlist->dma.list);
729
730 list_for_each_safe(curr, next, &head) {
731 mlast = list_entry(curr, struct lpfc_dmabufext , dma.list);
732 if (mlast->dma.virt)
733 dma_free_coherent(&pcidev->dev,
734 mlast->size,
735 mlast->dma.virt,
736 mlast->dma.phys);
737 kfree(mlast);
738 }
739 return 0;
740}
469 741
470/** 742/**
471 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command 743 * lpfc_bsg_ct_unsol_event - process an unsolicited CT command
@@ -474,9 +746,9 @@ enum ELX_LOOPBACK_CMD {
474 * @piocbq: 746 * @piocbq:
475 * 747 *
476 * This function is called when an unsolicited CT command is received. It 748 * This function is called when an unsolicited CT command is received. It
477 * forwards the event to any processes registerd to receive CT events. 749 * forwards the event to any processes registered to receive CT events.
478 */ 750 **/
479void 751int
480lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 752lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
481 struct lpfc_iocbq *piocbq) 753 struct lpfc_iocbq *piocbq)
482{ 754{
@@ -484,7 +756,7 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
484 uint32_t cmd; 756 uint32_t cmd;
485 uint32_t len; 757 uint32_t len;
486 struct lpfc_dmabuf *dmabuf = NULL; 758 struct lpfc_dmabuf *dmabuf = NULL;
487 struct lpfc_ct_event *evt; 759 struct lpfc_bsg_event *evt;
488 struct event_data *evt_dat = NULL; 760 struct event_data *evt_dat = NULL;
489 struct lpfc_iocbq *iocbq; 761 struct lpfc_iocbq *iocbq;
490 size_t offset = 0; 762 size_t offset = 0;
@@ -496,6 +768,9 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
496 struct lpfc_dmabuf *bdeBuf2 = piocbq->context3; 768 struct lpfc_dmabuf *bdeBuf2 = piocbq->context3;
497 struct lpfc_hbq_entry *hbqe; 769 struct lpfc_hbq_entry *hbqe;
498 struct lpfc_sli_ct_request *ct_req; 770 struct lpfc_sli_ct_request *ct_req;
771 struct fc_bsg_job *job = NULL;
772 unsigned long flags;
773 int size = 0;
499 774
500 INIT_LIST_HEAD(&head); 775 INIT_LIST_HEAD(&head);
501 list_add_tail(&head, &piocbq->list); 776 list_add_tail(&head, &piocbq->list);
@@ -504,6 +779,10 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
504 piocbq->iocb.un.cont64[0].tus.f.bdeSize == 0) 779 piocbq->iocb.un.cont64[0].tus.f.bdeSize == 0)
505 goto error_ct_unsol_exit; 780 goto error_ct_unsol_exit;
506 781
782 if (phba->link_state == LPFC_HBA_ERROR ||
783 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)))
784 goto error_ct_unsol_exit;
785
507 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) 786 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
508 dmabuf = bdeBuf1; 787 dmabuf = bdeBuf1;
509 else { 788 else {
@@ -511,7 +790,8 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
511 piocbq->iocb.un.cont64[0].addrLow); 790 piocbq->iocb.un.cont64[0].addrLow);
512 dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, dma_addr); 791 dmabuf = lpfc_sli_ringpostbuf_get(phba, pring, dma_addr);
513 } 792 }
514 793 if (dmabuf == NULL)
794 goto error_ct_unsol_exit;
515 ct_req = (struct lpfc_sli_ct_request *)dmabuf->virt; 795 ct_req = (struct lpfc_sli_ct_request *)dmabuf->virt;
516 evt_req_id = ct_req->FsType; 796 evt_req_id = ct_req->FsType;
517 cmd = ct_req->CommandResponse.bits.CmdRsp; 797 cmd = ct_req->CommandResponse.bits.CmdRsp;
@@ -519,24 +799,24 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
519 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) 799 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
520 lpfc_sli_ringpostbuf_put(phba, pring, dmabuf); 800 lpfc_sli_ringpostbuf_put(phba, pring, dmabuf);
521 801
522 mutex_lock(&phba->ct_event_mutex); 802 spin_lock_irqsave(&phba->ct_ev_lock, flags);
523 list_for_each_entry(evt, &phba->ct_ev_waiters, node) { 803 list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
524 if (evt->req_id != evt_req_id) 804 if (!(evt->type_mask & FC_REG_CT_EVENT) ||
805 evt->req_id != evt_req_id)
525 continue; 806 continue;
526 807
527 lpfc_ct_event_ref(evt); 808 lpfc_bsg_event_ref(evt);
528 809 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
529 evt_dat = kzalloc(sizeof(*evt_dat), GFP_KERNEL); 810 evt_dat = kzalloc(sizeof(*evt_dat), GFP_KERNEL);
530 if (!evt_dat) { 811 if (evt_dat == NULL) {
531 lpfc_ct_event_unref(evt); 812 spin_lock_irqsave(&phba->ct_ev_lock, flags);
813 lpfc_bsg_event_unref(evt);
532 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, 814 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
533 "2614 Memory allocation failed for " 815 "2614 Memory allocation failed for "
534 "CT event\n"); 816 "CT event\n");
535 break; 817 break;
536 } 818 }
537 819
538 mutex_unlock(&phba->ct_event_mutex);
539
540 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 820 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
541 /* take accumulated byte count from the last iocbq */ 821 /* take accumulated byte count from the last iocbq */
542 iocbq = list_entry(head.prev, typeof(*iocbq), list); 822 iocbq = list_entry(head.prev, typeof(*iocbq), list);
@@ -550,25 +830,25 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
550 } 830 }
551 831
552 evt_dat->data = kzalloc(evt_dat->len, GFP_KERNEL); 832 evt_dat->data = kzalloc(evt_dat->len, GFP_KERNEL);
553 if (!evt_dat->data) { 833 if (evt_dat->data == NULL) {
554 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, 834 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
555 "2615 Memory allocation failed for " 835 "2615 Memory allocation failed for "
556 "CT event data, size %d\n", 836 "CT event data, size %d\n",
557 evt_dat->len); 837 evt_dat->len);
558 kfree(evt_dat); 838 kfree(evt_dat);
559 mutex_lock(&phba->ct_event_mutex); 839 spin_lock_irqsave(&phba->ct_ev_lock, flags);
560 lpfc_ct_event_unref(evt); 840 lpfc_bsg_event_unref(evt);
561 mutex_unlock(&phba->ct_event_mutex); 841 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
562 goto error_ct_unsol_exit; 842 goto error_ct_unsol_exit;
563 } 843 }
564 844
565 list_for_each_entry(iocbq, &head, list) { 845 list_for_each_entry(iocbq, &head, list) {
846 size = 0;
566 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 847 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
567 bdeBuf1 = iocbq->context2; 848 bdeBuf1 = iocbq->context2;
568 bdeBuf2 = iocbq->context3; 849 bdeBuf2 = iocbq->context3;
569 } 850 }
570 for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) { 851 for (i = 0; i < iocbq->iocb.ulpBdeCount; i++) {
571 int size = 0;
572 if (phba->sli3_options & 852 if (phba->sli3_options &
573 LPFC_SLI3_HBQ_ENABLED) { 853 LPFC_SLI3_HBQ_ENABLED) {
574 if (i == 0) { 854 if (i == 0) {
@@ -601,9 +881,11 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
601 iocbq); 881 iocbq);
602 kfree(evt_dat->data); 882 kfree(evt_dat->data);
603 kfree(evt_dat); 883 kfree(evt_dat);
604 mutex_lock(&phba->ct_event_mutex); 884 spin_lock_irqsave(&phba->ct_ev_lock,
605 lpfc_ct_event_unref(evt); 885 flags);
606 mutex_unlock(&phba->ct_event_mutex); 886 lpfc_bsg_event_unref(evt);
887 spin_unlock_irqrestore(
888 &phba->ct_ev_lock, flags);
607 goto error_ct_unsol_exit; 889 goto error_ct_unsol_exit;
608 } 890 }
609 memcpy((char *)(evt_dat->data) + offset, 891 memcpy((char *)(evt_dat->data) + offset,
@@ -616,15 +898,24 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
616 dmabuf); 898 dmabuf);
617 } else { 899 } else {
618 switch (cmd) { 900 switch (cmd) {
901 case ELX_LOOPBACK_DATA:
902 diag_cmd_data_free(phba,
903 (struct lpfc_dmabufext *)
904 dmabuf);
905 break;
619 case ELX_LOOPBACK_XRI_SETUP: 906 case ELX_LOOPBACK_XRI_SETUP:
620 if (!(phba->sli3_options & 907 if ((phba->sli_rev ==
621 LPFC_SLI3_HBQ_ENABLED)) 908 LPFC_SLI_REV2) ||
909 (phba->sli3_options &
910 LPFC_SLI3_HBQ_ENABLED
911 )) {
912 lpfc_in_buf_free(phba,
913 dmabuf);
914 } else {
622 lpfc_post_buffer(phba, 915 lpfc_post_buffer(phba,
623 pring, 916 pring,
624 1); 917 1);
625 else 918 }
626 lpfc_in_buf_free(phba,
627 dmabuf);
628 break; 919 break;
629 default: 920 default:
630 if (!(phba->sli3_options & 921 if (!(phba->sli3_options &
@@ -638,7 +929,7 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
638 } 929 }
639 } 930 }
640 931
641 mutex_lock(&phba->ct_event_mutex); 932 spin_lock_irqsave(&phba->ct_ev_lock, flags);
642 if (phba->sli_rev == LPFC_SLI_REV4) { 933 if (phba->sli_rev == LPFC_SLI_REV4) {
643 evt_dat->immed_dat = phba->ctx_idx; 934 evt_dat->immed_dat = phba->ctx_idx;
644 phba->ctx_idx = (phba->ctx_idx + 1) % 64; 935 phba->ctx_idx = (phba->ctx_idx + 1) % 64;
@@ -651,122 +942,144 @@ lpfc_bsg_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
651 942
652 evt_dat->type = FC_REG_CT_EVENT; 943 evt_dat->type = FC_REG_CT_EVENT;
653 list_add(&evt_dat->node, &evt->events_to_see); 944 list_add(&evt_dat->node, &evt->events_to_see);
654 wake_up_interruptible(&evt->wq); 945 if (evt_req_id == SLI_CT_ELX_LOOPBACK) {
655 lpfc_ct_event_unref(evt); 946 wake_up_interruptible(&evt->wq);
656 if (evt_req_id == SLI_CT_ELX_LOOPBACK) 947 lpfc_bsg_event_unref(evt);
657 break; 948 break;
949 }
950
951 list_move(evt->events_to_see.prev, &evt->events_to_get);
952 lpfc_bsg_event_unref(evt);
953
954 job = evt->set_job;
955 evt->set_job = NULL;
956 if (job) {
957 job->reply->reply_payload_rcv_len = size;
958 /* make error code available to userspace */
959 job->reply->result = 0;
960 job->dd_data = NULL;
961 /* complete the job back to userspace */
962 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
963 job->job_done(job);
964 spin_lock_irqsave(&phba->ct_ev_lock, flags);
965 }
658 } 966 }
659 mutex_unlock(&phba->ct_event_mutex); 967 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
660 968
661error_ct_unsol_exit: 969error_ct_unsol_exit:
662 if (!list_empty(&head)) 970 if (!list_empty(&head))
663 list_del(&head); 971 list_del(&head);
664 972 if (evt_req_id == SLI_CT_ELX_LOOPBACK)
665 return; 973 return 0;
974 return 1;
666} 975}
667 976
668/** 977/**
669 * lpfc_bsg_set_event - process a SET_EVENT bsg vendor command 978 * lpfc_bsg_hba_set_event - process a SET_EVENT bsg vendor command
670 * @job: SET_EVENT fc_bsg_job 979 * @job: SET_EVENT fc_bsg_job
671 */ 980 **/
672static int 981static int
673lpfc_bsg_set_event(struct fc_bsg_job *job) 982lpfc_bsg_hba_set_event(struct fc_bsg_job *job)
674{ 983{
675 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; 984 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
676 struct lpfc_hba *phba = vport->phba; 985 struct lpfc_hba *phba = vport->phba;
677 struct set_ct_event *event_req; 986 struct set_ct_event *event_req;
678 struct lpfc_ct_event *evt; 987 struct lpfc_bsg_event *evt;
679 int rc = 0; 988 int rc = 0;
989 struct bsg_job_data *dd_data = NULL;
990 uint32_t ev_mask;
991 unsigned long flags;
680 992
681 if (job->request_len < 993 if (job->request_len <
682 sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) { 994 sizeof(struct fc_bsg_request) + sizeof(struct set_ct_event)) {
683 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, 995 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
684 "2612 Received SET_CT_EVENT below minimum " 996 "2612 Received SET_CT_EVENT below minimum "
685 "size\n"); 997 "size\n");
686 return -EINVAL; 998 rc = -EINVAL;
999 goto job_error;
1000 }
1001
1002 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
1003 if (dd_data == NULL) {
1004 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1005 "2734 Failed allocation of dd_data\n");
1006 rc = -ENOMEM;
1007 goto job_error;
687 } 1008 }
688 1009
689 event_req = (struct set_ct_event *) 1010 event_req = (struct set_ct_event *)
690 job->request->rqst_data.h_vendor.vendor_cmd; 1011 job->request->rqst_data.h_vendor.vendor_cmd;
691 1012 ev_mask = ((uint32_t)(unsigned long)event_req->type_mask &
692 mutex_lock(&phba->ct_event_mutex); 1013 FC_REG_EVENT_MASK);
1014 spin_lock_irqsave(&phba->ct_ev_lock, flags);
693 list_for_each_entry(evt, &phba->ct_ev_waiters, node) { 1015 list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
694 if (evt->reg_id == event_req->ev_reg_id) { 1016 if (evt->reg_id == event_req->ev_reg_id) {
695 lpfc_ct_event_ref(evt); 1017 lpfc_bsg_event_ref(evt);
696 evt->wait_time_stamp = jiffies; 1018 evt->wait_time_stamp = jiffies;
697 break; 1019 break;
698 } 1020 }
699 } 1021 }
700 mutex_unlock(&phba->ct_event_mutex); 1022 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
701 1023
702 if (&evt->node == &phba->ct_ev_waiters) { 1024 if (&evt->node == &phba->ct_ev_waiters) {
703 /* no event waiting struct yet - first call */ 1025 /* no event waiting struct yet - first call */
704 evt = lpfc_ct_event_new(event_req->ev_reg_id, 1026 evt = lpfc_bsg_event_new(ev_mask, event_req->ev_reg_id,
705 event_req->ev_req_id); 1027 event_req->ev_req_id);
706 if (!evt) { 1028 if (!evt) {
707 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, 1029 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
708 "2617 Failed allocation of event " 1030 "2617 Failed allocation of event "
709 "waiter\n"); 1031 "waiter\n");
710 return -ENOMEM; 1032 rc = -ENOMEM;
1033 goto job_error;
711 } 1034 }
712 1035
713 mutex_lock(&phba->ct_event_mutex); 1036 spin_lock_irqsave(&phba->ct_ev_lock, flags);
714 list_add(&evt->node, &phba->ct_ev_waiters); 1037 list_add(&evt->node, &phba->ct_ev_waiters);
715 lpfc_ct_event_ref(evt); 1038 lpfc_bsg_event_ref(evt);
716 mutex_unlock(&phba->ct_event_mutex); 1039 evt->wait_time_stamp = jiffies;
1040 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
717 } 1041 }
718 1042
1043 spin_lock_irqsave(&phba->ct_ev_lock, flags);
719 evt->waiting = 1; 1044 evt->waiting = 1;
720 if (wait_event_interruptible(evt->wq, 1045 dd_data->type = TYPE_EVT;
721 !list_empty(&evt->events_to_see))) { 1046 dd_data->context_un.evt = evt;
722 mutex_lock(&phba->ct_event_mutex); 1047 evt->set_job = job; /* for unsolicited command */
723 lpfc_ct_event_unref(evt); /* release ref */ 1048 job->dd_data = dd_data; /* for fc transport timeout callback*/
724 lpfc_ct_event_unref(evt); /* delete */ 1049 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
725 mutex_unlock(&phba->ct_event_mutex); 1050 return 0; /* call job done later */
726 rc = -EINTR; 1051
727 goto set_event_out; 1052job_error:
728 } 1053 if (dd_data != NULL)
729 1054 kfree(dd_data);
730 evt->wait_time_stamp = jiffies; 1055
731 evt->waiting = 0; 1056 job->dd_data = NULL;
732 1057 return rc;
733 mutex_lock(&phba->ct_event_mutex);
734 list_move(evt->events_to_see.prev, &evt->events_to_get);
735 lpfc_ct_event_unref(evt); /* release ref */
736 mutex_unlock(&phba->ct_event_mutex);
737
738set_event_out:
739 /* set_event carries no reply payload */
740 job->reply->reply_payload_rcv_len = 0;
741 /* make error code available to userspace */
742 job->reply->result = rc;
743 /* complete the job back to userspace */
744 job->job_done(job);
745
746 return 0;
747} 1058}
748 1059
749/** 1060/**
750 * lpfc_bsg_get_event - process a GET_EVENT bsg vendor command 1061 * lpfc_bsg_hba_get_event - process a GET_EVENT bsg vendor command
751 * @job: GET_EVENT fc_bsg_job 1062 * @job: GET_EVENT fc_bsg_job
752 */ 1063 **/
753static int 1064static int
754lpfc_bsg_get_event(struct fc_bsg_job *job) 1065lpfc_bsg_hba_get_event(struct fc_bsg_job *job)
755{ 1066{
756 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; 1067 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
757 struct lpfc_hba *phba = vport->phba; 1068 struct lpfc_hba *phba = vport->phba;
758 struct get_ct_event *event_req; 1069 struct get_ct_event *event_req;
759 struct get_ct_event_reply *event_reply; 1070 struct get_ct_event_reply *event_reply;
760 struct lpfc_ct_event *evt; 1071 struct lpfc_bsg_event *evt;
761 struct event_data *evt_dat = NULL; 1072 struct event_data *evt_dat = NULL;
762 int rc = 0; 1073 unsigned long flags;
1074 uint32_t rc = 0;
763 1075
764 if (job->request_len < 1076 if (job->request_len <
765 sizeof(struct fc_bsg_request) + sizeof(struct get_ct_event)) { 1077 sizeof(struct fc_bsg_request) + sizeof(struct get_ct_event)) {
766 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, 1078 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
767 "2613 Received GET_CT_EVENT request below " 1079 "2613 Received GET_CT_EVENT request below "
768 "minimum size\n"); 1080 "minimum size\n");
769 return -EINVAL; 1081 rc = -EINVAL;
1082 goto job_error;
770 } 1083 }
771 1084
772 event_req = (struct get_ct_event *) 1085 event_req = (struct get_ct_event *)
@@ -774,13 +1087,12 @@ lpfc_bsg_get_event(struct fc_bsg_job *job)
774 1087
775 event_reply = (struct get_ct_event_reply *) 1088 event_reply = (struct get_ct_event_reply *)
776 job->reply->reply_data.vendor_reply.vendor_rsp; 1089 job->reply->reply_data.vendor_reply.vendor_rsp;
777 1090 spin_lock_irqsave(&phba->ct_ev_lock, flags);
778 mutex_lock(&phba->ct_event_mutex);
779 list_for_each_entry(evt, &phba->ct_ev_waiters, node) { 1091 list_for_each_entry(evt, &phba->ct_ev_waiters, node) {
780 if (evt->reg_id == event_req->ev_reg_id) { 1092 if (evt->reg_id == event_req->ev_reg_id) {
781 if (list_empty(&evt->events_to_get)) 1093 if (list_empty(&evt->events_to_get))
782 break; 1094 break;
783 lpfc_ct_event_ref(evt); 1095 lpfc_bsg_event_ref(evt);
784 evt->wait_time_stamp = jiffies; 1096 evt->wait_time_stamp = jiffies;
785 evt_dat = list_entry(evt->events_to_get.prev, 1097 evt_dat = list_entry(evt->events_to_get.prev,
786 struct event_data, node); 1098 struct event_data, node);
@@ -788,45 +1100,1539 @@ lpfc_bsg_get_event(struct fc_bsg_job *job)
788 break; 1100 break;
789 } 1101 }
790 } 1102 }
791 mutex_unlock(&phba->ct_event_mutex); 1103 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
792 1104
793 if (!evt_dat) { 1105 /* The app may continue to ask for event data until it gets
1106 * an error indicating that there isn't anymore
1107 */
1108 if (evt_dat == NULL) {
794 job->reply->reply_payload_rcv_len = 0; 1109 job->reply->reply_payload_rcv_len = 0;
795 rc = -ENOENT; 1110 rc = -ENOENT;
796 goto error_get_event_exit; 1111 goto job_error;
797 } 1112 }
798 1113
799 if (evt_dat->len > job->reply_payload.payload_len) { 1114 if (evt_dat->len > job->request_payload.payload_len) {
800 evt_dat->len = job->reply_payload.payload_len; 1115 evt_dat->len = job->request_payload.payload_len;
801 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC, 1116 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
802 "2618 Truncated event data at %d " 1117 "2618 Truncated event data at %d "
803 "bytes\n", 1118 "bytes\n",
804 job->reply_payload.payload_len); 1119 job->request_payload.payload_len);
805 } 1120 }
806 1121
1122 event_reply->type = evt_dat->type;
807 event_reply->immed_data = evt_dat->immed_dat; 1123 event_reply->immed_data = evt_dat->immed_dat;
808
809 if (evt_dat->len > 0) 1124 if (evt_dat->len > 0)
810 job->reply->reply_payload_rcv_len = 1125 job->reply->reply_payload_rcv_len =
811 sg_copy_from_buffer(job->reply_payload.sg_list, 1126 sg_copy_from_buffer(job->request_payload.sg_list,
812 job->reply_payload.sg_cnt, 1127 job->request_payload.sg_cnt,
813 evt_dat->data, evt_dat->len); 1128 evt_dat->data, evt_dat->len);
814 else 1129 else
815 job->reply->reply_payload_rcv_len = 0; 1130 job->reply->reply_payload_rcv_len = 0;
816 rc = 0;
817 1131
818 if (evt_dat) 1132 if (evt_dat) {
819 kfree(evt_dat->data); 1133 kfree(evt_dat->data);
820 kfree(evt_dat); 1134 kfree(evt_dat);
821 mutex_lock(&phba->ct_event_mutex); 1135 }
822 lpfc_ct_event_unref(evt); 1136
823 mutex_unlock(&phba->ct_event_mutex); 1137 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1138 lpfc_bsg_event_unref(evt);
1139 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1140 job->dd_data = NULL;
1141 job->reply->result = 0;
1142 job->job_done(job);
1143 return 0;
1144
1145job_error:
1146 job->dd_data = NULL;
1147 job->reply->result = rc;
1148 return rc;
1149}
1150
1151/**
1152 * lpfc_issue_ct_rsp_cmp - lpfc_issue_ct_rsp's completion handler
1153 * @phba: Pointer to HBA context object.
1154 * @cmdiocbq: Pointer to command iocb.
1155 * @rspiocbq: Pointer to response iocb.
1156 *
1157 * This function is the completion handler for iocbs issued using
1158 * lpfc_issue_ct_rsp_cmp function. This function is called by the
1159 * ring event handler function without any lock held. This function
1160 * can be called from both worker thread context and interrupt
1161 * context. This function also can be called from other thread which
1162 * cleans up the SLI layer objects.
1163 * This function copy the contents of the response iocb to the
1164 * response iocb memory object provided by the caller of
1165 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
1166 * sleeps for the iocb completion.
1167 **/
1168static void
1169lpfc_issue_ct_rsp_cmp(struct lpfc_hba *phba,
1170 struct lpfc_iocbq *cmdiocbq,
1171 struct lpfc_iocbq *rspiocbq)
1172{
1173 struct bsg_job_data *dd_data;
1174 struct fc_bsg_job *job;
1175 IOCB_t *rsp;
1176 struct lpfc_dmabuf *bmp;
1177 struct lpfc_nodelist *ndlp;
1178 unsigned long flags;
1179 int rc = 0;
1180
1181 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1182 dd_data = cmdiocbq->context1;
1183 /* normal completion and timeout crossed paths, already done */
1184 if (!dd_data) {
1185 spin_unlock_irqrestore(&phba->hbalock, flags);
1186 return;
1187 }
824 1188
825error_get_event_exit: 1189 job = dd_data->context_un.iocb.set_job;
1190 bmp = dd_data->context_un.iocb.bmp;
1191 rsp = &rspiocbq->iocb;
1192 ndlp = dd_data->context_un.iocb.ndlp;
1193
1194 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
1195 job->request_payload.sg_cnt, DMA_TO_DEVICE);
1196
1197 if (rsp->ulpStatus) {
1198 if (rsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
1199 switch (rsp->un.ulpWord[4] & 0xff) {
1200 case IOERR_SEQUENCE_TIMEOUT:
1201 rc = -ETIMEDOUT;
1202 break;
1203 case IOERR_INVALID_RPI:
1204 rc = -EFAULT;
1205 break;
1206 default:
1207 rc = -EACCES;
1208 break;
1209 }
1210 } else
1211 rc = -EACCES;
1212 } else
1213 job->reply->reply_payload_rcv_len =
1214 rsp->un.genreq64.bdl.bdeSize;
1215
1216 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1217 lpfc_sli_release_iocbq(phba, cmdiocbq);
1218 lpfc_nlp_put(ndlp);
1219 kfree(bmp);
1220 kfree(dd_data);
826 /* make error code available to userspace */ 1221 /* make error code available to userspace */
827 job->reply->result = rc; 1222 job->reply->result = rc;
1223 job->dd_data = NULL;
828 /* complete the job back to userspace */ 1224 /* complete the job back to userspace */
829 job->job_done(job); 1225 job->job_done(job);
1226 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1227 return;
1228}
1229
1230/**
1231 * lpfc_issue_ct_rsp - issue a ct response
1232 * @phba: Pointer to HBA context object.
1233 * @job: Pointer to the job object.
1234 * @tag: tag index value into the ports context exchange array.
1235 * @bmp: Pointer to a dma buffer descriptor.
1236 * @num_entry: Number of enties in the bde.
1237 **/
1238static int
1239lpfc_issue_ct_rsp(struct lpfc_hba *phba, struct fc_bsg_job *job, uint32_t tag,
1240 struct lpfc_dmabuf *bmp, int num_entry)
1241{
1242 IOCB_t *icmd;
1243 struct lpfc_iocbq *ctiocb = NULL;
1244 int rc = 0;
1245 struct lpfc_nodelist *ndlp = NULL;
1246 struct bsg_job_data *dd_data;
1247 uint32_t creg_val;
1248
1249 /* allocate our bsg tracking structure */
1250 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
1251 if (!dd_data) {
1252 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1253 "2736 Failed allocation of dd_data\n");
1254 rc = -ENOMEM;
1255 goto no_dd_data;
1256 }
1257
1258 /* Allocate buffer for command iocb */
1259 ctiocb = lpfc_sli_get_iocbq(phba);
1260 if (!ctiocb) {
1261 rc = ENOMEM;
1262 goto no_ctiocb;
1263 }
1264
1265 icmd = &ctiocb->iocb;
1266 icmd->un.xseq64.bdl.ulpIoTag32 = 0;
1267 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
1268 icmd->un.xseq64.bdl.addrLow = putPaddrLow(bmp->phys);
1269 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
1270 icmd->un.xseq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
1271 icmd->un.xseq64.w5.hcsw.Fctl = (LS | LA);
1272 icmd->un.xseq64.w5.hcsw.Dfctl = 0;
1273 icmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_SOL_CTL;
1274 icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
1275
1276 /* Fill in rest of iocb */
1277 icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
1278 icmd->ulpBdeCount = 1;
1279 icmd->ulpLe = 1;
1280 icmd->ulpClass = CLASS3;
1281 if (phba->sli_rev == LPFC_SLI_REV4) {
1282 /* Do not issue unsol response if oxid not marked as valid */
1283 if (!(phba->ct_ctx[tag].flags & UNSOL_VALID)) {
1284 rc = IOCB_ERROR;
1285 goto issue_ct_rsp_exit;
1286 }
1287 icmd->ulpContext = phba->ct_ctx[tag].oxid;
1288 ndlp = lpfc_findnode_did(phba->pport, phba->ct_ctx[tag].SID);
1289 if (!ndlp) {
1290 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
1291 "2721 ndlp null for oxid %x SID %x\n",
1292 icmd->ulpContext,
1293 phba->ct_ctx[tag].SID);
1294 rc = IOCB_ERROR;
1295 goto issue_ct_rsp_exit;
1296 }
1297 icmd->un.ulpWord[3] = ndlp->nlp_rpi;
1298 /* The exchange is done, mark the entry as invalid */
1299 phba->ct_ctx[tag].flags &= ~UNSOL_VALID;
1300 } else
1301 icmd->ulpContext = (ushort) tag;
1302
1303 icmd->ulpTimeout = phba->fc_ratov * 2;
1304
1305 /* Xmit CT response on exchange <xid> */
1306 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1307 "2722 Xmit CT response on exchange x%x Data: x%x x%x\n",
1308 icmd->ulpContext, icmd->ulpIoTag, phba->link_state);
1309
1310 ctiocb->iocb_cmpl = NULL;
1311 ctiocb->iocb_flag |= LPFC_IO_LIBDFC;
1312 ctiocb->vport = phba->pport;
1313 ctiocb->context3 = bmp;
1314
1315 ctiocb->iocb_cmpl = lpfc_issue_ct_rsp_cmp;
1316 ctiocb->context1 = dd_data;
1317 ctiocb->context2 = NULL;
1318 dd_data->type = TYPE_IOCB;
1319 dd_data->context_un.iocb.cmdiocbq = ctiocb;
1320 dd_data->context_un.iocb.rspiocbq = NULL;
1321 dd_data->context_un.iocb.set_job = job;
1322 dd_data->context_un.iocb.bmp = bmp;
1323 dd_data->context_un.iocb.ndlp = ndlp;
1324
1325 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1326 creg_val = readl(phba->HCregaddr);
1327 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1328 writel(creg_val, phba->HCregaddr);
1329 readl(phba->HCregaddr); /* flush */
1330 }
1331
1332 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
1333
1334 if (rc == IOCB_SUCCESS)
1335 return 0; /* done for now */
1336
1337issue_ct_rsp_exit:
1338 lpfc_sli_release_iocbq(phba, ctiocb);
1339no_ctiocb:
1340 kfree(dd_data);
1341no_dd_data:
1342 return rc;
1343}
1344
1345/**
1346 * lpfc_bsg_send_mgmt_rsp - process a SEND_MGMT_RESP bsg vendor command
1347 * @job: SEND_MGMT_RESP fc_bsg_job
1348 **/
1349static int
1350lpfc_bsg_send_mgmt_rsp(struct fc_bsg_job *job)
1351{
1352 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
1353 struct lpfc_hba *phba = vport->phba;
1354 struct send_mgmt_resp *mgmt_resp = (struct send_mgmt_resp *)
1355 job->request->rqst_data.h_vendor.vendor_cmd;
1356 struct ulp_bde64 *bpl;
1357 struct lpfc_dmabuf *bmp = NULL;
1358 struct scatterlist *sgel = NULL;
1359 int request_nseg;
1360 int numbde;
1361 dma_addr_t busaddr;
1362 uint32_t tag = mgmt_resp->tag;
1363 unsigned long reqbfrcnt =
1364 (unsigned long)job->request_payload.payload_len;
1365 int rc = 0;
1366
1367 /* in case no data is transferred */
1368 job->reply->reply_payload_rcv_len = 0;
1369
1370 if (!reqbfrcnt || (reqbfrcnt > (80 * BUF_SZ_4K))) {
1371 rc = -ERANGE;
1372 goto send_mgmt_rsp_exit;
1373 }
1374
1375 bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1376 if (!bmp) {
1377 rc = -ENOMEM;
1378 goto send_mgmt_rsp_exit;
1379 }
1380
1381 bmp->virt = lpfc_mbuf_alloc(phba, 0, &bmp->phys);
1382 if (!bmp->virt) {
1383 rc = -ENOMEM;
1384 goto send_mgmt_rsp_free_bmp;
1385 }
1386
1387 INIT_LIST_HEAD(&bmp->list);
1388 bpl = (struct ulp_bde64 *) bmp->virt;
1389 request_nseg = pci_map_sg(phba->pcidev, job->request_payload.sg_list,
1390 job->request_payload.sg_cnt, DMA_TO_DEVICE);
1391 for_each_sg(job->request_payload.sg_list, sgel, request_nseg, numbde) {
1392 busaddr = sg_dma_address(sgel);
1393 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1394 bpl->tus.f.bdeSize = sg_dma_len(sgel);
1395 bpl->tus.w = cpu_to_le32(bpl->tus.w);
1396 bpl->addrLow = cpu_to_le32(putPaddrLow(busaddr));
1397 bpl->addrHigh = cpu_to_le32(putPaddrHigh(busaddr));
1398 bpl++;
1399 }
1400
1401 rc = lpfc_issue_ct_rsp(phba, job, tag, bmp, request_nseg);
1402
1403 if (rc == IOCB_SUCCESS)
1404 return 0; /* done for now */
1405
1406 /* TBD need to handle a timeout */
1407 pci_unmap_sg(phba->pcidev, job->request_payload.sg_list,
1408 job->request_payload.sg_cnt, DMA_TO_DEVICE);
1409 rc = -EACCES;
1410 lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
1411
1412send_mgmt_rsp_free_bmp:
1413 kfree(bmp);
1414send_mgmt_rsp_exit:
1415 /* make error code available to userspace */
1416 job->reply->result = rc;
1417 job->dd_data = NULL;
1418 return rc;
1419}
1420
1421/**
1422 * lpfc_bsg_diag_mode - process a LPFC_BSG_VENDOR_DIAG_MODE bsg vendor command
1423 * @job: LPFC_BSG_VENDOR_DIAG_MODE
1424 *
1425 * This function is responsible for placing a port into diagnostic loopback
1426 * mode in order to perform a diagnostic loopback test.
1427 * All new scsi requests are blocked, a small delay is used to allow the
1428 * scsi requests to complete then the link is brought down. If the link is
1429 * is placed in loopback mode then scsi requests are again allowed
1430 * so the scsi mid-layer doesn't give up on the port.
1431 * All of this is done in-line.
1432 */
1433static int
1434lpfc_bsg_diag_mode(struct fc_bsg_job *job)
1435{
1436 struct Scsi_Host *shost = job->shost;
1437 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
1438 struct lpfc_hba *phba = vport->phba;
1439 struct diag_mode_set *loopback_mode;
1440 struct lpfc_sli *psli = &phba->sli;
1441 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
1442 uint32_t link_flags;
1443 uint32_t timeout;
1444 struct lpfc_vport **vports;
1445 LPFC_MBOXQ_t *pmboxq;
1446 int mbxstatus;
1447 int i = 0;
1448 int rc = 0;
1449
1450 /* no data to return just the return code */
1451 job->reply->reply_payload_rcv_len = 0;
1452
1453 if (job->request_len <
1454 sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_set)) {
1455 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
1456 "2738 Received DIAG MODE request below minimum "
1457 "size\n");
1458 rc = -EINVAL;
1459 goto job_error;
1460 }
1461
1462 loopback_mode = (struct diag_mode_set *)
1463 job->request->rqst_data.h_vendor.vendor_cmd;
1464 link_flags = loopback_mode->type;
1465 timeout = loopback_mode->timeout;
1466
1467 if ((phba->link_state == LPFC_HBA_ERROR) ||
1468 (psli->sli_flag & LPFC_BLOCK_MGMT_IO) ||
1469 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
1470 rc = -EACCES;
1471 goto job_error;
1472 }
1473
1474 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1475 if (!pmboxq) {
1476 rc = -ENOMEM;
1477 goto job_error;
1478 }
1479
1480 vports = lpfc_create_vport_work_array(phba);
1481 if (vports) {
1482 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1483 shost = lpfc_shost_from_vport(vports[i]);
1484 scsi_block_requests(shost);
1485 }
1486
1487 lpfc_destroy_vport_work_array(phba, vports);
1488 } else {
1489 shost = lpfc_shost_from_vport(phba->pport);
1490 scsi_block_requests(shost);
1491 }
1492
1493 while (pring->txcmplq_cnt) {
1494 if (i++ > 500) /* wait up to 5 seconds */
1495 break;
1496
1497 msleep(10);
1498 }
1499
1500 memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1501 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1502 pmboxq->u.mb.mbxOwner = OWN_HOST;
1503
1504 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO);
1505
1506 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->u.mb.mbxStatus == 0)) {
1507 /* wait for link down before proceeding */
1508 i = 0;
1509 while (phba->link_state != LPFC_LINK_DOWN) {
1510 if (i++ > timeout) {
1511 rc = -ETIMEDOUT;
1512 goto loopback_mode_exit;
1513 }
1514
1515 msleep(10);
1516 }
1517
1518 memset((void *)pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1519 if (link_flags == INTERNAL_LOOP_BACK)
1520 pmboxq->u.mb.un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
1521 else
1522 pmboxq->u.mb.un.varInitLnk.link_flags =
1523 FLAGS_TOPOLOGY_MODE_LOOP;
1524
1525 pmboxq->u.mb.mbxCommand = MBX_INIT_LINK;
1526 pmboxq->u.mb.mbxOwner = OWN_HOST;
1527
1528 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1529 LPFC_MBOX_TMO);
1530
1531 if ((mbxstatus != MBX_SUCCESS) || (pmboxq->u.mb.mbxStatus))
1532 rc = -ENODEV;
1533 else {
1534 phba->link_flag |= LS_LOOPBACK_MODE;
1535 /* wait for the link attention interrupt */
1536 msleep(100);
1537
1538 i = 0;
1539 while (phba->link_state != LPFC_HBA_READY) {
1540 if (i++ > timeout) {
1541 rc = -ETIMEDOUT;
1542 break;
1543 }
1544
1545 msleep(10);
1546 }
1547 }
1548
1549 } else
1550 rc = -ENODEV;
1551
1552loopback_mode_exit:
1553 vports = lpfc_create_vport_work_array(phba);
1554 if (vports) {
1555 for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
1556 shost = lpfc_shost_from_vport(vports[i]);
1557 scsi_unblock_requests(shost);
1558 }
1559 lpfc_destroy_vport_work_array(phba, vports);
1560 } else {
1561 shost = lpfc_shost_from_vport(phba->pport);
1562 scsi_unblock_requests(shost);
1563 }
1564
1565 /*
1566 * Let SLI layer release mboxq if mbox command completed after timeout.
1567 */
1568 if (mbxstatus != MBX_TIMEOUT)
1569 mempool_free(pmboxq, phba->mbox_mem_pool);
1570
1571job_error:
1572 /* make error code available to userspace */
1573 job->reply->result = rc;
1574 /* complete the job back to userspace if no error */
1575 if (rc == 0)
1576 job->job_done(job);
1577 return rc;
1578}
1579
1580/**
1581 * lpfcdiag_loop_self_reg - obtains a remote port login id
1582 * @phba: Pointer to HBA context object
1583 * @rpi: Pointer to a remote port login id
1584 *
1585 * This function obtains a remote port login id so the diag loopback test
1586 * can send and receive its own unsolicited CT command.
1587 **/
1588static int lpfcdiag_loop_self_reg(struct lpfc_hba *phba, uint16_t * rpi)
1589{
1590 LPFC_MBOXQ_t *mbox;
1591 struct lpfc_dmabuf *dmabuff;
1592 int status;
1593
1594 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1595 if (!mbox)
1596 return ENOMEM;
1597
1598 status = lpfc_reg_rpi(phba, 0, phba->pport->fc_myDID,
1599 (uint8_t *)&phba->pport->fc_sparam, mbox, 0);
1600 if (status) {
1601 mempool_free(mbox, phba->mbox_mem_pool);
1602 return ENOMEM;
1603 }
1604
1605 dmabuff = (struct lpfc_dmabuf *) mbox->context1;
1606 mbox->context1 = NULL;
1607 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
1608
1609 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
1610 lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys);
1611 kfree(dmabuff);
1612 if (status != MBX_TIMEOUT)
1613 mempool_free(mbox, phba->mbox_mem_pool);
1614 return ENODEV;
1615 }
1616
1617 *rpi = mbox->u.mb.un.varWords[0];
1618
1619 lpfc_mbuf_free(phba, dmabuff->virt, dmabuff->phys);
1620 kfree(dmabuff);
1621 mempool_free(mbox, phba->mbox_mem_pool);
1622 return 0;
1623}
1624
1625/**
1626 * lpfcdiag_loop_self_unreg - unregs from the rpi
1627 * @phba: Pointer to HBA context object
1628 * @rpi: Remote port login id
1629 *
1630 * This function unregisters the rpi obtained in lpfcdiag_loop_self_reg
1631 **/
1632static int lpfcdiag_loop_self_unreg(struct lpfc_hba *phba, uint16_t rpi)
1633{
1634 LPFC_MBOXQ_t *mbox;
1635 int status;
1636
1637 /* Allocate mboxq structure */
1638 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1639 if (mbox == NULL)
1640 return ENOMEM;
1641
1642 lpfc_unreg_login(phba, 0, rpi, mbox);
1643 status = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
1644
1645 if ((status != MBX_SUCCESS) || (mbox->u.mb.mbxStatus)) {
1646 if (status != MBX_TIMEOUT)
1647 mempool_free(mbox, phba->mbox_mem_pool);
1648 return EIO;
1649 }
1650
1651 mempool_free(mbox, phba->mbox_mem_pool);
1652 return 0;
1653}
1654
1655/**
1656 * lpfcdiag_loop_get_xri - obtains the transmit and receive ids
1657 * @phba: Pointer to HBA context object
1658 * @rpi: Remote port login id
1659 * @txxri: Pointer to transmit exchange id
1660 * @rxxri: Pointer to response exchabge id
1661 *
1662 * This function obtains the transmit and receive ids required to send
1663 * an unsolicited ct command with a payload. A special lpfc FsType and CmdRsp
1664 * flags are used to the unsolicted response handler is able to process
1665 * the ct command sent on the same port.
1666 **/
1667static int lpfcdiag_loop_get_xri(struct lpfc_hba *phba, uint16_t rpi,
1668 uint16_t *txxri, uint16_t * rxxri)
1669{
1670 struct lpfc_bsg_event *evt;
1671 struct lpfc_iocbq *cmdiocbq, *rspiocbq;
1672 IOCB_t *cmd, *rsp;
1673 struct lpfc_dmabuf *dmabuf;
1674 struct ulp_bde64 *bpl = NULL;
1675 struct lpfc_sli_ct_request *ctreq = NULL;
1676 int ret_val = 0;
1677 unsigned long flags;
1678
1679 *txxri = 0;
1680 *rxxri = 0;
1681 evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
1682 SLI_CT_ELX_LOOPBACK);
1683 if (!evt)
1684 return ENOMEM;
1685
1686 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1687 list_add(&evt->node, &phba->ct_ev_waiters);
1688 lpfc_bsg_event_ref(evt);
1689 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1690
1691 cmdiocbq = lpfc_sli_get_iocbq(phba);
1692 rspiocbq = lpfc_sli_get_iocbq(phba);
1693
1694 dmabuf = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1695 if (dmabuf) {
1696 dmabuf->virt = lpfc_mbuf_alloc(phba, 0, &dmabuf->phys);
1697 INIT_LIST_HEAD(&dmabuf->list);
1698 bpl = (struct ulp_bde64 *) dmabuf->virt;
1699 memset(bpl, 0, sizeof(*bpl));
1700 ctreq = (struct lpfc_sli_ct_request *)(bpl + 1);
1701 bpl->addrHigh =
1702 le32_to_cpu(putPaddrHigh(dmabuf->phys + sizeof(*bpl)));
1703 bpl->addrLow =
1704 le32_to_cpu(putPaddrLow(dmabuf->phys + sizeof(*bpl)));
1705 bpl->tus.f.bdeFlags = 0;
1706 bpl->tus.f.bdeSize = ELX_LOOPBACK_HEADER_SZ;
1707 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1708 }
1709
1710 if (cmdiocbq == NULL || rspiocbq == NULL ||
1711 dmabuf == NULL || bpl == NULL || ctreq == NULL) {
1712 ret_val = ENOMEM;
1713 goto err_get_xri_exit;
1714 }
1715
1716 cmd = &cmdiocbq->iocb;
1717 rsp = &rspiocbq->iocb;
1718
1719 memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ);
1720
1721 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
1722 ctreq->RevisionId.bits.InId = 0;
1723 ctreq->FsType = SLI_CT_ELX_LOOPBACK;
1724 ctreq->FsSubType = 0;
1725 ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_XRI_SETUP;
1726 ctreq->CommandResponse.bits.Size = 0;
1727
1728
1729 cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(dmabuf->phys);
1730 cmd->un.xseq64.bdl.addrLow = putPaddrLow(dmabuf->phys);
1731 cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
1732 cmd->un.xseq64.bdl.bdeSize = sizeof(*bpl);
1733
1734 cmd->un.xseq64.w5.hcsw.Fctl = LA;
1735 cmd->un.xseq64.w5.hcsw.Dfctl = 0;
1736 cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
1737 cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
1738
1739 cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CR;
1740 cmd->ulpBdeCount = 1;
1741 cmd->ulpLe = 1;
1742 cmd->ulpClass = CLASS3;
1743 cmd->ulpContext = rpi;
1744
1745 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
1746 cmdiocbq->vport = phba->pport;
1747
1748 ret_val = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq,
1749 rspiocbq,
1750 (phba->fc_ratov * 2)
1751 + LPFC_DRVR_TIMEOUT);
1752 if (ret_val)
1753 goto err_get_xri_exit;
1754
1755 *txxri = rsp->ulpContext;
1756
1757 evt->waiting = 1;
1758 evt->wait_time_stamp = jiffies;
1759 ret_val = wait_event_interruptible_timeout(
1760 evt->wq, !list_empty(&evt->events_to_see),
1761 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ);
1762 if (list_empty(&evt->events_to_see))
1763 ret_val = (ret_val) ? EINTR : ETIMEDOUT;
1764 else {
1765 ret_val = IOCB_SUCCESS;
1766 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1767 list_move(evt->events_to_see.prev, &evt->events_to_get);
1768 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1769 *rxxri = (list_entry(evt->events_to_get.prev,
1770 typeof(struct event_data),
1771 node))->immed_dat;
1772 }
1773 evt->waiting = 0;
1774
1775err_get_xri_exit:
1776 spin_lock_irqsave(&phba->ct_ev_lock, flags);
1777 lpfc_bsg_event_unref(evt); /* release ref */
1778 lpfc_bsg_event_unref(evt); /* delete */
1779 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
1780
1781 if (dmabuf) {
1782 if (dmabuf->virt)
1783 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
1784 kfree(dmabuf);
1785 }
1786
1787 if (cmdiocbq && (ret_val != IOCB_TIMEDOUT))
1788 lpfc_sli_release_iocbq(phba, cmdiocbq);
1789 if (rspiocbq)
1790 lpfc_sli_release_iocbq(phba, rspiocbq);
1791 return ret_val;
1792}
1793
1794/**
1795 * diag_cmd_data_alloc - fills in a bde struct with dma buffers
1796 * @phba: Pointer to HBA context object
1797 * @bpl: Pointer to 64 bit bde structure
1798 * @size: Number of bytes to process
1799 * @nocopydata: Flag to copy user data into the allocated buffer
1800 *
1801 * This function allocates page size buffers and populates an lpfc_dmabufext.
1802 * If allowed the user data pointed to with indataptr is copied into the kernel
1803 * memory. The chained list of page size buffers is returned.
1804 **/
1805static struct lpfc_dmabufext *
1806diag_cmd_data_alloc(struct lpfc_hba *phba,
1807 struct ulp_bde64 *bpl, uint32_t size,
1808 int nocopydata)
1809{
1810 struct lpfc_dmabufext *mlist = NULL;
1811 struct lpfc_dmabufext *dmp;
1812 int cnt, offset = 0, i = 0;
1813 struct pci_dev *pcidev;
1814
1815 pcidev = phba->pcidev;
1816
1817 while (size) {
1818 /* We get chunks of 4K */
1819 if (size > BUF_SZ_4K)
1820 cnt = BUF_SZ_4K;
1821 else
1822 cnt = size;
1823
1824 /* allocate struct lpfc_dmabufext buffer header */
1825 dmp = kmalloc(sizeof(struct lpfc_dmabufext), GFP_KERNEL);
1826 if (!dmp)
1827 goto out;
1828
1829 INIT_LIST_HEAD(&dmp->dma.list);
1830
1831 /* Queue it to a linked list */
1832 if (mlist)
1833 list_add_tail(&dmp->dma.list, &mlist->dma.list);
1834 else
1835 mlist = dmp;
1836
1837 /* allocate buffer */
1838 dmp->dma.virt = dma_alloc_coherent(&pcidev->dev,
1839 cnt,
1840 &(dmp->dma.phys),
1841 GFP_KERNEL);
1842
1843 if (!dmp->dma.virt)
1844 goto out;
1845
1846 dmp->size = cnt;
1847
1848 if (nocopydata) {
1849 bpl->tus.f.bdeFlags = 0;
1850 pci_dma_sync_single_for_device(phba->pcidev,
1851 dmp->dma.phys, LPFC_BPL_SIZE, PCI_DMA_TODEVICE);
1852
1853 } else {
1854 memset((uint8_t *)dmp->dma.virt, 0, cnt);
1855 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
1856 }
1857
1858 /* build buffer ptr list for IOCB */
1859 bpl->addrLow = le32_to_cpu(putPaddrLow(dmp->dma.phys));
1860 bpl->addrHigh = le32_to_cpu(putPaddrHigh(dmp->dma.phys));
1861 bpl->tus.f.bdeSize = (ushort) cnt;
1862 bpl->tus.w = le32_to_cpu(bpl->tus.w);
1863 bpl++;
1864
1865 i++;
1866 offset += cnt;
1867 size -= cnt;
1868 }
1869
1870 mlist->flag = i;
1871 return mlist;
1872out:
1873 diag_cmd_data_free(phba, mlist);
1874 return NULL;
1875}
1876
1877/**
1878 * lpfcdiag_loop_post_rxbufs - post the receive buffers for an unsol CT cmd
1879 * @phba: Pointer to HBA context object
1880 * @rxxri: Receive exchange id
1881 * @len: Number of data bytes
1882 *
1883 * This function allocates and posts a data buffer of sufficient size to recieve
1884 * an unsolicted CT command.
1885 **/
1886static int lpfcdiag_loop_post_rxbufs(struct lpfc_hba *phba, uint16_t rxxri,
1887 size_t len)
1888{
1889 struct lpfc_sli *psli = &phba->sli;
1890 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1891 struct lpfc_iocbq *cmdiocbq;
1892 IOCB_t *cmd = NULL;
1893 struct list_head head, *curr, *next;
1894 struct lpfc_dmabuf *rxbmp;
1895 struct lpfc_dmabuf *dmp;
1896 struct lpfc_dmabuf *mp[2] = {NULL, NULL};
1897 struct ulp_bde64 *rxbpl = NULL;
1898 uint32_t num_bde;
1899 struct lpfc_dmabufext *rxbuffer = NULL;
1900 int ret_val = 0;
1901 int i = 0;
1902
1903 cmdiocbq = lpfc_sli_get_iocbq(phba);
1904 rxbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1905 if (rxbmp != NULL) {
1906 rxbmp->virt = lpfc_mbuf_alloc(phba, 0, &rxbmp->phys);
1907 INIT_LIST_HEAD(&rxbmp->list);
1908 rxbpl = (struct ulp_bde64 *) rxbmp->virt;
1909 rxbuffer = diag_cmd_data_alloc(phba, rxbpl, len, 0);
1910 }
1911
1912 if (!cmdiocbq || !rxbmp || !rxbpl || !rxbuffer) {
1913 ret_val = ENOMEM;
1914 goto err_post_rxbufs_exit;
1915 }
1916
1917 /* Queue buffers for the receive exchange */
1918 num_bde = (uint32_t)rxbuffer->flag;
1919 dmp = &rxbuffer->dma;
1920
1921 cmd = &cmdiocbq->iocb;
1922 i = 0;
1923
1924 INIT_LIST_HEAD(&head);
1925 list_add_tail(&head, &dmp->list);
1926 list_for_each_safe(curr, next, &head) {
1927 mp[i] = list_entry(curr, struct lpfc_dmabuf, list);
1928 list_del(curr);
1929
1930 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
1931 mp[i]->buffer_tag = lpfc_sli_get_buffer_tag(phba);
1932 cmd->un.quexri64cx.buff.bde.addrHigh =
1933 putPaddrHigh(mp[i]->phys);
1934 cmd->un.quexri64cx.buff.bde.addrLow =
1935 putPaddrLow(mp[i]->phys);
1936 cmd->un.quexri64cx.buff.bde.tus.f.bdeSize =
1937 ((struct lpfc_dmabufext *)mp[i])->size;
1938 cmd->un.quexri64cx.buff.buffer_tag = mp[i]->buffer_tag;
1939 cmd->ulpCommand = CMD_QUE_XRI64_CX;
1940 cmd->ulpPU = 0;
1941 cmd->ulpLe = 1;
1942 cmd->ulpBdeCount = 1;
1943 cmd->unsli3.que_xri64cx_ext_words.ebde_count = 0;
1944
1945 } else {
1946 cmd->un.cont64[i].addrHigh = putPaddrHigh(mp[i]->phys);
1947 cmd->un.cont64[i].addrLow = putPaddrLow(mp[i]->phys);
1948 cmd->un.cont64[i].tus.f.bdeSize =
1949 ((struct lpfc_dmabufext *)mp[i])->size;
1950 cmd->ulpBdeCount = ++i;
1951
1952 if ((--num_bde > 0) && (i < 2))
1953 continue;
1954
1955 cmd->ulpCommand = CMD_QUE_XRI_BUF64_CX;
1956 cmd->ulpLe = 1;
1957 }
1958
1959 cmd->ulpClass = CLASS3;
1960 cmd->ulpContext = rxxri;
1961
1962 ret_val = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, cmdiocbq, 0);
1963
1964 if (ret_val == IOCB_ERROR) {
1965 diag_cmd_data_free(phba,
1966 (struct lpfc_dmabufext *)mp[0]);
1967 if (mp[1])
1968 diag_cmd_data_free(phba,
1969 (struct lpfc_dmabufext *)mp[1]);
1970 dmp = list_entry(next, struct lpfc_dmabuf, list);
1971 ret_val = EIO;
1972 goto err_post_rxbufs_exit;
1973 }
1974
1975 lpfc_sli_ringpostbuf_put(phba, pring, mp[0]);
1976 if (mp[1]) {
1977 lpfc_sli_ringpostbuf_put(phba, pring, mp[1]);
1978 mp[1] = NULL;
1979 }
1980
1981 /* The iocb was freed by lpfc_sli_issue_iocb */
1982 cmdiocbq = lpfc_sli_get_iocbq(phba);
1983 if (!cmdiocbq) {
1984 dmp = list_entry(next, struct lpfc_dmabuf, list);
1985 ret_val = EIO;
1986 goto err_post_rxbufs_exit;
1987 }
1988
1989 cmd = &cmdiocbq->iocb;
1990 i = 0;
1991 }
1992 list_del(&head);
1993
1994err_post_rxbufs_exit:
1995
1996 if (rxbmp) {
1997 if (rxbmp->virt)
1998 lpfc_mbuf_free(phba, rxbmp->virt, rxbmp->phys);
1999 kfree(rxbmp);
2000 }
2001
2002 if (cmdiocbq)
2003 lpfc_sli_release_iocbq(phba, cmdiocbq);
2004 return ret_val;
2005}
2006
2007/**
2008 * lpfc_bsg_diag_test - with a port in loopback issues a Ct cmd to itself
2009 * @job: LPFC_BSG_VENDOR_DIAG_TEST fc_bsg_job
2010 *
2011 * This function receives a user data buffer to be transmitted and received on
2012 * the same port, the link must be up and in loopback mode prior
2013 * to being called.
2014 * 1. A kernel buffer is allocated to copy the user data into.
2015 * 2. The port registers with "itself".
2016 * 3. The transmit and receive exchange ids are obtained.
2017 * 4. The receive exchange id is posted.
2018 * 5. A new els loopback event is created.
2019 * 6. The command and response iocbs are allocated.
2020 * 7. The cmd iocb FsType is set to elx loopback and the CmdRsp to looppback.
2021 *
2022 * This function is meant to be called n times while the port is in loopback
2023 * so it is the apps responsibility to issue a reset to take the port out
2024 * of loopback mode.
2025 **/
2026static int
2027lpfc_bsg_diag_test(struct fc_bsg_job *job)
2028{
2029 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
2030 struct lpfc_hba *phba = vport->phba;
2031 struct diag_mode_test *diag_mode;
2032 struct lpfc_bsg_event *evt;
2033 struct event_data *evdat;
2034 struct lpfc_sli *psli = &phba->sli;
2035 uint32_t size;
2036 uint32_t full_size;
2037 size_t segment_len = 0, segment_offset = 0, current_offset = 0;
2038 uint16_t rpi;
2039 struct lpfc_iocbq *cmdiocbq, *rspiocbq;
2040 IOCB_t *cmd, *rsp;
2041 struct lpfc_sli_ct_request *ctreq;
2042 struct lpfc_dmabuf *txbmp;
2043 struct ulp_bde64 *txbpl = NULL;
2044 struct lpfc_dmabufext *txbuffer = NULL;
2045 struct list_head head;
2046 struct lpfc_dmabuf *curr;
2047 uint16_t txxri, rxxri;
2048 uint32_t num_bde;
2049 uint8_t *ptr = NULL, *rx_databuf = NULL;
2050 int rc = 0;
2051 unsigned long flags;
2052 void *dataout = NULL;
2053 uint32_t total_mem;
2054
2055 /* in case no data is returned return just the return code */
2056 job->reply->reply_payload_rcv_len = 0;
2057
2058 if (job->request_len <
2059 sizeof(struct fc_bsg_request) + sizeof(struct diag_mode_test)) {
2060 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2061 "2739 Received DIAG TEST request below minimum "
2062 "size\n");
2063 rc = -EINVAL;
2064 goto loopback_test_exit;
2065 }
2066
2067 if (job->request_payload.payload_len !=
2068 job->reply_payload.payload_len) {
2069 rc = -EINVAL;
2070 goto loopback_test_exit;
2071 }
2072
2073 diag_mode = (struct diag_mode_test *)
2074 job->request->rqst_data.h_vendor.vendor_cmd;
2075
2076 if ((phba->link_state == LPFC_HBA_ERROR) ||
2077 (psli->sli_flag & LPFC_BLOCK_MGMT_IO) ||
2078 (!(psli->sli_flag & LPFC_SLI_ACTIVE))) {
2079 rc = -EACCES;
2080 goto loopback_test_exit;
2081 }
2082
2083 if (!lpfc_is_link_up(phba) || !(phba->link_flag & LS_LOOPBACK_MODE)) {
2084 rc = -EACCES;
2085 goto loopback_test_exit;
2086 }
2087
2088 size = job->request_payload.payload_len;
2089 full_size = size + ELX_LOOPBACK_HEADER_SZ; /* plus the header */
2090
2091 if ((size == 0) || (size > 80 * BUF_SZ_4K)) {
2092 rc = -ERANGE;
2093 goto loopback_test_exit;
2094 }
2095
2096 if (size >= BUF_SZ_4K) {
2097 /*
2098 * Allocate memory for ioctl data. If buffer is bigger than 64k,
2099 * then we allocate 64k and re-use that buffer over and over to
2100 * xfer the whole block. This is because Linux kernel has a
2101 * problem allocating more than 120k of kernel space memory. Saw
2102 * problem with GET_FCPTARGETMAPPING...
2103 */
2104 if (size <= (64 * 1024))
2105 total_mem = size;
2106 else
2107 total_mem = 64 * 1024;
2108 } else
2109 /* Allocate memory for ioctl data */
2110 total_mem = BUF_SZ_4K;
2111
2112 dataout = kmalloc(total_mem, GFP_KERNEL);
2113 if (dataout == NULL) {
2114 rc = -ENOMEM;
2115 goto loopback_test_exit;
2116 }
2117
2118 ptr = dataout;
2119 ptr += ELX_LOOPBACK_HEADER_SZ;
2120 sg_copy_to_buffer(job->request_payload.sg_list,
2121 job->request_payload.sg_cnt,
2122 ptr, size);
2123
2124 rc = lpfcdiag_loop_self_reg(phba, &rpi);
2125 if (rc) {
2126 rc = -ENOMEM;
2127 goto loopback_test_exit;
2128 }
2129
2130 rc = lpfcdiag_loop_get_xri(phba, rpi, &txxri, &rxxri);
2131 if (rc) {
2132 lpfcdiag_loop_self_unreg(phba, rpi);
2133 rc = -ENOMEM;
2134 goto loopback_test_exit;
2135 }
2136
2137 rc = lpfcdiag_loop_post_rxbufs(phba, rxxri, full_size);
2138 if (rc) {
2139 lpfcdiag_loop_self_unreg(phba, rpi);
2140 rc = -ENOMEM;
2141 goto loopback_test_exit;
2142 }
2143
2144 evt = lpfc_bsg_event_new(FC_REG_CT_EVENT, current->pid,
2145 SLI_CT_ELX_LOOPBACK);
2146 if (!evt) {
2147 lpfcdiag_loop_self_unreg(phba, rpi);
2148 rc = -ENOMEM;
2149 goto loopback_test_exit;
2150 }
2151
2152 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2153 list_add(&evt->node, &phba->ct_ev_waiters);
2154 lpfc_bsg_event_ref(evt);
2155 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2156
2157 cmdiocbq = lpfc_sli_get_iocbq(phba);
2158 rspiocbq = lpfc_sli_get_iocbq(phba);
2159 txbmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2160
2161 if (txbmp) {
2162 txbmp->virt = lpfc_mbuf_alloc(phba, 0, &txbmp->phys);
2163 INIT_LIST_HEAD(&txbmp->list);
2164 txbpl = (struct ulp_bde64 *) txbmp->virt;
2165 if (txbpl)
2166 txbuffer = diag_cmd_data_alloc(phba,
2167 txbpl, full_size, 0);
2168 }
2169
2170 if (!cmdiocbq || !rspiocbq || !txbmp || !txbpl || !txbuffer) {
2171 rc = -ENOMEM;
2172 goto err_loopback_test_exit;
2173 }
2174
2175 cmd = &cmdiocbq->iocb;
2176 rsp = &rspiocbq->iocb;
2177
2178 INIT_LIST_HEAD(&head);
2179 list_add_tail(&head, &txbuffer->dma.list);
2180 list_for_each_entry(curr, &head, list) {
2181 segment_len = ((struct lpfc_dmabufext *)curr)->size;
2182 if (current_offset == 0) {
2183 ctreq = curr->virt;
2184 memset(ctreq, 0, ELX_LOOPBACK_HEADER_SZ);
2185 ctreq->RevisionId.bits.Revision = SLI_CT_REVISION;
2186 ctreq->RevisionId.bits.InId = 0;
2187 ctreq->FsType = SLI_CT_ELX_LOOPBACK;
2188 ctreq->FsSubType = 0;
2189 ctreq->CommandResponse.bits.CmdRsp = ELX_LOOPBACK_DATA;
2190 ctreq->CommandResponse.bits.Size = size;
2191 segment_offset = ELX_LOOPBACK_HEADER_SZ;
2192 } else
2193 segment_offset = 0;
2194
2195 BUG_ON(segment_offset >= segment_len);
2196 memcpy(curr->virt + segment_offset,
2197 ptr + current_offset,
2198 segment_len - segment_offset);
2199
2200 current_offset += segment_len - segment_offset;
2201 BUG_ON(current_offset > size);
2202 }
2203 list_del(&head);
2204
2205 /* Build the XMIT_SEQUENCE iocb */
2206
2207 num_bde = (uint32_t)txbuffer->flag;
2208
2209 cmd->un.xseq64.bdl.addrHigh = putPaddrHigh(txbmp->phys);
2210 cmd->un.xseq64.bdl.addrLow = putPaddrLow(txbmp->phys);
2211 cmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
2212 cmd->un.xseq64.bdl.bdeSize = (num_bde * sizeof(struct ulp_bde64));
2213
2214 cmd->un.xseq64.w5.hcsw.Fctl = (LS | LA);
2215 cmd->un.xseq64.w5.hcsw.Dfctl = 0;
2216 cmd->un.xseq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
2217 cmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
2218
2219 cmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
2220 cmd->ulpBdeCount = 1;
2221 cmd->ulpLe = 1;
2222 cmd->ulpClass = CLASS3;
2223 cmd->ulpContext = txxri;
2224
2225 cmdiocbq->iocb_flag |= LPFC_IO_LIBDFC;
2226 cmdiocbq->vport = phba->pport;
2227
2228 rc = lpfc_sli_issue_iocb_wait(phba, LPFC_ELS_RING, cmdiocbq, rspiocbq,
2229 (phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT);
2230
2231 if ((rc != IOCB_SUCCESS) || (rsp->ulpStatus != IOCB_SUCCESS)) {
2232 rc = -EIO;
2233 goto err_loopback_test_exit;
2234 }
2235
2236 evt->waiting = 1;
2237 rc = wait_event_interruptible_timeout(
2238 evt->wq, !list_empty(&evt->events_to_see),
2239 ((phba->fc_ratov * 2) + LPFC_DRVR_TIMEOUT) * HZ);
2240 evt->waiting = 0;
2241 if (list_empty(&evt->events_to_see))
2242 rc = (rc) ? -EINTR : -ETIMEDOUT;
2243 else {
2244 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2245 list_move(evt->events_to_see.prev, &evt->events_to_get);
2246 evdat = list_entry(evt->events_to_get.prev,
2247 typeof(*evdat), node);
2248 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2249 rx_databuf = evdat->data;
2250 if (evdat->len != full_size) {
2251 lpfc_printf_log(phba, KERN_ERR, LOG_LIBDFC,
2252 "1603 Loopback test did not receive expected "
2253 "data length. actual length 0x%x expected "
2254 "length 0x%x\n",
2255 evdat->len, full_size);
2256 rc = -EIO;
2257 } else if (rx_databuf == NULL)
2258 rc = -EIO;
2259 else {
2260 rc = IOCB_SUCCESS;
2261 /* skip over elx loopback header */
2262 rx_databuf += ELX_LOOPBACK_HEADER_SZ;
2263 job->reply->reply_payload_rcv_len =
2264 sg_copy_from_buffer(job->reply_payload.sg_list,
2265 job->reply_payload.sg_cnt,
2266 rx_databuf, size);
2267 job->reply->reply_payload_rcv_len = size;
2268 }
2269 }
2270
2271err_loopback_test_exit:
2272 lpfcdiag_loop_self_unreg(phba, rpi);
2273
2274 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2275 lpfc_bsg_event_unref(evt); /* release ref */
2276 lpfc_bsg_event_unref(evt); /* delete */
2277 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2278
2279 if (cmdiocbq != NULL)
2280 lpfc_sli_release_iocbq(phba, cmdiocbq);
2281
2282 if (rspiocbq != NULL)
2283 lpfc_sli_release_iocbq(phba, rspiocbq);
2284
2285 if (txbmp != NULL) {
2286 if (txbpl != NULL) {
2287 if (txbuffer != NULL)
2288 diag_cmd_data_free(phba, txbuffer);
2289 lpfc_mbuf_free(phba, txbmp->virt, txbmp->phys);
2290 }
2291 kfree(txbmp);
2292 }
2293
2294loopback_test_exit:
2295 kfree(dataout);
2296 /* make error code available to userspace */
2297 job->reply->result = rc;
2298 job->dd_data = NULL;
2299 /* complete the job back to userspace if no error */
2300 if (rc == 0)
2301 job->job_done(job);
2302 return rc;
2303}
2304
2305/**
2306 * lpfc_bsg_get_dfc_rev - process a GET_DFC_REV bsg vendor command
2307 * @job: GET_DFC_REV fc_bsg_job
2308 **/
2309static int
2310lpfc_bsg_get_dfc_rev(struct fc_bsg_job *job)
2311{
2312 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
2313 struct lpfc_hba *phba = vport->phba;
2314 struct get_mgmt_rev *event_req;
2315 struct get_mgmt_rev_reply *event_reply;
2316 int rc = 0;
2317
2318 if (job->request_len <
2319 sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev)) {
2320 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2321 "2740 Received GET_DFC_REV request below "
2322 "minimum size\n");
2323 rc = -EINVAL;
2324 goto job_error;
2325 }
2326
2327 event_req = (struct get_mgmt_rev *)
2328 job->request->rqst_data.h_vendor.vendor_cmd;
2329
2330 event_reply = (struct get_mgmt_rev_reply *)
2331 job->reply->reply_data.vendor_reply.vendor_rsp;
2332
2333 if (job->reply_len <
2334 sizeof(struct fc_bsg_request) + sizeof(struct get_mgmt_rev_reply)) {
2335 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2336 "2741 Received GET_DFC_REV reply below "
2337 "minimum size\n");
2338 rc = -EINVAL;
2339 goto job_error;
2340 }
2341
2342 event_reply->info.a_Major = MANAGEMENT_MAJOR_REV;
2343 event_reply->info.a_Minor = MANAGEMENT_MINOR_REV;
2344job_error:
2345 job->reply->result = rc;
2346 if (rc == 0)
2347 job->job_done(job);
2348 return rc;
2349}
2350
2351/**
2352 * lpfc_bsg_wake_mbox_wait - lpfc_bsg_issue_mbox mbox completion handler
2353 * @phba: Pointer to HBA context object.
2354 * @pmboxq: Pointer to mailbox command.
2355 *
2356 * This is completion handler function for mailbox commands issued from
2357 * lpfc_bsg_issue_mbox function. This function is called by the
2358 * mailbox event handler function with no lock held. This function
2359 * will wake up thread waiting on the wait queue pointed by context1
2360 * of the mailbox.
2361 **/
2362void
2363lpfc_bsg_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
2364{
2365 struct bsg_job_data *dd_data;
2366 MAILBOX_t *pmb;
2367 MAILBOX_t *mb;
2368 struct fc_bsg_job *job;
2369 uint32_t size;
2370 unsigned long flags;
2371
2372 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2373 dd_data = pmboxq->context1;
2374 if (!dd_data) {
2375 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2376 return;
2377 }
2378
2379 pmb = &dd_data->context_un.mbox.pmboxq->u.mb;
2380 mb = dd_data->context_un.mbox.mb;
2381 job = dd_data->context_un.mbox.set_job;
2382 memcpy(mb, pmb, sizeof(*pmb));
2383 size = job->request_payload.payload_len;
2384 job->reply->reply_payload_rcv_len =
2385 sg_copy_from_buffer(job->reply_payload.sg_list,
2386 job->reply_payload.sg_cnt,
2387 mb, size);
2388 job->reply->result = 0;
2389 dd_data->context_un.mbox.set_job = NULL;
2390 job->dd_data = NULL;
2391 job->job_done(job);
2392 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2393 mempool_free(dd_data->context_un.mbox.pmboxq, phba->mbox_mem_pool);
2394 kfree(mb);
2395 kfree(dd_data);
2396 return;
2397}
2398
2399/**
2400 * lpfc_bsg_check_cmd_access - test for a supported mailbox command
2401 * @phba: Pointer to HBA context object.
2402 * @mb: Pointer to a mailbox object.
2403 * @vport: Pointer to a vport object.
2404 *
2405 * Some commands require the port to be offline, some may not be called from
2406 * the application.
2407 **/
2408static int lpfc_bsg_check_cmd_access(struct lpfc_hba *phba,
2409 MAILBOX_t *mb, struct lpfc_vport *vport)
2410{
2411 /* return negative error values for bsg job */
2412 switch (mb->mbxCommand) {
2413 /* Offline only */
2414 case MBX_INIT_LINK:
2415 case MBX_DOWN_LINK:
2416 case MBX_CONFIG_LINK:
2417 case MBX_CONFIG_RING:
2418 case MBX_RESET_RING:
2419 case MBX_UNREG_LOGIN:
2420 case MBX_CLEAR_LA:
2421 case MBX_DUMP_CONTEXT:
2422 case MBX_RUN_DIAGS:
2423 case MBX_RESTART:
2424 case MBX_SET_MASK:
2425 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
2426 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2427 "2743 Command 0x%x is illegal in on-line "
2428 "state\n",
2429 mb->mbxCommand);
2430 return -EPERM;
2431 }
2432 case MBX_WRITE_NV:
2433 case MBX_WRITE_VPARMS:
2434 case MBX_LOAD_SM:
2435 case MBX_READ_NV:
2436 case MBX_READ_CONFIG:
2437 case MBX_READ_RCONFIG:
2438 case MBX_READ_STATUS:
2439 case MBX_READ_XRI:
2440 case MBX_READ_REV:
2441 case MBX_READ_LNK_STAT:
2442 case MBX_DUMP_MEMORY:
2443 case MBX_DOWN_LOAD:
2444 case MBX_UPDATE_CFG:
2445 case MBX_KILL_BOARD:
2446 case MBX_LOAD_AREA:
2447 case MBX_LOAD_EXP_ROM:
2448 case MBX_BEACON:
2449 case MBX_DEL_LD_ENTRY:
2450 case MBX_SET_DEBUG:
2451 case MBX_WRITE_WWN:
2452 case MBX_SLI4_CONFIG:
2453 case MBX_READ_EVENT_LOG_STATUS:
2454 case MBX_WRITE_EVENT_LOG:
2455 case MBX_PORT_CAPABILITIES:
2456 case MBX_PORT_IOV_CONTROL:
2457 break;
2458 case MBX_SET_VARIABLE:
2459 case MBX_RUN_BIU_DIAG64:
2460 case MBX_READ_EVENT_LOG:
2461 case MBX_READ_SPARM64:
2462 case MBX_READ_LA:
2463 case MBX_READ_LA64:
2464 case MBX_REG_LOGIN:
2465 case MBX_REG_LOGIN64:
2466 case MBX_CONFIG_PORT:
2467 case MBX_RUN_BIU_DIAG:
2468 default:
2469 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2470 "2742 Unknown Command 0x%x\n",
2471 mb->mbxCommand);
2472 return -EPERM;
2473 }
2474
2475 return 0; /* ok */
2476}
2477
2478/**
2479 * lpfc_bsg_issue_mbox - issues a mailbox command on behalf of an app
2480 * @phba: Pointer to HBA context object.
2481 * @mb: Pointer to a mailbox object.
2482 * @vport: Pointer to a vport object.
2483 *
2484 * Allocate a tracking object, mailbox command memory, get a mailbox
2485 * from the mailbox pool, copy the caller mailbox command.
2486 *
2487 * If offline and the sli is active we need to poll for the command (port is
2488 * being reset) and com-plete the job, otherwise issue the mailbox command and
2489 * let our completion handler finish the command.
2490 **/
2491static uint32_t
2492lpfc_bsg_issue_mbox(struct lpfc_hba *phba, struct fc_bsg_job *job,
2493 struct lpfc_vport *vport)
2494{
2495 LPFC_MBOXQ_t *pmboxq;
2496 MAILBOX_t *pmb;
2497 MAILBOX_t *mb;
2498 struct bsg_job_data *dd_data;
2499 uint32_t size;
2500 int rc = 0;
2501
2502 /* allocate our bsg tracking structure */
2503 dd_data = kmalloc(sizeof(struct bsg_job_data), GFP_KERNEL);
2504 if (!dd_data) {
2505 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2506 "2727 Failed allocation of dd_data\n");
2507 return -ENOMEM;
2508 }
2509
2510 mb = kzalloc(PAGE_SIZE, GFP_KERNEL);
2511 if (!mb) {
2512 kfree(dd_data);
2513 return -ENOMEM;
2514 }
2515
2516 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2517 if (!pmboxq) {
2518 kfree(dd_data);
2519 kfree(mb);
2520 return -ENOMEM;
2521 }
2522
2523 size = job->request_payload.payload_len;
2524 job->reply->reply_payload_rcv_len =
2525 sg_copy_to_buffer(job->request_payload.sg_list,
2526 job->request_payload.sg_cnt,
2527 mb, size);
2528
2529 rc = lpfc_bsg_check_cmd_access(phba, mb, vport);
2530 if (rc != 0) {
2531 kfree(dd_data);
2532 kfree(mb);
2533 mempool_free(pmboxq, phba->mbox_mem_pool);
2534 return rc; /* must be negative */
2535 }
2536
2537 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2538 pmb = &pmboxq->u.mb;
2539 memcpy(pmb, mb, sizeof(*pmb));
2540 pmb->mbxOwner = OWN_HOST;
2541 pmboxq->context1 = NULL;
2542 pmboxq->vport = vport;
2543
2544 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2545 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
2546 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2547 if (rc != MBX_SUCCESS) {
2548 if (rc != MBX_TIMEOUT) {
2549 kfree(dd_data);
2550 kfree(mb);
2551 mempool_free(pmboxq, phba->mbox_mem_pool);
2552 }
2553 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
2554 }
2555
2556 memcpy(mb, pmb, sizeof(*pmb));
2557 job->reply->reply_payload_rcv_len =
2558 sg_copy_from_buffer(job->reply_payload.sg_list,
2559 job->reply_payload.sg_cnt,
2560 mb, size);
2561 kfree(dd_data);
2562 kfree(mb);
2563 mempool_free(pmboxq, phba->mbox_mem_pool);
2564 /* not waiting mbox already done */
2565 return 0;
2566 }
2567
2568 /* setup wake call as IOCB callback */
2569 pmboxq->mbox_cmpl = lpfc_bsg_wake_mbox_wait;
2570 /* setup context field to pass wait_queue pointer to wake function */
2571 pmboxq->context1 = dd_data;
2572 dd_data->type = TYPE_MBOX;
2573 dd_data->context_un.mbox.pmboxq = pmboxq;
2574 dd_data->context_un.mbox.mb = mb;
2575 dd_data->context_un.mbox.set_job = job;
2576 job->dd_data = dd_data;
2577 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
2578 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
2579 kfree(dd_data);
2580 kfree(mb);
2581 mempool_free(pmboxq, phba->mbox_mem_pool);
2582 return -EIO;
2583 }
2584
2585 return 1;
2586}
2587
2588/**
2589 * lpfc_bsg_mbox_cmd - process an fc bsg LPFC_BSG_VENDOR_MBOX command
2590 * @job: MBOX fc_bsg_job for LPFC_BSG_VENDOR_MBOX.
2591 **/
2592static int
2593lpfc_bsg_mbox_cmd(struct fc_bsg_job *job)
2594{
2595 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
2596 struct lpfc_hba *phba = vport->phba;
2597 int rc = 0;
2598
2599 /* in case no data is transferred */
2600 job->reply->reply_payload_rcv_len = 0;
2601 if (job->request_len <
2602 sizeof(struct fc_bsg_request) + sizeof(struct dfc_mbox_req)) {
2603 lpfc_printf_log(phba, KERN_WARNING, LOG_LIBDFC,
2604 "2737 Received MBOX_REQ request below "
2605 "minimum size\n");
2606 rc = -EINVAL;
2607 goto job_error;
2608 }
2609
2610 if (job->request_payload.payload_len != PAGE_SIZE) {
2611 rc = -EINVAL;
2612 goto job_error;
2613 }
2614
2615 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
2616 rc = -EAGAIN;
2617 goto job_error;
2618 }
2619
2620 rc = lpfc_bsg_issue_mbox(phba, job, vport);
2621
2622job_error:
2623 if (rc == 0) {
2624 /* job done */
2625 job->reply->result = 0;
2626 job->dd_data = NULL;
2627 job->job_done(job);
2628 } else if (rc == 1)
2629 /* job submitted, will complete later*/
2630 rc = 0; /* return zero, no error */
2631 else {
2632 /* some error occurred */
2633 job->reply->result = rc;
2634 job->dd_data = NULL;
2635 }
830 2636
831 return rc; 2637 return rc;
832} 2638}
@@ -834,38 +2640,57 @@ error_get_event_exit:
834/** 2640/**
835 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job 2641 * lpfc_bsg_hst_vendor - process a vendor-specific fc_bsg_job
836 * @job: fc_bsg_job to handle 2642 * @job: fc_bsg_job to handle
837 */ 2643 **/
838static int 2644static int
839lpfc_bsg_hst_vendor(struct fc_bsg_job *job) 2645lpfc_bsg_hst_vendor(struct fc_bsg_job *job)
840{ 2646{
841 int command = job->request->rqst_data.h_vendor.vendor_cmd[0]; 2647 int command = job->request->rqst_data.h_vendor.vendor_cmd[0];
2648 int rc;
842 2649
843 switch (command) { 2650 switch (command) {
844 case LPFC_BSG_VENDOR_SET_CT_EVENT: 2651 case LPFC_BSG_VENDOR_SET_CT_EVENT:
845 return lpfc_bsg_set_event(job); 2652 rc = lpfc_bsg_hba_set_event(job);
846 break; 2653 break;
847
848 case LPFC_BSG_VENDOR_GET_CT_EVENT: 2654 case LPFC_BSG_VENDOR_GET_CT_EVENT:
849 return lpfc_bsg_get_event(job); 2655 rc = lpfc_bsg_hba_get_event(job);
2656 break;
2657 case LPFC_BSG_VENDOR_SEND_MGMT_RESP:
2658 rc = lpfc_bsg_send_mgmt_rsp(job);
2659 break;
2660 case LPFC_BSG_VENDOR_DIAG_MODE:
2661 rc = lpfc_bsg_diag_mode(job);
2662 break;
2663 case LPFC_BSG_VENDOR_DIAG_TEST:
2664 rc = lpfc_bsg_diag_test(job);
2665 break;
2666 case LPFC_BSG_VENDOR_GET_MGMT_REV:
2667 rc = lpfc_bsg_get_dfc_rev(job);
2668 break;
2669 case LPFC_BSG_VENDOR_MBOX:
2670 rc = lpfc_bsg_mbox_cmd(job);
850 break; 2671 break;
851
852 default: 2672 default:
853 return -EINVAL; 2673 rc = -EINVAL;
2674 job->reply->reply_payload_rcv_len = 0;
2675 /* make error code available to userspace */
2676 job->reply->result = rc;
2677 break;
854 } 2678 }
2679
2680 return rc;
855} 2681}
856 2682
857/** 2683/**
858 * lpfc_bsg_request - handle a bsg request from the FC transport 2684 * lpfc_bsg_request - handle a bsg request from the FC transport
859 * @job: fc_bsg_job to handle 2685 * @job: fc_bsg_job to handle
860 */ 2686 **/
861int 2687int
862lpfc_bsg_request(struct fc_bsg_job *job) 2688lpfc_bsg_request(struct fc_bsg_job *job)
863{ 2689{
864 uint32_t msgcode; 2690 uint32_t msgcode;
865 int rc = -EINVAL; 2691 int rc;
866 2692
867 msgcode = job->request->msgcode; 2693 msgcode = job->request->msgcode;
868
869 switch (msgcode) { 2694 switch (msgcode) {
870 case FC_BSG_HST_VENDOR: 2695 case FC_BSG_HST_VENDOR:
871 rc = lpfc_bsg_hst_vendor(job); 2696 rc = lpfc_bsg_hst_vendor(job);
@@ -874,9 +2699,13 @@ lpfc_bsg_request(struct fc_bsg_job *job)
874 rc = lpfc_bsg_rport_els(job); 2699 rc = lpfc_bsg_rport_els(job);
875 break; 2700 break;
876 case FC_BSG_RPT_CT: 2701 case FC_BSG_RPT_CT:
877 rc = lpfc_bsg_rport_ct(job); 2702 rc = lpfc_bsg_send_mgmt_cmd(job);
878 break; 2703 break;
879 default: 2704 default:
2705 rc = -EINVAL;
2706 job->reply->reply_payload_rcv_len = 0;
2707 /* make error code available to userspace */
2708 job->reply->result = rc;
880 break; 2709 break;
881 } 2710 }
882 2711
@@ -889,17 +2718,71 @@ lpfc_bsg_request(struct fc_bsg_job *job)
889 * 2718 *
890 * This function just aborts the job's IOCB. The aborted IOCB will return to 2719 * This function just aborts the job's IOCB. The aborted IOCB will return to
891 * the waiting function which will handle passing the error back to userspace 2720 * the waiting function which will handle passing the error back to userspace
892 */ 2721 **/
893int 2722int
894lpfc_bsg_timeout(struct fc_bsg_job *job) 2723lpfc_bsg_timeout(struct fc_bsg_job *job)
895{ 2724{
896 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata; 2725 struct lpfc_vport *vport = (struct lpfc_vport *)job->shost->hostdata;
897 struct lpfc_hba *phba = vport->phba; 2726 struct lpfc_hba *phba = vport->phba;
898 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *)job->dd_data; 2727 struct lpfc_iocbq *cmdiocb;
2728 struct lpfc_bsg_event *evt;
2729 struct lpfc_bsg_iocb *iocb;
2730 struct lpfc_bsg_mbox *mbox;
899 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; 2731 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
2732 struct bsg_job_data *dd_data;
2733 unsigned long flags;
2734
2735 spin_lock_irqsave(&phba->ct_ev_lock, flags);
2736 dd_data = (struct bsg_job_data *)job->dd_data;
2737 /* timeout and completion crossed paths if no dd_data */
2738 if (!dd_data) {
2739 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2740 return 0;
2741 }
900 2742
901 if (cmdiocb) 2743 switch (dd_data->type) {
2744 case TYPE_IOCB:
2745 iocb = &dd_data->context_un.iocb;
2746 cmdiocb = iocb->cmdiocbq;
2747 /* hint to completion handler that the job timed out */
2748 job->reply->result = -EAGAIN;
2749 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2750 /* this will call our completion handler */
2751 spin_lock_irq(&phba->hbalock);
902 lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb); 2752 lpfc_sli_issue_abort_iotag(phba, pring, cmdiocb);
2753 spin_unlock_irq(&phba->hbalock);
2754 break;
2755 case TYPE_EVT:
2756 evt = dd_data->context_un.evt;
2757 /* this event has no job anymore */
2758 evt->set_job = NULL;
2759 job->dd_data = NULL;
2760 job->reply->reply_payload_rcv_len = 0;
2761 /* Return -EAGAIN which is our way of signallying the
2762 * app to retry.
2763 */
2764 job->reply->result = -EAGAIN;
2765 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2766 job->job_done(job);
2767 break;
2768 case TYPE_MBOX:
2769 mbox = &dd_data->context_un.mbox;
2770 /* this mbox has no job anymore */
2771 mbox->set_job = NULL;
2772 job->dd_data = NULL;
2773 job->reply->reply_payload_rcv_len = 0;
2774 job->reply->result = -EAGAIN;
2775 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2776 job->job_done(job);
2777 break;
2778 default:
2779 spin_unlock_irqrestore(&phba->ct_ev_lock, flags);
2780 break;
2781 }
903 2782
2783 /* scsi transport fc fc_bsg_job_timeout expects a zero return code,
2784 * otherwise an error message will be displayed on the console
2785 * so always return success (zero)
2786 */
904 return 0; 2787 return 0;
905} 2788}
diff --git a/drivers/scsi/lpfc/lpfc_bsg.h b/drivers/scsi/lpfc/lpfc_bsg.h
new file mode 100644
index 000000000000..6c8f87e39b98
--- /dev/null
+++ b/drivers/scsi/lpfc/lpfc_bsg.h
@@ -0,0 +1,98 @@
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
20/* bsg definitions
21 * No pointers to user data are allowed, all application buffers and sizes will
22 * derived through the bsg interface.
23 *
24 * These are the vendor unique structures passed in using the bsg
25 * FC_BSG_HST_VENDOR message code type.
26 */
27#define LPFC_BSG_VENDOR_SET_CT_EVENT 1
28#define LPFC_BSG_VENDOR_GET_CT_EVENT 2
29#define LPFC_BSG_VENDOR_SEND_MGMT_RESP 3
30#define LPFC_BSG_VENDOR_DIAG_MODE 4
31#define LPFC_BSG_VENDOR_DIAG_TEST 5
32#define LPFC_BSG_VENDOR_GET_MGMT_REV 6
33#define LPFC_BSG_VENDOR_MBOX 7
34
35struct set_ct_event {
36 uint32_t command;
37 uint32_t type_mask;
38 uint32_t ev_req_id;
39 uint32_t ev_reg_id;
40};
41
42struct get_ct_event {
43 uint32_t command;
44 uint32_t ev_reg_id;
45 uint32_t ev_req_id;
46};
47
48struct get_ct_event_reply {
49 uint32_t immed_data;
50 uint32_t type;
51};
52
53struct send_mgmt_resp {
54 uint32_t command;
55 uint32_t tag;
56};
57
58
59#define INTERNAL_LOOP_BACK 0x1 /* adapter short cuts the loop internally */
60#define EXTERNAL_LOOP_BACK 0x2 /* requires an external loopback plug */
61
62struct diag_mode_set {
63 uint32_t command;
64 uint32_t type;
65 uint32_t timeout;
66};
67
68struct diag_mode_test {
69 uint32_t command;
70};
71
72#define LPFC_WWNN_TYPE 0
73#define LPFC_WWPN_TYPE 1
74
75struct get_mgmt_rev {
76 uint32_t command;
77};
78
79#define MANAGEMENT_MAJOR_REV 1
80#define MANAGEMENT_MINOR_REV 0
81
82/* the MgmtRevInfo structure */
83struct MgmtRevInfo {
84 uint32_t a_Major;
85 uint32_t a_Minor;
86};
87
88struct get_mgmt_rev_reply {
89 struct MgmtRevInfo info;
90};
91
92struct dfc_mbox_req {
93 uint32_t command;
94 uint32_t inExtWLen;
95 uint32_t outExtWLen;
96 uint8_t mbOffset;
97};
98
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index 650494d622c1..6f0fb51eb461 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -44,18 +44,26 @@ int lpfc_reg_rpi(struct lpfc_hba *, uint16_t, uint32_t, uint8_t *,
44void lpfc_unreg_login(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *); 44void lpfc_unreg_login(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *);
45void lpfc_unreg_did(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *); 45void lpfc_unreg_did(struct lpfc_hba *, uint16_t, uint32_t, LPFC_MBOXQ_t *);
46void lpfc_reg_vpi(struct lpfc_vport *, LPFC_MBOXQ_t *); 46void lpfc_reg_vpi(struct lpfc_vport *, LPFC_MBOXQ_t *);
47void lpfc_register_new_vport(struct lpfc_hba *, struct lpfc_vport *,
48 struct lpfc_nodelist *);
47void lpfc_unreg_vpi(struct lpfc_hba *, uint16_t, LPFC_MBOXQ_t *); 49void lpfc_unreg_vpi(struct lpfc_hba *, uint16_t, LPFC_MBOXQ_t *);
48void lpfc_init_link(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t); 50void lpfc_init_link(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t);
49void lpfc_request_features(struct lpfc_hba *, struct lpfcMboxq *); 51void lpfc_request_features(struct lpfc_hba *, struct lpfcMboxq *);
52void lpfc_supported_pages(struct lpfcMboxq *);
53void lpfc_sli4_params(struct lpfcMboxq *);
54int lpfc_pc_sli4_params_get(struct lpfc_hba *, LPFC_MBOXQ_t *);
50 55
51struct lpfc_vport *lpfc_find_vport_by_did(struct lpfc_hba *, uint32_t); 56struct lpfc_vport *lpfc_find_vport_by_did(struct lpfc_hba *, uint32_t);
52void lpfc_cleanup_rcv_buffers(struct lpfc_vport *); 57void lpfc_cleanup_rcv_buffers(struct lpfc_vport *);
53void lpfc_rcv_seq_check_edtov(struct lpfc_vport *); 58void lpfc_rcv_seq_check_edtov(struct lpfc_vport *);
54void lpfc_cleanup_rpis(struct lpfc_vport *, int); 59void lpfc_cleanup_rpis(struct lpfc_vport *, int);
60void lpfc_cleanup_pending_mbox(struct lpfc_vport *);
55int lpfc_linkdown(struct lpfc_hba *); 61int lpfc_linkdown(struct lpfc_hba *);
56void lpfc_linkdown_port(struct lpfc_vport *); 62void lpfc_linkdown_port(struct lpfc_vport *);
57void lpfc_port_link_failure(struct lpfc_vport *); 63void lpfc_port_link_failure(struct lpfc_vport *);
58void lpfc_mbx_cmpl_read_la(struct lpfc_hba *, LPFC_MBOXQ_t *); 64void lpfc_mbx_cmpl_read_la(struct lpfc_hba *, LPFC_MBOXQ_t *);
65void lpfc_init_vpi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
66void lpfc_retry_pport_discovery(struct lpfc_hba *);
59 67
60void lpfc_mbx_cmpl_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *); 68void lpfc_mbx_cmpl_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
61void lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *, LPFC_MBOXQ_t *); 69void lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *, LPFC_MBOXQ_t *);
@@ -73,6 +81,7 @@ void lpfc_set_disctmo(struct lpfc_vport *);
73int lpfc_can_disctmo(struct lpfc_vport *); 81int lpfc_can_disctmo(struct lpfc_vport *);
74int lpfc_unreg_rpi(struct lpfc_vport *, struct lpfc_nodelist *); 82int lpfc_unreg_rpi(struct lpfc_vport *, struct lpfc_nodelist *);
75void lpfc_unreg_all_rpis(struct lpfc_vport *); 83void lpfc_unreg_all_rpis(struct lpfc_vport *);
84void lpfc_unreg_hba_rpis(struct lpfc_hba *);
76void lpfc_unreg_default_rpis(struct lpfc_vport *); 85void lpfc_unreg_default_rpis(struct lpfc_vport *);
77void lpfc_issue_reg_vpi(struct lpfc_hba *, struct lpfc_vport *); 86void lpfc_issue_reg_vpi(struct lpfc_hba *, struct lpfc_vport *);
78 87
@@ -99,7 +108,7 @@ int lpfc_disc_state_machine(struct lpfc_vport *, struct lpfc_nodelist *, void *,
99 108
100void lpfc_do_scr_ns_plogi(struct lpfc_hba *, struct lpfc_vport *); 109void lpfc_do_scr_ns_plogi(struct lpfc_hba *, struct lpfc_vport *);
101int lpfc_check_sparm(struct lpfc_vport *, struct lpfc_nodelist *, 110int lpfc_check_sparm(struct lpfc_vport *, struct lpfc_nodelist *,
102 struct serv_parm *, uint32_t); 111 struct serv_parm *, uint32_t, int);
103int lpfc_els_abort(struct lpfc_hba *, struct lpfc_nodelist *); 112int lpfc_els_abort(struct lpfc_hba *, struct lpfc_nodelist *);
104void lpfc_more_plogi(struct lpfc_vport *); 113void lpfc_more_plogi(struct lpfc_vport *);
105void lpfc_more_adisc(struct lpfc_vport *); 114void lpfc_more_adisc(struct lpfc_vport *);
@@ -197,6 +206,7 @@ void lpfc_reg_fcfi(struct lpfc_hba *, struct lpfcMboxq *);
197void lpfc_unreg_fcfi(struct lpfcMboxq *, uint16_t); 206void lpfc_unreg_fcfi(struct lpfcMboxq *, uint16_t);
198void lpfc_resume_rpi(struct lpfcMboxq *, struct lpfc_nodelist *); 207void lpfc_resume_rpi(struct lpfcMboxq *, struct lpfc_nodelist *);
199int lpfc_check_pending_fcoe_event(struct lpfc_hba *, uint8_t); 208int lpfc_check_pending_fcoe_event(struct lpfc_hba *, uint8_t);
209void lpfc_issue_init_vpi(struct lpfc_vport *);
200 210
201void lpfc_config_hbq(struct lpfc_hba *, uint32_t, struct lpfc_hbq_init *, 211void lpfc_config_hbq(struct lpfc_hba *, uint32_t, struct lpfc_hbq_init *,
202 uint32_t , LPFC_MBOXQ_t *); 212 uint32_t , LPFC_MBOXQ_t *);
@@ -206,7 +216,11 @@ struct hbq_dmabuf *lpfc_sli4_rb_alloc(struct lpfc_hba *);
206void lpfc_sli4_rb_free(struct lpfc_hba *, struct hbq_dmabuf *); 216void lpfc_sli4_rb_free(struct lpfc_hba *, struct hbq_dmabuf *);
207void lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *, struct fcf_record *, 217void lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *, struct fcf_record *,
208 uint16_t); 218 uint16_t);
219void lpfc_unregister_fcf(struct lpfc_hba *);
220void lpfc_unregister_fcf_rescan(struct lpfc_hba *);
209void lpfc_unregister_unused_fcf(struct lpfc_hba *); 221void lpfc_unregister_unused_fcf(struct lpfc_hba *);
222int lpfc_sli4_redisc_fcf_table(struct lpfc_hba *);
223void lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *);
210 224
211int lpfc_mem_alloc(struct lpfc_hba *, int align); 225int lpfc_mem_alloc(struct lpfc_hba *, int align);
212void lpfc_mem_free(struct lpfc_hba *); 226void lpfc_mem_free(struct lpfc_hba *);
@@ -365,6 +379,8 @@ void lpfc_free_fast_evt(struct lpfc_hba *, struct lpfc_fast_path_event *);
365void lpfc_create_static_vport(struct lpfc_hba *); 379void lpfc_create_static_vport(struct lpfc_hba *);
366void lpfc_stop_hba_timers(struct lpfc_hba *); 380void lpfc_stop_hba_timers(struct lpfc_hba *);
367void lpfc_stop_port(struct lpfc_hba *); 381void lpfc_stop_port(struct lpfc_hba *);
382void __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *);
383void lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *);
368void lpfc_parse_fcoe_conf(struct lpfc_hba *, uint8_t *, uint32_t); 384void lpfc_parse_fcoe_conf(struct lpfc_hba *, uint8_t *, uint32_t);
369int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); 385int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
370void lpfc_start_fdiscs(struct lpfc_hba *phba); 386void lpfc_start_fdiscs(struct lpfc_hba *phba);
@@ -378,5 +394,5 @@ struct lpfc_vport *lpfc_find_vport_by_vpid(struct lpfc_hba *, uint16_t);
378/* functions to support SGIOv4/bsg interface */ 394/* functions to support SGIOv4/bsg interface */
379int lpfc_bsg_request(struct fc_bsg_job *); 395int lpfc_bsg_request(struct fc_bsg_job *);
380int lpfc_bsg_timeout(struct fc_bsg_job *); 396int lpfc_bsg_timeout(struct fc_bsg_job *);
381void lpfc_bsg_ct_unsol_event(struct lpfc_hba *, struct lpfc_sli_ring *, 397int lpfc_bsg_ct_unsol_event(struct lpfc_hba *, struct lpfc_sli_ring *,
382 struct lpfc_iocbq *); 398 struct lpfc_iocbq *);
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index 0ebcd9baca79..c7e921973f66 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -97,7 +97,8 @@ lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
97 struct list_head head; 97 struct list_head head;
98 struct lpfc_dmabuf *bdeBuf; 98 struct lpfc_dmabuf *bdeBuf;
99 99
100 lpfc_bsg_ct_unsol_event(phba, pring, piocbq); 100 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
101 return;
101 102
102 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) { 103 if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
103 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); 104 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
@@ -181,7 +182,8 @@ lpfc_sli4_ct_abort_unsol_event(struct lpfc_hba *phba,
181 uint32_t size; 182 uint32_t size;
182 183
183 /* Forward abort event to any process registered to receive ct event */ 184 /* Forward abort event to any process registered to receive ct event */
184 lpfc_bsg_ct_unsol_event(phba, pring, piocbq); 185 if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
186 return;
185 187
186 /* If there is no BDE associated with IOCB, there is nothing to do */ 188 /* If there is no BDE associated with IOCB, there is nothing to do */
187 if (icmd->ulpBdeCount == 0) 189 if (icmd->ulpBdeCount == 0)
@@ -1843,12 +1845,7 @@ lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
1843 c = (rev & 0x0000ff00) >> 8; 1845 c = (rev & 0x0000ff00) >> 8;
1844 b4 = (rev & 0x000000ff); 1846 b4 = (rev & 0x000000ff);
1845 1847
1846 if (flag) 1848 sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
1847 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1848 b2, b3, c, b4);
1849 else
1850 sprintf(fwrevision, "%d.%d%d%c%d ", b1,
1851 b2, b3, c, b4);
1852 } 1849 }
1853 return; 1850 return;
1854} 1851}
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index 2cc39684ce97..08b6634cb994 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -50,9 +50,6 @@ static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
50 struct lpfc_nodelist *ndlp, uint8_t retry); 50 struct lpfc_nodelist *ndlp, uint8_t retry);
51static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba, 51static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
52 struct lpfc_iocbq *iocb); 52 struct lpfc_iocbq *iocb);
53static void lpfc_register_new_vport(struct lpfc_hba *phba,
54 struct lpfc_vport *vport,
55 struct lpfc_nodelist *ndlp);
56 53
57static int lpfc_max_els_tries = 3; 54static int lpfc_max_els_tries = 3;
58 55
@@ -592,6 +589,15 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
592 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 589 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
593 spin_unlock_irq(shost->host_lock); 590 spin_unlock_irq(shost->host_lock);
594 } 591 }
592 /*
593 * If VPI is unreged, driver need to do INIT_VPI
594 * before re-registering
595 */
596 if (phba->sli_rev == LPFC_SLI_REV4) {
597 spin_lock_irq(shost->host_lock);
598 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
599 spin_unlock_irq(shost->host_lock);
600 }
595 } 601 }
596 602
597 if (phba->sli_rev < LPFC_SLI_REV4) { 603 if (phba->sli_rev < LPFC_SLI_REV4) {
@@ -604,10 +610,13 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
604 } else { 610 } else {
605 ndlp->nlp_type |= NLP_FABRIC; 611 ndlp->nlp_type |= NLP_FABRIC;
606 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE); 612 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
607 if (vport->vpi_state & LPFC_VPI_REGISTERED) { 613 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
614 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
608 lpfc_start_fdiscs(phba); 615 lpfc_start_fdiscs(phba);
609 lpfc_do_scr_ns_plogi(phba, vport); 616 lpfc_do_scr_ns_plogi(phba, vport);
610 } else 617 } else if (vport->fc_flag & FC_VFI_REGISTERED)
618 lpfc_issue_init_vpi(vport);
619 else
611 lpfc_issue_reg_vfi(vport); 620 lpfc_issue_reg_vfi(vport);
612 } 621 }
613 return 0; 622 return 0;
@@ -804,6 +813,9 @@ lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
804 irsp->ulpTimeout); 813 irsp->ulpTimeout);
805 goto flogifail; 814 goto flogifail;
806 } 815 }
816 spin_lock_irq(shost->host_lock);
817 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
818 spin_unlock_irq(shost->host_lock);
807 819
808 /* 820 /*
809 * The FLogI succeeded. Sync the data for the CPU before 821 * The FLogI succeeded. Sync the data for the CPU before
@@ -2720,7 +2732,7 @@ lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2720 if (did == FDMI_DID) 2732 if (did == FDMI_DID)
2721 retry = 1; 2733 retry = 1;
2722 2734
2723 if ((cmd == ELS_CMD_FLOGI) && 2735 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
2724 (phba->fc_topology != TOPOLOGY_LOOP) && 2736 (phba->fc_topology != TOPOLOGY_LOOP) &&
2725 !lpfc_error_lost_link(irsp)) { 2737 !lpfc_error_lost_link(irsp)) {
2726 /* FLOGI retry policy */ 2738 /* FLOGI retry policy */
@@ -4385,7 +4397,7 @@ lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4385 4397
4386 did = Fabric_DID; 4398 did = Fabric_DID;
4387 4399
4388 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) { 4400 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
4389 /* For a FLOGI we accept, then if our portname is greater 4401 /* For a FLOGI we accept, then if our portname is greater
4390 * then the remote portname we initiate Nport login. 4402 * then the remote portname we initiate Nport login.
4391 */ 4403 */
@@ -5915,6 +5927,7 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5915 struct Scsi_Host *shost = lpfc_shost_from_vport(vport); 5927 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5916 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2; 5928 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5917 MAILBOX_t *mb = &pmb->u.mb; 5929 MAILBOX_t *mb = &pmb->u.mb;
5930 int rc;
5918 5931
5919 spin_lock_irq(shost->host_lock); 5932 spin_lock_irq(shost->host_lock);
5920 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI; 5933 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
@@ -5936,6 +5949,26 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5936 spin_unlock_irq(shost->host_lock); 5949 spin_unlock_irq(shost->host_lock);
5937 lpfc_can_disctmo(vport); 5950 lpfc_can_disctmo(vport);
5938 break; 5951 break;
5952 /* If reg_vpi fail with invalid VPI status, re-init VPI */
5953 case 0x20:
5954 spin_lock_irq(shost->host_lock);
5955 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5956 spin_unlock_irq(shost->host_lock);
5957 lpfc_init_vpi(phba, pmb, vport->vpi);
5958 pmb->vport = vport;
5959 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
5960 rc = lpfc_sli_issue_mbox(phba, pmb,
5961 MBX_NOWAIT);
5962 if (rc == MBX_NOT_FINISHED) {
5963 lpfc_printf_vlog(vport,
5964 KERN_ERR, LOG_MBOX,
5965 "2732 Failed to issue INIT_VPI"
5966 " mailbox command\n");
5967 } else {
5968 lpfc_nlp_put(ndlp);
5969 return;
5970 }
5971
5939 default: 5972 default:
5940 /* Try to recover from this error */ 5973 /* Try to recover from this error */
5941 lpfc_mbx_unreg_vpi(vport); 5974 lpfc_mbx_unreg_vpi(vport);
@@ -5949,13 +5982,17 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5949 break; 5982 break;
5950 } 5983 }
5951 } else { 5984 } else {
5985 spin_lock_irq(shost->host_lock);
5952 vport->vpi_state |= LPFC_VPI_REGISTERED; 5986 vport->vpi_state |= LPFC_VPI_REGISTERED;
5953 if (vport == phba->pport) 5987 spin_unlock_irq(shost->host_lock);
5988 if (vport == phba->pport) {
5954 if (phba->sli_rev < LPFC_SLI_REV4) 5989 if (phba->sli_rev < LPFC_SLI_REV4)
5955 lpfc_issue_fabric_reglogin(vport); 5990 lpfc_issue_fabric_reglogin(vport);
5956 else 5991 else {
5957 lpfc_issue_reg_vfi(vport); 5992 lpfc_start_fdiscs(phba);
5958 else 5993 lpfc_do_scr_ns_plogi(phba, vport);
5994 }
5995 } else
5959 lpfc_do_scr_ns_plogi(phba, vport); 5996 lpfc_do_scr_ns_plogi(phba, vport);
5960 } 5997 }
5961 5998
@@ -5977,7 +6014,7 @@ lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5977 * This routine registers the @vport as a new virtual port with a HBA. 6014 * This routine registers the @vport as a new virtual port with a HBA.
5978 * It is done through a registering vpi mailbox command. 6015 * It is done through a registering vpi mailbox command.
5979 **/ 6016 **/
5980static void 6017void
5981lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport, 6018lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5982 struct lpfc_nodelist *ndlp) 6019 struct lpfc_nodelist *ndlp)
5983{ 6020{
@@ -6018,6 +6055,78 @@ mbox_err_exit:
6018} 6055}
6019 6056
6020/** 6057/**
6058 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6059 * @phba: pointer to lpfc hba data structure.
6060 *
6061 * This routine abort all pending discovery commands and
6062 * start a timer to retry FLOGI for the physical port
6063 * discovery.
6064 **/
6065void
6066lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6067{
6068 struct lpfc_vport **vports;
6069 struct lpfc_nodelist *ndlp;
6070 struct Scsi_Host *shost;
6071 int i;
6072 uint32_t link_state;
6073
6074 /* Treat this failure as linkdown for all vports */
6075 link_state = phba->link_state;
6076 lpfc_linkdown(phba);
6077 phba->link_state = link_state;
6078
6079 vports = lpfc_create_vport_work_array(phba);
6080
6081 if (vports) {
6082 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6083 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6084 if (ndlp)
6085 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6086 lpfc_els_flush_cmd(vports[i]);
6087 }
6088 lpfc_destroy_vport_work_array(phba, vports);
6089 }
6090
6091 /* If fabric require FLOGI, then re-instantiate physical login */
6092 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6093 if (!ndlp)
6094 return;
6095
6096
6097 shost = lpfc_shost_from_vport(phba->pport);
6098 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6099 spin_lock_irq(shost->host_lock);
6100 ndlp->nlp_flag |= NLP_DELAY_TMO;
6101 spin_unlock_irq(shost->host_lock);
6102 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6103 phba->pport->port_state = LPFC_FLOGI;
6104 return;
6105}
6106
6107/**
6108 * lpfc_fabric_login_reqd - Check if FLOGI required.
6109 * @phba: pointer to lpfc hba data structure.
6110 * @cmdiocb: pointer to FDISC command iocb.
6111 * @rspiocb: pointer to FDISC response iocb.
6112 *
6113 * This routine checks if a FLOGI is reguired for FDISC
6114 * to succeed.
6115 **/
6116static int
6117lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6118 struct lpfc_iocbq *cmdiocb,
6119 struct lpfc_iocbq *rspiocb)
6120{
6121
6122 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6123 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6124 return 0;
6125 else
6126 return 1;
6127}
6128
6129/**
6021 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command 6130 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6022 * @phba: pointer to lpfc hba data structure. 6131 * @phba: pointer to lpfc hba data structure.
6023 * @cmdiocb: pointer to lpfc command iocb data structure. 6132 * @cmdiocb: pointer to lpfc command iocb data structure.
@@ -6066,6 +6175,12 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6066 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID); 6175 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6067 6176
6068 if (irsp->ulpStatus) { 6177 if (irsp->ulpStatus) {
6178
6179 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6180 lpfc_retry_pport_discovery(phba);
6181 goto out;
6182 }
6183
6069 /* Check for retry */ 6184 /* Check for retry */
6070 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) 6185 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6071 goto out; 6186 goto out;
@@ -6076,6 +6191,7 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6076 goto fdisc_failed; 6191 goto fdisc_failed;
6077 } 6192 }
6078 spin_lock_irq(shost->host_lock); 6193 spin_lock_irq(shost->host_lock);
6194 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
6079 vport->fc_flag |= FC_FABRIC; 6195 vport->fc_flag |= FC_FABRIC;
6080 if (vport->phba->fc_topology == TOPOLOGY_LOOP) 6196 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6081 vport->fc_flag |= FC_PUBLIC_LOOP; 6197 vport->fc_flag |= FC_PUBLIC_LOOP;
@@ -6103,10 +6219,13 @@ lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6103 lpfc_mbx_unreg_vpi(vport); 6219 lpfc_mbx_unreg_vpi(vport);
6104 spin_lock_irq(shost->host_lock); 6220 spin_lock_irq(shost->host_lock);
6105 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 6221 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6222 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6106 spin_unlock_irq(shost->host_lock); 6223 spin_unlock_irq(shost->host_lock);
6107 } 6224 }
6108 6225
6109 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) 6226 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6227 lpfc_issue_init_vpi(vport);
6228 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
6110 lpfc_register_new_vport(phba, vport, ndlp); 6229 lpfc_register_new_vport(phba, vport, ndlp);
6111 else 6230 else
6112 lpfc_do_scr_ns_plogi(phba, vport); 6231 lpfc_do_scr_ns_plogi(phba, vport);
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index 2445e399fd60..2359d0bfb734 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -525,6 +525,8 @@ lpfc_work_done(struct lpfc_hba *phba)
525 spin_unlock_irq(&phba->hbalock); 525 spin_unlock_irq(&phba->hbalock);
526 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ); 526 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
527 } 527 }
528 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
529 lpfc_sli4_fcf_redisc_event_proc(phba);
528 } 530 }
529 531
530 vports = lpfc_create_vport_work_array(phba); 532 vports = lpfc_create_vport_work_array(phba);
@@ -706,6 +708,8 @@ lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
706void 708void
707lpfc_port_link_failure(struct lpfc_vport *vport) 709lpfc_port_link_failure(struct lpfc_vport *vport)
708{ 710{
711 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
712
709 /* Cleanup any outstanding received buffers */ 713 /* Cleanup any outstanding received buffers */
710 lpfc_cleanup_rcv_buffers(vport); 714 lpfc_cleanup_rcv_buffers(vport);
711 715
@@ -752,12 +756,14 @@ lpfc_linkdown(struct lpfc_hba *phba)
752 lpfc_scsi_dev_block(phba); 756 lpfc_scsi_dev_block(phba);
753 757
754 spin_lock_irq(&phba->hbalock); 758 spin_lock_irq(&phba->hbalock);
755 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_DISCOVERED); 759 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
760 spin_unlock_irq(&phba->hbalock);
756 if (phba->link_state > LPFC_LINK_DOWN) { 761 if (phba->link_state > LPFC_LINK_DOWN) {
757 phba->link_state = LPFC_LINK_DOWN; 762 phba->link_state = LPFC_LINK_DOWN;
763 spin_lock_irq(shost->host_lock);
758 phba->pport->fc_flag &= ~FC_LBIT; 764 phba->pport->fc_flag &= ~FC_LBIT;
765 spin_unlock_irq(shost->host_lock);
759 } 766 }
760 spin_unlock_irq(&phba->hbalock);
761 vports = lpfc_create_vport_work_array(phba); 767 vports = lpfc_create_vport_work_array(phba);
762 if (vports != NULL) 768 if (vports != NULL)
763 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 769 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
@@ -1023,7 +1029,7 @@ lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1023 return; 1029 return;
1024 } 1030 }
1025 spin_lock_irqsave(&phba->hbalock, flags); 1031 spin_lock_irqsave(&phba->hbalock, flags);
1026 phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE); 1032 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1027 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1033 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1028 spin_unlock_irqrestore(&phba->hbalock, flags); 1034 spin_unlock_irqrestore(&phba->hbalock, flags);
1029 if (vport->port_state != LPFC_FLOGI) 1035 if (vport->port_state != LPFC_FLOGI)
@@ -1045,25 +1051,23 @@ lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1045static uint32_t 1051static uint32_t
1046lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record) 1052lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1047{ 1053{
1048 if ((fab_name[0] == 1054 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1049 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record)) && 1055 return 0;
1050 (fab_name[1] == 1056 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1051 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record)) && 1057 return 0;
1052 (fab_name[2] == 1058 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1053 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record)) &&
1054 (fab_name[3] ==
1055 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record)) &&
1056 (fab_name[4] ==
1057 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record)) &&
1058 (fab_name[5] ==
1059 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record)) &&
1060 (fab_name[6] ==
1061 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record)) &&
1062 (fab_name[7] ==
1063 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record)))
1064 return 1;
1065 else
1066 return 0; 1059 return 0;
1060 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1061 return 0;
1062 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1063 return 0;
1064 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1065 return 0;
1066 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1067 return 0;
1068 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1069 return 0;
1070 return 1;
1067} 1071}
1068 1072
1069/** 1073/**
@@ -1078,30 +1082,28 @@ lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1078static uint32_t 1082static uint32_t
1079lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record) 1083lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1080{ 1084{
1081 if ((sw_name[0] == 1085 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1082 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record)) &&
1083 (sw_name[1] ==
1084 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record)) &&
1085 (sw_name[2] ==
1086 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record)) &&
1087 (sw_name[3] ==
1088 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record)) &&
1089 (sw_name[4] ==
1090 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record)) &&
1091 (sw_name[5] ==
1092 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record)) &&
1093 (sw_name[6] ==
1094 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record)) &&
1095 (sw_name[7] ==
1096 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record)))
1097 return 1;
1098 else
1099 return 0; 1086 return 0;
1087 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1088 return 0;
1089 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1090 return 0;
1091 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1092 return 0;
1093 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1094 return 0;
1095 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1096 return 0;
1097 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1098 return 0;
1099 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1100 return 0;
1101 return 1;
1100} 1102}
1101 1103
1102/** 1104/**
1103 * lpfc_mac_addr_match - Check if the fcf mac address match. 1105 * lpfc_mac_addr_match - Check if the fcf mac address match.
1104 * @phba: pointer to lpfc hba data structure. 1106 * @mac_addr: pointer to mac address.
1105 * @new_fcf_record: pointer to fcf record. 1107 * @new_fcf_record: pointer to fcf record.
1106 * 1108 *
1107 * This routine compare the fcf record's mac address with HBA's 1109 * This routine compare the fcf record's mac address with HBA's
@@ -1109,85 +1111,115 @@ lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1109 * returns 1 else return 0. 1111 * returns 1 else return 0.
1110 **/ 1112 **/
1111static uint32_t 1113static uint32_t
1112lpfc_mac_addr_match(struct lpfc_hba *phba, struct fcf_record *new_fcf_record) 1114lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1113{ 1115{
1114 if ((phba->fcf.mac_addr[0] == 1116 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1115 bf_get(lpfc_fcf_record_mac_0, new_fcf_record)) && 1117 return 0;
1116 (phba->fcf.mac_addr[1] == 1118 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1117 bf_get(lpfc_fcf_record_mac_1, new_fcf_record)) && 1119 return 0;
1118 (phba->fcf.mac_addr[2] == 1120 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1119 bf_get(lpfc_fcf_record_mac_2, new_fcf_record)) &&
1120 (phba->fcf.mac_addr[3] ==
1121 bf_get(lpfc_fcf_record_mac_3, new_fcf_record)) &&
1122 (phba->fcf.mac_addr[4] ==
1123 bf_get(lpfc_fcf_record_mac_4, new_fcf_record)) &&
1124 (phba->fcf.mac_addr[5] ==
1125 bf_get(lpfc_fcf_record_mac_5, new_fcf_record)))
1126 return 1;
1127 else
1128 return 0; 1121 return 0;
1122 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1123 return 0;
1124 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1125 return 0;
1126 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1127 return 0;
1128 return 1;
1129}
1130
1131static bool
1132lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1133{
1134 return (curr_vlan_id == new_vlan_id);
1129} 1135}
1130 1136
1131/** 1137/**
1132 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba. 1138 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1133 * @phba: pointer to lpfc hba data structure. 1139 * @fcf: pointer to driver fcf record.
1134 * @new_fcf_record: pointer to fcf record. 1140 * @new_fcf_record: pointer to fcf record.
1135 * 1141 *
1136 * This routine copies the FCF information from the FCF 1142 * This routine copies the FCF information from the FCF
1137 * record to lpfc_hba data structure. 1143 * record to lpfc_hba data structure.
1138 **/ 1144 **/
1139static void 1145static void
1140lpfc_copy_fcf_record(struct lpfc_hba *phba, struct fcf_record *new_fcf_record) 1146lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1147 struct fcf_record *new_fcf_record)
1141{ 1148{
1142 phba->fcf.fabric_name[0] = 1149 /* Fabric name */
1150 fcf_rec->fabric_name[0] =
1143 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record); 1151 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1144 phba->fcf.fabric_name[1] = 1152 fcf_rec->fabric_name[1] =
1145 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record); 1153 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1146 phba->fcf.fabric_name[2] = 1154 fcf_rec->fabric_name[2] =
1147 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record); 1155 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1148 phba->fcf.fabric_name[3] = 1156 fcf_rec->fabric_name[3] =
1149 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record); 1157 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1150 phba->fcf.fabric_name[4] = 1158 fcf_rec->fabric_name[4] =
1151 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record); 1159 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1152 phba->fcf.fabric_name[5] = 1160 fcf_rec->fabric_name[5] =
1153 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record); 1161 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1154 phba->fcf.fabric_name[6] = 1162 fcf_rec->fabric_name[6] =
1155 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record); 1163 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1156 phba->fcf.fabric_name[7] = 1164 fcf_rec->fabric_name[7] =
1157 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record); 1165 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1158 phba->fcf.mac_addr[0] = 1166 /* Mac address */
1159 bf_get(lpfc_fcf_record_mac_0, new_fcf_record); 1167 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1160 phba->fcf.mac_addr[1] = 1168 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1161 bf_get(lpfc_fcf_record_mac_1, new_fcf_record); 1169 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1162 phba->fcf.mac_addr[2] = 1170 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1163 bf_get(lpfc_fcf_record_mac_2, new_fcf_record); 1171 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1164 phba->fcf.mac_addr[3] = 1172 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1165 bf_get(lpfc_fcf_record_mac_3, new_fcf_record); 1173 /* FCF record index */
1166 phba->fcf.mac_addr[4] = 1174 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1167 bf_get(lpfc_fcf_record_mac_4, new_fcf_record); 1175 /* FCF record priority */
1168 phba->fcf.mac_addr[5] = 1176 fcf_rec->priority = new_fcf_record->fip_priority;
1169 bf_get(lpfc_fcf_record_mac_5, new_fcf_record); 1177 /* Switch name */
1170 phba->fcf.fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record); 1178 fcf_rec->switch_name[0] =
1171 phba->fcf.priority = new_fcf_record->fip_priority;
1172 phba->fcf.switch_name[0] =
1173 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record); 1179 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1174 phba->fcf.switch_name[1] = 1180 fcf_rec->switch_name[1] =
1175 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record); 1181 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1176 phba->fcf.switch_name[2] = 1182 fcf_rec->switch_name[2] =
1177 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record); 1183 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1178 phba->fcf.switch_name[3] = 1184 fcf_rec->switch_name[3] =
1179 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record); 1185 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1180 phba->fcf.switch_name[4] = 1186 fcf_rec->switch_name[4] =
1181 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record); 1187 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1182 phba->fcf.switch_name[5] = 1188 fcf_rec->switch_name[5] =
1183 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record); 1189 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1184 phba->fcf.switch_name[6] = 1190 fcf_rec->switch_name[6] =
1185 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record); 1191 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1186 phba->fcf.switch_name[7] = 1192 fcf_rec->switch_name[7] =
1187 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record); 1193 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1188} 1194}
1189 1195
1190/** 1196/**
1197 * lpfc_update_fcf_record - Update driver fcf record
1198 * @phba: pointer to lpfc hba data structure.
1199 * @fcf_rec: pointer to driver fcf record.
1200 * @new_fcf_record: pointer to hba fcf record.
1201 * @addr_mode: address mode to be set to the driver fcf record.
1202 * @vlan_id: vlan tag to be set to the driver fcf record.
1203 * @flag: flag bits to be set to the driver fcf record.
1204 *
1205 * This routine updates the driver FCF record from the new HBA FCF record
1206 * together with the address mode, vlan_id, and other informations. This
1207 * routine is called with the host lock held.
1208 **/
1209static void
1210__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1211 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1212 uint16_t vlan_id, uint32_t flag)
1213{
1214 /* Copy the fields from the HBA's FCF record */
1215 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1216 /* Update other fields of driver FCF record */
1217 fcf_rec->addr_mode = addr_mode;
1218 fcf_rec->vlan_id = vlan_id;
1219 fcf_rec->flag |= (flag | RECORD_VALID);
1220}
1221
1222/**
1191 * lpfc_register_fcf - Register the FCF with hba. 1223 * lpfc_register_fcf - Register the FCF with hba.
1192 * @phba: pointer to lpfc hba data structure. 1224 * @phba: pointer to lpfc hba data structure.
1193 * 1225 *
@@ -1212,7 +1244,7 @@ lpfc_register_fcf(struct lpfc_hba *phba)
1212 1244
1213 /* The FCF is already registered, start discovery */ 1245 /* The FCF is already registered, start discovery */
1214 if (phba->fcf.fcf_flag & FCF_REGISTERED) { 1246 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1215 phba->fcf.fcf_flag |= (FCF_DISCOVERED | FCF_IN_USE); 1247 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1216 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1248 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1217 spin_unlock_irqrestore(&phba->hbalock, flags); 1249 spin_unlock_irqrestore(&phba->hbalock, flags);
1218 if (phba->pport->port_state != LPFC_FLOGI) 1250 if (phba->pport->port_state != LPFC_FLOGI)
@@ -1250,6 +1282,7 @@ lpfc_register_fcf(struct lpfc_hba *phba)
1250 * @new_fcf_record: pointer to fcf record. 1282 * @new_fcf_record: pointer to fcf record.
1251 * @boot_flag: Indicates if this record used by boot bios. 1283 * @boot_flag: Indicates if this record used by boot bios.
1252 * @addr_mode: The address mode to be used by this FCF 1284 * @addr_mode: The address mode to be used by this FCF
1285 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1253 * 1286 *
1254 * This routine compare the fcf record with connect list obtained from the 1287 * This routine compare the fcf record with connect list obtained from the
1255 * config region to decide if this FCF can be used for SAN discovery. It returns 1288 * config region to decide if this FCF can be used for SAN discovery. It returns
@@ -1323,7 +1356,8 @@ lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1323 return 1; 1356 return 1;
1324 } 1357 }
1325 1358
1326 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list, list) { 1359 list_for_each_entry(conn_entry,
1360 &phba->fcf_conn_rec_list, list) {
1327 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID)) 1361 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1328 continue; 1362 continue;
1329 1363
@@ -1470,6 +1504,7 @@ lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1470 */ 1504 */
1471 spin_lock_irq(&phba->hbalock); 1505 spin_lock_irq(&phba->hbalock);
1472 phba->hba_flag &= ~FCF_DISC_INPROGRESS; 1506 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1507 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1473 spin_unlock_irq(&phba->hbalock); 1508 spin_unlock_irq(&phba->hbalock);
1474 } 1509 }
1475 1510
@@ -1524,11 +1559,12 @@ lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1524 uint32_t shdr_status, shdr_add_status; 1559 uint32_t shdr_status, shdr_add_status;
1525 union lpfc_sli4_cfg_shdr *shdr; 1560 union lpfc_sli4_cfg_shdr *shdr;
1526 struct fcf_record *new_fcf_record; 1561 struct fcf_record *new_fcf_record;
1527 int rc;
1528 uint32_t boot_flag, addr_mode; 1562 uint32_t boot_flag, addr_mode;
1529 uint32_t next_fcf_index; 1563 uint32_t next_fcf_index;
1530 unsigned long flags; 1564 struct lpfc_fcf_rec *fcf_rec = NULL;
1565 unsigned long iflags;
1531 uint16_t vlan_id; 1566 uint16_t vlan_id;
1567 int rc;
1532 1568
1533 /* If there is pending FCoE event restart FCF table scan */ 1569 /* If there is pending FCoE event restart FCF table scan */
1534 if (lpfc_check_pending_fcoe_event(phba, 0)) { 1570 if (lpfc_check_pending_fcoe_event(phba, 0)) {
@@ -1583,9 +1619,8 @@ lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1583 sizeof(struct fcf_record)); 1619 sizeof(struct fcf_record));
1584 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); 1620 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
1585 1621
1586 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, 1622 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
1587 &boot_flag, &addr_mode, 1623 &addr_mode, &vlan_id);
1588 &vlan_id);
1589 /* 1624 /*
1590 * If the fcf record does not match with connect list entries 1625 * If the fcf record does not match with connect list entries
1591 * read the next entry. 1626 * read the next entry.
@@ -1594,90 +1629,159 @@ lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1594 goto read_next_fcf; 1629 goto read_next_fcf;
1595 /* 1630 /*
1596 * If this is not the first FCF discovery of the HBA, use last 1631 * If this is not the first FCF discovery of the HBA, use last
1597 * FCF record for the discovery. 1632 * FCF record for the discovery. The condition that a rescan
1633 * matches the in-use FCF record: fabric name, switch name, mac
1634 * address, and vlan_id.
1598 */ 1635 */
1599 spin_lock_irqsave(&phba->hbalock, flags); 1636 spin_lock_irqsave(&phba->hbalock, iflags);
1600 if (phba->fcf.fcf_flag & FCF_IN_USE) { 1637 if (phba->fcf.fcf_flag & FCF_IN_USE) {
1601 if (lpfc_fab_name_match(phba->fcf.fabric_name, 1638 if (lpfc_fab_name_match(phba->fcf.current_rec.fabric_name,
1602 new_fcf_record) && 1639 new_fcf_record) &&
1603 lpfc_sw_name_match(phba->fcf.switch_name, 1640 lpfc_sw_name_match(phba->fcf.current_rec.switch_name,
1604 new_fcf_record) && 1641 new_fcf_record) &&
1605 lpfc_mac_addr_match(phba, new_fcf_record)) { 1642 lpfc_mac_addr_match(phba->fcf.current_rec.mac_addr,
1643 new_fcf_record) &&
1644 lpfc_vlan_id_match(phba->fcf.current_rec.vlan_id,
1645 vlan_id)) {
1606 phba->fcf.fcf_flag |= FCF_AVAILABLE; 1646 phba->fcf.fcf_flag |= FCF_AVAILABLE;
1607 spin_unlock_irqrestore(&phba->hbalock, flags); 1647 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
1648 /* Stop FCF redisc wait timer if pending */
1649 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
1650 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
1651 /* If in fast failover, mark it's completed */
1652 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1653 spin_unlock_irqrestore(&phba->hbalock, iflags);
1608 goto out; 1654 goto out;
1609 } 1655 }
1610 spin_unlock_irqrestore(&phba->hbalock, flags); 1656 /*
1611 goto read_next_fcf; 1657 * Read next FCF record from HBA searching for the matching
1658 * with in-use record only if not during the fast failover
1659 * period. In case of fast failover period, it shall try to
1660 * determine whether the FCF record just read should be the
1661 * next candidate.
1662 */
1663 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
1664 spin_unlock_irqrestore(&phba->hbalock, iflags);
1665 goto read_next_fcf;
1666 }
1612 } 1667 }
1668 /*
1669 * Update on failover FCF record only if it's in FCF fast-failover
1670 * period; otherwise, update on current FCF record.
1671 */
1672 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
1673 /* Fast FCF failover only to the same fabric name */
1674 if (lpfc_fab_name_match(phba->fcf.current_rec.fabric_name,
1675 new_fcf_record))
1676 fcf_rec = &phba->fcf.failover_rec;
1677 else
1678 goto read_next_fcf;
1679 } else
1680 fcf_rec = &phba->fcf.current_rec;
1681
1613 if (phba->fcf.fcf_flag & FCF_AVAILABLE) { 1682 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
1614 /* 1683 /*
1615 * If the current FCF record does not have boot flag 1684 * If the driver FCF record does not have boot flag
1616 * set and new fcf record has boot flag set, use the 1685 * set and new hba fcf record has boot flag set, use
1617 * new fcf record. 1686 * the new hba fcf record.
1618 */ 1687 */
1619 if (boot_flag && !(phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) { 1688 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
1620 /* Use this FCF record */ 1689 /* Choose this FCF record */
1621 lpfc_copy_fcf_record(phba, new_fcf_record); 1690 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1622 phba->fcf.addr_mode = addr_mode; 1691 addr_mode, vlan_id, BOOT_ENABLE);
1623 phba->fcf.fcf_flag |= FCF_BOOT_ENABLE; 1692 spin_unlock_irqrestore(&phba->hbalock, iflags);
1624 if (vlan_id != 0xFFFF) {
1625 phba->fcf.fcf_flag |= FCF_VALID_VLAN;
1626 phba->fcf.vlan_id = vlan_id;
1627 }
1628 spin_unlock_irqrestore(&phba->hbalock, flags);
1629 goto read_next_fcf; 1693 goto read_next_fcf;
1630 } 1694 }
1631 /* 1695 /*
1632 * If the current FCF record has boot flag set and the 1696 * If the driver FCF record has boot flag set and the
1633 * new FCF record does not have boot flag, read the next 1697 * new hba FCF record does not have boot flag, read
1634 * FCF record. 1698 * the next FCF record.
1635 */ 1699 */
1636 if (!boot_flag && (phba->fcf.fcf_flag & FCF_BOOT_ENABLE)) { 1700 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
1637 spin_unlock_irqrestore(&phba->hbalock, flags); 1701 spin_unlock_irqrestore(&phba->hbalock, iflags);
1638 goto read_next_fcf; 1702 goto read_next_fcf;
1639 } 1703 }
1640 /* 1704 /*
1641 * If there is a record with lower priority value for 1705 * If the new hba FCF record has lower priority value
1642 * the current FCF, use that record. 1706 * than the driver FCF record, use the new record.
1643 */ 1707 */
1644 if (lpfc_fab_name_match(phba->fcf.fabric_name, 1708 if (lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record) &&
1645 new_fcf_record) && 1709 (new_fcf_record->fip_priority < fcf_rec->priority)) {
1646 (new_fcf_record->fip_priority < phba->fcf.priority)) { 1710 /* Choose this FCF record */
1647 /* Use this FCF record */ 1711 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1648 lpfc_copy_fcf_record(phba, new_fcf_record); 1712 addr_mode, vlan_id, 0);
1649 phba->fcf.addr_mode = addr_mode;
1650 if (vlan_id != 0xFFFF) {
1651 phba->fcf.fcf_flag |= FCF_VALID_VLAN;
1652 phba->fcf.vlan_id = vlan_id;
1653 }
1654 spin_unlock_irqrestore(&phba->hbalock, flags);
1655 goto read_next_fcf;
1656 } 1713 }
1657 spin_unlock_irqrestore(&phba->hbalock, flags); 1714 spin_unlock_irqrestore(&phba->hbalock, iflags);
1658 goto read_next_fcf; 1715 goto read_next_fcf;
1659 } 1716 }
1660 /* 1717 /*
1661 * This is the first available FCF record, use this 1718 * This is the first suitable FCF record, choose this record for
1662 * record. 1719 * initial best-fit FCF.
1663 */ 1720 */
1664 lpfc_copy_fcf_record(phba, new_fcf_record); 1721 if (fcf_rec) {
1665 phba->fcf.addr_mode = addr_mode; 1722 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1666 if (boot_flag) 1723 addr_mode, vlan_id, (boot_flag ?
1667 phba->fcf.fcf_flag |= FCF_BOOT_ENABLE; 1724 BOOT_ENABLE : 0));
1668 phba->fcf.fcf_flag |= FCF_AVAILABLE; 1725 phba->fcf.fcf_flag |= FCF_AVAILABLE;
1669 if (vlan_id != 0xFFFF) {
1670 phba->fcf.fcf_flag |= FCF_VALID_VLAN;
1671 phba->fcf.vlan_id = vlan_id;
1672 } 1726 }
1673 spin_unlock_irqrestore(&phba->hbalock, flags); 1727 spin_unlock_irqrestore(&phba->hbalock, iflags);
1674 goto read_next_fcf; 1728 goto read_next_fcf;
1675 1729
1676read_next_fcf: 1730read_next_fcf:
1677 lpfc_sli4_mbox_cmd_free(phba, mboxq); 1731 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1678 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) 1732 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
1679 lpfc_register_fcf(phba); 1733 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
1680 else 1734 /*
1735 * Case of FCF fast failover scan
1736 */
1737
1738 /*
1739 * It has not found any suitable FCF record, cancel
1740 * FCF scan inprogress, and do nothing
1741 */
1742 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
1743 spin_lock_irqsave(&phba->hbalock, iflags);
1744 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1745 spin_unlock_irqrestore(&phba->hbalock, iflags);
1746 return;
1747 }
1748 /*
1749 * It has found a suitable FCF record that is not
1750 * the same as in-use FCF record, unregister the
1751 * in-use FCF record, replace the in-use FCF record
1752 * with the new FCF record, mark FCF fast failover
1753 * completed, and then start register the new FCF
1754 * record.
1755 */
1756
1757 /* unregister the current in-use FCF record */
1758 lpfc_unregister_fcf(phba);
1759 /* replace in-use record with the new record */
1760 memcpy(&phba->fcf.current_rec,
1761 &phba->fcf.failover_rec,
1762 sizeof(struct lpfc_fcf_rec));
1763 /* mark the FCF fast failover completed */
1764 spin_lock_irqsave(&phba->hbalock, iflags);
1765 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1766 spin_unlock_irqrestore(&phba->hbalock, iflags);
1767 /* Register to the new FCF record */
1768 lpfc_register_fcf(phba);
1769 } else {
1770 /*
1771 * In case of transaction period to fast FCF failover,
1772 * do nothing when search to the end of the FCF table.
1773 */
1774 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
1775 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
1776 return;
1777 /*
1778 * Otherwise, initial scan or post linkdown rescan,
1779 * register with the best fit FCF record found so
1780 * far through the scanning process.
1781 */
1782 lpfc_register_fcf(phba);
1783 }
1784 } else
1681 lpfc_sli4_read_fcf_record(phba, next_fcf_index); 1785 lpfc_sli4_read_fcf_record(phba, next_fcf_index);
1682 return; 1786 return;
1683 1787
@@ -1695,10 +1799,13 @@ out:
1695 * 1799 *
1696 * This function handles completion of init vpi mailbox command. 1800 * This function handles completion of init vpi mailbox command.
1697 */ 1801 */
1698static void 1802void
1699lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) 1803lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1700{ 1804{
1701 struct lpfc_vport *vport = mboxq->vport; 1805 struct lpfc_vport *vport = mboxq->vport;
1806 struct lpfc_nodelist *ndlp;
1807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1808
1702 if (mboxq->u.mb.mbxStatus) { 1809 if (mboxq->u.mb.mbxStatus) {
1703 lpfc_printf_vlog(vport, KERN_ERR, 1810 lpfc_printf_vlog(vport, KERN_ERR,
1704 LOG_MBOX, 1811 LOG_MBOX,
@@ -1708,9 +1815,23 @@ lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1708 lpfc_vport_set_state(vport, FC_VPORT_FAILED); 1815 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1709 return; 1816 return;
1710 } 1817 }
1711 spin_lock_irq(&phba->hbalock); 1818 spin_lock_irq(shost->host_lock);
1712 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI; 1819 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
1713 spin_unlock_irq(&phba->hbalock); 1820 spin_unlock_irq(shost->host_lock);
1821
1822 /* If this port is physical port or FDISC is done, do reg_vpi */
1823 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
1824 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1825 if (!ndlp)
1826 lpfc_printf_vlog(vport, KERN_ERR,
1827 LOG_DISCOVERY,
1828 "2731 Cannot find fabric "
1829 "controller node\n");
1830 else
1831 lpfc_register_new_vport(phba, vport, ndlp);
1832 mempool_free(mboxq, phba->mbox_mem_pool);
1833 return;
1834 }
1714 1835
1715 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) 1836 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
1716 lpfc_initial_fdisc(vport); 1837 lpfc_initial_fdisc(vport);
@@ -1719,10 +1840,42 @@ lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1719 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS, 1840 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1720 "2606 No NPIV Fabric support\n"); 1841 "2606 No NPIV Fabric support\n");
1721 } 1842 }
1843 mempool_free(mboxq, phba->mbox_mem_pool);
1722 return; 1844 return;
1723} 1845}
1724 1846
1725/** 1847/**
1848 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
1849 * @vport: pointer to lpfc_vport data structure.
1850 *
1851 * This function issue a init_vpi mailbox command to initialize
1852 * VPI for the vport.
1853 */
1854void
1855lpfc_issue_init_vpi(struct lpfc_vport *vport)
1856{
1857 LPFC_MBOXQ_t *mboxq;
1858 int rc;
1859
1860 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
1861 if (!mboxq) {
1862 lpfc_printf_vlog(vport, KERN_ERR,
1863 LOG_MBOX, "2607 Failed to allocate "
1864 "init_vpi mailbox\n");
1865 return;
1866 }
1867 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
1868 mboxq->vport = vport;
1869 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
1870 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
1871 if (rc == MBX_NOT_FINISHED) {
1872 lpfc_printf_vlog(vport, KERN_ERR,
1873 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
1874 mempool_free(mboxq, vport->phba->mbox_mem_pool);
1875 }
1876}
1877
1878/**
1726 * lpfc_start_fdiscs - send fdiscs for each vports on this port. 1879 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
1727 * @phba: pointer to lpfc hba data structure. 1880 * @phba: pointer to lpfc hba data structure.
1728 * 1881 *
@@ -1734,8 +1887,6 @@ lpfc_start_fdiscs(struct lpfc_hba *phba)
1734{ 1887{
1735 struct lpfc_vport **vports; 1888 struct lpfc_vport **vports;
1736 int i; 1889 int i;
1737 LPFC_MBOXQ_t *mboxq;
1738 int rc;
1739 1890
1740 vports = lpfc_create_vport_work_array(phba); 1891 vports = lpfc_create_vport_work_array(phba);
1741 if (vports != NULL) { 1892 if (vports != NULL) {
@@ -1754,26 +1905,7 @@ lpfc_start_fdiscs(struct lpfc_hba *phba)
1754 continue; 1905 continue;
1755 } 1906 }
1756 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) { 1907 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
1757 mboxq = mempool_alloc(phba->mbox_mem_pool, 1908 lpfc_issue_init_vpi(vports[i]);
1758 GFP_KERNEL);
1759 if (!mboxq) {
1760 lpfc_printf_vlog(vports[i], KERN_ERR,
1761 LOG_MBOX, "2607 Failed to allocate "
1762 "init_vpi mailbox\n");
1763 continue;
1764 }
1765 lpfc_init_vpi(phba, mboxq, vports[i]->vpi);
1766 mboxq->vport = vports[i];
1767 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
1768 rc = lpfc_sli_issue_mbox(phba, mboxq,
1769 MBX_NOWAIT);
1770 if (rc == MBX_NOT_FINISHED) {
1771 lpfc_printf_vlog(vports[i], KERN_ERR,
1772 LOG_MBOX, "2608 Failed to issue "
1773 "init_vpi mailbox\n");
1774 mempool_free(mboxq,
1775 phba->mbox_mem_pool);
1776 }
1777 continue; 1909 continue;
1778 } 1910 }
1779 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) 1911 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
@@ -1796,6 +1928,7 @@ lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1796{ 1928{
1797 struct lpfc_dmabuf *dmabuf = mboxq->context1; 1929 struct lpfc_dmabuf *dmabuf = mboxq->context1;
1798 struct lpfc_vport *vport = mboxq->vport; 1930 struct lpfc_vport *vport = mboxq->vport;
1931 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1799 1932
1800 if (mboxq->u.mb.mbxStatus) { 1933 if (mboxq->u.mb.mbxStatus) {
1801 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX, 1934 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
@@ -1813,7 +1946,11 @@ lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1813 goto fail_free_mem; 1946 goto fail_free_mem;
1814 } 1947 }
1815 /* The VPI is implicitly registered when the VFI is registered */ 1948 /* The VPI is implicitly registered when the VFI is registered */
1949 spin_lock_irq(shost->host_lock);
1816 vport->vpi_state |= LPFC_VPI_REGISTERED; 1950 vport->vpi_state |= LPFC_VPI_REGISTERED;
1951 vport->fc_flag |= FC_VFI_REGISTERED;
1952 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
1953 spin_unlock_irq(shost->host_lock);
1817 1954
1818 if (vport->port_state == LPFC_FABRIC_CFG_LINK) { 1955 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
1819 lpfc_start_fdiscs(phba); 1956 lpfc_start_fdiscs(phba);
@@ -2050,8 +2187,7 @@ lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
2050 return; 2187 return;
2051 } 2188 }
2052 spin_unlock_irq(&phba->hbalock); 2189 spin_unlock_irq(&phba->hbalock);
2053 rc = lpfc_sli4_read_fcf_record(phba, 2190 rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
2054 LPFC_FCOE_FCF_GET_FIRST);
2055 if (rc) 2191 if (rc)
2056 goto out; 2192 goto out;
2057 } 2193 }
@@ -2139,10 +2275,12 @@ lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2139 } 2275 }
2140 2276
2141 phba->fc_eventTag = la->eventTag; 2277 phba->fc_eventTag = la->eventTag;
2278 spin_lock_irq(&phba->hbalock);
2142 if (la->mm) 2279 if (la->mm)
2143 phba->sli.sli_flag |= LPFC_MENLO_MAINT; 2280 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
2144 else 2281 else
2145 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT; 2282 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
2283 spin_unlock_irq(&phba->hbalock);
2146 2284
2147 phba->link_events++; 2285 phba->link_events++;
2148 if (la->attType == AT_LINK_UP && (!la->mm)) { 2286 if (la->attType == AT_LINK_UP && (!la->mm)) {
@@ -2271,10 +2409,10 @@ lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2271 mb->mbxStatus); 2409 mb->mbxStatus);
2272 break; 2410 break;
2273 } 2411 }
2274 spin_lock_irq(&phba->hbalock); 2412 spin_lock_irq(shost->host_lock);
2275 vport->vpi_state &= ~LPFC_VPI_REGISTERED; 2413 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
2276 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 2414 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2277 spin_unlock_irq(&phba->hbalock); 2415 spin_unlock_irq(shost->host_lock);
2278 vport->unreg_vpi_cmpl = VPORT_OK; 2416 vport->unreg_vpi_cmpl = VPORT_OK;
2279 mempool_free(pmb, phba->mbox_mem_pool); 2417 mempool_free(pmb, phba->mbox_mem_pool);
2280 /* 2418 /*
@@ -2332,7 +2470,10 @@ lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2332 goto out; 2470 goto out;
2333 } 2471 }
2334 2472
2473 spin_lock_irq(shost->host_lock);
2335 vport->vpi_state |= LPFC_VPI_REGISTERED; 2474 vport->vpi_state |= LPFC_VPI_REGISTERED;
2475 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2476 spin_unlock_irq(shost->host_lock);
2336 vport->num_disc_nodes = 0; 2477 vport->num_disc_nodes = 0;
2337 /* go thru NPR list and issue ELS PLOGIs */ 2478 /* go thru NPR list and issue ELS PLOGIs */
2338 if (vport->fc_npr_cnt) 2479 if (vport->fc_npr_cnt)
@@ -3218,6 +3359,34 @@ lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3218 return 0; 3359 return 0;
3219} 3360}
3220 3361
3362/**
3363 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
3364 * @phba: pointer to lpfc hba data structure.
3365 *
3366 * This routine is invoked to unregister all the currently registered RPIs
3367 * to the HBA.
3368 **/
3369void
3370lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
3371{
3372 struct lpfc_vport **vports;
3373 struct lpfc_nodelist *ndlp;
3374 struct Scsi_Host *shost;
3375 int i;
3376
3377 vports = lpfc_create_vport_work_array(phba);
3378 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3379 shost = lpfc_shost_from_vport(vports[i]);
3380 spin_lock_irq(shost->host_lock);
3381 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
3382 if (ndlp->nlp_flag & NLP_RPI_VALID)
3383 lpfc_unreg_rpi(vports[i], ndlp);
3384 }
3385 spin_unlock_irq(shost->host_lock);
3386 }
3387 lpfc_destroy_vport_work_array(phba, vports);
3388}
3389
3221void 3390void
3222lpfc_unreg_all_rpis(struct lpfc_vport *vport) 3391lpfc_unreg_all_rpis(struct lpfc_vport *vport)
3223{ 3392{
@@ -4448,63 +4617,56 @@ lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
4448} 4617}
4449 4618
4450/** 4619/**
4451 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected. 4620 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
4452 * @phba: Pointer to hba context object. 4621 * @phba: Pointer to hba context object.
4453 * 4622 *
4454 * This function check if there are any connected remote port for the FCF and 4623 * This function prepare the HBA for unregistering the currently registered
4455 * if all the devices are disconnected, this function unregister FCFI. 4624 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
4456 * This function also tries to use another FCF for discovery. 4625 * VFIs.
4457 */ 4626 */
4458void 4627int
4459lpfc_unregister_unused_fcf(struct lpfc_hba *phba) 4628lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
4460{ 4629{
4461 LPFC_MBOXQ_t *mbox; 4630 LPFC_MBOXQ_t *mbox;
4462 int rc;
4463 struct lpfc_vport **vports; 4631 struct lpfc_vport **vports;
4464 int i; 4632 struct lpfc_nodelist *ndlp;
4465 4633 struct Scsi_Host *shost;
4466 spin_lock_irq(&phba->hbalock); 4634 int i, rc;
4467 /*
4468 * If HBA is not running in FIP mode or
4469 * If HBA does not support FCoE or
4470 * If FCF is not registered.
4471 * do nothing.
4472 */
4473 if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
4474 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
4475 (!(phba->hba_flag & HBA_FIP_SUPPORT))) {
4476 spin_unlock_irq(&phba->hbalock);
4477 return;
4478 }
4479 spin_unlock_irq(&phba->hbalock);
4480 4635
4636 /* Unregister RPIs */
4481 if (lpfc_fcf_inuse(phba)) 4637 if (lpfc_fcf_inuse(phba))
4482 return; 4638 lpfc_unreg_hba_rpis(phba);
4483 4639
4484 /* At this point, all discovery is aborted */ 4640 /* At this point, all discovery is aborted */
4485 phba->pport->port_state = LPFC_VPORT_UNKNOWN; 4641 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4486 4642
4487 /* Unregister VPIs */ 4643 /* Unregister VPIs */
4488 vports = lpfc_create_vport_work_array(phba); 4644 vports = lpfc_create_vport_work_array(phba);
4489 if (vports && 4645 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
4490 (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
4491 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 4646 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4647 /* Stop FLOGI/FDISC retries */
4648 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
4649 if (ndlp)
4650 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
4492 lpfc_mbx_unreg_vpi(vports[i]); 4651 lpfc_mbx_unreg_vpi(vports[i]);
4493 spin_lock_irq(&phba->hbalock); 4652 shost = lpfc_shost_from_vport(vports[i]);
4653 spin_lock_irq(shost->host_lock);
4494 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; 4654 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
4495 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; 4655 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
4496 spin_unlock_irq(&phba->hbalock); 4656 spin_unlock_irq(shost->host_lock);
4497 } 4657 }
4498 lpfc_destroy_vport_work_array(phba, vports); 4658 lpfc_destroy_vport_work_array(phba, vports);
4499 4659
4660 /* Cleanup any outstanding ELS commands */
4661 lpfc_els_flush_all_cmd(phba);
4662
4500 /* Unregister VFI */ 4663 /* Unregister VFI */
4501 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 4664 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4502 if (!mbox) { 4665 if (!mbox) {
4503 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, 4666 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4504 "2556 UNREG_VFI mbox allocation failed" 4667 "2556 UNREG_VFI mbox allocation failed"
4505 "HBA state x%x\n", 4668 "HBA state x%x\n", phba->pport->port_state);
4506 phba->pport->port_state); 4669 return -ENOMEM;
4507 return;
4508 } 4670 }
4509 4671
4510 lpfc_unreg_vfi(mbox, phba->pport); 4672 lpfc_unreg_vfi(mbox, phba->pport);
@@ -4514,58 +4676,163 @@ lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
4514 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 4676 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4515 if (rc == MBX_NOT_FINISHED) { 4677 if (rc == MBX_NOT_FINISHED) {
4516 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, 4678 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4517 "2557 UNREG_VFI issue mbox failed rc x%x " 4679 "2557 UNREG_VFI issue mbox failed rc x%x "
4518 "HBA state x%x\n", 4680 "HBA state x%x\n",
4519 rc, phba->pport->port_state); 4681 rc, phba->pport->port_state);
4520 mempool_free(mbox, phba->mbox_mem_pool); 4682 mempool_free(mbox, phba->mbox_mem_pool);
4521 return; 4683 return -EIO;
4522 } 4684 }
4523 4685
4524 /* Unregister FCF */ 4686 shost = lpfc_shost_from_vport(phba->pport);
4687 spin_lock_irq(shost->host_lock);
4688 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
4689 spin_unlock_irq(shost->host_lock);
4690
4691 return 0;
4692}
4693
4694/**
4695 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
4696 * @phba: Pointer to hba context object.
4697 *
4698 * This function issues synchronous unregister FCF mailbox command to HBA to
4699 * unregister the currently registered FCF record. The driver does not reset
4700 * the driver FCF usage state flags.
4701 *
4702 * Return 0 if successfully issued, none-zero otherwise.
4703 */
4704int
4705lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
4706{
4707 LPFC_MBOXQ_t *mbox;
4708 int rc;
4709
4525 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 4710 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4526 if (!mbox) { 4711 if (!mbox) {
4527 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, 4712 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4528 "2551 UNREG_FCFI mbox allocation failed" 4713 "2551 UNREG_FCFI mbox allocation failed"
4529 "HBA state x%x\n", 4714 "HBA state x%x\n", phba->pport->port_state);
4530 phba->pport->port_state); 4715 return -ENOMEM;
4531 return;
4532 } 4716 }
4533
4534 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi); 4717 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
4535 mbox->vport = phba->pport; 4718 mbox->vport = phba->pport;
4536 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl; 4719 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
4537 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); 4720 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4538 4721
4539 if (rc == MBX_NOT_FINISHED) { 4722 if (rc == MBX_NOT_FINISHED) {
4540 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, 4723 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4541 "2552 UNREG_FCFI issue mbox failed rc x%x " 4724 "2552 Unregister FCFI command failed rc x%x "
4542 "HBA state x%x\n", 4725 "HBA state x%x\n",
4543 rc, phba->pport->port_state); 4726 rc, phba->pport->port_state);
4544 mempool_free(mbox, phba->mbox_mem_pool); 4727 return -EINVAL;
4728 }
4729 return 0;
4730}
4731
4732/**
4733 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
4734 * @phba: Pointer to hba context object.
4735 *
4736 * This function unregisters the currently reigstered FCF. This function
4737 * also tries to find another FCF for discovery by rescan the HBA FCF table.
4738 */
4739void
4740lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
4741{
4742 int rc;
4743
4744 /* Preparation for unregistering fcf */
4745 rc = lpfc_unregister_fcf_prep(phba);
4746 if (rc) {
4747 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4748 "2748 Failed to prepare for unregistering "
4749 "HBA's FCF record: rc=%d\n", rc);
4545 return; 4750 return;
4546 } 4751 }
4547 4752
4548 spin_lock_irq(&phba->hbalock); 4753 /* Now, unregister FCF record and reset HBA FCF state */
4549 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_REGISTERED | 4754 rc = lpfc_sli4_unregister_fcf(phba);
4550 FCF_DISCOVERED | FCF_BOOT_ENABLE | FCF_IN_USE | 4755 if (rc)
4551 FCF_VALID_VLAN); 4756 return;
4552 spin_unlock_irq(&phba->hbalock); 4757 /* Reset HBA FCF states after successful unregister FCF */
4758 phba->fcf.fcf_flag = 0;
4553 4759
4554 /* 4760 /*
4555 * If driver is not unloading, check if there is any other 4761 * If driver is not unloading, check if there is any other
4556 * FCF record that can be used for discovery. 4762 * FCF record that can be used for discovery.
4557 */ 4763 */
4558 if ((phba->pport->load_flag & FC_UNLOADING) || 4764 if ((phba->pport->load_flag & FC_UNLOADING) ||
4559 (phba->link_state < LPFC_LINK_UP)) 4765 (phba->link_state < LPFC_LINK_UP))
4560 return; 4766 return;
4561 4767
4562 rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST); 4768 rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
4563 4769
4564 if (rc) 4770 if (rc)
4565 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX, 4771 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4566 "2553 lpfc_unregister_unused_fcf failed to read FCF" 4772 "2553 lpfc_unregister_unused_fcf failed "
4567 " record HBA state x%x\n", 4773 "to read FCF record HBA state x%x\n",
4568 phba->pport->port_state); 4774 phba->pport->port_state);
4775}
4776
4777/**
4778 * lpfc_unregister_fcf - Unregister the currently registered fcf record
4779 * @phba: Pointer to hba context object.
4780 *
4781 * This function just unregisters the currently reigstered FCF. It does not
4782 * try to find another FCF for discovery.
4783 */
4784void
4785lpfc_unregister_fcf(struct lpfc_hba *phba)
4786{
4787 int rc;
4788
4789 /* Preparation for unregistering fcf */
4790 rc = lpfc_unregister_fcf_prep(phba);
4791 if (rc) {
4792 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4793 "2749 Failed to prepare for unregistering "
4794 "HBA's FCF record: rc=%d\n", rc);
4795 return;
4796 }
4797
4798 /* Now, unregister FCF record and reset HBA FCF state */
4799 rc = lpfc_sli4_unregister_fcf(phba);
4800 if (rc)
4801 return;
4802 /* Set proper HBA FCF states after successful unregister FCF */
4803 spin_lock_irq(&phba->hbalock);
4804 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
4805 spin_unlock_irq(&phba->hbalock);
4806}
4807
4808/**
4809 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
4810 * @phba: Pointer to hba context object.
4811 *
4812 * This function check if there are any connected remote port for the FCF and
4813 * if all the devices are disconnected, this function unregister FCFI.
4814 * This function also tries to use another FCF for discovery.
4815 */
4816void
4817lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
4818{
4819 /*
4820 * If HBA is not running in FIP mode or if HBA does not support
4821 * FCoE or if FCF is not registered, do nothing.
4822 */
4823 spin_lock_irq(&phba->hbalock);
4824 if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
4825 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
4826 !(phba->hba_flag & HBA_FIP_SUPPORT)) {
4827 spin_unlock_irq(&phba->hbalock);
4828 return;
4829 }
4830 spin_unlock_irq(&phba->hbalock);
4831
4832 if (lpfc_fcf_inuse(phba))
4833 return;
4834
4835 lpfc_unregister_fcf_rescan(phba);
4569} 4836}
4570 4837
4571/** 4838/**
diff --git a/drivers/scsi/lpfc/lpfc_hw.h b/drivers/scsi/lpfc/lpfc_hw.h
index c9faa1d8c3c8..89ff7c09e298 100644
--- a/drivers/scsi/lpfc/lpfc_hw.h
+++ b/drivers/scsi/lpfc/lpfc_hw.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -1346,6 +1346,9 @@ typedef struct { /* FireFly BIU registers */
1346#define MBX_HEARTBEAT 0x31 1346#define MBX_HEARTBEAT 0x31
1347#define MBX_WRITE_VPARMS 0x32 1347#define MBX_WRITE_VPARMS 0x32
1348#define MBX_ASYNCEVT_ENABLE 0x33 1348#define MBX_ASYNCEVT_ENABLE 0x33
1349#define MBX_READ_EVENT_LOG_STATUS 0x37
1350#define MBX_READ_EVENT_LOG 0x38
1351#define MBX_WRITE_EVENT_LOG 0x39
1349 1352
1350#define MBX_PORT_CAPABILITIES 0x3B 1353#define MBX_PORT_CAPABILITIES 0x3B
1351#define MBX_PORT_IOV_CONTROL 0x3C 1354#define MBX_PORT_IOV_CONTROL 0x3C
@@ -1465,17 +1468,13 @@ typedef struct { /* FireFly BIU registers */
1465#define CMD_IOCB_LOGENTRY_CN 0x94 1468#define CMD_IOCB_LOGENTRY_CN 0x94
1466#define CMD_IOCB_LOGENTRY_ASYNC_CN 0x96 1469#define CMD_IOCB_LOGENTRY_ASYNC_CN 0x96
1467 1470
1468/* Unhandled Data Security SLI Commands */ 1471/* Data Security SLI Commands */
1469#define DSSCMD_IWRITE64_CR 0xD8 1472#define DSSCMD_IWRITE64_CR 0xF8
1470#define DSSCMD_IWRITE64_CX 0xD9 1473#define DSSCMD_IWRITE64_CX 0xF9
1471#define DSSCMD_IREAD64_CR 0xDA 1474#define DSSCMD_IREAD64_CR 0xFA
1472#define DSSCMD_IREAD64_CX 0xDB 1475#define DSSCMD_IREAD64_CX 0xFB
1473#define DSSCMD_INVALIDATE_DEK 0xDC 1476
1474#define DSSCMD_SET_KEK 0xDD 1477#define CMD_MAX_IOCB_CMD 0xFB
1475#define DSSCMD_GET_KEK_ID 0xDE
1476#define DSSCMD_GEN_XFER 0xDF
1477
1478#define CMD_MAX_IOCB_CMD 0xE6
1479#define CMD_IOCB_MASK 0xff 1478#define CMD_IOCB_MASK 0xff
1480 1479
1481#define MAX_MSG_DATA 28 /* max msg data in CMD_ADAPTER_MSG 1480#define MAX_MSG_DATA 28 /* max msg data in CMD_ADAPTER_MSG
diff --git a/drivers/scsi/lpfc/lpfc_hw4.h b/drivers/scsi/lpfc/lpfc_hw4.h
index 8a2a1c5935c6..820015fbc4d6 100644
--- a/drivers/scsi/lpfc/lpfc_hw4.h
+++ b/drivers/scsi/lpfc/lpfc_hw4.h
@@ -52,35 +52,37 @@ struct dma_address {
52 uint32_t addr_hi; 52 uint32_t addr_hi;
53}; 53};
54 54
55#define LPFC_SLIREV_CONF_WORD 0x58
56struct lpfc_sli_intf { 55struct lpfc_sli_intf {
57 uint32_t word0; 56 uint32_t word0;
58#define lpfc_sli_intf_iftype_MASK 0x00000007 57#define lpfc_sli_intf_valid_SHIFT 29
59#define lpfc_sli_intf_iftype_SHIFT 0 58#define lpfc_sli_intf_valid_MASK 0x00000007
60#define lpfc_sli_intf_iftype_WORD word0 59#define lpfc_sli_intf_valid_WORD word0
61#define lpfc_sli_intf_rev_MASK 0x0000000f
62#define lpfc_sli_intf_rev_SHIFT 4
63#define lpfc_sli_intf_rev_WORD word0
64#define LPFC_SLIREV_CONF_SLI4 4
65#define lpfc_sli_intf_family_MASK 0x000000ff
66#define lpfc_sli_intf_family_SHIFT 8
67#define lpfc_sli_intf_family_WORD word0
68#define lpfc_sli_intf_feat1_MASK 0x000000ff
69#define lpfc_sli_intf_feat1_SHIFT 16
70#define lpfc_sli_intf_feat1_WORD word0
71#define lpfc_sli_intf_feat2_MASK 0x0000001f
72#define lpfc_sli_intf_feat2_SHIFT 24
73#define lpfc_sli_intf_feat2_WORD word0
74#define lpfc_sli_intf_valid_MASK 0x00000007
75#define lpfc_sli_intf_valid_SHIFT 29
76#define lpfc_sli_intf_valid_WORD word0
77#define LPFC_SLI_INTF_VALID 6 60#define LPFC_SLI_INTF_VALID 6
61#define lpfc_sli_intf_featurelevel2_SHIFT 24
62#define lpfc_sli_intf_featurelevel2_MASK 0x0000001F
63#define lpfc_sli_intf_featurelevel2_WORD word0
64#define lpfc_sli_intf_featurelevel1_SHIFT 16
65#define lpfc_sli_intf_featurelevel1_MASK 0x000000FF
66#define lpfc_sli_intf_featurelevel1_WORD word0
67#define LPFC_SLI_INTF_FEATURELEVEL1_1 1
68#define LPFC_SLI_INTF_FEATURELEVEL1_2 2
69#define lpfc_sli_intf_sli_family_SHIFT 8
70#define lpfc_sli_intf_sli_family_MASK 0x000000FF
71#define lpfc_sli_intf_sli_family_WORD word0
72#define LPFC_SLI_INTF_FAMILY_BE2 0
73#define LPFC_SLI_INTF_FAMILY_BE3 1
74#define lpfc_sli_intf_slirev_SHIFT 4
75#define lpfc_sli_intf_slirev_MASK 0x0000000F
76#define lpfc_sli_intf_slirev_WORD word0
77#define LPFC_SLI_INTF_REV_SLI3 3
78#define LPFC_SLI_INTF_REV_SLI4 4
79#define lpfc_sli_intf_if_type_SHIFT 0
80#define lpfc_sli_intf_if_type_MASK 0x00000007
81#define lpfc_sli_intf_if_type_WORD word0
82#define LPFC_SLI_INTF_IF_TYPE_0 0
83#define LPFC_SLI_INTF_IF_TYPE_1 1
78}; 84};
79 85
80#define LPFC_SLI4_BAR0 1
81#define LPFC_SLI4_BAR1 2
82#define LPFC_SLI4_BAR2 4
83
84#define LPFC_SLI4_MBX_EMBED true 86#define LPFC_SLI4_MBX_EMBED true
85#define LPFC_SLI4_MBX_NEMBED false 87#define LPFC_SLI4_MBX_NEMBED false
86 88
@@ -161,6 +163,9 @@ struct lpfc_sli_intf {
161#define LPFC_FP_DEF_IMAX 10000 163#define LPFC_FP_DEF_IMAX 10000
162#define LPFC_SP_DEF_IMAX 10000 164#define LPFC_SP_DEF_IMAX 10000
163 165
166/* PORT_CAPABILITIES constants. */
167#define LPFC_MAX_SUPPORTED_PAGES 8
168
164struct ulp_bde64 { 169struct ulp_bde64 {
165 union ULP_BDE_TUS { 170 union ULP_BDE_TUS {
166 uint32_t w; 171 uint32_t w;
@@ -516,7 +521,7 @@ struct lpfc_register {
516#define LPFC_UERR_STATUS_LO 0x00A0 521#define LPFC_UERR_STATUS_LO 0x00A0
517#define LPFC_UE_MASK_HI 0x00AC 522#define LPFC_UE_MASK_HI 0x00AC
518#define LPFC_UE_MASK_LO 0x00A8 523#define LPFC_UE_MASK_LO 0x00A8
519#define LPFC_SCRATCHPAD 0x0058 524#define LPFC_SLI_INTF 0x0058
520 525
521/* BAR0 Registers */ 526/* BAR0 Registers */
522#define LPFC_HST_STATE 0x00AC 527#define LPFC_HST_STATE 0x00AC
@@ -576,19 +581,6 @@ struct lpfc_register {
576#define LPFC_POST_STAGE_ARMFW_READY 0xC000 581#define LPFC_POST_STAGE_ARMFW_READY 0xC000
577#define LPFC_POST_STAGE_ARMFW_UE 0xF000 582#define LPFC_POST_STAGE_ARMFW_UE 0xF000
578 583
579#define lpfc_scratchpad_slirev_SHIFT 4
580#define lpfc_scratchpad_slirev_MASK 0xF
581#define lpfc_scratchpad_slirev_WORD word0
582#define lpfc_scratchpad_chiptype_SHIFT 8
583#define lpfc_scratchpad_chiptype_MASK 0xFF
584#define lpfc_scratchpad_chiptype_WORD word0
585#define lpfc_scratchpad_featurelevel1_SHIFT 16
586#define lpfc_scratchpad_featurelevel1_MASK 0xFF
587#define lpfc_scratchpad_featurelevel1_WORD word0
588#define lpfc_scratchpad_featurelevel2_SHIFT 24
589#define lpfc_scratchpad_featurelevel2_MASK 0xFF
590#define lpfc_scratchpad_featurelevel2_WORD word0
591
592/* BAR1 Registers */ 584/* BAR1 Registers */
593#define LPFC_IMR_MASK_ALL 0xFFFFFFFF 585#define LPFC_IMR_MASK_ALL 0xFFFFFFFF
594#define LPFC_ISCR_CLEAR_ALL 0xFFFFFFFF 586#define LPFC_ISCR_CLEAR_ALL 0xFFFFFFFF
@@ -801,6 +793,7 @@ struct mbox_header {
801#define LPFC_MBOX_OPCODE_FCOE_ADD_FCF 0x09 793#define LPFC_MBOX_OPCODE_FCOE_ADD_FCF 0x09
802#define LPFC_MBOX_OPCODE_FCOE_DELETE_FCF 0x0A 794#define LPFC_MBOX_OPCODE_FCOE_DELETE_FCF 0x0A
803#define LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE 0x0B 795#define LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE 0x0B
796#define LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF 0x10
804 797
805/* Mailbox command structures */ 798/* Mailbox command structures */
806struct eq_context { 799struct eq_context {
@@ -1149,10 +1142,7 @@ struct sli4_sge { /* SLI-4 */
1149 this flag !! */ 1142 this flag !! */
1150#define lpfc_sli4_sge_last_MASK 0x00000001 1143#define lpfc_sli4_sge_last_MASK 0x00000001
1151#define lpfc_sli4_sge_last_WORD word2 1144#define lpfc_sli4_sge_last_WORD word2
1152 uint32_t word3; 1145 uint32_t sge_len;
1153#define lpfc_sli4_sge_len_SHIFT 0
1154#define lpfc_sli4_sge_len_MASK 0x0001FFFF
1155#define lpfc_sli4_sge_len_WORD word3
1156}; 1146};
1157 1147
1158struct fcf_record { 1148struct fcf_record {
@@ -1301,6 +1291,19 @@ struct lpfc_mbx_del_fcf_tbl_entry {
1301#define lpfc_mbx_del_fcf_tbl_index_WORD word10 1291#define lpfc_mbx_del_fcf_tbl_index_WORD word10
1302}; 1292};
1303 1293
1294struct lpfc_mbx_redisc_fcf_tbl {
1295 struct mbox_header header;
1296 uint32_t word10;
1297#define lpfc_mbx_redisc_fcf_count_SHIFT 0
1298#define lpfc_mbx_redisc_fcf_count_MASK 0x0000FFFF
1299#define lpfc_mbx_redisc_fcf_count_WORD word10
1300 uint32_t resvd;
1301 uint32_t word12;
1302#define lpfc_mbx_redisc_fcf_index_SHIFT 0
1303#define lpfc_mbx_redisc_fcf_index_MASK 0x0000FFFF
1304#define lpfc_mbx_redisc_fcf_index_WORD word12
1305};
1306
1304struct lpfc_mbx_query_fw_cfg { 1307struct lpfc_mbx_query_fw_cfg {
1305 struct mbox_header header; 1308 struct mbox_header header;
1306 uint32_t config_number; 1309 uint32_t config_number;
@@ -1834,6 +1837,177 @@ struct lpfc_mbx_request_features {
1834#define lpfc_mbx_rq_ftr_rsp_ifip_WORD word3 1837#define lpfc_mbx_rq_ftr_rsp_ifip_WORD word3
1835}; 1838};
1836 1839
1840struct lpfc_mbx_supp_pages {
1841 uint32_t word1;
1842#define qs_SHIFT 0
1843#define qs_MASK 0x00000001
1844#define qs_WORD word1
1845#define wr_SHIFT 1
1846#define wr_MASK 0x00000001
1847#define wr_WORD word1
1848#define pf_SHIFT 8
1849#define pf_MASK 0x000000ff
1850#define pf_WORD word1
1851#define cpn_SHIFT 16
1852#define cpn_MASK 0x000000ff
1853#define cpn_WORD word1
1854 uint32_t word2;
1855#define list_offset_SHIFT 0
1856#define list_offset_MASK 0x000000ff
1857#define list_offset_WORD word2
1858#define next_offset_SHIFT 8
1859#define next_offset_MASK 0x000000ff
1860#define next_offset_WORD word2
1861#define elem_cnt_SHIFT 16
1862#define elem_cnt_MASK 0x000000ff
1863#define elem_cnt_WORD word2
1864 uint32_t word3;
1865#define pn_0_SHIFT 24
1866#define pn_0_MASK 0x000000ff
1867#define pn_0_WORD word3
1868#define pn_1_SHIFT 16
1869#define pn_1_MASK 0x000000ff
1870#define pn_1_WORD word3
1871#define pn_2_SHIFT 8
1872#define pn_2_MASK 0x000000ff
1873#define pn_2_WORD word3
1874#define pn_3_SHIFT 0
1875#define pn_3_MASK 0x000000ff
1876#define pn_3_WORD word3
1877 uint32_t word4;
1878#define pn_4_SHIFT 24
1879#define pn_4_MASK 0x000000ff
1880#define pn_4_WORD word4
1881#define pn_5_SHIFT 16
1882#define pn_5_MASK 0x000000ff
1883#define pn_5_WORD word4
1884#define pn_6_SHIFT 8
1885#define pn_6_MASK 0x000000ff
1886#define pn_6_WORD word4
1887#define pn_7_SHIFT 0
1888#define pn_7_MASK 0x000000ff
1889#define pn_7_WORD word4
1890 uint32_t rsvd[27];
1891#define LPFC_SUPP_PAGES 0
1892#define LPFC_BLOCK_GUARD_PROFILES 1
1893#define LPFC_SLI4_PARAMETERS 2
1894};
1895
1896struct lpfc_mbx_sli4_params {
1897 uint32_t word1;
1898#define qs_SHIFT 0
1899#define qs_MASK 0x00000001
1900#define qs_WORD word1
1901#define wr_SHIFT 1
1902#define wr_MASK 0x00000001
1903#define wr_WORD word1
1904#define pf_SHIFT 8
1905#define pf_MASK 0x000000ff
1906#define pf_WORD word1
1907#define cpn_SHIFT 16
1908#define cpn_MASK 0x000000ff
1909#define cpn_WORD word1
1910 uint32_t word2;
1911#define if_type_SHIFT 0
1912#define if_type_MASK 0x00000007
1913#define if_type_WORD word2
1914#define sli_rev_SHIFT 4
1915#define sli_rev_MASK 0x0000000f
1916#define sli_rev_WORD word2
1917#define sli_family_SHIFT 8
1918#define sli_family_MASK 0x000000ff
1919#define sli_family_WORD word2
1920#define featurelevel_1_SHIFT 16
1921#define featurelevel_1_MASK 0x000000ff
1922#define featurelevel_1_WORD word2
1923#define featurelevel_2_SHIFT 24
1924#define featurelevel_2_MASK 0x0000001f
1925#define featurelevel_2_WORD word2
1926 uint32_t word3;
1927#define fcoe_SHIFT 0
1928#define fcoe_MASK 0x00000001
1929#define fcoe_WORD word3
1930#define fc_SHIFT 1
1931#define fc_MASK 0x00000001
1932#define fc_WORD word3
1933#define nic_SHIFT 2
1934#define nic_MASK 0x00000001
1935#define nic_WORD word3
1936#define iscsi_SHIFT 3
1937#define iscsi_MASK 0x00000001
1938#define iscsi_WORD word3
1939#define rdma_SHIFT 4
1940#define rdma_MASK 0x00000001
1941#define rdma_WORD word3
1942 uint32_t sge_supp_len;
1943 uint32_t word5;
1944#define if_page_sz_SHIFT 0
1945#define if_page_sz_MASK 0x0000ffff
1946#define if_page_sz_WORD word5
1947#define loopbk_scope_SHIFT 24
1948#define loopbk_scope_MASK 0x0000000f
1949#define loopbk_scope_WORD word5
1950#define rq_db_window_SHIFT 28
1951#define rq_db_window_MASK 0x0000000f
1952#define rq_db_window_WORD word5
1953 uint32_t word6;
1954#define eq_pages_SHIFT 0
1955#define eq_pages_MASK 0x0000000f
1956#define eq_pages_WORD word6
1957#define eqe_size_SHIFT 8
1958#define eqe_size_MASK 0x000000ff
1959#define eqe_size_WORD word6
1960 uint32_t word7;
1961#define cq_pages_SHIFT 0
1962#define cq_pages_MASK 0x0000000f
1963#define cq_pages_WORD word7
1964#define cqe_size_SHIFT 8
1965#define cqe_size_MASK 0x000000ff
1966#define cqe_size_WORD word7
1967 uint32_t word8;
1968#define mq_pages_SHIFT 0
1969#define mq_pages_MASK 0x0000000f
1970#define mq_pages_WORD word8
1971#define mqe_size_SHIFT 8
1972#define mqe_size_MASK 0x000000ff
1973#define mqe_size_WORD word8
1974#define mq_elem_cnt_SHIFT 16
1975#define mq_elem_cnt_MASK 0x000000ff
1976#define mq_elem_cnt_WORD word8
1977 uint32_t word9;
1978#define wq_pages_SHIFT 0
1979#define wq_pages_MASK 0x0000ffff
1980#define wq_pages_WORD word9
1981#define wqe_size_SHIFT 8
1982#define wqe_size_MASK 0x000000ff
1983#define wqe_size_WORD word9
1984 uint32_t word10;
1985#define rq_pages_SHIFT 0
1986#define rq_pages_MASK 0x0000ffff
1987#define rq_pages_WORD word10
1988#define rqe_size_SHIFT 8
1989#define rqe_size_MASK 0x000000ff
1990#define rqe_size_WORD word10
1991 uint32_t word11;
1992#define hdr_pages_SHIFT 0
1993#define hdr_pages_MASK 0x0000000f
1994#define hdr_pages_WORD word11
1995#define hdr_size_SHIFT 8
1996#define hdr_size_MASK 0x0000000f
1997#define hdr_size_WORD word11
1998#define hdr_pp_align_SHIFT 16
1999#define hdr_pp_align_MASK 0x0000ffff
2000#define hdr_pp_align_WORD word11
2001 uint32_t word12;
2002#define sgl_pages_SHIFT 0
2003#define sgl_pages_MASK 0x0000000f
2004#define sgl_pages_WORD word12
2005#define sgl_pp_align_SHIFT 16
2006#define sgl_pp_align_MASK 0x0000ffff
2007#define sgl_pp_align_WORD word12
2008 uint32_t rsvd_13_63[51];
2009};
2010
1837/* Mailbox Completion Queue Error Messages */ 2011/* Mailbox Completion Queue Error Messages */
1838#define MB_CQE_STATUS_SUCCESS 0x0 2012#define MB_CQE_STATUS_SUCCESS 0x0
1839#define MB_CQE_STATUS_INSUFFICIENT_PRIVILEGES 0x1 2013#define MB_CQE_STATUS_INSUFFICIENT_PRIVILEGES 0x1
@@ -1863,6 +2037,7 @@ struct lpfc_mqe {
1863 struct lpfc_mbx_read_fcf_tbl read_fcf_tbl; 2037 struct lpfc_mbx_read_fcf_tbl read_fcf_tbl;
1864 struct lpfc_mbx_add_fcf_tbl_entry add_fcf_entry; 2038 struct lpfc_mbx_add_fcf_tbl_entry add_fcf_entry;
1865 struct lpfc_mbx_del_fcf_tbl_entry del_fcf_entry; 2039 struct lpfc_mbx_del_fcf_tbl_entry del_fcf_entry;
2040 struct lpfc_mbx_redisc_fcf_tbl redisc_fcf_tbl;
1866 struct lpfc_mbx_reg_fcfi reg_fcfi; 2041 struct lpfc_mbx_reg_fcfi reg_fcfi;
1867 struct lpfc_mbx_unreg_fcfi unreg_fcfi; 2042 struct lpfc_mbx_unreg_fcfi unreg_fcfi;
1868 struct lpfc_mbx_mq_create mq_create; 2043 struct lpfc_mbx_mq_create mq_create;
@@ -1883,6 +2058,8 @@ struct lpfc_mqe {
1883 struct lpfc_mbx_request_features req_ftrs; 2058 struct lpfc_mbx_request_features req_ftrs;
1884 struct lpfc_mbx_post_hdr_tmpl hdr_tmpl; 2059 struct lpfc_mbx_post_hdr_tmpl hdr_tmpl;
1885 struct lpfc_mbx_query_fw_cfg query_fw_cfg; 2060 struct lpfc_mbx_query_fw_cfg query_fw_cfg;
2061 struct lpfc_mbx_supp_pages supp_pages;
2062 struct lpfc_mbx_sli4_params sli4_params;
1886 struct lpfc_mbx_nop nop; 2063 struct lpfc_mbx_nop nop;
1887 } un; 2064 } un;
1888}; 2065};
@@ -1959,6 +2136,9 @@ struct lpfc_acqe_link {
1959#define LPFC_ASYNC_LINK_FAULT_NONE 0x0 2136#define LPFC_ASYNC_LINK_FAULT_NONE 0x0
1960#define LPFC_ASYNC_LINK_FAULT_LOCAL 0x1 2137#define LPFC_ASYNC_LINK_FAULT_LOCAL 0x1
1961#define LPFC_ASYNC_LINK_FAULT_REMOTE 0x2 2138#define LPFC_ASYNC_LINK_FAULT_REMOTE 0x2
2139#define lpfc_acqe_qos_link_speed_SHIFT 16
2140#define lpfc_acqe_qos_link_speed_MASK 0x0000FFFF
2141#define lpfc_acqe_qos_link_speed_WORD word1
1962 uint32_t event_tag; 2142 uint32_t event_tag;
1963 uint32_t trailer; 2143 uint32_t trailer;
1964}; 2144};
@@ -1976,6 +2156,7 @@ struct lpfc_acqe_fcoe {
1976#define LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL 0x2 2156#define LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL 0x2
1977#define LPFC_FCOE_EVENT_TYPE_FCF_DEAD 0x3 2157#define LPFC_FCOE_EVENT_TYPE_FCF_DEAD 0x3
1978#define LPFC_FCOE_EVENT_TYPE_CVL 0x4 2158#define LPFC_FCOE_EVENT_TYPE_CVL 0x4
2159#define LPFC_FCOE_EVENT_TYPE_FCF_PARAM_MOD 0x5
1979 uint32_t event_tag; 2160 uint32_t event_tag;
1980 uint32_t trailer; 2161 uint32_t trailer;
1981}; 2162};
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index b8eb1b6e5e77..d29ac7c317d9 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -544,7 +544,7 @@ lpfc_config_port_post(struct lpfc_hba *phba)
544 mempool_free(pmb, phba->mbox_mem_pool); 544 mempool_free(pmb, phba->mbox_mem_pool);
545 return -EIO; 545 return -EIO;
546 } 546 }
547 } else { 547 } else if (phba->cfg_suppress_link_up == 0) {
548 lpfc_init_link(phba, pmb, phba->cfg_topology, 548 lpfc_init_link(phba, pmb, phba->cfg_topology,
549 phba->cfg_link_speed); 549 phba->cfg_link_speed);
550 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 550 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
@@ -603,6 +603,102 @@ lpfc_config_port_post(struct lpfc_hba *phba)
603} 603}
604 604
605/** 605/**
606 * lpfc_hba_init_link - Initialize the FC link
607 * @phba: pointer to lpfc hba data structure.
608 *
609 * This routine will issue the INIT_LINK mailbox command call.
610 * It is available to other drivers through the lpfc_hba data
611 * structure for use as a delayed link up mechanism with the
612 * module parameter lpfc_suppress_link_up.
613 *
614 * Return code
615 * 0 - success
616 * Any other value - error
617 **/
618int
619lpfc_hba_init_link(struct lpfc_hba *phba)
620{
621 struct lpfc_vport *vport = phba->pport;
622 LPFC_MBOXQ_t *pmb;
623 MAILBOX_t *mb;
624 int rc;
625
626 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
627 if (!pmb) {
628 phba->link_state = LPFC_HBA_ERROR;
629 return -ENOMEM;
630 }
631 mb = &pmb->u.mb;
632 pmb->vport = vport;
633
634 lpfc_init_link(phba, pmb, phba->cfg_topology,
635 phba->cfg_link_speed);
636 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
637 lpfc_set_loopback_flag(phba);
638 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
639 if (rc != MBX_SUCCESS) {
640 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
641 "0498 Adapter failed to init, mbxCmd x%x "
642 "INIT_LINK, mbxStatus x%x\n",
643 mb->mbxCommand, mb->mbxStatus);
644 /* Clear all interrupt enable conditions */
645 writel(0, phba->HCregaddr);
646 readl(phba->HCregaddr); /* flush */
647 /* Clear all pending interrupts */
648 writel(0xffffffff, phba->HAregaddr);
649 readl(phba->HAregaddr); /* flush */
650 phba->link_state = LPFC_HBA_ERROR;
651 if (rc != MBX_BUSY)
652 mempool_free(pmb, phba->mbox_mem_pool);
653 return -EIO;
654 }
655 phba->cfg_suppress_link_up = 0;
656
657 return 0;
658}
659
660/**
661 * lpfc_hba_down_link - this routine downs the FC link
662 *
663 * This routine will issue the DOWN_LINK mailbox command call.
664 * It is available to other drivers through the lpfc_hba data
665 * structure for use to stop the link.
666 *
667 * Return code
668 * 0 - success
669 * Any other value - error
670 **/
671int
672lpfc_hba_down_link(struct lpfc_hba *phba)
673{
674 LPFC_MBOXQ_t *pmb;
675 int rc;
676
677 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
678 if (!pmb) {
679 phba->link_state = LPFC_HBA_ERROR;
680 return -ENOMEM;
681 }
682
683 lpfc_printf_log(phba,
684 KERN_ERR, LOG_INIT,
685 "0491 Adapter Link is disabled.\n");
686 lpfc_down_link(phba, pmb);
687 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
688 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
689 if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) {
690 lpfc_printf_log(phba,
691 KERN_ERR, LOG_INIT,
692 "2522 Adapter failed to issue DOWN_LINK"
693 " mbox command rc 0x%x\n", rc);
694
695 mempool_free(pmb, phba->mbox_mem_pool);
696 return -EIO;
697 }
698 return 0;
699}
700
701/**
606 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset 702 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
607 * @phba: pointer to lpfc HBA data structure. 703 * @phba: pointer to lpfc HBA data structure.
608 * 704 *
@@ -2073,6 +2169,44 @@ lpfc_stop_vport_timers(struct lpfc_vport *vport)
2073} 2169}
2074 2170
2075/** 2171/**
2172 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2173 * @phba: pointer to lpfc hba data structure.
2174 *
2175 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2176 * caller of this routine should already hold the host lock.
2177 **/
2178void
2179__lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2180{
2181 /* Clear pending FCF rediscovery wait timer */
2182 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2183 /* Now, try to stop the timer */
2184 del_timer(&phba->fcf.redisc_wait);
2185}
2186
2187/**
2188 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2189 * @phba: pointer to lpfc hba data structure.
2190 *
2191 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2192 * checks whether the FCF rediscovery wait timer is pending with the host
2193 * lock held before proceeding with disabling the timer and clearing the
2194 * wait timer pendig flag.
2195 **/
2196void
2197lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba)
2198{
2199 spin_lock_irq(&phba->hbalock);
2200 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2201 /* FCF rediscovery timer already fired or stopped */
2202 spin_unlock_irq(&phba->hbalock);
2203 return;
2204 }
2205 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2206 spin_unlock_irq(&phba->hbalock);
2207}
2208
2209/**
2076 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA 2210 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2077 * @phba: pointer to lpfc hba data structure. 2211 * @phba: pointer to lpfc hba data structure.
2078 * 2212 *
@@ -2096,6 +2230,7 @@ lpfc_stop_hba_timers(struct lpfc_hba *phba)
2096 break; 2230 break;
2097 case LPFC_PCI_DEV_OC: 2231 case LPFC_PCI_DEV_OC:
2098 /* Stop any OneConnect device sepcific driver timers */ 2232 /* Stop any OneConnect device sepcific driver timers */
2233 lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
2099 break; 2234 break;
2100 default: 2235 default:
2101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
@@ -2228,6 +2363,7 @@ lpfc_offline_prep(struct lpfc_hba * phba)
2228 struct lpfc_vport *vport = phba->pport; 2363 struct lpfc_vport *vport = phba->pport;
2229 struct lpfc_nodelist *ndlp, *next_ndlp; 2364 struct lpfc_nodelist *ndlp, *next_ndlp;
2230 struct lpfc_vport **vports; 2365 struct lpfc_vport **vports;
2366 struct Scsi_Host *shost;
2231 int i; 2367 int i;
2232 2368
2233 if (vport->fc_flag & FC_OFFLINE_MODE) 2369 if (vport->fc_flag & FC_OFFLINE_MODE)
@@ -2241,11 +2377,15 @@ lpfc_offline_prep(struct lpfc_hba * phba)
2241 vports = lpfc_create_vport_work_array(phba); 2377 vports = lpfc_create_vport_work_array(phba);
2242 if (vports != NULL) { 2378 if (vports != NULL) {
2243 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { 2379 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2244 struct Scsi_Host *shost;
2245
2246 if (vports[i]->load_flag & FC_UNLOADING) 2380 if (vports[i]->load_flag & FC_UNLOADING)
2247 continue; 2381 continue;
2382 shost = lpfc_shost_from_vport(vports[i]);
2383 spin_lock_irq(shost->host_lock);
2248 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; 2384 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
2385 vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2386 vports[i]->fc_flag &= ~FC_VFI_REGISTERED;
2387 spin_unlock_irq(shost->host_lock);
2388
2249 shost = lpfc_shost_from_vport(vports[i]); 2389 shost = lpfc_shost_from_vport(vports[i]);
2250 list_for_each_entry_safe(ndlp, next_ndlp, 2390 list_for_each_entry_safe(ndlp, next_ndlp,
2251 &vports[i]->fc_nodes, 2391 &vports[i]->fc_nodes,
@@ -2401,7 +2541,8 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
2401 shost->this_id = -1; 2541 shost->this_id = -1;
2402 shost->max_cmd_len = 16; 2542 shost->max_cmd_len = 16;
2403 if (phba->sli_rev == LPFC_SLI_REV4) { 2543 if (phba->sli_rev == LPFC_SLI_REV4) {
2404 shost->dma_boundary = LPFC_SLI4_MAX_SEGMENT_SIZE; 2544 shost->dma_boundary =
2545 phba->sli4_hba.pc_sli4_params.sge_supp_len;
2405 shost->sg_tablesize = phba->cfg_sg_seg_cnt; 2546 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
2406 } 2547 }
2407 2548
@@ -2650,8 +2791,6 @@ lpfc_stop_port_s4(struct lpfc_hba *phba)
2650 lpfc_stop_hba_timers(phba); 2791 lpfc_stop_hba_timers(phba);
2651 phba->pport->work_port_events = 0; 2792 phba->pport->work_port_events = 0;
2652 phba->sli4_hba.intr_enable = 0; 2793 phba->sli4_hba.intr_enable = 0;
2653 /* Hard clear it for now, shall have more graceful way to wait later */
2654 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2655} 2794}
2656 2795
2657/** 2796/**
@@ -2703,7 +2842,7 @@ lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba)
2703 del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry; 2842 del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry;
2704 bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1); 2843 bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1);
2705 bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record, 2844 bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record,
2706 phba->fcf.fcf_indx); 2845 phba->fcf.current_rec.fcf_indx);
2707 2846
2708 if (!phba->sli4_hba.intr_enable) 2847 if (!phba->sli4_hba.intr_enable)
2709 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); 2848 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
@@ -2727,6 +2866,57 @@ lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba)
2727} 2866}
2728 2867
2729/** 2868/**
2869 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
2870 * @phba: Pointer to hba for which this call is being executed.
2871 *
2872 * This routine starts the timer waiting for the FCF rediscovery to complete.
2873 **/
2874void
2875lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba)
2876{
2877 unsigned long fcf_redisc_wait_tmo =
2878 (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO));
2879 /* Start fcf rediscovery wait period timer */
2880 mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo);
2881 spin_lock_irq(&phba->hbalock);
2882 /* Allow action to new fcf asynchronous event */
2883 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2884 /* Mark the FCF rediscovery pending state */
2885 phba->fcf.fcf_flag |= FCF_REDISC_PEND;
2886 spin_unlock_irq(&phba->hbalock);
2887}
2888
2889/**
2890 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
2891 * @ptr: Map to lpfc_hba data structure pointer.
2892 *
2893 * This routine is invoked when waiting for FCF table rediscover has been
2894 * timed out. If new FCF record(s) has (have) been discovered during the
2895 * wait period, a new FCF event shall be added to the FCOE async event
2896 * list, and then worker thread shall be waked up for processing from the
2897 * worker thread context.
2898 **/
2899void
2900lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr)
2901{
2902 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2903
2904 /* Don't send FCF rediscovery event if timer cancelled */
2905 spin_lock_irq(&phba->hbalock);
2906 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) {
2907 spin_unlock_irq(&phba->hbalock);
2908 return;
2909 }
2910 /* Clear FCF rediscovery timer pending flag */
2911 phba->fcf.fcf_flag &= ~FCF_REDISC_PEND;
2912 /* FCF rediscovery event to worker thread */
2913 phba->fcf.fcf_flag |= FCF_REDISC_EVT;
2914 spin_unlock_irq(&phba->hbalock);
2915 /* wake up worker thread */
2916 lpfc_worker_wake_up(phba);
2917}
2918
2919/**
2730 * lpfc_sli4_fw_cfg_check - Read the firmware config and verify FCoE support 2920 * lpfc_sli4_fw_cfg_check - Read the firmware config and verify FCoE support
2731 * @phba: pointer to lpfc hba data structure. 2921 * @phba: pointer to lpfc hba data structure.
2732 * 2922 *
@@ -2978,6 +3168,8 @@ lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
2978 bf_get(lpfc_acqe_link_physical, acqe_link); 3168 bf_get(lpfc_acqe_link_physical, acqe_link);
2979 phba->sli4_hba.link_state.fault = 3169 phba->sli4_hba.link_state.fault =
2980 bf_get(lpfc_acqe_link_fault, acqe_link); 3170 bf_get(lpfc_acqe_link_fault, acqe_link);
3171 phba->sli4_hba.link_state.logical_speed =
3172 bf_get(lpfc_acqe_qos_link_speed, acqe_link);
2981 3173
2982 /* Invoke the lpfc_handle_latt mailbox command callback function */ 3174 /* Invoke the lpfc_handle_latt mailbox command callback function */
2983 lpfc_mbx_cmpl_read_la(phba, pmb); 3175 lpfc_mbx_cmpl_read_la(phba, pmb);
@@ -3007,22 +3199,34 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3007 struct lpfc_nodelist *ndlp; 3199 struct lpfc_nodelist *ndlp;
3008 struct Scsi_Host *shost; 3200 struct Scsi_Host *shost;
3009 uint32_t link_state; 3201 uint32_t link_state;
3202 int active_vlink_present;
3203 struct lpfc_vport **vports;
3204 int i;
3010 3205
3011 phba->fc_eventTag = acqe_fcoe->event_tag; 3206 phba->fc_eventTag = acqe_fcoe->event_tag;
3012 phba->fcoe_eventtag = acqe_fcoe->event_tag; 3207 phba->fcoe_eventtag = acqe_fcoe->event_tag;
3013 switch (event_type) { 3208 switch (event_type) {
3014 case LPFC_FCOE_EVENT_TYPE_NEW_FCF: 3209 case LPFC_FCOE_EVENT_TYPE_NEW_FCF:
3210 case LPFC_FCOE_EVENT_TYPE_FCF_PARAM_MOD:
3015 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY, 3211 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
3016 "2546 New FCF found index 0x%x tag 0x%x\n", 3212 "2546 New FCF found index 0x%x tag 0x%x\n",
3017 acqe_fcoe->index, 3213 acqe_fcoe->index,
3018 acqe_fcoe->event_tag); 3214 acqe_fcoe->event_tag);
3019 /*
3020 * If the current FCF is in discovered state, or
3021 * FCF discovery is in progress do nothing.
3022 */
3023 spin_lock_irq(&phba->hbalock); 3215 spin_lock_irq(&phba->hbalock);
3024 if ((phba->fcf.fcf_flag & FCF_DISCOVERED) || 3216 if ((phba->fcf.fcf_flag & FCF_SCAN_DONE) ||
3025 (phba->hba_flag & FCF_DISC_INPROGRESS)) { 3217 (phba->hba_flag & FCF_DISC_INPROGRESS)) {
3218 /*
3219 * If the current FCF is in discovered state or
3220 * FCF discovery is in progress, do nothing.
3221 */
3222 spin_unlock_irq(&phba->hbalock);
3223 break;
3224 }
3225 if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
3226 /*
3227 * If fast FCF failover rescan event is pending,
3228 * do nothing.
3229 */
3026 spin_unlock_irq(&phba->hbalock); 3230 spin_unlock_irq(&phba->hbalock);
3027 break; 3231 break;
3028 } 3232 }
@@ -3049,7 +3253,7 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3049 " tag 0x%x\n", acqe_fcoe->index, 3253 " tag 0x%x\n", acqe_fcoe->index,
3050 acqe_fcoe->event_tag); 3254 acqe_fcoe->event_tag);
3051 /* If the event is not for currently used fcf do nothing */ 3255 /* If the event is not for currently used fcf do nothing */
3052 if (phba->fcf.fcf_indx != acqe_fcoe->index) 3256 if (phba->fcf.current_rec.fcf_indx != acqe_fcoe->index)
3053 break; 3257 break;
3054 /* 3258 /*
3055 * Currently, driver support only one FCF - so treat this as 3259 * Currently, driver support only one FCF - so treat this as
@@ -3074,14 +3278,58 @@ lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
3074 if (!ndlp) 3278 if (!ndlp)
3075 break; 3279 break;
3076 shost = lpfc_shost_from_vport(vport); 3280 shost = lpfc_shost_from_vport(vport);
3281 if (phba->pport->port_state <= LPFC_FLOGI)
3282 break;
3283 /* If virtual link is not yet instantiated ignore CVL */
3284 if (vport->port_state <= LPFC_FDISC)
3285 break;
3286
3077 lpfc_linkdown_port(vport); 3287 lpfc_linkdown_port(vport);
3078 if (vport->port_type != LPFC_NPIV_PORT) { 3288 lpfc_cleanup_pending_mbox(vport);
3289 spin_lock_irq(shost->host_lock);
3290 vport->fc_flag |= FC_VPORT_CVL_RCVD;
3291 spin_unlock_irq(shost->host_lock);
3292 active_vlink_present = 0;
3293
3294 vports = lpfc_create_vport_work_array(phba);
3295 if (vports) {
3296 for (i = 0; i <= phba->max_vports && vports[i] != NULL;
3297 i++) {
3298 if ((!(vports[i]->fc_flag &
3299 FC_VPORT_CVL_RCVD)) &&
3300 (vports[i]->port_state > LPFC_FDISC)) {
3301 active_vlink_present = 1;
3302 break;
3303 }
3304 }
3305 lpfc_destroy_vport_work_array(phba, vports);
3306 }
3307
3308 if (active_vlink_present) {
3309 /*
3310 * If there are other active VLinks present,
3311 * re-instantiate the Vlink using FDISC.
3312 */
3079 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); 3313 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
3080 spin_lock_irq(shost->host_lock); 3314 spin_lock_irq(shost->host_lock);
3081 ndlp->nlp_flag |= NLP_DELAY_TMO; 3315 ndlp->nlp_flag |= NLP_DELAY_TMO;
3082 spin_unlock_irq(shost->host_lock); 3316 spin_unlock_irq(shost->host_lock);
3083 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI; 3317 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
3084 vport->port_state = LPFC_FLOGI; 3318 vport->port_state = LPFC_FDISC;
3319 } else {
3320 /*
3321 * Otherwise, we request port to rediscover
3322 * the entire FCF table for a fast recovery
3323 * from possible case that the current FCF
3324 * is no longer valid.
3325 */
3326 rc = lpfc_sli4_redisc_fcf_table(phba);
3327 if (rc)
3328 /*
3329 * Last resort will be re-try on the
3330 * the current registered FCF entry.
3331 */
3332 lpfc_retry_pport_discovery(phba);
3085 } 3333 }
3086 break; 3334 break;
3087 default: 3335 default:
@@ -3158,6 +3406,34 @@ void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
3158} 3406}
3159 3407
3160/** 3408/**
3409 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
3410 * @phba: pointer to lpfc hba data structure.
3411 *
3412 * This routine is invoked by the worker thread to process FCF table
3413 * rediscovery pending completion event.
3414 **/
3415void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba)
3416{
3417 int rc;
3418
3419 spin_lock_irq(&phba->hbalock);
3420 /* Clear FCF rediscovery timeout event */
3421 phba->fcf.fcf_flag &= ~FCF_REDISC_EVT;
3422 /* Clear driver fast failover FCF record flag */
3423 phba->fcf.failover_rec.flag = 0;
3424 /* Set state for FCF fast failover */
3425 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
3426 spin_unlock_irq(&phba->hbalock);
3427
3428 /* Scan FCF table from the first entry to re-discover SAN */
3429 rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
3430 if (rc)
3431 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
3432 "2747 Post FCF rediscovery read FCF record "
3433 "failed 0x%x\n", rc);
3434}
3435
3436/**
3161 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table 3437 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
3162 * @phba: pointer to lpfc hba data structure. 3438 * @phba: pointer to lpfc hba data structure.
3163 * @dev_grp: The HBA PCI-Device group number. 3439 * @dev_grp: The HBA PCI-Device group number.
@@ -3442,8 +3718,10 @@ static int
3442lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) 3718lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
3443{ 3719{
3444 struct lpfc_sli *psli; 3720 struct lpfc_sli *psli;
3445 int rc; 3721 LPFC_MBOXQ_t *mboxq;
3446 int i, hbq_count; 3722 int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size;
3723 uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0};
3724 struct lpfc_mqe *mqe;
3447 3725
3448 /* Before proceed, wait for POST done and device ready */ 3726 /* Before proceed, wait for POST done and device ready */
3449 rc = lpfc_sli4_post_status_check(phba); 3727 rc = lpfc_sli4_post_status_check(phba);
@@ -3472,6 +3750,11 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
3472 init_timer(&phba->eratt_poll); 3750 init_timer(&phba->eratt_poll);
3473 phba->eratt_poll.function = lpfc_poll_eratt; 3751 phba->eratt_poll.function = lpfc_poll_eratt;
3474 phba->eratt_poll.data = (unsigned long) phba; 3752 phba->eratt_poll.data = (unsigned long) phba;
3753 /* FCF rediscover timer */
3754 init_timer(&phba->fcf.redisc_wait);
3755 phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo;
3756 phba->fcf.redisc_wait.data = (unsigned long)phba;
3757
3475 /* 3758 /*
3476 * We need to do a READ_CONFIG mailbox command here before 3759 * We need to do a READ_CONFIG mailbox command here before
3477 * calling lpfc_get_cfgparam. For VFs this will report the 3760 * calling lpfc_get_cfgparam. For VFs this will report the
@@ -3496,31 +3779,26 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
3496 * used to create the sg_dma_buf_pool must be dynamically calculated. 3779 * used to create the sg_dma_buf_pool must be dynamically calculated.
3497 * 2 segments are added since the IOCB needs a command and response bde. 3780 * 2 segments are added since the IOCB needs a command and response bde.
3498 * To insure that the scsi sgl does not cross a 4k page boundary only 3781 * To insure that the scsi sgl does not cross a 4k page boundary only
3499 * sgl sizes of 1k, 2k, 4k, and 8k are supported. 3782 * sgl sizes of must be a power of 2.
3500 * Table of sgl sizes and seg_cnt:
3501 * sgl size, sg_seg_cnt total seg
3502 * 1k 50 52
3503 * 2k 114 116
3504 * 4k 242 244
3505 * 8k 498 500
3506 * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024
3507 * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048
3508 * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096
3509 * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192
3510 */ 3783 */
3511 if (phba->cfg_sg_seg_cnt <= LPFC_DEFAULT_SG_SEG_CNT) 3784 buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) +
3512 phba->cfg_sg_seg_cnt = 50; 3785 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)));
3513 else if (phba->cfg_sg_seg_cnt <= 114) 3786 /* Feature Level 1 hardware is limited to 2 pages */
3514 phba->cfg_sg_seg_cnt = 114; 3787 if ((bf_get(lpfc_sli_intf_featurelevel1, &phba->sli4_hba.sli_intf) ==
3515 else if (phba->cfg_sg_seg_cnt <= 242) 3788 LPFC_SLI_INTF_FEATURELEVEL1_1))
3516 phba->cfg_sg_seg_cnt = 242; 3789 max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE;
3517 else 3790 else
3518 phba->cfg_sg_seg_cnt = 498; 3791 max_buf_size = LPFC_SLI4_MAX_BUF_SIZE;
3519 3792 for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE;
3520 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) 3793 dma_buf_size < max_buf_size && buf_size > dma_buf_size;
3521 + sizeof(struct fcp_rsp); 3794 dma_buf_size = dma_buf_size << 1)
3522 phba->cfg_sg_dma_buf_size += 3795 ;
3523 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)); 3796 if (dma_buf_size == max_buf_size)
3797 phba->cfg_sg_seg_cnt = (dma_buf_size -
3798 sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) -
3799 (2 * sizeof(struct sli4_sge))) /
3800 sizeof(struct sli4_sge);
3801 phba->cfg_sg_dma_buf_size = dma_buf_size;
3524 3802
3525 /* Initialize buffer queue management fields */ 3803 /* Initialize buffer queue management fields */
3526 hbq_count = lpfc_sli_hbq_count(); 3804 hbq_count = lpfc_sli_hbq_count();
@@ -3638,6 +3916,43 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
3638 goto out_free_fcp_eq_hdl; 3916 goto out_free_fcp_eq_hdl;
3639 } 3917 }
3640 3918
3919 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
3920 GFP_KERNEL);
3921 if (!mboxq) {
3922 rc = -ENOMEM;
3923 goto out_free_fcp_eq_hdl;
3924 }
3925
3926 /* Get the Supported Pages. It is always available. */
3927 lpfc_supported_pages(mboxq);
3928 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
3929 if (unlikely(rc)) {
3930 rc = -EIO;
3931 mempool_free(mboxq, phba->mbox_mem_pool);
3932 goto out_free_fcp_eq_hdl;
3933 }
3934
3935 mqe = &mboxq->u.mqe;
3936 memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3),
3937 LPFC_MAX_SUPPORTED_PAGES);
3938 for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) {
3939 switch (pn_page[i]) {
3940 case LPFC_SLI4_PARAMETERS:
3941 phba->sli4_hba.pc_sli4_params.supported = 1;
3942 break;
3943 default:
3944 break;
3945 }
3946 }
3947
3948 /* Read the port's SLI4 Parameters capabilities if supported. */
3949 if (phba->sli4_hba.pc_sli4_params.supported)
3950 rc = lpfc_pc_sli4_params_get(phba, mboxq);
3951 mempool_free(mboxq, phba->mbox_mem_pool);
3952 if (rc) {
3953 rc = -EIO;
3954 goto out_free_fcp_eq_hdl;
3955 }
3641 return rc; 3956 return rc;
3642 3957
3643out_free_fcp_eq_hdl: 3958out_free_fcp_eq_hdl:
@@ -3733,6 +4048,8 @@ lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
3733int 4048int
3734lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) 4049lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
3735{ 4050{
4051 phba->lpfc_hba_init_link = lpfc_hba_init_link;
4052 phba->lpfc_hba_down_link = lpfc_hba_down_link;
3736 switch (dev_grp) { 4053 switch (dev_grp) {
3737 case LPFC_PCI_DEV_LP: 4054 case LPFC_PCI_DEV_LP:
3738 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; 4055 phba->lpfc_hba_down_post = lpfc_hba_down_post_s3;
@@ -4291,7 +4608,7 @@ lpfc_hba_alloc(struct pci_dev *pdev)
4291 return NULL; 4608 return NULL;
4292 } 4609 }
4293 4610
4294 mutex_init(&phba->ct_event_mutex); 4611 spin_lock_init(&phba->ct_ev_lock);
4295 INIT_LIST_HEAD(&phba->ct_ev_waiters); 4612 INIT_LIST_HEAD(&phba->ct_ev_waiters);
4296 4613
4297 return phba; 4614 return phba;
@@ -4641,7 +4958,7 @@ lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
4641int 4958int
4642lpfc_sli4_post_status_check(struct lpfc_hba *phba) 4959lpfc_sli4_post_status_check(struct lpfc_hba *phba)
4643{ 4960{
4644 struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg, scratchpad; 4961 struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg;
4645 int i, port_error = -ENODEV; 4962 int i, port_error = -ENODEV;
4646 4963
4647 if (!phba->sli4_hba.STAregaddr) 4964 if (!phba->sli4_hba.STAregaddr)
@@ -4677,14 +4994,21 @@ lpfc_sli4_post_status_check(struct lpfc_hba *phba)
4677 bf_get(lpfc_hst_state_port_status, &sta_reg)); 4994 bf_get(lpfc_hst_state_port_status, &sta_reg));
4678 4995
4679 /* Log device information */ 4996 /* Log device information */
4680 scratchpad.word0 = readl(phba->sli4_hba.SCRATCHPADregaddr); 4997 phba->sli4_hba.sli_intf.word0 = readl(phba->sli4_hba.SLIINTFregaddr);
4681 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 4998 if (bf_get(lpfc_sli_intf_valid,
4682 "2534 Device Info: ChipType=0x%x, SliRev=0x%x, " 4999 &phba->sli4_hba.sli_intf) == LPFC_SLI_INTF_VALID) {
4683 "FeatureL1=0x%x, FeatureL2=0x%x\n", 5000 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4684 bf_get(lpfc_scratchpad_chiptype, &scratchpad), 5001 "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
4685 bf_get(lpfc_scratchpad_slirev, &scratchpad), 5002 "FeatureL1=0x%x, FeatureL2=0x%x\n",
4686 bf_get(lpfc_scratchpad_featurelevel1, &scratchpad), 5003 bf_get(lpfc_sli_intf_sli_family,
4687 bf_get(lpfc_scratchpad_featurelevel2, &scratchpad)); 5004 &phba->sli4_hba.sli_intf),
5005 bf_get(lpfc_sli_intf_slirev,
5006 &phba->sli4_hba.sli_intf),
5007 bf_get(lpfc_sli_intf_featurelevel1,
5008 &phba->sli4_hba.sli_intf),
5009 bf_get(lpfc_sli_intf_featurelevel2,
5010 &phba->sli4_hba.sli_intf));
5011 }
4688 phba->sli4_hba.ue_mask_lo = readl(phba->sli4_hba.UEMASKLOregaddr); 5012 phba->sli4_hba.ue_mask_lo = readl(phba->sli4_hba.UEMASKLOregaddr);
4689 phba->sli4_hba.ue_mask_hi = readl(phba->sli4_hba.UEMASKHIregaddr); 5013 phba->sli4_hba.ue_mask_hi = readl(phba->sli4_hba.UEMASKHIregaddr);
4690 /* With uncoverable error, log the error message and return error */ 5014 /* With uncoverable error, log the error message and return error */
@@ -4723,8 +5047,8 @@ lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba)
4723 LPFC_UE_MASK_LO; 5047 LPFC_UE_MASK_LO;
4724 phba->sli4_hba.UEMASKHIregaddr = phba->sli4_hba.conf_regs_memmap_p + 5048 phba->sli4_hba.UEMASKHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
4725 LPFC_UE_MASK_HI; 5049 LPFC_UE_MASK_HI;
4726 phba->sli4_hba.SCRATCHPADregaddr = phba->sli4_hba.conf_regs_memmap_p + 5050 phba->sli4_hba.SLIINTFregaddr = phba->sli4_hba.conf_regs_memmap_p +
4727 LPFC_SCRATCHPAD; 5051 LPFC_SLI_INTF;
4728} 5052}
4729 5053
4730/** 5054/**
@@ -5999,7 +6323,7 @@ lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi)
5999 spin_lock_irqsave(&phba->hbalock, flags); 6323 spin_lock_irqsave(&phba->hbalock, flags);
6000 /* Mark the FCFI is no longer registered */ 6324 /* Mark the FCFI is no longer registered */
6001 phba->fcf.fcf_flag &= 6325 phba->fcf.fcf_flag &=
6002 ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_DISCOVERED); 6326 ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_SCAN_DONE);
6003 spin_unlock_irqrestore(&phba->hbalock, flags); 6327 spin_unlock_irqrestore(&phba->hbalock, flags);
6004 } 6328 }
6005} 6329}
@@ -6039,16 +6363,20 @@ lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
6039 6363
6040 /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the 6364 /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
6041 * number of bytes required by each mapping. They are actually 6365 * number of bytes required by each mapping. They are actually
6042 * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device. 6366 * mapping to the PCI BAR regions 0 or 1, 2, and 4 by the SLI4 device.
6043 */ 6367 */
6044 phba->pci_bar0_map = pci_resource_start(pdev, LPFC_SLI4_BAR0); 6368 if (pci_resource_start(pdev, 0)) {
6045 bar0map_len = pci_resource_len(pdev, LPFC_SLI4_BAR0); 6369 phba->pci_bar0_map = pci_resource_start(pdev, 0);
6046 6370 bar0map_len = pci_resource_len(pdev, 0);
6047 phba->pci_bar1_map = pci_resource_start(pdev, LPFC_SLI4_BAR1); 6371 } else {
6048 bar1map_len = pci_resource_len(pdev, LPFC_SLI4_BAR1); 6372 phba->pci_bar0_map = pci_resource_start(pdev, 1);
6373 bar0map_len = pci_resource_len(pdev, 1);
6374 }
6375 phba->pci_bar1_map = pci_resource_start(pdev, 2);
6376 bar1map_len = pci_resource_len(pdev, 2);
6049 6377
6050 phba->pci_bar2_map = pci_resource_start(pdev, LPFC_SLI4_BAR2); 6378 phba->pci_bar2_map = pci_resource_start(pdev, 4);
6051 bar2map_len = pci_resource_len(pdev, LPFC_SLI4_BAR2); 6379 bar2map_len = pci_resource_len(pdev, 4);
6052 6380
6053 /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */ 6381 /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
6054 phba->sli4_hba.conf_regs_memmap_p = 6382 phba->sli4_hba.conf_regs_memmap_p =
@@ -6793,6 +7121,73 @@ lpfc_sli4_hba_unset(struct lpfc_hba *phba)
6793 phba->pport->work_port_events = 0; 7121 phba->pport->work_port_events = 0;
6794} 7122}
6795 7123
7124 /**
7125 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
7126 * @phba: Pointer to HBA context object.
7127 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
7128 *
7129 * This function is called in the SLI4 code path to read the port's
7130 * sli4 capabilities.
7131 *
7132 * This function may be be called from any context that can block-wait
7133 * for the completion. The expectation is that this routine is called
7134 * typically from probe_one or from the online routine.
7135 **/
7136int
7137lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
7138{
7139 int rc;
7140 struct lpfc_mqe *mqe;
7141 struct lpfc_pc_sli4_params *sli4_params;
7142 uint32_t mbox_tmo;
7143
7144 rc = 0;
7145 mqe = &mboxq->u.mqe;
7146
7147 /* Read the port's SLI4 Parameters port capabilities */
7148 lpfc_sli4_params(mboxq);
7149 if (!phba->sli4_hba.intr_enable)
7150 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
7151 else {
7152 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES);
7153 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
7154 }
7155
7156 if (unlikely(rc))
7157 return 1;
7158
7159 sli4_params = &phba->sli4_hba.pc_sli4_params;
7160 sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params);
7161 sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params);
7162 sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params);
7163 sli4_params->featurelevel_1 = bf_get(featurelevel_1,
7164 &mqe->un.sli4_params);
7165 sli4_params->featurelevel_2 = bf_get(featurelevel_2,
7166 &mqe->un.sli4_params);
7167 sli4_params->proto_types = mqe->un.sli4_params.word3;
7168 sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len;
7169 sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params);
7170 sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params);
7171 sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params);
7172 sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params);
7173 sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params);
7174 sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params);
7175 sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params);
7176 sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params);
7177 sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params);
7178 sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params);
7179 sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params);
7180 sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params);
7181 sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params);
7182 sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params);
7183 sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params);
7184 sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params);
7185 sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params);
7186 sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params);
7187 sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params);
7188 return rc;
7189}
7190
6796/** 7191/**
6797 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. 7192 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
6798 * @pdev: pointer to PCI device 7193 * @pdev: pointer to PCI device
@@ -7134,6 +7529,12 @@ lpfc_pci_resume_one_s3(struct pci_dev *pdev)
7134 pci_set_power_state(pdev, PCI_D0); 7529 pci_set_power_state(pdev, PCI_D0);
7135 pci_restore_state(pdev); 7530 pci_restore_state(pdev);
7136 7531
7532 /*
7533 * As the new kernel behavior of pci_restore_state() API call clears
7534 * device saved_state flag, need to save the restored state again.
7535 */
7536 pci_save_state(pdev);
7537
7137 if (pdev->is_busmaster) 7538 if (pdev->is_busmaster)
7138 pci_set_master(pdev); 7539 pci_set_master(pdev);
7139 7540
@@ -7317,6 +7718,13 @@ lpfc_io_slot_reset_s3(struct pci_dev *pdev)
7317 } 7718 }
7318 7719
7319 pci_restore_state(pdev); 7720 pci_restore_state(pdev);
7721
7722 /*
7723 * As the new kernel behavior of pci_restore_state() API call clears
7724 * device saved_state flag, need to save the restored state again.
7725 */
7726 pci_save_state(pdev);
7727
7320 if (pdev->is_busmaster) 7728 if (pdev->is_busmaster)
7321 pci_set_master(pdev); 7729 pci_set_master(pdev);
7322 7730
@@ -7726,6 +8134,13 @@ lpfc_pci_resume_one_s4(struct pci_dev *pdev)
7726 /* Restore device state from PCI config space */ 8134 /* Restore device state from PCI config space */
7727 pci_set_power_state(pdev, PCI_D0); 8135 pci_set_power_state(pdev, PCI_D0);
7728 pci_restore_state(pdev); 8136 pci_restore_state(pdev);
8137
8138 /*
8139 * As the new kernel behavior of pci_restore_state() API call clears
8140 * device saved_state flag, need to save the restored state again.
8141 */
8142 pci_save_state(pdev);
8143
7729 if (pdev->is_busmaster) 8144 if (pdev->is_busmaster)
7730 pci_set_master(pdev); 8145 pci_set_master(pdev);
7731 8146
@@ -7845,11 +8260,11 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
7845 int rc; 8260 int rc;
7846 struct lpfc_sli_intf intf; 8261 struct lpfc_sli_intf intf;
7847 8262
7848 if (pci_read_config_dword(pdev, LPFC_SLIREV_CONF_WORD, &intf.word0)) 8263 if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0))
7849 return -ENODEV; 8264 return -ENODEV;
7850 8265
7851 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && 8266 if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) &&
7852 (bf_get(lpfc_sli_intf_rev, &intf) == LPFC_SLIREV_CONF_SLI4)) 8267 (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4))
7853 rc = lpfc_pci_probe_one_s4(pdev, pid); 8268 rc = lpfc_pci_probe_one_s4(pdev, pid);
7854 else 8269 else
7855 rc = lpfc_pci_probe_one_s3(pdev, pid); 8270 rc = lpfc_pci_probe_one_s3(pdev, pid);
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index a9afd8b94b6a..6c4dce1a30ca 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -1707,7 +1707,8 @@ lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1707 alloc_len - sizeof(union lpfc_sli4_cfg_shdr); 1707 alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
1708 } 1708 }
1709 /* The sub-header is in DMA memory, which needs endian converstion */ 1709 /* The sub-header is in DMA memory, which needs endian converstion */
1710 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr, 1710 if (cfg_shdr)
1711 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
1711 sizeof(union lpfc_sli4_cfg_shdr)); 1712 sizeof(union lpfc_sli4_cfg_shdr));
1712 1713
1713 return alloc_len; 1714 return alloc_len;
@@ -1747,6 +1748,65 @@ lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1747} 1748}
1748 1749
1749/** 1750/**
1751 * lpfc_sli4_mbx_read_fcf_record - Allocate and construct read fcf mbox cmd
1752 * @phba: pointer to lpfc hba data structure.
1753 * @fcf_index: index to fcf table.
1754 *
1755 * This routine routine allocates and constructs non-embedded mailbox command
1756 * for reading a FCF table entry refered by @fcf_index.
1757 *
1758 * Return: pointer to the mailbox command constructed if successful, otherwise
1759 * NULL.
1760 **/
1761int
1762lpfc_sli4_mbx_read_fcf_record(struct lpfc_hba *phba,
1763 struct lpfcMboxq *mboxq,
1764 uint16_t fcf_index)
1765{
1766 void *virt_addr;
1767 dma_addr_t phys_addr;
1768 uint8_t *bytep;
1769 struct lpfc_mbx_sge sge;
1770 uint32_t alloc_len, req_len;
1771 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1772
1773 if (!mboxq)
1774 return -ENOMEM;
1775
1776 req_len = sizeof(struct fcf_record) +
1777 sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
1778
1779 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
1780 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1781 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
1782 LPFC_SLI4_MBX_NEMBED);
1783
1784 if (alloc_len < req_len) {
1785 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1786 "0291 Allocated DMA memory size (x%x) is "
1787 "less than the requested DMA memory "
1788 "size (x%x)\n", alloc_len, req_len);
1789 return -ENOMEM;
1790 }
1791
1792 /* Get the first SGE entry from the non-embedded DMA memory. This
1793 * routine only uses a single SGE.
1794 */
1795 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1796 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1797 virt_addr = mboxq->sge_array->addr[0];
1798 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1799
1800 /* Set up command fields */
1801 bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
1802 /* Perform necessary endian conversion */
1803 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
1804 lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
1805
1806 return 0;
1807}
1808
1809/**
1750 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox 1810 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
1751 * @mboxq: pointer to lpfc mbox command. 1811 * @mboxq: pointer to lpfc mbox command.
1752 * 1812 *
@@ -1946,13 +2006,14 @@ lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1946 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID); 2006 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
1947 bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); 2007 bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
1948 bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); 2008 bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
1949 bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, phba->fcf.fcf_indx); 2009 bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2010 phba->fcf.current_rec.fcf_indx);
1950 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */ 2011 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
1951 bf_set(lpfc_reg_fcfi_mam, reg_fcfi, 2012 bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3);
1952 (~phba->fcf.addr_mode) & 0x3); 2013 if (phba->fcf.current_rec.vlan_id != 0xFFFF) {
1953 if (phba->fcf.fcf_flag & FCF_VALID_VLAN) {
1954 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1); 2014 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
1955 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, phba->fcf.vlan_id); 2015 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2016 phba->fcf.current_rec.vlan_id);
1956 } 2017 }
1957} 2018}
1958 2019
@@ -1992,3 +2053,41 @@ lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
1992 bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI); 2053 bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
1993 resume_rpi->event_tag = ndlp->phba->fc_eventTag; 2054 resume_rpi->event_tag = ndlp->phba->fc_eventTag;
1994} 2055}
2056
2057/**
2058 * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
2059 * mailbox command.
2060 * @mbox: pointer to lpfc mbox command to initialize.
2061 *
2062 * The PORT_CAPABILITIES supported pages mailbox command is issued to
2063 * retrieve the particular feature pages supported by the port.
2064 **/
2065void
2066lpfc_supported_pages(struct lpfcMboxq *mbox)
2067{
2068 struct lpfc_mbx_supp_pages *supp_pages;
2069
2070 memset(mbox, 0, sizeof(*mbox));
2071 supp_pages = &mbox->u.mqe.un.supp_pages;
2072 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
2073 bf_set(cpn, supp_pages, LPFC_SUPP_PAGES);
2074}
2075
2076/**
2077 * lpfc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params
2078 * mailbox command.
2079 * @mbox: pointer to lpfc mbox command to initialize.
2080 *
2081 * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
2082 * retrieve the particular SLI4 features supported by the port.
2083 **/
2084void
2085lpfc_sli4_params(struct lpfcMboxq *mbox)
2086{
2087 struct lpfc_mbx_sli4_params *sli4_params;
2088
2089 memset(mbox, 0, sizeof(*mbox));
2090 sli4_params = &mbox->u.mqe.un.sli4_params;
2091 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
2092 bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS);
2093}
diff --git a/drivers/scsi/lpfc/lpfc_nl.h b/drivers/scsi/lpfc/lpfc_nl.h
index d655ed3eebef..f3cfbe2ce986 100644
--- a/drivers/scsi/lpfc/lpfc_nl.h
+++ b/drivers/scsi/lpfc/lpfc_nl.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2008 Emulex. All rights reserved. * 4 * Copyright (C) 2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -177,23 +177,3 @@ struct temp_event {
177 uint32_t data; 177 uint32_t data;
178}; 178};
179 179
180/* bsg definitions */
181#define LPFC_BSG_VENDOR_SET_CT_EVENT 1
182#define LPFC_BSG_VENDOR_GET_CT_EVENT 2
183
184struct set_ct_event {
185 uint32_t command;
186 uint32_t ev_req_id;
187 uint32_t ev_reg_id;
188};
189
190struct get_ct_event {
191 uint32_t command;
192 uint32_t ev_reg_id;
193 uint32_t ev_req_id;
194};
195
196struct get_ct_event_reply {
197 uint32_t immed_data;
198 uint32_t type;
199};
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index 2ed6af194932..d20ae6b3b3cf 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -62,7 +62,7 @@ lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
62 62
63int 63int
64lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp, 64lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
65 struct serv_parm * sp, uint32_t class) 65 struct serv_parm *sp, uint32_t class, int flogi)
66{ 66{
67 volatile struct serv_parm *hsp = &vport->fc_sparam; 67 volatile struct serv_parm *hsp = &vport->fc_sparam;
68 uint16_t hsp_value, ssp_value = 0; 68 uint16_t hsp_value, ssp_value = 0;
@@ -75,49 +75,56 @@ lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
75 * correcting the byte values. 75 * correcting the byte values.
76 */ 76 */
77 if (sp->cls1.classValid) { 77 if (sp->cls1.classValid) {
78 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) | 78 if (!flogi) {
79 hsp->cls1.rcvDataSizeLsb; 79 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
80 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) | 80 hsp->cls1.rcvDataSizeLsb);
81 sp->cls1.rcvDataSizeLsb; 81 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
82 if (!ssp_value) 82 sp->cls1.rcvDataSizeLsb);
83 goto bad_service_param; 83 if (!ssp_value)
84 if (ssp_value > hsp_value) { 84 goto bad_service_param;
85 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb; 85 if (ssp_value > hsp_value) {
86 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb; 86 sp->cls1.rcvDataSizeLsb =
87 hsp->cls1.rcvDataSizeLsb;
88 sp->cls1.rcvDataSizeMsb =
89 hsp->cls1.rcvDataSizeMsb;
90 }
87 } 91 }
88 } else if (class == CLASS1) { 92 } else if (class == CLASS1)
89 goto bad_service_param; 93 goto bad_service_param;
90 }
91
92 if (sp->cls2.classValid) { 94 if (sp->cls2.classValid) {
93 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) | 95 if (!flogi) {
94 hsp->cls2.rcvDataSizeLsb; 96 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
95 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) | 97 hsp->cls2.rcvDataSizeLsb);
96 sp->cls2.rcvDataSizeLsb; 98 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
97 if (!ssp_value) 99 sp->cls2.rcvDataSizeLsb);
98 goto bad_service_param; 100 if (!ssp_value)
99 if (ssp_value > hsp_value) { 101 goto bad_service_param;
100 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb; 102 if (ssp_value > hsp_value) {
101 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb; 103 sp->cls2.rcvDataSizeLsb =
104 hsp->cls2.rcvDataSizeLsb;
105 sp->cls2.rcvDataSizeMsb =
106 hsp->cls2.rcvDataSizeMsb;
107 }
102 } 108 }
103 } else if (class == CLASS2) { 109 } else if (class == CLASS2)
104 goto bad_service_param; 110 goto bad_service_param;
105 }
106
107 if (sp->cls3.classValid) { 111 if (sp->cls3.classValid) {
108 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) | 112 if (!flogi) {
109 hsp->cls3.rcvDataSizeLsb; 113 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
110 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) | 114 hsp->cls3.rcvDataSizeLsb);
111 sp->cls3.rcvDataSizeLsb; 115 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
112 if (!ssp_value) 116 sp->cls3.rcvDataSizeLsb);
113 goto bad_service_param; 117 if (!ssp_value)
114 if (ssp_value > hsp_value) { 118 goto bad_service_param;
115 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb; 119 if (ssp_value > hsp_value) {
116 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb; 120 sp->cls3.rcvDataSizeLsb =
121 hsp->cls3.rcvDataSizeLsb;
122 sp->cls3.rcvDataSizeMsb =
123 hsp->cls3.rcvDataSizeMsb;
124 }
117 } 125 }
118 } else if (class == CLASS3) { 126 } else if (class == CLASS3)
119 goto bad_service_param; 127 goto bad_service_param;
120 }
121 128
122 /* 129 /*
123 * Preserve the upper four bits of the MSB from the PLOGI response. 130 * Preserve the upper four bits of the MSB from the PLOGI response.
@@ -247,7 +254,7 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
247 int rc; 254 int rc;
248 255
249 memset(&stat, 0, sizeof (struct ls_rjt)); 256 memset(&stat, 0, sizeof (struct ls_rjt));
250 if (vport->port_state <= LPFC_FLOGI) { 257 if (vport->port_state <= LPFC_FDISC) {
251 /* Before responding to PLOGI, check for pt2pt mode. 258 /* Before responding to PLOGI, check for pt2pt mode.
252 * If we are pt2pt, with an outstanding FLOGI, abort 259 * If we are pt2pt, with an outstanding FLOGI, abort
253 * the FLOGI and resend it first. 260 * the FLOGI and resend it first.
@@ -295,7 +302,7 @@ lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
295 NULL); 302 NULL);
296 return 0; 303 return 0;
297 } 304 }
298 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) { 305 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
299 /* Reject this request because invalid parameters */ 306 /* Reject this request because invalid parameters */
300 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC; 307 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
301 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS; 308 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
@@ -831,7 +838,7 @@ lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
831 "0142 PLOGI RSP: Invalid WWN.\n"); 838 "0142 PLOGI RSP: Invalid WWN.\n");
832 goto out; 839 goto out;
833 } 840 }
834 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3)) 841 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
835 goto out; 842 goto out;
836 /* PLOGI chkparm OK */ 843 /* PLOGI chkparm OK */
837 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, 844 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index a246410ce9df..7f21b47db791 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -626,6 +626,7 @@ lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *phba,
626 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) { 626 &phba->sli4_hba.lpfc_abts_scsi_buf_list, list) {
627 if (psb->cur_iocbq.sli4_xritag == xri) { 627 if (psb->cur_iocbq.sli4_xritag == xri) {
628 list_del(&psb->list); 628 list_del(&psb->list);
629 psb->exch_busy = 0;
629 psb->status = IOSTAT_SUCCESS; 630 psb->status = IOSTAT_SUCCESS;
630 spin_unlock_irqrestore( 631 spin_unlock_irqrestore(
631 &phba->sli4_hba.abts_scsi_buf_list_lock, 632 &phba->sli4_hba.abts_scsi_buf_list_lock,
@@ -688,11 +689,12 @@ lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *phba)
688 list); 689 list);
689 if (status) { 690 if (status) {
690 /* Put this back on the abort scsi list */ 691 /* Put this back on the abort scsi list */
691 psb->status = IOSTAT_LOCAL_REJECT; 692 psb->exch_busy = 1;
692 psb->result = IOERR_ABORT_REQUESTED;
693 rc++; 693 rc++;
694 } else 694 } else {
695 psb->exch_busy = 0;
695 psb->status = IOSTAT_SUCCESS; 696 psb->status = IOSTAT_SUCCESS;
697 }
696 /* Put it back into the SCSI buffer list */ 698 /* Put it back into the SCSI buffer list */
697 lpfc_release_scsi_buf_s4(phba, psb); 699 lpfc_release_scsi_buf_s4(phba, psb);
698 } 700 }
@@ -796,19 +798,17 @@ lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
796 */ 798 */
797 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd)); 799 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_cmd));
798 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd)); 800 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_cmd));
799 bf_set(lpfc_sli4_sge_len, sgl, sizeof(struct fcp_cmnd));
800 bf_set(lpfc_sli4_sge_last, sgl, 0); 801 bf_set(lpfc_sli4_sge_last, sgl, 0);
801 sgl->word2 = cpu_to_le32(sgl->word2); 802 sgl->word2 = cpu_to_le32(sgl->word2);
802 sgl->word3 = cpu_to_le32(sgl->word3); 803 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_cmnd));
803 sgl++; 804 sgl++;
804 805
805 /* Setup the physical region for the FCP RSP */ 806 /* Setup the physical region for the FCP RSP */
806 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp)); 807 sgl->addr_hi = cpu_to_le32(putPaddrHigh(pdma_phys_fcp_rsp));
807 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp)); 808 sgl->addr_lo = cpu_to_le32(putPaddrLow(pdma_phys_fcp_rsp));
808 bf_set(lpfc_sli4_sge_len, sgl, sizeof(struct fcp_rsp));
809 bf_set(lpfc_sli4_sge_last, sgl, 1); 809 bf_set(lpfc_sli4_sge_last, sgl, 1);
810 sgl->word2 = cpu_to_le32(sgl->word2); 810 sgl->word2 = cpu_to_le32(sgl->word2);
811 sgl->word3 = cpu_to_le32(sgl->word3); 811 sgl->sge_len = cpu_to_le32(sizeof(struct fcp_rsp));
812 812
813 /* 813 /*
814 * Since the IOCB for the FCP I/O is built into this 814 * Since the IOCB for the FCP I/O is built into this
@@ -839,11 +839,12 @@ lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
839 psb->cur_iocbq.sli4_xritag); 839 psb->cur_iocbq.sli4_xritag);
840 if (status) { 840 if (status) {
841 /* Put this back on the abort scsi list */ 841 /* Put this back on the abort scsi list */
842 psb->status = IOSTAT_LOCAL_REJECT; 842 psb->exch_busy = 1;
843 psb->result = IOERR_ABORT_REQUESTED;
844 rc++; 843 rc++;
845 } else 844 } else {
845 psb->exch_busy = 0;
846 psb->status = IOSTAT_SUCCESS; 846 psb->status = IOSTAT_SUCCESS;
847 }
847 /* Put it back into the SCSI buffer list */ 848 /* Put it back into the SCSI buffer list */
848 lpfc_release_scsi_buf_s4(phba, psb); 849 lpfc_release_scsi_buf_s4(phba, psb);
849 break; 850 break;
@@ -857,11 +858,12 @@ lpfc_new_scsi_buf_s4(struct lpfc_vport *vport, int num_to_alloc)
857 list); 858 list);
858 if (status) { 859 if (status) {
859 /* Put this back on the abort scsi list */ 860 /* Put this back on the abort scsi list */
860 psb->status = IOSTAT_LOCAL_REJECT; 861 psb->exch_busy = 1;
861 psb->result = IOERR_ABORT_REQUESTED;
862 rc++; 862 rc++;
863 } else 863 } else {
864 psb->exch_busy = 0;
864 psb->status = IOSTAT_SUCCESS; 865 psb->status = IOSTAT_SUCCESS;
866 }
865 /* Put it back into the SCSI buffer list */ 867 /* Put it back into the SCSI buffer list */
866 lpfc_release_scsi_buf_s4(phba, psb); 868 lpfc_release_scsi_buf_s4(phba, psb);
867 } 869 }
@@ -951,8 +953,7 @@ lpfc_release_scsi_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *psb)
951{ 953{
952 unsigned long iflag = 0; 954 unsigned long iflag = 0;
953 955
954 if (psb->status == IOSTAT_LOCAL_REJECT 956 if (psb->exch_busy) {
955 && psb->result == IOERR_ABORT_REQUESTED) {
956 spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock, 957 spin_lock_irqsave(&phba->sli4_hba.abts_scsi_buf_list_lock,
957 iflag); 958 iflag);
958 psb->pCmd = NULL; 959 psb->pCmd = NULL;
@@ -1869,7 +1870,6 @@ lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
1869 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) { 1870 scsi_for_each_sg(scsi_cmnd, sgel, nseg, num_bde) {
1870 physaddr = sg_dma_address(sgel); 1871 physaddr = sg_dma_address(sgel);
1871 dma_len = sg_dma_len(sgel); 1872 dma_len = sg_dma_len(sgel);
1872 bf_set(lpfc_sli4_sge_len, sgl, sg_dma_len(sgel));
1873 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr)); 1873 sgl->addr_lo = cpu_to_le32(putPaddrLow(physaddr));
1874 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr)); 1874 sgl->addr_hi = cpu_to_le32(putPaddrHigh(physaddr));
1875 if ((num_bde + 1) == nseg) 1875 if ((num_bde + 1) == nseg)
@@ -1878,7 +1878,7 @@ lpfc_scsi_prep_dma_buf_s4(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
1878 bf_set(lpfc_sli4_sge_last, sgl, 0); 1878 bf_set(lpfc_sli4_sge_last, sgl, 0);
1879 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset); 1879 bf_set(lpfc_sli4_sge_offset, sgl, dma_offset);
1880 sgl->word2 = cpu_to_le32(sgl->word2); 1880 sgl->word2 = cpu_to_le32(sgl->word2);
1881 sgl->word3 = cpu_to_le32(sgl->word3); 1881 sgl->sge_len = cpu_to_le32(dma_len);
1882 dma_offset += dma_len; 1882 dma_offset += dma_len;
1883 sgl++; 1883 sgl++;
1884 } 1884 }
@@ -2221,6 +2221,9 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
2221 2221
2222 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4]; 2222 lpfc_cmd->result = pIocbOut->iocb.un.ulpWord[4];
2223 lpfc_cmd->status = pIocbOut->iocb.ulpStatus; 2223 lpfc_cmd->status = pIocbOut->iocb.ulpStatus;
2224 /* pick up SLI4 exhange busy status from HBA */
2225 lpfc_cmd->exch_busy = pIocbOut->iocb_flag & LPFC_EXCHANGE_BUSY;
2226
2224 if (pnode && NLP_CHK_NODE_ACT(pnode)) 2227 if (pnode && NLP_CHK_NODE_ACT(pnode))
2225 atomic_dec(&pnode->cmd_pending); 2228 atomic_dec(&pnode->cmd_pending);
2226 2229
@@ -2637,6 +2640,7 @@ lpfc_scsi_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
2637 } 2640 }
2638 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf; 2641 phba->lpfc_get_scsi_buf = lpfc_get_scsi_buf;
2639 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth; 2642 phba->lpfc_rampdown_queue_depth = lpfc_rampdown_queue_depth;
2643 phba->lpfc_scsi_cmd_iocb_cmpl = lpfc_scsi_cmd_iocb_cmpl;
2640 return 0; 2644 return 0;
2641} 2645}
2642 2646
@@ -2695,6 +2699,13 @@ lpfc_info(struct Scsi_Host *host)
2695 " port %s", 2699 " port %s",
2696 phba->Port); 2700 phba->Port);
2697 } 2701 }
2702 len = strlen(lpfcinfobuf);
2703 if (phba->sli4_hba.link_state.logical_speed) {
2704 snprintf(lpfcinfobuf + len,
2705 384-len,
2706 " Logical Link Speed: %d Mbps",
2707 phba->sli4_hba.link_state.logical_speed * 10);
2708 }
2698 } 2709 }
2699 return lpfcinfobuf; 2710 return lpfcinfobuf;
2700} 2711}
@@ -2990,6 +3001,7 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
2990 3001
2991 /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 3002 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
2992 abtsiocb->fcp_wqidx = iocb->fcp_wqidx; 3003 abtsiocb->fcp_wqidx = iocb->fcp_wqidx;
3004 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
2993 3005
2994 if (lpfc_is_link_up(phba)) 3006 if (lpfc_is_link_up(phba))
2995 icmd->ulpCommand = CMD_ABORT_XRI_CN; 3007 icmd->ulpCommand = CMD_ABORT_XRI_CN;
diff --git a/drivers/scsi/lpfc/lpfc_scsi.h b/drivers/scsi/lpfc/lpfc_scsi.h
index 65dfc8bd5b49..5932273870a5 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.h
+++ b/drivers/scsi/lpfc/lpfc_scsi.h
@@ -118,6 +118,7 @@ struct lpfc_scsi_buf {
118 118
119 uint32_t timeout; 119 uint32_t timeout;
120 120
121 uint16_t exch_busy; /* SLI4 hba reported XB on complete WCQE */
121 uint16_t status; /* From IOCB Word 7- ulpStatus */ 122 uint16_t status; /* From IOCB Word 7- ulpStatus */
122 uint32_t result; /* From IOCB Word 4. */ 123 uint32_t result; /* From IOCB Word 4. */
123 124
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 589549b2bf0e..35e3b96d4e07 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -580,10 +580,7 @@ __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
580 else 580 else
581 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag); 581 sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_xritag);
582 if (sglq) { 582 if (sglq) {
583 if (iocbq->iocb_flag & LPFC_DRIVER_ABORTED 583 if (iocbq->iocb_flag & LPFC_EXCHANGE_BUSY) {
584 && ((iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
585 && (iocbq->iocb.un.ulpWord[4]
586 == IOERR_ABORT_REQUESTED))) {
587 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, 584 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock,
588 iflag); 585 iflag);
589 list_add(&sglq->list, 586 list_add(&sglq->list,
@@ -764,10 +761,6 @@ lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
764 case DSSCMD_IWRITE64_CX: 761 case DSSCMD_IWRITE64_CX:
765 case DSSCMD_IREAD64_CR: 762 case DSSCMD_IREAD64_CR:
766 case DSSCMD_IREAD64_CX: 763 case DSSCMD_IREAD64_CX:
767 case DSSCMD_INVALIDATE_DEK:
768 case DSSCMD_SET_KEK:
769 case DSSCMD_GET_KEK_ID:
770 case DSSCMD_GEN_XFER:
771 type = LPFC_SOL_IOCB; 764 type = LPFC_SOL_IOCB;
772 break; 765 break;
773 case CMD_ABORT_XRI_CN: 766 case CMD_ABORT_XRI_CN:
@@ -1717,6 +1710,7 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1717 struct lpfc_dmabuf *mp; 1710 struct lpfc_dmabuf *mp;
1718 uint16_t rpi, vpi; 1711 uint16_t rpi, vpi;
1719 int rc; 1712 int rc;
1713 struct lpfc_vport *vport = pmb->vport;
1720 1714
1721 mp = (struct lpfc_dmabuf *) (pmb->context1); 1715 mp = (struct lpfc_dmabuf *) (pmb->context1);
1722 1716
@@ -1745,6 +1739,18 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1745 return; 1739 return;
1746 } 1740 }
1747 1741
1742 /* Unreg VPI, if the REG_VPI succeed after VLink failure */
1743 if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
1744 !(phba->pport->load_flag & FC_UNLOADING) &&
1745 !pmb->u.mb.mbxStatus) {
1746 lpfc_unreg_vpi(phba, pmb->u.mb.un.varRegVpi.vpi, pmb);
1747 pmb->vport = vport;
1748 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1749 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1750 if (rc != MBX_NOT_FINISHED)
1751 return;
1752 }
1753
1748 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG) 1754 if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
1749 lpfc_sli4_mbox_cmd_free(phba, pmb); 1755 lpfc_sli4_mbox_cmd_free(phba, pmb);
1750 else 1756 else
@@ -2228,9 +2234,15 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2228 * All other are passed to the completion callback. 2234 * All other are passed to the completion callback.
2229 */ 2235 */
2230 if (pring->ringno == LPFC_ELS_RING) { 2236 if (pring->ringno == LPFC_ELS_RING) {
2231 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) { 2237 if ((phba->sli_rev < LPFC_SLI_REV4) &&
2238 (cmdiocbp->iocb_flag &
2239 LPFC_DRIVER_ABORTED)) {
2240 spin_lock_irqsave(&phba->hbalock,
2241 iflag);
2232 cmdiocbp->iocb_flag &= 2242 cmdiocbp->iocb_flag &=
2233 ~LPFC_DRIVER_ABORTED; 2243 ~LPFC_DRIVER_ABORTED;
2244 spin_unlock_irqrestore(&phba->hbalock,
2245 iflag);
2234 saveq->iocb.ulpStatus = 2246 saveq->iocb.ulpStatus =
2235 IOSTAT_LOCAL_REJECT; 2247 IOSTAT_LOCAL_REJECT;
2236 saveq->iocb.un.ulpWord[4] = 2248 saveq->iocb.un.ulpWord[4] =
@@ -2240,7 +2252,47 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2240 * of DMAing payload, so don't free data 2252 * of DMAing payload, so don't free data
2241 * buffer till after a hbeat. 2253 * buffer till after a hbeat.
2242 */ 2254 */
2255 spin_lock_irqsave(&phba->hbalock,
2256 iflag);
2243 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE; 2257 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
2258 spin_unlock_irqrestore(&phba->hbalock,
2259 iflag);
2260 }
2261 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2262 (saveq->iocb_flag & LPFC_EXCHANGE_BUSY)) {
2263 /* Set cmdiocb flag for the exchange
2264 * busy so sgl (xri) will not be
2265 * released until the abort xri is
2266 * received from hba, clear the
2267 * LPFC_DRIVER_ABORTED bit in case
2268 * it was driver initiated abort.
2269 */
2270 spin_lock_irqsave(&phba->hbalock,
2271 iflag);
2272 cmdiocbp->iocb_flag &=
2273 ~LPFC_DRIVER_ABORTED;
2274 cmdiocbp->iocb_flag |=
2275 LPFC_EXCHANGE_BUSY;
2276 spin_unlock_irqrestore(&phba->hbalock,
2277 iflag);
2278 cmdiocbp->iocb.ulpStatus =
2279 IOSTAT_LOCAL_REJECT;
2280 cmdiocbp->iocb.un.ulpWord[4] =
2281 IOERR_ABORT_REQUESTED;
2282 /*
2283 * For SLI4, irsiocb contains NO_XRI
2284 * in sli_xritag, it shall not affect
2285 * releasing sgl (xri) process.
2286 */
2287 saveq->iocb.ulpStatus =
2288 IOSTAT_LOCAL_REJECT;
2289 saveq->iocb.un.ulpWord[4] =
2290 IOERR_SLI_ABORTED;
2291 spin_lock_irqsave(&phba->hbalock,
2292 iflag);
2293 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
2294 spin_unlock_irqrestore(&phba->hbalock,
2295 iflag);
2244 } 2296 }
2245 } 2297 }
2246 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); 2298 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
@@ -5687,19 +5739,19 @@ lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
5687 5739
5688 for (i = 0; i < numBdes; i++) { 5740 for (i = 0; i < numBdes; i++) {
5689 /* Should already be byte swapped. */ 5741 /* Should already be byte swapped. */
5690 sgl->addr_hi = bpl->addrHigh; 5742 sgl->addr_hi = bpl->addrHigh;
5691 sgl->addr_lo = bpl->addrLow; 5743 sgl->addr_lo = bpl->addrLow;
5692 /* swap the size field back to the cpu so we 5744
5693 * can assign it to the sgl.
5694 */
5695 bde.tus.w = le32_to_cpu(bpl->tus.w);
5696 bf_set(lpfc_sli4_sge_len, sgl, bde.tus.f.bdeSize);
5697 if ((i+1) == numBdes) 5745 if ((i+1) == numBdes)
5698 bf_set(lpfc_sli4_sge_last, sgl, 1); 5746 bf_set(lpfc_sli4_sge_last, sgl, 1);
5699 else 5747 else
5700 bf_set(lpfc_sli4_sge_last, sgl, 0); 5748 bf_set(lpfc_sli4_sge_last, sgl, 0);
5701 sgl->word2 = cpu_to_le32(sgl->word2); 5749 sgl->word2 = cpu_to_le32(sgl->word2);
5702 sgl->word3 = cpu_to_le32(sgl->word3); 5750 /* swap the size field back to the cpu so we
5751 * can assign it to the sgl.
5752 */
5753 bde.tus.w = le32_to_cpu(bpl->tus.w);
5754 sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
5703 bpl++; 5755 bpl++;
5704 sgl++; 5756 sgl++;
5705 } 5757 }
@@ -5712,11 +5764,10 @@ lpfc_sli4_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
5712 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh); 5764 cpu_to_le32(icmd->un.genreq64.bdl.addrHigh);
5713 sgl->addr_lo = 5765 sgl->addr_lo =
5714 cpu_to_le32(icmd->un.genreq64.bdl.addrLow); 5766 cpu_to_le32(icmd->un.genreq64.bdl.addrLow);
5715 bf_set(lpfc_sli4_sge_len, sgl,
5716 icmd->un.genreq64.bdl.bdeSize);
5717 bf_set(lpfc_sli4_sge_last, sgl, 1); 5767 bf_set(lpfc_sli4_sge_last, sgl, 1);
5718 sgl->word2 = cpu_to_le32(sgl->word2); 5768 sgl->word2 = cpu_to_le32(sgl->word2);
5719 sgl->word3 = cpu_to_le32(sgl->word3); 5769 sgl->sge_len =
5770 cpu_to_le32(icmd->un.genreq64.bdl.bdeSize);
5720 } 5771 }
5721 return sglq->sli4_xritag; 5772 return sglq->sli4_xritag;
5722} 5773}
@@ -5987,12 +6038,10 @@ lpfc_sli4_iocb2wqe(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq,
5987 else 6038 else
5988 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0); 6039 bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
5989 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG); 6040 bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
5990 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
5991 wqe->words[5] = 0; 6041 wqe->words[5] = 0;
5992 bf_set(lpfc_wqe_gen_ct, &wqe->generic, 6042 bf_set(lpfc_wqe_gen_ct, &wqe->generic,
5993 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l)); 6043 ((iocbq->iocb.ulpCt_h << 1) | iocbq->iocb.ulpCt_l));
5994 abort_tag = iocbq->iocb.un.acxri.abortIoTag; 6044 abort_tag = iocbq->iocb.un.acxri.abortIoTag;
5995 wqe->generic.abort_tag = abort_tag;
5996 /* 6045 /*
5997 * The abort handler will send us CMD_ABORT_XRI_CN or 6046 * The abort handler will send us CMD_ABORT_XRI_CN or
5998 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX 6047 * CMD_CLOSE_XRI_CN and the fw only accepts CMD_ABORT_XRI_CX
@@ -6121,15 +6170,15 @@ __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
6121 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe)) 6170 if (lpfc_sli4_iocb2wqe(phba, piocb, &wqe))
6122 return IOCB_ERROR; 6171 return IOCB_ERROR;
6123 6172
6124 if (piocb->iocb_flag & LPFC_IO_FCP) { 6173 if ((piocb->iocb_flag & LPFC_IO_FCP) ||
6174 (piocb->iocb_flag & LPFC_USE_FCPWQIDX)) {
6125 /* 6175 /*
6126 * For FCP command IOCB, get a new WQ index to distribute 6176 * For FCP command IOCB, get a new WQ index to distribute
6127 * WQE across the WQsr. On the other hand, for abort IOCB, 6177 * WQE across the WQsr. On the other hand, for abort IOCB,
6128 * it carries the same WQ index to the original command 6178 * it carries the same WQ index to the original command
6129 * IOCB. 6179 * IOCB.
6130 */ 6180 */
6131 if ((piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) && 6181 if (piocb->iocb_flag & LPFC_IO_FCP)
6132 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN))
6133 piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba); 6182 piocb->fcp_wqidx = lpfc_sli4_scmd_to_wqidx_distr(phba);
6134 if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx], 6183 if (lpfc_sli4_wq_put(phba->sli4_hba.fcp_wq[piocb->fcp_wqidx],
6135 &wqe)) 6184 &wqe))
@@ -7004,7 +7053,14 @@ lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7004 abort_iocb->iocb.ulpContext != abort_context || 7053 abort_iocb->iocb.ulpContext != abort_context ||
7005 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0) 7054 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
7006 spin_unlock_irq(&phba->hbalock); 7055 spin_unlock_irq(&phba->hbalock);
7007 else { 7056 else if (phba->sli_rev < LPFC_SLI_REV4) {
7057 /*
7058 * leave the SLI4 aborted command on the txcmplq
7059 * list and the command complete WCQE's XB bit
7060 * will tell whether the SGL (XRI) can be released
7061 * immediately or to the aborted SGL list for the
7062 * following abort XRI from the HBA.
7063 */
7008 list_del_init(&abort_iocb->list); 7064 list_del_init(&abort_iocb->list);
7009 pring->txcmplq_cnt--; 7065 pring->txcmplq_cnt--;
7010 spin_unlock_irq(&phba->hbalock); 7066 spin_unlock_irq(&phba->hbalock);
@@ -7013,11 +7069,13 @@ lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7013 * payload, so don't free data buffer till after 7069 * payload, so don't free data buffer till after
7014 * a hbeat. 7070 * a hbeat.
7015 */ 7071 */
7072 spin_lock_irq(&phba->hbalock);
7016 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE; 7073 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
7017
7018 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED; 7074 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
7075 spin_unlock_irq(&phba->hbalock);
7076
7019 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT; 7077 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
7020 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED; 7078 abort_iocb->iocb.un.ulpWord[4] = IOERR_ABORT_REQUESTED;
7021 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb); 7079 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
7022 } 7080 }
7023 } 7081 }
@@ -7106,7 +7164,7 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7106 return 0; 7164 return 0;
7107 7165
7108 /* This signals the response to set the correct status 7166 /* This signals the response to set the correct status
7109 * before calling the completion handler. 7167 * before calling the completion handler
7110 */ 7168 */
7111 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED; 7169 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
7112 7170
@@ -7124,6 +7182,8 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7124 7182
7125 /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 7183 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7126 abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx; 7184 abtsiocbp->fcp_wqidx = cmdiocb->fcp_wqidx;
7185 if (cmdiocb->iocb_flag & LPFC_IO_FCP)
7186 abtsiocbp->iocb_flag |= LPFC_USE_FCPWQIDX;
7127 7187
7128 if (phba->link_state >= LPFC_LINK_UP) 7188 if (phba->link_state >= LPFC_LINK_UP)
7129 iabt->ulpCommand = CMD_ABORT_XRI_CN; 7189 iabt->ulpCommand = CMD_ABORT_XRI_CN;
@@ -7330,6 +7390,8 @@ lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
7330 7390
7331 /* ABTS WQE must go to the same WQ as the WQE to be aborted */ 7391 /* ABTS WQE must go to the same WQ as the WQE to be aborted */
7332 abtsiocb->fcp_wqidx = iocbq->fcp_wqidx; 7392 abtsiocb->fcp_wqidx = iocbq->fcp_wqidx;
7393 if (iocbq->iocb_flag & LPFC_IO_FCP)
7394 abtsiocb->iocb_flag |= LPFC_USE_FCPWQIDX;
7333 7395
7334 if (lpfc_is_link_up(phba)) 7396 if (lpfc_is_link_up(phba))
7335 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; 7397 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
@@ -8359,11 +8421,24 @@ void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
8359 } 8421 }
8360} 8422}
8361 8423
8424/**
8425 * lpfc_sli4_iocb_param_transfer - Transfer pIocbOut and cmpl status to pIocbIn
8426 * @phba: pointer to lpfc hba data structure
8427 * @pIocbIn: pointer to the rspiocbq
8428 * @pIocbOut: pointer to the cmdiocbq
8429 * @wcqe: pointer to the complete wcqe
8430 *
8431 * This routine transfers the fields of a command iocbq to a response iocbq
8432 * by copying all the IOCB fields from command iocbq and transferring the
8433 * completion status information from the complete wcqe.
8434 **/
8362static void 8435static void
8363lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn, 8436lpfc_sli4_iocb_param_transfer(struct lpfc_hba *phba,
8437 struct lpfc_iocbq *pIocbIn,
8364 struct lpfc_iocbq *pIocbOut, 8438 struct lpfc_iocbq *pIocbOut,
8365 struct lpfc_wcqe_complete *wcqe) 8439 struct lpfc_wcqe_complete *wcqe)
8366{ 8440{
8441 unsigned long iflags;
8367 size_t offset = offsetof(struct lpfc_iocbq, iocb); 8442 size_t offset = offsetof(struct lpfc_iocbq, iocb);
8368 8443
8369 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset, 8444 memcpy((char *)pIocbIn + offset, (char *)pIocbOut + offset,
@@ -8377,8 +8452,17 @@ lpfc_sli4_iocb_param_transfer(struct lpfc_iocbq *pIocbIn,
8377 wcqe->total_data_placed; 8452 wcqe->total_data_placed;
8378 else 8453 else
8379 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; 8454 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
8380 else 8455 else {
8381 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter; 8456 pIocbIn->iocb.un.ulpWord[4] = wcqe->parameter;
8457 pIocbIn->iocb.un.genreq64.bdl.bdeSize = wcqe->total_data_placed;
8458 }
8459
8460 /* Pick up HBA exchange busy condition */
8461 if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
8462 spin_lock_irqsave(&phba->hbalock, iflags);
8463 pIocbIn->iocb_flag |= LPFC_EXCHANGE_BUSY;
8464 spin_unlock_irqrestore(&phba->hbalock, iflags);
8465 }
8382} 8466}
8383 8467
8384/** 8468/**
@@ -8419,7 +8503,7 @@ lpfc_sli4_els_wcqe_to_rspiocbq(struct lpfc_hba *phba,
8419 } 8503 }
8420 8504
8421 /* Fake the irspiocbq and copy necessary response information */ 8505 /* Fake the irspiocbq and copy necessary response information */
8422 lpfc_sli4_iocb_param_transfer(irspiocbq, cmdiocbq, wcqe); 8506 lpfc_sli4_iocb_param_transfer(phba, irspiocbq, cmdiocbq, wcqe);
8423 8507
8424 return irspiocbq; 8508 return irspiocbq;
8425} 8509}
@@ -8849,8 +8933,7 @@ lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe)
8849 int ecount = 0; 8933 int ecount = 0;
8850 uint16_t cqid; 8934 uint16_t cqid;
8851 8935
8852 if (bf_get(lpfc_eqe_major_code, eqe) != 0 || 8936 if (bf_get(lpfc_eqe_major_code, eqe) != 0) {
8853 bf_get(lpfc_eqe_minor_code, eqe) != 0) {
8854 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 8937 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
8855 "0359 Not a valid slow-path completion " 8938 "0359 Not a valid slow-path completion "
8856 "event: majorcode=x%x, minorcode=x%x\n", 8939 "event: majorcode=x%x, minorcode=x%x\n",
@@ -8976,7 +9059,7 @@ lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba,
8976 } 9059 }
8977 9060
8978 /* Fake the irspiocb and copy necessary response information */ 9061 /* Fake the irspiocb and copy necessary response information */
8979 lpfc_sli4_iocb_param_transfer(&irspiocbq, cmdiocbq, wcqe); 9062 lpfc_sli4_iocb_param_transfer(phba, &irspiocbq, cmdiocbq, wcqe);
8980 9063
8981 /* Pass the cmd_iocb and the rsp state to the upper layer */ 9064 /* Pass the cmd_iocb and the rsp state to the upper layer */
8982 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq); 9065 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, &irspiocbq);
@@ -9082,8 +9165,7 @@ lpfc_sli4_fp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
9082 uint16_t cqid; 9165 uint16_t cqid;
9083 int ecount = 0; 9166 int ecount = 0;
9084 9167
9085 if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0) || 9168 if (unlikely(bf_get(lpfc_eqe_major_code, eqe) != 0)) {
9086 unlikely(bf_get(lpfc_eqe_minor_code, eqe) != 0)) {
9087 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 9169 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
9088 "0366 Not a valid fast-path completion " 9170 "0366 Not a valid fast-path completion "
9089 "event: majorcode=x%x, minorcode=x%x\n", 9171 "event: majorcode=x%x, minorcode=x%x\n",
@@ -11871,12 +11953,6 @@ lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
11871{ 11953{
11872 int rc = 0, error; 11954 int rc = 0, error;
11873 LPFC_MBOXQ_t *mboxq; 11955 LPFC_MBOXQ_t *mboxq;
11874 void *virt_addr;
11875 dma_addr_t phys_addr;
11876 uint8_t *bytep;
11877 struct lpfc_mbx_sge sge;
11878 uint32_t alloc_len, req_len;
11879 struct lpfc_mbx_read_fcf_tbl *read_fcf;
11880 11956
11881 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag; 11957 phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
11882 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 11958 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
@@ -11887,43 +11963,19 @@ lpfc_sli4_read_fcf_record(struct lpfc_hba *phba, uint16_t fcf_index)
11887 error = -ENOMEM; 11963 error = -ENOMEM;
11888 goto fail_fcfscan; 11964 goto fail_fcfscan;
11889 } 11965 }
11890 11966 /* Construct the read FCF record mailbox command */
11891 req_len = sizeof(struct fcf_record) + 11967 rc = lpfc_sli4_mbx_read_fcf_record(phba, mboxq, fcf_index);
11892 sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t); 11968 if (rc) {
11893 11969 error = -EINVAL;
11894 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
11895 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
11896 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
11897 LPFC_SLI4_MBX_NEMBED);
11898
11899 if (alloc_len < req_len) {
11900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
11901 "0291 Allocated DMA memory size (x%x) is "
11902 "less than the requested DMA memory "
11903 "size (x%x)\n", alloc_len, req_len);
11904 error = -ENOMEM;
11905 goto fail_fcfscan; 11970 goto fail_fcfscan;
11906 } 11971 }
11907 11972 /* Issue the mailbox command asynchronously */
11908 /* Get the first SGE entry from the non-embedded DMA memory. This
11909 * routine only uses a single SGE.
11910 */
11911 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
11912 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
11913 virt_addr = mboxq->sge_array->addr[0];
11914 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
11915
11916 /* Set up command fields */
11917 bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
11918 /* Perform necessary endian conversion */
11919 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
11920 lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
11921 mboxq->vport = phba->pport; 11973 mboxq->vport = phba->pport;
11922 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record; 11974 mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_record;
11923 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT); 11975 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
11924 if (rc == MBX_NOT_FINISHED) { 11976 if (rc == MBX_NOT_FINISHED)
11925 error = -EIO; 11977 error = -EIO;
11926 } else { 11978 else {
11927 spin_lock_irq(&phba->hbalock); 11979 spin_lock_irq(&phba->hbalock);
11928 phba->hba_flag |= FCF_DISC_INPROGRESS; 11980 phba->hba_flag |= FCF_DISC_INPROGRESS;
11929 spin_unlock_irq(&phba->hbalock); 11981 spin_unlock_irq(&phba->hbalock);
@@ -11942,6 +11994,90 @@ fail_fcfscan:
11942} 11994}
11943 11995
11944/** 11996/**
11997 * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
11998 * @phba: pointer to lpfc hba data structure.
11999 *
12000 * This routine is the completion routine for the rediscover FCF table mailbox
12001 * command. If the mailbox command returned failure, it will try to stop the
12002 * FCF rediscover wait timer.
12003 **/
12004void
12005lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
12006{
12007 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
12008 uint32_t shdr_status, shdr_add_status;
12009
12010 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
12011
12012 shdr_status = bf_get(lpfc_mbox_hdr_status,
12013 &redisc_fcf->header.cfg_shdr.response);
12014 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
12015 &redisc_fcf->header.cfg_shdr.response);
12016 if (shdr_status || shdr_add_status) {
12017 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12018 "2746 Requesting for FCF rediscovery failed "
12019 "status x%x add_status x%x\n",
12020 shdr_status, shdr_add_status);
12021 /*
12022 * Request failed, last resort to re-try current
12023 * registered FCF entry
12024 */
12025 lpfc_retry_pport_discovery(phba);
12026 } else
12027 /*
12028 * Start FCF rediscovery wait timer for pending FCF
12029 * before rescan FCF record table.
12030 */
12031 lpfc_fcf_redisc_wait_start_timer(phba);
12032
12033 mempool_free(mbox, phba->mbox_mem_pool);
12034}
12035
12036/**
12037 * lpfc_sli4_redisc_all_fcf - Request to rediscover entire FCF table by port.
12038 * @phba: pointer to lpfc hba data structure.
12039 *
12040 * This routine is invoked to request for rediscovery of the entire FCF table
12041 * by the port.
12042 **/
12043int
12044lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
12045{
12046 LPFC_MBOXQ_t *mbox;
12047 struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
12048 int rc, length;
12049
12050 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
12051 if (!mbox) {
12052 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
12053 "2745 Failed to allocate mbox for "
12054 "requesting FCF rediscover.\n");
12055 return -ENOMEM;
12056 }
12057
12058 length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
12059 sizeof(struct lpfc_sli4_cfg_mhdr));
12060 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
12061 LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
12062 length, LPFC_SLI4_MBX_EMBED);
12063
12064 redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
12065 /* Set count to 0 for invalidating the entire FCF database */
12066 bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
12067
12068 /* Issue the mailbox command asynchronously */
12069 mbox->vport = phba->pport;
12070 mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
12071 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
12072
12073 if (rc == MBX_NOT_FINISHED) {
12074 mempool_free(mbox, phba->mbox_mem_pool);
12075 return -EIO;
12076 }
12077 return 0;
12078}
12079
12080/**
11945 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled. 12081 * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
11946 * @phba: pointer to lpfc hba data structure. 12082 * @phba: pointer to lpfc hba data structure.
11947 * 12083 *
@@ -12069,3 +12205,48 @@ out:
12069 kfree(rgn23_data); 12205 kfree(rgn23_data);
12070 return; 12206 return;
12071} 12207}
12208
12209/**
12210 * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
12211 * @vport: pointer to vport data structure.
12212 *
12213 * This function iterate through the mailboxq and clean up all REG_LOGIN
12214 * and REG_VPI mailbox commands associated with the vport. This function
12215 * is called when driver want to restart discovery of the vport due to
12216 * a Clear Virtual Link event.
12217 **/
12218void
12219lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
12220{
12221 struct lpfc_hba *phba = vport->phba;
12222 LPFC_MBOXQ_t *mb, *nextmb;
12223 struct lpfc_dmabuf *mp;
12224
12225 spin_lock_irq(&phba->hbalock);
12226 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
12227 if (mb->vport != vport)
12228 continue;
12229
12230 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
12231 (mb->u.mb.mbxCommand != MBX_REG_VPI))
12232 continue;
12233
12234 if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
12235 mp = (struct lpfc_dmabuf *) (mb->context1);
12236 if (mp) {
12237 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
12238 kfree(mp);
12239 }
12240 }
12241 list_del(&mb->list);
12242 mempool_free(mb, phba->mbox_mem_pool);
12243 }
12244 mb = phba->sli.mbox_active;
12245 if (mb && (mb->vport == vport)) {
12246 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
12247 (mb->u.mb.mbxCommand == MBX_REG_VPI))
12248 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
12249 }
12250 spin_unlock_irq(&phba->hbalock);
12251}
12252
diff --git a/drivers/scsi/lpfc/lpfc_sli.h b/drivers/scsi/lpfc/lpfc_sli.h
index ba38de3c28f1..dfcf5437d1f5 100644
--- a/drivers/scsi/lpfc/lpfc_sli.h
+++ b/drivers/scsi/lpfc/lpfc_sli.h
@@ -53,17 +53,19 @@ struct lpfc_iocbq {
53 53
54 IOCB_t iocb; /* IOCB cmd */ 54 IOCB_t iocb; /* IOCB cmd */
55 uint8_t retry; /* retry counter for IOCB cmd - if needed */ 55 uint8_t retry; /* retry counter for IOCB cmd - if needed */
56 uint8_t iocb_flag; 56 uint16_t iocb_flag;
57#define LPFC_IO_LIBDFC 1 /* libdfc iocb */ 57#define LPFC_IO_LIBDFC 1 /* libdfc iocb */
58#define LPFC_IO_WAKE 2 /* High Priority Queue signal flag */ 58#define LPFC_IO_WAKE 2 /* High Priority Queue signal flag */
59#define LPFC_IO_FCP 4 /* FCP command -- iocbq in scsi_buf */ 59#define LPFC_IO_FCP 4 /* FCP command -- iocbq in scsi_buf */
60#define LPFC_DRIVER_ABORTED 8 /* driver aborted this request */ 60#define LPFC_DRIVER_ABORTED 8 /* driver aborted this request */
61#define LPFC_IO_FABRIC 0x10 /* Iocb send using fabric scheduler */ 61#define LPFC_IO_FABRIC 0x10 /* Iocb send using fabric scheduler */
62#define LPFC_DELAY_MEM_FREE 0x20 /* Defer free'ing of FC data */ 62#define LPFC_DELAY_MEM_FREE 0x20 /* Defer free'ing of FC data */
63#define LPFC_FIP_ELS_ID_MASK 0xc0 /* ELS_ID range 0-3 */ 63#define LPFC_EXCHANGE_BUSY 0x40 /* SLI4 hba reported XB in response */
64#define LPFC_FIP_ELS_ID_SHIFT 6 64#define LPFC_USE_FCPWQIDX 0x80 /* Submit to specified FCPWQ index */
65
66#define LPFC_FIP_ELS_ID_MASK 0xc000 /* ELS_ID range 0-3, non-shifted mask */
67#define LPFC_FIP_ELS_ID_SHIFT 14
65 68
66 uint8_t abort_count;
67 uint8_t rsvd2; 69 uint8_t rsvd2;
68 uint32_t drvrTimeout; /* driver timeout in seconds */ 70 uint32_t drvrTimeout; /* driver timeout in seconds */
69 uint32_t fcp_wqidx; /* index to FCP work queue */ 71 uint32_t fcp_wqidx; /* index to FCP work queue */
diff --git a/drivers/scsi/lpfc/lpfc_sli4.h b/drivers/scsi/lpfc/lpfc_sli4.h
index 44e5f574236b..86308836600f 100644
--- a/drivers/scsi/lpfc/lpfc_sli4.h
+++ b/drivers/scsi/lpfc/lpfc_sli4.h
@@ -22,6 +22,10 @@
22#define LPFC_RELEASE_NOTIFICATION_INTERVAL 32 22#define LPFC_RELEASE_NOTIFICATION_INTERVAL 32
23#define LPFC_GET_QE_REL_INT 32 23#define LPFC_GET_QE_REL_INT 32
24#define LPFC_RPI_LOW_WATER_MARK 10 24#define LPFC_RPI_LOW_WATER_MARK 10
25
26/* Amount of time in seconds for waiting FCF rediscovery to complete */
27#define LPFC_FCF_REDISCOVER_WAIT_TMO 2000 /* msec */
28
25/* Number of SGL entries can be posted in a 4KB nonembedded mbox command */ 29/* Number of SGL entries can be posted in a 4KB nonembedded mbox command */
26#define LPFC_NEMBED_MBOX_SGL_CNT 254 30#define LPFC_NEMBED_MBOX_SGL_CNT 254
27 31
@@ -126,24 +130,36 @@ struct lpfc_sli4_link {
126 uint8_t status; 130 uint8_t status;
127 uint8_t physical; 131 uint8_t physical;
128 uint8_t fault; 132 uint8_t fault;
133 uint16_t logical_speed;
129}; 134};
130 135
131struct lpfc_fcf { 136struct lpfc_fcf_rec {
132 uint8_t fabric_name[8]; 137 uint8_t fabric_name[8];
133 uint8_t switch_name[8]; 138 uint8_t switch_name[8];
134 uint8_t mac_addr[6]; 139 uint8_t mac_addr[6];
135 uint16_t fcf_indx; 140 uint16_t fcf_indx;
141 uint32_t priority;
142 uint16_t vlan_id;
143 uint32_t addr_mode;
144 uint32_t flag;
145#define BOOT_ENABLE 0x01
146#define RECORD_VALID 0x02
147};
148
149struct lpfc_fcf {
136 uint16_t fcfi; 150 uint16_t fcfi;
137 uint32_t fcf_flag; 151 uint32_t fcf_flag;
138#define FCF_AVAILABLE 0x01 /* FCF available for discovery */ 152#define FCF_AVAILABLE 0x01 /* FCF available for discovery */
139#define FCF_REGISTERED 0x02 /* FCF registered with FW */ 153#define FCF_REGISTERED 0x02 /* FCF registered with FW */
140#define FCF_DISCOVERED 0x04 /* FCF discovery started */ 154#define FCF_SCAN_DONE 0x04 /* FCF table scan done */
141#define FCF_BOOT_ENABLE 0x08 /* Boot bios use this FCF */ 155#define FCF_IN_USE 0x08 /* Atleast one discovery completed */
142#define FCF_IN_USE 0x10 /* Atleast one discovery completed */ 156#define FCF_REDISC_PEND 0x10 /* FCF rediscovery pending */
143#define FCF_VALID_VLAN 0x20 /* Use the vlan id specified */ 157#define FCF_REDISC_EVT 0x20 /* FCF rediscovery event to worker thread */
144 uint32_t priority; 158#define FCF_REDISC_FOV 0x40 /* Post FCF rediscovery fast failover */
145 uint32_t addr_mode; 159 uint32_t addr_mode;
146 uint16_t vlan_id; 160 struct lpfc_fcf_rec current_rec;
161 struct lpfc_fcf_rec failover_rec;
162 struct timer_list redisc_wait;
147}; 163};
148 164
149#define LPFC_REGION23_SIGNATURE "RG23" 165#define LPFC_REGION23_SIGNATURE "RG23"
@@ -248,7 +264,10 @@ struct lpfc_bmbx {
248#define SLI4_CT_VFI 2 264#define SLI4_CT_VFI 2
249#define SLI4_CT_FCFI 3 265#define SLI4_CT_FCFI 3
250 266
251#define LPFC_SLI4_MAX_SEGMENT_SIZE 0x10000 267#define LPFC_SLI4_FL1_MAX_SEGMENT_SIZE 0x10000
268#define LPFC_SLI4_FL1_MAX_BUF_SIZE 0X2000
269#define LPFC_SLI4_MIN_BUF_SIZE 0x400
270#define LPFC_SLI4_MAX_BUF_SIZE 0x20000
252 271
253/* 272/*
254 * SLI4 specific data structures 273 * SLI4 specific data structures
@@ -282,6 +301,42 @@ struct lpfc_fcp_eq_hdl {
282 struct lpfc_hba *phba; 301 struct lpfc_hba *phba;
283}; 302};
284 303
304/* Port Capabilities for SLI4 Parameters */
305struct lpfc_pc_sli4_params {
306 uint32_t supported;
307 uint32_t if_type;
308 uint32_t sli_rev;
309 uint32_t sli_family;
310 uint32_t featurelevel_1;
311 uint32_t featurelevel_2;
312 uint32_t proto_types;
313#define LPFC_SLI4_PROTO_FCOE 0x0000001
314#define LPFC_SLI4_PROTO_FC 0x0000002
315#define LPFC_SLI4_PROTO_NIC 0x0000004
316#define LPFC_SLI4_PROTO_ISCSI 0x0000008
317#define LPFC_SLI4_PROTO_RDMA 0x0000010
318 uint32_t sge_supp_len;
319 uint32_t if_page_sz;
320 uint32_t rq_db_window;
321 uint32_t loopbk_scope;
322 uint32_t eq_pages_max;
323 uint32_t eqe_size;
324 uint32_t cq_pages_max;
325 uint32_t cqe_size;
326 uint32_t mq_pages_max;
327 uint32_t mqe_size;
328 uint32_t mq_elem_cnt;
329 uint32_t wq_pages_max;
330 uint32_t wqe_size;
331 uint32_t rq_pages_max;
332 uint32_t rqe_size;
333 uint32_t hdr_pages_max;
334 uint32_t hdr_size;
335 uint32_t hdr_pp_align;
336 uint32_t sgl_pages_max;
337 uint32_t sgl_pp_align;
338};
339
285/* SLI4 HBA data structure entries */ 340/* SLI4 HBA data structure entries */
286struct lpfc_sli4_hba { 341struct lpfc_sli4_hba {
287 void __iomem *conf_regs_memmap_p; /* Kernel memory mapped address for 342 void __iomem *conf_regs_memmap_p; /* Kernel memory mapped address for
@@ -295,7 +350,7 @@ struct lpfc_sli4_hba {
295 void __iomem *UERRHIregaddr; /* Address to UERR_STATUS_HI register */ 350 void __iomem *UERRHIregaddr; /* Address to UERR_STATUS_HI register */
296 void __iomem *UEMASKLOregaddr; /* Address to UE_MASK_LO register */ 351 void __iomem *UEMASKLOregaddr; /* Address to UE_MASK_LO register */
297 void __iomem *UEMASKHIregaddr; /* Address to UE_MASK_HI register */ 352 void __iomem *UEMASKHIregaddr; /* Address to UE_MASK_HI register */
298 void __iomem *SCRATCHPADregaddr; /* Address to scratchpad register */ 353 void __iomem *SLIINTFregaddr; /* Address to SLI_INTF register */
299 /* BAR1 FCoE function CSR register memory map */ 354 /* BAR1 FCoE function CSR register memory map */
300 void __iomem *STAregaddr; /* Address to HST_STATE register */ 355 void __iomem *STAregaddr; /* Address to HST_STATE register */
301 void __iomem *ISRregaddr; /* Address to HST_ISR register */ 356 void __iomem *ISRregaddr; /* Address to HST_ISR register */
@@ -310,6 +365,8 @@ struct lpfc_sli4_hba {
310 365
311 uint32_t ue_mask_lo; 366 uint32_t ue_mask_lo;
312 uint32_t ue_mask_hi; 367 uint32_t ue_mask_hi;
368 struct lpfc_register sli_intf;
369 struct lpfc_pc_sli4_params pc_sli4_params;
313 struct msix_entry *msix_entries; 370 struct msix_entry *msix_entries;
314 uint32_t cfg_eqn; 371 uint32_t cfg_eqn;
315 struct lpfc_fcp_eq_hdl *fcp_eq_hdl; /* FCP per-WQ handle */ 372 struct lpfc_fcp_eq_hdl *fcp_eq_hdl; /* FCP per-WQ handle */
@@ -406,6 +463,8 @@ void lpfc_sli4_mbox_cmd_free(struct lpfc_hba *, struct lpfcMboxq *);
406void lpfc_sli4_mbx_sge_set(struct lpfcMboxq *, uint32_t, dma_addr_t, uint32_t); 463void lpfc_sli4_mbx_sge_set(struct lpfcMboxq *, uint32_t, dma_addr_t, uint32_t);
407void lpfc_sli4_mbx_sge_get(struct lpfcMboxq *, uint32_t, 464void lpfc_sli4_mbx_sge_get(struct lpfcMboxq *, uint32_t,
408 struct lpfc_mbx_sge *); 465 struct lpfc_mbx_sge *);
466int lpfc_sli4_mbx_read_fcf_record(struct lpfc_hba *, struct lpfcMboxq *,
467 uint16_t);
409 468
410void lpfc_sli4_hba_reset(struct lpfc_hba *); 469void lpfc_sli4_hba_reset(struct lpfc_hba *);
411struct lpfc_queue *lpfc_sli4_queue_alloc(struct lpfc_hba *, uint32_t, 470struct lpfc_queue *lpfc_sli4_queue_alloc(struct lpfc_hba *, uint32_t,
@@ -448,6 +507,7 @@ int lpfc_sli4_alloc_rpi(struct lpfc_hba *);
448void lpfc_sli4_free_rpi(struct lpfc_hba *, int); 507void lpfc_sli4_free_rpi(struct lpfc_hba *, int);
449void lpfc_sli4_remove_rpis(struct lpfc_hba *); 508void lpfc_sli4_remove_rpis(struct lpfc_hba *);
450void lpfc_sli4_async_event_proc(struct lpfc_hba *); 509void lpfc_sli4_async_event_proc(struct lpfc_hba *);
510void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *);
451int lpfc_sli4_resume_rpi(struct lpfc_nodelist *); 511int lpfc_sli4_resume_rpi(struct lpfc_nodelist *);
452void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *); 512void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *);
453void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *); 513void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *);
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index 792f72263f1a..ac276aa46fba 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2010 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -18,7 +18,7 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_DRIVER_VERSION "8.3.7" 21#define LPFC_DRIVER_VERSION "8.3.9"
22#define LPFC_DRIVER_NAME "lpfc" 22#define LPFC_DRIVER_NAME "lpfc"
23#define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp" 23#define LPFC_SP_DRIVER_HANDLER_NAME "lpfc:sp"
24#define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp" 24#define LPFC_FP_DRIVER_HANDLER_NAME "lpfc:fp"
diff --git a/drivers/scsi/lpfc/lpfc_vport.c b/drivers/scsi/lpfc/lpfc_vport.c
index e3c7fa642306..dc86e873102a 100644
--- a/drivers/scsi/lpfc/lpfc_vport.c
+++ b/drivers/scsi/lpfc/lpfc_vport.c
@@ -389,7 +389,7 @@ lpfc_vport_create(struct fc_vport *fc_vport, bool disable)
389 * by the port. 389 * by the port.
390 */ 390 */
391 if ((phba->sli_rev == LPFC_SLI_REV4) && 391 if ((phba->sli_rev == LPFC_SLI_REV4) &&
392 (pport->vpi_state & LPFC_VPI_REGISTERED)) { 392 (pport->fc_flag & FC_VFI_REGISTERED)) {
393 rc = lpfc_sli4_init_vpi(phba, vpi); 393 rc = lpfc_sli4_init_vpi(phba, vpi);
394 if (rc) { 394 if (rc) {
395 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT, 395 lpfc_printf_log(phba, KERN_ERR, LOG_VPORT,
@@ -505,6 +505,7 @@ enable_vport(struct fc_vport *fc_vport)
505 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; 505 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
506 struct lpfc_hba *phba = vport->phba; 506 struct lpfc_hba *phba = vport->phba;
507 struct lpfc_nodelist *ndlp = NULL; 507 struct lpfc_nodelist *ndlp = NULL;
508 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
508 509
509 if ((phba->link_state < LPFC_LINK_UP) || 510 if ((phba->link_state < LPFC_LINK_UP) ||
510 (phba->fc_topology == TOPOLOGY_LOOP)) { 511 (phba->fc_topology == TOPOLOGY_LOOP)) {
@@ -512,10 +513,10 @@ enable_vport(struct fc_vport *fc_vport)
512 return VPORT_OK; 513 return VPORT_OK;
513 } 514 }
514 515
515 spin_lock_irq(&phba->hbalock); 516 spin_lock_irq(shost->host_lock);
516 vport->load_flag |= FC_LOADING; 517 vport->load_flag |= FC_LOADING;
517 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; 518 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
518 spin_unlock_irq(&phba->hbalock); 519 spin_unlock_irq(shost->host_lock);
519 520
520 /* Use the Physical nodes Fabric NDLP to determine if the link is 521 /* Use the Physical nodes Fabric NDLP to determine if the link is
521 * up and ready to FDISC. 522 * up and ready to FDISC.
diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c
index c24e86f07804..4a90eaf7cb63 100644
--- a/drivers/scsi/mac_esp.c
+++ b/drivers/scsi/mac_esp.c
@@ -22,7 +22,6 @@
22 22
23#include <asm/irq.h> 23#include <asm/irq.h>
24#include <asm/dma.h> 24#include <asm/dma.h>
25
26#include <asm/macints.h> 25#include <asm/macints.h>
27#include <asm/macintosh.h> 26#include <asm/macintosh.h>
28 27
@@ -53,7 +52,6 @@ struct mac_esp_priv {
53 void __iomem *pdma_io; 52 void __iomem *pdma_io;
54 int error; 53 int error;
55}; 54};
56static struct platform_device *internal_pdev, *external_pdev;
57static struct esp *esp_chips[2]; 55static struct esp *esp_chips[2];
58 56
59#define MAC_ESP_GET_PRIV(esp) ((struct mac_esp_priv *) \ 57#define MAC_ESP_GET_PRIV(esp) ((struct mac_esp_priv *) \
@@ -279,24 +277,27 @@ static void mac_esp_send_pdma_cmd(struct esp *esp, u32 addr, u32 esp_count,
279 * Programmed IO routines follow. 277 * Programmed IO routines follow.
280 */ 278 */
281 279
282static inline int mac_esp_wait_for_fifo(struct esp *esp) 280static inline unsigned int mac_esp_wait_for_fifo(struct esp *esp)
283{ 281{
284 int i = 500000; 282 int i = 500000;
285 283
286 do { 284 do {
287 if (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES) 285 unsigned int fbytes = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
288 return 0; 286
287 if (fbytes)
288 return fbytes;
289 289
290 udelay(2); 290 udelay(2);
291 } while (--i); 291 } while (--i);
292 292
293 printk(KERN_ERR PFX "FIFO is empty (sreg %02x)\n", 293 printk(KERN_ERR PFX "FIFO is empty (sreg %02x)\n",
294 esp_read8(ESP_STATUS)); 294 esp_read8(ESP_STATUS));
295 return 1; 295 return 0;
296} 296}
297 297
298static inline int mac_esp_wait_for_intr(struct esp *esp) 298static inline int mac_esp_wait_for_intr(struct esp *esp)
299{ 299{
300 struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp);
300 int i = 500000; 301 int i = 500000;
301 302
302 do { 303 do {
@@ -308,6 +309,7 @@ static inline int mac_esp_wait_for_intr(struct esp *esp)
308 } while (--i); 309 } while (--i);
309 310
310 printk(KERN_ERR PFX "IRQ timeout (sreg %02x)\n", esp->sreg); 311 printk(KERN_ERR PFX "IRQ timeout (sreg %02x)\n", esp->sreg);
312 mep->error = 1;
311 return 1; 313 return 1;
312} 314}
313 315
@@ -347,11 +349,10 @@ static inline int mac_esp_wait_for_intr(struct esp *esp)
347static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count, 349static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
348 u32 dma_count, int write, u8 cmd) 350 u32 dma_count, int write, u8 cmd)
349{ 351{
350 unsigned long flags;
351 struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp); 352 struct mac_esp_priv *mep = MAC_ESP_GET_PRIV(esp);
352 u8 *fifo = esp->regs + ESP_FDATA * 16; 353 u8 *fifo = esp->regs + ESP_FDATA * 16;
353 354
354 local_irq_save(flags); 355 disable_irq(esp->host->irq);
355 356
356 cmd &= ~ESP_CMD_DMA; 357 cmd &= ~ESP_CMD_DMA;
357 mep->error = 0; 358 mep->error = 0;
@@ -359,11 +360,35 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
359 if (write) { 360 if (write) {
360 scsi_esp_cmd(esp, cmd); 361 scsi_esp_cmd(esp, cmd);
361 362
362 if (!mac_esp_wait_for_intr(esp)) { 363 while (1) {
363 if (mac_esp_wait_for_fifo(esp)) 364 unsigned int n;
364 esp_count = 0; 365
365 } else { 366 n = mac_esp_wait_for_fifo(esp);
366 esp_count = 0; 367 if (!n)
368 break;
369
370 if (n > esp_count)
371 n = esp_count;
372 esp_count -= n;
373
374 MAC_ESP_PIO_LOOP("%2@,%0@+", n);
375
376 if (!esp_count)
377 break;
378
379 if (mac_esp_wait_for_intr(esp))
380 break;
381
382 if (((esp->sreg & ESP_STAT_PMASK) != ESP_DIP) &&
383 ((esp->sreg & ESP_STAT_PMASK) != ESP_MIP))
384 break;
385
386 esp->ireg = esp_read8(ESP_INTRPT);
387 if ((esp->ireg & (ESP_INTR_DC | ESP_INTR_BSERV)) !=
388 ESP_INTR_BSERV)
389 break;
390
391 scsi_esp_cmd(esp, ESP_CMD_TI);
367 } 392 }
368 } else { 393 } else {
369 scsi_esp_cmd(esp, ESP_CMD_FLUSH); 394 scsi_esp_cmd(esp, ESP_CMD_FLUSH);
@@ -374,47 +399,24 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
374 MAC_ESP_PIO_LOOP("%0@+,%2@", esp_count); 399 MAC_ESP_PIO_LOOP("%0@+,%2@", esp_count);
375 400
376 scsi_esp_cmd(esp, cmd); 401 scsi_esp_cmd(esp, cmd);
377 }
378
379 while (esp_count) {
380 unsigned int n;
381 402
382 if (mac_esp_wait_for_intr(esp)) { 403 while (esp_count) {
383 mep->error = 1; 404 unsigned int n;
384 break;
385 }
386
387 if (esp->sreg & ESP_STAT_SPAM) {
388 printk(KERN_ERR PFX "gross error\n");
389 mep->error = 1;
390 break;
391 }
392
393 n = esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES;
394
395 if (write) {
396 if (n > esp_count)
397 n = esp_count;
398 esp_count -= n;
399
400 MAC_ESP_PIO_LOOP("%2@,%0@+", n);
401 405
402 if ((esp->sreg & ESP_STAT_PMASK) == ESP_STATP) 406 if (mac_esp_wait_for_intr(esp))
403 break; 407 break;
404 408
405 if (esp_count) { 409 if (((esp->sreg & ESP_STAT_PMASK) != ESP_DOP) &&
406 esp->ireg = esp_read8(ESP_INTRPT); 410 ((esp->sreg & ESP_STAT_PMASK) != ESP_MOP))
407 if (esp->ireg & ESP_INTR_DC) 411 break;
408 break;
409 412
410 scsi_esp_cmd(esp, ESP_CMD_TI);
411 }
412 } else {
413 esp->ireg = esp_read8(ESP_INTRPT); 413 esp->ireg = esp_read8(ESP_INTRPT);
414 if (esp->ireg & ESP_INTR_DC) 414 if ((esp->ireg & (ESP_INTR_DC | ESP_INTR_BSERV)) !=
415 ESP_INTR_BSERV)
415 break; 416 break;
416 417
417 n = MAC_ESP_FIFO_SIZE - n; 418 n = MAC_ESP_FIFO_SIZE -
419 (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES);
418 if (n > esp_count) 420 if (n > esp_count)
419 n = esp_count; 421 n = esp_count;
420 422
@@ -429,7 +431,7 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count,
429 } 431 }
430 } 432 }
431 433
432 local_irq_restore(flags); 434 enable_irq(esp->host->irq);
433} 435}
434 436
435static int mac_esp_irq_pending(struct esp *esp) 437static int mac_esp_irq_pending(struct esp *esp)
@@ -492,29 +494,12 @@ static int __devinit esp_mac_probe(struct platform_device *dev)
492 struct Scsi_Host *host; 494 struct Scsi_Host *host;
493 struct esp *esp; 495 struct esp *esp;
494 int err; 496 int err;
495 int chips_present;
496 struct mac_esp_priv *mep; 497 struct mac_esp_priv *mep;
497 498
498 if (!MACH_IS_MAC) 499 if (!MACH_IS_MAC)
499 return -ENODEV; 500 return -ENODEV;
500 501
501 switch (macintosh_config->scsi_type) { 502 if (dev->id > 1)
502 case MAC_SCSI_QUADRA:
503 case MAC_SCSI_QUADRA3:
504 chips_present = 1;
505 break;
506 case MAC_SCSI_QUADRA2:
507 if ((macintosh_config->ident == MAC_MODEL_Q900) ||
508 (macintosh_config->ident == MAC_MODEL_Q950))
509 chips_present = 2;
510 else
511 chips_present = 1;
512 break;
513 default:
514 chips_present = 0;
515 }
516
517 if (dev->id + 1 > chips_present)
518 return -ENODEV; 503 return -ENODEV;
519 504
520 host = scsi_host_alloc(tpnt, sizeof(struct esp)); 505 host = scsi_host_alloc(tpnt, sizeof(struct esp));
@@ -639,55 +624,26 @@ static struct platform_driver esp_mac_driver = {
639 .probe = esp_mac_probe, 624 .probe = esp_mac_probe,
640 .remove = __devexit_p(esp_mac_remove), 625 .remove = __devexit_p(esp_mac_remove),
641 .driver = { 626 .driver = {
642 .name = DRV_MODULE_NAME, 627 .name = DRV_MODULE_NAME,
628 .owner = THIS_MODULE,
643 }, 629 },
644}; 630};
645 631
646static int __init mac_esp_init(void) 632static int __init mac_esp_init(void)
647{ 633{
648 int err; 634 return platform_driver_register(&esp_mac_driver);
649
650 err = platform_driver_register(&esp_mac_driver);
651 if (err)
652 return err;
653
654 internal_pdev = platform_device_alloc(DRV_MODULE_NAME, 0);
655 if (internal_pdev && platform_device_add(internal_pdev)) {
656 platform_device_put(internal_pdev);
657 internal_pdev = NULL;
658 }
659 external_pdev = platform_device_alloc(DRV_MODULE_NAME, 1);
660 if (external_pdev && platform_device_add(external_pdev)) {
661 platform_device_put(external_pdev);
662 external_pdev = NULL;
663 }
664
665 if (internal_pdev || external_pdev) {
666 return 0;
667 } else {
668 platform_driver_unregister(&esp_mac_driver);
669 return -ENOMEM;
670 }
671} 635}
672 636
673static void __exit mac_esp_exit(void) 637static void __exit mac_esp_exit(void)
674{ 638{
675 platform_driver_unregister(&esp_mac_driver); 639 platform_driver_unregister(&esp_mac_driver);
676
677 if (internal_pdev) {
678 platform_device_unregister(internal_pdev);
679 internal_pdev = NULL;
680 }
681 if (external_pdev) {
682 platform_device_unregister(external_pdev);
683 external_pdev = NULL;
684 }
685} 640}
686 641
687MODULE_DESCRIPTION("Mac ESP SCSI driver"); 642MODULE_DESCRIPTION("Mac ESP SCSI driver");
688MODULE_AUTHOR("Finn Thain <fthain@telegraphics.com.au>"); 643MODULE_AUTHOR("Finn Thain <fthain@telegraphics.com.au>");
689MODULE_LICENSE("GPL v2"); 644MODULE_LICENSE("GPL v2");
690MODULE_VERSION(DRV_VERSION); 645MODULE_VERSION(DRV_VERSION);
646MODULE_ALIAS("platform:" DRV_MODULE_NAME);
691 647
692module_init(mac_esp_init); 648module_init(mac_esp_init);
693module_exit(mac_esp_exit); 649module_exit(mac_esp_exit);
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 708ea3157b60..409648f5845f 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -10,7 +10,7 @@
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.04.12-rc1 13 * Version : v00.00.04.17.1-rc1
14 * 14 *
15 * Authors: 15 * Authors:
16 * (email-id : megaraidlinux@lsi.com) 16 * (email-id : megaraidlinux@lsi.com)
@@ -843,6 +843,7 @@ megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp,
843 pthru->lun = scp->device->lun; 843 pthru->lun = scp->device->lun;
844 pthru->cdb_len = scp->cmd_len; 844 pthru->cdb_len = scp->cmd_len;
845 pthru->timeout = 0; 845 pthru->timeout = 0;
846 pthru->pad_0 = 0;
846 pthru->flags = flags; 847 pthru->flags = flags;
847 pthru->data_xfer_len = scsi_bufflen(scp); 848 pthru->data_xfer_len = scsi_bufflen(scp);
848 849
@@ -874,6 +875,12 @@ megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp,
874 pthru->sge_count = megasas_make_sgl32(instance, scp, 875 pthru->sge_count = megasas_make_sgl32(instance, scp,
875 &pthru->sgl); 876 &pthru->sgl);
876 877
878 if (pthru->sge_count > instance->max_num_sge) {
879 printk(KERN_ERR "megasas: DCDB two many SGE NUM=%x\n",
880 pthru->sge_count);
881 return 0;
882 }
883
877 /* 884 /*
878 * Sense info specific 885 * Sense info specific
879 */ 886 */
@@ -1000,6 +1007,12 @@ megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp,
1000 } else 1007 } else
1001 ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); 1008 ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl);
1002 1009
1010 if (ldio->sge_count > instance->max_num_sge) {
1011 printk(KERN_ERR "megasas: build_ld_io: sge_count = %x\n",
1012 ldio->sge_count);
1013 return 0;
1014 }
1015
1003 /* 1016 /*
1004 * Sense info specific 1017 * Sense info specific
1005 */ 1018 */
@@ -2250,6 +2263,7 @@ megasas_get_pd_list(struct megasas_instance *instance)
2250 dcmd->sge_count = 1; 2263 dcmd->sge_count = 1;
2251 dcmd->flags = MFI_FRAME_DIR_READ; 2264 dcmd->flags = MFI_FRAME_DIR_READ;
2252 dcmd->timeout = 0; 2265 dcmd->timeout = 0;
2266 dcmd->pad_0 = 0;
2253 dcmd->data_xfer_len = MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST); 2267 dcmd->data_xfer_len = MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST);
2254 dcmd->opcode = MR_DCMD_PD_LIST_QUERY; 2268 dcmd->opcode = MR_DCMD_PD_LIST_QUERY;
2255 dcmd->sgl.sge32[0].phys_addr = ci_h; 2269 dcmd->sgl.sge32[0].phys_addr = ci_h;
@@ -2294,6 +2308,86 @@ megasas_get_pd_list(struct megasas_instance *instance)
2294 return ret; 2308 return ret;
2295} 2309}
2296 2310
2311/*
2312 * megasas_get_ld_list_info - Returns FW's ld_list structure
2313 * @instance: Adapter soft state
2314 * @ld_list: ld_list structure
2315 *
2316 * Issues an internal command (DCMD) to get the FW's controller PD
2317 * list structure. This information is mainly used to find out SYSTEM
2318 * supported by the FW.
2319 */
2320static int
2321megasas_get_ld_list(struct megasas_instance *instance)
2322{
2323 int ret = 0, ld_index = 0, ids = 0;
2324 struct megasas_cmd *cmd;
2325 struct megasas_dcmd_frame *dcmd;
2326 struct MR_LD_LIST *ci;
2327 dma_addr_t ci_h = 0;
2328
2329 cmd = megasas_get_cmd(instance);
2330
2331 if (!cmd) {
2332 printk(KERN_DEBUG "megasas_get_ld_list: Failed to get cmd\n");
2333 return -ENOMEM;
2334 }
2335
2336 dcmd = &cmd->frame->dcmd;
2337
2338 ci = pci_alloc_consistent(instance->pdev,
2339 sizeof(struct MR_LD_LIST),
2340 &ci_h);
2341
2342 if (!ci) {
2343 printk(KERN_DEBUG "Failed to alloc mem in get_ld_list\n");
2344 megasas_return_cmd(instance, cmd);
2345 return -ENOMEM;
2346 }
2347
2348 memset(ci, 0, sizeof(*ci));
2349 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
2350
2351 dcmd->cmd = MFI_CMD_DCMD;
2352 dcmd->cmd_status = 0xFF;
2353 dcmd->sge_count = 1;
2354 dcmd->flags = MFI_FRAME_DIR_READ;
2355 dcmd->timeout = 0;
2356 dcmd->data_xfer_len = sizeof(struct MR_LD_LIST);
2357 dcmd->opcode = MR_DCMD_LD_GET_LIST;
2358 dcmd->sgl.sge32[0].phys_addr = ci_h;
2359 dcmd->sgl.sge32[0].length = sizeof(struct MR_LD_LIST);
2360 dcmd->pad_0 = 0;
2361
2362 if (!megasas_issue_polled(instance, cmd)) {
2363 ret = 0;
2364 } else {
2365 ret = -1;
2366 }
2367
2368 /* the following function will get the instance PD LIST */
2369
2370 if ((ret == 0) && (ci->ldCount < MAX_LOGICAL_DRIVES)) {
2371 memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
2372
2373 for (ld_index = 0; ld_index < ci->ldCount; ld_index++) {
2374 if (ci->ldList[ld_index].state != 0) {
2375 ids = ci->ldList[ld_index].ref.targetId;
2376 instance->ld_ids[ids] =
2377 ci->ldList[ld_index].ref.targetId;
2378 }
2379 }
2380 }
2381
2382 pci_free_consistent(instance->pdev,
2383 sizeof(struct MR_LD_LIST),
2384 ci,
2385 ci_h);
2386
2387 megasas_return_cmd(instance, cmd);
2388 return ret;
2389}
2390
2297/** 2391/**
2298 * megasas_get_controller_info - Returns FW's controller structure 2392 * megasas_get_controller_info - Returns FW's controller structure
2299 * @instance: Adapter soft state 2393 * @instance: Adapter soft state
@@ -2339,6 +2433,7 @@ megasas_get_ctrl_info(struct megasas_instance *instance,
2339 dcmd->sge_count = 1; 2433 dcmd->sge_count = 1;
2340 dcmd->flags = MFI_FRAME_DIR_READ; 2434 dcmd->flags = MFI_FRAME_DIR_READ;
2341 dcmd->timeout = 0; 2435 dcmd->timeout = 0;
2436 dcmd->pad_0 = 0;
2342 dcmd->data_xfer_len = sizeof(struct megasas_ctrl_info); 2437 dcmd->data_xfer_len = sizeof(struct megasas_ctrl_info);
2343 dcmd->opcode = MR_DCMD_CTRL_GET_INFO; 2438 dcmd->opcode = MR_DCMD_CTRL_GET_INFO;
2344 dcmd->sgl.sge32[0].phys_addr = ci_h; 2439 dcmd->sgl.sge32[0].phys_addr = ci_h;
@@ -2590,6 +2685,9 @@ static int megasas_init_mfi(struct megasas_instance *instance)
2590 (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); 2685 (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)));
2591 megasas_get_pd_list(instance); 2686 megasas_get_pd_list(instance);
2592 2687
2688 memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
2689 megasas_get_ld_list(instance);
2690
2593 ctrl_info = kmalloc(sizeof(struct megasas_ctrl_info), GFP_KERNEL); 2691 ctrl_info = kmalloc(sizeof(struct megasas_ctrl_info), GFP_KERNEL);
2594 2692
2595 /* 2693 /*
@@ -2714,6 +2812,7 @@ megasas_get_seq_num(struct megasas_instance *instance,
2714 dcmd->sge_count = 1; 2812 dcmd->sge_count = 1;
2715 dcmd->flags = MFI_FRAME_DIR_READ; 2813 dcmd->flags = MFI_FRAME_DIR_READ;
2716 dcmd->timeout = 0; 2814 dcmd->timeout = 0;
2815 dcmd->pad_0 = 0;
2717 dcmd->data_xfer_len = sizeof(struct megasas_evt_log_info); 2816 dcmd->data_xfer_len = sizeof(struct megasas_evt_log_info);
2718 dcmd->opcode = MR_DCMD_CTRL_EVENT_GET_INFO; 2817 dcmd->opcode = MR_DCMD_CTRL_EVENT_GET_INFO;
2719 dcmd->sgl.sge32[0].phys_addr = el_info_h; 2818 dcmd->sgl.sge32[0].phys_addr = el_info_h;
@@ -2828,6 +2927,7 @@ megasas_register_aen(struct megasas_instance *instance, u32 seq_num,
2828 dcmd->sge_count = 1; 2927 dcmd->sge_count = 1;
2829 dcmd->flags = MFI_FRAME_DIR_READ; 2928 dcmd->flags = MFI_FRAME_DIR_READ;
2830 dcmd->timeout = 0; 2929 dcmd->timeout = 0;
2930 dcmd->pad_0 = 0;
2831 dcmd->data_xfer_len = sizeof(struct megasas_evt_detail); 2931 dcmd->data_xfer_len = sizeof(struct megasas_evt_detail);
2832 dcmd->opcode = MR_DCMD_CTRL_EVENT_WAIT; 2932 dcmd->opcode = MR_DCMD_CTRL_EVENT_WAIT;
2833 dcmd->mbox.w[0] = seq_num; 2933 dcmd->mbox.w[0] = seq_num;
@@ -3166,6 +3266,7 @@ static void megasas_flush_cache(struct megasas_instance *instance)
3166 dcmd->sge_count = 0; 3266 dcmd->sge_count = 0;
3167 dcmd->flags = MFI_FRAME_DIR_NONE; 3267 dcmd->flags = MFI_FRAME_DIR_NONE;
3168 dcmd->timeout = 0; 3268 dcmd->timeout = 0;
3269 dcmd->pad_0 = 0;
3169 dcmd->data_xfer_len = 0; 3270 dcmd->data_xfer_len = 0;
3170 dcmd->opcode = MR_DCMD_CTRL_CACHE_FLUSH; 3271 dcmd->opcode = MR_DCMD_CTRL_CACHE_FLUSH;
3171 dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; 3272 dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE;
@@ -3205,6 +3306,7 @@ static void megasas_shutdown_controller(struct megasas_instance *instance,
3205 dcmd->sge_count = 0; 3306 dcmd->sge_count = 0;
3206 dcmd->flags = MFI_FRAME_DIR_NONE; 3307 dcmd->flags = MFI_FRAME_DIR_NONE;
3207 dcmd->timeout = 0; 3308 dcmd->timeout = 0;
3309 dcmd->pad_0 = 0;
3208 dcmd->data_xfer_len = 0; 3310 dcmd->data_xfer_len = 0;
3209 dcmd->opcode = opcode; 3311 dcmd->opcode = opcode;
3210 3312
@@ -3781,6 +3883,7 @@ static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg)
3781 compat_alloc_user_space(sizeof(struct megasas_iocpacket)); 3883 compat_alloc_user_space(sizeof(struct megasas_iocpacket));
3782 int i; 3884 int i;
3783 int error = 0; 3885 int error = 0;
3886 compat_uptr_t ptr;
3784 3887
3785 if (clear_user(ioc, sizeof(*ioc))) 3888 if (clear_user(ioc, sizeof(*ioc)))
3786 return -EFAULT; 3889 return -EFAULT;
@@ -3793,9 +3896,22 @@ static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg)
3793 copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) 3896 copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32)))
3794 return -EFAULT; 3897 return -EFAULT;
3795 3898
3796 for (i = 0; i < MAX_IOCTL_SGE; i++) { 3899 /*
3797 compat_uptr_t ptr; 3900 * The sense_ptr is used in megasas_mgmt_fw_ioctl only when
3901 * sense_len is not null, so prepare the 64bit value under
3902 * the same condition.
3903 */
3904 if (ioc->sense_len) {
3905 void __user **sense_ioc_ptr =
3906 (void __user **)(ioc->frame.raw + ioc->sense_off);
3907 compat_uptr_t *sense_cioc_ptr =
3908 (compat_uptr_t *)(cioc->frame.raw + cioc->sense_off);
3909 if (get_user(ptr, sense_cioc_ptr) ||
3910 put_user(compat_ptr(ptr), sense_ioc_ptr))
3911 return -EFAULT;
3912 }
3798 3913
3914 for (i = 0; i < MAX_IOCTL_SGE; i++) {
3799 if (get_user(ptr, &cioc->sgl[i].iov_base) || 3915 if (get_user(ptr, &cioc->sgl[i].iov_base) ||
3800 put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || 3916 put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) ||
3801 copy_in_user(&ioc->sgl[i].iov_len, 3917 copy_in_user(&ioc->sgl[i].iov_len,
@@ -3970,6 +4086,7 @@ megasas_aen_polling(struct work_struct *work)
3970 struct Scsi_Host *host; 4086 struct Scsi_Host *host;
3971 struct scsi_device *sdev1; 4087 struct scsi_device *sdev1;
3972 u16 pd_index = 0; 4088 u16 pd_index = 0;
4089 u16 ld_index = 0;
3973 int i, j, doscan = 0; 4090 int i, j, doscan = 0;
3974 u32 seq_num; 4091 u32 seq_num;
3975 int error; 4092 int error;
@@ -3985,8 +4102,124 @@ megasas_aen_polling(struct work_struct *work)
3985 4102
3986 switch (instance->evt_detail->code) { 4103 switch (instance->evt_detail->code) {
3987 case MR_EVT_PD_INSERTED: 4104 case MR_EVT_PD_INSERTED:
4105 if (megasas_get_pd_list(instance) == 0) {
4106 for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
4107 for (j = 0;
4108 j < MEGASAS_MAX_DEV_PER_CHANNEL;
4109 j++) {
4110
4111 pd_index =
4112 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
4113
4114 sdev1 =
4115 scsi_device_lookup(host, i, j, 0);
4116
4117 if (instance->pd_list[pd_index].driveState
4118 == MR_PD_STATE_SYSTEM) {
4119 if (!sdev1) {
4120 scsi_add_device(host, i, j, 0);
4121 }
4122
4123 if (sdev1)
4124 scsi_device_put(sdev1);
4125 }
4126 }
4127 }
4128 }
4129 doscan = 0;
4130 break;
4131
3988 case MR_EVT_PD_REMOVED: 4132 case MR_EVT_PD_REMOVED:
4133 if (megasas_get_pd_list(instance) == 0) {
4134 megasas_get_pd_list(instance);
4135 for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
4136 for (j = 0;
4137 j < MEGASAS_MAX_DEV_PER_CHANNEL;
4138 j++) {
4139
4140 pd_index =
4141 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
4142
4143 sdev1 =
4144 scsi_device_lookup(host, i, j, 0);
4145
4146 if (instance->pd_list[pd_index].driveState
4147 == MR_PD_STATE_SYSTEM) {
4148 if (sdev1) {
4149 scsi_device_put(sdev1);
4150 }
4151 } else {
4152 if (sdev1) {
4153 scsi_remove_device(sdev1);
4154 scsi_device_put(sdev1);
4155 }
4156 }
4157 }
4158 }
4159 }
4160 doscan = 0;
4161 break;
4162
4163 case MR_EVT_LD_OFFLINE:
4164 case MR_EVT_LD_DELETED:
4165 megasas_get_ld_list(instance);
4166 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
4167 for (j = 0;
4168 j < MEGASAS_MAX_DEV_PER_CHANNEL;
4169 j++) {
4170
4171 ld_index =
4172 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
4173
4174 sdev1 = scsi_device_lookup(host,
4175 i + MEGASAS_MAX_LD_CHANNELS,
4176 j,
4177 0);
4178
4179 if (instance->ld_ids[ld_index] != 0xff) {
4180 if (sdev1) {
4181 scsi_device_put(sdev1);
4182 }
4183 } else {
4184 if (sdev1) {
4185 scsi_remove_device(sdev1);
4186 scsi_device_put(sdev1);
4187 }
4188 }
4189 }
4190 }
4191 doscan = 0;
4192 break;
4193 case MR_EVT_LD_CREATED:
4194 megasas_get_ld_list(instance);
4195 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
4196 for (j = 0;
4197 j < MEGASAS_MAX_DEV_PER_CHANNEL;
4198 j++) {
4199 ld_index =
4200 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
4201
4202 sdev1 = scsi_device_lookup(host,
4203 i+MEGASAS_MAX_LD_CHANNELS,
4204 j, 0);
4205
4206 if (instance->ld_ids[ld_index] !=
4207 0xff) {
4208 if (!sdev1) {
4209 scsi_add_device(host,
4210 i + 2,
4211 j, 0);
4212 }
4213 }
4214 if (sdev1) {
4215 scsi_device_put(sdev1);
4216 }
4217 }
4218 }
4219 doscan = 0;
4220 break;
3989 case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: 4221 case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED:
4222 case MR_EVT_FOREIGN_CFG_IMPORTED:
3990 doscan = 1; 4223 doscan = 1;
3991 break; 4224 break;
3992 default: 4225 default:
@@ -4021,6 +4254,31 @@ megasas_aen_polling(struct work_struct *work)
4021 } 4254 }
4022 } 4255 }
4023 } 4256 }
4257
4258 megasas_get_ld_list(instance);
4259 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
4260 for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
4261 ld_index =
4262 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
4263
4264 sdev1 = scsi_device_lookup(host,
4265 i+MEGASAS_MAX_LD_CHANNELS, j, 0);
4266 if (instance->ld_ids[ld_index] != 0xff) {
4267 if (!sdev1) {
4268 scsi_add_device(host,
4269 i+2,
4270 j, 0);
4271 } else {
4272 scsi_device_put(sdev1);
4273 }
4274 } else {
4275 if (sdev1) {
4276 scsi_remove_device(sdev1);
4277 scsi_device_put(sdev1);
4278 }
4279 }
4280 }
4281 }
4024 } 4282 }
4025 4283
4026 if ( instance->aen_cmd != NULL ) { 4284 if ( instance->aen_cmd != NULL ) {
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 72b28e436e32..9d8b6bf605aa 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.04.12-rc1" 21#define MEGASAS_VERSION "00.00.04.17.1-rc1"
22#define MEGASAS_RELDATE "Sep. 17, 2009" 22#define MEGASAS_RELDATE "Oct. 29, 2009"
23#define MEGASAS_EXT_VERSION "Thu Sep. 17 11:41:51 PST 2009" 23#define MEGASAS_EXT_VERSION "Thu. Oct. 29, 11:41:51 PST 2009"
24 24
25/* 25/*
26 * Device IDs 26 * Device IDs
@@ -117,6 +117,7 @@
117#define MFI_CMD_STP 0x08 117#define MFI_CMD_STP 0x08
118 118
119#define MR_DCMD_CTRL_GET_INFO 0x01010000 119#define MR_DCMD_CTRL_GET_INFO 0x01010000
120#define MR_DCMD_LD_GET_LIST 0x03010000
120 121
121#define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000 122#define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000
122#define MR_FLUSH_CTRL_CACHE 0x01 123#define MR_FLUSH_CTRL_CACHE 0x01
@@ -349,6 +350,32 @@ struct megasas_pd_list {
349 u8 driveState; 350 u8 driveState;
350} __packed; 351} __packed;
351 352
353 /*
354 * defines the logical drive reference structure
355 */
356union MR_LD_REF {
357 struct {
358 u8 targetId;
359 u8 reserved;
360 u16 seqNum;
361 };
362 u32 ref;
363} __packed;
364
365/*
366 * defines the logical drive list structure
367 */
368struct MR_LD_LIST {
369 u32 ldCount;
370 u32 reserved;
371 struct {
372 union MR_LD_REF ref;
373 u8 state;
374 u8 reserved[3];
375 u64 size;
376 } ldList[MAX_LOGICAL_DRIVES];
377} __packed;
378
352/* 379/*
353 * SAS controller properties 380 * SAS controller properties
354 */ 381 */
@@ -637,6 +664,8 @@ struct megasas_ctrl_info {
637#define MEGASAS_MAX_LD 64 664#define MEGASAS_MAX_LD 64
638#define MEGASAS_MAX_PD (MEGASAS_MAX_PD_CHANNELS * \ 665#define MEGASAS_MAX_PD (MEGASAS_MAX_PD_CHANNELS * \
639 MEGASAS_MAX_DEV_PER_CHANNEL) 666 MEGASAS_MAX_DEV_PER_CHANNEL)
667#define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \
668 MEGASAS_MAX_DEV_PER_CHANNEL)
640 669
641#define MEGASAS_DBG_LVL 1 670#define MEGASAS_DBG_LVL 1
642 671
@@ -1187,6 +1216,7 @@ struct megasas_instance {
1187 struct megasas_register_set __iomem *reg_set; 1216 struct megasas_register_set __iomem *reg_set;
1188 1217
1189 struct megasas_pd_list pd_list[MEGASAS_MAX_PD]; 1218 struct megasas_pd_list pd_list[MEGASAS_MAX_PD];
1219 u8 ld_ids[MEGASAS_MAX_LD_IDS];
1190 s8 init_id; 1220 s8 init_id;
1191 1221
1192 u16 max_num_sge; 1222 u16 max_num_sge;
diff --git a/drivers/scsi/mpt2sas/Kconfig b/drivers/scsi/mpt2sas/Kconfig
index 70c4c2467dd8..ba8e128de238 100644
--- a/drivers/scsi/mpt2sas/Kconfig
+++ b/drivers/scsi/mpt2sas/Kconfig
@@ -44,6 +44,7 @@ config SCSI_MPT2SAS
44 tristate "LSI MPT Fusion SAS 2.0 Device Driver" 44 tristate "LSI MPT Fusion SAS 2.0 Device Driver"
45 depends on PCI && SCSI 45 depends on PCI && SCSI
46 select SCSI_SAS_ATTRS 46 select SCSI_SAS_ATTRS
47 select RAID_ATTRS
47 ---help--- 48 ---help---
48 This driver supports PCI-Express SAS 6Gb/s Host Adapters. 49 This driver supports PCI-Express SAS 6Gb/s Host Adapters.
49 50
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2.h b/drivers/scsi/mpt2sas/mpi/mpi2.h
index 914168105297..9958d847a88d 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2.h
@@ -8,7 +8,7 @@
8 * scatter/gather formats. 8 * scatter/gather formats.
9 * Creation Date: June 21, 2006 9 * Creation Date: June 21, 2006
10 * 10 *
11 * mpi2.h Version: 02.00.13 11 * mpi2.h Version: 02.00.14
12 * 12 *
13 * Version History 13 * Version History
14 * --------------- 14 * ---------------
@@ -53,6 +53,10 @@
53 * bytes reserved. 53 * bytes reserved.
54 * Added RAID Accelerator functionality. 54 * Added RAID Accelerator functionality.
55 * 07-30-09 02.00.13 Bumped MPI2_HEADER_VERSION_UNIT. 55 * 07-30-09 02.00.13 Bumped MPI2_HEADER_VERSION_UNIT.
56 * 10-28-09 02.00.14 Bumped MPI2_HEADER_VERSION_UNIT.
57 * Added MSI-x index mask and shift for Reply Post Host
58 * Index register.
59 * Added function code for Host Based Discovery Action.
56 * -------------------------------------------------------------------------- 60 * --------------------------------------------------------------------------
57 */ 61 */
58 62
@@ -78,7 +82,7 @@
78#define MPI2_VERSION_02_00 (0x0200) 82#define MPI2_VERSION_02_00 (0x0200)
79 83
80/* versioning for this MPI header set */ 84/* versioning for this MPI header set */
81#define MPI2_HEADER_VERSION_UNIT (0x0D) 85#define MPI2_HEADER_VERSION_UNIT (0x0E)
82#define MPI2_HEADER_VERSION_DEV (0x00) 86#define MPI2_HEADER_VERSION_DEV (0x00)
83#define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00) 87#define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00)
84#define MPI2_HEADER_VERSION_UNIT_SHIFT (8) 88#define MPI2_HEADER_VERSION_UNIT_SHIFT (8)
@@ -232,9 +236,12 @@ typedef volatile struct _MPI2_SYSTEM_INTERFACE_REGS
232#define MPI2_REPLY_FREE_HOST_INDEX_OFFSET (0x00000048) 236#define MPI2_REPLY_FREE_HOST_INDEX_OFFSET (0x00000048)
233 237
234/* 238/*
235 * Offset for the Reply Descriptor Post Queue 239 * Defines for the Reply Descriptor Post Queue
236 */ 240 */
237#define MPI2_REPLY_POST_HOST_INDEX_OFFSET (0x0000006C) 241#define MPI2_REPLY_POST_HOST_INDEX_OFFSET (0x0000006C)
242#define MPI2_REPLY_POST_HOST_INDEX_MASK (0x00FFFFFF)
243#define MPI2_RPHI_MSIX_INDEX_MASK (0xFF000000)
244#define MPI2_RPHI_MSIX_INDEX_SHIFT (24)
238 245
239/* 246/*
240 * Defines for the HCBSize and address 247 * Defines for the HCBSize and address
@@ -497,12 +504,13 @@ typedef union _MPI2_REPLY_DESCRIPTORS_UNION
497#define MPI2_FUNCTION_TARGET_CMD_BUF_BASE_POST (0x24) /* Target Command Buffer Post Base */ 504#define MPI2_FUNCTION_TARGET_CMD_BUF_BASE_POST (0x24) /* Target Command Buffer Post Base */
498#define MPI2_FUNCTION_TARGET_CMD_BUF_LIST_POST (0x25) /* Target Command Buffer Post List */ 505#define MPI2_FUNCTION_TARGET_CMD_BUF_LIST_POST (0x25) /* Target Command Buffer Post List */
499#define MPI2_FUNCTION_RAID_ACCELERATOR (0x2C) /* RAID Accelerator*/ 506#define MPI2_FUNCTION_RAID_ACCELERATOR (0x2C) /* RAID Accelerator*/
507/* Host Based Discovery Action */
508#define MPI2_FUNCTION_HOST_BASED_DISCOVERY_ACTION (0x2F)
500 509
501 510
502 511
503/* Doorbell functions */ 512/* Doorbell functions */
504#define MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET (0x40) 513#define MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET (0x40)
505/* #define MPI2_FUNCTION_IO_UNIT_RESET (0x41) */
506#define MPI2_FUNCTION_HANDSHAKE (0x42) 514#define MPI2_FUNCTION_HANDSHAKE (0x42)
507 515
508 516
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h b/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
index 1611c57a6fdf..cf0ac9f40c97 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
@@ -6,7 +6,7 @@
6 * Title: MPI Configuration messages and pages 6 * Title: MPI Configuration messages and pages
7 * Creation Date: November 10, 2006 7 * Creation Date: November 10, 2006
8 * 8 *
9 * mpi2_cnfg.h Version: 02.00.12 9 * mpi2_cnfg.h Version: 02.00.13
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -107,6 +107,8 @@
107 * to SAS Device Page 0 Flags field. 107 * to SAS Device Page 0 Flags field.
108 * Added PhyInfo defines for power condition. 108 * Added PhyInfo defines for power condition.
109 * Added Ethernet configuration pages. 109 * Added Ethernet configuration pages.
110 * 10-28-09 02.00.13 Added MPI2_IOUNITPAGE1_ENABLE_HOST_BASED_DISCOVERY.
111 * Added SAS PHY Page 4 structure and defines.
110 * -------------------------------------------------------------------------- 112 * --------------------------------------------------------------------------
111 */ 113 */
112 114
@@ -712,6 +714,7 @@ typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_1
712#define MPI2_IOUNITPAGE1_PAGEVERSION (0x04) 714#define MPI2_IOUNITPAGE1_PAGEVERSION (0x04)
713 715
714/* IO Unit Page 1 Flags defines */ 716/* IO Unit Page 1 Flags defines */
717#define MPI2_IOUNITPAGE1_ENABLE_HOST_BASED_DISCOVERY (0x00000800)
715#define MPI2_IOUNITPAGE1_MASK_SATA_WRITE_CACHE (0x00000600) 718#define MPI2_IOUNITPAGE1_MASK_SATA_WRITE_CACHE (0x00000600)
716#define MPI2_IOUNITPAGE1_ENABLE_SATA_WRITE_CACHE (0x00000000) 719#define MPI2_IOUNITPAGE1_ENABLE_SATA_WRITE_CACHE (0x00000000)
717#define MPI2_IOUNITPAGE1_DISABLE_SATA_WRITE_CACHE (0x00000200) 720#define MPI2_IOUNITPAGE1_DISABLE_SATA_WRITE_CACHE (0x00000200)
@@ -2291,6 +2294,26 @@ typedef struct _MPI2_CONFIG_PAGE_SAS_PHY_3 {
2291#define MPI2_SASPHY3_PAGEVERSION (0x00) 2294#define MPI2_SASPHY3_PAGEVERSION (0x00)
2292 2295
2293 2296
2297/* SAS PHY Page 4 */
2298
2299typedef struct _MPI2_CONFIG_PAGE_SAS_PHY_4 {
2300 MPI2_CONFIG_EXTENDED_PAGE_HEADER Header; /* 0x00 */
2301 U16 Reserved1; /* 0x08 */
2302 U8 Reserved2; /* 0x0A */
2303 U8 Flags; /* 0x0B */
2304 U8 InitialFrame[28]; /* 0x0C */
2305} MPI2_CONFIG_PAGE_SAS_PHY_4, MPI2_POINTER PTR_MPI2_CONFIG_PAGE_SAS_PHY_4,
2306 Mpi2SasPhyPage4_t, MPI2_POINTER pMpi2SasPhyPage4_t;
2307
2308#define MPI2_SASPHY4_PAGEVERSION (0x00)
2309
2310/* values for the Flags field */
2311#define MPI2_SASPHY4_FLAGS_FRAME_VALID (0x02)
2312#define MPI2_SASPHY4_FLAGS_SATA_FRAME (0x01)
2313
2314
2315
2316
2294/**************************************************************************** 2317/****************************************************************************
2295* SAS Port Config Pages 2318* SAS Port Config Pages
2296****************************************************************************/ 2319****************************************************************************/
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_history.txt b/drivers/scsi/mpt2sas/mpi/mpi2_history.txt
index 65fcaa31cb30..c4adf76b49d9 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_history.txt
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_history.txt
@@ -5,23 +5,24 @@
5 Copyright (c) 2000-2009 LSI Corporation. 5 Copyright (c) 2000-2009 LSI Corporation.
6 6
7 --------------------------------------- 7 ---------------------------------------
8 Header Set Release Version: 02.00.12 8 Header Set Release Version: 02.00.14
9 Header Set Release Date: 05-06-09 9 Header Set Release Date: 10-28-09
10 --------------------------------------- 10 ---------------------------------------
11 11
12 Filename Current version Prior version 12 Filename Current version Prior version
13 ---------- --------------- ------------- 13 ---------- --------------- -------------
14 mpi2.h 02.00.12 02.00.11 14 mpi2.h 02.00.14 02.00.13
15 mpi2_cnfg.h 02.00.11 02.00.10 15 mpi2_cnfg.h 02.00.13 02.00.12
16 mpi2_init.h 02.00.07 02.00.06 16 mpi2_init.h 02.00.08 02.00.07
17 mpi2_ioc.h 02.00.11 02.00.10 17 mpi2_ioc.h 02.00.13 02.00.12
18 mpi2_raid.h 02.00.03 02.00.03 18 mpi2_raid.h 02.00.04 02.00.04
19 mpi2_sas.h 02.00.02 02.00.02 19 mpi2_sas.h 02.00.03 02.00.02
20 mpi2_targ.h 02.00.03 02.00.03 20 mpi2_targ.h 02.00.03 02.00.03
21 mpi2_tool.h 02.00.03 02.00.02 21 mpi2_tool.h 02.00.04 02.00.04
22 mpi2_type.h 02.00.00 02.00.00 22 mpi2_type.h 02.00.00 02.00.00
23 mpi2_ra.h 02.00.00 23 mpi2_ra.h 02.00.00 02.00.00
24 mpi2_history.txt 02.00.11 02.00.12 24 mpi2_hbd.h 02.00.00
25 mpi2_history.txt 02.00.14 02.00.13
25 26
26 27
27 * Date Version Description 28 * Date Version Description
@@ -65,6 +66,11 @@ mpi2.h
65 * MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR and made those 66 * MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR and made those
66 * bytes reserved. 67 * bytes reserved.
67 * Added RAID Accelerator functionality. 68 * Added RAID Accelerator functionality.
69 * 07-30-09 02.00.13 Bumped MPI2_HEADER_VERSION_UNIT.
70 * 10-28-09 02.00.14 Bumped MPI2_HEADER_VERSION_UNIT.
71 * Added MSI-x index mask and shift for Reply Post Host
72 * Index register.
73 * Added function code for Host Based Discovery Action.
68 * -------------------------------------------------------------------------- 74 * --------------------------------------------------------------------------
69 75
70mpi2_cnfg.h 76mpi2_cnfg.h
@@ -155,6 +161,15 @@ mpi2_cnfg.h
155 * Added expander reduced functionality data to SAS 161 * Added expander reduced functionality data to SAS
156 * Expander Page 0. 162 * Expander Page 0.
157 * Added SAS PHY Page 2 and SAS PHY Page 3. 163 * Added SAS PHY Page 2 and SAS PHY Page 3.
164 * 07-30-09 02.00.12 Added IO Unit Page 7.
165 * Added new device ids.
166 * Added SAS IO Unit Page 5.
167 * Added partial and slumber power management capable flags
168 * to SAS Device Page 0 Flags field.
169 * Added PhyInfo defines for power condition.
170 * Added Ethernet configuration pages.
171 * 10-28-09 02.00.13 Added MPI2_IOUNITPAGE1_ENABLE_HOST_BASED_DISCOVERY.
172 * Added SAS PHY Page 4 structure and defines.
158 * -------------------------------------------------------------------------- 173 * --------------------------------------------------------------------------
159 174
160mpi2_init.h 175mpi2_init.h
@@ -172,6 +187,10 @@ mpi2_init.h
172 * Query Asynchronous Event. 187 * Query Asynchronous Event.
173 * Defined two new bits in the SlotStatus field of the SCSI 188 * Defined two new bits in the SlotStatus field of the SCSI
174 * Enclosure Processor Request and Reply. 189 * Enclosure Processor Request and Reply.
190 * 10-28-09 02.00.08 Added defines for decoding the ResponseInfo bytes for
191 * both SCSI IO Error Reply and SCSI Task Management Reply.
192 * Added ResponseInfo field to MPI2_SCSI_TASK_MANAGE_REPLY.
193 * Added MPI2_SCSITASKMGMT_RSP_TM_OVERLAPPED_TAG define.
175 * -------------------------------------------------------------------------- 194 * --------------------------------------------------------------------------
176 195
177mpi2_ioc.h 196mpi2_ioc.h
@@ -246,6 +265,20 @@ mpi2_ioc.h
246 * Added two new reason codes for SAS Device Status Change 265 * Added two new reason codes for SAS Device Status Change
247 * Event. 266 * Event.
248 * Added new event: SAS PHY Counter. 267 * Added new event: SAS PHY Counter.
268 * 07-30-09 02.00.12 Added GPIO Interrupt event define and structure.
269 * Added MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER define.
270 * Added new product id family for 2208.
271 * 10-28-09 02.00.13 Added HostMSIxVectors field to MPI2_IOC_INIT_REQUEST.
272 * Added MaxMSIxVectors field to MPI2_IOC_FACTS_REPLY.
273 * Added MinDevHandle field to MPI2_IOC_FACTS_REPLY.
274 * Added MPI2_IOCFACTS_CAPABILITY_HOST_BASED_DISCOVERY.
275 * Added MPI2_EVENT_HOST_BASED_DISCOVERY_PHY define.
276 * Added MPI2_EVENT_SAS_TOPO_ES_NO_EXPANDER define.
277 * Added Host Based Discovery Phy Event data.
278 * Added defines for ProductID Product field
279 * (MPI2_FW_HEADER_PID_).
280 * Modified values for SAS ProductID Family
281 * (MPI2_FW_HEADER_PID_FAMILY_).
249 * -------------------------------------------------------------------------- 282 * --------------------------------------------------------------------------
250 283
251mpi2_raid.h 284mpi2_raid.h
@@ -256,6 +289,8 @@ mpi2_raid.h
256 * 05-21-08 02.00.03 Added MPI2_RAID_VOL_CREATION_NUM_PHYSDISKS so that 289 * 05-21-08 02.00.03 Added MPI2_RAID_VOL_CREATION_NUM_PHYSDISKS so that
257 * the PhysDisk array in MPI2_RAID_VOLUME_CREATION_STRUCT 290 * the PhysDisk array in MPI2_RAID_VOLUME_CREATION_STRUCT
258 * can be sized by the build environment. 291 * can be sized by the build environment.
292 * 07-30-09 02.00.04 Added proper define for the Use Default Settings bit of
293 * VolumeCreationFlags and marked the old one as obsolete.
259 * -------------------------------------------------------------------------- 294 * --------------------------------------------------------------------------
260 295
261mpi2_sas.h 296mpi2_sas.h
@@ -264,6 +299,8 @@ mpi2_sas.h
264 * Control Request. 299 * Control Request.
265 * 10-02-08 02.00.02 Added Set IOC Parameter Operation to SAS IO Unit Control 300 * 10-02-08 02.00.02 Added Set IOC Parameter Operation to SAS IO Unit Control
266 * Request. 301 * Request.
302 * 10-28-09 02.00.03 Changed the type of SGL in MPI2_SATA_PASSTHROUGH_REQUEST
303 * to MPI2_SGE_IO_UNION since it supports chained SGLs.
267 * -------------------------------------------------------------------------- 304 * --------------------------------------------------------------------------
268 305
269mpi2_targ.h 306mpi2_targ.h
@@ -283,6 +320,10 @@ mpi2_tool.h
283 * structures and defines. 320 * structures and defines.
284 * 02-29-08 02.00.02 Modified various names to make them 32-character unique. 321 * 02-29-08 02.00.02 Modified various names to make them 32-character unique.
285 * 05-06-09 02.00.03 Added ISTWI Read Write Tool and Diagnostic CLI Tool. 322 * 05-06-09 02.00.03 Added ISTWI Read Write Tool and Diagnostic CLI Tool.
323 * 07-30-09 02.00.04 Added ExtendedType field to DiagnosticBufferPost request
324 * and reply messages.
325 * Added MPI2_DIAG_BUF_TYPE_EXTENDED.
326 * Incremented MPI2_DIAG_BUF_TYPE_COUNT.
286 * -------------------------------------------------------------------------- 327 * --------------------------------------------------------------------------
287 328
288mpi2_type.h 329mpi2_type.h
@@ -293,20 +334,26 @@ mpi2_ra.h
293 * 05-06-09 02.00.00 Initial version. 334 * 05-06-09 02.00.00 Initial version.
294 * -------------------------------------------------------------------------- 335 * --------------------------------------------------------------------------
295 336
337mpi2_hbd.h
338 * 10-28-09 02.00.00 Initial version.
339 * --------------------------------------------------------------------------
340
341
296mpi2_history.txt Parts list history 342mpi2_history.txt Parts list history
297 343
298Filename 02.00.12 344Filename 02.00.14 02.00.13 02.00.12
299---------- -------- 345---------- -------- -------- --------
300mpi2.h 02.00.12 346mpi2.h 02.00.14 02.00.13 02.00.12
301mpi2_cnfg.h 02.00.11 347mpi2_cnfg.h 02.00.13 02.00.12 02.00.11
302mpi2_init.h 02.00.07 348mpi2_init.h 02.00.08 02.00.07 02.00.07
303mpi2_ioc.h 02.00.11 349mpi2_ioc.h 02.00.13 02.00.12 02.00.11
304mpi2_raid.h 02.00.03 350mpi2_raid.h 02.00.04 02.00.04 02.00.03
305mpi2_sas.h 02.00.02 351mpi2_sas.h 02.00.03 02.00.02 02.00.02
306mpi2_targ.h 02.00.03 352mpi2_targ.h 02.00.03 02.00.03 02.00.03
307mpi2_tool.h 02.00.03 353mpi2_tool.h 02.00.04 02.00.04 02.00.03
308mpi2_type.h 02.00.00 354mpi2_type.h 02.00.00 02.00.00 02.00.00
309mpi2_ra.h 02.00.00 355mpi2_ra.h 02.00.00 02.00.00 02.00.00
356mpi2_hbd.h 02.00.00
310 357
311Filename 02.00.11 02.00.10 02.00.09 02.00.08 02.00.07 02.00.06 358Filename 02.00.11 02.00.10 02.00.09 02.00.08 02.00.07 02.00.06
312---------- -------- -------- -------- -------- -------- -------- 359---------- -------- -------- -------- -------- -------- --------
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_init.h b/drivers/scsi/mpt2sas/mpi/mpi2_init.h
index 563e56d2e945..6541945e97c3 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_init.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_init.h
@@ -6,7 +6,7 @@
6 * Title: MPI SCSI initiator mode messages and structures 6 * Title: MPI SCSI initiator mode messages and structures
7 * Creation Date: June 23, 2006 7 * Creation Date: June 23, 2006
8 * 8 *
9 * mpi2_init.h Version: 02.00.07 9 * mpi2_init.h Version: 02.00.08
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -27,6 +27,10 @@
27 * Query Asynchronous Event. 27 * Query Asynchronous Event.
28 * Defined two new bits in the SlotStatus field of the SCSI 28 * Defined two new bits in the SlotStatus field of the SCSI
29 * Enclosure Processor Request and Reply. 29 * Enclosure Processor Request and Reply.
30 * 10-28-09 02.00.08 Added defines for decoding the ResponseInfo bytes for
31 * both SCSI IO Error Reply and SCSI Task Management Reply.
32 * Added ResponseInfo field to MPI2_SCSI_TASK_MANAGE_REPLY.
33 * Added MPI2_SCSITASKMGMT_RSP_TM_OVERLAPPED_TAG define.
30 * -------------------------------------------------------------------------- 34 * --------------------------------------------------------------------------
31 */ 35 */
32 36
@@ -254,6 +258,11 @@ typedef struct _MPI2_SCSI_IO_REPLY
254#define MPI2_SCSI_STATE_AUTOSENSE_FAILED (0x02) 258#define MPI2_SCSI_STATE_AUTOSENSE_FAILED (0x02)
255#define MPI2_SCSI_STATE_AUTOSENSE_VALID (0x01) 259#define MPI2_SCSI_STATE_AUTOSENSE_VALID (0x01)
256 260
261/* masks and shifts for the ResponseInfo field */
262
263#define MPI2_SCSI_RI_MASK_REASONCODE (0x000000FF)
264#define MPI2_SCSI_RI_SHIFT_REASONCODE (0)
265
257#define MPI2_SCSI_TASKTAG_UNKNOWN (0xFFFF) 266#define MPI2_SCSI_TASKTAG_UNKNOWN (0xFFFF)
258 267
259 268
@@ -327,6 +336,7 @@ typedef struct _MPI2_SCSI_TASK_MANAGE_REPLY
327 U16 IOCStatus; /* 0x0E */ 336 U16 IOCStatus; /* 0x0E */
328 U32 IOCLogInfo; /* 0x10 */ 337 U32 IOCLogInfo; /* 0x10 */
329 U32 TerminationCount; /* 0x14 */ 338 U32 TerminationCount; /* 0x14 */
339 U32 ResponseInfo; /* 0x18 */
330} MPI2_SCSI_TASK_MANAGE_REPLY, 340} MPI2_SCSI_TASK_MANAGE_REPLY,
331 MPI2_POINTER PTR_MPI2_SCSI_TASK_MANAGE_REPLY, 341 MPI2_POINTER PTR_MPI2_SCSI_TASK_MANAGE_REPLY,
332 Mpi2SCSITaskManagementReply_t, MPI2_POINTER pMpi2SCSIManagementReply_t; 342 Mpi2SCSITaskManagementReply_t, MPI2_POINTER pMpi2SCSIManagementReply_t;
@@ -339,8 +349,20 @@ typedef struct _MPI2_SCSI_TASK_MANAGE_REPLY
339#define MPI2_SCSITASKMGMT_RSP_TM_FAILED (0x05) 349#define MPI2_SCSITASKMGMT_RSP_TM_FAILED (0x05)
340#define MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED (0x08) 350#define MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED (0x08)
341#define MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN (0x09) 351#define MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN (0x09)
352#define MPI2_SCSITASKMGMT_RSP_TM_OVERLAPPED_TAG (0x0A)
342#define MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC (0x80) 353#define MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC (0x80)
343 354
355/* masks and shifts for the ResponseInfo field */
356
357#define MPI2_SCSITASKMGMT_RI_MASK_REASONCODE (0x000000FF)
358#define MPI2_SCSITASKMGMT_RI_SHIFT_REASONCODE (0)
359#define MPI2_SCSITASKMGMT_RI_MASK_ARI2 (0x0000FF00)
360#define MPI2_SCSITASKMGMT_RI_SHIFT_ARI2 (8)
361#define MPI2_SCSITASKMGMT_RI_MASK_ARI1 (0x00FF0000)
362#define MPI2_SCSITASKMGMT_RI_SHIFT_ARI1 (16)
363#define MPI2_SCSITASKMGMT_RI_MASK_ARI0 (0xFF000000)
364#define MPI2_SCSITASKMGMT_RI_SHIFT_ARI0 (24)
365
344 366
345/**************************************************************************** 367/****************************************************************************
346* SCSI Enclosure Processor messages 368* SCSI Enclosure Processor messages
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_ioc.h b/drivers/scsi/mpt2sas/mpi/mpi2_ioc.h
index ea51ce868690..754938422f6a 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_ioc.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_ioc.h
@@ -6,7 +6,7 @@
6 * Title: MPI IOC, Port, Event, FW Download, and FW Upload messages 6 * Title: MPI IOC, Port, Event, FW Download, and FW Upload messages
7 * Creation Date: October 11, 2006 7 * Creation Date: October 11, 2006
8 * 8 *
9 * mpi2_ioc.h Version: 02.00.12 9 * mpi2_ioc.h Version: 02.00.13
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -87,6 +87,17 @@
87 * 07-30-09 02.00.12 Added GPIO Interrupt event define and structure. 87 * 07-30-09 02.00.12 Added GPIO Interrupt event define and structure.
88 * Added MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER define. 88 * Added MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER define.
89 * Added new product id family for 2208. 89 * Added new product id family for 2208.
90 * 10-28-09 02.00.13 Added HostMSIxVectors field to MPI2_IOC_INIT_REQUEST.
91 * Added MaxMSIxVectors field to MPI2_IOC_FACTS_REPLY.
92 * Added MinDevHandle field to MPI2_IOC_FACTS_REPLY.
93 * Added MPI2_IOCFACTS_CAPABILITY_HOST_BASED_DISCOVERY.
94 * Added MPI2_EVENT_HOST_BASED_DISCOVERY_PHY define.
95 * Added MPI2_EVENT_SAS_TOPO_ES_NO_EXPANDER define.
96 * Added Host Based Discovery Phy Event data.
97 * Added defines for ProductID Product field
98 * (MPI2_FW_HEADER_PID_).
99 * Modified values for SAS ProductID Family
100 * (MPI2_FW_HEADER_PID_FAMILY_).
90 * -------------------------------------------------------------------------- 101 * --------------------------------------------------------------------------
91 */ 102 */
92 103
@@ -119,8 +130,10 @@ typedef struct _MPI2_IOC_INIT_REQUEST
119 U16 MsgVersion; /* 0x0C */ 130 U16 MsgVersion; /* 0x0C */
120 U16 HeaderVersion; /* 0x0E */ 131 U16 HeaderVersion; /* 0x0E */
121 U32 Reserved5; /* 0x10 */ 132 U32 Reserved5; /* 0x10 */
122 U32 Reserved6; /* 0x14 */ 133 U16 Reserved6; /* 0x14 */
123 U16 Reserved7; /* 0x18 */ 134 U8 Reserved7; /* 0x16 */
135 U8 HostMSIxVectors; /* 0x17 */
136 U16 Reserved8; /* 0x18 */
124 U16 SystemRequestFrameSize; /* 0x1A */ 137 U16 SystemRequestFrameSize; /* 0x1A */
125 U16 ReplyDescriptorPostQueueDepth; /* 0x1C */ 138 U16 ReplyDescriptorPostQueueDepth; /* 0x1C */
126 U16 ReplyFreeQueueDepth; /* 0x1E */ 139 U16 ReplyFreeQueueDepth; /* 0x1E */
@@ -215,7 +228,7 @@ typedef struct _MPI2_IOC_FACTS_REPLY
215 U8 MaxChainDepth; /* 0x14 */ 228 U8 MaxChainDepth; /* 0x14 */
216 U8 WhoInit; /* 0x15 */ 229 U8 WhoInit; /* 0x15 */
217 U8 NumberOfPorts; /* 0x16 */ 230 U8 NumberOfPorts; /* 0x16 */
218 U8 Reserved2; /* 0x17 */ 231 U8 MaxMSIxVectors; /* 0x17 */
219 U16 RequestCredit; /* 0x18 */ 232 U16 RequestCredit; /* 0x18 */
220 U16 ProductID; /* 0x1A */ 233 U16 ProductID; /* 0x1A */
221 U32 IOCCapabilities; /* 0x1C */ 234 U32 IOCCapabilities; /* 0x1C */
@@ -233,7 +246,8 @@ typedef struct _MPI2_IOC_FACTS_REPLY
233 U8 MaxVolumes; /* 0x37 */ 246 U8 MaxVolumes; /* 0x37 */
234 U16 MaxDevHandle; /* 0x38 */ 247 U16 MaxDevHandle; /* 0x38 */
235 U16 MaxPersistentEntries; /* 0x3A */ 248 U16 MaxPersistentEntries; /* 0x3A */
236 U32 Reserved4; /* 0x3C */ 249 U16 MinDevHandle; /* 0x3C */
250 U16 Reserved4; /* 0x3E */
237} MPI2_IOC_FACTS_REPLY, MPI2_POINTER PTR_MPI2_IOC_FACTS_REPLY, 251} MPI2_IOC_FACTS_REPLY, MPI2_POINTER PTR_MPI2_IOC_FACTS_REPLY,
238 Mpi2IOCFactsReply_t, MPI2_POINTER pMpi2IOCFactsReply_t; 252 Mpi2IOCFactsReply_t, MPI2_POINTER pMpi2IOCFactsReply_t;
239 253
@@ -269,6 +283,7 @@ typedef struct _MPI2_IOC_FACTS_REPLY
269/* ProductID field uses MPI2_FW_HEADER_PID_ */ 283/* ProductID field uses MPI2_FW_HEADER_PID_ */
270 284
271/* IOCCapabilities */ 285/* IOCCapabilities */
286#define MPI2_IOCFACTS_CAPABILITY_HOST_BASED_DISCOVERY (0x00010000)
272#define MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX (0x00008000) 287#define MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX (0x00008000)
273#define MPI2_IOCFACTS_CAPABILITY_RAID_ACCELERATOR (0x00004000) 288#define MPI2_IOCFACTS_CAPABILITY_RAID_ACCELERATOR (0x00004000)
274#define MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY (0x00002000) 289#define MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY (0x00002000)
@@ -453,6 +468,7 @@ typedef struct _MPI2_EVENT_NOTIFICATION_REPLY
453#define MPI2_EVENT_LOG_ENTRY_ADDED (0x0021) 468#define MPI2_EVENT_LOG_ENTRY_ADDED (0x0021)
454#define MPI2_EVENT_SAS_PHY_COUNTER (0x0022) 469#define MPI2_EVENT_SAS_PHY_COUNTER (0x0022)
455#define MPI2_EVENT_GPIO_INTERRUPT (0x0023) 470#define MPI2_EVENT_GPIO_INTERRUPT (0x0023)
471#define MPI2_EVENT_HOST_BASED_DISCOVERY_PHY (0x0024)
456 472
457 473
458/* Log Entry Added Event data */ 474/* Log Entry Added Event data */
@@ -793,6 +809,7 @@ typedef struct _MPI2_EVENT_DATA_SAS_TOPOLOGY_CHANGE_LIST
793 MPI2_POINTER pMpi2EventDataSasTopologyChangeList_t; 809 MPI2_POINTER pMpi2EventDataSasTopologyChangeList_t;
794 810
795/* values for the ExpStatus field */ 811/* values for the ExpStatus field */
812#define MPI2_EVENT_SAS_TOPO_ES_NO_EXPANDER (0x00)
796#define MPI2_EVENT_SAS_TOPO_ES_ADDED (0x01) 813#define MPI2_EVENT_SAS_TOPO_ES_ADDED (0x01)
797#define MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING (0x02) 814#define MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING (0x02)
798#define MPI2_EVENT_SAS_TOPO_ES_RESPONDING (0x03) 815#define MPI2_EVENT_SAS_TOPO_ES_RESPONDING (0x03)
@@ -878,6 +895,44 @@ typedef struct _MPI2_EVENT_DATA_SAS_PHY_COUNTER {
878 * */ 895 * */
879 896
880 897
898/* Host Based Discovery Phy Event data */
899
900typedef struct _MPI2_EVENT_HBD_PHY_SAS {
901 U8 Flags; /* 0x00 */
902 U8 NegotiatedLinkRate; /* 0x01 */
903 U8 PhyNum; /* 0x02 */
904 U8 PhysicalPort; /* 0x03 */
905 U32 Reserved1; /* 0x04 */
906 U8 InitialFrame[28]; /* 0x08 */
907} MPI2_EVENT_HBD_PHY_SAS, MPI2_POINTER PTR_MPI2_EVENT_HBD_PHY_SAS,
908 Mpi2EventHbdPhySas_t, MPI2_POINTER pMpi2EventHbdPhySas_t;
909
910/* values for the Flags field */
911#define MPI2_EVENT_HBD_SAS_FLAGS_FRAME_VALID (0x02)
912#define MPI2_EVENT_HBD_SAS_FLAGS_SATA_FRAME (0x01)
913
914/* use MPI2_SAS_NEG_LINK_RATE_ defines from mpi2_cnfg.h for
915 * the NegotiatedLinkRate field */
916
917typedef union _MPI2_EVENT_HBD_DESCRIPTOR {
918 MPI2_EVENT_HBD_PHY_SAS Sas;
919} MPI2_EVENT_HBD_DESCRIPTOR, MPI2_POINTER PTR_MPI2_EVENT_HBD_DESCRIPTOR,
920 Mpi2EventHbdDescriptor_t, MPI2_POINTER pMpi2EventHbdDescriptor_t;
921
922typedef struct _MPI2_EVENT_DATA_HBD_PHY {
923 U8 DescriptorType; /* 0x00 */
924 U8 Reserved1; /* 0x01 */
925 U16 Reserved2; /* 0x02 */
926 U32 Reserved3; /* 0x04 */
927 MPI2_EVENT_HBD_DESCRIPTOR Descriptor; /* 0x08 */
928} MPI2_EVENT_DATA_HBD_PHY, MPI2_POINTER PTR_MPI2_EVENT_DATA_HBD_PHY,
929 Mpi2EventDataHbdPhy_t, MPI2_POINTER pMpi2EventDataMpi2EventDataHbdPhy_t;
930
931/* values for the DescriptorType field */
932#define MPI2_EVENT_HBD_DT_SAS (0x01)
933
934
935
881/**************************************************************************** 936/****************************************************************************
882* EventAck message 937* EventAck message
883****************************************************************************/ 938****************************************************************************/
@@ -1126,13 +1181,17 @@ typedef struct _MPI2_FW_IMAGE_HEADER
1126#define MPI2_FW_HEADER_PID_TYPE_MASK (0xF000) 1181#define MPI2_FW_HEADER_PID_TYPE_MASK (0xF000)
1127#define MPI2_FW_HEADER_PID_TYPE_SAS (0x2000) 1182#define MPI2_FW_HEADER_PID_TYPE_SAS (0x2000)
1128 1183
1129#define MPI2_FW_HEADER_PID_PROD_MASK (0x0F00) 1184#define MPI2_FW_HEADER_PID_PROD_MASK (0x0F00)
1130#define MPI2_FW_HEADER_PID_PROD_A (0x0000) 1185#define MPI2_FW_HEADER_PID_PROD_A (0x0000)
1186#define MPI2_FW_HEADER_PID_PROD_MASK (0x0F00)
1187#define MPI2_FW_HEADER_PID_PROD_TARGET_INITIATOR_SCSI (0x0200)
1188#define MPI2_FW_HEADER_PID_PROD_IR_SCSI (0x0700)
1189
1131 1190
1132#define MPI2_FW_HEADER_PID_FAMILY_MASK (0x00FF) 1191#define MPI2_FW_HEADER_PID_FAMILY_MASK (0x00FF)
1133/* SAS */ 1192/* SAS */
1134#define MPI2_FW_HEADER_PID_FAMILY_2108_SAS (0x0010) 1193#define MPI2_FW_HEADER_PID_FAMILY_2108_SAS (0x0013)
1135#define MPI2_FW_HEADER_PID_FAMILY_2208_SAS (0x0011) 1194#define MPI2_FW_HEADER_PID_FAMILY_2208_SAS (0x0014)
1136 1195
1137/* use MPI2_IOCFACTS_PROTOCOL_ defines for ProtocolFlags field */ 1196/* use MPI2_IOCFACTS_PROTOCOL_ defines for ProtocolFlags field */
1138 1197
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_sas.h b/drivers/scsi/mpt2sas/mpi/mpi2_sas.h
index 8a42b136cf53..2d8aeed51392 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_sas.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_sas.h
@@ -6,7 +6,7 @@
6 * Title: MPI Serial Attached SCSI structures and definitions 6 * Title: MPI Serial Attached SCSI structures and definitions
7 * Creation Date: February 9, 2007 7 * Creation Date: February 9, 2007
8 * 8 *
9 * mpi2.h Version: 02.00.02 9 * mpi2.h Version: 02.00.03
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -18,6 +18,8 @@
18 * Control Request. 18 * Control Request.
19 * 10-02-08 02.00.02 Added Set IOC Parameter Operation to SAS IO Unit Control 19 * 10-02-08 02.00.02 Added Set IOC Parameter Operation to SAS IO Unit Control
20 * Request. 20 * Request.
21 * 10-28-09 02.00.03 Changed the type of SGL in MPI2_SATA_PASSTHROUGH_REQUEST
22 * to MPI2_SGE_IO_UNION since it supports chained SGLs.
21 * -------------------------------------------------------------------------- 23 * --------------------------------------------------------------------------
22 */ 24 */
23 25
@@ -160,7 +162,7 @@ typedef struct _MPI2_SATA_PASSTHROUGH_REQUEST
160 U32 Reserved4; /* 0x14 */ 162 U32 Reserved4; /* 0x14 */
161 U32 DataLength; /* 0x18 */ 163 U32 DataLength; /* 0x18 */
162 U8 CommandFIS[20]; /* 0x1C */ 164 U8 CommandFIS[20]; /* 0x1C */
163 MPI2_SIMPLE_SGE_UNION SGL; /* 0x20 */ 165 MPI2_SGE_IO_UNION SGL; /* 0x20 */
164} MPI2_SATA_PASSTHROUGH_REQUEST, MPI2_POINTER PTR_MPI2_SATA_PASSTHROUGH_REQUEST, 166} MPI2_SATA_PASSTHROUGH_REQUEST, MPI2_POINTER PTR_MPI2_SATA_PASSTHROUGH_REQUEST,
165 Mpi2SataPassthroughRequest_t, MPI2_POINTER pMpi2SataPassthroughRequest_t; 167 Mpi2SataPassthroughRequest_t, MPI2_POINTER pMpi2SataPassthroughRequest_t;
166 168
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c b/drivers/scsi/mpt2sas/mpt2sas_base.c
index 89d02401b9ec..88e6eebc3159 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
@@ -107,8 +107,7 @@ _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
107 if (ret) 107 if (ret)
108 return ret; 108 return ret;
109 109
110 printk(KERN_INFO "setting logging_level(0x%08x)\n", 110 printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug);
111 mpt2sas_fwfault_debug);
112 list_for_each_entry(ioc, &mpt2sas_ioc_list, list) 111 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
113 ioc->fwfault_debug = mpt2sas_fwfault_debug; 112 ioc->fwfault_debug = mpt2sas_fwfault_debug;
114 return 0; 113 return 0;
@@ -1222,6 +1221,8 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1222 u32 memap_sz; 1221 u32 memap_sz;
1223 u32 pio_sz; 1222 u32 pio_sz;
1224 int i, r = 0; 1223 int i, r = 0;
1224 u64 pio_chip = 0;
1225 u64 chip_phys = 0;
1225 1226
1226 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", 1227 dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n",
1227 ioc->name, __func__)); 1228 ioc->name, __func__));
@@ -1255,12 +1256,13 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1255 if (pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE_IO) { 1256 if (pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE_IO) {
1256 if (pio_sz) 1257 if (pio_sz)
1257 continue; 1258 continue;
1258 ioc->pio_chip = pci_resource_start(pdev, i); 1259 pio_chip = (u64)pci_resource_start(pdev, i);
1259 pio_sz = pci_resource_len(pdev, i); 1260 pio_sz = pci_resource_len(pdev, i);
1260 } else { 1261 } else {
1261 if (memap_sz) 1262 if (memap_sz)
1262 continue; 1263 continue;
1263 ioc->chip_phys = pci_resource_start(pdev, i); 1264 ioc->chip_phys = pci_resource_start(pdev, i);
1265 chip_phys = (u64)ioc->chip_phys;
1264 memap_sz = pci_resource_len(pdev, i); 1266 memap_sz = pci_resource_len(pdev, i);
1265 ioc->chip = ioremap(ioc->chip_phys, memap_sz); 1267 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1266 if (ioc->chip == NULL) { 1268 if (ioc->chip == NULL) {
@@ -1280,10 +1282,10 @@ mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1280 printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n", 1282 printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
1281 ioc->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" : 1283 ioc->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
1282 "IO-APIC enabled"), ioc->pci_irq); 1284 "IO-APIC enabled"), ioc->pci_irq);
1283 printk(MPT2SAS_INFO_FMT "iomem(0x%lx), mapped(0x%p), size(%d)\n", 1285 printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1284 ioc->name, ioc->chip_phys, ioc->chip, memap_sz); 1286 ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
1285 printk(MPT2SAS_INFO_FMT "ioport(0x%lx), size(%d)\n", 1287 printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
1286 ioc->name, ioc->pio_chip, pio_sz); 1288 ioc->name, (unsigned long long)pio_chip, pio_sz);
1287 1289
1288 return 0; 1290 return 0;
1289 1291
@@ -3573,6 +3575,8 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
3573 3575
3574 init_waitqueue_head(&ioc->reset_wq); 3576 init_waitqueue_head(&ioc->reset_wq);
3575 3577
3578 ioc->fwfault_debug = mpt2sas_fwfault_debug;
3579
3576 /* base internal command bits */ 3580 /* base internal command bits */
3577 mutex_init(&ioc->base_cmds.mutex); 3581 mutex_init(&ioc->base_cmds.mutex);
3578 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); 3582 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h
index bb4f14656afa..e18b0544c38f 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.h
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.h
@@ -69,10 +69,10 @@
69#define MPT2SAS_DRIVER_NAME "mpt2sas" 69#define MPT2SAS_DRIVER_NAME "mpt2sas"
70#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>" 70#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>"
71#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver" 71#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver"
72#define MPT2SAS_DRIVER_VERSION "03.100.03.00" 72#define MPT2SAS_DRIVER_VERSION "04.100.01.00"
73#define MPT2SAS_MAJOR_VERSION 03 73#define MPT2SAS_MAJOR_VERSION 04
74#define MPT2SAS_MINOR_VERSION 100 74#define MPT2SAS_MINOR_VERSION 100
75#define MPT2SAS_BUILD_VERSION 03 75#define MPT2SAS_BUILD_VERSION 01
76#define MPT2SAS_RELEASE_VERSION 00 76#define MPT2SAS_RELEASE_VERSION 00
77 77
78/* 78/*
@@ -323,6 +323,7 @@ struct _sas_device {
323 * @device_info: bitfield provides detailed info about the hidden components 323 * @device_info: bitfield provides detailed info about the hidden components
324 * @num_pds: number of hidden raid components 324 * @num_pds: number of hidden raid components
325 * @responding: used in _scsih_raid_device_mark_responding 325 * @responding: used in _scsih_raid_device_mark_responding
326 * @percent_complete: resync percent complete
326 */ 327 */
327struct _raid_device { 328struct _raid_device {
328 struct list_head list; 329 struct list_head list;
@@ -336,6 +337,7 @@ struct _raid_device {
336 u32 device_info; 337 u32 device_info;
337 u8 num_pds; 338 u8 num_pds;
338 u8 responding; 339 u8 responding;
340 u8 percent_complete;
339}; 341};
340 342
341/** 343/**
@@ -464,7 +466,6 @@ typedef void (*MPT_ADD_SGE)(void *paddr, u32 flags_length, dma_addr_t dma_addr);
464 * @pdev: pci pdev object 466 * @pdev: pci pdev object
465 * @chip: memory mapped register space 467 * @chip: memory mapped register space
466 * @chip_phys: physical addrss prior to mapping 468 * @chip_phys: physical addrss prior to mapping
467 * @pio_chip: I/O mapped register space
468 * @logging_level: see mpt2sas_debug.h 469 * @logging_level: see mpt2sas_debug.h
469 * @fwfault_debug: debuging FW timeouts 470 * @fwfault_debug: debuging FW timeouts
470 * @ir_firmware: IR firmware present 471 * @ir_firmware: IR firmware present
@@ -587,8 +588,7 @@ struct MPT2SAS_ADAPTER {
587 char tmp_string[MPT_STRING_LENGTH]; 588 char tmp_string[MPT_STRING_LENGTH];
588 struct pci_dev *pdev; 589 struct pci_dev *pdev;
589 Mpi2SystemInterfaceRegs_t __iomem *chip; 590 Mpi2SystemInterfaceRegs_t __iomem *chip;
590 unsigned long chip_phys; 591 resource_size_t chip_phys;
591 unsigned long pio_chip;
592 int logging_level; 592 int logging_level;
593 int fwfault_debug; 593 int fwfault_debug;
594 u8 ir_firmware; 594 u8 ir_firmware;
@@ -853,6 +853,8 @@ int mpt2sas_config_set_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
853 *mpi_reply, Mpi2IOUnitPage1_t *config_page); 853 *mpi_reply, Mpi2IOUnitPage1_t *config_page);
854int mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t 854int mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
855 *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz); 855 *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
856int mpt2sas_config_set_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc,
857 Mpi2ConfigReply_t *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz);
856int mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t 858int mpt2sas_config_get_ioc_pg8(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
857 *mpi_reply, Mpi2IOCPage8_t *config_page); 859 *mpi_reply, Mpi2IOCPage8_t *config_page);
858int mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t 860int mpt2sas_config_get_expander_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
diff --git a/drivers/scsi/mpt2sas/mpt2sas_config.c b/drivers/scsi/mpt2sas/mpt2sas_config.c
index 594a389c6526..411c27d7f787 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_config.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_config.c
@@ -324,7 +324,9 @@ _config_request(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigRequest_t
324 if (r != 0) 324 if (r != 0)
325 goto out; 325 goto out;
326 if (mpi_request->Action == 326 if (mpi_request->Action ==
327 MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT) { 327 MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT ||
328 mpi_request->Action ==
329 MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM) {
328 ioc->base_add_sg_single(&mpi_request->PageBufferSGE, 330 ioc->base_add_sg_single(&mpi_request->PageBufferSGE,
329 MPT2_CONFIG_COMMON_WRITE_SGLFLAGS | mem.sz, 331 MPT2_CONFIG_COMMON_WRITE_SGLFLAGS | mem.sz,
330 mem.page_dma); 332 mem.page_dma);
@@ -882,7 +884,7 @@ mpt2sas_config_get_sas_iounit_pg0(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
882} 884}
883 885
884/** 886/**
885 * mpt2sas_config_get_sas_iounit_pg1 - obtain sas iounit page 0 887 * mpt2sas_config_get_sas_iounit_pg1 - obtain sas iounit page 1
886 * @ioc: per adapter object 888 * @ioc: per adapter object
887 * @mpi_reply: reply mf payload returned from firmware 889 * @mpi_reply: reply mf payload returned from firmware
888 * @config_page: contents of the config page 890 * @config_page: contents of the config page
@@ -907,7 +909,7 @@ mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
907 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED; 909 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
908 mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT; 910 mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
909 mpi_request.Header.PageNumber = 1; 911 mpi_request.Header.PageNumber = 1;
910 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE0_PAGEVERSION; 912 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION;
911 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE); 913 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
912 r = _config_request(ioc, &mpi_request, mpi_reply, 914 r = _config_request(ioc, &mpi_request, mpi_reply,
913 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0); 915 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
@@ -922,6 +924,49 @@ mpt2sas_config_get_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
922} 924}
923 925
924/** 926/**
927 * mpt2sas_config_set_sas_iounit_pg1 - send sas iounit page 1
928 * @ioc: per adapter object
929 * @mpi_reply: reply mf payload returned from firmware
930 * @config_page: contents of the config page
931 * @sz: size of buffer passed in config_page
932 * Context: sleep.
933 *
934 * Calling function should call config_get_number_hba_phys prior to
935 * this function, so enough memory is allocated for config_page.
936 *
937 * Returns 0 for success, non-zero for failure.
938 */
939int
940mpt2sas_config_set_sas_iounit_pg1(struct MPT2SAS_ADAPTER *ioc, Mpi2ConfigReply_t
941 *mpi_reply, Mpi2SasIOUnitPage1_t *config_page, u16 sz)
942{
943 Mpi2ConfigRequest_t mpi_request;
944 int r;
945
946 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
947 mpi_request.Function = MPI2_FUNCTION_CONFIG;
948 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
949 mpi_request.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
950 mpi_request.ExtPageType = MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
951 mpi_request.Header.PageNumber = 1;
952 mpi_request.Header.PageVersion = MPI2_SASIOUNITPAGE1_PAGEVERSION;
953 mpt2sas_base_build_zero_len_sge(ioc, &mpi_request.PageBufferSGE);
954 r = _config_request(ioc, &mpi_request, mpi_reply,
955 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, NULL, 0);
956 if (r)
957 goto out;
958
959 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
960 _config_request(ioc, &mpi_request, mpi_reply,
961 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
962 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
963 r = _config_request(ioc, &mpi_request, mpi_reply,
964 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page, sz);
965 out:
966 return r;
967}
968
969/**
925 * mpt2sas_config_get_expander_pg0 - obtain expander page 0 970 * mpt2sas_config_get_expander_pg0 - obtain expander page 0
926 * @ioc: per adapter object 971 * @ioc: per adapter object
927 * @mpi_reply: reply mf payload returned from firmware 972 * @mpi_reply: reply mf payload returned from firmware
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index 84a124f8e21f..fa9bf83819d5 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -891,6 +891,7 @@ _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc,
891 891
892 issue_host_reset: 892 issue_host_reset:
893 if (issue_reset) { 893 if (issue_reset) {
894 ret = -ENODATA;
894 if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || 895 if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
895 mpi_request->Function == 896 mpi_request->Function ==
896 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { 897 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
@@ -2202,14 +2203,10 @@ _ctl_compat_mpt_command(struct file *file, unsigned cmd, unsigned long arg)
2202 karg.data_out_size = karg32.data_out_size; 2203 karg.data_out_size = karg32.data_out_size;
2203 karg.max_sense_bytes = karg32.max_sense_bytes; 2204 karg.max_sense_bytes = karg32.max_sense_bytes;
2204 karg.data_sge_offset = karg32.data_sge_offset; 2205 karg.data_sge_offset = karg32.data_sge_offset;
2205 memcpy(&karg.reply_frame_buf_ptr, &karg32.reply_frame_buf_ptr, 2206 karg.reply_frame_buf_ptr = compat_ptr(karg32.reply_frame_buf_ptr);
2206 sizeof(uint32_t)); 2207 karg.data_in_buf_ptr = compat_ptr(karg32.data_in_buf_ptr);
2207 memcpy(&karg.data_in_buf_ptr, &karg32.data_in_buf_ptr, 2208 karg.data_out_buf_ptr = compat_ptr(karg32.data_out_buf_ptr);
2208 sizeof(uint32_t)); 2209 karg.sense_data_ptr = compat_ptr(karg32.sense_data_ptr);
2209 memcpy(&karg.data_out_buf_ptr, &karg32.data_out_buf_ptr,
2210 sizeof(uint32_t));
2211 memcpy(&karg.sense_data_ptr, &karg32.sense_data_ptr,
2212 sizeof(uint32_t));
2213 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING; 2210 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
2214 return _ctl_do_mpt_command(ioc, karg, &uarg->mf, state); 2211 return _ctl_do_mpt_command(ioc, karg, &uarg->mf, state);
2215} 2212}
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index efabea1a3ce4..c7ec3f174782 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -52,6 +52,7 @@
52#include <linux/delay.h> 52#include <linux/delay.h>
53#include <linux/pci.h> 53#include <linux/pci.h>
54#include <linux/interrupt.h> 54#include <linux/interrupt.h>
55#include <linux/raid_class.h>
55 56
56#include "mpt2sas_base.h" 57#include "mpt2sas_base.h"
57 58
@@ -133,6 +134,9 @@ struct fw_event_work {
133 void *event_data; 134 void *event_data;
134}; 135};
135 136
137/* raid transport support */
138static struct raid_template *mpt2sas_raid_template;
139
136/** 140/**
137 * struct _scsi_io_transfer - scsi io transfer 141 * struct _scsi_io_transfer - scsi io transfer
138 * @handle: sas device handle (assigned by firmware) 142 * @handle: sas device handle (assigned by firmware)
@@ -1305,7 +1309,6 @@ _scsih_slave_alloc(struct scsi_device *sdev)
1305 struct MPT2SAS_DEVICE *sas_device_priv_data; 1309 struct MPT2SAS_DEVICE *sas_device_priv_data;
1306 struct scsi_target *starget; 1310 struct scsi_target *starget;
1307 struct _raid_device *raid_device; 1311 struct _raid_device *raid_device;
1308 struct _sas_device *sas_device;
1309 unsigned long flags; 1312 unsigned long flags;
1310 1313
1311 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL); 1314 sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
@@ -1332,21 +1335,8 @@ _scsih_slave_alloc(struct scsi_device *sdev)
1332 if (raid_device) 1335 if (raid_device)
1333 raid_device->sdev = sdev; /* raid is single lun */ 1336 raid_device->sdev = sdev; /* raid is single lun */
1334 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 1337 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1335 } else {
1336 /* set TLR bit for SSP devices */
1337 if (!(ioc->facts.IOCCapabilities &
1338 MPI2_IOCFACTS_CAPABILITY_TLR))
1339 goto out;
1340 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1341 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1342 sas_device_priv_data->sas_target->sas_address);
1343 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1344 if (sas_device && sas_device->device_info &
1345 MPI2_SAS_DEVICE_INFO_SSP_TARGET)
1346 sas_device_priv_data->flags |= MPT_DEVICE_TLR_ON;
1347 } 1338 }
1348 1339
1349 out:
1350 return 0; 1340 return 0;
1351} 1341}
1352 1342
@@ -1419,6 +1409,140 @@ _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
1419} 1409}
1420 1410
1421/** 1411/**
1412 * _scsih_is_raid - return boolean indicating device is raid volume
1413 * @dev the device struct object
1414 */
1415static int
1416_scsih_is_raid(struct device *dev)
1417{
1418 struct scsi_device *sdev = to_scsi_device(dev);
1419
1420 return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
1421}
1422
1423/**
1424 * _scsih_get_resync - get raid volume resync percent complete
1425 * @dev the device struct object
1426 */
1427static void
1428_scsih_get_resync(struct device *dev)
1429{
1430 struct scsi_device *sdev = to_scsi_device(dev);
1431 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1432 static struct _raid_device *raid_device;
1433 unsigned long flags;
1434 Mpi2RaidVolPage0_t vol_pg0;
1435 Mpi2ConfigReply_t mpi_reply;
1436 u32 volume_status_flags;
1437 u8 percent_complete = 0;
1438
1439 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1440 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1441 sdev->channel);
1442 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1443
1444 if (!raid_device)
1445 goto out;
1446
1447 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1448 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1449 sizeof(Mpi2RaidVolPage0_t))) {
1450 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1451 ioc->name, __FILE__, __LINE__, __func__);
1452 goto out;
1453 }
1454
1455 volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1456 if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
1457 percent_complete = raid_device->percent_complete;
1458 out:
1459 raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
1460}
1461
1462/**
1463 * _scsih_get_state - get raid volume level
1464 * @dev the device struct object
1465 */
1466static void
1467_scsih_get_state(struct device *dev)
1468{
1469 struct scsi_device *sdev = to_scsi_device(dev);
1470 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
1471 static struct _raid_device *raid_device;
1472 unsigned long flags;
1473 Mpi2RaidVolPage0_t vol_pg0;
1474 Mpi2ConfigReply_t mpi_reply;
1475 u32 volstate;
1476 enum raid_state state = RAID_STATE_UNKNOWN;
1477
1478 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1479 raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
1480 sdev->channel);
1481 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1482
1483 if (!raid_device)
1484 goto out;
1485
1486 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
1487 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
1488 sizeof(Mpi2RaidVolPage0_t))) {
1489 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1490 ioc->name, __FILE__, __LINE__, __func__);
1491 goto out;
1492 }
1493
1494 volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
1495 if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
1496 state = RAID_STATE_RESYNCING;
1497 goto out;
1498 }
1499
1500 switch (vol_pg0.VolumeState) {
1501 case MPI2_RAID_VOL_STATE_OPTIMAL:
1502 case MPI2_RAID_VOL_STATE_ONLINE:
1503 state = RAID_STATE_ACTIVE;
1504 break;
1505 case MPI2_RAID_VOL_STATE_DEGRADED:
1506 state = RAID_STATE_DEGRADED;
1507 break;
1508 case MPI2_RAID_VOL_STATE_FAILED:
1509 case MPI2_RAID_VOL_STATE_MISSING:
1510 state = RAID_STATE_OFFLINE;
1511 break;
1512 }
1513 out:
1514 raid_set_state(mpt2sas_raid_template, dev, state);
1515}
1516
1517/**
1518 * _scsih_set_level - set raid level
1519 * @sdev: scsi device struct
1520 * @raid_device: raid_device object
1521 */
1522static void
1523_scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1524{
1525 enum raid_level level = RAID_LEVEL_UNKNOWN;
1526
1527 switch (raid_device->volume_type) {
1528 case MPI2_RAID_VOL_TYPE_RAID0:
1529 level = RAID_LEVEL_0;
1530 break;
1531 case MPI2_RAID_VOL_TYPE_RAID10:
1532 level = RAID_LEVEL_10;
1533 break;
1534 case MPI2_RAID_VOL_TYPE_RAID1E:
1535 level = RAID_LEVEL_1E;
1536 break;
1537 case MPI2_RAID_VOL_TYPE_RAID1:
1538 level = RAID_LEVEL_1;
1539 break;
1540 }
1541
1542 raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
1543}
1544
1545/**
1422 * _scsih_get_volume_capabilities - volume capabilities 1546 * _scsih_get_volume_capabilities - volume capabilities
1423 * @ioc: per adapter object 1547 * @ioc: per adapter object
1424 * @sas_device: the raid_device object 1548 * @sas_device: the raid_device object
@@ -1479,6 +1603,32 @@ _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1479} 1603}
1480 1604
1481/** 1605/**
1606 * _scsih_enable_tlr - setting TLR flags
1607 * @ioc: per adapter object
1608 * @sdev: scsi device struct
1609 *
1610 * Enabling Transaction Layer Retries for tape devices when
1611 * vpd page 0x90 is present
1612 *
1613 */
1614static void
1615_scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
1616{
1617 /* only for TAPE */
1618 if (sdev->type != TYPE_TAPE)
1619 return;
1620
1621 if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
1622 return;
1623
1624 sas_enable_tlr(sdev);
1625 sdev_printk(KERN_INFO, sdev, "TLR %s\n",
1626 sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
1627 return;
1628
1629}
1630
1631/**
1482 * _scsih_slave_configure - device configure routine. 1632 * _scsih_slave_configure - device configure routine.
1483 * @sdev: scsi device struct 1633 * @sdev: scsi device struct
1484 * 1634 *
@@ -1574,6 +1724,8 @@ _scsih_slave_configure(struct scsi_device *sdev)
1574 (unsigned long long)raid_device->wwid, 1724 (unsigned long long)raid_device->wwid,
1575 raid_device->num_pds, ds); 1725 raid_device->num_pds, ds);
1576 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 1726 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1727 /* raid transport support */
1728 _scsih_set_level(sdev, raid_device);
1577 return 0; 1729 return 0;
1578 } 1730 }
1579 1731
@@ -1621,8 +1773,10 @@ _scsih_slave_configure(struct scsi_device *sdev)
1621 1773
1622 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 1774 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
1623 1775
1624 if (ssp_target) 1776 if (ssp_target) {
1625 sas_read_port_mode_page(sdev); 1777 sas_read_port_mode_page(sdev);
1778 _scsih_enable_tlr(ioc, sdev);
1779 }
1626 return 0; 1780 return 0;
1627} 1781}
1628 1782
@@ -2908,8 +3062,9 @@ _scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
2908 3062
2909 } else 3063 } else
2910 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ; 3064 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
2911 3065 /* Make sure Device is not raid volume */
2912 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON)) 3066 if (!_scsih_is_raid(&scmd->device->sdev_gendev) &&
3067 sas_is_tlr_enabled(scmd->device))
2913 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON; 3068 mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
2914 3069
2915 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd); 3070 smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
@@ -3298,10 +3453,12 @@ _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
3298 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF; 3453 le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
3299 if (!sas_device_priv_data->tlr_snoop_check) { 3454 if (!sas_device_priv_data->tlr_snoop_check) {
3300 sas_device_priv_data->tlr_snoop_check++; 3455 sas_device_priv_data->tlr_snoop_check++;
3301 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && 3456 if (!_scsih_is_raid(&scmd->device->sdev_gendev) &&
3302 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) 3457 sas_is_tlr_enabled(scmd->device) &&
3303 sas_device_priv_data->flags &= 3458 response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
3304 ~MPT_DEVICE_TLR_ON; 3459 sas_disable_tlr(scmd->device);
3460 sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
3461 }
3305 } 3462 }
3306 3463
3307 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount); 3464 xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
@@ -5170,11 +5327,33 @@ static void
5170_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc, 5327_scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
5171 struct fw_event_work *fw_event) 5328 struct fw_event_work *fw_event)
5172{ 5329{
5330 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
5331 static struct _raid_device *raid_device;
5332 unsigned long flags;
5333 u16 handle;
5334
5173#ifdef CONFIG_SCSI_MPT2SAS_LOGGING 5335#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
5174 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) 5336 if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
5175 _scsih_sas_ir_operation_status_event_debug(ioc, 5337 _scsih_sas_ir_operation_status_event_debug(ioc,
5176 fw_event->event_data); 5338 event_data);
5177#endif 5339#endif
5340
5341 /* code added for raid transport support */
5342 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
5343
5344 handle = le16_to_cpu(event_data->VolDevHandle);
5345
5346 spin_lock_irqsave(&ioc->raid_device_lock, flags);
5347 raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
5348 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
5349
5350 if (!raid_device)
5351 return;
5352
5353 if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
5354 raid_device->percent_complete =
5355 event_data->PercentComplete;
5356 }
5178} 5357}
5179 5358
5180/** 5359/**
@@ -5998,6 +6177,8 @@ _scsih_remove(struct pci_dev *pdev)
5998 struct _sas_port *mpt2sas_port; 6177 struct _sas_port *mpt2sas_port;
5999 struct _sas_device *sas_device; 6178 struct _sas_device *sas_device;
6000 struct _sas_node *expander_sibling; 6179 struct _sas_node *expander_sibling;
6180 struct _raid_device *raid_device, *next;
6181 struct MPT2SAS_TARGET *sas_target_priv_data;
6001 struct workqueue_struct *wq; 6182 struct workqueue_struct *wq;
6002 unsigned long flags; 6183 unsigned long flags;
6003 6184
@@ -6011,6 +6192,21 @@ _scsih_remove(struct pci_dev *pdev)
6011 if (wq) 6192 if (wq)
6012 destroy_workqueue(wq); 6193 destroy_workqueue(wq);
6013 6194
6195 /* release all the volumes */
6196 list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
6197 list) {
6198 if (raid_device->starget) {
6199 sas_target_priv_data =
6200 raid_device->starget->hostdata;
6201 sas_target_priv_data->deleted = 1;
6202 scsi_remove_target(&raid_device->starget->dev);
6203 }
6204 printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
6205 "(0x%016llx)\n", ioc->name, raid_device->handle,
6206 (unsigned long long) raid_device->wwid);
6207 _scsih_raid_device_remove(ioc, raid_device);
6208 }
6209
6014 /* free ports attached to the sas_host */ 6210 /* free ports attached to the sas_host */
6015 retry_again: 6211 retry_again:
6016 list_for_each_entry(mpt2sas_port, 6212 list_for_each_entry(mpt2sas_port,
@@ -6373,6 +6569,13 @@ static struct pci_driver scsih_driver = {
6373#endif 6569#endif
6374}; 6570};
6375 6571
6572/* raid transport support */
6573static struct raid_function_template mpt2sas_raid_functions = {
6574 .cookie = &scsih_driver_template,
6575 .is_raid = _scsih_is_raid,
6576 .get_resync = _scsih_get_resync,
6577 .get_state = _scsih_get_state,
6578};
6376 6579
6377/** 6580/**
6378 * _scsih_init - main entry point for this driver. 6581 * _scsih_init - main entry point for this driver.
@@ -6392,6 +6595,12 @@ _scsih_init(void)
6392 sas_attach_transport(&mpt2sas_transport_functions); 6595 sas_attach_transport(&mpt2sas_transport_functions);
6393 if (!mpt2sas_transport_template) 6596 if (!mpt2sas_transport_template)
6394 return -ENODEV; 6597 return -ENODEV;
6598 /* raid transport support */
6599 mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
6600 if (!mpt2sas_raid_template) {
6601 sas_release_transport(mpt2sas_transport_template);
6602 return -ENODEV;
6603 }
6395 6604
6396 mpt2sas_base_initialize_callback_handler(); 6605 mpt2sas_base_initialize_callback_handler();
6397 6606
@@ -6426,8 +6635,11 @@ _scsih_init(void)
6426 mpt2sas_ctl_init(); 6635 mpt2sas_ctl_init();
6427 6636
6428 error = pci_register_driver(&scsih_driver); 6637 error = pci_register_driver(&scsih_driver);
6429 if (error) 6638 if (error) {
6639 /* raid transport support */
6640 raid_class_release(mpt2sas_raid_template);
6430 sas_release_transport(mpt2sas_transport_template); 6641 sas_release_transport(mpt2sas_transport_template);
6642 }
6431 6643
6432 return error; 6644 return error;
6433} 6645}
@@ -6445,7 +6657,8 @@ _scsih_exit(void)
6445 6657
6446 pci_unregister_driver(&scsih_driver); 6658 pci_unregister_driver(&scsih_driver);
6447 6659
6448 sas_release_transport(mpt2sas_transport_template); 6660 mpt2sas_ctl_exit();
6661
6449 mpt2sas_base_release_callback_handler(scsi_io_cb_idx); 6662 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
6450 mpt2sas_base_release_callback_handler(tm_cb_idx); 6663 mpt2sas_base_release_callback_handler(tm_cb_idx);
6451 mpt2sas_base_release_callback_handler(base_cb_idx); 6664 mpt2sas_base_release_callback_handler(base_cb_idx);
@@ -6457,7 +6670,10 @@ _scsih_exit(void)
6457 mpt2sas_base_release_callback_handler(tm_tr_cb_idx); 6670 mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
6458 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx); 6671 mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
6459 6672
6460 mpt2sas_ctl_exit(); 6673 /* raid transport support */
6674 raid_class_release(mpt2sas_raid_template);
6675 sas_release_transport(mpt2sas_transport_template);
6676
6461} 6677}
6462 6678
6463module_init(_scsih_init); 6679module_init(_scsih_init);
diff --git a/drivers/scsi/mpt2sas/mpt2sas_transport.c b/drivers/scsi/mpt2sas/mpt2sas_transport.c
index 3a82872bad44..789f9ee7f001 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_transport.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_transport.c
@@ -855,6 +855,17 @@ rphy_to_ioc(struct sas_rphy *rphy)
855 return shost_priv(shost); 855 return shost_priv(shost);
856} 856}
857 857
858static struct _sas_phy *
859_transport_find_local_phy(struct MPT2SAS_ADAPTER *ioc, struct sas_phy *phy)
860{
861 int i;
862
863 for (i = 0; i < ioc->sas_hba.num_phys; i++)
864 if (ioc->sas_hba.phy[i].phy == phy)
865 return(&ioc->sas_hba.phy[i]);
866 return NULL;
867}
868
858/** 869/**
859 * _transport_get_linkerrors - 870 * _transport_get_linkerrors -
860 * @phy: The sas phy object 871 * @phy: The sas phy object
@@ -870,14 +881,8 @@ _transport_get_linkerrors(struct sas_phy *phy)
870 struct _sas_phy *mpt2sas_phy; 881 struct _sas_phy *mpt2sas_phy;
871 Mpi2ConfigReply_t mpi_reply; 882 Mpi2ConfigReply_t mpi_reply;
872 Mpi2SasPhyPage1_t phy_pg1; 883 Mpi2SasPhyPage1_t phy_pg1;
873 int i;
874 884
875 for (i = 0, mpt2sas_phy = NULL; i < ioc->sas_hba.num_phys && 885 mpt2sas_phy = _transport_find_local_phy(ioc, phy);
876 !mpt2sas_phy; i++) {
877 if (ioc->sas_hba.phy[i].phy != phy)
878 continue;
879 mpt2sas_phy = &ioc->sas_hba.phy[i];
880 }
881 886
882 if (!mpt2sas_phy) /* this phy not on sas_host */ 887 if (!mpt2sas_phy) /* this phy not on sas_host */
883 return -EINVAL; 888 return -EINVAL;
@@ -971,14 +976,8 @@ _transport_phy_reset(struct sas_phy *phy, int hard_reset)
971 struct _sas_phy *mpt2sas_phy; 976 struct _sas_phy *mpt2sas_phy;
972 Mpi2SasIoUnitControlReply_t mpi_reply; 977 Mpi2SasIoUnitControlReply_t mpi_reply;
973 Mpi2SasIoUnitControlRequest_t mpi_request; 978 Mpi2SasIoUnitControlRequest_t mpi_request;
974 int i;
975 979
976 for (i = 0, mpt2sas_phy = NULL; i < ioc->sas_hba.num_phys && 980 mpt2sas_phy = _transport_find_local_phy(ioc, phy);
977 !mpt2sas_phy; i++) {
978 if (ioc->sas_hba.phy[i].phy != phy)
979 continue;
980 mpt2sas_phy = &ioc->sas_hba.phy[i];
981 }
982 981
983 if (!mpt2sas_phy) /* this phy not on sas_host */ 982 if (!mpt2sas_phy) /* this phy not on sas_host */
984 return -EINVAL; 983 return -EINVAL;
@@ -1006,6 +1005,173 @@ _transport_phy_reset(struct sas_phy *phy, int hard_reset)
1006} 1005}
1007 1006
1008/** 1007/**
1008 * _transport_phy_enable - enable/disable phys
1009 * @phy: The sas phy object
1010 * @enable: enable phy when true
1011 *
1012 * Only support sas_host direct attached phys.
1013 * Returns 0 for success, non-zero for failure.
1014 */
1015static int
1016_transport_phy_enable(struct sas_phy *phy, int enable)
1017{
1018 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
1019 struct _sas_phy *mpt2sas_phy;
1020 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
1021 Mpi2ConfigReply_t mpi_reply;
1022 u16 ioc_status;
1023 u16 sz;
1024 int rc = 0;
1025
1026 mpt2sas_phy = _transport_find_local_phy(ioc, phy);
1027
1028 if (!mpt2sas_phy) /* this phy not on sas_host */
1029 return -EINVAL;
1030
1031 /* sas_iounit page 1 */
1032 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
1033 sizeof(Mpi2SasIOUnit1PhyData_t));
1034 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
1035 if (!sas_iounit_pg1) {
1036 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1037 ioc->name, __FILE__, __LINE__, __func__);
1038 rc = -ENOMEM;
1039 goto out;
1040 }
1041 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
1042 sas_iounit_pg1, sz))) {
1043 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1044 ioc->name, __FILE__, __LINE__, __func__);
1045 rc = -ENXIO;
1046 goto out;
1047 }
1048 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1049 MPI2_IOCSTATUS_MASK;
1050 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1051 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1052 ioc->name, __FILE__, __LINE__, __func__);
1053 rc = -EIO;
1054 goto out;
1055 }
1056
1057 if (enable)
1058 sas_iounit_pg1->PhyData[mpt2sas_phy->phy_id].PhyFlags
1059 &= ~MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
1060 else
1061 sas_iounit_pg1->PhyData[mpt2sas_phy->phy_id].PhyFlags
1062 |= MPI2_SASIOUNIT1_PHYFLAGS_PHY_DISABLE;
1063
1064 mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, sz);
1065
1066 out:
1067 kfree(sas_iounit_pg1);
1068 return rc;
1069}
1070
1071/**
1072 * _transport_phy_speed - set phy min/max link rates
1073 * @phy: The sas phy object
1074 * @rates: rates defined in sas_phy_linkrates
1075 *
1076 * Only support sas_host direct attached phys.
1077 * Returns 0 for success, non-zero for failure.
1078 */
1079static int
1080_transport_phy_speed(struct sas_phy *phy, struct sas_phy_linkrates *rates)
1081{
1082 struct MPT2SAS_ADAPTER *ioc = phy_to_ioc(phy);
1083 struct _sas_phy *mpt2sas_phy;
1084 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
1085 Mpi2SasPhyPage0_t phy_pg0;
1086 Mpi2ConfigReply_t mpi_reply;
1087 u16 ioc_status;
1088 u16 sz;
1089 int i;
1090 int rc = 0;
1091
1092 mpt2sas_phy = _transport_find_local_phy(ioc, phy);
1093
1094 if (!mpt2sas_phy) /* this phy not on sas_host */
1095 return -EINVAL;
1096
1097 if (!rates->minimum_linkrate)
1098 rates->minimum_linkrate = phy->minimum_linkrate;
1099 else if (rates->minimum_linkrate < phy->minimum_linkrate_hw)
1100 rates->minimum_linkrate = phy->minimum_linkrate_hw;
1101
1102 if (!rates->maximum_linkrate)
1103 rates->maximum_linkrate = phy->maximum_linkrate;
1104 else if (rates->maximum_linkrate > phy->maximum_linkrate_hw)
1105 rates->maximum_linkrate = phy->maximum_linkrate_hw;
1106
1107 /* sas_iounit page 1 */
1108 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
1109 sizeof(Mpi2SasIOUnit1PhyData_t));
1110 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
1111 if (!sas_iounit_pg1) {
1112 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1113 ioc->name, __FILE__, __LINE__, __func__);
1114 rc = -ENOMEM;
1115 goto out;
1116 }
1117 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
1118 sas_iounit_pg1, sz))) {
1119 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1120 ioc->name, __FILE__, __LINE__, __func__);
1121 rc = -ENXIO;
1122 goto out;
1123 }
1124 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1125 MPI2_IOCSTATUS_MASK;
1126 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
1127 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1128 ioc->name, __FILE__, __LINE__, __func__);
1129 rc = -EIO;
1130 goto out;
1131 }
1132
1133 for (i = 0; i < ioc->sas_hba.num_phys; i++) {
1134 if (mpt2sas_phy->phy_id != i) {
1135 sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
1136 (ioc->sas_hba.phy[i].phy->minimum_linkrate +
1137 (ioc->sas_hba.phy[i].phy->maximum_linkrate << 4));
1138 } else {
1139 sas_iounit_pg1->PhyData[i].MaxMinLinkRate =
1140 (rates->minimum_linkrate +
1141 (rates->maximum_linkrate << 4));
1142 }
1143 }
1144
1145 if (mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
1146 sz)) {
1147 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
1148 ioc->name, __FILE__, __LINE__, __func__);
1149 rc = -ENXIO;
1150 goto out;
1151 }
1152
1153 /* link reset */
1154 _transport_phy_reset(phy, 0);
1155
1156 /* read phy page 0, then update the rates in the sas transport phy */
1157 if (!mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
1158 mpt2sas_phy->phy_id)) {
1159 phy->minimum_linkrate = _transport_convert_phy_link_rate(
1160 phy_pg0.ProgrammedLinkRate & MPI2_SAS_PRATE_MIN_RATE_MASK);
1161 phy->maximum_linkrate = _transport_convert_phy_link_rate(
1162 phy_pg0.ProgrammedLinkRate >> 4);
1163 phy->negotiated_linkrate = _transport_convert_phy_link_rate(
1164 phy_pg0.NegotiatedLinkRate &
1165 MPI2_SAS_NEG_LINK_RATE_MASK_PHYSICAL);
1166 }
1167
1168 out:
1169 kfree(sas_iounit_pg1);
1170 return rc;
1171}
1172
1173
1174/**
1009 * _transport_smp_handler - transport portal for smp passthru 1175 * _transport_smp_handler - transport portal for smp passthru
1010 * @shost: shost object 1176 * @shost: shost object
1011 * @rphy: sas transport rphy object 1177 * @rphy: sas transport rphy object
@@ -1207,6 +1373,8 @@ struct sas_function_template mpt2sas_transport_functions = {
1207 .get_enclosure_identifier = _transport_get_enclosure_identifier, 1373 .get_enclosure_identifier = _transport_get_enclosure_identifier,
1208 .get_bay_identifier = _transport_get_bay_identifier, 1374 .get_bay_identifier = _transport_get_bay_identifier,
1209 .phy_reset = _transport_phy_reset, 1375 .phy_reset = _transport_phy_reset,
1376 .phy_enable = _transport_phy_enable,
1377 .set_phy_speed = _transport_phy_speed,
1210 .smp_handler = _transport_smp_handler, 1378 .smp_handler = _transport_smp_handler,
1211}; 1379};
1212 1380
diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index c2f1032496cb..f80c1da8f6ca 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -654,7 +654,7 @@ static int __devinit pm8001_pci_probe(struct pci_dev *pdev,
654 } 654 }
655 chip = &pm8001_chips[ent->driver_data]; 655 chip = &pm8001_chips[ent->driver_data];
656 SHOST_TO_SAS_HA(shost) = 656 SHOST_TO_SAS_HA(shost) =
657 kcalloc(1, sizeof(struct sas_ha_struct), GFP_KERNEL); 657 kzalloc(sizeof(struct sas_ha_struct), GFP_KERNEL);
658 if (!SHOST_TO_SAS_HA(shost)) { 658 if (!SHOST_TO_SAS_HA(shost)) {
659 rc = -ENOMEM; 659 rc = -ENOMEM;
660 goto err_out_free_host; 660 goto err_out_free_host;
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 8371d917a9a2..49ac4148493b 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1640,8 +1640,10 @@ qla1280_load_firmware_pio(struct scsi_qla_host *ha)
1640 uint16_t mb[MAILBOX_REGISTER_COUNT], i; 1640 uint16_t mb[MAILBOX_REGISTER_COUNT], i;
1641 int err; 1641 int err;
1642 1642
1643 spin_unlock_irq(ha->host->host_lock);
1643 err = request_firmware(&fw, ql1280_board_tbl[ha->devnum].fwname, 1644 err = request_firmware(&fw, ql1280_board_tbl[ha->devnum].fwname,
1644 &ha->pdev->dev); 1645 &ha->pdev->dev);
1646 spin_lock_irq(ha->host->host_lock);
1645 if (err) { 1647 if (err) {
1646 printk(KERN_ERR "Failed to load image \"%s\" err %d\n", 1648 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
1647 ql1280_board_tbl[ha->devnum].fwname, err); 1649 ql1280_board_tbl[ha->devnum].fwname, err);
@@ -1699,8 +1701,10 @@ qla1280_load_firmware_dma(struct scsi_qla_host *ha)
1699 return -ENOMEM; 1701 return -ENOMEM;
1700#endif 1702#endif
1701 1703
1704 spin_unlock_irq(ha->host->host_lock);
1702 err = request_firmware(&fw, ql1280_board_tbl[ha->devnum].fwname, 1705 err = request_firmware(&fw, ql1280_board_tbl[ha->devnum].fwname,
1703 &ha->pdev->dev); 1706 &ha->pdev->dev);
1707 spin_lock_irq(ha->host->host_lock);
1704 if (err) { 1708 if (err) {
1705 printk(KERN_ERR "Failed to load image \"%s\" err %d\n", 1709 printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
1706 ql1280_board_tbl[ha->devnum].fwname, err); 1710 ql1280_board_tbl[ha->devnum].fwname, err);
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 3a9f5b288aee..90d1e062ec4f 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -11,7 +11,9 @@
11#include <linux/delay.h> 11#include <linux/delay.h>
12 12
13static int qla24xx_vport_disable(struct fc_vport *, bool); 13static int qla24xx_vport_disable(struct fc_vport *, bool);
14 14static int qla84xx_reset(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
15int qla84xx_reset_chip(scsi_qla_host_t *, uint16_t, uint16_t *);
16static int qla84xx_mgmt_cmd(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
15/* SYSFS attributes --------------------------------------------------------- */ 17/* SYSFS attributes --------------------------------------------------------- */
16 18
17static ssize_t 19static ssize_t
@@ -1168,6 +1170,28 @@ qla2x00_total_isp_aborts_show(struct device *dev,
1168} 1170}
1169 1171
1170static ssize_t 1172static ssize_t
1173qla24xx_84xx_fw_version_show(struct device *dev,
1174 struct device_attribute *attr, char *buf)
1175{
1176 int rval = QLA_SUCCESS;
1177 uint16_t status[2] = {0, 0};
1178 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1179 struct qla_hw_data *ha = vha->hw;
1180
1181 if (IS_QLA84XX(ha) && ha->cs84xx) {
1182 if (ha->cs84xx->op_fw_version == 0) {
1183 rval = qla84xx_verify_chip(vha, status);
1184 }
1185
1186 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1187 return snprintf(buf, PAGE_SIZE, "%u\n",
1188 (uint32_t)ha->cs84xx->op_fw_version);
1189 }
1190
1191 return snprintf(buf, PAGE_SIZE, "\n");
1192}
1193
1194static ssize_t
1171qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr, 1195qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1172 char *buf) 1196 char *buf)
1173{ 1197{
@@ -1281,6 +1305,8 @@ static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1281 qla2x00_optrom_fcode_version_show, NULL); 1305 qla2x00_optrom_fcode_version_show, NULL);
1282static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show, 1306static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1283 NULL); 1307 NULL);
1308static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1309 NULL);
1284static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show, 1310static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1285 NULL); 1311 NULL);
1286static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL); 1312static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
@@ -1310,6 +1336,7 @@ struct device_attribute *qla2x00_host_attrs[] = {
1310 &dev_attr_optrom_efi_version, 1336 &dev_attr_optrom_efi_version,
1311 &dev_attr_optrom_fcode_version, 1337 &dev_attr_optrom_fcode_version,
1312 &dev_attr_optrom_fw_version, 1338 &dev_attr_optrom_fw_version,
1339 &dev_attr_84xx_fw_version,
1313 &dev_attr_total_isp_aborts, 1340 &dev_attr_total_isp_aborts,
1314 &dev_attr_mpi_version, 1341 &dev_attr_mpi_version,
1315 &dev_attr_phy_version, 1342 &dev_attr_phy_version,
@@ -1504,8 +1531,6 @@ qla2x00_terminate_rport_io(struct fc_rport *rport)
1504 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha, 1531 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1505 fcport->loop_id, fcport->d_id.b.domain, 1532 fcport->loop_id, fcport->d_id.b.domain,
1506 fcport->d_id.b.area, fcport->d_id.b.al_pa); 1533 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1507
1508 qla2x00_abort_fcport_cmds(fcport);
1509} 1534}
1510 1535
1511static int 1536static int
@@ -1795,6 +1820,581 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1795 return 0; 1820 return 0;
1796} 1821}
1797 1822
1823/* BSG support for ELS/CT pass through */
1824inline srb_t *
1825qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
1826{
1827 srb_t *sp;
1828 struct qla_hw_data *ha = vha->hw;
1829 struct srb_bsg_ctx *ctx;
1830
1831 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
1832 if (!sp)
1833 goto done;
1834 ctx = kzalloc(size, GFP_KERNEL);
1835 if (!ctx) {
1836 mempool_free(sp, ha->srb_mempool);
1837 goto done;
1838 }
1839
1840 memset(sp, 0, sizeof(*sp));
1841 sp->fcport = fcport;
1842 sp->ctx = ctx;
1843done:
1844 return sp;
1845}
1846
1847static int
1848qla2x00_process_els(struct fc_bsg_job *bsg_job)
1849{
1850 struct fc_rport *rport;
1851 fc_port_t *fcport;
1852 struct Scsi_Host *host;
1853 scsi_qla_host_t *vha;
1854 struct qla_hw_data *ha;
1855 srb_t *sp;
1856 const char *type;
1857 int req_sg_cnt, rsp_sg_cnt;
1858 int rval = (DRIVER_ERROR << 16);
1859 uint16_t nextlid = 0;
1860 struct srb_bsg *els;
1861
1862 /* Multiple SG's are not supported for ELS requests */
1863 if (bsg_job->request_payload.sg_cnt > 1 ||
1864 bsg_job->reply_payload.sg_cnt > 1) {
1865 DEBUG2(printk(KERN_INFO
1866 "multiple SG's are not supported for ELS requests"
1867 " [request_sg_cnt: %x reply_sg_cnt: %x]\n",
1868 bsg_job->request_payload.sg_cnt,
1869 bsg_job->reply_payload.sg_cnt));
1870 rval = -EPERM;
1871 goto done;
1872 }
1873
1874 /* ELS request for rport */
1875 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
1876 rport = bsg_job->rport;
1877 fcport = *(fc_port_t **) rport->dd_data;
1878 host = rport_to_shost(rport);
1879 vha = shost_priv(host);
1880 ha = vha->hw;
1881 type = "FC_BSG_RPT_ELS";
1882
1883 /* make sure the rport is logged in,
1884 * if not perform fabric login
1885 */
1886 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
1887 DEBUG2(qla_printk(KERN_WARNING, ha,
1888 "failed to login port %06X for ELS passthru\n",
1889 fcport->d_id.b24));
1890 rval = -EIO;
1891 goto done;
1892 }
1893 } else {
1894 host = bsg_job->shost;
1895 vha = shost_priv(host);
1896 ha = vha->hw;
1897 type = "FC_BSG_HST_ELS_NOLOGIN";
1898
1899 /* Allocate a dummy fcport structure, since functions
1900 * preparing the IOCB and mailbox command retrieves port
1901 * specific information from fcport structure. For Host based
1902 * ELS commands there will be no fcport structure allocated
1903 */
1904 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1905 if (!fcport) {
1906 rval = -ENOMEM;
1907 goto done;
1908 }
1909
1910 /* Initialize all required fields of fcport */
1911 fcport->vha = vha;
1912 fcport->vp_idx = vha->vp_idx;
1913 fcport->d_id.b.al_pa =
1914 bsg_job->request->rqst_data.h_els.port_id[0];
1915 fcport->d_id.b.area =
1916 bsg_job->request->rqst_data.h_els.port_id[1];
1917 fcport->d_id.b.domain =
1918 bsg_job->request->rqst_data.h_els.port_id[2];
1919 fcport->loop_id =
1920 (fcport->d_id.b.al_pa == 0xFD) ?
1921 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
1922 }
1923
1924 if (!vha->flags.online) {
1925 DEBUG2(qla_printk(KERN_WARNING, ha,
1926 "host not online\n"));
1927 rval = -EIO;
1928 goto done;
1929 }
1930
1931 req_sg_cnt =
1932 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1933 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1934 if (!req_sg_cnt) {
1935 rval = -ENOMEM;
1936 goto done_free_fcport;
1937 }
1938 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1939 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1940 if (!rsp_sg_cnt) {
1941 rval = -ENOMEM;
1942 goto done_free_fcport;
1943 }
1944
1945 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1946 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
1947 {
1948 DEBUG2(printk(KERN_INFO
1949 "dma mapping resulted in different sg counts \
1950 [request_sg_cnt: %x dma_request_sg_cnt: %x\
1951 reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
1952 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1953 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
1954 rval = -EAGAIN;
1955 goto done_unmap_sg;
1956 }
1957
1958 /* Alloc SRB structure */
1959 sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
1960 if (!sp) {
1961 rval = -ENOMEM;
1962 goto done_unmap_sg;
1963 }
1964
1965 els = sp->ctx;
1966 els->ctx.type =
1967 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
1968 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
1969 els->bsg_job = bsg_job;
1970
1971 DEBUG2(qla_printk(KERN_INFO, ha,
1972 "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
1973 "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
1974 bsg_job->request->rqst_data.h_els.command_code,
1975 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
1976 fcport->d_id.b.al_pa));
1977
1978 rval = qla2x00_start_sp(sp);
1979 if (rval != QLA_SUCCESS) {
1980 kfree(sp->ctx);
1981 mempool_free(sp, ha->srb_mempool);
1982 rval = -EIO;
1983 goto done_unmap_sg;
1984 }
1985 return rval;
1986
1987done_unmap_sg:
1988 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1989 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1990 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1991 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1992 goto done_free_fcport;
1993
1994done_free_fcport:
1995 if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
1996 kfree(fcport);
1997done:
1998 return rval;
1999}
2000
2001static int
2002qla2x00_process_ct(struct fc_bsg_job *bsg_job)
2003{
2004 srb_t *sp;
2005 struct Scsi_Host *host = bsg_job->shost;
2006 scsi_qla_host_t *vha = shost_priv(host);
2007 struct qla_hw_data *ha = vha->hw;
2008 int rval = (DRIVER_ERROR << 16);
2009 int req_sg_cnt, rsp_sg_cnt;
2010 uint16_t loop_id;
2011 struct fc_port *fcport;
2012 char *type = "FC_BSG_HST_CT";
2013 struct srb_bsg *ct;
2014
2015 /* pass through is supported only for ISP 4Gb or higher */
2016 if (!IS_FWI2_CAPABLE(ha)) {
2017 DEBUG2(qla_printk(KERN_INFO, ha,
2018 "scsi(%ld):Firmware is not capable to support FC "
2019 "CT pass thru\n", vha->host_no));
2020 rval = -EPERM;
2021 goto done;
2022 }
2023
2024 req_sg_cnt =
2025 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
2026 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2027 if (!req_sg_cnt) {
2028 rval = -ENOMEM;
2029 goto done;
2030 }
2031
2032 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
2033 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2034 if (!rsp_sg_cnt) {
2035 rval = -ENOMEM;
2036 goto done;
2037 }
2038
2039 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
2040 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
2041 {
2042 DEBUG2(qla_printk(KERN_WARNING, ha,
2043 "dma mapping resulted in different sg counts \
2044 [request_sg_cnt: %x dma_request_sg_cnt: %x\
2045 reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
2046 bsg_job->request_payload.sg_cnt, req_sg_cnt,
2047 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
2048 rval = -EAGAIN;
2049 goto done_unmap_sg;
2050 }
2051
2052 if (!vha->flags.online) {
2053 DEBUG2(qla_printk(KERN_WARNING, ha,
2054 "host not online\n"));
2055 rval = -EIO;
2056 goto done_unmap_sg;
2057 }
2058
2059 loop_id =
2060 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
2061 >> 24;
2062 switch (loop_id) {
2063 case 0xFC:
2064 loop_id = cpu_to_le16(NPH_SNS);
2065 break;
2066 case 0xFA:
2067 loop_id = vha->mgmt_svr_loop_id;
2068 break;
2069 default:
2070 DEBUG2(qla_printk(KERN_INFO, ha,
2071 "Unknown loop id: %x\n", loop_id));
2072 rval = -EINVAL;
2073 goto done_unmap_sg;
2074 }
2075
2076 /* Allocate a dummy fcport structure, since functions preparing the
2077 * IOCB and mailbox command retrieves port specific information
2078 * from fcport structure. For Host based ELS commands there will be
2079 * no fcport structure allocated
2080 */
2081 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2082 if (!fcport)
2083 {
2084 rval = -ENOMEM;
2085 goto done_unmap_sg;
2086 }
2087
2088 /* Initialize all required fields of fcport */
2089 fcport->vha = vha;
2090 fcport->vp_idx = vha->vp_idx;
2091 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
2092 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
2093 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
2094 fcport->loop_id = loop_id;
2095
2096 /* Alloc SRB structure */
2097 sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
2098 if (!sp) {
2099 rval = -ENOMEM;
2100 goto done_free_fcport;
2101 }
2102
2103 ct = sp->ctx;
2104 ct->ctx.type = SRB_CT_CMD;
2105 ct->bsg_job = bsg_job;
2106
2107 DEBUG2(qla_printk(KERN_INFO, ha,
2108 "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
2109 "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
2110 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
2111 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
2112 fcport->d_id.b.al_pa));
2113
2114 rval = qla2x00_start_sp(sp);
2115 if (rval != QLA_SUCCESS) {
2116 kfree(sp->ctx);
2117 mempool_free(sp, ha->srb_mempool);
2118 rval = -EIO;
2119 goto done_free_fcport;
2120 }
2121 return rval;
2122
2123done_free_fcport:
2124 kfree(fcport);
2125done_unmap_sg:
2126 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
2127 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2128 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
2129 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2130done:
2131 return rval;
2132}
2133
2134static int
2135qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
2136{
2137 struct Scsi_Host *host = bsg_job->shost;
2138 scsi_qla_host_t *vha = shost_priv(host);
2139 struct qla_hw_data *ha = vha->hw;
2140 int rval;
2141 uint8_t command_sent;
2142 uint32_t vendor_cmd;
2143 char *type;
2144 struct msg_echo_lb elreq;
2145 uint16_t response[MAILBOX_REGISTER_COUNT];
2146 uint8_t* fw_sts_ptr;
2147 uint8_t *req_data;
2148 dma_addr_t req_data_dma;
2149 uint32_t req_data_len;
2150 uint8_t *rsp_data;
2151 dma_addr_t rsp_data_dma;
2152 uint32_t rsp_data_len;
2153
2154 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2155 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
2156 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
2157 rval = -EBUSY;
2158 goto done;
2159 }
2160
2161 if (!vha->flags.online) {
2162 DEBUG2(qla_printk(KERN_WARNING, ha,
2163 "host not online\n"));
2164 rval = -EIO;
2165 goto done;
2166 }
2167
2168 elreq.req_sg_cnt =
2169 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
2170 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2171 if (!elreq.req_sg_cnt) {
2172 rval = -ENOMEM;
2173 goto done;
2174 }
2175 elreq.rsp_sg_cnt =
2176 dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
2177 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2178 if (!elreq.rsp_sg_cnt) {
2179 rval = -ENOMEM;
2180 goto done;
2181 }
2182
2183 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
2184 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
2185 {
2186 DEBUG2(printk(KERN_INFO
2187 "dma mapping resulted in different sg counts \
2188 [request_sg_cnt: %x dma_request_sg_cnt: %x\
2189 reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
2190 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
2191 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
2192 rval = -EAGAIN;
2193 goto done_unmap_sg;
2194 }
2195 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
2196 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
2197 &req_data_dma, GFP_KERNEL);
2198
2199 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
2200 &rsp_data_dma, GFP_KERNEL);
2201
2202 /* Copy the request buffer in req_data now */
2203 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2204 bsg_job->request_payload.sg_cnt, req_data,
2205 req_data_len);
2206
2207 elreq.send_dma = req_data_dma;
2208 elreq.rcv_dma = rsp_data_dma;
2209 elreq.transfer_size = req_data_len;
2210
2211 /* Vendor cmd : loopback or ECHO diagnostic
2212 * Options:
2213 * Loopback : Either internal or external loopback
2214 * ECHO: ECHO ELS or Vendor specific FC4 link data
2215 */
2216 vendor_cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd[0];
2217 elreq.options =
2218 *(((uint32_t *)bsg_job->request->rqst_data.h_vendor.vendor_cmd)
2219 + 1);
2220
2221 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
2222 case QL_VND_LOOPBACK:
2223 if (ha->current_topology != ISP_CFG_F) {
2224 type = "FC_BSG_HST_VENDOR_LOOPBACK";
2225
2226 DEBUG2(qla_printk(KERN_INFO, ha,
2227 "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
2228 vha->host_no, type, vendor_cmd, elreq.options));
2229
2230 command_sent = INT_DEF_LB_LOOPBACK_CMD;
2231 rval = qla2x00_loopback_test(vha, &elreq, response);
2232 if (IS_QLA81XX(ha)) {
2233 if (response[0] == MBS_COMMAND_ERROR && response[1] == MBS_LB_RESET) {
2234 DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
2235 "ISP\n", __func__, vha->host_no));
2236 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2237 qla2xxx_wake_dpc(vha);
2238 }
2239 }
2240 } else {
2241 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
2242 DEBUG2(qla_printk(KERN_INFO, ha,
2243 "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
2244 vha->host_no, type, vendor_cmd, elreq.options));
2245
2246 command_sent = INT_DEF_LB_ECHO_CMD;
2247 rval = qla2x00_echo_test(vha, &elreq, response);
2248 }
2249 break;
2250 case QLA84_RESET:
2251 if (!IS_QLA84XX(vha->hw)) {
2252 rval = -EINVAL;
2253 DEBUG16(printk(
2254 "%s(%ld): 8xxx exiting.\n",
2255 __func__, vha->host_no));
2256 return rval;
2257 }
2258 rval = qla84xx_reset(vha, &elreq, bsg_job);
2259 break;
2260 case QLA84_MGMT_CMD:
2261 if (!IS_QLA84XX(vha->hw)) {
2262 rval = -EINVAL;
2263 DEBUG16(printk(
2264 "%s(%ld): 8xxx exiting.\n",
2265 __func__, vha->host_no));
2266 return rval;
2267 }
2268 rval = qla84xx_mgmt_cmd(vha, &elreq, bsg_job);
2269 break;
2270 default:
2271 rval = -ENOSYS;
2272 }
2273
2274 if (rval != QLA_SUCCESS) {
2275 DEBUG2(qla_printk(KERN_WARNING, ha,
2276 "scsi(%ld) Vendor request %s failed\n", vha->host_no, type));
2277 rval = 0;
2278 bsg_job->reply->result = (DID_ERROR << 16);
2279 bsg_job->reply->reply_payload_rcv_len = 0;
2280 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
2281 memcpy( fw_sts_ptr, response, sizeof(response));
2282 fw_sts_ptr += sizeof(response);
2283 *fw_sts_ptr = command_sent;
2284 } else {
2285 DEBUG2(qla_printk(KERN_WARNING, ha,
2286 "scsi(%ld) Vendor request %s completed\n", vha->host_no, type));
2287 rval = bsg_job->reply->result = 0;
2288 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(response) + sizeof(uint8_t);
2289 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
2290 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
2291 memcpy(fw_sts_ptr, response, sizeof(response));
2292 fw_sts_ptr += sizeof(response);
2293 *fw_sts_ptr = command_sent;
2294 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2295 bsg_job->reply_payload.sg_cnt, rsp_data,
2296 rsp_data_len);
2297 }
2298 bsg_job->job_done(bsg_job);
2299
2300done_unmap_sg:
2301
2302 if(req_data)
2303 dma_free_coherent(&ha->pdev->dev, req_data_len,
2304 req_data, req_data_dma);
2305 dma_unmap_sg(&ha->pdev->dev,
2306 bsg_job->request_payload.sg_list,
2307 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2308 dma_unmap_sg(&ha->pdev->dev,
2309 bsg_job->reply_payload.sg_list,
2310 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2311
2312done:
2313 return rval;
2314}
2315
2316static int
2317qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
2318{
2319 int ret = -EINVAL;
2320
2321 switch (bsg_job->request->msgcode) {
2322 case FC_BSG_RPT_ELS:
2323 case FC_BSG_HST_ELS_NOLOGIN:
2324 ret = qla2x00_process_els(bsg_job);
2325 break;
2326 case FC_BSG_HST_CT:
2327 ret = qla2x00_process_ct(bsg_job);
2328 break;
2329 case FC_BSG_HST_VENDOR:
2330 ret = qla2x00_process_vendor_specific(bsg_job);
2331 break;
2332 case FC_BSG_HST_ADD_RPORT:
2333 case FC_BSG_HST_DEL_RPORT:
2334 case FC_BSG_RPT_CT:
2335 default:
2336 DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
2337 break;
2338 }
2339 return ret;
2340}
2341
2342static int
2343qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
2344{
2345 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
2346 struct qla_hw_data *ha = vha->hw;
2347 srb_t *sp;
2348 int cnt, que;
2349 unsigned long flags;
2350 struct req_que *req;
2351 struct srb_bsg *sp_bsg;
2352
2353 /* find the bsg job from the active list of commands */
2354 spin_lock_irqsave(&ha->hardware_lock, flags);
2355 for (que = 0; que < ha->max_req_queues; que++) {
2356 req = ha->req_q_map[que];
2357 if (!req)
2358 continue;
2359
2360 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++ ) {
2361 sp = req->outstanding_cmds[cnt];
2362
2363 if (sp) {
2364 sp_bsg = (struct srb_bsg*)sp->ctx;
2365
2366 if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
2367 (sp_bsg->ctx.type == SRB_ELS_CMD_RPT)
2368 || ( sp_bsg->ctx.type == SRB_ELS_CMD_HST)) &&
2369 (sp_bsg->bsg_job == bsg_job)) {
2370 if (ha->isp_ops->abort_command(sp)) {
2371 DEBUG2(qla_printk(KERN_INFO, ha,
2372 "scsi(%ld): mbx abort_command failed\n", vha->host_no));
2373 bsg_job->req->errors = bsg_job->reply->result = -EIO;
2374 } else {
2375 DEBUG2(qla_printk(KERN_INFO, ha,
2376 "scsi(%ld): mbx abort_command success\n", vha->host_no));
2377 bsg_job->req->errors = bsg_job->reply->result = 0;
2378 }
2379 goto done;
2380 }
2381 }
2382 }
2383 }
2384 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2385 DEBUG2(qla_printk(KERN_INFO, ha,
2386 "scsi(%ld) SRB not found to abort\n", vha->host_no));
2387 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
2388 return 0;
2389
2390done:
2391 if (bsg_job->request->msgcode == FC_BSG_HST_CT)
2392 kfree(sp->fcport);
2393 kfree(sp->ctx);
2394 mempool_free(sp, ha->srb_mempool);
2395 return 0;
2396}
2397
1798struct fc_function_template qla2xxx_transport_functions = { 2398struct fc_function_template qla2xxx_transport_functions = {
1799 2399
1800 .show_host_node_name = 1, 2400 .show_host_node_name = 1,
@@ -1838,6 +2438,8 @@ struct fc_function_template qla2xxx_transport_functions = {
1838 .vport_create = qla24xx_vport_create, 2438 .vport_create = qla24xx_vport_create,
1839 .vport_disable = qla24xx_vport_disable, 2439 .vport_disable = qla24xx_vport_disable,
1840 .vport_delete = qla24xx_vport_delete, 2440 .vport_delete = qla24xx_vport_delete,
2441 .bsg_request = qla24xx_bsg_request,
2442 .bsg_timeout = qla24xx_bsg_timeout,
1841}; 2443};
1842 2444
1843struct fc_function_template qla2xxx_transport_vport_functions = { 2445struct fc_function_template qla2xxx_transport_vport_functions = {
@@ -1878,6 +2480,8 @@ struct fc_function_template qla2xxx_transport_vport_functions = {
1878 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk, 2480 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1879 .terminate_rport_io = qla2x00_terminate_rport_io, 2481 .terminate_rport_io = qla2x00_terminate_rport_io,
1880 .get_fc_host_stats = qla2x00_get_fc_host_stats, 2482 .get_fc_host_stats = qla2x00_get_fc_host_stats,
2483 .bsg_request = qla24xx_bsg_request,
2484 .bsg_timeout = qla24xx_bsg_timeout,
1881}; 2485};
1882 2486
1883void 2487void
@@ -1906,3 +2510,125 @@ qla2x00_init_host_attr(scsi_qla_host_t *vha)
1906 speed = FC_PORTSPEED_1GBIT; 2510 speed = FC_PORTSPEED_1GBIT;
1907 fc_host_supported_speeds(vha->host) = speed; 2511 fc_host_supported_speeds(vha->host) = speed;
1908} 2512}
2513static int
2514qla84xx_reset(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
2515{
2516 int ret = 0;
2517 int cmd;
2518 uint16_t cmd_status;
2519
2520 DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2521
2522 cmd = (*((bsg_job->request->rqst_data.h_vendor.vendor_cmd) + 2))
2523 == A84_RESET_FLAG_ENABLE_DIAG_FW ?
2524 A84_ISSUE_RESET_DIAG_FW : A84_ISSUE_RESET_OP_FW;
2525 ret = qla84xx_reset_chip(ha, cmd == A84_ISSUE_RESET_DIAG_FW,
2526 &cmd_status);
2527 return ret;
2528}
2529
2530static int
2531qla84xx_mgmt_cmd(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
2532{
2533 struct access_chip_84xx *mn;
2534 dma_addr_t mn_dma, mgmt_dma;
2535 void *mgmt_b = NULL;
2536 int ret = 0;
2537 int rsp_hdr_len, len = 0;
2538 struct qla84_msg_mgmt *ql84_mgmt;
2539
2540 ql84_mgmt = (struct qla84_msg_mgmt *) vmalloc(sizeof(struct qla84_msg_mgmt));
2541 ql84_mgmt->cmd =
2542 *((uint16_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 2));
2543 ql84_mgmt->mgmtp.u.mem.start_addr =
2544 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 3));
2545 ql84_mgmt->len =
2546 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 4));
2547 ql84_mgmt->mgmtp.u.config.id =
2548 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 5));
2549 ql84_mgmt->mgmtp.u.config.param0 =
2550 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 6));
2551 ql84_mgmt->mgmtp.u.config.param1 =
2552 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 7));
2553 ql84_mgmt->mgmtp.u.info.type =
2554 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 8));
2555 ql84_mgmt->mgmtp.u.info.context =
2556 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 9));
2557
2558 rsp_hdr_len = bsg_job->request_payload.payload_len;
2559
2560 mn = dma_pool_alloc(ha->hw->s_dma_pool, GFP_KERNEL, &mn_dma);
2561 if (mn == NULL) {
2562 DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
2563 "failed%lu\n", __func__, ha->host_no));
2564 return -ENOMEM;
2565 }
2566
2567 memset(mn, 0, sizeof (struct access_chip_84xx));
2568
2569 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
2570 mn->entry_count = 1;
2571
2572 switch (ql84_mgmt->cmd) {
2573 case QLA84_MGMT_READ_MEM:
2574 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
2575 mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
2576 break;
2577 case QLA84_MGMT_WRITE_MEM:
2578 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
2579 mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
2580 break;
2581 case QLA84_MGMT_CHNG_CONFIG:
2582 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
2583 mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.id);
2584 mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param0);
2585 mn->parameter3 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param1);
2586 break;
2587 case QLA84_MGMT_GET_INFO:
2588 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
2589 mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.type);
2590 mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.context);
2591 break;
2592 default:
2593 ret = -EIO;
2594 goto exit_mgmt0;
2595 }
2596
2597 if ((len == ql84_mgmt->len) &&
2598 ql84_mgmt->cmd != QLA84_MGMT_CHNG_CONFIG) {
2599 mgmt_b = dma_alloc_coherent(&ha->hw->pdev->dev, len,
2600 &mgmt_dma, GFP_KERNEL);
2601 if (mgmt_b == NULL) {
2602 DEBUG2(printk(KERN_ERR "%s: dma alloc mgmt_b "
2603 "failed%lu\n", __func__, ha->host_no));
2604 ret = -ENOMEM;
2605 goto exit_mgmt0;
2606 }
2607 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->len);
2608 mn->dseg_count = cpu_to_le16(1);
2609 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
2610 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
2611 mn->dseg_length = cpu_to_le32(len);
2612
2613 if (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM) {
2614 memcpy(mgmt_b, ql84_mgmt->payload, len);
2615 }
2616 }
2617
2618 ret = qla2x00_issue_iocb(ha, mn, mn_dma, 0);
2619 if ((ret != QLA_SUCCESS) || (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM)
2620 || (ql84_mgmt->cmd == QLA84_MGMT_CHNG_CONFIG)) {
2621 if (ret != QLA_SUCCESS)
2622 DEBUG2(printk(KERN_ERR "%s(%lu): failed\n",
2623 __func__, ha->host_no));
2624 } else if ((ql84_mgmt->cmd == QLA84_MGMT_READ_MEM) ||
2625 (ql84_mgmt->cmd == QLA84_MGMT_GET_INFO)) {
2626 }
2627
2628 if (mgmt_b)
2629 dma_free_coherent(&ha->hw->pdev->dev, len, mgmt_b, mgmt_dma);
2630
2631exit_mgmt0:
2632 dma_pool_free(ha->hw->s_dma_pool, mn, mn_dma);
2633 return ret;
2634}
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 1263d9796e89..afa95614aaf8 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -31,6 +31,7 @@
31#include <scsi/scsi_device.h> 31#include <scsi/scsi_device.h>
32#include <scsi/scsi_cmnd.h> 32#include <scsi/scsi_cmnd.h>
33#include <scsi/scsi_transport_fc.h> 33#include <scsi/scsi_transport_fc.h>
34#include <scsi/scsi_bsg_fc.h>
34 35
35#define QLA2XXX_DRIVER_NAME "qla2xxx" 36#define QLA2XXX_DRIVER_NAME "qla2xxx"
36 37
@@ -228,6 +229,27 @@ struct srb_logio {
228 uint16_t flags; 229 uint16_t flags;
229}; 230};
230 231
232struct srb_bsg_ctx {
233#define SRB_ELS_CMD_RPT 3
234#define SRB_ELS_CMD_HST 4
235#define SRB_CT_CMD 5
236 uint16_t type;
237};
238
239struct srb_bsg {
240 struct srb_bsg_ctx ctx;
241 struct fc_bsg_job *bsg_job;
242};
243
244struct msg_echo_lb {
245 dma_addr_t send_dma;
246 dma_addr_t rcv_dma;
247 uint16_t req_sg_cnt;
248 uint16_t rsp_sg_cnt;
249 uint16_t options;
250 uint32_t transfer_size;
251};
252
231/* 253/*
232 * ISP I/O Register Set structure definitions. 254 * ISP I/O Register Set structure definitions.
233 */ 255 */
@@ -522,6 +544,8 @@ typedef struct {
522#define MBA_DISCARD_RND_FRAME 0x8048 /* discard RND frame due to error. */ 544#define MBA_DISCARD_RND_FRAME 0x8048 /* discard RND frame due to error. */
523#define MBA_REJECTED_FCP_CMD 0x8049 /* rejected FCP_CMD. */ 545#define MBA_REJECTED_FCP_CMD 0x8049 /* rejected FCP_CMD. */
524 546
547/* ISP mailbox loopback echo diagnostic error code */
548#define MBS_LB_RESET 0x17
525/* 549/*
526 * Firmware options 1, 2, 3. 550 * Firmware options 1, 2, 3.
527 */ 551 */
@@ -2230,6 +2254,13 @@ struct req_que {
2230 int max_q_depth; 2254 int max_q_depth;
2231}; 2255};
2232 2256
2257/* Place holder for FW buffer parameters */
2258struct qlfc_fw {
2259 void *fw_buf;
2260 dma_addr_t fw_dma;
2261 uint32_t len;
2262};
2263
2233/* 2264/*
2234 * Qlogic host adapter specific data structure. 2265 * Qlogic host adapter specific data structure.
2235*/ 2266*/
@@ -2594,6 +2625,7 @@ struct qla_hw_data {
2594 struct qla_statistics qla_stats; 2625 struct qla_statistics qla_stats;
2595 struct isp_operations *isp_ops; 2626 struct isp_operations *isp_ops;
2596 struct workqueue_struct *wq; 2627 struct workqueue_struct *wq;
2628 struct qlfc_fw fw_buf;
2597}; 2629};
2598 2630
2599/* 2631/*
@@ -2766,4 +2798,127 @@ typedef struct scsi_qla_host {
2766 2798
2767#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr) 2799#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
2768 2800
2801/*
2802 * BSG Vendor specific commands
2803 */
2804
2805#define QL_VND_LOOPBACK 0x01
2806#define QLA84_RESET 0x02
2807#define QLA84_UPDATE_FW 0x03
2808#define QLA84_MGMT_CMD 0x04
2809
2810/* BSG definations for interpreting CommandSent field */
2811#define INT_DEF_LB_LOOPBACK_CMD 0
2812#define INT_DEF_LB_ECHO_CMD 1
2813
2814/* BSG Vendor specific definations */
2815typedef struct _A84_RESET {
2816 uint16_t Flags;
2817 uint16_t Reserved;
2818#define A84_RESET_FLAG_ENABLE_DIAG_FW 1
2819} __attribute__((packed)) A84_RESET, *PA84_RESET;
2820
2821#define A84_ISSUE_WRITE_TYPE_CMD 0
2822#define A84_ISSUE_READ_TYPE_CMD 1
2823#define A84_CLEANUP_CMD 2
2824#define A84_ISSUE_RESET_OP_FW 3
2825#define A84_ISSUE_RESET_DIAG_FW 4
2826#define A84_ISSUE_UPDATE_OPFW_CMD 5
2827#define A84_ISSUE_UPDATE_DIAGFW_CMD 6
2828
2829struct qla84_mgmt_param {
2830 union {
2831 struct {
2832 uint32_t start_addr;
2833 } mem; /* for QLA84_MGMT_READ/WRITE_MEM */
2834 struct {
2835 uint32_t id;
2836#define QLA84_MGMT_CONFIG_ID_UIF 1
2837#define QLA84_MGMT_CONFIG_ID_FCOE_COS 2
2838#define QLA84_MGMT_CONFIG_ID_PAUSE 3
2839#define QLA84_MGMT_CONFIG_ID_TIMEOUTS 4
2840
2841 uint32_t param0;
2842 uint32_t param1;
2843 } config; /* for QLA84_MGMT_CHNG_CONFIG */
2844
2845 struct {
2846 uint32_t type;
2847#define QLA84_MGMT_INFO_CONFIG_LOG_DATA 1 /* Get Config Log Data */
2848#define QLA84_MGMT_INFO_LOG_DATA 2 /* Get Log Data */
2849#define QLA84_MGMT_INFO_PORT_STAT 3 /* Get Port Statistics */
2850#define QLA84_MGMT_INFO_LIF_STAT 4 /* Get LIF Statistics */
2851#define QLA84_MGMT_INFO_ASIC_STAT 5 /* Get ASIC Statistics */
2852#define QLA84_MGMT_INFO_CONFIG_PARAMS 6 /* Get Config Parameters */
2853#define QLA84_MGMT_INFO_PANIC_LOG 7 /* Get Panic Log */
2854
2855 uint32_t context;
2856/*
2857* context definitions for QLA84_MGMT_INFO_CONFIG_LOG_DATA
2858*/
2859#define IC_LOG_DATA_LOG_ID_DEBUG_LOG 0
2860#define IC_LOG_DATA_LOG_ID_LEARN_LOG 1
2861#define IC_LOG_DATA_LOG_ID_FC_ACL_INGRESS_LOG 2
2862#define IC_LOG_DATA_LOG_ID_FC_ACL_EGRESS_LOG 3
2863#define IC_LOG_DATA_LOG_ID_ETHERNET_ACL_INGRESS_LOG 4
2864#define IC_LOG_DATA_LOG_ID_ETHERNET_ACL_EGRESS_LOG 5
2865#define IC_LOG_DATA_LOG_ID_MESSAGE_TRANSMIT_LOG 6
2866#define IC_LOG_DATA_LOG_ID_MESSAGE_RECEIVE_LOG 7
2867#define IC_LOG_DATA_LOG_ID_LINK_EVENT_LOG 8
2868#define IC_LOG_DATA_LOG_ID_DCX_LOG 9
2869
2870/*
2871* context definitions for QLA84_MGMT_INFO_PORT_STAT
2872*/
2873#define IC_PORT_STATISTICS_PORT_NUMBER_ETHERNET_PORT0 0
2874#define IC_PORT_STATISTICS_PORT_NUMBER_ETHERNET_PORT1 1
2875#define IC_PORT_STATISTICS_PORT_NUMBER_NSL_PORT0 2
2876#define IC_PORT_STATISTICS_PORT_NUMBER_NSL_PORT1 3
2877#define IC_PORT_STATISTICS_PORT_NUMBER_FC_PORT0 4
2878#define IC_PORT_STATISTICS_PORT_NUMBER_FC_PORT1 5
2879
2880
2881/*
2882* context definitions for QLA84_MGMT_INFO_LIF_STAT
2883*/
2884#define IC_LIF_STATISTICS_LIF_NUMBER_ETHERNET_PORT0 0
2885#define IC_LIF_STATISTICS_LIF_NUMBER_ETHERNET_PORT1 1
2886#define IC_LIF_STATISTICS_LIF_NUMBER_FC_PORT0 2
2887#define IC_LIF_STATISTICS_LIF_NUMBER_FC_PORT1 3
2888#define IC_LIF_STATISTICS_LIF_NUMBER_CPU 6
2889
2890 } info; /* for QLA84_MGMT_GET_INFO */
2891 } u;
2892};
2893
2894struct qla84_msg_mgmt {
2895 uint16_t cmd;
2896#define QLA84_MGMT_READ_MEM 0x00
2897#define QLA84_MGMT_WRITE_MEM 0x01
2898#define QLA84_MGMT_CHNG_CONFIG 0x02
2899#define QLA84_MGMT_GET_INFO 0x03
2900 uint16_t rsrvd;
2901 struct qla84_mgmt_param mgmtp;/* parameters for cmd */
2902 uint32_t len; /* bytes in payload following this struct */
2903 uint8_t payload[0]; /* payload for cmd */
2904};
2905
2906struct msg_update_fw {
2907 /*
2908 * diag_fw = 0 operational fw
2909 * otherwise diagnostic fw
2910 * offset, len, fw_len are present to overcome the current limitation
2911 * of 128Kb xfer size. The fw is sent in smaller chunks. Each chunk
2912 * specifies the byte "offset" where it fits in the fw buffer. The
2913 * number of bytes in each chunk is specified in "len". "fw_len"
2914 * is the total size of fw. The first chunk should start at offset = 0.
2915 * When offset+len == fw_len, the fw is written to the HBA.
2916 */
2917 uint32_t diag_fw;
2918 uint32_t offset;/* start offset */
2919 uint32_t len; /* num bytes in cur xfer */
2920 uint32_t fw_len; /* size of fw in bytes */
2921 uint8_t fw_bytes[0];
2922};
2923
2769#endif 2924#endif
diff --git a/drivers/scsi/qla2xxx/qla_fw.h b/drivers/scsi/qla2xxx/qla_fw.h
index 66a8da5d7d08..cebf4f1bb7d9 100644
--- a/drivers/scsi/qla2xxx/qla_fw.h
+++ b/drivers/scsi/qla2xxx/qla_fw.h
@@ -627,6 +627,39 @@ struct els_entry_24xx {
627 uint32_t rx_len; /* Data segment 1 length. */ 627 uint32_t rx_len; /* Data segment 1 length. */
628}; 628};
629 629
630struct els_sts_entry_24xx {
631 uint8_t entry_type; /* Entry type. */
632 uint8_t entry_count; /* Entry count. */
633 uint8_t sys_define; /* System Defined. */
634 uint8_t entry_status; /* Entry Status. */
635
636 uint32_t handle; /* System handle. */
637
638 uint16_t comp_status;
639
640 uint16_t nport_handle; /* N_PORT handle. */
641
642 uint16_t reserved_1;
643
644 uint8_t vp_index;
645 uint8_t sof_type;
646
647 uint32_t rx_xchg_address; /* Receive exchange address. */
648 uint16_t reserved_2;
649
650 uint8_t opcode;
651 uint8_t reserved_3;
652
653 uint8_t port_id[3];
654 uint8_t reserved_4;
655
656 uint16_t reserved_5;
657
658 uint16_t control_flags; /* Control flags. */
659 uint32_t total_byte_count;
660 uint32_t error_subcode_1;
661 uint32_t error_subcode_2;
662};
630/* 663/*
631 * ISP queue - Mailbox Command entry structure definition. 664 * ISP queue - Mailbox Command entry structure definition.
632 */ 665 */
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index 8bc6f53691e9..3a89bc514e2b 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -60,6 +60,8 @@ extern int qla2x00_async_login_done(struct scsi_qla_host *, fc_port_t *,
60extern int qla2x00_async_logout_done(struct scsi_qla_host *, fc_port_t *, 60extern int qla2x00_async_logout_done(struct scsi_qla_host *, fc_port_t *,
61 uint16_t *); 61 uint16_t *);
62 62
63extern fc_port_t *
64qla2x00_alloc_fcport(scsi_qla_host_t *, gfp_t );
63/* 65/*
64 * Global Data in qla_os.c source file. 66 * Global Data in qla_os.c source file.
65 */ 67 */
@@ -76,6 +78,7 @@ extern int ql2xiidmaenable;
76extern int ql2xmaxqueues; 78extern int ql2xmaxqueues;
77extern int ql2xmultique_tag; 79extern int ql2xmultique_tag;
78extern int ql2xfwloadbin; 80extern int ql2xfwloadbin;
81extern int ql2xetsenable;
79 82
80extern int qla2x00_loop_reset(scsi_qla_host_t *); 83extern int qla2x00_loop_reset(scsi_qla_host_t *);
81extern void qla2x00_abort_all_cmds(scsi_qla_host_t *, int); 84extern void qla2x00_abort_all_cmds(scsi_qla_host_t *, int);
@@ -94,7 +97,6 @@ extern int qla2x00_post_uevent_work(struct scsi_qla_host *, u32);
94 97
95extern int qla81xx_restart_mpi_firmware(scsi_qla_host_t *); 98extern int qla81xx_restart_mpi_firmware(scsi_qla_host_t *);
96 99
97extern void qla2x00_abort_fcport_cmds(fc_port_t *);
98extern struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *, 100extern struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *,
99 struct qla_hw_data *); 101 struct qla_hw_data *);
100extern void qla2x00_free_host(struct scsi_qla_host *); 102extern void qla2x00_free_host(struct scsi_qla_host *);
@@ -154,6 +156,7 @@ int qla2x00_marker(struct scsi_qla_host *, struct req_que *, struct rsp_que *,
154int __qla2x00_marker(struct scsi_qla_host *, struct req_que *, struct rsp_que *, 156int __qla2x00_marker(struct scsi_qla_host *, struct req_que *, struct rsp_que *,
155 uint16_t, uint16_t, uint8_t); 157 uint16_t, uint16_t, uint8_t);
156extern int qla2x00_start_sp(srb_t *); 158extern int qla2x00_start_sp(srb_t *);
159extern void qla2x00_ctx_sp_free(srb_t *);
157 160
158/* 161/*
159 * Global Function Prototypes in qla_mbx.c source file. 162 * Global Function Prototypes in qla_mbx.c source file.
@@ -426,6 +429,8 @@ extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
426extern void qla2x00_init_host_attr(scsi_qla_host_t *); 429extern void qla2x00_init_host_attr(scsi_qla_host_t *);
427extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *); 430extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
428extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *); 431extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
432extern int qla2x00_loopback_test(scsi_qla_host_t *, struct msg_echo_lb *, uint16_t *);
433extern int qla2x00_echo_test(scsi_qla_host_t *, struct msg_echo_lb *, uint16_t *);
429 434
430/* 435/*
431 * Global Function Prototypes in qla_dfs.c source file. 436 * Global Function Prototypes in qla_dfs.c source file.
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 3f8e8495b743..a67b2bafb882 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -62,7 +62,7 @@ qla2x00_ctx_sp_timeout(unsigned long __data)
62 ctx->free(sp); 62 ctx->free(sp);
63} 63}
64 64
65static void 65void
66qla2x00_ctx_sp_free(srb_t *sp) 66qla2x00_ctx_sp_free(srb_t *sp)
67{ 67{
68 struct srb_ctx *ctx = sp->ctx; 68 struct srb_ctx *ctx = sp->ctx;
@@ -338,6 +338,16 @@ qla2x00_initialize_adapter(scsi_qla_host_t *vha)
338 rval = qla2x00_init_rings(vha); 338 rval = qla2x00_init_rings(vha);
339 ha->flags.chip_reset_done = 1; 339 ha->flags.chip_reset_done = 1;
340 340
341 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
342 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
343 rval = qla84xx_init_chip(vha);
344 if (rval != QLA_SUCCESS) {
345 qla_printk(KERN_ERR, ha,
346 "Unable to initialize ISP84XX.\n");
347 qla84xx_put_chip(vha);
348 }
349 }
350
341 return (rval); 351 return (rval);
342} 352}
343 353
@@ -2216,7 +2226,7 @@ qla2x00_rport_del(void *data)
2216 * 2226 *
2217 * Returns a pointer to the allocated fcport, or NULL, if none available. 2227 * Returns a pointer to the allocated fcport, or NULL, if none available.
2218 */ 2228 */
2219static fc_port_t * 2229fc_port_t *
2220qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) 2230qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
2221{ 2231{
2222 fc_port_t *fcport; 2232 fc_port_t *fcport;
@@ -2900,8 +2910,13 @@ qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2900 if (qla2x00_is_reserved_id(vha, loop_id)) 2910 if (qla2x00_is_reserved_id(vha, loop_id))
2901 continue; 2911 continue;
2902 2912
2903 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha)) 2913 if (atomic_read(&vha->loop_down_timer) ||
2914 LOOP_TRANSITION(vha)) {
2915 atomic_set(&vha->loop_down_timer, 0);
2916 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2917 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2904 break; 2918 break;
2919 }
2905 2920
2906 if (swl != NULL) { 2921 if (swl != NULL) {
2907 if (last_dev) { 2922 if (last_dev) {
@@ -4877,6 +4892,15 @@ qla81xx_nvram_config(scsi_qla_host_t *vha)
4877} 4892}
4878 4893
4879void 4894void
4880qla81xx_update_fw_options(scsi_qla_host_t *ha) 4895qla81xx_update_fw_options(scsi_qla_host_t *vha)
4881{ 4896{
4897 struct qla_hw_data *ha = vha->hw;
4898
4899 if (!ql2xetsenable)
4900 return;
4901
4902 /* Enable ETS Burst. */
4903 memset(ha->fw_options, 0, sizeof(ha->fw_options));
4904 ha->fw_options[2] |= BIT_9;
4905 qla2x00_set_fw_options(vha, ha->fw_options);
4882} 4906}
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index c5ccac0bef76..8299a9891bfe 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -1025,6 +1025,119 @@ qla2x00_logout_iocb(srb_t *sp, struct mbx_entry *mbx)
1025 /* Implicit: mbx->mbx10 = 0. */ 1025 /* Implicit: mbx->mbx10 = 0. */
1026} 1026}
1027 1027
1028static void
1029qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb)
1030{
1031 struct fc_bsg_job *bsg_job = ((struct srb_bsg*)sp->ctx)->bsg_job;
1032
1033 els_iocb->entry_type = ELS_IOCB_TYPE;
1034 els_iocb->entry_count = 1;
1035 els_iocb->sys_define = 0;
1036 els_iocb->entry_status = 0;
1037 els_iocb->handle = sp->handle;
1038 els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1039 els_iocb->tx_dsd_count = __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
1040 els_iocb->vp_index = sp->fcport->vp_idx;
1041 els_iocb->sof_type = EST_SOFI3;
1042 els_iocb->rx_dsd_count = __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
1043
1044 els_iocb->opcode =(((struct srb_bsg*)sp->ctx)->ctx.type == SRB_ELS_CMD_RPT) ?
1045 bsg_job->request->rqst_data.r_els.els_code : bsg_job->request->rqst_data.h_els.command_code;
1046 els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
1047 els_iocb->port_id[1] = sp->fcport->d_id.b.area;
1048 els_iocb->port_id[2] = sp->fcport->d_id.b.domain;
1049 els_iocb->control_flags = 0;
1050 els_iocb->rx_byte_count =
1051 cpu_to_le32(bsg_job->reply_payload.payload_len);
1052 els_iocb->tx_byte_count =
1053 cpu_to_le32(bsg_job->request_payload.payload_len);
1054
1055 els_iocb->tx_address[0] = cpu_to_le32(LSD(sg_dma_address
1056 (bsg_job->request_payload.sg_list)));
1057 els_iocb->tx_address[1] = cpu_to_le32(MSD(sg_dma_address
1058 (bsg_job->request_payload.sg_list)));
1059 els_iocb->tx_len = cpu_to_le32(sg_dma_len
1060 (bsg_job->request_payload.sg_list));
1061
1062 els_iocb->rx_address[0] = cpu_to_le32(LSD(sg_dma_address
1063 (bsg_job->reply_payload.sg_list)));
1064 els_iocb->rx_address[1] = cpu_to_le32(MSD(sg_dma_address
1065 (bsg_job->reply_payload.sg_list)));
1066 els_iocb->rx_len = cpu_to_le32(sg_dma_len
1067 (bsg_job->reply_payload.sg_list));
1068}
1069
1070static void
1071qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb)
1072{
1073 uint16_t avail_dsds;
1074 uint32_t *cur_dsd;
1075 struct scatterlist *sg;
1076 int index;
1077 uint16_t tot_dsds;
1078 scsi_qla_host_t *vha = sp->fcport->vha;
1079 struct fc_bsg_job *bsg_job = ((struct srb_bsg*)sp->ctx)->bsg_job;
1080 int loop_iterartion = 0;
1081 int cont_iocb_prsnt = 0;
1082 int entry_count = 1;
1083
1084 ct_iocb->entry_type = CT_IOCB_TYPE;
1085 ct_iocb->entry_status = 0;
1086 ct_iocb->sys_define = 0;
1087 ct_iocb->handle = sp->handle;
1088
1089 ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
1090 ct_iocb->vp_index = sp->fcport->vp_idx;
1091 ct_iocb->comp_status = __constant_cpu_to_le16(0);
1092
1093 ct_iocb->cmd_dsd_count =
1094 __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
1095 ct_iocb->timeout = 0;
1096 ct_iocb->rsp_dsd_count =
1097 __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
1098 ct_iocb->rsp_byte_count =
1099 cpu_to_le32(bsg_job->reply_payload.payload_len);
1100 ct_iocb->cmd_byte_count =
1101 cpu_to_le32(bsg_job->request_payload.payload_len);
1102 ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address
1103 (bsg_job->request_payload.sg_list)));
1104 ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address
1105 (bsg_job->request_payload.sg_list)));
1106 ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len
1107 (bsg_job->request_payload.sg_list));
1108
1109 avail_dsds = 1;
1110 cur_dsd = (uint32_t *)ct_iocb->dseg_1_address;
1111 index = 0;
1112 tot_dsds = bsg_job->reply_payload.sg_cnt;
1113
1114 for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
1115 dma_addr_t sle_dma;
1116 cont_a64_entry_t *cont_pkt;
1117
1118 /* Allocate additional continuation packets? */
1119 if (avail_dsds == 0) {
1120 /*
1121 * Five DSDs are available in the Cont.
1122 * Type 1 IOCB.
1123 */
1124 cont_pkt = qla2x00_prep_cont_type1_iocb(vha);
1125 cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
1126 avail_dsds = 5;
1127 cont_iocb_prsnt = 1;
1128 entry_count++;
1129 }
1130
1131 sle_dma = sg_dma_address(sg);
1132 *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
1133 *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
1134 *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
1135 loop_iterartion++;
1136 avail_dsds--;
1137 }
1138 ct_iocb->entry_count = entry_count;
1139}
1140
1028int 1141int
1029qla2x00_start_sp(srb_t *sp) 1142qla2x00_start_sp(srb_t *sp)
1030{ 1143{
@@ -1052,6 +1165,13 @@ qla2x00_start_sp(srb_t *sp)
1052 qla24xx_logout_iocb(sp, pkt): 1165 qla24xx_logout_iocb(sp, pkt):
1053 qla2x00_logout_iocb(sp, pkt); 1166 qla2x00_logout_iocb(sp, pkt);
1054 break; 1167 break;
1168 case SRB_ELS_CMD_RPT:
1169 case SRB_ELS_CMD_HST:
1170 qla24xx_els_iocb(sp, pkt);
1171 break;
1172 case SRB_CT_CMD:
1173 qla24xx_ct_iocb(sp, pkt);
1174 break;
1055 default: 1175 default:
1056 break; 1176 break;
1057 } 1177 }
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 6fc63b98818c..ab90329ff2e4 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/delay.h> 9#include <linux/delay.h>
10#include <scsi/scsi_tcq.h> 10#include <scsi/scsi_tcq.h>
11#include <scsi/scsi_bsg_fc.h>
11 12
12static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t); 13static void qla2x00_mbx_completion(scsi_qla_host_t *, uint16_t);
13static void qla2x00_process_completed_request(struct scsi_qla_host *, 14static void qla2x00_process_completed_request(struct scsi_qla_host *,
@@ -881,7 +882,9 @@ qla2x00_get_sp_from_handle(scsi_qla_host_t *vha, const char *func,
881 index); 882 index);
882 return NULL; 883 return NULL;
883 } 884 }
885
884 req->outstanding_cmds[index] = NULL; 886 req->outstanding_cmds[index] = NULL;
887
885done: 888done:
886 return sp; 889 return sp;
887} 890}
@@ -982,6 +985,100 @@ done_post_logio_done_work:
982} 985}
983 986
984static void 987static void
988qla24xx_els_ct_entry(scsi_qla_host_t *vha, struct req_que *req,
989 struct sts_entry_24xx *pkt, int iocb_type)
990{
991 const char func[] = "ELS_CT_IOCB";
992 const char *type;
993 struct qla_hw_data *ha = vha->hw;
994 srb_t *sp;
995 struct srb_bsg *sp_bsg;
996 struct fc_bsg_job *bsg_job;
997 uint16_t comp_status;
998 uint32_t fw_status[3];
999 uint8_t* fw_sts_ptr;
1000
1001 sp = qla2x00_get_sp_from_handle(vha, func, req, pkt);
1002 if (!sp)
1003 return;
1004 sp_bsg = (struct srb_bsg*)sp->ctx;
1005 bsg_job = sp_bsg->bsg_job;
1006
1007 type = NULL;
1008 switch (sp_bsg->ctx.type) {
1009 case SRB_ELS_CMD_RPT:
1010 case SRB_ELS_CMD_HST:
1011 type = "els";
1012 break;
1013 case SRB_CT_CMD:
1014 type = "ct pass-through";
1015 break;
1016 default:
1017 qla_printk(KERN_WARNING, ha,
1018 "%s: Unrecognized SRB: (%p) type=%d.\n", func, sp,
1019 sp_bsg->ctx.type);
1020 return;
1021 }
1022
1023 comp_status = fw_status[0] = le16_to_cpu(pkt->comp_status);
1024 fw_status[1] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1);
1025 fw_status[2] = le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2);
1026
1027 /* return FC_CTELS_STATUS_OK and leave the decoding of the ELS/CT
1028 * fc payload to the caller
1029 */
1030 bsg_job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1031 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(fw_status);
1032
1033 if (comp_status != CS_COMPLETE) {
1034 if (comp_status == CS_DATA_UNDERRUN) {
1035 bsg_job->reply->result = DID_OK << 16;
1036 bsg_job->reply->reply_payload_rcv_len =
1037 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->total_byte_count);
1038
1039 DEBUG2(qla_printk(KERN_WARNING, ha,
1040 "scsi(%ld:0x%x): ELS-CT pass-through-%s error comp_status-status=0x%x "
1041 "error subcode 1=0x%x error subcode 2=0x%x total_byte = 0x%x.\n",
1042 vha->host_no, sp->handle, type, comp_status, fw_status[1], fw_status[2],
1043 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->total_byte_count)));
1044 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1045 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1046 }
1047 else {
1048 DEBUG2(qla_printk(KERN_WARNING, ha,
1049 "scsi(%ld:0x%x): ELS-CT pass-through-%s error comp_status-status=0x%x "
1050 "error subcode 1=0x%x error subcode 2=0x%x.\n",
1051 vha->host_no, sp->handle, type, comp_status,
1052 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_1),
1053 le16_to_cpu(((struct els_sts_entry_24xx*)pkt)->error_subcode_2)));
1054 bsg_job->reply->result = DID_ERROR << 16;
1055 bsg_job->reply->reply_payload_rcv_len = 0;
1056 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
1057 memcpy( fw_sts_ptr, fw_status, sizeof(fw_status));
1058 }
1059 DEBUG2(qla2x00_dump_buffer((uint8_t *)pkt, sizeof(*pkt)));
1060 }
1061 else {
1062 bsg_job->reply->result = DID_OK << 16;;
1063 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
1064 bsg_job->reply_len = 0;
1065 }
1066
1067 dma_unmap_sg(&ha->pdev->dev,
1068 bsg_job->request_payload.sg_list,
1069 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1070 dma_unmap_sg(&ha->pdev->dev,
1071 bsg_job->reply_payload.sg_list,
1072 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1073 if ((sp_bsg->ctx.type == SRB_ELS_CMD_HST) ||
1074 (sp_bsg->ctx.type == SRB_CT_CMD))
1075 kfree(sp->fcport);
1076 kfree(sp->ctx);
1077 mempool_free(sp, ha->srb_mempool);
1078 bsg_job->job_done(bsg_job);
1079}
1080
1081static void
985qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req, 1082qla24xx_logio_entry(scsi_qla_host_t *vha, struct req_que *req,
986 struct logio_entry_24xx *logio) 1083 struct logio_entry_24xx *logio)
987{ 1084{
@@ -1749,6 +1846,13 @@ void qla24xx_process_response_queue(struct scsi_qla_host *vha,
1749 qla24xx_logio_entry(vha, rsp->req, 1846 qla24xx_logio_entry(vha, rsp->req,
1750 (struct logio_entry_24xx *)pkt); 1847 (struct logio_entry_24xx *)pkt);
1751 break; 1848 break;
1849 case CT_IOCB_TYPE:
1850 qla24xx_els_ct_entry(vha, rsp->req, pkt, CT_IOCB_TYPE);
1851 clear_bit(MBX_INTERRUPT, &vha->hw->mbx_cmd_flags);
1852 break;
1853 case ELS_IOCB_TYPE:
1854 qla24xx_els_ct_entry(vha, rsp->req, pkt, ELS_IOCB_TYPE);
1855 break;
1752 default: 1856 default:
1753 /* Type Not Supported. */ 1857 /* Type Not Supported. */
1754 DEBUG4(printk(KERN_WARNING 1858 DEBUG4(printk(KERN_WARNING
@@ -2049,7 +2153,6 @@ qla24xx_msix_default(int irq, void *dev_id)
2049 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); 2153 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
2050 complete(&ha->mbx_intr_comp); 2154 complete(&ha->mbx_intr_comp);
2051 } 2155 }
2052
2053 return IRQ_HANDLED; 2156 return IRQ_HANDLED;
2054} 2157}
2055 2158
@@ -2255,10 +2358,11 @@ qla2x00_free_irqs(scsi_qla_host_t *vha)
2255 2358
2256 if (ha->flags.msix_enabled) 2359 if (ha->flags.msix_enabled)
2257 qla24xx_disable_msix(ha); 2360 qla24xx_disable_msix(ha);
2258 else if (ha->flags.inta_enabled) { 2361 else if (ha->flags.msi_enabled) {
2259 free_irq(ha->pdev->irq, rsp); 2362 free_irq(ha->pdev->irq, rsp);
2260 pci_disable_msi(ha->pdev); 2363 pci_disable_msi(ha->pdev);
2261 } 2364 } else
2365 free_irq(ha->pdev->irq, rsp);
2262} 2366}
2263 2367
2264 2368
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 056e4d4505f3..6e53bdbb1da8 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -3636,6 +3636,157 @@ qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3636} 3636}
3637 3637
3638int 3638int
3639qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3640{
3641 int rval;
3642 mbx_cmd_t mc;
3643 mbx_cmd_t *mcp = &mc;
3644 uint32_t iter_cnt = 0x1;
3645
3646 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3647
3648 memset(mcp->mb, 0 , sizeof(mcp->mb));
3649 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
3650 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
3651
3652 /* transfer count */
3653 mcp->mb[10] = LSW(mreq->transfer_size);
3654 mcp->mb[11] = MSW(mreq->transfer_size);
3655
3656 /* send data address */
3657 mcp->mb[14] = LSW(mreq->send_dma);
3658 mcp->mb[15] = MSW(mreq->send_dma);
3659 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3660 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3661
3662 /* recieve data address */
3663 mcp->mb[16] = LSW(mreq->rcv_dma);
3664 mcp->mb[17] = MSW(mreq->rcv_dma);
3665 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3666 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3667
3668 /* Iteration count */
3669 mcp->mb[18] = LSW(iter_cnt);
3670 mcp->mb[19] = MSW(iter_cnt);
3671
3672 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
3673 MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3674 if (IS_QLA81XX(vha->hw))
3675 mcp->out_mb |= MBX_2;
3676 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
3677
3678 mcp->buf_size = mreq->transfer_size;
3679 mcp->tov = MBX_TOV_SECONDS;
3680 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3681
3682 rval = qla2x00_mailbox_command(vha, mcp);
3683
3684 if (rval != QLA_SUCCESS) {
3685 DEBUG2(printk(KERN_WARNING
3686 "(%ld): failed=%x mb[0]=0x%x "
3687 "mb[1]=0x%x mb[2]=0x%x mb[3]=0x%x mb[18]=0x%x mb[19]=0x%x. \n", vha->host_no, rval,
3688 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[18], mcp->mb[19]));
3689 } else {
3690 DEBUG2(printk(KERN_WARNING
3691 "scsi(%ld): done.\n", vha->host_no));
3692 }
3693
3694 /* Copy mailbox information */
3695 memcpy( mresp, mcp->mb, 64);
3696 mresp[3] = mcp->mb[18];
3697 mresp[4] = mcp->mb[19];
3698 return rval;
3699}
3700
3701int
3702qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3703{
3704 int rval;
3705 mbx_cmd_t mc;
3706 mbx_cmd_t *mcp = &mc;
3707 struct qla_hw_data *ha = vha->hw;
3708
3709 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3710
3711 memset(mcp->mb, 0 , sizeof(mcp->mb));
3712 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
3713 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
3714 if (IS_QLA81XX(ha))
3715 mcp->mb[1] |= BIT_15;
3716 mcp->mb[2] = IS_QLA81XX(ha) ? vha->fcoe_fcf_idx : 0;
3717 mcp->mb[16] = LSW(mreq->rcv_dma);
3718 mcp->mb[17] = MSW(mreq->rcv_dma);
3719 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3720 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3721
3722 mcp->mb[10] = LSW(mreq->transfer_size);
3723
3724 mcp->mb[14] = LSW(mreq->send_dma);
3725 mcp->mb[15] = MSW(mreq->send_dma);
3726 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3727 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3728
3729 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
3730 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3731 if (IS_QLA81XX(ha))
3732 mcp->out_mb |= MBX_2;
3733
3734 mcp->in_mb = MBX_0;
3735 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))
3736 mcp->in_mb |= MBX_1;
3737 if (IS_QLA81XX(ha))
3738 mcp->in_mb |= MBX_3;
3739
3740 mcp->tov = MBX_TOV_SECONDS;
3741 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3742 mcp->buf_size = mreq->transfer_size;
3743
3744 rval = qla2x00_mailbox_command(vha, mcp);
3745
3746 if (rval != QLA_SUCCESS) {
3747 DEBUG2(printk(KERN_WARNING
3748 "(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3749 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3750 } else {
3751 DEBUG2(printk(KERN_WARNING
3752 "scsi(%ld): done.\n", vha->host_no));
3753 }
3754
3755 /* Copy mailbox information */
3756 memcpy( mresp, mcp->mb, 32);
3757 return rval;
3758}
3759int
3760qla84xx_reset_chip(scsi_qla_host_t *ha, uint16_t enable_diagnostic,
3761 uint16_t *cmd_status)
3762{
3763 int rval;
3764 mbx_cmd_t mc;
3765 mbx_cmd_t *mcp = &mc;
3766
3767 DEBUG16(printk("%s(%ld): enable_diag=%d entered.\n", __func__,
3768 ha->host_no, enable_diagnostic));
3769
3770 mcp->mb[0] = MBC_ISP84XX_RESET;
3771 mcp->mb[1] = enable_diagnostic;
3772 mcp->out_mb = MBX_1|MBX_0;
3773 mcp->in_mb = MBX_1|MBX_0;
3774 mcp->tov = MBX_TOV_SECONDS;
3775 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3776 rval = qla2x00_mailbox_command(ha, mcp);
3777
3778 /* Return mailbox statuses. */
3779 *cmd_status = mcp->mb[0];
3780 if (rval != QLA_SUCCESS)
3781 DEBUG16(printk("%s(%ld): failed=%x.\n", __func__, ha->host_no,
3782 rval));
3783 else
3784 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));
3785
3786 return rval;
3787}
3788
3789int
3639qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data) 3790qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3640{ 3791{
3641 int rval; 3792 int rval;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index 8529eb1f3cd4..46720b23028f 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -107,6 +107,12 @@ MODULE_PARM_DESC(ql2xfwloadbin,
107 " 1 -- load firmware from flash.\n" 107 " 1 -- load firmware from flash.\n"
108 " 0 -- use default semantics.\n"); 108 " 0 -- use default semantics.\n");
109 109
110int ql2xetsenable;
111module_param(ql2xetsenable, int, S_IRUGO|S_IRUSR);
112MODULE_PARM_DESC(ql2xetsenable,
113 "Enables firmware ETS burst."
114 "Default is 0 - skip ETS enablement.");
115
110/* 116/*
111 * SCSI host template entry points 117 * SCSI host template entry points
112 */ 118 */
@@ -682,44 +688,6 @@ qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
682 return (return_status); 688 return (return_status);
683} 689}
684 690
685void
686qla2x00_abort_fcport_cmds(fc_port_t *fcport)
687{
688 int cnt;
689 unsigned long flags;
690 srb_t *sp;
691 scsi_qla_host_t *vha = fcport->vha;
692 struct qla_hw_data *ha = vha->hw;
693 struct req_que *req;
694
695 spin_lock_irqsave(&ha->hardware_lock, flags);
696 req = vha->req;
697 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
698 sp = req->outstanding_cmds[cnt];
699 if (!sp)
700 continue;
701 if (sp->fcport != fcport)
702 continue;
703 if (sp->ctx)
704 continue;
705
706 spin_unlock_irqrestore(&ha->hardware_lock, flags);
707 if (ha->isp_ops->abort_command(sp)) {
708 DEBUG2(qla_printk(KERN_WARNING, ha,
709 "Abort failed -- %lx\n",
710 sp->cmd->serial_number));
711 } else {
712 if (qla2x00_eh_wait_on_command(sp->cmd) !=
713 QLA_SUCCESS)
714 DEBUG2(qla_printk(KERN_WARNING, ha,
715 "Abort failed while waiting -- %lx\n",
716 sp->cmd->serial_number));
717 }
718 spin_lock_irqsave(&ha->hardware_lock, flags);
719 }
720 spin_unlock_irqrestore(&ha->hardware_lock, flags);
721}
722
723/************************************************************************** 691/**************************************************************************
724* qla2xxx_eh_abort 692* qla2xxx_eh_abort
725* 693*
@@ -1095,6 +1063,20 @@ qla2x00_loop_reset(scsi_qla_host_t *vha)
1095 struct fc_port *fcport; 1063 struct fc_port *fcport;
1096 struct qla_hw_data *ha = vha->hw; 1064 struct qla_hw_data *ha = vha->hw;
1097 1065
1066 if (ha->flags.enable_target_reset) {
1067 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1068 if (fcport->port_type != FCT_TARGET)
1069 continue;
1070
1071 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1072 if (ret != QLA_SUCCESS) {
1073 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1074 "target_reset=%d d_id=%x.\n", __func__,
1075 vha->host_no, ret, fcport->d_id.b24));
1076 }
1077 }
1078 }
1079
1098 if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) { 1080 if (ha->flags.enable_lip_full_login && !IS_QLA81XX(ha)) {
1099 ret = qla2x00_full_login_lip(vha); 1081 ret = qla2x00_full_login_lip(vha);
1100 if (ret != QLA_SUCCESS) { 1082 if (ret != QLA_SUCCESS) {
@@ -1117,19 +1099,6 @@ qla2x00_loop_reset(scsi_qla_host_t *vha)
1117 qla2x00_wait_for_loop_ready(vha); 1099 qla2x00_wait_for_loop_ready(vha);
1118 } 1100 }
1119 1101
1120 if (ha->flags.enable_target_reset) {
1121 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1122 if (fcport->port_type != FCT_TARGET)
1123 continue;
1124
1125 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1126 if (ret != QLA_SUCCESS) {
1127 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1128 "target_reset=%d d_id=%x.\n", __func__,
1129 vha->host_no, ret, fcport->d_id.b24));
1130 }
1131 }
1132 }
1133 /* Issue marker command only when we are going to start the I/O */ 1102 /* Issue marker command only when we are going to start the I/O */
1134 vha->marker_needed = 1; 1103 vha->marker_needed = 1;
1135 1104
@@ -1160,8 +1129,19 @@ qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1160 qla2x00_sp_compl(ha, sp); 1129 qla2x00_sp_compl(ha, sp);
1161 } else { 1130 } else {
1162 ctx = sp->ctx; 1131 ctx = sp->ctx;
1163 del_timer_sync(&ctx->timer); 1132 if (ctx->type == SRB_LOGIN_CMD || ctx->type == SRB_LOGOUT_CMD) {
1164 ctx->free(sp); 1133 del_timer_sync(&ctx->timer);
1134 ctx->free(sp);
1135 } else {
1136 struct srb_bsg* sp_bsg = (struct srb_bsg*)sp->ctx;
1137 if (sp_bsg->bsg_job->request->msgcode == FC_BSG_HST_CT)
1138 kfree(sp->fcport);
1139 sp_bsg->bsg_job->req->errors = 0;
1140 sp_bsg->bsg_job->reply->result = res;
1141 sp_bsg->bsg_job->job_done(sp_bsg->bsg_job);
1142 kfree(sp->ctx);
1143 mempool_free(sp, ha->srb_mempool);
1144 }
1165 } 1145 }
1166 } 1146 }
1167 } 1147 }
@@ -1258,7 +1238,7 @@ qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1258 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth); 1238 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1259 break; 1239 break;
1260 default: 1240 default:
1261 return EOPNOTSUPP; 1241 return -EOPNOTSUPP;
1262 } 1242 }
1263 1243
1264 return sdev->queue_depth; 1244 return sdev->queue_depth;
@@ -1818,7 +1798,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1818 /* Set EEH reset type to fundamental if required by hba */ 1798 /* Set EEH reset type to fundamental if required by hba */
1819 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) { 1799 if ( IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha)) {
1820 pdev->needs_freset = 1; 1800 pdev->needs_freset = 1;
1821 pci_save_state(pdev);
1822 } 1801 }
1823 1802
1824 /* Configure PCI I/O space */ 1803 /* Configure PCI I/O space */
@@ -1970,11 +1949,15 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1970 host->max_channel = MAX_BUSES - 1; 1949 host->max_channel = MAX_BUSES - 1;
1971 host->max_lun = MAX_LUNS; 1950 host->max_lun = MAX_LUNS;
1972 host->transportt = qla2xxx_transport_template; 1951 host->transportt = qla2xxx_transport_template;
1952 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
1973 1953
1974 /* Set up the irqs */ 1954 /* Set up the irqs */
1975 ret = qla2x00_request_irqs(ha, rsp); 1955 ret = qla2x00_request_irqs(ha, rsp);
1976 if (ret) 1956 if (ret)
1977 goto probe_init_failed; 1957 goto probe_init_failed;
1958
1959 pci_save_state(pdev);
1960
1978 /* Alloc arrays of request and response ring ptrs */ 1961 /* Alloc arrays of request and response ring ptrs */
1979que_init: 1962que_init:
1980 if (!qla2x00_alloc_queues(ha)) { 1963 if (!qla2x00_alloc_queues(ha)) {
@@ -2176,6 +2159,8 @@ qla2x00_remove_one(struct pci_dev *pdev)
2176 kfree(ha); 2159 kfree(ha);
2177 ha = NULL; 2160 ha = NULL;
2178 2161
2162 pci_disable_pcie_error_reporting(pdev);
2163
2179 pci_disable_device(pdev); 2164 pci_disable_device(pdev);
2180 pci_set_drvdata(pdev, NULL); 2165 pci_set_drvdata(pdev, NULL);
2181} 2166}
@@ -3310,6 +3295,7 @@ qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3310 return PCI_ERS_RESULT_CAN_RECOVER; 3295 return PCI_ERS_RESULT_CAN_RECOVER;
3311 case pci_channel_io_frozen: 3296 case pci_channel_io_frozen:
3312 ha->flags.eeh_busy = 1; 3297 ha->flags.eeh_busy = 1;
3298 qla2x00_free_irqs(vha);
3313 pci_disable_device(pdev); 3299 pci_disable_device(pdev);
3314 return PCI_ERS_RESULT_NEED_RESET; 3300 return PCI_ERS_RESULT_NEED_RESET;
3315 case pci_channel_io_perm_failure: 3301 case pci_channel_io_perm_failure:
@@ -3363,10 +3349,24 @@ qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3363 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; 3349 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3364 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev); 3350 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3365 struct qla_hw_data *ha = base_vha->hw; 3351 struct qla_hw_data *ha = base_vha->hw;
3366 int rc; 3352 struct rsp_que *rsp;
3353 int rc, retries = 10;
3367 3354
3368 DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n")); 3355 DEBUG17(qla_printk(KERN_WARNING, ha, "slot_reset\n"));
3369 3356
3357 /* Workaround: qla2xxx driver which access hardware earlier
3358 * needs error state to be pci_channel_io_online.
3359 * Otherwise mailbox command timesout.
3360 */
3361 pdev->error_state = pci_channel_io_normal;
3362
3363 pci_restore_state(pdev);
3364
3365 /* pci_restore_state() clears the saved_state flag of the device
3366 * save restored state which resets saved_state flag
3367 */
3368 pci_save_state(pdev);
3369
3370 if (ha->mem_only) 3370 if (ha->mem_only)
3371 rc = pci_enable_device_mem(pdev); 3371 rc = pci_enable_device_mem(pdev);
3372 else 3372 else
@@ -3378,27 +3378,23 @@ qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3378 return ret; 3378 return ret;
3379 } 3379 }
3380 3380
3381 rsp = ha->rsp_q_map[0];
3382 if (qla2x00_request_irqs(ha, rsp))
3383 return ret;
3384
3381 if (ha->isp_ops->pci_config(base_vha)) 3385 if (ha->isp_ops->pci_config(base_vha))
3382 return ret; 3386 return ret;
3383 3387
3384#ifdef QL_DEBUG_LEVEL_17 3388 while (ha->flags.mbox_busy && retries--)
3385 { 3389 msleep(1000);
3386 uint8_t b;
3387 uint32_t i;
3388 3390
3389 printk("slot_reset_1: ");
3390 for (i = 0; i < 256; i++) {
3391 pci_read_config_byte(ha->pdev, i, &b);
3392 printk("%s%02x", (i%16) ? " " : "\n", b);
3393 }
3394 printk("\n");
3395 }
3396#endif
3397 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); 3391 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3398 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS) 3392 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
3399 ret = PCI_ERS_RESULT_RECOVERED; 3393 ret = PCI_ERS_RESULT_RECOVERED;
3400 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); 3394 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3401 3395
3396 pci_cleanup_aer_uncorrect_error_status(pdev);
3397
3402 DEBUG17(qla_printk(KERN_WARNING, ha, 3398 DEBUG17(qla_printk(KERN_WARNING, ha,
3403 "slot_reset-return:ret=%x\n", ret)); 3399 "slot_reset-return:ret=%x\n", ret));
3404 3400
@@ -3422,8 +3418,6 @@ qla2xxx_pci_resume(struct pci_dev *pdev)
3422 } 3418 }
3423 3419
3424 ha->flags.eeh_busy = 0; 3420 ha->flags.eeh_busy = 0;
3425
3426 pci_cleanup_aer_uncorrect_error_status(pdev);
3427} 3421}
3428 3422
3429static struct pci_error_handlers qla2xxx_err_handler = { 3423static struct pci_error_handlers qla2xxx_err_handler = {
@@ -3536,4 +3530,3 @@ MODULE_FIRMWARE(FW_FILE_ISP2300);
3536MODULE_FIRMWARE(FW_FILE_ISP2322); 3530MODULE_FIRMWARE(FW_FILE_ISP2322);
3537MODULE_FIRMWARE(FW_FILE_ISP24XX); 3531MODULE_FIRMWARE(FW_FILE_ISP24XX);
3538MODULE_FIRMWARE(FW_FILE_ISP25XX); 3532MODULE_FIRMWARE(FW_FILE_ISP25XX);
3539MODULE_FIRMWARE(FW_FILE_ISP81XX);
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index ed36279a33c1..8d2fc2fa7a6b 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,9 +7,9 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.03.01-k10" 10#define QLA2XXX_VERSION "8.03.02-k1"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 3 13#define QLA_DRIVER_MINOR_VER 3
14#define QLA_DRIVER_PATCH_VER 1 14#define QLA_DRIVER_PATCH_VER 2
15#define QLA_DRIVER_BETA_VER 0 15#define QLA_DRIVER_BETA_VER 1
diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
index af8c3233e8ae..92329a461c68 100644
--- a/drivers/scsi/qla4xxx/ql4_init.c
+++ b/drivers/scsi/qla4xxx/ql4_init.c
@@ -844,10 +844,10 @@ static int qla4xxx_config_nvram(struct scsi_qla_host *ha)
844 DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha->host_no, 844 DEBUG2(printk("scsi%ld: %s: Get EEProm parameters \n", ha->host_no,
845 __func__)); 845 __func__));
846 if (ql4xxx_lock_flash(ha) != QLA_SUCCESS) 846 if (ql4xxx_lock_flash(ha) != QLA_SUCCESS)
847 return (QLA_ERROR); 847 return QLA_ERROR;
848 if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS) { 848 if (ql4xxx_lock_nvram(ha) != QLA_SUCCESS) {
849 ql4xxx_unlock_flash(ha); 849 ql4xxx_unlock_flash(ha);
850 return (QLA_ERROR); 850 return QLA_ERROR;
851 } 851 }
852 852
853 /* Get EEPRom Parameters from NVRAM and validate */ 853 /* Get EEPRom Parameters from NVRAM and validate */
@@ -858,20 +858,18 @@ static int qla4xxx_config_nvram(struct scsi_qla_host *ha)
858 rd_nvram_word(ha, eeprom_ext_hw_conf_offset(ha)); 858 rd_nvram_word(ha, eeprom_ext_hw_conf_offset(ha));
859 spin_unlock_irqrestore(&ha->hardware_lock, flags); 859 spin_unlock_irqrestore(&ha->hardware_lock, flags);
860 } else { 860 } else {
861 /*
862 * QLogic adapters should always have a valid NVRAM.
863 * If not valid, do not load.
864 */
865 dev_warn(&ha->pdev->dev, 861 dev_warn(&ha->pdev->dev,
866 "scsi%ld: %s: EEProm checksum invalid. " 862 "scsi%ld: %s: EEProm checksum invalid. "
867 "Please update your EEPROM\n", ha->host_no, 863 "Please update your EEPROM\n", ha->host_no,
868 __func__); 864 __func__);
869 865
870 /* set defaults */ 866 /* Attempt to set defaults */
871 if (is_qla4010(ha)) 867 if (is_qla4010(ha))
872 extHwConfig.Asuint32_t = 0x1912; 868 extHwConfig.Asuint32_t = 0x1912;
873 else if (is_qla4022(ha) | is_qla4032(ha)) 869 else if (is_qla4022(ha) | is_qla4032(ha))
874 extHwConfig.Asuint32_t = 0x0023; 870 extHwConfig.Asuint32_t = 0x0023;
871 else
872 return QLA_ERROR;
875 } 873 }
876 DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n", 874 DEBUG(printk("scsi%ld: %s: Setting extHwConfig to 0xFFFF%04x\n",
877 ha->host_no, __func__, extHwConfig.Asuint32_t)); 875 ha->host_no, __func__, extHwConfig.Asuint32_t));
@@ -884,7 +882,7 @@ static int qla4xxx_config_nvram(struct scsi_qla_host *ha)
884 ql4xxx_unlock_nvram(ha); 882 ql4xxx_unlock_nvram(ha);
885 ql4xxx_unlock_flash(ha); 883 ql4xxx_unlock_flash(ha);
886 884
887 return (QLA_SUCCESS); 885 return QLA_SUCCESS;
888} 886}
889 887
890static void qla4x00_pci_config(struct scsi_qla_host *ha) 888static void qla4x00_pci_config(struct scsi_qla_host *ha)
diff --git a/drivers/scsi/raid_class.c b/drivers/scsi/raid_class.c
index 8e5c169b03fb..bd88349b8526 100644
--- a/drivers/scsi/raid_class.c
+++ b/drivers/scsi/raid_class.c
@@ -149,6 +149,7 @@ static struct {
149 { RAID_LEVEL_0, "raid0" }, 149 { RAID_LEVEL_0, "raid0" },
150 { RAID_LEVEL_1, "raid1" }, 150 { RAID_LEVEL_1, "raid1" },
151 { RAID_LEVEL_10, "raid10" }, 151 { RAID_LEVEL_10, "raid10" },
152 { RAID_LEVEL_1E, "raid1e" },
152 { RAID_LEVEL_3, "raid3" }, 153 { RAID_LEVEL_3, "raid3" },
153 { RAID_LEVEL_4, "raid4" }, 154 { RAID_LEVEL_4, "raid4" },
154 { RAID_LEVEL_5, "raid5" }, 155 { RAID_LEVEL_5, "raid5" },
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index a60da5555577..513661f45e5f 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -1026,55 +1026,39 @@ static int scsi_vpd_inquiry(struct scsi_device *sdev, unsigned char *buffer,
1026 * responsible for calling kfree() on this pointer when it is no longer 1026 * responsible for calling kfree() on this pointer when it is no longer
1027 * needed. If we cannot retrieve the VPD page this routine returns %NULL. 1027 * needed. If we cannot retrieve the VPD page this routine returns %NULL.
1028 */ 1028 */
1029unsigned char *scsi_get_vpd_page(struct scsi_device *sdev, u8 page) 1029int scsi_get_vpd_page(struct scsi_device *sdev, u8 page, unsigned char *buf,
1030 int buf_len)
1030{ 1031{
1031 int i, result; 1032 int i, result;
1032 unsigned int len;
1033 const unsigned int init_vpd_len = 255;
1034 unsigned char *buf = kmalloc(init_vpd_len, GFP_KERNEL);
1035
1036 if (!buf)
1037 return NULL;
1038 1033
1039 /* Ask for all the pages supported by this device */ 1034 /* Ask for all the pages supported by this device */
1040 result = scsi_vpd_inquiry(sdev, buf, 0, init_vpd_len); 1035 result = scsi_vpd_inquiry(sdev, buf, 0, buf_len);
1041 if (result) 1036 if (result)
1042 goto fail; 1037 goto fail;
1043 1038
1044 /* If the user actually wanted this page, we can skip the rest */ 1039 /* If the user actually wanted this page, we can skip the rest */
1045 if (page == 0) 1040 if (page == 0)
1046 return buf; 1041 return -EINVAL;
1047 1042
1048 for (i = 0; i < buf[3]; i++) 1043 for (i = 0; i < min((int)buf[3], buf_len - 4); i++)
1049 if (buf[i + 4] == page) 1044 if (buf[i + 4] == page)
1050 goto found; 1045 goto found;
1046
1047 if (i < buf[3] && i > buf_len)
1048 /* ran off the end of the buffer, give us benefit of doubt */
1049 goto found;
1051 /* The device claims it doesn't support the requested page */ 1050 /* The device claims it doesn't support the requested page */
1052 goto fail; 1051 goto fail;
1053 1052
1054 found: 1053 found:
1055 result = scsi_vpd_inquiry(sdev, buf, page, 255); 1054 result = scsi_vpd_inquiry(sdev, buf, page, buf_len);
1056 if (result) 1055 if (result)
1057 goto fail; 1056 goto fail;
1058 1057
1059 /* 1058 return 0;
1060 * Some pages are longer than 255 bytes. The actual length of
1061 * the page is returned in the header.
1062 */
1063 len = ((buf[2] << 8) | buf[3]) + 4;
1064 if (len <= init_vpd_len)
1065 return buf;
1066
1067 kfree(buf);
1068 buf = kmalloc(len, GFP_KERNEL);
1069 result = scsi_vpd_inquiry(sdev, buf, page, len);
1070 if (result)
1071 goto fail;
1072
1073 return buf;
1074 1059
1075 fail: 1060 fail:
1076 kfree(buf); 1061 return -EINVAL;
1077 return NULL;
1078} 1062}
1079EXPORT_SYMBOL_GPL(scsi_get_vpd_page); 1063EXPORT_SYMBOL_GPL(scsi_get_vpd_page);
1080 1064
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index c6642423cc67..56977097de9f 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -773,8 +773,14 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
773 * we already took a copy of the original into rq->errors which 773 * we already took a copy of the original into rq->errors which
774 * is what gets returned to the user 774 * is what gets returned to the user
775 */ 775 */
776 if (sense_valid && sshdr.sense_key == RECOVERED_ERROR) { 776 if (sense_valid && (sshdr.sense_key == RECOVERED_ERROR)) {
777 if (!(req->cmd_flags & REQ_QUIET)) 777 /* if ATA PASS-THROUGH INFORMATION AVAILABLE skip
778 * print since caller wants ATA registers. Only occurs on
779 * SCSI ATA PASS_THROUGH commands when CK_COND=1
780 */
781 if ((sshdr.asc == 0x0) && (sshdr.ascq == 0x1d))
782 ;
783 else if (!(req->cmd_flags & REQ_QUIET))
778 scsi_print_sense("", cmd); 784 scsi_print_sense("", cmd);
779 result = 0; 785 result = 0;
780 /* BLOCK_PC may have set error */ 786 /* BLOCK_PC may have set error */
diff --git a/drivers/scsi/scsi_sas_internal.h b/drivers/scsi/scsi_sas_internal.h
index 998cb5be6833..6266a5d73d0f 100644
--- a/drivers/scsi/scsi_sas_internal.h
+++ b/drivers/scsi/scsi_sas_internal.h
@@ -5,7 +5,7 @@
5#define SAS_PHY_ATTRS 17 5#define SAS_PHY_ATTRS 17
6#define SAS_PORT_ATTRS 1 6#define SAS_PORT_ATTRS 1
7#define SAS_RPORT_ATTRS 7 7#define SAS_RPORT_ATTRS 7
8#define SAS_END_DEV_ATTRS 3 8#define SAS_END_DEV_ATTRS 5
9#define SAS_EXPANDER_ATTRS 7 9#define SAS_EXPANDER_ATTRS 7
10 10
11struct sas_internal { 11struct sas_internal {
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 012f73a96880..f697229ae5a9 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1339,8 +1339,10 @@ static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
1339 sdev = scsi_alloc_sdev(starget, 0, NULL); 1339 sdev = scsi_alloc_sdev(starget, 0, NULL);
1340 if (!sdev) 1340 if (!sdev)
1341 return 0; 1341 return 0;
1342 if (scsi_device_get(sdev)) 1342 if (scsi_device_get(sdev)) {
1343 __scsi_remove_device(sdev);
1343 return 0; 1344 return 0;
1345 }
1344 } 1346 }
1345 1347
1346 sprintf(devname, "host %d channel %d id %d", 1348 sprintf(devname, "host %d channel %d id %d",
@@ -1907,10 +1909,9 @@ struct scsi_device *scsi_get_host_dev(struct Scsi_Host *shost)
1907 goto out; 1909 goto out;
1908 1910
1909 sdev = scsi_alloc_sdev(starget, 0, NULL); 1911 sdev = scsi_alloc_sdev(starget, 0, NULL);
1910 if (sdev) { 1912 if (sdev)
1911 sdev->sdev_gendev.parent = get_device(&starget->dev);
1912 sdev->borken = 0; 1913 sdev->borken = 0;
1913 } else 1914 else
1914 scsi_target_reap(starget); 1915 scsi_target_reap(starget);
1915 put_device(&starget->dev); 1916 put_device(&starget->dev);
1916 out: 1917 out:
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 5a065055e68a..19ec9e2d3f39 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -847,6 +847,8 @@ static int scsi_target_add(struct scsi_target *starget)
847 if (starget->state != STARGET_CREATED) 847 if (starget->state != STARGET_CREATED)
848 return 0; 848 return 0;
849 849
850 device_enable_async_suspend(&starget->dev);
851
850 error = device_add(&starget->dev); 852 error = device_add(&starget->dev);
851 if (error) { 853 if (error) {
852 dev_err(&starget->dev, "target device_add failed, error %d\n", error); 854 dev_err(&starget->dev, "target device_add failed, error %d\n", error);
@@ -878,7 +880,8 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
878 struct request_queue *rq = sdev->request_queue; 880 struct request_queue *rq = sdev->request_queue;
879 struct scsi_target *starget = sdev->sdev_target; 881 struct scsi_target *starget = sdev->sdev_target;
880 882
881 if ((error = scsi_device_set_state(sdev, SDEV_RUNNING)) != 0) 883 error = scsi_device_set_state(sdev, SDEV_RUNNING);
884 if (error)
882 return error; 885 return error;
883 886
884 error = scsi_target_add(starget); 887 error = scsi_target_add(starget);
@@ -886,16 +889,18 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
886 return error; 889 return error;
887 890
888 transport_configure_device(&starget->dev); 891 transport_configure_device(&starget->dev);
892 device_enable_async_suspend(&sdev->sdev_gendev);
889 error = device_add(&sdev->sdev_gendev); 893 error = device_add(&sdev->sdev_gendev);
890 if (error) { 894 if (error) {
891 printk(KERN_INFO "error 1\n"); 895 printk(KERN_INFO "error 1\n");
892 goto out_remove; 896 return error;
893 } 897 }
898 device_enable_async_suspend(&sdev->sdev_dev);
894 error = device_add(&sdev->sdev_dev); 899 error = device_add(&sdev->sdev_dev);
895 if (error) { 900 if (error) {
896 printk(KERN_INFO "error 2\n"); 901 printk(KERN_INFO "error 2\n");
897 device_del(&sdev->sdev_gendev); 902 device_del(&sdev->sdev_gendev);
898 goto out_remove; 903 return error;
899 } 904 }
900 transport_add_device(&sdev->sdev_gendev); 905 transport_add_device(&sdev->sdev_gendev);
901 sdev->is_visible = 1; 906 sdev->is_visible = 1;
@@ -910,14 +915,14 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
910 else 915 else
911 error = device_create_file(&sdev->sdev_gendev, &dev_attr_queue_depth); 916 error = device_create_file(&sdev->sdev_gendev, &dev_attr_queue_depth);
912 if (error) 917 if (error)
913 goto out_remove; 918 return error;
914 919
915 if (sdev->host->hostt->change_queue_type) 920 if (sdev->host->hostt->change_queue_type)
916 error = device_create_file(&sdev->sdev_gendev, &sdev_attr_queue_type_rw); 921 error = device_create_file(&sdev->sdev_gendev, &sdev_attr_queue_type_rw);
917 else 922 else
918 error = device_create_file(&sdev->sdev_gendev, &dev_attr_queue_type); 923 error = device_create_file(&sdev->sdev_gendev, &dev_attr_queue_type);
919 if (error) 924 if (error)
920 goto out_remove; 925 return error;
921 926
922 error = bsg_register_queue(rq, &sdev->sdev_gendev, NULL, NULL); 927 error = bsg_register_queue(rq, &sdev->sdev_gendev, NULL, NULL);
923 928
@@ -933,16 +938,11 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
933 error = device_create_file(&sdev->sdev_gendev, 938 error = device_create_file(&sdev->sdev_gendev,
934 sdev->host->hostt->sdev_attrs[i]); 939 sdev->host->hostt->sdev_attrs[i]);
935 if (error) 940 if (error)
936 goto out_remove; 941 return error;
937 } 942 }
938 } 943 }
939 944
940 return 0;
941
942 out_remove:
943 __scsi_remove_device(sdev);
944 return error; 945 return error;
945
946} 946}
947 947
948void __scsi_remove_device(struct scsi_device *sdev) 948void __scsi_remove_device(struct scsi_device *sdev)
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 653f22a8deb9..79660ee3e211 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -475,7 +475,8 @@ MODULE_PARM_DESC(dev_loss_tmo,
475 "Maximum number of seconds that the FC transport should" 475 "Maximum number of seconds that the FC transport should"
476 " insulate the loss of a remote port. Once this value is" 476 " insulate the loss of a remote port. Once this value is"
477 " exceeded, the scsi target is removed. Value should be" 477 " exceeded, the scsi target is removed. Value should be"
478 " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT."); 478 " between 1 and SCSI_DEVICE_BLOCK_MAX_TIMEOUT if"
479 " fast_io_fail_tmo is not set.");
479 480
480/* 481/*
481 * Netlink Infrastructure 482 * Netlink Infrastructure
@@ -842,9 +843,17 @@ store_fc_rport_dev_loss_tmo(struct device *dev, struct device_attribute *attr,
842 (rport->port_state == FC_PORTSTATE_NOTPRESENT)) 843 (rport->port_state == FC_PORTSTATE_NOTPRESENT))
843 return -EBUSY; 844 return -EBUSY;
844 val = simple_strtoul(buf, &cp, 0); 845 val = simple_strtoul(buf, &cp, 0);
845 if ((*cp && (*cp != '\n')) || 846 if ((*cp && (*cp != '\n')) || (val < 0))
846 (val < 0) || (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT))
847 return -EINVAL; 847 return -EINVAL;
848
849 /*
850 * If fast_io_fail is off we have to cap
851 * dev_loss_tmo at SCSI_DEVICE_BLOCK_MAX_TIMEOUT
852 */
853 if (rport->fast_io_fail_tmo == -1 &&
854 val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT)
855 return -EINVAL;
856
848 i->f->set_rport_dev_loss_tmo(rport, val); 857 i->f->set_rport_dev_loss_tmo(rport, val);
849 return count; 858 return count;
850} 859}
@@ -925,9 +934,16 @@ store_fc_rport_fast_io_fail_tmo(struct device *dev,
925 rport->fast_io_fail_tmo = -1; 934 rport->fast_io_fail_tmo = -1;
926 else { 935 else {
927 val = simple_strtoul(buf, &cp, 0); 936 val = simple_strtoul(buf, &cp, 0);
928 if ((*cp && (*cp != '\n')) || 937 if ((*cp && (*cp != '\n')) || (val < 0))
929 (val < 0) || (val >= rport->dev_loss_tmo))
930 return -EINVAL; 938 return -EINVAL;
939 /*
940 * Cap fast_io_fail by dev_loss_tmo or
941 * SCSI_DEVICE_BLOCK_MAX_TIMEOUT.
942 */
943 if ((val >= rport->dev_loss_tmo) ||
944 (val > SCSI_DEVICE_BLOCK_MAX_TIMEOUT))
945 return -EINVAL;
946
931 rport->fast_io_fail_tmo = val; 947 rport->fast_io_fail_tmo = val;
932 } 948 }
933 return count; 949 return count;
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index f27e52d963d3..927e99cb7225 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -155,6 +155,17 @@ static struct {
155sas_bitfield_name_search(linkspeed, sas_linkspeed_names) 155sas_bitfield_name_search(linkspeed, sas_linkspeed_names)
156sas_bitfield_name_set(linkspeed, sas_linkspeed_names) 156sas_bitfield_name_set(linkspeed, sas_linkspeed_names)
157 157
158static struct sas_end_device *sas_sdev_to_rdev(struct scsi_device *sdev)
159{
160 struct sas_rphy *rphy = target_to_rphy(sdev->sdev_target);
161 struct sas_end_device *rdev;
162
163 BUG_ON(rphy->identify.device_type != SAS_END_DEVICE);
164
165 rdev = rphy_to_end_device(rphy);
166 return rdev;
167}
168
158static void sas_smp_request(struct request_queue *q, struct Scsi_Host *shost, 169static void sas_smp_request(struct request_queue *q, struct Scsi_Host *shost,
159 struct sas_rphy *rphy) 170 struct sas_rphy *rphy)
160{ 171{
@@ -358,6 +369,85 @@ void sas_remove_host(struct Scsi_Host *shost)
358} 369}
359EXPORT_SYMBOL(sas_remove_host); 370EXPORT_SYMBOL(sas_remove_host);
360 371
372/**
373 * sas_tlr_supported - checking TLR bit in vpd 0x90
374 * @sdev: scsi device struct
375 *
376 * Check Transport Layer Retries are supported or not.
377 * If vpd page 0x90 is present, TRL is supported.
378 *
379 */
380unsigned int
381sas_tlr_supported(struct scsi_device *sdev)
382{
383 const int vpd_len = 32;
384 struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
385 char *buffer = kzalloc(vpd_len, GFP_KERNEL);
386 int ret = 0;
387
388 if (scsi_get_vpd_page(sdev, 0x90, buffer, vpd_len))
389 goto out;
390
391 /*
392 * Magic numbers: the VPD Protocol page (0x90)
393 * has a 4 byte header and then one entry per device port
394 * the TLR bit is at offset 8 on each port entry
395 * if we take the first port, that's at total offset 12
396 */
397 ret = buffer[12] & 0x01;
398
399 out:
400 kfree(buffer);
401 rdev->tlr_supported = ret;
402 return ret;
403
404}
405EXPORT_SYMBOL_GPL(sas_tlr_supported);
406
407/**
408 * sas_disable_tlr - setting TLR flags
409 * @sdev: scsi device struct
410 *
411 * Seting tlr_enabled flag to 0.
412 *
413 */
414void
415sas_disable_tlr(struct scsi_device *sdev)
416{
417 struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
418
419 rdev->tlr_enabled = 0;
420}
421EXPORT_SYMBOL_GPL(sas_disable_tlr);
422
423/**
424 * sas_enable_tlr - setting TLR flags
425 * @sdev: scsi device struct
426 *
427 * Seting tlr_enabled flag 1.
428 *
429 */
430void sas_enable_tlr(struct scsi_device *sdev)
431{
432 unsigned int tlr_supported = 0;
433 tlr_supported = sas_tlr_supported(sdev);
434
435 if (tlr_supported) {
436 struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
437
438 rdev->tlr_enabled = 1;
439 }
440
441 return;
442}
443EXPORT_SYMBOL_GPL(sas_enable_tlr);
444
445unsigned int sas_is_tlr_enabled(struct scsi_device *sdev)
446{
447 struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
448 return rdev->tlr_enabled;
449}
450EXPORT_SYMBOL_GPL(sas_is_tlr_enabled);
361 451
362/* 452/*
363 * SAS Phy attributes 453 * SAS Phy attributes
@@ -1146,15 +1236,10 @@ sas_rphy_simple_attr(identify.phy_identifier, phy_identifier, "%d\n", u8);
1146int sas_read_port_mode_page(struct scsi_device *sdev) 1236int sas_read_port_mode_page(struct scsi_device *sdev)
1147{ 1237{
1148 char *buffer = kzalloc(BUF_SIZE, GFP_KERNEL), *msdata; 1238 char *buffer = kzalloc(BUF_SIZE, GFP_KERNEL), *msdata;
1149 struct sas_rphy *rphy = target_to_rphy(sdev->sdev_target); 1239 struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
1150 struct sas_end_device *rdev;
1151 struct scsi_mode_data mode_data; 1240 struct scsi_mode_data mode_data;
1152 int res, error; 1241 int res, error;
1153 1242
1154 BUG_ON(rphy->identify.device_type != SAS_END_DEVICE);
1155
1156 rdev = rphy_to_end_device(rphy);
1157
1158 if (!buffer) 1243 if (!buffer)
1159 return -ENOMEM; 1244 return -ENOMEM;
1160 1245
@@ -1207,6 +1292,10 @@ sas_end_dev_simple_attr(I_T_nexus_loss_timeout, I_T_nexus_loss_timeout,
1207 "%d\n", int); 1292 "%d\n", int);
1208sas_end_dev_simple_attr(initiator_response_timeout, initiator_response_timeout, 1293sas_end_dev_simple_attr(initiator_response_timeout, initiator_response_timeout,
1209 "%d\n", int); 1294 "%d\n", int);
1295sas_end_dev_simple_attr(tlr_supported, tlr_supported,
1296 "%d\n", int);
1297sas_end_dev_simple_attr(tlr_enabled, tlr_enabled,
1298 "%d\n", int);
1210 1299
1211static DECLARE_TRANSPORT_CLASS(sas_expander_class, 1300static DECLARE_TRANSPORT_CLASS(sas_expander_class,
1212 "sas_expander", NULL, NULL, NULL); 1301 "sas_expander", NULL, NULL, NULL);
@@ -1733,6 +1822,8 @@ sas_attach_transport(struct sas_function_template *ft)
1733 SETUP_END_DEV_ATTRIBUTE(end_dev_ready_led_meaning); 1822 SETUP_END_DEV_ATTRIBUTE(end_dev_ready_led_meaning);
1734 SETUP_END_DEV_ATTRIBUTE(end_dev_I_T_nexus_loss_timeout); 1823 SETUP_END_DEV_ATTRIBUTE(end_dev_I_T_nexus_loss_timeout);
1735 SETUP_END_DEV_ATTRIBUTE(end_dev_initiator_response_timeout); 1824 SETUP_END_DEV_ATTRIBUTE(end_dev_initiator_response_timeout);
1825 SETUP_END_DEV_ATTRIBUTE(end_dev_tlr_supported);
1826 SETUP_END_DEV_ATTRIBUTE(end_dev_tlr_enabled);
1736 i->end_dev_attrs[count] = NULL; 1827 i->end_dev_attrs[count] = NULL;
1737 1828
1738 count = 0; 1829 count = 0;
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 255da53e5a01..1dd4d8407694 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1196,19 +1196,10 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1196 SCpnt->result = 0; 1196 SCpnt->result = 0;
1197 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); 1197 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1198 break; 1198 break;
1199 case ABORTED_COMMAND: 1199 case ABORTED_COMMAND: /* DIF: Target detected corruption */
1200 if (sshdr.asc == 0x10) { /* DIF: Disk detected corruption */ 1200 case ILLEGAL_REQUEST: /* DIX: Host detected corruption */
1201 scsi_print_result(SCpnt); 1201 if (sshdr.asc == 0x10)
1202 scsi_print_sense("sd", SCpnt);
1203 good_bytes = sd_completed_bytes(SCpnt); 1202 good_bytes = sd_completed_bytes(SCpnt);
1204 }
1205 break;
1206 case ILLEGAL_REQUEST:
1207 if (sshdr.asc == 0x10) { /* DIX: HBA detected corruption */
1208 scsi_print_result(SCpnt);
1209 scsi_print_sense("sd", SCpnt);
1210 good_bytes = sd_completed_bytes(SCpnt);
1211 }
1212 break; 1203 break;
1213 default: 1204 default:
1214 break; 1205 break;
@@ -1218,8 +1209,19 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1218 sd_dif_complete(SCpnt, good_bytes); 1209 sd_dif_complete(SCpnt, good_bytes);
1219 1210
1220 if (scsi_host_dif_capable(sdkp->device->host, sdkp->protection_type) 1211 if (scsi_host_dif_capable(sdkp->device->host, sdkp->protection_type)
1221 == SD_DIF_TYPE2_PROTECTION && SCpnt->cmnd != SCpnt->request->cmd) 1212 == SD_DIF_TYPE2_PROTECTION && SCpnt->cmnd != SCpnt->request->cmd) {
1213
1214 /* We have to print a failed command here as the
1215 * extended CDB gets freed before scsi_io_completion()
1216 * is called.
1217 */
1218 if (result)
1219 scsi_print_command(SCpnt);
1220
1222 mempool_free(SCpnt->cmnd, sd_cdb_pool); 1221 mempool_free(SCpnt->cmnd, sd_cdb_pool);
1222 SCpnt->cmnd = NULL;
1223 SCpnt->cmd_len = 0;
1224 }
1223 1225
1224 return good_bytes; 1226 return good_bytes;
1225} 1227}
@@ -1946,13 +1948,13 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
1946{ 1948{
1947 struct request_queue *q = sdkp->disk->queue; 1949 struct request_queue *q = sdkp->disk->queue;
1948 unsigned int sector_sz = sdkp->device->sector_size; 1950 unsigned int sector_sz = sdkp->device->sector_size;
1949 char *buffer; 1951 const int vpd_len = 32;
1952 unsigned char *buffer = kmalloc(vpd_len, GFP_KERNEL);
1950 1953
1951 /* Block Limits VPD */ 1954 if (!buffer ||
1952 buffer = scsi_get_vpd_page(sdkp->device, 0xb0); 1955 /* Block Limits VPD */
1953 1956 scsi_get_vpd_page(sdkp->device, 0xb0, buffer, vpd_len))
1954 if (buffer == NULL) 1957 goto out;
1955 return;
1956 1958
1957 blk_queue_io_min(sdkp->disk->queue, 1959 blk_queue_io_min(sdkp->disk->queue,
1958 get_unaligned_be16(&buffer[6]) * sector_sz); 1960 get_unaligned_be16(&buffer[6]) * sector_sz);
@@ -1984,6 +1986,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
1984 get_unaligned_be32(&buffer[32]) & ~(1 << 31); 1986 get_unaligned_be32(&buffer[32]) & ~(1 << 31);
1985 } 1987 }
1986 1988
1989 out:
1987 kfree(buffer); 1990 kfree(buffer);
1988} 1991}
1989 1992
@@ -1993,20 +1996,23 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
1993 */ 1996 */
1994static void sd_read_block_characteristics(struct scsi_disk *sdkp) 1997static void sd_read_block_characteristics(struct scsi_disk *sdkp)
1995{ 1998{
1996 char *buffer; 1999 unsigned char *buffer;
1997 u16 rot; 2000 u16 rot;
2001 const int vpd_len = 32;
1998 2002
1999 /* Block Device Characteristics VPD */ 2003 buffer = kmalloc(vpd_len, GFP_KERNEL);
2000 buffer = scsi_get_vpd_page(sdkp->device, 0xb1);
2001 2004
2002 if (buffer == NULL) 2005 if (!buffer ||
2003 return; 2006 /* Block Device Characteristics VPD */
2007 scsi_get_vpd_page(sdkp->device, 0xb1, buffer, vpd_len))
2008 goto out;
2004 2009
2005 rot = get_unaligned_be16(&buffer[4]); 2010 rot = get_unaligned_be16(&buffer[4]);
2006 2011
2007 if (rot == 1) 2012 if (rot == 1)
2008 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, sdkp->disk->queue); 2013 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, sdkp->disk->queue);
2009 2014
2015 out:
2010 kfree(buffer); 2016 kfree(buffer);
2011} 2017}
2012 2018
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index 55b034b72708..1d7a8780e00c 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -448,13 +448,17 @@ static void ses_match_to_enclosure(struct enclosure_device *edev,
448 .addr = 0, 448 .addr = 0,
449 }; 449 };
450 450
451 buf = scsi_get_vpd_page(sdev, 0x83); 451 buf = kmalloc(INIT_ALLOC_SIZE, GFP_KERNEL);
452 if (!buf) 452 if (!buf || scsi_get_vpd_page(sdev, 0x83, buf, INIT_ALLOC_SIZE))
453 return; 453 goto free;
454 454
455 ses_enclosure_data_process(edev, to_scsi_device(edev->edev.parent), 0); 455 ses_enclosure_data_process(edev, to_scsi_device(edev->edev.parent), 0);
456 456
457 vpd_len = ((buf[2] << 8) | buf[3]) + 4; 457 vpd_len = ((buf[2] << 8) | buf[3]) + 4;
458 kfree(buf);
459 buf = kmalloc(vpd_len, GFP_KERNEL);
460 if (!buf ||scsi_get_vpd_page(sdev, 0x83, buf, vpd_len))
461 goto free;
458 462
459 desc = buf + 4; 463 desc = buf + 4;
460 while (desc < buf + vpd_len) { 464 while (desc < buf + vpd_len) {
diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index 54023d41fd15..26e8e0e6b8dd 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -1070,7 +1070,7 @@ static int option_setup(char *str) {
1070 char *cur = str; 1070 char *cur = str;
1071 int i = 1; 1071 int i = 1;
1072 1072
1073 while (cur && isdigit(*cur) && i <= MAX_INT_PARAM) { 1073 while (cur && isdigit(*cur) && i < MAX_INT_PARAM) {
1074 ints[i++] = simple_strtoul(cur, NULL, 0); 1074 ints[i++] = simple_strtoul(cur, NULL, 0);
1075 1075
1076 if ((cur = strchr(cur, ',')) != NULL) cur++; 1076 if ((cur = strchr(cur, ',')) != NULL) cur++;
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index d2604c813a20..e4ac5829b637 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -1069,7 +1069,8 @@ static void pvscsi_free_sgls(const struct pvscsi_adapter *adapter)
1069 free_pages((unsigned long)ctx->sgl, get_order(SGL_SIZE)); 1069 free_pages((unsigned long)ctx->sgl, get_order(SGL_SIZE));
1070} 1070}
1071 1071
1072static int pvscsi_setup_msix(const struct pvscsi_adapter *adapter, int *irq) 1072static int pvscsi_setup_msix(const struct pvscsi_adapter *adapter,
1073 unsigned int *irq)
1073{ 1074{
1074 struct msix_entry entry = { 0, PVSCSI_VECTOR_COMPLETION }; 1075 struct msix_entry entry = { 0, PVSCSI_VECTOR_COMPLETION };
1075 int ret; 1076 int ret;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index e9b15c3746fa..a81ff7bc5fa1 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -1217,12 +1217,6 @@ static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
1217 } 1217 }
1218#endif 1218#endif
1219 1219
1220#ifdef CONFIG_SERIAL_8250_AU1X00
1221 /* if access method is AU, it is a 16550 with a quirk */
1222 if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU)
1223 up->bugs |= UART_BUG_NOMSR;
1224#endif
1225
1226 serial_outp(up, UART_LCR, save_lcr); 1220 serial_outp(up, UART_LCR, save_lcr);
1227 1221
1228 if (up->capabilities != uart_config[up->port.type].flags) { 1222 if (up->capabilities != uart_config[up->port.type].flags) {
@@ -2428,7 +2422,7 @@ serial8250_pm(struct uart_port *port, unsigned int state,
2428static unsigned int serial8250_port_size(struct uart_8250_port *pt) 2422static unsigned int serial8250_port_size(struct uart_8250_port *pt)
2429{ 2423{
2430 if (pt->port.iotype == UPIO_AU) 2424 if (pt->port.iotype == UPIO_AU)
2431 return 0x100000; 2425 return 0x1000;
2432#ifdef CONFIG_ARCH_OMAP 2426#ifdef CONFIG_ARCH_OMAP
2433 if (is_omap_port(pt)) 2427 if (is_omap_port(pt))
2434 return 0x16 << pt->port.regshift; 2428 return 0x16 << pt->port.regshift;
@@ -2585,6 +2579,13 @@ static void serial8250_config_port(struct uart_port *port, int flags)
2585 2579
2586 if (flags & UART_CONFIG_TYPE) 2580 if (flags & UART_CONFIG_TYPE)
2587 autoconfig(up, probeflags); 2581 autoconfig(up, probeflags);
2582
2583#ifdef CONFIG_SERIAL_8250_AU1X00
2584 /* if access method is AU, it is a 16550 with a quirk */
2585 if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU)
2586 up->bugs |= UART_BUG_NOMSR;
2587#endif
2588
2588 if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ) 2589 if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
2589 autoconfig_irq(up); 2590 autoconfig_irq(up);
2590 2591
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 9ff47db0b2ce..888a0ce91c4b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -1086,12 +1086,12 @@ config SERIAL_68360
1086 default y 1086 default y
1087 1087
1088config SERIAL_PMACZILOG 1088config SERIAL_PMACZILOG
1089 tristate "PowerMac z85c30 ESCC support" 1089 tristate "Mac or PowerMac z85c30 ESCC support"
1090 depends on PPC_OF && PPC_PMAC 1090 depends on (M68K && MAC) || (PPC_OF && PPC_PMAC)
1091 select SERIAL_CORE 1091 select SERIAL_CORE
1092 help 1092 help
1093 This driver supports the Zilog z85C30 serial ports found on 1093 This driver supports the Zilog z85C30 serial ports found on
1094 PowerMac machines. 1094 (Power)Mac machines.
1095 Say Y or M if you want to be able to these serial ports. 1095 Say Y or M if you want to be able to these serial ports.
1096 1096
1097config SERIAL_PMACZILOG_TTYS 1097config SERIAL_PMACZILOG_TTYS
@@ -1116,16 +1116,16 @@ config SERIAL_PMACZILOG_TTYS
1116 unable to use the 8250 module for PCMCIA or other 16C550-style 1116 unable to use the 8250 module for PCMCIA or other 16C550-style
1117 UARTs. 1117 UARTs.
1118 1118
1119 Say N unless you need the z85c30 ports on your powermac 1119 Say N unless you need the z85c30 ports on your (Power)Mac
1120 to appear as /dev/ttySn. 1120 to appear as /dev/ttySn.
1121 1121
1122config SERIAL_PMACZILOG_CONSOLE 1122config SERIAL_PMACZILOG_CONSOLE
1123 bool "Console on PowerMac z85c30 serial port" 1123 bool "Console on Mac or PowerMac z85c30 serial port"
1124 depends on SERIAL_PMACZILOG=y 1124 depends on SERIAL_PMACZILOG=y
1125 select SERIAL_CORE_CONSOLE 1125 select SERIAL_CORE_CONSOLE
1126 help 1126 help
1127 If you would like to be able to use the z85c30 serial port 1127 If you would like to be able to use the z85c30 serial port
1128 on your PowerMac as the console, you can do so by answering 1128 on your (Power)Mac as the console, you can do so by answering
1129 Y to this option. 1129 Y to this option.
1130 1130
1131config SERIAL_LH7A40X 1131config SERIAL_LH7A40X
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 7ce9e9f567a3..3119fddaedb5 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -74,6 +74,7 @@
74#include <linux/io.h> 74#include <linux/io.h>
75#include <linux/of.h> 75#include <linux/of.h>
76#include <linux/of_platform.h> 76#include <linux/of_platform.h>
77#include <linux/clk.h>
77 78
78#include <asm/mpc52xx.h> 79#include <asm/mpc52xx.h>
79#include <asm/mpc52xx_psc.h> 80#include <asm/mpc52xx_psc.h>
@@ -113,6 +114,7 @@ static void mpc52xx_uart_of_enumerate(void);
113 114
114/* Forward declaration of the interruption handling routine */ 115/* Forward declaration of the interruption handling routine */
115static irqreturn_t mpc52xx_uart_int(int irq, void *dev_id); 116static irqreturn_t mpc52xx_uart_int(int irq, void *dev_id);
117static irqreturn_t mpc5xxx_uart_process_int(struct uart_port *port);
116 118
117 119
118/* Simple macro to test if a port is console or not. This one is taken 120/* Simple macro to test if a port is console or not. This one is taken
@@ -145,6 +147,11 @@ struct psc_ops {
145 void (*cw_disable_ints)(struct uart_port *port); 147 void (*cw_disable_ints)(struct uart_port *port);
146 void (*cw_restore_ints)(struct uart_port *port); 148 void (*cw_restore_ints)(struct uart_port *port);
147 unsigned long (*getuartclk)(void *p); 149 unsigned long (*getuartclk)(void *p);
150 int (*clock)(struct uart_port *port, int enable);
151 int (*fifoc_init)(void);
152 void (*fifoc_uninit)(void);
153 void (*get_irq)(struct uart_port *, struct device_node *);
154 irqreturn_t (*handle_irq)(struct uart_port *port);
148}; 155};
149 156
150#ifdef CONFIG_PPC_MPC52xx 157#ifdef CONFIG_PPC_MPC52xx
@@ -256,6 +263,18 @@ static unsigned long mpc52xx_getuartclk(void *p)
256 return mpc5xxx_get_bus_frequency(p) / 2; 263 return mpc5xxx_get_bus_frequency(p) / 2;
257} 264}
258 265
266static void mpc52xx_psc_get_irq(struct uart_port *port, struct device_node *np)
267{
268 port->irqflags = IRQF_DISABLED;
269 port->irq = irq_of_parse_and_map(np, 0);
270}
271
272/* 52xx specific interrupt handler. The caller holds the port lock */
273static irqreturn_t mpc52xx_psc_handle_irq(struct uart_port *port)
274{
275 return mpc5xxx_uart_process_int(port);
276}
277
259static struct psc_ops mpc52xx_psc_ops = { 278static struct psc_ops mpc52xx_psc_ops = {
260 .fifo_init = mpc52xx_psc_fifo_init, 279 .fifo_init = mpc52xx_psc_fifo_init,
261 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy, 280 .raw_rx_rdy = mpc52xx_psc_raw_rx_rdy,
@@ -273,14 +292,32 @@ static struct psc_ops mpc52xx_psc_ops = {
273 .cw_disable_ints = mpc52xx_psc_cw_disable_ints, 292 .cw_disable_ints = mpc52xx_psc_cw_disable_ints,
274 .cw_restore_ints = mpc52xx_psc_cw_restore_ints, 293 .cw_restore_ints = mpc52xx_psc_cw_restore_ints,
275 .getuartclk = mpc52xx_getuartclk, 294 .getuartclk = mpc52xx_getuartclk,
295 .get_irq = mpc52xx_psc_get_irq,
296 .handle_irq = mpc52xx_psc_handle_irq,
276}; 297};
277 298
278#endif /* CONFIG_MPC52xx */ 299#endif /* CONFIG_MPC52xx */
279 300
280#ifdef CONFIG_PPC_MPC512x 301#ifdef CONFIG_PPC_MPC512x
281#define FIFO_512x(port) ((struct mpc512x_psc_fifo __iomem *)(PSC(port)+1)) 302#define FIFO_512x(port) ((struct mpc512x_psc_fifo __iomem *)(PSC(port)+1))
303
304/* PSC FIFO Controller for mpc512x */
305struct psc_fifoc {
306 u32 fifoc_cmd;
307 u32 fifoc_int;
308 u32 fifoc_dma;
309 u32 fifoc_axe;
310 u32 fifoc_debug;
311};
312
313static struct psc_fifoc __iomem *psc_fifoc;
314static unsigned int psc_fifoc_irq;
315
282static void mpc512x_psc_fifo_init(struct uart_port *port) 316static void mpc512x_psc_fifo_init(struct uart_port *port)
283{ 317{
318 /* /32 prescaler */
319 out_be16(&PSC(port)->mpc52xx_psc_clock_select, 0xdd00);
320
284 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_RESET_SLICE); 321 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_RESET_SLICE);
285 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_ENABLE_SLICE); 322 out_be32(&FIFO_512x(port)->txcmd, MPC512x_PSC_FIFO_ENABLE_SLICE);
286 out_be32(&FIFO_512x(port)->txalarm, 1); 323 out_be32(&FIFO_512x(port)->txalarm, 1);
@@ -393,6 +430,160 @@ static unsigned long mpc512x_getuartclk(void *p)
393 return mpc5xxx_get_bus_frequency(p); 430 return mpc5xxx_get_bus_frequency(p);
394} 431}
395 432
433#define DEFAULT_FIFO_SIZE 16
434
435static unsigned int __init get_fifo_size(struct device_node *np,
436 char *fifo_name)
437{
438 const unsigned int *fp;
439
440 fp = of_get_property(np, fifo_name, NULL);
441 if (fp)
442 return *fp;
443
444 pr_warning("no %s property in %s node, defaulting to %d\n",
445 fifo_name, np->full_name, DEFAULT_FIFO_SIZE);
446
447 return DEFAULT_FIFO_SIZE;
448}
449
450#define FIFOC(_base) ((struct mpc512x_psc_fifo __iomem *) \
451 ((u32)(_base) + sizeof(struct mpc52xx_psc)))
452
453/* Init PSC FIFO Controller */
454static int __init mpc512x_psc_fifoc_init(void)
455{
456 struct device_node *np;
457 void __iomem *psc;
458 unsigned int tx_fifo_size;
459 unsigned int rx_fifo_size;
460 int fifobase = 0; /* current fifo address in 32 bit words */
461
462 np = of_find_compatible_node(NULL, NULL,
463 "fsl,mpc5121-psc-fifo");
464 if (!np) {
465 pr_err("%s: Can't find FIFOC node\n", __func__);
466 return -ENODEV;
467 }
468
469 psc_fifoc = of_iomap(np, 0);
470 if (!psc_fifoc) {
471 pr_err("%s: Can't map FIFOC\n", __func__);
472 return -ENODEV;
473 }
474
475 psc_fifoc_irq = irq_of_parse_and_map(np, 0);
476 of_node_put(np);
477 if (psc_fifoc_irq == NO_IRQ) {
478 pr_err("%s: Can't get FIFOC irq\n", __func__);
479 iounmap(psc_fifoc);
480 return -ENODEV;
481 }
482
483 for_each_compatible_node(np, NULL, "fsl,mpc5121-psc-uart") {
484 tx_fifo_size = get_fifo_size(np, "fsl,tx-fifo-size");
485 rx_fifo_size = get_fifo_size(np, "fsl,rx-fifo-size");
486
487 /* size in register is in 4 byte units */
488 tx_fifo_size /= 4;
489 rx_fifo_size /= 4;
490 if (!tx_fifo_size)
491 tx_fifo_size = 1;
492 if (!rx_fifo_size)
493 rx_fifo_size = 1;
494
495 psc = of_iomap(np, 0);
496 if (!psc) {
497 pr_err("%s: Can't map %s device\n",
498 __func__, np->full_name);
499 continue;
500 }
501
502 /* FIFO space is 4KiB, check if requested size is available */
503 if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) {
504 pr_err("%s: no fifo space available for %s\n",
505 __func__, np->full_name);
506 iounmap(psc);
507 /*
508 * chances are that another device requests less
509 * fifo space, so we continue.
510 */
511 continue;
512 }
513 /* set tx and rx fifo size registers */
514 out_be32(&FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size);
515 fifobase += tx_fifo_size;
516 out_be32(&FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size);
517 fifobase += rx_fifo_size;
518
519 /* reset and enable the slices */
520 out_be32(&FIFOC(psc)->txcmd, 0x80);
521 out_be32(&FIFOC(psc)->txcmd, 0x01);
522 out_be32(&FIFOC(psc)->rxcmd, 0x80);
523 out_be32(&FIFOC(psc)->rxcmd, 0x01);
524
525 iounmap(psc);
526 }
527
528 return 0;
529}
530
531static void __exit mpc512x_psc_fifoc_uninit(void)
532{
533 iounmap(psc_fifoc);
534}
535
536/* 512x specific interrupt handler. The caller holds the port lock */
537static irqreturn_t mpc512x_psc_handle_irq(struct uart_port *port)
538{
539 unsigned long fifoc_int;
540 int psc_num;
541
542 /* Read pending PSC FIFOC interrupts */
543 fifoc_int = in_be32(&psc_fifoc->fifoc_int);
544
545 /* Check if it is an interrupt for this port */
546 psc_num = (port->mapbase & 0xf00) >> 8;
547 if (test_bit(psc_num, &fifoc_int) ||
548 test_bit(psc_num + 16, &fifoc_int))
549 return mpc5xxx_uart_process_int(port);
550
551 return IRQ_NONE;
552}
553
554static int mpc512x_psc_clock(struct uart_port *port, int enable)
555{
556 struct clk *psc_clk;
557 int psc_num;
558 char clk_name[10];
559
560 if (uart_console(port))
561 return 0;
562
563 psc_num = (port->mapbase & 0xf00) >> 8;
564 snprintf(clk_name, sizeof(clk_name), "psc%d_clk", psc_num);
565 psc_clk = clk_get(port->dev, clk_name);
566 if (IS_ERR(psc_clk)) {
567 dev_err(port->dev, "Failed to get PSC clock entry!\n");
568 return -ENODEV;
569 }
570
571 dev_dbg(port->dev, "%s %sable\n", clk_name, enable ? "en" : "dis");
572
573 if (enable)
574 clk_enable(psc_clk);
575 else
576 clk_disable(psc_clk);
577
578 return 0;
579}
580
581static void mpc512x_psc_get_irq(struct uart_port *port, struct device_node *np)
582{
583 port->irqflags = IRQF_SHARED;
584 port->irq = psc_fifoc_irq;
585}
586
396static struct psc_ops mpc512x_psc_ops = { 587static struct psc_ops mpc512x_psc_ops = {
397 .fifo_init = mpc512x_psc_fifo_init, 588 .fifo_init = mpc512x_psc_fifo_init,
398 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy, 589 .raw_rx_rdy = mpc512x_psc_raw_rx_rdy,
@@ -410,6 +601,11 @@ static struct psc_ops mpc512x_psc_ops = {
410 .cw_disable_ints = mpc512x_psc_cw_disable_ints, 601 .cw_disable_ints = mpc512x_psc_cw_disable_ints,
411 .cw_restore_ints = mpc512x_psc_cw_restore_ints, 602 .cw_restore_ints = mpc512x_psc_cw_restore_ints,
412 .getuartclk = mpc512x_getuartclk, 603 .getuartclk = mpc512x_getuartclk,
604 .clock = mpc512x_psc_clock,
605 .fifoc_init = mpc512x_psc_fifoc_init,
606 .fifoc_uninit = mpc512x_psc_fifoc_uninit,
607 .get_irq = mpc512x_psc_get_irq,
608 .handle_irq = mpc512x_psc_handle_irq,
413}; 609};
414#endif 610#endif
415 611
@@ -519,10 +715,15 @@ mpc52xx_uart_startup(struct uart_port *port)
519 struct mpc52xx_psc __iomem *psc = PSC(port); 715 struct mpc52xx_psc __iomem *psc = PSC(port);
520 int ret; 716 int ret;
521 717
718 if (psc_ops->clock) {
719 ret = psc_ops->clock(port, 1);
720 if (ret)
721 return ret;
722 }
723
522 /* Request IRQ */ 724 /* Request IRQ */
523 ret = request_irq(port->irq, mpc52xx_uart_int, 725 ret = request_irq(port->irq, mpc52xx_uart_int,
524 IRQF_DISABLED | IRQF_SAMPLE_RANDOM, 726 port->irqflags, "mpc52xx_psc_uart", port);
525 "mpc52xx_psc_uart", port);
526 if (ret) 727 if (ret)
527 return ret; 728 return ret;
528 729
@@ -553,6 +754,9 @@ mpc52xx_uart_shutdown(struct uart_port *port)
553 port->read_status_mask = 0; 754 port->read_status_mask = 0;
554 out_be16(&psc->mpc52xx_psc_imr, port->read_status_mask); 755 out_be16(&psc->mpc52xx_psc_imr, port->read_status_mask);
555 756
757 if (psc_ops->clock)
758 psc_ops->clock(port, 0);
759
556 /* Release interrupt */ 760 /* Release interrupt */
557 free_irq(port->irq, port); 761 free_irq(port->irq, port);
558} 762}
@@ -851,15 +1055,12 @@ mpc52xx_uart_int_tx_chars(struct uart_port *port)
851} 1055}
852 1056
853static irqreturn_t 1057static irqreturn_t
854mpc52xx_uart_int(int irq, void *dev_id) 1058mpc5xxx_uart_process_int(struct uart_port *port)
855{ 1059{
856 struct uart_port *port = dev_id;
857 unsigned long pass = ISR_PASS_LIMIT; 1060 unsigned long pass = ISR_PASS_LIMIT;
858 unsigned int keepgoing; 1061 unsigned int keepgoing;
859 u8 status; 1062 u8 status;
860 1063
861 spin_lock(&port->lock);
862
863 /* While we have stuff to do, we continue */ 1064 /* While we have stuff to do, we continue */
864 do { 1065 do {
865 /* If we don't find anything to do, we stop */ 1066 /* If we don't find anything to do, we stop */
@@ -886,11 +1087,23 @@ mpc52xx_uart_int(int irq, void *dev_id)
886 1087
887 } while (keepgoing); 1088 } while (keepgoing);
888 1089
889 spin_unlock(&port->lock);
890
891 return IRQ_HANDLED; 1090 return IRQ_HANDLED;
892} 1091}
893 1092
1093static irqreturn_t
1094mpc52xx_uart_int(int irq, void *dev_id)
1095{
1096 struct uart_port *port = dev_id;
1097 irqreturn_t ret;
1098
1099 spin_lock(&port->lock);
1100
1101 ret = psc_ops->handle_irq(port);
1102
1103 spin_unlock(&port->lock);
1104
1105 return ret;
1106}
894 1107
895/* ======================================================================== */ 1108/* ======================================================================== */
896/* Console ( if applicable ) */ 1109/* Console ( if applicable ) */
@@ -1152,7 +1365,7 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
1152 return -EINVAL; 1365 return -EINVAL;
1153 } 1366 }
1154 1367
1155 port->irq = irq_of_parse_and_map(op->node, 0); 1368 psc_ops->get_irq(port, op->node);
1156 if (port->irq == NO_IRQ) { 1369 if (port->irq == NO_IRQ) {
1157 dev_dbg(&op->dev, "Could not get irq\n"); 1370 dev_dbg(&op->dev, "Could not get irq\n");
1158 return -EINVAL; 1371 return -EINVAL;
@@ -1163,10 +1376,8 @@ mpc52xx_uart_of_probe(struct of_device *op, const struct of_device_id *match)
1163 1376
1164 /* Add the port to the uart sub-system */ 1377 /* Add the port to the uart sub-system */
1165 ret = uart_add_one_port(&mpc52xx_uart_driver, port); 1378 ret = uart_add_one_port(&mpc52xx_uart_driver, port);
1166 if (ret) { 1379 if (ret)
1167 irq_dispose_mapping(port->irq);
1168 return ret; 1380 return ret;
1169 }
1170 1381
1171 dev_set_drvdata(&op->dev, (void *)port); 1382 dev_set_drvdata(&op->dev, (void *)port);
1172 return 0; 1383 return 0;
@@ -1178,10 +1389,8 @@ mpc52xx_uart_of_remove(struct of_device *op)
1178 struct uart_port *port = dev_get_drvdata(&op->dev); 1389 struct uart_port *port = dev_get_drvdata(&op->dev);
1179 dev_set_drvdata(&op->dev, NULL); 1390 dev_set_drvdata(&op->dev, NULL);
1180 1391
1181 if (port) { 1392 if (port)
1182 uart_remove_one_port(&mpc52xx_uart_driver, port); 1393 uart_remove_one_port(&mpc52xx_uart_driver, port);
1183 irq_dispose_mapping(port->irq);
1184 }
1185 1394
1186 return 0; 1395 return 0;
1187} 1396}
@@ -1288,6 +1497,15 @@ mpc52xx_uart_init(void)
1288 1497
1289 mpc52xx_uart_of_enumerate(); 1498 mpc52xx_uart_of_enumerate();
1290 1499
1500 /*
1501 * Map the PSC FIFO Controller and init if on MPC512x.
1502 */
1503 if (psc_ops->fifoc_init) {
1504 ret = psc_ops->fifoc_init();
1505 if (ret)
1506 return ret;
1507 }
1508
1291 ret = of_register_platform_driver(&mpc52xx_uart_of_driver); 1509 ret = of_register_platform_driver(&mpc52xx_uart_of_driver);
1292 if (ret) { 1510 if (ret) {
1293 printk(KERN_ERR "%s: of_register_platform_driver failed (%i)\n", 1511 printk(KERN_ERR "%s: of_register_platform_driver failed (%i)\n",
@@ -1302,6 +1520,9 @@ mpc52xx_uart_init(void)
1302static void __exit 1520static void __exit
1303mpc52xx_uart_exit(void) 1521mpc52xx_uart_exit(void)
1304{ 1522{
1523 if (psc_ops->fifoc_uninit)
1524 psc_ops->fifoc_uninit();
1525
1305 of_unregister_platform_driver(&mpc52xx_uart_of_driver); 1526 of_unregister_platform_driver(&mpc52xx_uart_of_driver);
1306 uart_unregister_driver(&mpc52xx_uart_driver); 1527 uart_unregister_driver(&mpc52xx_uart_driver);
1307} 1528}
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index 683e66f18e8c..f020de1cdd50 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -63,11 +63,17 @@
63#include <asm/sections.h> 63#include <asm/sections.h>
64#include <asm/io.h> 64#include <asm/io.h>
65#include <asm/irq.h> 65#include <asm/irq.h>
66
67#ifdef CONFIG_PPC_PMAC
66#include <asm/prom.h> 68#include <asm/prom.h>
67#include <asm/machdep.h> 69#include <asm/machdep.h>
68#include <asm/pmac_feature.h> 70#include <asm/pmac_feature.h>
69#include <asm/dbdma.h> 71#include <asm/dbdma.h>
70#include <asm/macio.h> 72#include <asm/macio.h>
73#else
74#include <linux/platform_device.h>
75#define of_machine_is_compatible(x) (0)
76#endif
71 77
72#if defined (CONFIG_SERIAL_PMACZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 78#if defined (CONFIG_SERIAL_PMACZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
73#define SUPPORT_SYSRQ 79#define SUPPORT_SYSRQ
@@ -83,11 +89,9 @@
83 89
84static char version[] __initdata = "pmac_zilog: 0.6 (Benjamin Herrenschmidt <benh@kernel.crashing.org>)"; 90static char version[] __initdata = "pmac_zilog: 0.6 (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
85MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); 91MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
86MODULE_DESCRIPTION("Driver for the PowerMac serial ports."); 92MODULE_DESCRIPTION("Driver for the Mac and PowerMac serial ports.");
87MODULE_LICENSE("GPL"); 93MODULE_LICENSE("GPL");
88 94
89#define PWRDBG(fmt, arg...) printk(KERN_DEBUG fmt , ## arg)
90
91#ifdef CONFIG_SERIAL_PMACZILOG_TTYS 95#ifdef CONFIG_SERIAL_PMACZILOG_TTYS
92#define PMACZILOG_MAJOR TTY_MAJOR 96#define PMACZILOG_MAJOR TTY_MAJOR
93#define PMACZILOG_MINOR 64 97#define PMACZILOG_MINOR 64
@@ -153,8 +157,8 @@ static void pmz_load_zsregs(struct uart_pmac_port *uap, u8 *regs)
153 write_zsreg(uap, R10, regs[R10]); 157 write_zsreg(uap, R10, regs[R10]);
154 158
155 /* Set TX/RX controls sans the enable bits. */ 159 /* Set TX/RX controls sans the enable bits. */
156 write_zsreg(uap, R3, regs[R3] & ~RxENABLE); 160 write_zsreg(uap, R3, regs[R3] & ~RxENABLE);
157 write_zsreg(uap, R5, regs[R5] & ~TxENABLE); 161 write_zsreg(uap, R5, regs[R5] & ~TxENABLE);
158 162
159 /* now set R7 "prime" on ESCC */ 163 /* now set R7 "prime" on ESCC */
160 write_zsreg(uap, R15, regs[R15] | EN85C30); 164 write_zsreg(uap, R15, regs[R15] | EN85C30);
@@ -205,7 +209,7 @@ static void pmz_load_zsregs(struct uart_pmac_port *uap, u8 *regs)
205 */ 209 */
206static void pmz_maybe_update_regs(struct uart_pmac_port *uap) 210static void pmz_maybe_update_regs(struct uart_pmac_port *uap)
207{ 211{
208 if (!ZS_REGS_HELD(uap)) { 212 if (!ZS_REGS_HELD(uap)) {
209 if (ZS_TX_ACTIVE(uap)) { 213 if (ZS_TX_ACTIVE(uap)) {
210 uap->flags |= PMACZILOG_FLAG_REGS_HELD; 214 uap->flags |= PMACZILOG_FLAG_REGS_HELD;
211 } else { 215 } else {
@@ -281,7 +285,7 @@ static struct tty_struct *pmz_receive_chars(struct uart_pmac_port *uap)
281 spin_lock(&uap->port.lock); 285 spin_lock(&uap->port.lock);
282 if (swallow) 286 if (swallow)
283 goto next_char; 287 goto next_char;
284 } 288 }
285#endif /* CONFIG_MAGIC_SYSRQ && CONFIG_SERIAL_CORE_CONSOLE */ 289#endif /* CONFIG_MAGIC_SYSRQ && CONFIG_SERIAL_CORE_CONSOLE */
286 290
287 /* A real serial line, record the character and status. */ 291 /* A real serial line, record the character and status. */
@@ -317,7 +321,7 @@ static struct tty_struct *pmz_receive_chars(struct uart_pmac_port *uap)
317 321
318 if (uap->port.ignore_status_mask == 0xff || 322 if (uap->port.ignore_status_mask == 0xff ||
319 (r1 & uap->port.ignore_status_mask) == 0) { 323 (r1 & uap->port.ignore_status_mask) == 0) {
320 tty_insert_flip_char(tty, ch, flag); 324 tty_insert_flip_char(tty, ch, flag);
321 } 325 }
322 if (r1 & Rx_OVR) 326 if (r1 & Rx_OVR)
323 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 327 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
@@ -341,7 +345,7 @@ static struct tty_struct *pmz_receive_chars(struct uart_pmac_port *uap)
341 uap->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK); 345 uap->curregs[R1] &= ~(EXT_INT_ENAB | TxINT_ENAB | RxINT_MASK);
342 write_zsreg(uap, R1, uap->curregs[R1]); 346 write_zsreg(uap, R1, uap->curregs[R1]);
343 zssync(uap); 347 zssync(uap);
344 dev_err(&uap->dev->ofdev.dev, "pmz: rx irq flood !\n"); 348 pmz_error("pmz: rx irq flood !\n");
345 return tty; 349 return tty;
346} 350}
347 351
@@ -470,47 +474,47 @@ static irqreturn_t pmz_interrupt(int irq, void *dev_id)
470 474
471 uap_a = pmz_get_port_A(uap); 475 uap_a = pmz_get_port_A(uap);
472 uap_b = uap_a->mate; 476 uap_b = uap_a->mate;
473 477
474 spin_lock(&uap_a->port.lock); 478 spin_lock(&uap_a->port.lock);
475 r3 = read_zsreg(uap_a, R3); 479 r3 = read_zsreg(uap_a, R3);
476 480
477#ifdef DEBUG_HARD 481#ifdef DEBUG_HARD
478 pmz_debug("irq, r3: %x\n", r3); 482 pmz_debug("irq, r3: %x\n", r3);
479#endif 483#endif
480 /* Channel A */ 484 /* Channel A */
481 tty = NULL; 485 tty = NULL;
482 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) { 486 if (r3 & (CHAEXT | CHATxIP | CHARxIP)) {
483 write_zsreg(uap_a, R0, RES_H_IUS); 487 write_zsreg(uap_a, R0, RES_H_IUS);
484 zssync(uap_a); 488 zssync(uap_a);
485 if (r3 & CHAEXT) 489 if (r3 & CHAEXT)
486 pmz_status_handle(uap_a); 490 pmz_status_handle(uap_a);
487 if (r3 & CHARxIP) 491 if (r3 & CHARxIP)
488 tty = pmz_receive_chars(uap_a); 492 tty = pmz_receive_chars(uap_a);
489 if (r3 & CHATxIP) 493 if (r3 & CHATxIP)
490 pmz_transmit_chars(uap_a); 494 pmz_transmit_chars(uap_a);
491 rc = IRQ_HANDLED; 495 rc = IRQ_HANDLED;
492 } 496 }
493 spin_unlock(&uap_a->port.lock); 497 spin_unlock(&uap_a->port.lock);
494 if (tty != NULL) 498 if (tty != NULL)
495 tty_flip_buffer_push(tty); 499 tty_flip_buffer_push(tty);
496 500
497 if (uap_b->node == NULL) 501 if (uap_b->node == NULL)
498 goto out; 502 goto out;
499 503
500 spin_lock(&uap_b->port.lock); 504 spin_lock(&uap_b->port.lock);
501 tty = NULL; 505 tty = NULL;
502 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) { 506 if (r3 & (CHBEXT | CHBTxIP | CHBRxIP)) {
503 write_zsreg(uap_b, R0, RES_H_IUS); 507 write_zsreg(uap_b, R0, RES_H_IUS);
504 zssync(uap_b); 508 zssync(uap_b);
505 if (r3 & CHBEXT) 509 if (r3 & CHBEXT)
506 pmz_status_handle(uap_b); 510 pmz_status_handle(uap_b);
507 if (r3 & CHBRxIP) 511 if (r3 & CHBRxIP)
508 tty = pmz_receive_chars(uap_b); 512 tty = pmz_receive_chars(uap_b);
509 if (r3 & CHBTxIP) 513 if (r3 & CHBTxIP)
510 pmz_transmit_chars(uap_b); 514 pmz_transmit_chars(uap_b);
511 rc = IRQ_HANDLED; 515 rc = IRQ_HANDLED;
512 } 516 }
513 spin_unlock(&uap_b->port.lock); 517 spin_unlock(&uap_b->port.lock);
514 if (tty != NULL) 518 if (tty != NULL)
515 tty_flip_buffer_push(tty); 519 tty_flip_buffer_push(tty);
516 520
@@ -718,7 +722,7 @@ static void pmz_enable_ms(struct uart_port *port)
718 722
719 if (ZS_IS_ASLEEP(uap)) 723 if (ZS_IS_ASLEEP(uap))
720 return; 724 return;
721 /* NOTE: Not subject to 'transmitter active' rule. */ 725 /* NOTE: Not subject to 'transmitter active' rule. */
722 write_zsreg(uap, R15, uap->curregs[R15]); 726 write_zsreg(uap, R15, uap->curregs[R15]);
723 } 727 }
724} 728}
@@ -748,7 +752,7 @@ static void pmz_break_ctl(struct uart_port *port, int break_state)
748 if (new_reg != uap->curregs[R5]) { 752 if (new_reg != uap->curregs[R5]) {
749 uap->curregs[R5] = new_reg; 753 uap->curregs[R5] = new_reg;
750 754
751 /* NOTE: Not subject to 'transmitter active' rule. */ 755 /* NOTE: Not subject to 'transmitter active' rule. */
752 if (ZS_IS_ASLEEP(uap)) 756 if (ZS_IS_ASLEEP(uap))
753 return; 757 return;
754 write_zsreg(uap, R5, uap->curregs[R5]); 758 write_zsreg(uap, R5, uap->curregs[R5]);
@@ -757,6 +761,8 @@ static void pmz_break_ctl(struct uart_port *port, int break_state)
757 spin_unlock_irqrestore(&port->lock, flags); 761 spin_unlock_irqrestore(&port->lock, flags);
758} 762}
759 763
764#ifdef CONFIG_PPC_PMAC
765
760/* 766/*
761 * Turn power on or off to the SCC and associated stuff 767 * Turn power on or off to the SCC and associated stuff
762 * (port drivers, modem, IR port, etc.) 768 * (port drivers, modem, IR port, etc.)
@@ -792,6 +798,15 @@ static int pmz_set_scc_power(struct uart_pmac_port *uap, int state)
792 return delay; 798 return delay;
793} 799}
794 800
801#else
802
803static int pmz_set_scc_power(struct uart_pmac_port *uap, int state)
804{
805 return 0;
806}
807
808#endif /* !CONFIG_PPC_PMAC */
809
795/* 810/*
796 * FixZeroBug....Works around a bug in the SCC receving channel. 811 * FixZeroBug....Works around a bug in the SCC receving channel.
797 * Inspired from Darwin code, 15 Sept. 2000 -DanM 812 * Inspired from Darwin code, 15 Sept. 2000 -DanM
@@ -908,7 +923,6 @@ static int __pmz_startup(struct uart_pmac_port *uap)
908 /* Remember status for DCD/CTS changes */ 923 /* Remember status for DCD/CTS changes */
909 uap->prev_status = read_zsreg(uap, R0); 924 uap->prev_status = read_zsreg(uap, R0);
910 925
911
912 return pwr_delay; 926 return pwr_delay;
913} 927}
914 928
@@ -955,9 +969,9 @@ static int pmz_startup(struct uart_port *port)
955 } 969 }
956 970
957 pmz_get_port_A(uap)->flags |= PMACZILOG_FLAG_IS_IRQ_ON; 971 pmz_get_port_A(uap)->flags |= PMACZILOG_FLAG_IS_IRQ_ON;
958 if (request_irq(uap->port.irq, pmz_interrupt, IRQF_SHARED, "PowerMac Zilog", uap)) { 972 if (request_irq(uap->port.irq, pmz_interrupt, IRQF_SHARED,
959 dev_err(&uap->dev->ofdev.dev, 973 "SCC", uap)) {
960 "Unable to register zs interrupt handler.\n"); 974 pmz_error("Unable to register zs interrupt handler.\n");
961 pmz_set_scc_power(uap, 0); 975 pmz_set_scc_power(uap, 0);
962 mutex_unlock(&pmz_irq_mutex); 976 mutex_unlock(&pmz_irq_mutex);
963 return -ENXIO; 977 return -ENXIO;
@@ -983,7 +997,7 @@ static int pmz_startup(struct uart_port *port)
983 if (!ZS_IS_EXTCLK(uap)) 997 if (!ZS_IS_EXTCLK(uap))
984 uap->curregs[R1] |= EXT_INT_ENAB; 998 uap->curregs[R1] |= EXT_INT_ENAB;
985 write_zsreg(uap, R1, uap->curregs[R1]); 999 write_zsreg(uap, R1, uap->curregs[R1]);
986 spin_unlock_irqrestore(&port->lock, flags); 1000 spin_unlock_irqrestore(&port->lock, flags);
987 1001
988 pmz_debug("pmz: startup() done.\n"); 1002 pmz_debug("pmz: startup() done.\n");
989 1003
@@ -1003,7 +1017,7 @@ static void pmz_shutdown(struct uart_port *port)
1003 mutex_lock(&pmz_irq_mutex); 1017 mutex_lock(&pmz_irq_mutex);
1004 1018
1005 /* Release interrupt handler */ 1019 /* Release interrupt handler */
1006 free_irq(uap->port.irq, uap); 1020 free_irq(uap->port.irq, uap);
1007 1021
1008 spin_lock_irqsave(&port->lock, flags); 1022 spin_lock_irqsave(&port->lock, flags);
1009 1023
@@ -1051,7 +1065,6 @@ static void pmz_convert_to_zs(struct uart_pmac_port *uap, unsigned int cflag,
1051{ 1065{
1052 int brg; 1066 int brg;
1053 1067
1054
1055 /* Switch to external clocking for IrDA high clock rates. That 1068 /* Switch to external clocking for IrDA high clock rates. That
1056 * code could be re-used for Midi interfaces with different 1069 * code could be re-used for Midi interfaces with different
1057 * multipliers 1070 * multipliers
@@ -1198,7 +1211,7 @@ static void pmz_irda_setup(struct uart_pmac_port *uap, unsigned long *baud)
1198 while ((read_zsreg(uap, R0) & Tx_BUF_EMP) == 0 1211 while ((read_zsreg(uap, R0) & Tx_BUF_EMP) == 0
1199 || (read_zsreg(uap, R1) & ALL_SNT) == 0) { 1212 || (read_zsreg(uap, R1) & ALL_SNT) == 0) {
1200 if (--t <= 0) { 1213 if (--t <= 0) {
1201 dev_err(&uap->dev->ofdev.dev, "transmitter didn't drain\n"); 1214 pmz_error("transmitter didn't drain\n");
1202 return; 1215 return;
1203 } 1216 }
1204 udelay(10); 1217 udelay(10);
@@ -1214,7 +1227,7 @@ static void pmz_irda_setup(struct uart_pmac_port *uap, unsigned long *baud)
1214 read_zsdata(uap); 1227 read_zsdata(uap);
1215 mdelay(10); 1228 mdelay(10);
1216 if (--t <= 0) { 1229 if (--t <= 0) {
1217 dev_err(&uap->dev->ofdev.dev, "receiver didn't drain\n"); 1230 pmz_error("receiver didn't drain\n");
1218 return; 1231 return;
1219 } 1232 }
1220 } 1233 }
@@ -1223,20 +1236,19 @@ static void pmz_irda_setup(struct uart_pmac_port *uap, unsigned long *baud)
1223 uap->curregs[R5] |= DTR; 1236 uap->curregs[R5] |= DTR;
1224 write_zsreg(uap, R5, uap->curregs[R5]); 1237 write_zsreg(uap, R5, uap->curregs[R5]);
1225 zssync(uap); 1238 zssync(uap);
1226 mdelay(1); 1239 mdelay(1);
1227 1240
1228 /* Switch SCC to 19200 */ 1241 /* Switch SCC to 19200 */
1229 pmz_convert_to_zs(uap, CS8, 0, 19200); 1242 pmz_convert_to_zs(uap, CS8, 0, 19200);
1230 pmz_load_zsregs(uap, uap->curregs); 1243 pmz_load_zsregs(uap, uap->curregs);
1231 mdelay(1); 1244 mdelay(1);
1232 1245
1233 /* Write get_version command byte */ 1246 /* Write get_version command byte */
1234 write_zsdata(uap, 1); 1247 write_zsdata(uap, 1);
1235 t = 5000; 1248 t = 5000;
1236 while ((read_zsreg(uap, R0) & Rx_CH_AV) == 0) { 1249 while ((read_zsreg(uap, R0) & Rx_CH_AV) == 0) {
1237 if (--t <= 0) { 1250 if (--t <= 0) {
1238 dev_err(&uap->dev->ofdev.dev, 1251 pmz_error("irda_setup timed out on get_version byte\n");
1239 "irda_setup timed out on get_version byte\n");
1240 goto out; 1252 goto out;
1241 } 1253 }
1242 udelay(10); 1254 udelay(10);
@@ -1244,8 +1256,7 @@ static void pmz_irda_setup(struct uart_pmac_port *uap, unsigned long *baud)
1244 version = read_zsdata(uap); 1256 version = read_zsdata(uap);
1245 1257
1246 if (version < 4) { 1258 if (version < 4) {
1247 dev_info(&uap->dev->ofdev.dev, "IrDA: dongle version %d not supported\n", 1259 pmz_info("IrDA: dongle version %d not supported\n", version);
1248 version);
1249 goto out; 1260 goto out;
1250 } 1261 }
1251 1262
@@ -1254,18 +1265,16 @@ static void pmz_irda_setup(struct uart_pmac_port *uap, unsigned long *baud)
1254 t = 5000; 1265 t = 5000;
1255 while ((read_zsreg(uap, R0) & Rx_CH_AV) == 0) { 1266 while ((read_zsreg(uap, R0) & Rx_CH_AV) == 0) {
1256 if (--t <= 0) { 1267 if (--t <= 0) {
1257 dev_err(&uap->dev->ofdev.dev, 1268 pmz_error("irda_setup timed out on speed mode byte\n");
1258 "irda_setup timed out on speed mode byte\n");
1259 goto out; 1269 goto out;
1260 } 1270 }
1261 udelay(10); 1271 udelay(10);
1262 } 1272 }
1263 t = read_zsdata(uap); 1273 t = read_zsdata(uap);
1264 if (t != cmdbyte) 1274 if (t != cmdbyte)
1265 dev_err(&uap->dev->ofdev.dev, 1275 pmz_error("irda_setup speed mode byte = %x (%x)\n", t, cmdbyte);
1266 "irda_setup speed mode byte = %x (%x)\n", t, cmdbyte);
1267 1276
1268 dev_info(&uap->dev->ofdev.dev, "IrDA setup for %ld bps, dongle version: %d\n", 1277 pmz_info("IrDA setup for %ld bps, dongle version: %d\n",
1269 *baud, version); 1278 *baud, version);
1270 1279
1271 (void)read_zsdata(uap); 1280 (void)read_zsdata(uap);
@@ -1415,7 +1424,7 @@ static void pmz_poll_put_char(struct uart_port *port, unsigned char c)
1415 write_zsdata(uap, c); 1424 write_zsdata(uap, c);
1416} 1425}
1417 1426
1418#endif 1427#endif /* CONFIG_CONSOLE_POLL */
1419 1428
1420static struct uart_ops pmz_pops = { 1429static struct uart_ops pmz_pops = {
1421 .tx_empty = pmz_tx_empty, 1430 .tx_empty = pmz_tx_empty,
@@ -1440,6 +1449,8 @@ static struct uart_ops pmz_pops = {
1440#endif 1449#endif
1441}; 1450};
1442 1451
1452#ifdef CONFIG_PPC_PMAC
1453
1443/* 1454/*
1444 * Setup one port structure after probing, HW is down at this point, 1455 * Setup one port structure after probing, HW is down at this point,
1445 * Unlike sunzilog, we don't need to pre-init the spinlock as we don't 1456 * Unlike sunzilog, we don't need to pre-init the spinlock as we don't
@@ -1463,7 +1474,7 @@ static int __init pmz_init_port(struct uart_pmac_port *uap)
1463 return -ENODEV; 1474 return -ENODEV;
1464 uap->port.mapbase = r_ports.start; 1475 uap->port.mapbase = r_ports.start;
1465 uap->port.membase = ioremap(uap->port.mapbase, 0x1000); 1476 uap->port.membase = ioremap(uap->port.mapbase, 0x1000);
1466 1477
1467 uap->control_reg = uap->port.membase; 1478 uap->control_reg = uap->port.membase;
1468 uap->data_reg = uap->control_reg + 0x10; 1479 uap->data_reg = uap->control_reg + 0x10;
1469 1480
@@ -1590,7 +1601,7 @@ static void pmz_dispose_port(struct uart_pmac_port *uap)
1590} 1601}
1591 1602
1592/* 1603/*
1593 * Called upon match with an escc node in the devive-tree. 1604 * Called upon match with an escc node in the device-tree.
1594 */ 1605 */
1595static int pmz_attach(struct macio_dev *mdev, const struct of_device_id *match) 1606static int pmz_attach(struct macio_dev *mdev, const struct of_device_id *match)
1596{ 1607{
@@ -1812,7 +1823,7 @@ static int __init pmz_probe(void)
1812 pmz_ports[count].node = node_a; 1823 pmz_ports[count].node = node_a;
1813 pmz_ports[count+1].node = node_b; 1824 pmz_ports[count+1].node = node_b;
1814 pmz_ports[count].port.line = count; 1825 pmz_ports[count].port.line = count;
1815 pmz_ports[count+1].port.line = count+1; 1826 pmz_ports[count+1].port.line = count+1;
1816 1827
1817 /* 1828 /*
1818 * Setup the ports for real 1829 * Setup the ports for real
@@ -1836,6 +1847,88 @@ next:
1836 return 0; 1847 return 0;
1837} 1848}
1838 1849
1850#else
1851
1852extern struct platform_device scc_a_pdev, scc_b_pdev;
1853
1854static int __init pmz_init_port(struct uart_pmac_port *uap)
1855{
1856 struct resource *r_ports;
1857 int irq;
1858
1859 r_ports = platform_get_resource(uap->node, IORESOURCE_MEM, 0);
1860 irq = platform_get_irq(uap->node, 0);
1861 if (!r_ports || !irq)
1862 return -ENODEV;
1863
1864 uap->port.mapbase = r_ports->start;
1865 uap->port.membase = (unsigned char __iomem *) r_ports->start;
1866 uap->port.iotype = UPIO_MEM;
1867 uap->port.irq = irq;
1868 uap->port.uartclk = ZS_CLOCK;
1869 uap->port.fifosize = 1;
1870 uap->port.ops = &pmz_pops;
1871 uap->port.type = PORT_PMAC_ZILOG;
1872 uap->port.flags = 0;
1873
1874 uap->control_reg = uap->port.membase;
1875 uap->data_reg = uap->control_reg + 4;
1876 uap->port_type = 0;
1877
1878 pmz_convert_to_zs(uap, CS8, 0, 9600);
1879
1880 return 0;
1881}
1882
1883static int __init pmz_probe(void)
1884{
1885 int err;
1886
1887 pmz_ports_count = 0;
1888
1889 pmz_ports[0].mate = &pmz_ports[1];
1890 pmz_ports[0].port.line = 0;
1891 pmz_ports[0].flags = PMACZILOG_FLAG_IS_CHANNEL_A;
1892 pmz_ports[0].node = &scc_a_pdev;
1893 err = pmz_init_port(&pmz_ports[0]);
1894 if (err)
1895 return err;
1896 pmz_ports_count++;
1897
1898 pmz_ports[1].mate = &pmz_ports[0];
1899 pmz_ports[1].port.line = 1;
1900 pmz_ports[1].flags = 0;
1901 pmz_ports[1].node = &scc_b_pdev;
1902 err = pmz_init_port(&pmz_ports[1]);
1903 if (err)
1904 return err;
1905 pmz_ports_count++;
1906
1907 return 0;
1908}
1909
1910static void pmz_dispose_port(struct uart_pmac_port *uap)
1911{
1912 memset(uap, 0, sizeof(struct uart_pmac_port));
1913}
1914
1915static int __init pmz_attach(struct platform_device *pdev)
1916{
1917 int i;
1918
1919 for (i = 0; i < pmz_ports_count; i++)
1920 if (pmz_ports[i].node == pdev)
1921 return 0;
1922 return -ENODEV;
1923}
1924
1925static int __exit pmz_detach(struct platform_device *pdev)
1926{
1927 return 0;
1928}
1929
1930#endif /* !CONFIG_PPC_PMAC */
1931
1839#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE 1932#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
1840 1933
1841static void pmz_console_write(struct console *con, const char *s, unsigned int count); 1934static void pmz_console_write(struct console *con, const char *s, unsigned int count);
@@ -1896,28 +1989,41 @@ err_out:
1896 return rc; 1989 return rc;
1897} 1990}
1898 1991
1992#ifdef CONFIG_PPC_PMAC
1993
1899static struct of_device_id pmz_match[] = 1994static struct of_device_id pmz_match[] =
1900{ 1995{
1901 { 1996 {
1902 .name = "ch-a", 1997 .name = "ch-a",
1903 }, 1998 },
1904 { 1999 {
1905 .name = "ch-b", 2000 .name = "ch-b",
1906 }, 2001 },
1907 {}, 2002 {},
1908}; 2003};
1909MODULE_DEVICE_TABLE (of, pmz_match); 2004MODULE_DEVICE_TABLE (of, pmz_match);
1910 2005
1911static struct macio_driver pmz_driver = 2006static struct macio_driver pmz_driver = {
1912{
1913 .name = "pmac_zilog", 2007 .name = "pmac_zilog",
1914 .match_table = pmz_match, 2008 .match_table = pmz_match,
1915 .probe = pmz_attach, 2009 .probe = pmz_attach,
1916 .remove = pmz_detach, 2010 .remove = pmz_detach,
1917 .suspend = pmz_suspend, 2011 .suspend = pmz_suspend,
1918 .resume = pmz_resume, 2012 .resume = pmz_resume,
1919}; 2013};
1920 2014
2015#else
2016
2017static struct platform_driver pmz_driver = {
2018 .remove = __exit_p(pmz_detach),
2019 .driver = {
2020 .name = "scc",
2021 .owner = THIS_MODULE,
2022 },
2023};
2024
2025#endif /* !CONFIG_PPC_PMAC */
2026
1921static int __init init_pmz(void) 2027static int __init init_pmz(void)
1922{ 2028{
1923 int rc, i; 2029 int rc, i;
@@ -1952,19 +2058,27 @@ static int __init init_pmz(void)
1952 pmz_dispose_port(&pmz_ports[i]); 2058 pmz_dispose_port(&pmz_ports[i]);
1953 return rc; 2059 return rc;
1954 } 2060 }
1955 2061
1956 /* 2062 /*
1957 * Then we register the macio driver itself 2063 * Then we register the macio driver itself
1958 */ 2064 */
2065#ifdef CONFIG_PPC_PMAC
1959 return macio_register_driver(&pmz_driver); 2066 return macio_register_driver(&pmz_driver);
2067#else
2068 return platform_driver_probe(&pmz_driver, pmz_attach);
2069#endif
1960} 2070}
1961 2071
1962static void __exit exit_pmz(void) 2072static void __exit exit_pmz(void)
1963{ 2073{
1964 int i; 2074 int i;
1965 2075
2076#ifdef CONFIG_PPC_PMAC
1966 /* Get rid of macio-driver (detach from macio) */ 2077 /* Get rid of macio-driver (detach from macio) */
1967 macio_unregister_driver(&pmz_driver); 2078 macio_unregister_driver(&pmz_driver);
2079#else
2080 platform_driver_unregister(&pmz_driver);
2081#endif
1968 2082
1969 for (i = 0; i < pmz_ports_count; i++) { 2083 for (i = 0; i < pmz_ports_count; i++) {
1970 struct uart_pmac_port *uport = &pmz_ports[i]; 2084 struct uart_pmac_port *uport = &pmz_ports[i];
@@ -2031,10 +2145,10 @@ static int __init pmz_console_setup(struct console *co, char *options)
2031 /* 2145 /*
2032 * XServe's default to 57600 bps 2146 * XServe's default to 57600 bps
2033 */ 2147 */
2034 if (machine_is_compatible("RackMac1,1") 2148 if (of_machine_is_compatible("RackMac1,1")
2035 || machine_is_compatible("RackMac1,2") 2149 || of_machine_is_compatible("RackMac1,2")
2036 || machine_is_compatible("MacRISC4")) 2150 || of_machine_is_compatible("MacRISC4"))
2037 baud = 57600; 2151 baud = 57600;
2038 2152
2039 /* 2153 /*
2040 * Check whether an invalid uart number has been specified, and 2154 * Check whether an invalid uart number has been specified, and
diff --git a/drivers/serial/pmac_zilog.h b/drivers/serial/pmac_zilog.h
index f6e77f12acd5..cbc34fbb1b20 100644
--- a/drivers/serial/pmac_zilog.h
+++ b/drivers/serial/pmac_zilog.h
@@ -1,7 +1,15 @@
1#ifndef __PMAC_ZILOG_H__ 1#ifndef __PMAC_ZILOG_H__
2#define __PMAC_ZILOG_H__ 2#define __PMAC_ZILOG_H__
3 3
4#define pmz_debug(fmt,arg...) dev_dbg(&uap->dev->ofdev.dev, fmt, ## arg) 4#ifdef CONFIG_PPC_PMAC
5#define pmz_debug(fmt, arg...) dev_dbg(&uap->dev->ofdev.dev, fmt, ## arg)
6#define pmz_error(fmt, arg...) dev_err(&uap->dev->ofdev.dev, fmt, ## arg)
7#define pmz_info(fmt, arg...) dev_info(&uap->dev->ofdev.dev, fmt, ## arg)
8#else
9#define pmz_debug(fmt, arg...) dev_dbg(&uap->node->dev, fmt, ## arg)
10#define pmz_error(fmt, arg...) dev_err(&uap->node->dev, fmt, ## arg)
11#define pmz_info(fmt, arg...) dev_info(&uap->node->dev, fmt, ## arg)
12#endif
5 13
6/* 14/*
7 * At most 2 ESCCs with 2 ports each 15 * At most 2 ESCCs with 2 ports each
@@ -17,6 +25,7 @@ struct uart_pmac_port {
17 struct uart_port port; 25 struct uart_port port;
18 struct uart_pmac_port *mate; 26 struct uart_pmac_port *mate;
19 27
28#ifdef CONFIG_PPC_PMAC
20 /* macio_dev for the escc holding this port (maybe be null on 29 /* macio_dev for the escc holding this port (maybe be null on
21 * early inited port) 30 * early inited port)
22 */ 31 */
@@ -25,6 +34,9 @@ struct uart_pmac_port {
25 * of "escc" node (ie. ch-a or ch-b) 34 * of "escc" node (ie. ch-a or ch-b)
26 */ 35 */
27 struct device_node *node; 36 struct device_node *node;
37#else
38 struct platform_device *node;
39#endif
28 40
29 /* Port type as obtained from device tree (IRDA, modem, ...) */ 41 /* Port type as obtained from device tree (IRDA, modem, ...) */
30 int port_type; 42 int port_type;
@@ -55,10 +67,12 @@ struct uart_pmac_port {
55 volatile u8 __iomem *control_reg; 67 volatile u8 __iomem *control_reg;
56 volatile u8 __iomem *data_reg; 68 volatile u8 __iomem *data_reg;
57 69
70#ifdef CONFIG_PPC_PMAC
58 unsigned int tx_dma_irq; 71 unsigned int tx_dma_irq;
59 unsigned int rx_dma_irq; 72 unsigned int rx_dma_irq;
60 volatile struct dbdma_regs __iomem *tx_dma_regs; 73 volatile struct dbdma_regs __iomem *tx_dma_regs;
61 volatile struct dbdma_regs __iomem *rx_dma_regs; 74 volatile struct dbdma_regs __iomem *rx_dma_regs;
75#endif
62 76
63 struct ktermios termios_cache; 77 struct ktermios termios_cache;
64}; 78};
@@ -113,7 +127,7 @@ static inline void zssync(struct uart_pmac_port *port)
113#define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2)) 127#define BRG_TO_BPS(brg, freq) ((freq) / 2 / ((brg) + 2))
114#define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2) 128#define BPS_TO_BRG(bps, freq) ((((freq) + (bps)) / (2 * (bps))) - 2)
115 129
116#define ZS_CLOCK 3686400 /* Z8530 RTxC input clock rate */ 130#define ZS_CLOCK 3686400 /* Z8530 RTxC input clock rate */
117 131
118/* The Zilog register set */ 132/* The Zilog register set */
119 133
@@ -171,7 +185,7 @@ static inline void zssync(struct uart_pmac_port *port)
171 185
172/* Write Register 3 */ 186/* Write Register 3 */
173 187
174#define RxENABLE 0x1 /* Rx Enable */ 188#define RxENABLE 0x1 /* Rx Enable */
175#define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */ 189#define SYNC_L_INH 0x2 /* Sync Character Load Inhibit */
176#define ADD_SM 0x4 /* Address Search Mode (SDLC) */ 190#define ADD_SM 0x4 /* Address Search Mode (SDLC) */
177#define RxCRC_ENAB 0x8 /* Rx CRC Enable */ 191#define RxCRC_ENAB 0x8 /* Rx CRC Enable */
@@ -185,7 +199,7 @@ static inline void zssync(struct uart_pmac_port *port)
185 199
186/* Write Register 4 */ 200/* Write Register 4 */
187 201
188#define PAR_ENAB 0x1 /* Parity Enable */ 202#define PAR_ENAB 0x1 /* Parity Enable */
189#define PAR_EVEN 0x2 /* Parity Even/Odd* */ 203#define PAR_EVEN 0x2 /* Parity Even/Odd* */
190 204
191#define SYNC_ENAB 0 /* Sync Modes Enable */ 205#define SYNC_ENAB 0 /* Sync Modes Enable */
@@ -210,7 +224,7 @@ static inline void zssync(struct uart_pmac_port *port)
210#define TxCRC_ENAB 0x1 /* Tx CRC Enable */ 224#define TxCRC_ENAB 0x1 /* Tx CRC Enable */
211#define RTS 0x2 /* RTS */ 225#define RTS 0x2 /* RTS */
212#define SDLC_CRC 0x4 /* SDLC/CRC-16 */ 226#define SDLC_CRC 0x4 /* SDLC/CRC-16 */
213#define TxENABLE 0x8 /* Tx Enable */ 227#define TxENABLE 0x8 /* Tx Enable */
214#define SND_BRK 0x10 /* Send Break */ 228#define SND_BRK 0x10 /* Send Break */
215#define Tx5 0x0 /* Tx 5 bits (or less)/character */ 229#define Tx5 0x0 /* Tx 5 bits (or less)/character */
216#define Tx7 0x20 /* Tx 7 bits/character */ 230#define Tx7 0x20 /* Tx 7 bits/character */
@@ -372,11 +386,11 @@ static inline void zssync(struct uart_pmac_port *port)
372#define ZS_TX_ACTIVE(UP) ((UP)->flags & PMACZILOG_FLAG_TX_ACTIVE) 386#define ZS_TX_ACTIVE(UP) ((UP)->flags & PMACZILOG_FLAG_TX_ACTIVE)
373#define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & PMACZILOG_FLAG_MODEM_STATUS) 387#define ZS_WANTS_MODEM_STATUS(UP) ((UP)->flags & PMACZILOG_FLAG_MODEM_STATUS)
374#define ZS_IS_IRDA(UP) ((UP)->flags & PMACZILOG_FLAG_IS_IRDA) 388#define ZS_IS_IRDA(UP) ((UP)->flags & PMACZILOG_FLAG_IS_IRDA)
375#define ZS_IS_INTMODEM(UP) ((UP)->flags & PMACZILOG_FLAG_IS_INTMODEM) 389#define ZS_IS_INTMODEM(UP) ((UP)->flags & PMACZILOG_FLAG_IS_INTMODEM)
376#define ZS_HAS_DMA(UP) ((UP)->flags & PMACZILOG_FLAG_HAS_DMA) 390#define ZS_HAS_DMA(UP) ((UP)->flags & PMACZILOG_FLAG_HAS_DMA)
377#define ZS_IS_ASLEEP(UP) ((UP)->flags & PMACZILOG_FLAG_IS_ASLEEP) 391#define ZS_IS_ASLEEP(UP) ((UP)->flags & PMACZILOG_FLAG_IS_ASLEEP)
378#define ZS_IS_OPEN(UP) ((UP)->flags & PMACZILOG_FLAG_IS_OPEN) 392#define ZS_IS_OPEN(UP) ((UP)->flags & PMACZILOG_FLAG_IS_OPEN)
379#define ZS_IS_IRQ_ON(UP) ((UP)->flags & PMACZILOG_FLAG_IS_IRQ_ON) 393#define ZS_IS_IRQ_ON(UP) ((UP)->flags & PMACZILOG_FLAG_IS_IRQ_ON)
380#define ZS_IS_EXTCLK(UP) ((UP)->flags & PMACZILOG_FLAG_IS_EXTCLK) 394#define ZS_IS_EXTCLK(UP) ((UP)->flags & PMACZILOG_FLAG_IS_EXTCLK)
381 395
382#endif /* __PMAC_ZILOG_H__ */ 396#endif /* __PMAC_ZILOG_H__ */
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index 95421fa3b304..e91db4b38012 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -696,11 +696,11 @@ static int serial_config(struct pcmcia_device * link)
696 info->multi = info->quirk->multi; 696 info->multi = info->quirk->multi;
697 697
698 if (info->multi > 1) 698 if (info->multi > 1)
699 multi_config(link); 699 i = multi_config(link);
700 else 700 else
701 simple_config(link); 701 i = simple_config(link);
702 702
703 if (info->ndev == 0) 703 if (i || info->ndev == 0)
704 goto failed; 704 goto failed;
705 705
706 /* 706 /*
@@ -715,6 +715,7 @@ static int serial_config(struct pcmcia_device * link)
715 return 0; 715 return 0;
716 716
717failed: 717failed:
718 dev_warn(&link->dev, "serial_cs: failed to initialize\n");
718 serial_remove(link); 719 serial_remove(link);
719 return -ENODEV; 720 return -ENODEV;
720} 721}
diff --git a/drivers/serial/sh-sci.h b/drivers/serial/sh-sci.h
index 0efcded59ae6..f7d2589926d2 100644
--- a/drivers/serial/sh-sci.h
+++ b/drivers/serial/sh-sci.h
@@ -518,34 +518,6 @@ static inline int sci_rxd_in(struct uart_port *port)
518{ 518{
519 if (port->mapbase == 0xfffffe80) 519 if (port->mapbase == 0xfffffe80)
520 return __raw_readb(SCPDR)&0x01 ? 1 : 0; /* SCI */ 520 return __raw_readb(SCPDR)&0x01 ? 1 : 0; /* SCI */
521 if (port->mapbase == 0xa4000150)
522 return __raw_readb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
523 if (port->mapbase == 0xa4000140)
524 return __raw_readb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
525 return 1;
526}
527#elif defined(CONFIG_CPU_SUBTYPE_SH7705)
528static inline int sci_rxd_in(struct uart_port *port)
529{
530 if (port->mapbase == SCIF0)
531 return __raw_readb(SCPDR)&0x04 ? 1 : 0; /* IRDA */
532 if (port->mapbase == SCIF2)
533 return __raw_readb(SCPDR)&0x10 ? 1 : 0; /* SCIF */
534 return 1;
535}
536#elif defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
537static inline int sci_rxd_in(struct uart_port *port)
538{
539 return sci_in(port,SCxSR)&0x0010 ? 1 : 0;
540}
541#elif defined(CONFIG_CPU_SUBTYPE_SH7720) || \
542 defined(CONFIG_CPU_SUBTYPE_SH7721)
543static inline int sci_rxd_in(struct uart_port *port)
544{
545 if (port->mapbase == 0xa4430000)
546 return sci_in(port, SCxSR) & 0x0003 ? 1 : 0;
547 else if (port->mapbase == 0xa4438000)
548 return sci_in(port, SCxSR) & 0x0003 ? 1 : 0;
549 return 1; 521 return 1;
550} 522}
551#elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \ 523#elif defined(CONFIG_CPU_SUBTYPE_SH7750) || \
@@ -558,207 +530,17 @@ static inline int sci_rxd_in(struct uart_port *port)
558{ 530{
559 if (port->mapbase == 0xffe00000) 531 if (port->mapbase == 0xffe00000)
560 return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */ 532 return __raw_readb(SCSPTR1)&0x01 ? 1 : 0; /* SCI */
561 if (port->mapbase == 0xffe80000)
562 return __raw_readw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
563 return 1;
564}
565#elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
566static inline int sci_rxd_in(struct uart_port *port)
567{
568 if (port->mapbase == 0xffe80000)
569 return __raw_readw(SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */
570 return 1; 533 return 1;
571} 534}
572#elif defined(CONFIG_CPU_SUBTYPE_SH7757)
573static inline int sci_rxd_in(struct uart_port *port)
574{
575 if (port->mapbase == 0xfe4b0000)
576 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0;
577 if (port->mapbase == 0xfe4c0000)
578 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0;
579 if (port->mapbase == 0xfe4d0000)
580 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0;
581}
582#elif defined(CONFIG_CPU_SUBTYPE_SH7760)
583static inline int sci_rxd_in(struct uart_port *port)
584{
585 if (port->mapbase == 0xfe600000)
586 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
587 if (port->mapbase == 0xfe610000)
588 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
589 if (port->mapbase == 0xfe620000)
590 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
591 return 1;
592}
593#elif defined(CONFIG_CPU_SUBTYPE_SH7343)
594static inline int sci_rxd_in(struct uart_port *port)
595{
596 if (port->mapbase == 0xffe00000)
597 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
598 if (port->mapbase == 0xffe10000)
599 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
600 if (port->mapbase == 0xffe20000)
601 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
602 if (port->mapbase == 0xffe30000)
603 return __raw_readw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
604 return 1;
605}
606#elif defined(CONFIG_CPU_SUBTYPE_SH7366)
607static inline int sci_rxd_in(struct uart_port *port)
608{
609 if (port->mapbase == 0xffe00000)
610 return __raw_readb(SCPDR0) & 0x0001 ? 1 : 0; /* SCIF0 */
611 return 1;
612}
613#elif defined(CONFIG_CPU_SUBTYPE_SH7722)
614static inline int sci_rxd_in(struct uart_port *port)
615{
616 if (port->mapbase == 0xffe00000)
617 return __raw_readb(PSDR) & 0x02 ? 1 : 0; /* SCIF0 */
618 if (port->mapbase == 0xffe10000)
619 return __raw_readb(PADR) & 0x40 ? 1 : 0; /* SCIF1 */
620 if (port->mapbase == 0xffe20000)
621 return __raw_readb(PWDR) & 0x04 ? 1 : 0; /* SCIF2 */
622
623 return 1;
624}
625#elif defined(CONFIG_CPU_SUBTYPE_SH7723)
626static inline int sci_rxd_in(struct uart_port *port)
627{
628 if (port->mapbase == 0xffe00000)
629 return __raw_readb(SCSPTR0) & 0x0008 ? 1 : 0; /* SCIF0 */
630 if (port->mapbase == 0xffe10000)
631 return __raw_readb(SCSPTR1) & 0x0020 ? 1 : 0; /* SCIF1 */
632 if (port->mapbase == 0xffe20000)
633 return __raw_readb(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF2 */
634 if (port->mapbase == 0xa4e30000)
635 return __raw_readb(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF3 */
636 if (port->mapbase == 0xa4e40000)
637 return __raw_readb(SCSPTR4) & 0x0001 ? 1 : 0; /* SCIF4 */
638 if (port->mapbase == 0xa4e50000)
639 return __raw_readb(SCSPTR5) & 0x0008 ? 1 : 0; /* SCIF5 */
640 return 1;
641}
642#elif defined(CONFIG_CPU_SUBTYPE_SH7724)
643# define SCFSR 0x0010
644# define SCASSR 0x0014
645static inline int sci_rxd_in(struct uart_port *port)
646{
647 if (port->type == PORT_SCIF)
648 return __raw_readw((port->mapbase + SCFSR)) & SCIF_BRK ? 1 : 0;
649 if (port->type == PORT_SCIFA)
650 return __raw_readw((port->mapbase + SCASSR)) & SCIF_BRK ? 1 : 0;
651 return 1;
652}
653#elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
654static inline int sci_rxd_in(struct uart_port *port)
655{
656 return sci_in(port, SCSPTR)&0x0001 ? 1 : 0; /* SCIF */
657}
658#elif defined(__H8300H__) || defined(__H8300S__) 535#elif defined(__H8300H__) || defined(__H8300S__)
659static inline int sci_rxd_in(struct uart_port *port) 536static inline int sci_rxd_in(struct uart_port *port)
660{ 537{
661 int ch = (port->mapbase - SMR0) >> 3; 538 int ch = (port->mapbase - SMR0) >> 3;
662 return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0; 539 return (H8300_SCI_DR(ch) & h8300_sci_pins[ch].rx) ? 1 : 0;
663} 540}
664#elif defined(CONFIG_CPU_SUBTYPE_SH7763) 541#else /* default case for non-SCI processors */
665static inline int sci_rxd_in(struct uart_port *port)
666{
667 if (port->mapbase == 0xffe00000)
668 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
669 if (port->mapbase == 0xffe08000)
670 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
671 if (port->mapbase == 0xffe10000)
672 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF/IRDA */
673
674 return 1;
675}
676#elif defined(CONFIG_CPU_SUBTYPE_SH7770)
677static inline int sci_rxd_in(struct uart_port *port)
678{
679 if (port->mapbase == 0xff923000)
680 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
681 if (port->mapbase == 0xff924000)
682 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
683 if (port->mapbase == 0xff925000)
684 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
685 return 1;
686}
687#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
688static inline int sci_rxd_in(struct uart_port *port)
689{
690 if (port->mapbase == 0xffe00000)
691 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
692 if (port->mapbase == 0xffe10000)
693 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
694 return 1;
695}
696#elif defined(CONFIG_CPU_SUBTYPE_SH7785) || \
697 defined(CONFIG_CPU_SUBTYPE_SH7786)
698static inline int sci_rxd_in(struct uart_port *port)
699{
700 if (port->mapbase == 0xffea0000)
701 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
702 if (port->mapbase == 0xffeb0000)
703 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
704 if (port->mapbase == 0xffec0000)
705 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
706 if (port->mapbase == 0xffed0000)
707 return __raw_readw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
708 if (port->mapbase == 0xffee0000)
709 return __raw_readw(SCSPTR4) & 0x0001 ? 1 : 0; /* SCIF */
710 if (port->mapbase == 0xffef0000)
711 return __raw_readw(SCSPTR5) & 0x0001 ? 1 : 0; /* SCIF */
712 return 1;
713}
714#elif defined(CONFIG_CPU_SUBTYPE_SH7201) || \
715 defined(CONFIG_CPU_SUBTYPE_SH7203) || \
716 defined(CONFIG_CPU_SUBTYPE_SH7206) || \
717 defined(CONFIG_CPU_SUBTYPE_SH7263)
718static inline int sci_rxd_in(struct uart_port *port)
719{
720 if (port->mapbase == 0xfffe8000)
721 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
722 if (port->mapbase == 0xfffe8800)
723 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
724 if (port->mapbase == 0xfffe9000)
725 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
726 if (port->mapbase == 0xfffe9800)
727 return __raw_readw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
728#if defined(CONFIG_CPU_SUBTYPE_SH7201)
729 if (port->mapbase == 0xfffeA000)
730 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
731 if (port->mapbase == 0xfffeA800)
732 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
733 if (port->mapbase == 0xfffeB000)
734 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
735 if (port->mapbase == 0xfffeB800)
736 return __raw_readw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
737#endif
738 return 1;
739}
740#elif defined(CONFIG_CPU_SUBTYPE_SH7619)
741static inline int sci_rxd_in(struct uart_port *port)
742{
743 if (port->mapbase == 0xf8400000)
744 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
745 if (port->mapbase == 0xf8410000)
746 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
747 if (port->mapbase == 0xf8420000)
748 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
749 return 1;
750}
751#elif defined(CONFIG_CPU_SUBTYPE_SHX3)
752static inline int sci_rxd_in(struct uart_port *port) 542static inline int sci_rxd_in(struct uart_port *port)
753{ 543{
754 if (port->mapbase == 0xffc30000)
755 return __raw_readw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
756 if (port->mapbase == 0xffc40000)
757 return __raw_readw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
758 if (port->mapbase == 0xffc50000)
759 return __raw_readw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
760 if (port->mapbase == 0xffc60000)
761 return __raw_readw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
762 return 1; 544 return 1;
763} 545}
764#endif 546#endif
diff --git a/drivers/sh/intc.c b/drivers/sh/intc.c
index d5d7f23c19a5..3a5a17db9474 100644
--- a/drivers/sh/intc.c
+++ b/drivers/sh/intc.c
@@ -259,6 +259,43 @@ static void intc_disable(unsigned int irq)
259 } 259 }
260} 260}
261 261
262static void (*intc_enable_noprio_fns[])(unsigned long addr,
263 unsigned long handle,
264 void (*fn)(unsigned long,
265 unsigned long,
266 unsigned long),
267 unsigned int irq) = {
268 [MODE_ENABLE_REG] = intc_mode_field,
269 [MODE_MASK_REG] = intc_mode_zero,
270 [MODE_DUAL_REG] = intc_mode_field,
271 [MODE_PRIO_REG] = intc_mode_field,
272 [MODE_PCLR_REG] = intc_mode_field,
273};
274
275static void intc_enable_disable(struct intc_desc_int *d,
276 unsigned long handle, int do_enable)
277{
278 unsigned long addr;
279 unsigned int cpu;
280 void (*fn)(unsigned long, unsigned long,
281 void (*)(unsigned long, unsigned long, unsigned long),
282 unsigned int);
283
284 if (do_enable) {
285 for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) {
286 addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu);
287 fn = intc_enable_noprio_fns[_INTC_MODE(handle)];
288 fn(addr, handle, intc_reg_fns[_INTC_FN(handle)], 0);
289 }
290 } else {
291 for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {
292 addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu);
293 fn = intc_disable_fns[_INTC_MODE(handle)];
294 fn(addr, handle, intc_reg_fns[_INTC_FN(handle)], 0);
295 }
296 }
297}
298
262static int intc_set_wake(unsigned int irq, unsigned int on) 299static int intc_set_wake(unsigned int irq, unsigned int on)
263{ 300{
264 return 0; /* allow wakeup, but setup hardware in intc_suspend() */ 301 return 0; /* allow wakeup, but setup hardware in intc_suspend() */
@@ -400,11 +437,11 @@ static unsigned int __init intc_get_reg(struct intc_desc_int *d,
400static intc_enum __init intc_grp_id(struct intc_desc *desc, 437static intc_enum __init intc_grp_id(struct intc_desc *desc,
401 intc_enum enum_id) 438 intc_enum enum_id)
402{ 439{
403 struct intc_group *g = desc->groups; 440 struct intc_group *g = desc->hw.groups;
404 unsigned int i, j; 441 unsigned int i, j;
405 442
406 for (i = 0; g && enum_id && i < desc->nr_groups; i++) { 443 for (i = 0; g && enum_id && i < desc->hw.nr_groups; i++) {
407 g = desc->groups + i; 444 g = desc->hw.groups + i;
408 445
409 for (j = 0; g->enum_ids[j]; j++) { 446 for (j = 0; g->enum_ids[j]; j++) {
410 if (g->enum_ids[j] != enum_id) 447 if (g->enum_ids[j] != enum_id)
@@ -417,19 +454,21 @@ static intc_enum __init intc_grp_id(struct intc_desc *desc,
417 return 0; 454 return 0;
418} 455}
419 456
420static unsigned int __init intc_mask_data(struct intc_desc *desc, 457static unsigned int __init _intc_mask_data(struct intc_desc *desc,
421 struct intc_desc_int *d, 458 struct intc_desc_int *d,
422 intc_enum enum_id, int do_grps) 459 intc_enum enum_id,
460 unsigned int *reg_idx,
461 unsigned int *fld_idx)
423{ 462{
424 struct intc_mask_reg *mr = desc->mask_regs; 463 struct intc_mask_reg *mr = desc->hw.mask_regs;
425 unsigned int i, j, fn, mode; 464 unsigned int fn, mode;
426 unsigned long reg_e, reg_d; 465 unsigned long reg_e, reg_d;
427 466
428 for (i = 0; mr && enum_id && i < desc->nr_mask_regs; i++) { 467 while (mr && enum_id && *reg_idx < desc->hw.nr_mask_regs) {
429 mr = desc->mask_regs + i; 468 mr = desc->hw.mask_regs + *reg_idx;
430 469
431 for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) { 470 for (; *fld_idx < ARRAY_SIZE(mr->enum_ids); (*fld_idx)++) {
432 if (mr->enum_ids[j] != enum_id) 471 if (mr->enum_ids[*fld_idx] != enum_id)
433 continue; 472 continue;
434 473
435 if (mr->set_reg && mr->clr_reg) { 474 if (mr->set_reg && mr->clr_reg) {
@@ -455,29 +494,49 @@ static unsigned int __init intc_mask_data(struct intc_desc *desc,
455 intc_get_reg(d, reg_e), 494 intc_get_reg(d, reg_e),
456 intc_get_reg(d, reg_d), 495 intc_get_reg(d, reg_d),
457 1, 496 1,
458 (mr->reg_width - 1) - j); 497 (mr->reg_width - 1) - *fld_idx);
459 } 498 }
499
500 *fld_idx = 0;
501 (*reg_idx)++;
460 } 502 }
461 503
504 return 0;
505}
506
507static unsigned int __init intc_mask_data(struct intc_desc *desc,
508 struct intc_desc_int *d,
509 intc_enum enum_id, int do_grps)
510{
511 unsigned int i = 0;
512 unsigned int j = 0;
513 unsigned int ret;
514
515 ret = _intc_mask_data(desc, d, enum_id, &i, &j);
516 if (ret)
517 return ret;
518
462 if (do_grps) 519 if (do_grps)
463 return intc_mask_data(desc, d, intc_grp_id(desc, enum_id), 0); 520 return intc_mask_data(desc, d, intc_grp_id(desc, enum_id), 0);
464 521
465 return 0; 522 return 0;
466} 523}
467 524
468static unsigned int __init intc_prio_data(struct intc_desc *desc, 525static unsigned int __init _intc_prio_data(struct intc_desc *desc,
469 struct intc_desc_int *d, 526 struct intc_desc_int *d,
470 intc_enum enum_id, int do_grps) 527 intc_enum enum_id,
528 unsigned int *reg_idx,
529 unsigned int *fld_idx)
471{ 530{
472 struct intc_prio_reg *pr = desc->prio_regs; 531 struct intc_prio_reg *pr = desc->hw.prio_regs;
473 unsigned int i, j, fn, mode, bit; 532 unsigned int fn, n, mode, bit;
474 unsigned long reg_e, reg_d; 533 unsigned long reg_e, reg_d;
475 534
476 for (i = 0; pr && enum_id && i < desc->nr_prio_regs; i++) { 535 while (pr && enum_id && *reg_idx < desc->hw.nr_prio_regs) {
477 pr = desc->prio_regs + i; 536 pr = desc->hw.prio_regs + *reg_idx;
478 537
479 for (j = 0; j < ARRAY_SIZE(pr->enum_ids); j++) { 538 for (; *fld_idx < ARRAY_SIZE(pr->enum_ids); (*fld_idx)++) {
480 if (pr->enum_ids[j] != enum_id) 539 if (pr->enum_ids[*fld_idx] != enum_id)
481 continue; 540 continue;
482 541
483 if (pr->set_reg && pr->clr_reg) { 542 if (pr->set_reg && pr->clr_reg) {
@@ -495,34 +554,79 @@ static unsigned int __init intc_prio_data(struct intc_desc *desc,
495 } 554 }
496 555
497 fn += (pr->reg_width >> 3) - 1; 556 fn += (pr->reg_width >> 3) - 1;
557 n = *fld_idx + 1;
498 558
499 BUG_ON((j + 1) * pr->field_width > pr->reg_width); 559 BUG_ON(n * pr->field_width > pr->reg_width);
500 560
501 bit = pr->reg_width - ((j + 1) * pr->field_width); 561 bit = pr->reg_width - (n * pr->field_width);
502 562
503 return _INTC_MK(fn, mode, 563 return _INTC_MK(fn, mode,
504 intc_get_reg(d, reg_e), 564 intc_get_reg(d, reg_e),
505 intc_get_reg(d, reg_d), 565 intc_get_reg(d, reg_d),
506 pr->field_width, bit); 566 pr->field_width, bit);
507 } 567 }
568
569 *fld_idx = 0;
570 (*reg_idx)++;
508 } 571 }
509 572
573 return 0;
574}
575
576static unsigned int __init intc_prio_data(struct intc_desc *desc,
577 struct intc_desc_int *d,
578 intc_enum enum_id, int do_grps)
579{
580 unsigned int i = 0;
581 unsigned int j = 0;
582 unsigned int ret;
583
584 ret = _intc_prio_data(desc, d, enum_id, &i, &j);
585 if (ret)
586 return ret;
587
510 if (do_grps) 588 if (do_grps)
511 return intc_prio_data(desc, d, intc_grp_id(desc, enum_id), 0); 589 return intc_prio_data(desc, d, intc_grp_id(desc, enum_id), 0);
512 590
513 return 0; 591 return 0;
514} 592}
515 593
594static void __init intc_enable_disable_enum(struct intc_desc *desc,
595 struct intc_desc_int *d,
596 intc_enum enum_id, int enable)
597{
598 unsigned int i, j, data;
599
600 /* go through and enable/disable all mask bits */
601 i = j = 0;
602 do {
603 data = _intc_mask_data(desc, d, enum_id, &i, &j);
604 if (data)
605 intc_enable_disable(d, data, enable);
606 j++;
607 } while (data);
608
609 /* go through and enable/disable all priority fields */
610 i = j = 0;
611 do {
612 data = _intc_prio_data(desc, d, enum_id, &i, &j);
613 if (data)
614 intc_enable_disable(d, data, enable);
615
616 j++;
617 } while (data);
618}
619
516static unsigned int __init intc_ack_data(struct intc_desc *desc, 620static unsigned int __init intc_ack_data(struct intc_desc *desc,
517 struct intc_desc_int *d, 621 struct intc_desc_int *d,
518 intc_enum enum_id) 622 intc_enum enum_id)
519{ 623{
520 struct intc_mask_reg *mr = desc->ack_regs; 624 struct intc_mask_reg *mr = desc->hw.ack_regs;
521 unsigned int i, j, fn, mode; 625 unsigned int i, j, fn, mode;
522 unsigned long reg_e, reg_d; 626 unsigned long reg_e, reg_d;
523 627
524 for (i = 0; mr && enum_id && i < desc->nr_ack_regs; i++) { 628 for (i = 0; mr && enum_id && i < desc->hw.nr_ack_regs; i++) {
525 mr = desc->ack_regs + i; 629 mr = desc->hw.ack_regs + i;
526 630
527 for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) { 631 for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) {
528 if (mr->enum_ids[j] != enum_id) 632 if (mr->enum_ids[j] != enum_id)
@@ -549,11 +653,11 @@ static unsigned int __init intc_sense_data(struct intc_desc *desc,
549 struct intc_desc_int *d, 653 struct intc_desc_int *d,
550 intc_enum enum_id) 654 intc_enum enum_id)
551{ 655{
552 struct intc_sense_reg *sr = desc->sense_regs; 656 struct intc_sense_reg *sr = desc->hw.sense_regs;
553 unsigned int i, j, fn, bit; 657 unsigned int i, j, fn, bit;
554 658
555 for (i = 0; sr && enum_id && i < desc->nr_sense_regs; i++) { 659 for (i = 0; sr && enum_id && i < desc->hw.nr_sense_regs; i++) {
556 sr = desc->sense_regs + i; 660 sr = desc->hw.sense_regs + i;
557 661
558 for (j = 0; j < ARRAY_SIZE(sr->enum_ids); j++) { 662 for (j = 0; j < ARRAY_SIZE(sr->enum_ids); j++) {
559 if (sr->enum_ids[j] != enum_id) 663 if (sr->enum_ids[j] != enum_id)
@@ -656,7 +760,7 @@ static void __init intc_register_irq(struct intc_desc *desc,
656 /* irq should be disabled by default */ 760 /* irq should be disabled by default */
657 d->chip.mask(irq); 761 d->chip.mask(irq);
658 762
659 if (desc->ack_regs) 763 if (desc->hw.ack_regs)
660 ack_handle[irq] = intc_ack_data(desc, d, enum_id); 764 ack_handle[irq] = intc_ack_data(desc, d, enum_id);
661} 765}
662 766
@@ -684,6 +788,7 @@ static void intc_redirect_irq(unsigned int irq, struct irq_desc *desc)
684void __init register_intc_controller(struct intc_desc *desc) 788void __init register_intc_controller(struct intc_desc *desc)
685{ 789{
686 unsigned int i, k, smp; 790 unsigned int i, k, smp;
791 struct intc_hw_desc *hw = &desc->hw;
687 struct intc_desc_int *d; 792 struct intc_desc_int *d;
688 793
689 d = kzalloc(sizeof(*d), GFP_NOWAIT); 794 d = kzalloc(sizeof(*d), GFP_NOWAIT);
@@ -691,10 +796,10 @@ void __init register_intc_controller(struct intc_desc *desc)
691 INIT_LIST_HEAD(&d->list); 796 INIT_LIST_HEAD(&d->list);
692 list_add(&d->list, &intc_list); 797 list_add(&d->list, &intc_list);
693 798
694 d->nr_reg = desc->mask_regs ? desc->nr_mask_regs * 2 : 0; 799 d->nr_reg = hw->mask_regs ? hw->nr_mask_regs * 2 : 0;
695 d->nr_reg += desc->prio_regs ? desc->nr_prio_regs * 2 : 0; 800 d->nr_reg += hw->prio_regs ? hw->nr_prio_regs * 2 : 0;
696 d->nr_reg += desc->sense_regs ? desc->nr_sense_regs : 0; 801 d->nr_reg += hw->sense_regs ? hw->nr_sense_regs : 0;
697 d->nr_reg += desc->ack_regs ? desc->nr_ack_regs : 0; 802 d->nr_reg += hw->ack_regs ? hw->nr_ack_regs : 0;
698 803
699 d->reg = kzalloc(d->nr_reg * sizeof(*d->reg), GFP_NOWAIT); 804 d->reg = kzalloc(d->nr_reg * sizeof(*d->reg), GFP_NOWAIT);
700#ifdef CONFIG_SMP 805#ifdef CONFIG_SMP
@@ -702,30 +807,31 @@ void __init register_intc_controller(struct intc_desc *desc)
702#endif 807#endif
703 k = 0; 808 k = 0;
704 809
705 if (desc->mask_regs) { 810 if (hw->mask_regs) {
706 for (i = 0; i < desc->nr_mask_regs; i++) { 811 for (i = 0; i < hw->nr_mask_regs; i++) {
707 smp = IS_SMP(desc->mask_regs[i]); 812 smp = IS_SMP(hw->mask_regs[i]);
708 k += save_reg(d, k, desc->mask_regs[i].set_reg, smp); 813 k += save_reg(d, k, hw->mask_regs[i].set_reg, smp);
709 k += save_reg(d, k, desc->mask_regs[i].clr_reg, smp); 814 k += save_reg(d, k, hw->mask_regs[i].clr_reg, smp);
710 } 815 }
711 } 816 }
712 817
713 if (desc->prio_regs) { 818 if (hw->prio_regs) {
714 d->prio = kzalloc(desc->nr_vectors * sizeof(*d->prio), GFP_NOWAIT); 819 d->prio = kzalloc(hw->nr_vectors * sizeof(*d->prio),
820 GFP_NOWAIT);
715 821
716 for (i = 0; i < desc->nr_prio_regs; i++) { 822 for (i = 0; i < hw->nr_prio_regs; i++) {
717 smp = IS_SMP(desc->prio_regs[i]); 823 smp = IS_SMP(hw->prio_regs[i]);
718 k += save_reg(d, k, desc->prio_regs[i].set_reg, smp); 824 k += save_reg(d, k, hw->prio_regs[i].set_reg, smp);
719 k += save_reg(d, k, desc->prio_regs[i].clr_reg, smp); 825 k += save_reg(d, k, hw->prio_regs[i].clr_reg, smp);
720 } 826 }
721 } 827 }
722 828
723 if (desc->sense_regs) { 829 if (hw->sense_regs) {
724 d->sense = kzalloc(desc->nr_vectors * sizeof(*d->sense), GFP_NOWAIT); 830 d->sense = kzalloc(hw->nr_vectors * sizeof(*d->sense),
831 GFP_NOWAIT);
725 832
726 for (i = 0; i < desc->nr_sense_regs; i++) { 833 for (i = 0; i < hw->nr_sense_regs; i++)
727 k += save_reg(d, k, desc->sense_regs[i].reg, 0); 834 k += save_reg(d, k, hw->sense_regs[i].reg, 0);
728 }
729 } 835 }
730 836
731 d->chip.name = desc->name; 837 d->chip.name = desc->name;
@@ -738,18 +844,26 @@ void __init register_intc_controller(struct intc_desc *desc)
738 d->chip.set_type = intc_set_sense; 844 d->chip.set_type = intc_set_sense;
739 d->chip.set_wake = intc_set_wake; 845 d->chip.set_wake = intc_set_wake;
740 846
741 if (desc->ack_regs) { 847 if (hw->ack_regs) {
742 for (i = 0; i < desc->nr_ack_regs; i++) 848 for (i = 0; i < hw->nr_ack_regs; i++)
743 k += save_reg(d, k, desc->ack_regs[i].set_reg, 0); 849 k += save_reg(d, k, hw->ack_regs[i].set_reg, 0);
744 850
745 d->chip.mask_ack = intc_mask_ack; 851 d->chip.mask_ack = intc_mask_ack;
746 } 852 }
747 853
854 /* disable bits matching force_disable before registering irqs */
855 if (desc->force_disable)
856 intc_enable_disable_enum(desc, d, desc->force_disable, 0);
857
858 /* disable bits matching force_enable before registering irqs */
859 if (desc->force_enable)
860 intc_enable_disable_enum(desc, d, desc->force_enable, 0);
861
748 BUG_ON(k > 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */ 862 BUG_ON(k > 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */
749 863
750 /* register the vectors one by one */ 864 /* register the vectors one by one */
751 for (i = 0; i < desc->nr_vectors; i++) { 865 for (i = 0; i < hw->nr_vectors; i++) {
752 struct intc_vect *vect = desc->vectors + i; 866 struct intc_vect *vect = hw->vectors + i;
753 unsigned int irq = evt2irq(vect->vect); 867 unsigned int irq = evt2irq(vect->vect);
754 struct irq_desc *irq_desc; 868 struct irq_desc *irq_desc;
755 869
@@ -764,8 +878,8 @@ void __init register_intc_controller(struct intc_desc *desc)
764 878
765 intc_register_irq(desc, d, vect->enum_id, irq); 879 intc_register_irq(desc, d, vect->enum_id, irq);
766 880
767 for (k = i + 1; k < desc->nr_vectors; k++) { 881 for (k = i + 1; k < hw->nr_vectors; k++) {
768 struct intc_vect *vect2 = desc->vectors + k; 882 struct intc_vect *vect2 = hw->vectors + k;
769 unsigned int irq2 = evt2irq(vect2->vect); 883 unsigned int irq2 = evt2irq(vect2->vect);
770 884
771 if (vect->enum_id != vect2->enum_id) 885 if (vect->enum_id != vect2->enum_id)
@@ -785,11 +899,15 @@ void __init register_intc_controller(struct intc_desc *desc)
785 vect2->enum_id = 0; 899 vect2->enum_id = 0;
786 900
787 /* redirect this interrupts to the first one */ 901 /* redirect this interrupts to the first one */
788 set_irq_chip_and_handler_name(irq2, &d->chip, 902 set_irq_chip(irq2, &dummy_irq_chip);
789 intc_redirect_irq, "redirect"); 903 set_irq_chained_handler(irq2, intc_redirect_irq);
790 set_irq_data(irq2, (void *)irq); 904 set_irq_data(irq2, (void *)irq);
791 } 905 }
792 } 906 }
907
908 /* enable bits matching force_enable after registering irqs */
909 if (desc->force_enable)
910 intc_enable_disable_enum(desc, d, desc->force_enable, 1);
793} 911}
794 912
795static int intc_suspend(struct sys_device *dev, pm_message_t state) 913static int intc_suspend(struct sys_device *dev, pm_message_t state)
@@ -872,7 +990,7 @@ device_initcall(register_intc_sysdevs);
872/* 990/*
873 * Dynamic IRQ allocation and deallocation 991 * Dynamic IRQ allocation and deallocation
874 */ 992 */
875static unsigned int create_irq_on_node(unsigned int irq_want, int node) 993unsigned int create_irq_nr(unsigned int irq_want, int node)
876{ 994{
877 unsigned int irq = 0, new; 995 unsigned int irq = 0, new;
878 unsigned long flags; 996 unsigned long flags;
@@ -881,24 +999,28 @@ static unsigned int create_irq_on_node(unsigned int irq_want, int node)
881 spin_lock_irqsave(&vector_lock, flags); 999 spin_lock_irqsave(&vector_lock, flags);
882 1000
883 /* 1001 /*
884 * First try the wanted IRQ, then scan. 1002 * First try the wanted IRQ
885 */ 1003 */
886 if (test_and_set_bit(irq_want, intc_irq_map)) { 1004 if (test_and_set_bit(irq_want, intc_irq_map) == 0) {
1005 new = irq_want;
1006 } else {
1007 /* .. then fall back to scanning. */
887 new = find_first_zero_bit(intc_irq_map, nr_irqs); 1008 new = find_first_zero_bit(intc_irq_map, nr_irqs);
888 if (unlikely(new == nr_irqs)) 1009 if (unlikely(new == nr_irqs))
889 goto out_unlock; 1010 goto out_unlock;
890 1011
891 desc = irq_to_desc_alloc_node(new, node);
892 if (unlikely(!desc)) {
893 pr_info("can't get irq_desc for %d\n", new);
894 goto out_unlock;
895 }
896
897 desc = move_irq_desc(desc, node);
898 __set_bit(new, intc_irq_map); 1012 __set_bit(new, intc_irq_map);
899 irq = new;
900 } 1013 }
901 1014
1015 desc = irq_to_desc_alloc_node(new, node);
1016 if (unlikely(!desc)) {
1017 pr_info("can't get irq_desc for %d\n", new);
1018 goto out_unlock;
1019 }
1020
1021 desc = move_irq_desc(desc, node);
1022 irq = new;
1023
902out_unlock: 1024out_unlock:
903 spin_unlock_irqrestore(&vector_lock, flags); 1025 spin_unlock_irqrestore(&vector_lock, flags);
904 1026
@@ -913,7 +1035,7 @@ int create_irq(void)
913 int nid = cpu_to_node(smp_processor_id()); 1035 int nid = cpu_to_node(smp_processor_id());
914 int irq; 1036 int irq;
915 1037
916 irq = create_irq_on_node(NR_IRQS_LEGACY, nid); 1038 irq = create_irq_nr(NR_IRQS_LEGACY, nid);
917 if (irq == 0) 1039 if (irq == 0)
918 irq = -1; 1040 irq = -1;
919 1041
diff --git a/drivers/sh/pfc.c b/drivers/sh/pfc.c
index 082604edc4c2..cf0303acab8e 100644
--- a/drivers/sh/pfc.c
+++ b/drivers/sh/pfc.c
@@ -337,12 +337,39 @@ static int pinmux_config_gpio(struct pinmux_info *gpioc, unsigned gpio,
337 if (!enum_id) 337 if (!enum_id)
338 break; 338 break;
339 339
340 /* first check if this is a function enum */
340 in_range = enum_in_range(enum_id, &gpioc->function); 341 in_range = enum_in_range(enum_id, &gpioc->function);
341 if (!in_range && range) { 342 if (!in_range) {
342 in_range = enum_in_range(enum_id, range); 343 /* not a function enum */
343 344 if (range) {
344 if (in_range && enum_id == range->force) 345 /*
345 continue; 346 * other range exists, so this pin is
347 * a regular GPIO pin that now is being
348 * bound to a specific direction.
349 *
350 * for this case we only allow function enums
351 * and the enums that match the other range.
352 */
353 in_range = enum_in_range(enum_id, range);
354
355 /*
356 * special case pass through for fixed
357 * input-only or output-only pins without
358 * function enum register association.
359 */
360 if (in_range && enum_id == range->force)
361 continue;
362 } else {
363 /*
364 * no other range exists, so this pin
365 * must then be of the function type.
366 *
367 * allow function type pins to select
368 * any combination of function/in/out
369 * in their MARK lists.
370 */
371 in_range = 1;
372 }
346 } 373 }
347 374
348 if (!in_range) 375 if (!in_range)
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index f55eb0107336..0fee95cd9a49 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -100,6 +100,23 @@ config SPI_BUTTERFLY
100 inexpensive battery powered microcontroller evaluation board. 100 inexpensive battery powered microcontroller evaluation board.
101 This same cable can be used to flash new firmware. 101 This same cable can be used to flash new firmware.
102 102
103config SPI_COLDFIRE_QSPI
104 tristate "Freescale Coldfire QSPI controller"
105 depends on (M520x || M523x || M5249 || M527x || M528x || M532x)
106 help
107 This enables support for the Coldfire QSPI controller in master
108 mode.
109
110 This driver can also be built as a module. If so, the module
111 will be called coldfire_qspi.
112
113config SPI_DAVINCI
114 tristate "SPI controller driver for DaVinci/DA8xx SoC's"
115 depends on SPI_MASTER && ARCH_DAVINCI
116 select SPI_BITBANG
117 help
118 SPI master controller for DaVinci and DA8xx SPI modules.
119
103config SPI_GPIO 120config SPI_GPIO
104 tristate "GPIO-based bitbanging SPI Master" 121 tristate "GPIO-based bitbanging SPI Master"
105 depends on GENERIC_GPIO 122 depends on GENERIC_GPIO
@@ -308,7 +325,7 @@ config SPI_NUC900
308# 325#
309 326
310config SPI_DESIGNWARE 327config SPI_DESIGNWARE
311 bool "DesignWare SPI controller core support" 328 tristate "DesignWare SPI controller core support"
312 depends on SPI_MASTER 329 depends on SPI_MASTER
313 help 330 help
314 general driver for SPI controller core from DesignWare 331 general driver for SPI controller core from DesignWare
@@ -317,6 +334,10 @@ config SPI_DW_PCI
317 tristate "PCI interface driver for DW SPI core" 334 tristate "PCI interface driver for DW SPI core"
318 depends on SPI_DESIGNWARE && PCI 335 depends on SPI_DESIGNWARE && PCI
319 336
337config SPI_DW_MMIO
338 tristate "Memory-mapped io interface driver for DW SPI core"
339 depends on SPI_DESIGNWARE && HAVE_CLK
340
320# 341#
321# There are lots of SPI device types, with sensors and memory 342# There are lots of SPI device types, with sensors and memory
322# being probably the most widely used ones. 343# being probably the most widely used ones.
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index f3d2810ba11c..d7d0f89b797b 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -16,8 +16,11 @@ obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.o
16obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o 16obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
17obj-$(CONFIG_SPI_AU1550) += au1550_spi.o 17obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
18obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o 18obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
19obj-$(CONFIG_SPI_COLDFIRE_QSPI) += coldfire_qspi.o
20obj-$(CONFIG_SPI_DAVINCI) += davinci_spi.o
19obj-$(CONFIG_SPI_DESIGNWARE) += dw_spi.o 21obj-$(CONFIG_SPI_DESIGNWARE) += dw_spi.o
20obj-$(CONFIG_SPI_DW_PCI) += dw_spi_pci.o 22obj-$(CONFIG_SPI_DW_PCI) += dw_spi_pci.o
23obj-$(CONFIG_SPI_DW_MMIO) += dw_spi_mmio.o
21obj-$(CONFIG_SPI_GPIO) += spi_gpio.o 24obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
22obj-$(CONFIG_SPI_IMX) += spi_imx.o 25obj-$(CONFIG_SPI_IMX) += spi_imx.o
23obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o 26obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
diff --git a/drivers/spi/au1550_spi.c b/drivers/spi/au1550_spi.c
index cfd5ff9508fa..ba8ac4f599d3 100644
--- a/drivers/spi/au1550_spi.c
+++ b/drivers/spi/au1550_spi.c
@@ -412,11 +412,13 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
412 } 412 }
413 413
414 /* put buffers on the ring */ 414 /* put buffers on the ring */
415 res = au1xxx_dbdma_put_dest(hw->dma_rx_ch, hw->rx, t->len); 415 res = au1xxx_dbdma_put_dest(hw->dma_rx_ch, virt_to_phys(hw->rx),
416 t->len, DDMA_FLAGS_IE);
416 if (!res) 417 if (!res)
417 dev_err(hw->dev, "rx dma put dest error\n"); 418 dev_err(hw->dev, "rx dma put dest error\n");
418 419
419 res = au1xxx_dbdma_put_source(hw->dma_tx_ch, (void *)hw->tx, t->len); 420 res = au1xxx_dbdma_put_source(hw->dma_tx_ch, virt_to_phys(hw->tx),
421 t->len, DDMA_FLAGS_IE);
420 if (!res) 422 if (!res)
421 dev_err(hw->dev, "tx dma put source error\n"); 423 dev_err(hw->dev, "tx dma put source error\n");
422 424
diff --git a/drivers/spi/coldfire_qspi.c b/drivers/spi/coldfire_qspi.c
new file mode 100644
index 000000000000..59be3efe0636
--- /dev/null
+++ b/drivers/spi/coldfire_qspi.c
@@ -0,0 +1,640 @@
1/*
2 * Freescale/Motorola Coldfire Queued SPI driver
3 *
4 * Copyright 2010 Steven King <sfking@fdwdc.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., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA
19 *
20*/
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/interrupt.h>
25#include <linux/errno.h>
26#include <linux/platform_device.h>
27#include <linux/workqueue.h>
28#include <linux/delay.h>
29#include <linux/io.h>
30#include <linux/clk.h>
31#include <linux/err.h>
32#include <linux/spi/spi.h>
33
34#include <asm/coldfire.h>
35#include <asm/mcfqspi.h>
36
37#define DRIVER_NAME "mcfqspi"
38
39#define MCFQSPI_BUSCLK (MCF_BUSCLK / 2)
40
41#define MCFQSPI_QMR 0x00
42#define MCFQSPI_QMR_MSTR 0x8000
43#define MCFQSPI_QMR_CPOL 0x0200
44#define MCFQSPI_QMR_CPHA 0x0100
45#define MCFQSPI_QDLYR 0x04
46#define MCFQSPI_QDLYR_SPE 0x8000
47#define MCFQSPI_QWR 0x08
48#define MCFQSPI_QWR_HALT 0x8000
49#define MCFQSPI_QWR_WREN 0x4000
50#define MCFQSPI_QWR_CSIV 0x1000
51#define MCFQSPI_QIR 0x0C
52#define MCFQSPI_QIR_WCEFB 0x8000
53#define MCFQSPI_QIR_ABRTB 0x4000
54#define MCFQSPI_QIR_ABRTL 0x1000
55#define MCFQSPI_QIR_WCEFE 0x0800
56#define MCFQSPI_QIR_ABRTE 0x0400
57#define MCFQSPI_QIR_SPIFE 0x0100
58#define MCFQSPI_QIR_WCEF 0x0008
59#define MCFQSPI_QIR_ABRT 0x0004
60#define MCFQSPI_QIR_SPIF 0x0001
61#define MCFQSPI_QAR 0x010
62#define MCFQSPI_QAR_TXBUF 0x00
63#define MCFQSPI_QAR_RXBUF 0x10
64#define MCFQSPI_QAR_CMDBUF 0x20
65#define MCFQSPI_QDR 0x014
66#define MCFQSPI_QCR 0x014
67#define MCFQSPI_QCR_CONT 0x8000
68#define MCFQSPI_QCR_BITSE 0x4000
69#define MCFQSPI_QCR_DT 0x2000
70
71struct mcfqspi {
72 void __iomem *iobase;
73 int irq;
74 struct clk *clk;
75 struct mcfqspi_cs_control *cs_control;
76
77 wait_queue_head_t waitq;
78
79 struct work_struct work;
80 struct workqueue_struct *workq;
81 spinlock_t lock;
82 struct list_head msgq;
83};
84
85static void mcfqspi_wr_qmr(struct mcfqspi *mcfqspi, u16 val)
86{
87 writew(val, mcfqspi->iobase + MCFQSPI_QMR);
88}
89
90static void mcfqspi_wr_qdlyr(struct mcfqspi *mcfqspi, u16 val)
91{
92 writew(val, mcfqspi->iobase + MCFQSPI_QDLYR);
93}
94
95static u16 mcfqspi_rd_qdlyr(struct mcfqspi *mcfqspi)
96{
97 return readw(mcfqspi->iobase + MCFQSPI_QDLYR);
98}
99
100static void mcfqspi_wr_qwr(struct mcfqspi *mcfqspi, u16 val)
101{
102 writew(val, mcfqspi->iobase + MCFQSPI_QWR);
103}
104
105static void mcfqspi_wr_qir(struct mcfqspi *mcfqspi, u16 val)
106{
107 writew(val, mcfqspi->iobase + MCFQSPI_QIR);
108}
109
110static void mcfqspi_wr_qar(struct mcfqspi *mcfqspi, u16 val)
111{
112 writew(val, mcfqspi->iobase + MCFQSPI_QAR);
113}
114
115static void mcfqspi_wr_qdr(struct mcfqspi *mcfqspi, u16 val)
116{
117 writew(val, mcfqspi->iobase + MCFQSPI_QDR);
118}
119
120static u16 mcfqspi_rd_qdr(struct mcfqspi *mcfqspi)
121{
122 return readw(mcfqspi->iobase + MCFQSPI_QDR);
123}
124
125static void mcfqspi_cs_select(struct mcfqspi *mcfqspi, u8 chip_select,
126 bool cs_high)
127{
128 mcfqspi->cs_control->select(mcfqspi->cs_control, chip_select, cs_high);
129}
130
131static void mcfqspi_cs_deselect(struct mcfqspi *mcfqspi, u8 chip_select,
132 bool cs_high)
133{
134 mcfqspi->cs_control->deselect(mcfqspi->cs_control, chip_select, cs_high);
135}
136
137static int mcfqspi_cs_setup(struct mcfqspi *mcfqspi)
138{
139 return (mcfqspi->cs_control && mcfqspi->cs_control->setup) ?
140 mcfqspi->cs_control->setup(mcfqspi->cs_control) : 0;
141}
142
143static void mcfqspi_cs_teardown(struct mcfqspi *mcfqspi)
144{
145 if (mcfqspi->cs_control && mcfqspi->cs_control->teardown)
146 mcfqspi->cs_control->teardown(mcfqspi->cs_control);
147}
148
149static u8 mcfqspi_qmr_baud(u32 speed_hz)
150{
151 return clamp((MCFQSPI_BUSCLK + speed_hz - 1) / speed_hz, 2u, 255u);
152}
153
154static bool mcfqspi_qdlyr_spe(struct mcfqspi *mcfqspi)
155{
156 return mcfqspi_rd_qdlyr(mcfqspi) & MCFQSPI_QDLYR_SPE;
157}
158
159static irqreturn_t mcfqspi_irq_handler(int this_irq, void *dev_id)
160{
161 struct mcfqspi *mcfqspi = dev_id;
162
163 /* clear interrupt */
164 mcfqspi_wr_qir(mcfqspi, MCFQSPI_QIR_SPIFE | MCFQSPI_QIR_SPIF);
165 wake_up(&mcfqspi->waitq);
166
167 return IRQ_HANDLED;
168}
169
170static void mcfqspi_transfer_msg8(struct mcfqspi *mcfqspi, unsigned count,
171 const u8 *txbuf, u8 *rxbuf)
172{
173 unsigned i, n, offset = 0;
174
175 n = min(count, 16u);
176
177 mcfqspi_wr_qar(mcfqspi, MCFQSPI_QAR_CMDBUF);
178 for (i = 0; i < n; ++i)
179 mcfqspi_wr_qdr(mcfqspi, MCFQSPI_QCR_BITSE);
180
181 mcfqspi_wr_qar(mcfqspi, MCFQSPI_QAR_TXBUF);
182 if (txbuf)
183 for (i = 0; i < n; ++i)
184 mcfqspi_wr_qdr(mcfqspi, *txbuf++);
185 else
186 for (i = 0; i < count; ++i)
187 mcfqspi_wr_qdr(mcfqspi, 0);
188
189 count -= n;
190 if (count) {
191 u16 qwr = 0xf08;
192 mcfqspi_wr_qwr(mcfqspi, 0x700);
193 mcfqspi_wr_qdlyr(mcfqspi, MCFQSPI_QDLYR_SPE);
194
195 do {
196 wait_event(mcfqspi->waitq, !mcfqspi_qdlyr_spe(mcfqspi));
197 mcfqspi_wr_qwr(mcfqspi, qwr);
198 mcfqspi_wr_qdlyr(mcfqspi, MCFQSPI_QDLYR_SPE);
199 if (rxbuf) {
200 mcfqspi_wr_qar(mcfqspi,
201 MCFQSPI_QAR_RXBUF + offset);
202 for (i = 0; i < 8; ++i)
203 *rxbuf++ = mcfqspi_rd_qdr(mcfqspi);
204 }
205 n = min(count, 8u);
206 if (txbuf) {
207 mcfqspi_wr_qar(mcfqspi,
208 MCFQSPI_QAR_TXBUF + offset);
209 for (i = 0; i < n; ++i)
210 mcfqspi_wr_qdr(mcfqspi, *txbuf++);
211 }
212 qwr = (offset ? 0x808 : 0) + ((n - 1) << 8);
213 offset ^= 8;
214 count -= n;
215 } while (count);
216 wait_event(mcfqspi->waitq, !mcfqspi_qdlyr_spe(mcfqspi));
217 mcfqspi_wr_qwr(mcfqspi, qwr);
218 mcfqspi_wr_qdlyr(mcfqspi, MCFQSPI_QDLYR_SPE);
219 if (rxbuf) {
220 mcfqspi_wr_qar(mcfqspi, MCFQSPI_QAR_RXBUF + offset);
221 for (i = 0; i < 8; ++i)
222 *rxbuf++ = mcfqspi_rd_qdr(mcfqspi);
223 offset ^= 8;
224 }
225 } else {
226 mcfqspi_wr_qwr(mcfqspi, (n - 1) << 8);
227 mcfqspi_wr_qdlyr(mcfqspi, MCFQSPI_QDLYR_SPE);
228 }
229 wait_event(mcfqspi->waitq, !mcfqspi_qdlyr_spe(mcfqspi));
230 if (rxbuf) {
231 mcfqspi_wr_qar(mcfqspi, MCFQSPI_QAR_RXBUF + offset);
232 for (i = 0; i < n; ++i)
233 *rxbuf++ = mcfqspi_rd_qdr(mcfqspi);
234 }
235}
236
237static void mcfqspi_transfer_msg16(struct mcfqspi *mcfqspi, unsigned count,
238 const u16 *txbuf, u16 *rxbuf)
239{
240 unsigned i, n, offset = 0;
241
242 n = min(count, 16u);
243
244 mcfqspi_wr_qar(mcfqspi, MCFQSPI_QAR_CMDBUF);
245 for (i = 0; i < n; ++i)
246 mcfqspi_wr_qdr(mcfqspi, MCFQSPI_QCR_BITSE);
247
248 mcfqspi_wr_qar(mcfqspi, MCFQSPI_QAR_TXBUF);
249 if (txbuf)
250 for (i = 0; i < n; ++i)
251 mcfqspi_wr_qdr(mcfqspi, *txbuf++);
252 else
253 for (i = 0; i < count; ++i)
254 mcfqspi_wr_qdr(mcfqspi, 0);
255
256 count -= n;
257 if (count) {
258 u16 qwr = 0xf08;
259 mcfqspi_wr_qwr(mcfqspi, 0x700);
260 mcfqspi_wr_qdlyr(mcfqspi, MCFQSPI_QDLYR_SPE);
261
262 do {
263 wait_event(mcfqspi->waitq, !mcfqspi_qdlyr_spe(mcfqspi));
264 mcfqspi_wr_qwr(mcfqspi, qwr);
265 mcfqspi_wr_qdlyr(mcfqspi, MCFQSPI_QDLYR_SPE);
266 if (rxbuf) {
267 mcfqspi_wr_qar(mcfqspi,
268 MCFQSPI_QAR_RXBUF + offset);
269 for (i = 0; i < 8; ++i)
270 *rxbuf++ = mcfqspi_rd_qdr(mcfqspi);
271 }
272 n = min(count, 8u);
273 if (txbuf) {
274 mcfqspi_wr_qar(mcfqspi,
275 MCFQSPI_QAR_TXBUF + offset);
276 for (i = 0; i < n; ++i)
277 mcfqspi_wr_qdr(mcfqspi, *txbuf++);
278 }
279 qwr = (offset ? 0x808 : 0x000) + ((n - 1) << 8);
280 offset ^= 8;
281 count -= n;
282 } while (count);
283 wait_event(mcfqspi->waitq, !mcfqspi_qdlyr_spe(mcfqspi));
284 mcfqspi_wr_qwr(mcfqspi, qwr);
285 mcfqspi_wr_qdlyr(mcfqspi, MCFQSPI_QDLYR_SPE);
286 if (rxbuf) {
287 mcfqspi_wr_qar(mcfqspi, MCFQSPI_QAR_RXBUF + offset);
288 for (i = 0; i < 8; ++i)
289 *rxbuf++ = mcfqspi_rd_qdr(mcfqspi);
290 offset ^= 8;
291 }
292 } else {
293 mcfqspi_wr_qwr(mcfqspi, (n - 1) << 8);
294 mcfqspi_wr_qdlyr(mcfqspi, MCFQSPI_QDLYR_SPE);
295 }
296 wait_event(mcfqspi->waitq, !mcfqspi_qdlyr_spe(mcfqspi));
297 if (rxbuf) {
298 mcfqspi_wr_qar(mcfqspi, MCFQSPI_QAR_RXBUF + offset);
299 for (i = 0; i < n; ++i)
300 *rxbuf++ = mcfqspi_rd_qdr(mcfqspi);
301 }
302}
303
304static void mcfqspi_work(struct work_struct *work)
305{
306 struct mcfqspi *mcfqspi = container_of(work, struct mcfqspi, work);
307 unsigned long flags;
308
309 spin_lock_irqsave(&mcfqspi->lock, flags);
310 while (!list_empty(&mcfqspi->msgq)) {
311 struct spi_message *msg;
312 struct spi_device *spi;
313 struct spi_transfer *xfer;
314 int status = 0;
315
316 msg = container_of(mcfqspi->msgq.next, struct spi_message,
317 queue);
318
319 list_del_init(&mcfqspi->msgq);
320 spin_unlock_irqrestore(&mcfqspi->lock, flags);
321
322 spi = msg->spi;
323
324 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
325 bool cs_high = spi->mode & SPI_CS_HIGH;
326 u16 qmr = MCFQSPI_QMR_MSTR;
327
328 if (xfer->bits_per_word)
329 qmr |= xfer->bits_per_word << 10;
330 else
331 qmr |= spi->bits_per_word << 10;
332 if (spi->mode & SPI_CPHA)
333 qmr |= MCFQSPI_QMR_CPHA;
334 if (spi->mode & SPI_CPOL)
335 qmr |= MCFQSPI_QMR_CPOL;
336 if (xfer->speed_hz)
337 qmr |= mcfqspi_qmr_baud(xfer->speed_hz);
338 else
339 qmr |= mcfqspi_qmr_baud(spi->max_speed_hz);
340 mcfqspi_wr_qmr(mcfqspi, qmr);
341
342 mcfqspi_cs_select(mcfqspi, spi->chip_select, cs_high);
343
344 mcfqspi_wr_qir(mcfqspi, MCFQSPI_QIR_SPIFE);
345 if ((xfer->bits_per_word ? xfer->bits_per_word :
346 spi->bits_per_word) == 8)
347 mcfqspi_transfer_msg8(mcfqspi, xfer->len,
348 xfer->tx_buf,
349 xfer->rx_buf);
350 else
351 mcfqspi_transfer_msg16(mcfqspi, xfer->len / 2,
352 xfer->tx_buf,
353 xfer->rx_buf);
354 mcfqspi_wr_qir(mcfqspi, 0);
355
356 if (xfer->delay_usecs)
357 udelay(xfer->delay_usecs);
358 if (xfer->cs_change) {
359 if (!list_is_last(&xfer->transfer_list,
360 &msg->transfers))
361 mcfqspi_cs_deselect(mcfqspi,
362 spi->chip_select,
363 cs_high);
364 } else {
365 if (list_is_last(&xfer->transfer_list,
366 &msg->transfers))
367 mcfqspi_cs_deselect(mcfqspi,
368 spi->chip_select,
369 cs_high);
370 }
371 msg->actual_length += xfer->len;
372 }
373 msg->status = status;
374 msg->complete(msg->context);
375
376 spin_lock_irqsave(&mcfqspi->lock, flags);
377 }
378 spin_unlock_irqrestore(&mcfqspi->lock, flags);
379}
380
381static int mcfqspi_transfer(struct spi_device *spi, struct spi_message *msg)
382{
383 struct mcfqspi *mcfqspi;
384 struct spi_transfer *xfer;
385 unsigned long flags;
386
387 mcfqspi = spi_master_get_devdata(spi->master);
388
389 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
390 if (xfer->bits_per_word && ((xfer->bits_per_word < 8)
391 || (xfer->bits_per_word > 16))) {
392 dev_dbg(&spi->dev,
393 "%d bits per word is not supported\n",
394 xfer->bits_per_word);
395 goto fail;
396 }
397 if (xfer->speed_hz) {
398 u32 real_speed = MCFQSPI_BUSCLK /
399 mcfqspi_qmr_baud(xfer->speed_hz);
400 if (real_speed != xfer->speed_hz)
401 dev_dbg(&spi->dev,
402 "using speed %d instead of %d\n",
403 real_speed, xfer->speed_hz);
404 }
405 }
406 msg->status = -EINPROGRESS;
407 msg->actual_length = 0;
408
409 spin_lock_irqsave(&mcfqspi->lock, flags);
410 list_add_tail(&msg->queue, &mcfqspi->msgq);
411 queue_work(mcfqspi->workq, &mcfqspi->work);
412 spin_unlock_irqrestore(&mcfqspi->lock, flags);
413
414 return 0;
415fail:
416 msg->status = -EINVAL;
417 return -EINVAL;
418}
419
420static int mcfqspi_setup(struct spi_device *spi)
421{
422 if ((spi->bits_per_word < 8) || (spi->bits_per_word > 16)) {
423 dev_dbg(&spi->dev, "%d bits per word is not supported\n",
424 spi->bits_per_word);
425 return -EINVAL;
426 }
427 if (spi->chip_select >= spi->master->num_chipselect) {
428 dev_dbg(&spi->dev, "%d chip select is out of range\n",
429 spi->chip_select);
430 return -EINVAL;
431 }
432
433 mcfqspi_cs_deselect(spi_master_get_devdata(spi->master),
434 spi->chip_select, spi->mode & SPI_CS_HIGH);
435
436 dev_dbg(&spi->dev,
437 "bits per word %d, chip select %d, speed %d KHz\n",
438 spi->bits_per_word, spi->chip_select,
439 (MCFQSPI_BUSCLK / mcfqspi_qmr_baud(spi->max_speed_hz))
440 / 1000);
441
442 return 0;
443}
444
445static int __devinit mcfqspi_probe(struct platform_device *pdev)
446{
447 struct spi_master *master;
448 struct mcfqspi *mcfqspi;
449 struct resource *res;
450 struct mcfqspi_platform_data *pdata;
451 int status;
452
453 master = spi_alloc_master(&pdev->dev, sizeof(*mcfqspi));
454 if (master == NULL) {
455 dev_dbg(&pdev->dev, "spi_alloc_master failed\n");
456 return -ENOMEM;
457 }
458
459 mcfqspi = spi_master_get_devdata(master);
460
461 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
462 if (!res) {
463 dev_dbg(&pdev->dev, "platform_get_resource failed\n");
464 status = -ENXIO;
465 goto fail0;
466 }
467
468 if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
469 dev_dbg(&pdev->dev, "request_mem_region failed\n");
470 status = -EBUSY;
471 goto fail0;
472 }
473
474 mcfqspi->iobase = ioremap(res->start, resource_size(res));
475 if (!mcfqspi->iobase) {
476 dev_dbg(&pdev->dev, "ioremap failed\n");
477 status = -ENOMEM;
478 goto fail1;
479 }
480
481 mcfqspi->irq = platform_get_irq(pdev, 0);
482 if (mcfqspi->irq < 0) {
483 dev_dbg(&pdev->dev, "platform_get_irq failed\n");
484 status = -ENXIO;
485 goto fail2;
486 }
487
488 status = request_irq(mcfqspi->irq, mcfqspi_irq_handler, IRQF_DISABLED,
489 pdev->name, mcfqspi);
490 if (status) {
491 dev_dbg(&pdev->dev, "request_irq failed\n");
492 goto fail2;
493 }
494
495 mcfqspi->clk = clk_get(&pdev->dev, "qspi_clk");
496 if (IS_ERR(mcfqspi->clk)) {
497 dev_dbg(&pdev->dev, "clk_get failed\n");
498 status = PTR_ERR(mcfqspi->clk);
499 goto fail3;
500 }
501 clk_enable(mcfqspi->clk);
502
503 mcfqspi->workq = create_singlethread_workqueue(dev_name(master->dev.parent));
504 if (!mcfqspi->workq) {
505 dev_dbg(&pdev->dev, "create_workqueue failed\n");
506 status = -ENOMEM;
507 goto fail4;
508 }
509 INIT_WORK(&mcfqspi->work, mcfqspi_work);
510 spin_lock_init(&mcfqspi->lock);
511 INIT_LIST_HEAD(&mcfqspi->msgq);
512 init_waitqueue_head(&mcfqspi->waitq);
513
514 pdata = pdev->dev.platform_data;
515 if (!pdata) {
516 dev_dbg(&pdev->dev, "platform data is missing\n");
517 goto fail5;
518 }
519 master->bus_num = pdata->bus_num;
520 master->num_chipselect = pdata->num_chipselect;
521
522 mcfqspi->cs_control = pdata->cs_control;
523 status = mcfqspi_cs_setup(mcfqspi);
524 if (status) {
525 dev_dbg(&pdev->dev, "error initializing cs_control\n");
526 goto fail5;
527 }
528
529 master->mode_bits = SPI_CS_HIGH | SPI_CPOL | SPI_CPHA;
530 master->setup = mcfqspi_setup;
531 master->transfer = mcfqspi_transfer;
532
533 platform_set_drvdata(pdev, master);
534
535 status = spi_register_master(master);
536 if (status) {
537 dev_dbg(&pdev->dev, "spi_register_master failed\n");
538 goto fail6;
539 }
540 dev_info(&pdev->dev, "Coldfire QSPI bus driver\n");
541
542 return 0;
543
544fail6:
545 mcfqspi_cs_teardown(mcfqspi);
546fail5:
547 destroy_workqueue(mcfqspi->workq);
548fail4:
549 clk_disable(mcfqspi->clk);
550 clk_put(mcfqspi->clk);
551fail3:
552 free_irq(mcfqspi->irq, mcfqspi);
553fail2:
554 iounmap(mcfqspi->iobase);
555fail1:
556 release_mem_region(res->start, resource_size(res));
557fail0:
558 spi_master_put(master);
559
560 dev_dbg(&pdev->dev, "Coldfire QSPI probe failed\n");
561
562 return status;
563}
564
565static int __devexit mcfqspi_remove(struct platform_device *pdev)
566{
567 struct spi_master *master = platform_get_drvdata(pdev);
568 struct mcfqspi *mcfqspi = spi_master_get_devdata(master);
569 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
570
571 /* disable the hardware (set the baud rate to 0) */
572 mcfqspi_wr_qmr(mcfqspi, MCFQSPI_QMR_MSTR);
573
574 platform_set_drvdata(pdev, NULL);
575 mcfqspi_cs_teardown(mcfqspi);
576 destroy_workqueue(mcfqspi->workq);
577 clk_disable(mcfqspi->clk);
578 clk_put(mcfqspi->clk);
579 free_irq(mcfqspi->irq, mcfqspi);
580 iounmap(mcfqspi->iobase);
581 release_mem_region(res->start, resource_size(res));
582 spi_unregister_master(master);
583 spi_master_put(master);
584
585 return 0;
586}
587
588#ifdef CONFIG_PM
589
590static int mcfqspi_suspend(struct device *dev)
591{
592 struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev));
593
594 clk_disable(mcfqspi->clk);
595
596 return 0;
597}
598
599static int mcfqspi_resume(struct device *dev)
600{
601 struct mcfqspi *mcfqspi = platform_get_drvdata(to_platform_device(dev));
602
603 clk_enable(mcfqspi->clk);
604
605 return 0;
606}
607
608static struct dev_pm_ops mcfqspi_dev_pm_ops = {
609 .suspend = mcfqspi_suspend,
610 .resume = mcfqspi_resume,
611};
612
613#define MCFQSPI_DEV_PM_OPS (&mcfqspi_dev_pm_ops)
614#else
615#define MCFQSPI_DEV_PM_OPS NULL
616#endif
617
618static struct platform_driver mcfqspi_driver = {
619 .driver.name = DRIVER_NAME,
620 .driver.owner = THIS_MODULE,
621 .driver.pm = MCFQSPI_DEV_PM_OPS,
622 .remove = __devexit_p(mcfqspi_remove),
623};
624
625static int __init mcfqspi_init(void)
626{
627 return platform_driver_probe(&mcfqspi_driver, mcfqspi_probe);
628}
629module_init(mcfqspi_init);
630
631static void __exit mcfqspi_exit(void)
632{
633 platform_driver_unregister(&mcfqspi_driver);
634}
635module_exit(mcfqspi_exit);
636
637MODULE_AUTHOR("Steven King <sfking@fdwdc.com>");
638MODULE_DESCRIPTION("Coldfire QSPI Controller Driver");
639MODULE_LICENSE("GPL");
640MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
new file mode 100644
index 000000000000..225ab60b02c4
--- /dev/null
+++ b/drivers/spi/davinci_spi.c
@@ -0,0 +1,1255 @@
1/*
2 * Copyright (C) 2009 Texas Instruments.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <linux/interrupt.h>
20#include <linux/io.h>
21#include <linux/gpio.h>
22#include <linux/module.h>
23#include <linux/delay.h>
24#include <linux/platform_device.h>
25#include <linux/err.h>
26#include <linux/clk.h>
27#include <linux/dma-mapping.h>
28#include <linux/spi/spi.h>
29#include <linux/spi/spi_bitbang.h>
30
31#include <mach/spi.h>
32#include <mach/edma.h>
33
34#define SPI_NO_RESOURCE ((resource_size_t)-1)
35
36#define SPI_MAX_CHIPSELECT 2
37
38#define CS_DEFAULT 0xFF
39
40#define SPI_BUFSIZ (SMP_CACHE_BYTES + 1)
41#define DAVINCI_DMA_DATA_TYPE_S8 0x01
42#define DAVINCI_DMA_DATA_TYPE_S16 0x02
43#define DAVINCI_DMA_DATA_TYPE_S32 0x04
44
45#define SPIFMT_PHASE_MASK BIT(16)
46#define SPIFMT_POLARITY_MASK BIT(17)
47#define SPIFMT_DISTIMER_MASK BIT(18)
48#define SPIFMT_SHIFTDIR_MASK BIT(20)
49#define SPIFMT_WAITENA_MASK BIT(21)
50#define SPIFMT_PARITYENA_MASK BIT(22)
51#define SPIFMT_ODD_PARITY_MASK BIT(23)
52#define SPIFMT_WDELAY_MASK 0x3f000000u
53#define SPIFMT_WDELAY_SHIFT 24
54#define SPIFMT_CHARLEN_MASK 0x0000001Fu
55
56/* SPIGCR1 */
57#define SPIGCR1_SPIENA_MASK 0x01000000u
58
59/* SPIPC0 */
60#define SPIPC0_DIFUN_MASK BIT(11) /* MISO */
61#define SPIPC0_DOFUN_MASK BIT(10) /* MOSI */
62#define SPIPC0_CLKFUN_MASK BIT(9) /* CLK */
63#define SPIPC0_SPIENA_MASK BIT(8) /* nREADY */
64#define SPIPC0_EN1FUN_MASK BIT(1)
65#define SPIPC0_EN0FUN_MASK BIT(0)
66
67#define SPIINT_MASKALL 0x0101035F
68#define SPI_INTLVL_1 0x000001FFu
69#define SPI_INTLVL_0 0x00000000u
70
71/* SPIDAT1 */
72#define SPIDAT1_CSHOLD_SHIFT 28
73#define SPIDAT1_CSNR_SHIFT 16
74#define SPIGCR1_CLKMOD_MASK BIT(1)
75#define SPIGCR1_MASTER_MASK BIT(0)
76#define SPIGCR1_LOOPBACK_MASK BIT(16)
77
78/* SPIBUF */
79#define SPIBUF_TXFULL_MASK BIT(29)
80#define SPIBUF_RXEMPTY_MASK BIT(31)
81
82/* Error Masks */
83#define SPIFLG_DLEN_ERR_MASK BIT(0)
84#define SPIFLG_TIMEOUT_MASK BIT(1)
85#define SPIFLG_PARERR_MASK BIT(2)
86#define SPIFLG_DESYNC_MASK BIT(3)
87#define SPIFLG_BITERR_MASK BIT(4)
88#define SPIFLG_OVRRUN_MASK BIT(6)
89#define SPIFLG_RX_INTR_MASK BIT(8)
90#define SPIFLG_TX_INTR_MASK BIT(9)
91#define SPIFLG_BUF_INIT_ACTIVE_MASK BIT(24)
92#define SPIFLG_MASK (SPIFLG_DLEN_ERR_MASK \
93 | SPIFLG_TIMEOUT_MASK | SPIFLG_PARERR_MASK \
94 | SPIFLG_DESYNC_MASK | SPIFLG_BITERR_MASK \
95 | SPIFLG_OVRRUN_MASK | SPIFLG_RX_INTR_MASK \
96 | SPIFLG_TX_INTR_MASK \
97 | SPIFLG_BUF_INIT_ACTIVE_MASK)
98
99#define SPIINT_DLEN_ERR_INTR BIT(0)
100#define SPIINT_TIMEOUT_INTR BIT(1)
101#define SPIINT_PARERR_INTR BIT(2)
102#define SPIINT_DESYNC_INTR BIT(3)
103#define SPIINT_BITERR_INTR BIT(4)
104#define SPIINT_OVRRUN_INTR BIT(6)
105#define SPIINT_RX_INTR BIT(8)
106#define SPIINT_TX_INTR BIT(9)
107#define SPIINT_DMA_REQ_EN BIT(16)
108#define SPIINT_ENABLE_HIGHZ BIT(24)
109
110#define SPI_T2CDELAY_SHIFT 16
111#define SPI_C2TDELAY_SHIFT 24
112
113/* SPI Controller registers */
114#define SPIGCR0 0x00
115#define SPIGCR1 0x04
116#define SPIINT 0x08
117#define SPILVL 0x0c
118#define SPIFLG 0x10
119#define SPIPC0 0x14
120#define SPIPC1 0x18
121#define SPIPC2 0x1c
122#define SPIPC3 0x20
123#define SPIPC4 0x24
124#define SPIPC5 0x28
125#define SPIPC6 0x2c
126#define SPIPC7 0x30
127#define SPIPC8 0x34
128#define SPIDAT0 0x38
129#define SPIDAT1 0x3c
130#define SPIBUF 0x40
131#define SPIEMU 0x44
132#define SPIDELAY 0x48
133#define SPIDEF 0x4c
134#define SPIFMT0 0x50
135#define SPIFMT1 0x54
136#define SPIFMT2 0x58
137#define SPIFMT3 0x5c
138#define TGINTVEC0 0x60
139#define TGINTVEC1 0x64
140
141struct davinci_spi_slave {
142 u32 cmd_to_write;
143 u32 clk_ctrl_to_write;
144 u32 bytes_per_word;
145 u8 active_cs;
146};
147
148/* We have 2 DMA channels per CS, one for RX and one for TX */
149struct davinci_spi_dma {
150 int dma_tx_channel;
151 int dma_rx_channel;
152 int dma_tx_sync_dev;
153 int dma_rx_sync_dev;
154 enum dma_event_q eventq;
155
156 struct completion dma_tx_completion;
157 struct completion dma_rx_completion;
158};
159
160/* SPI Controller driver's private data. */
161struct davinci_spi {
162 struct spi_bitbang bitbang;
163 struct clk *clk;
164
165 u8 version;
166 resource_size_t pbase;
167 void __iomem *base;
168 size_t region_size;
169 u32 irq;
170 struct completion done;
171
172 const void *tx;
173 void *rx;
174 u8 *tmp_buf;
175 int count;
176 struct davinci_spi_dma *dma_channels;
177 struct davinci_spi_platform_data *pdata;
178
179 void (*get_rx)(u32 rx_data, struct davinci_spi *);
180 u32 (*get_tx)(struct davinci_spi *);
181
182 struct davinci_spi_slave slave[SPI_MAX_CHIPSELECT];
183};
184
185static unsigned use_dma;
186
187static void davinci_spi_rx_buf_u8(u32 data, struct davinci_spi *davinci_spi)
188{
189 u8 *rx = davinci_spi->rx;
190
191 *rx++ = (u8)data;
192 davinci_spi->rx = rx;
193}
194
195static void davinci_spi_rx_buf_u16(u32 data, struct davinci_spi *davinci_spi)
196{
197 u16 *rx = davinci_spi->rx;
198
199 *rx++ = (u16)data;
200 davinci_spi->rx = rx;
201}
202
203static u32 davinci_spi_tx_buf_u8(struct davinci_spi *davinci_spi)
204{
205 u32 data;
206 const u8 *tx = davinci_spi->tx;
207
208 data = *tx++;
209 davinci_spi->tx = tx;
210 return data;
211}
212
213static u32 davinci_spi_tx_buf_u16(struct davinci_spi *davinci_spi)
214{
215 u32 data;
216 const u16 *tx = davinci_spi->tx;
217
218 data = *tx++;
219 davinci_spi->tx = tx;
220 return data;
221}
222
223static inline void set_io_bits(void __iomem *addr, u32 bits)
224{
225 u32 v = ioread32(addr);
226
227 v |= bits;
228 iowrite32(v, addr);
229}
230
231static inline void clear_io_bits(void __iomem *addr, u32 bits)
232{
233 u32 v = ioread32(addr);
234
235 v &= ~bits;
236 iowrite32(v, addr);
237}
238
239static inline void set_fmt_bits(void __iomem *addr, u32 bits, int cs_num)
240{
241 set_io_bits(addr + SPIFMT0 + (0x4 * cs_num), bits);
242}
243
244static inline void clear_fmt_bits(void __iomem *addr, u32 bits, int cs_num)
245{
246 clear_io_bits(addr + SPIFMT0 + (0x4 * cs_num), bits);
247}
248
249static void davinci_spi_set_dma_req(const struct spi_device *spi, int enable)
250{
251 struct davinci_spi *davinci_spi = spi_master_get_devdata(spi->master);
252
253 if (enable)
254 set_io_bits(davinci_spi->base + SPIINT, SPIINT_DMA_REQ_EN);
255 else
256 clear_io_bits(davinci_spi->base + SPIINT, SPIINT_DMA_REQ_EN);
257}
258
259/*
260 * Interface to control the chip select signal
261 */
262static void davinci_spi_chipselect(struct spi_device *spi, int value)
263{
264 struct davinci_spi *davinci_spi;
265 struct davinci_spi_platform_data *pdata;
266 u32 data1_reg_val = 0;
267
268 davinci_spi = spi_master_get_devdata(spi->master);
269 pdata = davinci_spi->pdata;
270
271 /*
272 * Board specific chip select logic decides the polarity and cs
273 * line for the controller
274 */
275 if (value == BITBANG_CS_INACTIVE) {
276 set_io_bits(davinci_spi->base + SPIDEF, CS_DEFAULT);
277
278 data1_reg_val |= CS_DEFAULT << SPIDAT1_CSNR_SHIFT;
279 iowrite32(data1_reg_val, davinci_spi->base + SPIDAT1);
280
281 while ((ioread32(davinci_spi->base + SPIBUF)
282 & SPIBUF_RXEMPTY_MASK) == 0)
283 cpu_relax();
284 }
285}
286
287/**
288 * davinci_spi_setup_transfer - This functions will determine transfer method
289 * @spi: spi device on which data transfer to be done
290 * @t: spi transfer in which transfer info is filled
291 *
292 * This function determines data transfer method (8/16/32 bit transfer).
293 * It will also set the SPI Clock Control register according to
294 * SPI slave device freq.
295 */
296static int davinci_spi_setup_transfer(struct spi_device *spi,
297 struct spi_transfer *t)
298{
299
300 struct davinci_spi *davinci_spi;
301 struct davinci_spi_platform_data *pdata;
302 u8 bits_per_word = 0;
303 u32 hz = 0, prescale;
304
305 davinci_spi = spi_master_get_devdata(spi->master);
306 pdata = davinci_spi->pdata;
307
308 if (t) {
309 bits_per_word = t->bits_per_word;
310 hz = t->speed_hz;
311 }
312
313 /* if bits_per_word is not set then set it default */
314 if (!bits_per_word)
315 bits_per_word = spi->bits_per_word;
316
317 /*
318 * Assign function pointer to appropriate transfer method
319 * 8bit, 16bit or 32bit transfer
320 */
321 if (bits_per_word <= 8 && bits_per_word >= 2) {
322 davinci_spi->get_rx = davinci_spi_rx_buf_u8;
323 davinci_spi->get_tx = davinci_spi_tx_buf_u8;
324 davinci_spi->slave[spi->chip_select].bytes_per_word = 1;
325 } else if (bits_per_word <= 16 && bits_per_word >= 2) {
326 davinci_spi->get_rx = davinci_spi_rx_buf_u16;
327 davinci_spi->get_tx = davinci_spi_tx_buf_u16;
328 davinci_spi->slave[spi->chip_select].bytes_per_word = 2;
329 } else
330 return -EINVAL;
331
332 if (!hz)
333 hz = spi->max_speed_hz;
334
335 clear_fmt_bits(davinci_spi->base, SPIFMT_CHARLEN_MASK,
336 spi->chip_select);
337 set_fmt_bits(davinci_spi->base, bits_per_word & 0x1f,
338 spi->chip_select);
339
340 prescale = ((clk_get_rate(davinci_spi->clk) / hz) - 1) & 0xff;
341
342 clear_fmt_bits(davinci_spi->base, 0x0000ff00, spi->chip_select);
343 set_fmt_bits(davinci_spi->base, prescale << 8, spi->chip_select);
344
345 return 0;
346}
347
348static void davinci_spi_dma_rx_callback(unsigned lch, u16 ch_status, void *data)
349{
350 struct spi_device *spi = (struct spi_device *)data;
351 struct davinci_spi *davinci_spi;
352 struct davinci_spi_dma *davinci_spi_dma;
353 struct davinci_spi_platform_data *pdata;
354
355 davinci_spi = spi_master_get_devdata(spi->master);
356 davinci_spi_dma = &(davinci_spi->dma_channels[spi->chip_select]);
357 pdata = davinci_spi->pdata;
358
359 if (ch_status == DMA_COMPLETE)
360 edma_stop(davinci_spi_dma->dma_rx_channel);
361 else
362 edma_clean_channel(davinci_spi_dma->dma_rx_channel);
363
364 complete(&davinci_spi_dma->dma_rx_completion);
365 /* We must disable the DMA RX request */
366 davinci_spi_set_dma_req(spi, 0);
367}
368
369static void davinci_spi_dma_tx_callback(unsigned lch, u16 ch_status, void *data)
370{
371 struct spi_device *spi = (struct spi_device *)data;
372 struct davinci_spi *davinci_spi;
373 struct davinci_spi_dma *davinci_spi_dma;
374 struct davinci_spi_platform_data *pdata;
375
376 davinci_spi = spi_master_get_devdata(spi->master);
377 davinci_spi_dma = &(davinci_spi->dma_channels[spi->chip_select]);
378 pdata = davinci_spi->pdata;
379
380 if (ch_status == DMA_COMPLETE)
381 edma_stop(davinci_spi_dma->dma_tx_channel);
382 else
383 edma_clean_channel(davinci_spi_dma->dma_tx_channel);
384
385 complete(&davinci_spi_dma->dma_tx_completion);
386 /* We must disable the DMA TX request */
387 davinci_spi_set_dma_req(spi, 0);
388}
389
390static int davinci_spi_request_dma(struct spi_device *spi)
391{
392 struct davinci_spi *davinci_spi;
393 struct davinci_spi_dma *davinci_spi_dma;
394 struct davinci_spi_platform_data *pdata;
395 struct device *sdev;
396 int r;
397
398 davinci_spi = spi_master_get_devdata(spi->master);
399 davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
400 pdata = davinci_spi->pdata;
401 sdev = davinci_spi->bitbang.master->dev.parent;
402
403 r = edma_alloc_channel(davinci_spi_dma->dma_rx_sync_dev,
404 davinci_spi_dma_rx_callback, spi,
405 davinci_spi_dma->eventq);
406 if (r < 0) {
407 dev_dbg(sdev, "Unable to request DMA channel for SPI RX\n");
408 return -EAGAIN;
409 }
410 davinci_spi_dma->dma_rx_channel = r;
411 r = edma_alloc_channel(davinci_spi_dma->dma_tx_sync_dev,
412 davinci_spi_dma_tx_callback, spi,
413 davinci_spi_dma->eventq);
414 if (r < 0) {
415 edma_free_channel(davinci_spi_dma->dma_rx_channel);
416 davinci_spi_dma->dma_rx_channel = -1;
417 dev_dbg(sdev, "Unable to request DMA channel for SPI TX\n");
418 return -EAGAIN;
419 }
420 davinci_spi_dma->dma_tx_channel = r;
421
422 return 0;
423}
424
425/**
426 * davinci_spi_setup - This functions will set default transfer method
427 * @spi: spi device on which data transfer to be done
428 *
429 * This functions sets the default transfer method.
430 */
431
432static int davinci_spi_setup(struct spi_device *spi)
433{
434 int retval;
435 struct davinci_spi *davinci_spi;
436 struct davinci_spi_dma *davinci_spi_dma;
437 struct device *sdev;
438
439 davinci_spi = spi_master_get_devdata(spi->master);
440 sdev = davinci_spi->bitbang.master->dev.parent;
441
442 /* if bits per word length is zero then set it default 8 */
443 if (!spi->bits_per_word)
444 spi->bits_per_word = 8;
445
446 davinci_spi->slave[spi->chip_select].cmd_to_write = 0;
447
448 if (use_dma && davinci_spi->dma_channels) {
449 davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
450
451 if ((davinci_spi_dma->dma_rx_channel == -1)
452 || (davinci_spi_dma->dma_tx_channel == -1)) {
453 retval = davinci_spi_request_dma(spi);
454 if (retval < 0)
455 return retval;
456 }
457 }
458
459 /*
460 * SPI in DaVinci and DA8xx operate between
461 * 600 KHz and 50 MHz
462 */
463 if (spi->max_speed_hz < 600000 || spi->max_speed_hz > 50000000) {
464 dev_dbg(sdev, "Operating frequency is not in acceptable "
465 "range\n");
466 return -EINVAL;
467 }
468
469 /*
470 * Set up SPIFMTn register, unique to this chipselect.
471 *
472 * NOTE: we could do all of these with one write. Also, some
473 * of the "version 2" features are found in chips that don't
474 * support all of them...
475 */
476 if (spi->mode & SPI_LSB_FIRST)
477 set_fmt_bits(davinci_spi->base, SPIFMT_SHIFTDIR_MASK,
478 spi->chip_select);
479 else
480 clear_fmt_bits(davinci_spi->base, SPIFMT_SHIFTDIR_MASK,
481 spi->chip_select);
482
483 if (spi->mode & SPI_CPOL)
484 set_fmt_bits(davinci_spi->base, SPIFMT_POLARITY_MASK,
485 spi->chip_select);
486 else
487 clear_fmt_bits(davinci_spi->base, SPIFMT_POLARITY_MASK,
488 spi->chip_select);
489
490 if (!(spi->mode & SPI_CPHA))
491 set_fmt_bits(davinci_spi->base, SPIFMT_PHASE_MASK,
492 spi->chip_select);
493 else
494 clear_fmt_bits(davinci_spi->base, SPIFMT_PHASE_MASK,
495 spi->chip_select);
496
497 /*
498 * Version 1 hardware supports two basic SPI modes:
499 * - Standard SPI mode uses 4 pins, with chipselect
500 * - 3 pin SPI is a 4 pin variant without CS (SPI_NO_CS)
501 * (distinct from SPI_3WIRE, with just one data wire;
502 * or similar variants without MOSI or without MISO)
503 *
504 * Version 2 hardware supports an optional handshaking signal,
505 * so it can support two more modes:
506 * - 5 pin SPI variant is standard SPI plus SPI_READY
507 * - 4 pin with enable is (SPI_READY | SPI_NO_CS)
508 */
509
510 if (davinci_spi->version == SPI_VERSION_2) {
511 clear_fmt_bits(davinci_spi->base, SPIFMT_WDELAY_MASK,
512 spi->chip_select);
513 set_fmt_bits(davinci_spi->base,
514 (davinci_spi->pdata->wdelay
515 << SPIFMT_WDELAY_SHIFT)
516 & SPIFMT_WDELAY_MASK,
517 spi->chip_select);
518
519 if (davinci_spi->pdata->odd_parity)
520 set_fmt_bits(davinci_spi->base,
521 SPIFMT_ODD_PARITY_MASK,
522 spi->chip_select);
523 else
524 clear_fmt_bits(davinci_spi->base,
525 SPIFMT_ODD_PARITY_MASK,
526 spi->chip_select);
527
528 if (davinci_spi->pdata->parity_enable)
529 set_fmt_bits(davinci_spi->base,
530 SPIFMT_PARITYENA_MASK,
531 spi->chip_select);
532 else
533 clear_fmt_bits(davinci_spi->base,
534 SPIFMT_PARITYENA_MASK,
535 spi->chip_select);
536
537 if (davinci_spi->pdata->wait_enable)
538 set_fmt_bits(davinci_spi->base,
539 SPIFMT_WAITENA_MASK,
540 spi->chip_select);
541 else
542 clear_fmt_bits(davinci_spi->base,
543 SPIFMT_WAITENA_MASK,
544 spi->chip_select);
545
546 if (davinci_spi->pdata->timer_disable)
547 set_fmt_bits(davinci_spi->base,
548 SPIFMT_DISTIMER_MASK,
549 spi->chip_select);
550 else
551 clear_fmt_bits(davinci_spi->base,
552 SPIFMT_DISTIMER_MASK,
553 spi->chip_select);
554 }
555
556 retval = davinci_spi_setup_transfer(spi, NULL);
557
558 return retval;
559}
560
561static void davinci_spi_cleanup(struct spi_device *spi)
562{
563 struct davinci_spi *davinci_spi = spi_master_get_devdata(spi->master);
564 struct davinci_spi_dma *davinci_spi_dma;
565
566 davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
567
568 if (use_dma && davinci_spi->dma_channels) {
569 davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
570
571 if ((davinci_spi_dma->dma_rx_channel != -1)
572 && (davinci_spi_dma->dma_tx_channel != -1)) {
573 edma_free_channel(davinci_spi_dma->dma_tx_channel);
574 edma_free_channel(davinci_spi_dma->dma_rx_channel);
575 }
576 }
577}
578
579static int davinci_spi_bufs_prep(struct spi_device *spi,
580 struct davinci_spi *davinci_spi)
581{
582 int op_mode = 0;
583
584 /*
585 * REVISIT unless devices disagree about SPI_LOOP or
586 * SPI_READY (SPI_NO_CS only allows one device!), this
587 * should not need to be done before each message...
588 * optimize for both flags staying cleared.
589 */
590
591 op_mode = SPIPC0_DIFUN_MASK
592 | SPIPC0_DOFUN_MASK
593 | SPIPC0_CLKFUN_MASK;
594 if (!(spi->mode & SPI_NO_CS))
595 op_mode |= 1 << spi->chip_select;
596 if (spi->mode & SPI_READY)
597 op_mode |= SPIPC0_SPIENA_MASK;
598
599 iowrite32(op_mode, davinci_spi->base + SPIPC0);
600
601 if (spi->mode & SPI_LOOP)
602 set_io_bits(davinci_spi->base + SPIGCR1,
603 SPIGCR1_LOOPBACK_MASK);
604 else
605 clear_io_bits(davinci_spi->base + SPIGCR1,
606 SPIGCR1_LOOPBACK_MASK);
607
608 return 0;
609}
610
611static int davinci_spi_check_error(struct davinci_spi *davinci_spi,
612 int int_status)
613{
614 struct device *sdev = davinci_spi->bitbang.master->dev.parent;
615
616 if (int_status & SPIFLG_TIMEOUT_MASK) {
617 dev_dbg(sdev, "SPI Time-out Error\n");
618 return -ETIMEDOUT;
619 }
620 if (int_status & SPIFLG_DESYNC_MASK) {
621 dev_dbg(sdev, "SPI Desynchronization Error\n");
622 return -EIO;
623 }
624 if (int_status & SPIFLG_BITERR_MASK) {
625 dev_dbg(sdev, "SPI Bit error\n");
626 return -EIO;
627 }
628
629 if (davinci_spi->version == SPI_VERSION_2) {
630 if (int_status & SPIFLG_DLEN_ERR_MASK) {
631 dev_dbg(sdev, "SPI Data Length Error\n");
632 return -EIO;
633 }
634 if (int_status & SPIFLG_PARERR_MASK) {
635 dev_dbg(sdev, "SPI Parity Error\n");
636 return -EIO;
637 }
638 if (int_status & SPIFLG_OVRRUN_MASK) {
639 dev_dbg(sdev, "SPI Data Overrun error\n");
640 return -EIO;
641 }
642 if (int_status & SPIFLG_TX_INTR_MASK) {
643 dev_dbg(sdev, "SPI TX intr bit set\n");
644 return -EIO;
645 }
646 if (int_status & SPIFLG_BUF_INIT_ACTIVE_MASK) {
647 dev_dbg(sdev, "SPI Buffer Init Active\n");
648 return -EBUSY;
649 }
650 }
651
652 return 0;
653}
654
655/**
656 * davinci_spi_bufs - functions which will handle transfer data
657 * @spi: spi device on which data transfer to be done
658 * @t: spi transfer in which transfer info is filled
659 *
660 * This function will put data to be transferred into data register
661 * of SPI controller and then wait until the completion will be marked
662 * by the IRQ Handler.
663 */
664static int davinci_spi_bufs_pio(struct spi_device *spi, struct spi_transfer *t)
665{
666 struct davinci_spi *davinci_spi;
667 int int_status, count, ret;
668 u8 conv, tmp;
669 u32 tx_data, data1_reg_val;
670 u32 buf_val, flg_val;
671 struct davinci_spi_platform_data *pdata;
672
673 davinci_spi = spi_master_get_devdata(spi->master);
674 pdata = davinci_spi->pdata;
675
676 davinci_spi->tx = t->tx_buf;
677 davinci_spi->rx = t->rx_buf;
678
679 /* convert len to words based on bits_per_word */
680 conv = davinci_spi->slave[spi->chip_select].bytes_per_word;
681 davinci_spi->count = t->len / conv;
682
683 INIT_COMPLETION(davinci_spi->done);
684
685 ret = davinci_spi_bufs_prep(spi, davinci_spi);
686 if (ret)
687 return ret;
688
689 /* Enable SPI */
690 set_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK);
691
692 iowrite32(0 | (pdata->c2tdelay << SPI_C2TDELAY_SHIFT) |
693 (pdata->t2cdelay << SPI_T2CDELAY_SHIFT),
694 davinci_spi->base + SPIDELAY);
695
696 count = davinci_spi->count;
697 data1_reg_val = pdata->cs_hold << SPIDAT1_CSHOLD_SHIFT;
698 tmp = ~(0x1 << spi->chip_select);
699
700 clear_io_bits(davinci_spi->base + SPIDEF, ~tmp);
701
702 data1_reg_val |= tmp << SPIDAT1_CSNR_SHIFT;
703
704 while ((ioread32(davinci_spi->base + SPIBUF)
705 & SPIBUF_RXEMPTY_MASK) == 0)
706 cpu_relax();
707
708 /* Determine the command to execute READ or WRITE */
709 if (t->tx_buf) {
710 clear_io_bits(davinci_spi->base + SPIINT, SPIINT_MASKALL);
711
712 while (1) {
713 tx_data = davinci_spi->get_tx(davinci_spi);
714
715 data1_reg_val &= ~(0xFFFF);
716 data1_reg_val |= (0xFFFF & tx_data);
717
718 buf_val = ioread32(davinci_spi->base + SPIBUF);
719 if ((buf_val & SPIBUF_TXFULL_MASK) == 0) {
720 iowrite32(data1_reg_val,
721 davinci_spi->base + SPIDAT1);
722
723 count--;
724 }
725 while (ioread32(davinci_spi->base + SPIBUF)
726 & SPIBUF_RXEMPTY_MASK)
727 cpu_relax();
728
729 /* getting the returned byte */
730 if (t->rx_buf) {
731 buf_val = ioread32(davinci_spi->base + SPIBUF);
732 davinci_spi->get_rx(buf_val, davinci_spi);
733 }
734 if (count <= 0)
735 break;
736 }
737 } else {
738 if (pdata->poll_mode) {
739 while (1) {
740 /* keeps the serial clock going */
741 if ((ioread32(davinci_spi->base + SPIBUF)
742 & SPIBUF_TXFULL_MASK) == 0)
743 iowrite32(data1_reg_val,
744 davinci_spi->base + SPIDAT1);
745
746 while (ioread32(davinci_spi->base + SPIBUF) &
747 SPIBUF_RXEMPTY_MASK)
748 cpu_relax();
749
750 flg_val = ioread32(davinci_spi->base + SPIFLG);
751 buf_val = ioread32(davinci_spi->base + SPIBUF);
752
753 davinci_spi->get_rx(buf_val, davinci_spi);
754
755 count--;
756 if (count <= 0)
757 break;
758 }
759 } else { /* Receive in Interrupt mode */
760 int i;
761
762 for (i = 0; i < davinci_spi->count; i++) {
763 set_io_bits(davinci_spi->base + SPIINT,
764 SPIINT_BITERR_INTR
765 | SPIINT_OVRRUN_INTR
766 | SPIINT_RX_INTR);
767
768 iowrite32(data1_reg_val,
769 davinci_spi->base + SPIDAT1);
770
771 while (ioread32(davinci_spi->base + SPIINT) &
772 SPIINT_RX_INTR)
773 cpu_relax();
774 }
775 iowrite32((data1_reg_val & 0x0ffcffff),
776 davinci_spi->base + SPIDAT1);
777 }
778 }
779
780 /*
781 * Check for bit error, desync error,parity error,timeout error and
782 * receive overflow errors
783 */
784 int_status = ioread32(davinci_spi->base + SPIFLG);
785
786 ret = davinci_spi_check_error(davinci_spi, int_status);
787 if (ret != 0)
788 return ret;
789
790 /* SPI Framework maintains the count only in bytes so convert back */
791 davinci_spi->count *= conv;
792
793 return t->len;
794}
795
796#define DAVINCI_DMA_DATA_TYPE_S8 0x01
797#define DAVINCI_DMA_DATA_TYPE_S16 0x02
798#define DAVINCI_DMA_DATA_TYPE_S32 0x04
799
800static int davinci_spi_bufs_dma(struct spi_device *spi, struct spi_transfer *t)
801{
802 struct davinci_spi *davinci_spi;
803 int int_status = 0;
804 int count, temp_count;
805 u8 conv = 1;
806 u8 tmp;
807 u32 data1_reg_val;
808 struct davinci_spi_dma *davinci_spi_dma;
809 int word_len, data_type, ret;
810 unsigned long tx_reg, rx_reg;
811 struct davinci_spi_platform_data *pdata;
812 struct device *sdev;
813
814 davinci_spi = spi_master_get_devdata(spi->master);
815 pdata = davinci_spi->pdata;
816 sdev = davinci_spi->bitbang.master->dev.parent;
817
818 davinci_spi_dma = &davinci_spi->dma_channels[spi->chip_select];
819
820 tx_reg = (unsigned long)davinci_spi->pbase + SPIDAT1;
821 rx_reg = (unsigned long)davinci_spi->pbase + SPIBUF;
822
823 davinci_spi->tx = t->tx_buf;
824 davinci_spi->rx = t->rx_buf;
825
826 /* convert len to words based on bits_per_word */
827 conv = davinci_spi->slave[spi->chip_select].bytes_per_word;
828 davinci_spi->count = t->len / conv;
829
830 INIT_COMPLETION(davinci_spi->done);
831
832 init_completion(&davinci_spi_dma->dma_rx_completion);
833 init_completion(&davinci_spi_dma->dma_tx_completion);
834
835 word_len = conv * 8;
836
837 if (word_len <= 8)
838 data_type = DAVINCI_DMA_DATA_TYPE_S8;
839 else if (word_len <= 16)
840 data_type = DAVINCI_DMA_DATA_TYPE_S16;
841 else if (word_len <= 32)
842 data_type = DAVINCI_DMA_DATA_TYPE_S32;
843 else
844 return -EINVAL;
845
846 ret = davinci_spi_bufs_prep(spi, davinci_spi);
847 if (ret)
848 return ret;
849
850 /* Put delay val if required */
851 iowrite32(0 | (pdata->c2tdelay << SPI_C2TDELAY_SHIFT) |
852 (pdata->t2cdelay << SPI_T2CDELAY_SHIFT),
853 davinci_spi->base + SPIDELAY);
854
855 count = davinci_spi->count; /* the number of elements */
856 data1_reg_val = pdata->cs_hold << SPIDAT1_CSHOLD_SHIFT;
857
858 /* CS default = 0xFF */
859 tmp = ~(0x1 << spi->chip_select);
860
861 clear_io_bits(davinci_spi->base + SPIDEF, ~tmp);
862
863 data1_reg_val |= tmp << SPIDAT1_CSNR_SHIFT;
864
865 /* disable all interrupts for dma transfers */
866 clear_io_bits(davinci_spi->base + SPIINT, SPIINT_MASKALL);
867 /* Disable SPI to write configuration bits in SPIDAT */
868 clear_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK);
869 iowrite32(data1_reg_val, davinci_spi->base + SPIDAT1);
870 /* Enable SPI */
871 set_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_SPIENA_MASK);
872
873 while ((ioread32(davinci_spi->base + SPIBUF)
874 & SPIBUF_RXEMPTY_MASK) == 0)
875 cpu_relax();
876
877
878 if (t->tx_buf) {
879 t->tx_dma = dma_map_single(&spi->dev, (void *)t->tx_buf, count,
880 DMA_TO_DEVICE);
881 if (dma_mapping_error(&spi->dev, t->tx_dma)) {
882 dev_dbg(sdev, "Unable to DMA map a %d bytes"
883 " TX buffer\n", count);
884 return -ENOMEM;
885 }
886 temp_count = count;
887 } else {
888 /* We need TX clocking for RX transaction */
889 t->tx_dma = dma_map_single(&spi->dev,
890 (void *)davinci_spi->tmp_buf, count + 1,
891 DMA_TO_DEVICE);
892 if (dma_mapping_error(&spi->dev, t->tx_dma)) {
893 dev_dbg(sdev, "Unable to DMA map a %d bytes"
894 " TX tmp buffer\n", count);
895 return -ENOMEM;
896 }
897 temp_count = count + 1;
898 }
899
900 edma_set_transfer_params(davinci_spi_dma->dma_tx_channel,
901 data_type, temp_count, 1, 0, ASYNC);
902 edma_set_dest(davinci_spi_dma->dma_tx_channel, tx_reg, INCR, W8BIT);
903 edma_set_src(davinci_spi_dma->dma_tx_channel, t->tx_dma, INCR, W8BIT);
904 edma_set_src_index(davinci_spi_dma->dma_tx_channel, data_type, 0);
905 edma_set_dest_index(davinci_spi_dma->dma_tx_channel, 0, 0);
906
907 if (t->rx_buf) {
908 /* initiate transaction */
909 iowrite32(data1_reg_val, davinci_spi->base + SPIDAT1);
910
911 t->rx_dma = dma_map_single(&spi->dev, (void *)t->rx_buf, count,
912 DMA_FROM_DEVICE);
913 if (dma_mapping_error(&spi->dev, t->rx_dma)) {
914 dev_dbg(sdev, "Couldn't DMA map a %d bytes RX buffer\n",
915 count);
916 if (t->tx_buf != NULL)
917 dma_unmap_single(NULL, t->tx_dma,
918 count, DMA_TO_DEVICE);
919 return -ENOMEM;
920 }
921 edma_set_transfer_params(davinci_spi_dma->dma_rx_channel,
922 data_type, count, 1, 0, ASYNC);
923 edma_set_src(davinci_spi_dma->dma_rx_channel,
924 rx_reg, INCR, W8BIT);
925 edma_set_dest(davinci_spi_dma->dma_rx_channel,
926 t->rx_dma, INCR, W8BIT);
927 edma_set_src_index(davinci_spi_dma->dma_rx_channel, 0, 0);
928 edma_set_dest_index(davinci_spi_dma->dma_rx_channel,
929 data_type, 0);
930 }
931
932 if ((t->tx_buf) || (t->rx_buf))
933 edma_start(davinci_spi_dma->dma_tx_channel);
934
935 if (t->rx_buf)
936 edma_start(davinci_spi_dma->dma_rx_channel);
937
938 if ((t->rx_buf) || (t->tx_buf))
939 davinci_spi_set_dma_req(spi, 1);
940
941 if (t->tx_buf)
942 wait_for_completion_interruptible(
943 &davinci_spi_dma->dma_tx_completion);
944
945 if (t->rx_buf)
946 wait_for_completion_interruptible(
947 &davinci_spi_dma->dma_rx_completion);
948
949 dma_unmap_single(NULL, t->tx_dma, temp_count, DMA_TO_DEVICE);
950
951 if (t->rx_buf)
952 dma_unmap_single(NULL, t->rx_dma, count, DMA_FROM_DEVICE);
953
954 /*
955 * Check for bit error, desync error,parity error,timeout error and
956 * receive overflow errors
957 */
958 int_status = ioread32(davinci_spi->base + SPIFLG);
959
960 ret = davinci_spi_check_error(davinci_spi, int_status);
961 if (ret != 0)
962 return ret;
963
964 /* SPI Framework maintains the count only in bytes so convert back */
965 davinci_spi->count *= conv;
966
967 return t->len;
968}
969
970/**
971 * davinci_spi_irq - IRQ handler for DaVinci SPI
972 * @irq: IRQ number for this SPI Master
973 * @context_data: structure for SPI Master controller davinci_spi
974 */
975static irqreturn_t davinci_spi_irq(s32 irq, void *context_data)
976{
977 struct davinci_spi *davinci_spi = context_data;
978 u32 int_status, rx_data = 0;
979 irqreturn_t ret = IRQ_NONE;
980
981 int_status = ioread32(davinci_spi->base + SPIFLG);
982
983 while ((int_status & SPIFLG_RX_INTR_MASK)) {
984 if (likely(int_status & SPIFLG_RX_INTR_MASK)) {
985 ret = IRQ_HANDLED;
986
987 rx_data = ioread32(davinci_spi->base + SPIBUF);
988 davinci_spi->get_rx(rx_data, davinci_spi);
989
990 /* Disable Receive Interrupt */
991 iowrite32(~(SPIINT_RX_INTR | SPIINT_TX_INTR),
992 davinci_spi->base + SPIINT);
993 } else
994 (void)davinci_spi_check_error(davinci_spi, int_status);
995
996 int_status = ioread32(davinci_spi->base + SPIFLG);
997 }
998
999 return ret;
1000}
1001
1002/**
1003 * davinci_spi_probe - probe function for SPI Master Controller
1004 * @pdev: platform_device structure which contains plateform specific data
1005 */
1006static int davinci_spi_probe(struct platform_device *pdev)
1007{
1008 struct spi_master *master;
1009 struct davinci_spi *davinci_spi;
1010 struct davinci_spi_platform_data *pdata;
1011 struct resource *r, *mem;
1012 resource_size_t dma_rx_chan = SPI_NO_RESOURCE;
1013 resource_size_t dma_tx_chan = SPI_NO_RESOURCE;
1014 resource_size_t dma_eventq = SPI_NO_RESOURCE;
1015 int i = 0, ret = 0;
1016
1017 pdata = pdev->dev.platform_data;
1018 if (pdata == NULL) {
1019 ret = -ENODEV;
1020 goto err;
1021 }
1022
1023 master = spi_alloc_master(&pdev->dev, sizeof(struct davinci_spi));
1024 if (master == NULL) {
1025 ret = -ENOMEM;
1026 goto err;
1027 }
1028
1029 dev_set_drvdata(&pdev->dev, master);
1030
1031 davinci_spi = spi_master_get_devdata(master);
1032 if (davinci_spi == NULL) {
1033 ret = -ENOENT;
1034 goto free_master;
1035 }
1036
1037 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1038 if (r == NULL) {
1039 ret = -ENOENT;
1040 goto free_master;
1041 }
1042
1043 davinci_spi->pbase = r->start;
1044 davinci_spi->region_size = resource_size(r);
1045 davinci_spi->pdata = pdata;
1046
1047 mem = request_mem_region(r->start, davinci_spi->region_size,
1048 pdev->name);
1049 if (mem == NULL) {
1050 ret = -EBUSY;
1051 goto free_master;
1052 }
1053
1054 davinci_spi->base = (struct davinci_spi_reg __iomem *)
1055 ioremap(r->start, davinci_spi->region_size);
1056 if (davinci_spi->base == NULL) {
1057 ret = -ENOMEM;
1058 goto release_region;
1059 }
1060
1061 davinci_spi->irq = platform_get_irq(pdev, 0);
1062 if (davinci_spi->irq <= 0) {
1063 ret = -EINVAL;
1064 goto unmap_io;
1065 }
1066
1067 ret = request_irq(davinci_spi->irq, davinci_spi_irq, IRQF_DISABLED,
1068 dev_name(&pdev->dev), davinci_spi);
1069 if (ret)
1070 goto unmap_io;
1071
1072 /* Allocate tmp_buf for tx_buf */
1073 davinci_spi->tmp_buf = kzalloc(SPI_BUFSIZ, GFP_KERNEL);
1074 if (davinci_spi->tmp_buf == NULL) {
1075 ret = -ENOMEM;
1076 goto irq_free;
1077 }
1078
1079 davinci_spi->bitbang.master = spi_master_get(master);
1080 if (davinci_spi->bitbang.master == NULL) {
1081 ret = -ENODEV;
1082 goto free_tmp_buf;
1083 }
1084
1085 davinci_spi->clk = clk_get(&pdev->dev, NULL);
1086 if (IS_ERR(davinci_spi->clk)) {
1087 ret = -ENODEV;
1088 goto put_master;
1089 }
1090 clk_enable(davinci_spi->clk);
1091
1092
1093 master->bus_num = pdev->id;
1094 master->num_chipselect = pdata->num_chipselect;
1095 master->setup = davinci_spi_setup;
1096 master->cleanup = davinci_spi_cleanup;
1097
1098 davinci_spi->bitbang.chipselect = davinci_spi_chipselect;
1099 davinci_spi->bitbang.setup_transfer = davinci_spi_setup_transfer;
1100
1101 davinci_spi->version = pdata->version;
1102 use_dma = pdata->use_dma;
1103
1104 davinci_spi->bitbang.flags = SPI_NO_CS | SPI_LSB_FIRST | SPI_LOOP;
1105 if (davinci_spi->version == SPI_VERSION_2)
1106 davinci_spi->bitbang.flags |= SPI_READY;
1107
1108 if (use_dma) {
1109 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1110 if (r)
1111 dma_rx_chan = r->start;
1112 r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1113 if (r)
1114 dma_tx_chan = r->start;
1115 r = platform_get_resource(pdev, IORESOURCE_DMA, 2);
1116 if (r)
1117 dma_eventq = r->start;
1118 }
1119
1120 if (!use_dma ||
1121 dma_rx_chan == SPI_NO_RESOURCE ||
1122 dma_tx_chan == SPI_NO_RESOURCE ||
1123 dma_eventq == SPI_NO_RESOURCE) {
1124 davinci_spi->bitbang.txrx_bufs = davinci_spi_bufs_pio;
1125 use_dma = 0;
1126 } else {
1127 davinci_spi->bitbang.txrx_bufs = davinci_spi_bufs_dma;
1128 davinci_spi->dma_channels = kzalloc(master->num_chipselect
1129 * sizeof(struct davinci_spi_dma), GFP_KERNEL);
1130 if (davinci_spi->dma_channels == NULL) {
1131 ret = -ENOMEM;
1132 goto free_clk;
1133 }
1134
1135 for (i = 0; i < master->num_chipselect; i++) {
1136 davinci_spi->dma_channels[i].dma_rx_channel = -1;
1137 davinci_spi->dma_channels[i].dma_rx_sync_dev =
1138 dma_rx_chan;
1139 davinci_spi->dma_channels[i].dma_tx_channel = -1;
1140 davinci_spi->dma_channels[i].dma_tx_sync_dev =
1141 dma_tx_chan;
1142 davinci_spi->dma_channels[i].eventq = dma_eventq;
1143 }
1144 dev_info(&pdev->dev, "DaVinci SPI driver in EDMA mode\n"
1145 "Using RX channel = %d , TX channel = %d and "
1146 "event queue = %d", dma_rx_chan, dma_tx_chan,
1147 dma_eventq);
1148 }
1149
1150 davinci_spi->get_rx = davinci_spi_rx_buf_u8;
1151 davinci_spi->get_tx = davinci_spi_tx_buf_u8;
1152
1153 init_completion(&davinci_spi->done);
1154
1155 /* Reset In/OUT SPI module */
1156 iowrite32(0, davinci_spi->base + SPIGCR0);
1157 udelay(100);
1158 iowrite32(1, davinci_spi->base + SPIGCR0);
1159
1160 /* Clock internal */
1161 if (davinci_spi->pdata->clk_internal)
1162 set_io_bits(davinci_spi->base + SPIGCR1,
1163 SPIGCR1_CLKMOD_MASK);
1164 else
1165 clear_io_bits(davinci_spi->base + SPIGCR1,
1166 SPIGCR1_CLKMOD_MASK);
1167
1168 /* master mode default */
1169 set_io_bits(davinci_spi->base + SPIGCR1, SPIGCR1_MASTER_MASK);
1170
1171 if (davinci_spi->pdata->intr_level)
1172 iowrite32(SPI_INTLVL_1, davinci_spi->base + SPILVL);
1173 else
1174 iowrite32(SPI_INTLVL_0, davinci_spi->base + SPILVL);
1175
1176 ret = spi_bitbang_start(&davinci_spi->bitbang);
1177 if (ret)
1178 goto free_clk;
1179
1180 dev_info(&pdev->dev, "Controller at 0x%p \n", davinci_spi->base);
1181
1182 if (!pdata->poll_mode)
1183 dev_info(&pdev->dev, "Operating in interrupt mode"
1184 " using IRQ %d\n", davinci_spi->irq);
1185
1186 return ret;
1187
1188free_clk:
1189 clk_disable(davinci_spi->clk);
1190 clk_put(davinci_spi->clk);
1191put_master:
1192 spi_master_put(master);
1193free_tmp_buf:
1194 kfree(davinci_spi->tmp_buf);
1195irq_free:
1196 free_irq(davinci_spi->irq, davinci_spi);
1197unmap_io:
1198 iounmap(davinci_spi->base);
1199release_region:
1200 release_mem_region(davinci_spi->pbase, davinci_spi->region_size);
1201free_master:
1202 kfree(master);
1203err:
1204 return ret;
1205}
1206
1207/**
1208 * davinci_spi_remove - remove function for SPI Master Controller
1209 * @pdev: platform_device structure which contains plateform specific data
1210 *
1211 * This function will do the reverse action of davinci_spi_probe function
1212 * It will free the IRQ and SPI controller's memory region.
1213 * It will also call spi_bitbang_stop to destroy the work queue which was
1214 * created by spi_bitbang_start.
1215 */
1216static int __exit davinci_spi_remove(struct platform_device *pdev)
1217{
1218 struct davinci_spi *davinci_spi;
1219 struct spi_master *master;
1220
1221 master = dev_get_drvdata(&pdev->dev);
1222 davinci_spi = spi_master_get_devdata(master);
1223
1224 spi_bitbang_stop(&davinci_spi->bitbang);
1225
1226 clk_disable(davinci_spi->clk);
1227 clk_put(davinci_spi->clk);
1228 spi_master_put(master);
1229 kfree(davinci_spi->tmp_buf);
1230 free_irq(davinci_spi->irq, davinci_spi);
1231 iounmap(davinci_spi->base);
1232 release_mem_region(davinci_spi->pbase, davinci_spi->region_size);
1233
1234 return 0;
1235}
1236
1237static struct platform_driver davinci_spi_driver = {
1238 .driver.name = "spi_davinci",
1239 .remove = __exit_p(davinci_spi_remove),
1240};
1241
1242static int __init davinci_spi_init(void)
1243{
1244 return platform_driver_probe(&davinci_spi_driver, davinci_spi_probe);
1245}
1246module_init(davinci_spi_init);
1247
1248static void __exit davinci_spi_exit(void)
1249{
1250 platform_driver_unregister(&davinci_spi_driver);
1251}
1252module_exit(davinci_spi_exit);
1253
1254MODULE_DESCRIPTION("TI DaVinci SPI Master Controller Driver");
1255MODULE_LICENSE("GPL");
diff --git a/drivers/spi/dw_spi.c b/drivers/spi/dw_spi.c
index 31620fae77be..8ed38f1d6c18 100644
--- a/drivers/spi/dw_spi.c
+++ b/drivers/spi/dw_spi.c
@@ -152,6 +152,7 @@ static void mrst_spi_debugfs_remove(struct dw_spi *dws)
152#else 152#else
153static inline int mrst_spi_debugfs_init(struct dw_spi *dws) 153static inline int mrst_spi_debugfs_init(struct dw_spi *dws)
154{ 154{
155 return 0;
155} 156}
156 157
157static inline void mrst_spi_debugfs_remove(struct dw_spi *dws) 158static inline void mrst_spi_debugfs_remove(struct dw_spi *dws)
@@ -161,14 +162,14 @@ static inline void mrst_spi_debugfs_remove(struct dw_spi *dws)
161 162
162static void wait_till_not_busy(struct dw_spi *dws) 163static void wait_till_not_busy(struct dw_spi *dws)
163{ 164{
164 unsigned long end = jiffies + usecs_to_jiffies(1000); 165 unsigned long end = jiffies + 1 + usecs_to_jiffies(1000);
165 166
166 while (time_before(jiffies, end)) { 167 while (time_before(jiffies, end)) {
167 if (!(dw_readw(dws, sr) & SR_BUSY)) 168 if (!(dw_readw(dws, sr) & SR_BUSY))
168 return; 169 return;
169 } 170 }
170 dev_err(&dws->master->dev, 171 dev_err(&dws->master->dev,
171 "DW SPI: Stutus keeps busy for 1000us after a read/write!\n"); 172 "DW SPI: Status keeps busy for 1000us after a read/write!\n");
172} 173}
173 174
174static void flush(struct dw_spi *dws) 175static void flush(struct dw_spi *dws)
@@ -358,6 +359,8 @@ static void transfer_complete(struct dw_spi *dws)
358static irqreturn_t interrupt_transfer(struct dw_spi *dws) 359static irqreturn_t interrupt_transfer(struct dw_spi *dws)
359{ 360{
360 u16 irq_status, irq_mask = 0x3f; 361 u16 irq_status, irq_mask = 0x3f;
362 u32 int_level = dws->fifo_len / 2;
363 u32 left;
361 364
362 irq_status = dw_readw(dws, isr) & irq_mask; 365 irq_status = dw_readw(dws, isr) & irq_mask;
363 /* Error handling */ 366 /* Error handling */
@@ -369,22 +372,23 @@ static irqreturn_t interrupt_transfer(struct dw_spi *dws)
369 return IRQ_HANDLED; 372 return IRQ_HANDLED;
370 } 373 }
371 374
372 /* INT comes from tx */ 375 if (irq_status & SPI_INT_TXEI) {
373 if (dws->tx && (irq_status & SPI_INT_TXEI)) { 376 spi_mask_intr(dws, SPI_INT_TXEI);
374 while (dws->tx < dws->tx_end) 377
378 left = (dws->tx_end - dws->tx) / dws->n_bytes;
379 left = (left > int_level) ? int_level : left;
380
381 while (left--)
375 dws->write(dws); 382 dws->write(dws);
383 dws->read(dws);
376 384
377 if (dws->tx == dws->tx_end) { 385 /* Re-enable the IRQ if there is still data left to tx */
378 spi_mask_intr(dws, SPI_INT_TXEI); 386 if (dws->tx_end > dws->tx)
387 spi_umask_intr(dws, SPI_INT_TXEI);
388 else
379 transfer_complete(dws); 389 transfer_complete(dws);
380 }
381 } 390 }
382 391
383 /* INT comes from rx */
384 if (dws->rx && (irq_status & SPI_INT_RXFI)) {
385 if (dws->read(dws))
386 transfer_complete(dws);
387 }
388 return IRQ_HANDLED; 392 return IRQ_HANDLED;
389} 393}
390 394
@@ -404,12 +408,9 @@ static irqreturn_t dw_spi_irq(int irq, void *dev_id)
404/* Must be called inside pump_transfers() */ 408/* Must be called inside pump_transfers() */
405static void poll_transfer(struct dw_spi *dws) 409static void poll_transfer(struct dw_spi *dws)
406{ 410{
407 if (dws->tx) { 411 while (dws->write(dws))
408 while (dws->write(dws)) 412 dws->read(dws);
409 dws->read(dws);
410 }
411 413
412 dws->read(dws);
413 transfer_complete(dws); 414 transfer_complete(dws);
414} 415}
415 416
@@ -428,6 +429,7 @@ static void pump_transfers(unsigned long data)
428 u8 bits = 0; 429 u8 bits = 0;
429 u8 imask = 0; 430 u8 imask = 0;
430 u8 cs_change = 0; 431 u8 cs_change = 0;
432 u16 txint_level = 0;
431 u16 clk_div = 0; 433 u16 clk_div = 0;
432 u32 speed = 0; 434 u32 speed = 0;
433 u32 cr0 = 0; 435 u32 cr0 = 0;
@@ -438,6 +440,9 @@ static void pump_transfers(unsigned long data)
438 chip = dws->cur_chip; 440 chip = dws->cur_chip;
439 spi = message->spi; 441 spi = message->spi;
440 442
443 if (unlikely(!chip->clk_div))
444 chip->clk_div = dws->max_freq / chip->speed_hz;
445
441 if (message->state == ERROR_STATE) { 446 if (message->state == ERROR_STATE) {
442 message->status = -EIO; 447 message->status = -EIO;
443 goto early_exit; 448 goto early_exit;
@@ -492,7 +497,7 @@ static void pump_transfers(unsigned long data)
492 497
493 /* clk_div doesn't support odd number */ 498 /* clk_div doesn't support odd number */
494 clk_div = dws->max_freq / speed; 499 clk_div = dws->max_freq / speed;
495 clk_div = (clk_div >> 1) << 1; 500 clk_div = (clk_div + 1) & 0xfffe;
496 501
497 chip->speed_hz = speed; 502 chip->speed_hz = speed;
498 chip->clk_div = clk_div; 503 chip->clk_div = clk_div;
@@ -532,14 +537,35 @@ static void pump_transfers(unsigned long data)
532 } 537 }
533 message->state = RUNNING_STATE; 538 message->state = RUNNING_STATE;
534 539
540 /*
541 * Adjust transfer mode if necessary. Requires platform dependent
542 * chipselect mechanism.
543 */
544 if (dws->cs_control) {
545 if (dws->rx && dws->tx)
546 chip->tmode = 0x00;
547 else if (dws->rx)
548 chip->tmode = 0x02;
549 else
550 chip->tmode = 0x01;
551
552 cr0 &= ~(0x3 << SPI_MODE_OFFSET);
553 cr0 |= (chip->tmode << SPI_TMOD_OFFSET);
554 }
555
535 /* Check if current transfer is a DMA transaction */ 556 /* Check if current transfer is a DMA transaction */
536 dws->dma_mapped = map_dma_buffers(dws); 557 dws->dma_mapped = map_dma_buffers(dws);
537 558
559 /*
560 * Interrupt mode
561 * we only need set the TXEI IRQ, as TX/RX always happen syncronizely
562 */
538 if (!dws->dma_mapped && !chip->poll_mode) { 563 if (!dws->dma_mapped && !chip->poll_mode) {
539 if (dws->rx) 564 int templen = dws->len / dws->n_bytes;
540 imask |= SPI_INT_RXFI; 565 txint_level = dws->fifo_len / 2;
541 if (dws->tx) 566 txint_level = (templen > txint_level) ? txint_level : templen;
542 imask |= SPI_INT_TXEI; 567
568 imask |= SPI_INT_TXEI;
543 dws->transfer_handler = interrupt_transfer; 569 dws->transfer_handler = interrupt_transfer;
544 } 570 }
545 571
@@ -549,21 +575,23 @@ static void pump_transfers(unsigned long data)
549 * 2. clk_div is changed 575 * 2. clk_div is changed
550 * 3. control value changes 576 * 3. control value changes
551 */ 577 */
552 if (dw_readw(dws, ctrl0) != cr0 || cs_change || clk_div) { 578 if (dw_readw(dws, ctrl0) != cr0 || cs_change || clk_div || imask) {
553 spi_enable_chip(dws, 0); 579 spi_enable_chip(dws, 0);
554 580
555 if (dw_readw(dws, ctrl0) != cr0) 581 if (dw_readw(dws, ctrl0) != cr0)
556 dw_writew(dws, ctrl0, cr0); 582 dw_writew(dws, ctrl0, cr0);
557 583
584 spi_set_clk(dws, clk_div ? clk_div : chip->clk_div);
585 spi_chip_sel(dws, spi->chip_select);
586
558 /* Set the interrupt mask, for poll mode just diable all int */ 587 /* Set the interrupt mask, for poll mode just diable all int */
559 spi_mask_intr(dws, 0xff); 588 spi_mask_intr(dws, 0xff);
560 if (!chip->poll_mode) 589 if (imask)
561 spi_umask_intr(dws, imask); 590 spi_umask_intr(dws, imask);
591 if (txint_level)
592 dw_writew(dws, txfltr, txint_level);
562 593
563 spi_set_clk(dws, clk_div ? clk_div : chip->clk_div);
564 spi_chip_sel(dws, spi->chip_select);
565 spi_enable_chip(dws, 1); 594 spi_enable_chip(dws, 1);
566
567 if (cs_change) 595 if (cs_change)
568 dws->prev_chip = chip; 596 dws->prev_chip = chip;
569 } 597 }
@@ -712,11 +740,11 @@ static int dw_spi_setup(struct spi_device *spi)
712 } 740 }
713 chip->bits_per_word = spi->bits_per_word; 741 chip->bits_per_word = spi->bits_per_word;
714 742
743 if (!spi->max_speed_hz) {
744 dev_err(&spi->dev, "No max speed HZ parameter\n");
745 return -EINVAL;
746 }
715 chip->speed_hz = spi->max_speed_hz; 747 chip->speed_hz = spi->max_speed_hz;
716 if (chip->speed_hz)
717 chip->clk_div = 25000000 / chip->speed_hz;
718 else
719 chip->clk_div = 8; /* default value */
720 748
721 chip->tmode = 0; /* Tx & Rx */ 749 chip->tmode = 0; /* Tx & Rx */
722 /* Default SPI mode is SCPOL = 0, SCPH = 0 */ 750 /* Default SPI mode is SCPOL = 0, SCPH = 0 */
@@ -735,7 +763,7 @@ static void dw_spi_cleanup(struct spi_device *spi)
735 kfree(chip); 763 kfree(chip);
736} 764}
737 765
738static int __init init_queue(struct dw_spi *dws) 766static int __devinit init_queue(struct dw_spi *dws)
739{ 767{
740 INIT_LIST_HEAD(&dws->queue); 768 INIT_LIST_HEAD(&dws->queue);
741 spin_lock_init(&dws->lock); 769 spin_lock_init(&dws->lock);
@@ -817,6 +845,22 @@ static void spi_hw_init(struct dw_spi *dws)
817 spi_mask_intr(dws, 0xff); 845 spi_mask_intr(dws, 0xff);
818 spi_enable_chip(dws, 1); 846 spi_enable_chip(dws, 1);
819 flush(dws); 847 flush(dws);
848
849 /*
850 * Try to detect the FIFO depth if not set by interface driver,
851 * the depth could be from 2 to 256 from HW spec
852 */
853 if (!dws->fifo_len) {
854 u32 fifo;
855 for (fifo = 2; fifo <= 257; fifo++) {
856 dw_writew(dws, txfltr, fifo);
857 if (fifo != dw_readw(dws, txfltr))
858 break;
859 }
860
861 dws->fifo_len = (fifo == 257) ? 0 : fifo;
862 dw_writew(dws, txfltr, 0);
863 }
820} 864}
821 865
822int __devinit dw_spi_add_host(struct dw_spi *dws) 866int __devinit dw_spi_add_host(struct dw_spi *dws)
@@ -913,6 +957,7 @@ void __devexit dw_spi_remove_host(struct dw_spi *dws)
913 /* Disconnect from the SPI framework */ 957 /* Disconnect from the SPI framework */
914 spi_unregister_master(dws->master); 958 spi_unregister_master(dws->master);
915} 959}
960EXPORT_SYMBOL(dw_spi_remove_host);
916 961
917int dw_spi_suspend_host(struct dw_spi *dws) 962int dw_spi_suspend_host(struct dw_spi *dws)
918{ 963{
diff --git a/drivers/spi/dw_spi_mmio.c b/drivers/spi/dw_spi_mmio.c
new file mode 100644
index 000000000000..e35b45ac5174
--- /dev/null
+++ b/drivers/spi/dw_spi_mmio.c
@@ -0,0 +1,147 @@
1/*
2 * dw_spi_mmio.c - Memory-mapped interface driver for DW SPI Core
3 *
4 * Copyright (c) 2010, Octasic semiconductor.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 */
10
11#include <linux/clk.h>
12#include <linux/interrupt.h>
13#include <linux/platform_device.h>
14#include <linux/spi/dw_spi.h>
15#include <linux/spi/spi.h>
16
17#define DRIVER_NAME "dw_spi_mmio"
18
19struct dw_spi_mmio {
20 struct dw_spi dws;
21 struct clk *clk;
22};
23
24static int __devinit dw_spi_mmio_probe(struct platform_device *pdev)
25{
26 struct dw_spi_mmio *dwsmmio;
27 struct dw_spi *dws;
28 struct resource *mem, *ioarea;
29 int ret;
30
31 dwsmmio = kzalloc(sizeof(struct dw_spi_mmio), GFP_KERNEL);
32 if (!dwsmmio) {
33 ret = -ENOMEM;
34 goto err_end;
35 }
36
37 dws = &dwsmmio->dws;
38
39 /* Get basic io resource and map it */
40 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
41 if (!mem) {
42 dev_err(&pdev->dev, "no mem resource?\n");
43 ret = -EINVAL;
44 goto err_kfree;
45 }
46
47 ioarea = request_mem_region(mem->start, resource_size(mem),
48 pdev->name);
49 if (!ioarea) {
50 dev_err(&pdev->dev, "SPI region already claimed\n");
51 ret = -EBUSY;
52 goto err_kfree;
53 }
54
55 dws->regs = ioremap_nocache(mem->start, resource_size(mem));
56 if (!dws->regs) {
57 dev_err(&pdev->dev, "SPI region already mapped\n");
58 ret = -ENOMEM;
59 goto err_release_reg;
60 }
61
62 dws->irq = platform_get_irq(pdev, 0);
63 if (dws->irq < 0) {
64 dev_err(&pdev->dev, "no irq resource?\n");
65 ret = dws->irq; /* -ENXIO */
66 goto err_unmap;
67 }
68
69 dwsmmio->clk = clk_get(&pdev->dev, NULL);
70 if (!dwsmmio->clk) {
71 ret = -ENODEV;
72 goto err_irq;
73 }
74 clk_enable(dwsmmio->clk);
75
76 dws->parent_dev = &pdev->dev;
77 dws->bus_num = 0;
78 dws->num_cs = 4;
79 dws->max_freq = clk_get_rate(dwsmmio->clk);
80
81 ret = dw_spi_add_host(dws);
82 if (ret)
83 goto err_clk;
84
85 platform_set_drvdata(pdev, dwsmmio);
86 return 0;
87
88err_clk:
89 clk_disable(dwsmmio->clk);
90 clk_put(dwsmmio->clk);
91 dwsmmio->clk = NULL;
92err_irq:
93 free_irq(dws->irq, dws);
94err_unmap:
95 iounmap(dws->regs);
96err_release_reg:
97 release_mem_region(mem->start, resource_size(mem));
98err_kfree:
99 kfree(dwsmmio);
100err_end:
101 return ret;
102}
103
104static int __devexit dw_spi_mmio_remove(struct platform_device *pdev)
105{
106 struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev);
107 struct resource *mem;
108
109 platform_set_drvdata(pdev, NULL);
110
111 clk_disable(dwsmmio->clk);
112 clk_put(dwsmmio->clk);
113 dwsmmio->clk = NULL;
114
115 free_irq(dwsmmio->dws.irq, &dwsmmio->dws);
116 dw_spi_remove_host(&dwsmmio->dws);
117 iounmap(dwsmmio->dws.regs);
118 kfree(dwsmmio);
119
120 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
121 release_mem_region(mem->start, resource_size(mem));
122 return 0;
123}
124
125static struct platform_driver dw_spi_mmio_driver = {
126 .remove = __devexit_p(dw_spi_mmio_remove),
127 .driver = {
128 .name = DRIVER_NAME,
129 .owner = THIS_MODULE,
130 },
131};
132
133static int __init dw_spi_mmio_init(void)
134{
135 return platform_driver_probe(&dw_spi_mmio_driver, dw_spi_mmio_probe);
136}
137module_init(dw_spi_mmio_init);
138
139static void __exit dw_spi_mmio_exit(void)
140{
141 platform_driver_unregister(&dw_spi_mmio_driver);
142}
143module_exit(dw_spi_mmio_exit);
144
145MODULE_AUTHOR("Jean-Hugues Deschenes <jean-hugues.deschenes@octasic.com>");
146MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
147MODULE_LICENSE("GPL v2");
diff --git a/drivers/spi/dw_spi_pci.c b/drivers/spi/dw_spi_pci.c
index 34ba69161734..1f0735f9cc76 100644
--- a/drivers/spi/dw_spi_pci.c
+++ b/drivers/spi/dw_spi_pci.c
@@ -73,6 +73,7 @@ static int __devinit spi_pci_probe(struct pci_dev *pdev,
73 dws->num_cs = 4; 73 dws->num_cs = 4;
74 dws->max_freq = 25000000; /* for Moorestwon */ 74 dws->max_freq = 25000000; /* for Moorestwon */
75 dws->irq = pdev->irq; 75 dws->irq = pdev->irq;
76 dws->fifo_len = 40; /* FIFO has 40 words buffer */
76 77
77 ret = dw_spi_add_host(dws); 78 ret = dw_spi_add_host(dws);
78 if (ret) 79 if (ret)
@@ -98,6 +99,7 @@ static void __devexit spi_pci_remove(struct pci_dev *pdev)
98 struct dw_spi_pci *dwpci = pci_get_drvdata(pdev); 99 struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
99 100
100 pci_set_drvdata(pdev, NULL); 101 pci_set_drvdata(pdev, NULL);
102 dw_spi_remove_host(&dwpci->dws);
101 iounmap(dwpci->dws.regs); 103 iounmap(dwpci->dws.regs);
102 pci_release_region(pdev, 0); 104 pci_release_region(pdev, 0);
103 kfree(dwpci); 105 kfree(dwpci);
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index f50c81df336a..04747868d6c4 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -503,7 +503,7 @@ static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
503 return mpc52xx_psc_spi_do_remove(&op->dev); 503 return mpc52xx_psc_spi_do_remove(&op->dev);
504} 504}
505 505
506static struct of_device_id mpc52xx_psc_spi_of_match[] = { 506static const struct of_device_id mpc52xx_psc_spi_of_match[] = {
507 { .compatible = "fsl,mpc5200-psc-spi", }, 507 { .compatible = "fsl,mpc5200-psc-spi", },
508 { .compatible = "mpc5200-psc-spi", }, /* old */ 508 { .compatible = "mpc5200-psc-spi", }, /* old */
509 {} 509 {}
diff --git a/drivers/spi/mpc52xx_spi.c b/drivers/spi/mpc52xx_spi.c
index 45bfe6458173..6eab46537a0a 100644
--- a/drivers/spi/mpc52xx_spi.c
+++ b/drivers/spi/mpc52xx_spi.c
@@ -550,7 +550,7 @@ static int __devexit mpc52xx_spi_remove(struct of_device *op)
550 return 0; 550 return 0;
551} 551}
552 552
553static struct of_device_id mpc52xx_spi_match[] __devinitdata = { 553static const struct of_device_id mpc52xx_spi_match[] __devinitconst = {
554 { .compatible = "fsl,mpc5200-spi", }, 554 { .compatible = "fsl,mpc5200-spi", },
555 {} 555 {}
556}; 556};
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 1893f1e96dc4..0ddbbe45e834 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -469,7 +469,7 @@ static int spi_imx_setup(struct spi_device *spi)
469 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); 469 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);
470 int gpio = spi_imx->chipselect[spi->chip_select]; 470 int gpio = spi_imx->chipselect[spi->chip_select];
471 471
472 pr_debug("%s: mode %d, %u bpw, %d hz\n", __func__, 472 dev_dbg(&spi->dev, "%s: mode %d, %u bpw, %d hz\n", __func__,
473 spi->mode, spi->bits_per_word, spi->max_speed_hz); 473 spi->mode, spi->bits_per_word, spi->max_speed_hz);
474 474
475 if (gpio >= 0) 475 if (gpio >= 0)
diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c
index 1fb2a6ea328c..4f0cc9d457e0 100644
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -365,7 +365,7 @@ int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
365 365
366 if ((mpc8xxx_spi->spibrg / hz) > 64) { 366 if ((mpc8xxx_spi->spibrg / hz) > 64) {
367 cs->hw_mode |= SPMODE_DIV16; 367 cs->hw_mode |= SPMODE_DIV16;
368 pm = mpc8xxx_spi->spibrg / (hz * 64); 368 pm = (mpc8xxx_spi->spibrg - 1) / (hz * 64) + 1;
369 369
370 WARN_ONCE(pm > 16, "%s: Requested speed is too low: %d Hz. " 370 WARN_ONCE(pm > 16, "%s: Requested speed is too low: %d Hz. "
371 "Will use %d Hz instead.\n", dev_name(&spi->dev), 371 "Will use %d Hz instead.\n", dev_name(&spi->dev),
@@ -373,7 +373,7 @@ int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
373 if (pm > 16) 373 if (pm > 16)
374 pm = 16; 374 pm = 16;
375 } else 375 } else
376 pm = mpc8xxx_spi->spibrg / (hz * 4); 376 pm = (mpc8xxx_spi->spibrg - 1) / (hz * 4) + 1;
377 if (pm) 377 if (pm)
378 pm--; 378 pm--;
379 379
@@ -1328,7 +1328,7 @@ static struct of_platform_driver of_mpc8xxx_spi_driver = {
1328static int __devinit plat_mpc8xxx_spi_probe(struct platform_device *pdev) 1328static int __devinit plat_mpc8xxx_spi_probe(struct platform_device *pdev)
1329{ 1329{
1330 struct resource *mem; 1330 struct resource *mem;
1331 unsigned int irq; 1331 int irq;
1332 struct spi_master *master; 1332 struct spi_master *master;
1333 1333
1334 if (!pdev->dev.platform_data) 1334 if (!pdev->dev.platform_data)
@@ -1339,7 +1339,7 @@ static int __devinit plat_mpc8xxx_spi_probe(struct platform_device *pdev)
1339 return -EINVAL; 1339 return -EINVAL;
1340 1340
1341 irq = platform_get_irq(pdev, 0); 1341 irq = platform_get_irq(pdev, 0);
1342 if (!irq) 1342 if (irq <= 0)
1343 return -EINVAL; 1343 return -EINVAL;
1344 1344
1345 master = mpc8xxx_spi_probe(&pdev->dev, mem, irq); 1345 master = mpc8xxx_spi_probe(&pdev->dev, mem, irq);
diff --git a/drivers/spi/spi_ppc4xx.c b/drivers/spi/spi_ppc4xx.c
index 140a18d6cf3e..6d8d4026a07a 100644
--- a/drivers/spi/spi_ppc4xx.c
+++ b/drivers/spi/spi_ppc4xx.c
@@ -578,7 +578,7 @@ static int __exit spi_ppc4xx_of_remove(struct of_device *op)
578 return 0; 578 return 0;
579} 579}
580 580
581static struct of_device_id spi_ppc4xx_of_match[] = { 581static const struct of_device_id spi_ppc4xx_of_match[] = {
582 { .compatible = "ibm,ppc4xx-spi", }, 582 { .compatible = "ibm,ppc4xx-spi", },
583 {}, 583 {},
584}; 584};
diff --git a/drivers/spi/spi_s3c64xx.c b/drivers/spi/spi_s3c64xx.c
index 88a456dba967..97365815a729 100644
--- a/drivers/spi/spi_s3c64xx.c
+++ b/drivers/spi/spi_s3c64xx.c
@@ -28,7 +28,7 @@
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29 29
30#include <mach/dma.h> 30#include <mach/dma.h>
31#include <plat/spi.h> 31#include <plat/s3c64xx-spi.h>
32 32
33/* Registers and bit-fields */ 33/* Registers and bit-fields */
34 34
@@ -137,6 +137,7 @@
137/** 137/**
138 * struct s3c64xx_spi_driver_data - Runtime info holder for SPI driver. 138 * struct s3c64xx_spi_driver_data - Runtime info holder for SPI driver.
139 * @clk: Pointer to the spi clock. 139 * @clk: Pointer to the spi clock.
140 * @src_clk: Pointer to the clock used to generate SPI signals.
140 * @master: Pointer to the SPI Protocol master. 141 * @master: Pointer to the SPI Protocol master.
141 * @workqueue: Work queue for the SPI xfer requests. 142 * @workqueue: Work queue for the SPI xfer requests.
142 * @cntrlr_info: Platform specific data for the controller this driver manages. 143 * @cntrlr_info: Platform specific data for the controller this driver manages.
@@ -157,10 +158,11 @@
157struct s3c64xx_spi_driver_data { 158struct s3c64xx_spi_driver_data {
158 void __iomem *regs; 159 void __iomem *regs;
159 struct clk *clk; 160 struct clk *clk;
161 struct clk *src_clk;
160 struct platform_device *pdev; 162 struct platform_device *pdev;
161 struct spi_master *master; 163 struct spi_master *master;
162 struct workqueue_struct *workqueue; 164 struct workqueue_struct *workqueue;
163 struct s3c64xx_spi_cntrlr_info *cntrlr_info; 165 struct s3c64xx_spi_info *cntrlr_info;
164 struct spi_device *tgl_spi; 166 struct spi_device *tgl_spi;
165 struct work_struct work; 167 struct work_struct work;
166 struct list_head queue; 168 struct list_head queue;
@@ -180,7 +182,7 @@ static struct s3c2410_dma_client s3c64xx_spi_dma_client = {
180 182
181static void flush_fifo(struct s3c64xx_spi_driver_data *sdd) 183static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
182{ 184{
183 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info; 185 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
184 void __iomem *regs = sdd->regs; 186 void __iomem *regs = sdd->regs;
185 unsigned long loops; 187 unsigned long loops;
186 u32 val; 188 u32 val;
@@ -225,7 +227,7 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
225 struct spi_device *spi, 227 struct spi_device *spi,
226 struct spi_transfer *xfer, int dma_mode) 228 struct spi_transfer *xfer, int dma_mode)
227{ 229{
228 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info; 230 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
229 void __iomem *regs = sdd->regs; 231 void __iomem *regs = sdd->regs;
230 u32 modecfg, chcfg; 232 u32 modecfg, chcfg;
231 233
@@ -298,19 +300,20 @@ static inline void enable_cs(struct s3c64xx_spi_driver_data *sdd,
298 if (sdd->tgl_spi != spi) { /* if last mssg on diff device */ 300 if (sdd->tgl_spi != spi) { /* if last mssg on diff device */
299 /* Deselect the last toggled device */ 301 /* Deselect the last toggled device */
300 cs = sdd->tgl_spi->controller_data; 302 cs = sdd->tgl_spi->controller_data;
301 cs->set_level(spi->mode & SPI_CS_HIGH ? 0 : 1); 303 cs->set_level(cs->line,
304 spi->mode & SPI_CS_HIGH ? 0 : 1);
302 } 305 }
303 sdd->tgl_spi = NULL; 306 sdd->tgl_spi = NULL;
304 } 307 }
305 308
306 cs = spi->controller_data; 309 cs = spi->controller_data;
307 cs->set_level(spi->mode & SPI_CS_HIGH ? 1 : 0); 310 cs->set_level(cs->line, spi->mode & SPI_CS_HIGH ? 1 : 0);
308} 311}
309 312
310static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd, 313static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd,
311 struct spi_transfer *xfer, int dma_mode) 314 struct spi_transfer *xfer, int dma_mode)
312{ 315{
313 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info; 316 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
314 void __iomem *regs = sdd->regs; 317 void __iomem *regs = sdd->regs;
315 unsigned long val; 318 unsigned long val;
316 int ms; 319 int ms;
@@ -384,12 +387,11 @@ static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd,
384 if (sdd->tgl_spi == spi) 387 if (sdd->tgl_spi == spi)
385 sdd->tgl_spi = NULL; 388 sdd->tgl_spi = NULL;
386 389
387 cs->set_level(spi->mode & SPI_CS_HIGH ? 0 : 1); 390 cs->set_level(cs->line, spi->mode & SPI_CS_HIGH ? 0 : 1);
388} 391}
389 392
390static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd) 393static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
391{ 394{
392 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info;
393 void __iomem *regs = sdd->regs; 395 void __iomem *regs = sdd->regs;
394 u32 val; 396 u32 val;
395 397
@@ -435,7 +437,7 @@ static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
435 /* Configure Clock */ 437 /* Configure Clock */
436 val = readl(regs + S3C64XX_SPI_CLK_CFG); 438 val = readl(regs + S3C64XX_SPI_CLK_CFG);
437 val &= ~S3C64XX_SPI_PSR_MASK; 439 val &= ~S3C64XX_SPI_PSR_MASK;
438 val |= ((clk_get_rate(sci->src_clk) / sdd->cur_speed / 2 - 1) 440 val |= ((clk_get_rate(sdd->src_clk) / sdd->cur_speed / 2 - 1)
439 & S3C64XX_SPI_PSR_MASK); 441 & S3C64XX_SPI_PSR_MASK);
440 writel(val, regs + S3C64XX_SPI_CLK_CFG); 442 writel(val, regs + S3C64XX_SPI_CLK_CFG);
441 443
@@ -558,7 +560,7 @@ static void s3c64xx_spi_unmap_mssg(struct s3c64xx_spi_driver_data *sdd,
558static void handle_msg(struct s3c64xx_spi_driver_data *sdd, 560static void handle_msg(struct s3c64xx_spi_driver_data *sdd,
559 struct spi_message *msg) 561 struct spi_message *msg)
560{ 562{
561 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info; 563 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
562 struct spi_device *spi = msg->spi; 564 struct spi_device *spi = msg->spi;
563 struct s3c64xx_spi_csinfo *cs = spi->controller_data; 565 struct s3c64xx_spi_csinfo *cs = spi->controller_data;
564 struct spi_transfer *xfer; 566 struct spi_transfer *xfer;
@@ -632,8 +634,8 @@ static void handle_msg(struct s3c64xx_spi_driver_data *sdd,
632 S3C64XX_SPI_DEACT(sdd); 634 S3C64XX_SPI_DEACT(sdd);
633 635
634 if (status) { 636 if (status) {
635 dev_err(&spi->dev, "I/O Error: \ 637 dev_err(&spi->dev, "I/O Error: "
636 rx-%d tx-%d res:rx-%c tx-%c len-%d\n", 638 "rx-%d tx-%d res:rx-%c tx-%c len-%d\n",
637 xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0, 639 xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0,
638 (sdd->state & RXBUSY) ? 'f' : 'p', 640 (sdd->state & RXBUSY) ? 'f' : 'p',
639 (sdd->state & TXBUSY) ? 'f' : 'p', 641 (sdd->state & TXBUSY) ? 'f' : 'p',
@@ -786,7 +788,7 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
786{ 788{
787 struct s3c64xx_spi_csinfo *cs = spi->controller_data; 789 struct s3c64xx_spi_csinfo *cs = spi->controller_data;
788 struct s3c64xx_spi_driver_data *sdd; 790 struct s3c64xx_spi_driver_data *sdd;
789 struct s3c64xx_spi_cntrlr_info *sci; 791 struct s3c64xx_spi_info *sci;
790 struct spi_message *msg; 792 struct spi_message *msg;
791 u32 psr, speed; 793 u32 psr, speed;
792 unsigned long flags; 794 unsigned long flags;
@@ -831,17 +833,17 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
831 } 833 }
832 834
833 /* Check if we can provide the requested rate */ 835 /* Check if we can provide the requested rate */
834 speed = clk_get_rate(sci->src_clk) / 2 / (0 + 1); /* Max possible */ 836 speed = clk_get_rate(sdd->src_clk) / 2 / (0 + 1); /* Max possible */
835 837
836 if (spi->max_speed_hz > speed) 838 if (spi->max_speed_hz > speed)
837 spi->max_speed_hz = speed; 839 spi->max_speed_hz = speed;
838 840
839 psr = clk_get_rate(sci->src_clk) / 2 / spi->max_speed_hz - 1; 841 psr = clk_get_rate(sdd->src_clk) / 2 / spi->max_speed_hz - 1;
840 psr &= S3C64XX_SPI_PSR_MASK; 842 psr &= S3C64XX_SPI_PSR_MASK;
841 if (psr == S3C64XX_SPI_PSR_MASK) 843 if (psr == S3C64XX_SPI_PSR_MASK)
842 psr--; 844 psr--;
843 845
844 speed = clk_get_rate(sci->src_clk) / 2 / (psr + 1); 846 speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1);
845 if (spi->max_speed_hz < speed) { 847 if (spi->max_speed_hz < speed) {
846 if (psr+1 < S3C64XX_SPI_PSR_MASK) { 848 if (psr+1 < S3C64XX_SPI_PSR_MASK) {
847 psr++; 849 psr++;
@@ -851,7 +853,7 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
851 } 853 }
852 } 854 }
853 855
854 speed = clk_get_rate(sci->src_clk) / 2 / (psr + 1); 856 speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1);
855 if (spi->max_speed_hz >= speed) 857 if (spi->max_speed_hz >= speed)
856 spi->max_speed_hz = speed; 858 spi->max_speed_hz = speed;
857 else 859 else
@@ -867,7 +869,7 @@ setup_exit:
867 869
868static void s3c64xx_spi_hwinit(struct s3c64xx_spi_driver_data *sdd, int channel) 870static void s3c64xx_spi_hwinit(struct s3c64xx_spi_driver_data *sdd, int channel)
869{ 871{
870 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info; 872 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
871 void __iomem *regs = sdd->regs; 873 void __iomem *regs = sdd->regs;
872 unsigned int val; 874 unsigned int val;
873 875
@@ -902,7 +904,7 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev)
902{ 904{
903 struct resource *mem_res, *dmatx_res, *dmarx_res; 905 struct resource *mem_res, *dmatx_res, *dmarx_res;
904 struct s3c64xx_spi_driver_data *sdd; 906 struct s3c64xx_spi_driver_data *sdd;
905 struct s3c64xx_spi_cntrlr_info *sci; 907 struct s3c64xx_spi_info *sci;
906 struct spi_master *master; 908 struct spi_master *master;
907 int ret; 909 int ret;
908 910
@@ -1000,18 +1002,15 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev)
1000 goto err4; 1002 goto err4;
1001 } 1003 }
1002 1004
1003 if (sci->src_clk_nr == S3C64XX_SPI_SRCCLK_PCLK) 1005 sdd->src_clk = clk_get(&pdev->dev, sci->src_clk_name);
1004 sci->src_clk = sdd->clk; 1006 if (IS_ERR(sdd->src_clk)) {
1005 else
1006 sci->src_clk = clk_get(&pdev->dev, sci->src_clk_name);
1007 if (IS_ERR(sci->src_clk)) {
1008 dev_err(&pdev->dev, 1007 dev_err(&pdev->dev,
1009 "Unable to acquire clock '%s'\n", sci->src_clk_name); 1008 "Unable to acquire clock '%s'\n", sci->src_clk_name);
1010 ret = PTR_ERR(sci->src_clk); 1009 ret = PTR_ERR(sdd->src_clk);
1011 goto err5; 1010 goto err5;
1012 } 1011 }
1013 1012
1014 if (sci->src_clk != sdd->clk && clk_enable(sci->src_clk)) { 1013 if (clk_enable(sdd->src_clk)) {
1015 dev_err(&pdev->dev, "Couldn't enable clock '%s'\n", 1014 dev_err(&pdev->dev, "Couldn't enable clock '%s'\n",
1016 sci->src_clk_name); 1015 sci->src_clk_name);
1017 ret = -EBUSY; 1016 ret = -EBUSY;
@@ -1040,11 +1039,10 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev)
1040 goto err8; 1039 goto err8;
1041 } 1040 }
1042 1041
1043 dev_dbg(&pdev->dev, "Samsung SoC SPI Driver loaded for Bus SPI-%d \ 1042 dev_dbg(&pdev->dev, "Samsung SoC SPI Driver loaded for Bus SPI-%d "
1044 with %d Slaves attached\n", 1043 "with %d Slaves attached\n",
1045 pdev->id, master->num_chipselect); 1044 pdev->id, master->num_chipselect);
1046 dev_dbg(&pdev->dev, "\tIOmem=[0x%x-0x%x]\ 1045 dev_dbg(&pdev->dev, "\tIOmem=[0x%x-0x%x]\tDMA=[Rx-%d, Tx-%d]\n",
1047 \tDMA=[Rx-%d, Tx-%d]\n",
1048 mem_res->end, mem_res->start, 1046 mem_res->end, mem_res->start,
1049 sdd->rx_dmach, sdd->tx_dmach); 1047 sdd->rx_dmach, sdd->tx_dmach);
1050 1048
@@ -1053,11 +1051,9 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev)
1053err8: 1051err8:
1054 destroy_workqueue(sdd->workqueue); 1052 destroy_workqueue(sdd->workqueue);
1055err7: 1053err7:
1056 if (sci->src_clk != sdd->clk) 1054 clk_disable(sdd->src_clk);
1057 clk_disable(sci->src_clk);
1058err6: 1055err6:
1059 if (sci->src_clk != sdd->clk) 1056 clk_put(sdd->src_clk);
1060 clk_put(sci->src_clk);
1061err5: 1057err5:
1062 clk_disable(sdd->clk); 1058 clk_disable(sdd->clk);
1063err4: 1059err4:
@@ -1078,7 +1074,6 @@ static int s3c64xx_spi_remove(struct platform_device *pdev)
1078{ 1074{
1079 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); 1075 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev));
1080 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1076 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1081 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info;
1082 struct resource *mem_res; 1077 struct resource *mem_res;
1083 unsigned long flags; 1078 unsigned long flags;
1084 1079
@@ -1093,11 +1088,8 @@ static int s3c64xx_spi_remove(struct platform_device *pdev)
1093 1088
1094 destroy_workqueue(sdd->workqueue); 1089 destroy_workqueue(sdd->workqueue);
1095 1090
1096 if (sci->src_clk != sdd->clk) 1091 clk_disable(sdd->src_clk);
1097 clk_disable(sci->src_clk); 1092 clk_put(sdd->src_clk);
1098
1099 if (sci->src_clk != sdd->clk)
1100 clk_put(sci->src_clk);
1101 1093
1102 clk_disable(sdd->clk); 1094 clk_disable(sdd->clk);
1103 clk_put(sdd->clk); 1095 clk_put(sdd->clk);
@@ -1105,7 +1097,8 @@ static int s3c64xx_spi_remove(struct platform_device *pdev)
1105 iounmap((void *) sdd->regs); 1097 iounmap((void *) sdd->regs);
1106 1098
1107 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1099 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1108 release_mem_region(mem_res->start, resource_size(mem_res)); 1100 if (mem_res != NULL)
1101 release_mem_region(mem_res->start, resource_size(mem_res));
1109 1102
1110 platform_set_drvdata(pdev, NULL); 1103 platform_set_drvdata(pdev, NULL);
1111 spi_master_put(master); 1104 spi_master_put(master);
@@ -1118,8 +1111,6 @@ static int s3c64xx_spi_suspend(struct platform_device *pdev, pm_message_t state)
1118{ 1111{
1119 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); 1112 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev));
1120 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1113 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1121 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info;
1122 struct s3c64xx_spi_csinfo *cs;
1123 unsigned long flags; 1114 unsigned long flags;
1124 1115
1125 spin_lock_irqsave(&sdd->lock, flags); 1116 spin_lock_irqsave(&sdd->lock, flags);
@@ -1130,9 +1121,7 @@ static int s3c64xx_spi_suspend(struct platform_device *pdev, pm_message_t state)
1130 msleep(10); 1121 msleep(10);
1131 1122
1132 /* Disable the clock */ 1123 /* Disable the clock */
1133 if (sci->src_clk != sdd->clk) 1124 clk_disable(sdd->src_clk);
1134 clk_disable(sci->src_clk);
1135
1136 clk_disable(sdd->clk); 1125 clk_disable(sdd->clk);
1137 1126
1138 sdd->cur_speed = 0; /* Output Clock is stopped */ 1127 sdd->cur_speed = 0; /* Output Clock is stopped */
@@ -1144,15 +1133,13 @@ static int s3c64xx_spi_resume(struct platform_device *pdev)
1144{ 1133{
1145 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); 1134 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev));
1146 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 1135 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master);
1147 struct s3c64xx_spi_cntrlr_info *sci = sdd->cntrlr_info; 1136 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
1148 unsigned long flags; 1137 unsigned long flags;
1149 1138
1150 sci->cfg_gpio(pdev); 1139 sci->cfg_gpio(pdev);
1151 1140
1152 /* Enable the clock */ 1141 /* Enable the clock */
1153 if (sci->src_clk != sdd->clk) 1142 clk_enable(sdd->src_clk);
1154 clk_enable(sci->src_clk);
1155
1156 clk_enable(sdd->clk); 1143 clk_enable(sdd->clk);
1157 1144
1158 s3c64xx_spi_hwinit(sdd, pdev->id); 1145 s3c64xx_spi_hwinit(sdd, pdev->id);
diff --git a/drivers/spi/spi_sh_msiof.c b/drivers/spi/spi_sh_msiof.c
index 30973ec16a93..d93b66743ba7 100644
--- a/drivers/spi/spi_sh_msiof.c
+++ b/drivers/spi/spi_sh_msiof.c
@@ -20,12 +20,12 @@
20#include <linux/bitmap.h> 20#include <linux/bitmap.h>
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/err.h>
23 24
24#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
25#include <linux/spi/spi_bitbang.h> 26#include <linux/spi/spi_bitbang.h>
26#include <linux/spi/sh_msiof.h> 27#include <linux/spi/sh_msiof.h>
27 28
28#include <asm/spi.h>
29#include <asm/unaligned.h> 29#include <asm/unaligned.h>
30 30
31struct sh_msiof_spi_priv { 31struct sh_msiof_spi_priv {
diff --git a/drivers/spi/spi_stmp.c b/drivers/spi/spi_stmp.c
index 2552bb364005..fadff76eb7e0 100644
--- a/drivers/spi/spi_stmp.c
+++ b/drivers/spi/spi_stmp.c
@@ -76,7 +76,7 @@ struct stmp_spi {
76 break; \ 76 break; \
77 } \ 77 } \
78 cpu_relax(); \ 78 cpu_relax(); \
79 } while (time_before(end_jiffies, jiffies)); \ 79 } while (time_before(jiffies, end_jiffies)); \
80 succeeded; \ 80 succeeded; \
81 }) 81 })
82 82
diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
index 9f386379c169..1b47363cb73f 100644
--- a/drivers/spi/xilinx_spi.c
+++ b/drivers/spi/xilinx_spi.c
@@ -93,6 +93,26 @@ struct xilinx_spi {
93 void (*rx_fn) (struct xilinx_spi *); 93 void (*rx_fn) (struct xilinx_spi *);
94}; 94};
95 95
96static void xspi_write32(u32 val, void __iomem *addr)
97{
98 iowrite32(val, addr);
99}
100
101static unsigned int xspi_read32(void __iomem *addr)
102{
103 return ioread32(addr);
104}
105
106static void xspi_write32_be(u32 val, void __iomem *addr)
107{
108 iowrite32be(val, addr);
109}
110
111static unsigned int xspi_read32_be(void __iomem *addr)
112{
113 return ioread32be(addr);
114}
115
96static void xspi_tx8(struct xilinx_spi *xspi) 116static void xspi_tx8(struct xilinx_spi *xspi)
97{ 117{
98 xspi->write_fn(*xspi->tx_ptr, xspi->regs + XSPI_TXD_OFFSET); 118 xspi->write_fn(*xspi->tx_ptr, xspi->regs + XSPI_TXD_OFFSET);
@@ -374,11 +394,11 @@ struct spi_master *xilinx_spi_init(struct device *dev, struct resource *mem,
374 xspi->mem = *mem; 394 xspi->mem = *mem;
375 xspi->irq = irq; 395 xspi->irq = irq;
376 if (pdata->little_endian) { 396 if (pdata->little_endian) {
377 xspi->read_fn = ioread32; 397 xspi->read_fn = xspi_read32;
378 xspi->write_fn = iowrite32; 398 xspi->write_fn = xspi_write32;
379 } else { 399 } else {
380 xspi->read_fn = ioread32be; 400 xspi->read_fn = xspi_read32_be;
381 xspi->write_fn = iowrite32be; 401 xspi->write_fn = xspi_write32_be;
382 } 402 }
383 xspi->bits_per_word = pdata->bits_per_word; 403 xspi->bits_per_word = pdata->bits_per_word;
384 if (xspi->bits_per_word == 8) { 404 if (xspi->bits_per_word == 8) {
diff --git a/drivers/spi/xilinx_spi_of.c b/drivers/spi/xilinx_spi_of.c
index 71dc3adc0495..ed34a8d419c7 100644
--- a/drivers/spi/xilinx_spi_of.c
+++ b/drivers/spi/xilinx_spi_of.c
@@ -99,7 +99,7 @@ static int __exit xilinx_spi_of_remove(struct of_device *op)
99 return xilinx_spi_remove(op); 99 return xilinx_spi_remove(op);
100} 100}
101 101
102static struct of_device_id xilinx_spi_of_match[] = { 102static const struct of_device_id xilinx_spi_of_match[] = {
103 { .compatible = "xlnx,xps-spi-2.00.a", }, 103 { .compatible = "xlnx,xps-spi-2.00.a", },
104 { .compatible = "xlnx,xps-spi-2.00.b", }, 104 { .compatible = "xlnx,xps-spi-2.00.b", },
105 {} 105 {}
diff --git a/drivers/staging/go7007/s2250-board.c b/drivers/staging/go7007/s2250-board.c
index 8cf7f2750b3f..c324f6ea002b 100644
--- a/drivers/staging/go7007/s2250-board.c
+++ b/drivers/staging/go7007/s2250-board.c
@@ -159,7 +159,7 @@ static int write_reg(struct i2c_client *client, u8 reg, u8 value)
159 struct go7007 *go = i2c_get_adapdata(client->adapter); 159 struct go7007 *go = i2c_get_adapdata(client->adapter);
160 struct go7007_usb *usb; 160 struct go7007_usb *usb;
161 int rc; 161 int rc;
162 int dev_addr = client->addr; 162 int dev_addr = client->addr << 1; /* firmware wants 8-bit address */
163 u8 *buf; 163 u8 *buf;
164 164
165 if (go == NULL) 165 if (go == NULL)
diff --git a/drivers/staging/octeon/Makefile b/drivers/staging/octeon/Makefile
index c0a583cc2227..87447c102fa0 100644
--- a/drivers/staging/octeon/Makefile
+++ b/drivers/staging/octeon/Makefile
@@ -14,7 +14,6 @@ obj-${CONFIG_OCTEON_ETHERNET} := octeon-ethernet.o
14octeon-ethernet-objs := ethernet.o 14octeon-ethernet-objs := ethernet.o
15octeon-ethernet-objs += ethernet-mdio.o 15octeon-ethernet-objs += ethernet-mdio.o
16octeon-ethernet-objs += ethernet-mem.o 16octeon-ethernet-objs += ethernet-mem.o
17octeon-ethernet-objs += ethernet-proc.o
18octeon-ethernet-objs += ethernet-rgmii.o 17octeon-ethernet-objs += ethernet-rgmii.o
19octeon-ethernet-objs += ethernet-rx.o 18octeon-ethernet-objs += ethernet-rx.o
20octeon-ethernet-objs += ethernet-sgmii.o 19octeon-ethernet-objs += ethernet-sgmii.o
diff --git a/drivers/staging/octeon/ethernet-defines.h b/drivers/staging/octeon/ethernet-defines.h
index f13131b03c33..6a2cd50a17df 100644
--- a/drivers/staging/octeon/ethernet-defines.h
+++ b/drivers/staging/octeon/ethernet-defines.h
@@ -41,17 +41,10 @@
41 * Tells the driver to populate the packet buffers with kernel skbuffs. 41 * Tells the driver to populate the packet buffers with kernel skbuffs.
42 * This allows the driver to receive packets without copying them. It also 42 * This allows the driver to receive packets without copying them. It also
43 * means that 32bit userspace can't access the packet buffers. 43 * means that 32bit userspace can't access the packet buffers.
44 * USE_32BIT_SHARED
45 * This define tells the driver to allocate memory for buffers from the
46 * 32bit sahred region instead of the kernel memory space.
47 * USE_HW_TCPUDP_CHECKSUM 44 * USE_HW_TCPUDP_CHECKSUM
48 * Controls if the Octeon TCP/UDP checksum engine is used for packet 45 * Controls if the Octeon TCP/UDP checksum engine is used for packet
49 * output. If this is zero, the kernel will perform the checksum in 46 * output. If this is zero, the kernel will perform the checksum in
50 * software. 47 * software.
51 * USE_MULTICORE_RECEIVE
52 * Process receive interrupts on multiple cores. This spreads the network
53 * load across the first 8 processors. If ths is zero, only one core
54 * processes incomming packets.
55 * USE_ASYNC_IOBDMA 48 * USE_ASYNC_IOBDMA
56 * Use asynchronous IO access to hardware. This uses Octeon's asynchronous 49 * Use asynchronous IO access to hardware. This uses Octeon's asynchronous
57 * IOBDMAs to issue IO accesses without stalling. Set this to zero 50 * IOBDMAs to issue IO accesses without stalling. Set this to zero
@@ -75,29 +68,15 @@
75#define CONFIG_CAVIUM_RESERVE32 0 68#define CONFIG_CAVIUM_RESERVE32 0
76#endif 69#endif
77 70
78#if CONFIG_CAVIUM_RESERVE32
79#define USE_32BIT_SHARED 1
80#define USE_SKBUFFS_IN_HW 0
81#define REUSE_SKBUFFS_WITHOUT_FREE 0
82#else
83#define USE_32BIT_SHARED 0
84#define USE_SKBUFFS_IN_HW 1 71#define USE_SKBUFFS_IN_HW 1
85#ifdef CONFIG_NETFILTER 72#ifdef CONFIG_NETFILTER
86#define REUSE_SKBUFFS_WITHOUT_FREE 0 73#define REUSE_SKBUFFS_WITHOUT_FREE 0
87#else 74#else
88#define REUSE_SKBUFFS_WITHOUT_FREE 1 75#define REUSE_SKBUFFS_WITHOUT_FREE 1
89#endif 76#endif
90#endif
91
92/* Max interrupts per second per core */
93#define INTERRUPT_LIMIT 10000
94 77
95/* Don't limit the number of interrupts */
96/*#define INTERRUPT_LIMIT 0 */
97#define USE_HW_TCPUDP_CHECKSUM 1 78#define USE_HW_TCPUDP_CHECKSUM 1
98 79
99#define USE_MULTICORE_RECEIVE 1
100
101/* Enable Random Early Dropping under load */ 80/* Enable Random Early Dropping under load */
102#define USE_RED 1 81#define USE_RED 1
103#define USE_ASYNC_IOBDMA (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0) 82#define USE_ASYNC_IOBDMA (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0)
@@ -115,21 +94,12 @@
115/* Use this to not have FPA frees control L2 */ 94/* Use this to not have FPA frees control L2 */
116/*#define DONT_WRITEBACK(x) 0 */ 95/*#define DONT_WRITEBACK(x) 0 */
117 96
118/* Maximum number of packets to process per interrupt. */
119#define MAX_RX_PACKETS 120
120/* Maximum number of SKBs to try to free per xmit packet. */ 97/* Maximum number of SKBs to try to free per xmit packet. */
121#define MAX_SKB_TO_FREE 10
122#define MAX_OUT_QUEUE_DEPTH 1000 98#define MAX_OUT_QUEUE_DEPTH 1000
123 99
124#ifndef CONFIG_SMP 100#define FAU_TOTAL_TX_TO_CLEAN (CVMX_FAU_REG_END - sizeof(uint32_t))
125#undef USE_MULTICORE_RECEIVE 101#define FAU_NUM_PACKET_BUFFERS_TO_FREE (FAU_TOTAL_TX_TO_CLEAN - sizeof(uint32_t))
126#define USE_MULTICORE_RECEIVE 0
127#endif
128
129#define IP_PROTOCOL_TCP 6
130#define IP_PROTOCOL_UDP 0x11
131 102
132#define FAU_NUM_PACKET_BUFFERS_TO_FREE (CVMX_FAU_REG_END - sizeof(uint32_t))
133#define TOTAL_NUMBER_OF_PORTS (CVMX_PIP_NUM_INPUT_PORTS+1) 103#define TOTAL_NUMBER_OF_PORTS (CVMX_PIP_NUM_INPUT_PORTS+1)
134 104
135 105
diff --git a/drivers/staging/octeon/ethernet-mdio.c b/drivers/staging/octeon/ethernet-mdio.c
index 05a5cc0f43ed..7e0be8d00dc3 100644
--- a/drivers/staging/octeon/ethernet-mdio.c
+++ b/drivers/staging/octeon/ethernet-mdio.c
@@ -96,11 +96,11 @@ const struct ethtool_ops cvm_oct_ethtool_ops = {
96}; 96};
97 97
98/** 98/**
99 * IOCTL support for PHY control 99 * cvm_oct_ioctl - IOCTL support for PHY control
100 *
101 * @dev: Device to change 100 * @dev: Device to change
102 * @rq: the request 101 * @rq: the request
103 * @cmd: the command 102 * @cmd: the command
103 *
104 * Returns Zero on success 104 * Returns Zero on success
105 */ 105 */
106int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 106int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
@@ -153,7 +153,7 @@ static void cvm_oct_adjust_link(struct net_device *dev)
153 153
154 154
155/** 155/**
156 * Setup the PHY 156 * cvm_oct_phy_setup_device - setup the PHY
157 * 157 *
158 * @dev: Device to setup 158 * @dev: Device to setup
159 * 159 *
diff --git a/drivers/staging/octeon/ethernet-mdio.h b/drivers/staging/octeon/ethernet-mdio.h
index 55d0614a7cd9..a417d4fce12c 100644
--- a/drivers/staging/octeon/ethernet-mdio.h
+++ b/drivers/staging/octeon/ethernet-mdio.h
@@ -32,7 +32,6 @@
32#include <linux/ip.h> 32#include <linux/ip.h>
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/ethtool.h> 34#include <linux/ethtool.h>
35#include <linux/mii.h>
36#include <linux/seq_file.h> 35#include <linux/seq_file.h>
37#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
38#include <net/dst.h> 37#include <net/dst.h>
diff --git a/drivers/staging/octeon/ethernet-mem.c b/drivers/staging/octeon/ethernet-mem.c
index b595903e2af1..00cc91df6b46 100644
--- a/drivers/staging/octeon/ethernet-mem.c
+++ b/drivers/staging/octeon/ethernet-mem.c
@@ -4,7 +4,7 @@
4 * Contact: support@caviumnetworks.com 4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK 5 * This file is part of the OCTEON SDK
6 * 6 *
7 * Copyright (c) 2003-2007 Cavium Networks 7 * Copyright (c) 2003-2010 Cavium Networks
8 * 8 *
9 * This file is free software; you can redistribute it and/or modify 9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as 10 * it under the terms of the GNU General Public License, Version 2, as
@@ -26,8 +26,6 @@
26**********************************************************************/ 26**********************************************************************/
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/netdevice.h> 28#include <linux/netdevice.h>
29#include <linux/mii.h>
30#include <net/dst.h>
31 29
32#include <asm/octeon/octeon.h> 30#include <asm/octeon/octeon.h>
33 31
@@ -36,18 +34,19 @@
36#include "cvmx-fpa.h" 34#include "cvmx-fpa.h"
37 35
38/** 36/**
39 * Fill the supplied hardware pool with skbuffs 37 * cvm_oct_fill_hw_skbuff - fill the supplied hardware pool with skbuffs
40 *
41 * @pool: Pool to allocate an skbuff for 38 * @pool: Pool to allocate an skbuff for
42 * @size: Size of the buffer needed for the pool 39 * @size: Size of the buffer needed for the pool
43 * @elements: Number of buffers to allocate 40 * @elements: Number of buffers to allocate
41 *
42 * Returns the actual number of buffers allocated.
44 */ 43 */
45static int cvm_oct_fill_hw_skbuff(int pool, int size, int elements) 44static int cvm_oct_fill_hw_skbuff(int pool, int size, int elements)
46{ 45{
47 int freed = elements; 46 int freed = elements;
48 while (freed) { 47 while (freed) {
49 48
50 struct sk_buff *skb = dev_alloc_skb(size + 128); 49 struct sk_buff *skb = dev_alloc_skb(size + 256);
51 if (unlikely(skb == NULL)) { 50 if (unlikely(skb == NULL)) {
52 pr_warning 51 pr_warning
53 ("Failed to allocate skb for hardware pool %d\n", 52 ("Failed to allocate skb for hardware pool %d\n",
@@ -55,7 +54,7 @@ static int cvm_oct_fill_hw_skbuff(int pool, int size, int elements)
55 break; 54 break;
56 } 55 }
57 56
58 skb_reserve(skb, 128 - (((unsigned long)skb->data) & 0x7f)); 57 skb_reserve(skb, 256 - (((unsigned long)skb->data) & 0x7f));
59 *(struct sk_buff **)(skb->data - sizeof(void *)) = skb; 58 *(struct sk_buff **)(skb->data - sizeof(void *)) = skb;
60 cvmx_fpa_free(skb->data, pool, DONT_WRITEBACK(size / 128)); 59 cvmx_fpa_free(skb->data, pool, DONT_WRITEBACK(size / 128));
61 freed--; 60 freed--;
@@ -64,8 +63,7 @@ static int cvm_oct_fill_hw_skbuff(int pool, int size, int elements)
64} 63}
65 64
66/** 65/**
67 * Free the supplied hardware pool of skbuffs 66 * cvm_oct_free_hw_skbuff- free hardware pool skbuffs
68 *
69 * @pool: Pool to allocate an skbuff for 67 * @pool: Pool to allocate an skbuff for
70 * @size: Size of the buffer needed for the pool 68 * @size: Size of the buffer needed for the pool
71 * @elements: Number of buffers to allocate 69 * @elements: Number of buffers to allocate
@@ -93,96 +91,76 @@ static void cvm_oct_free_hw_skbuff(int pool, int size, int elements)
93} 91}
94 92
95/** 93/**
96 * This function fills a hardware pool with memory. Depending 94 * cvm_oct_fill_hw_memory - fill a hardware pool with memory.
97 * on the config defines, this memory might come from the
98 * kernel or global 32bit memory allocated with
99 * cvmx_bootmem_alloc.
100 *
101 * @pool: Pool to populate 95 * @pool: Pool to populate
102 * @size: Size of each buffer in the pool 96 * @size: Size of each buffer in the pool
103 * @elements: Number of buffers to allocate 97 * @elements: Number of buffers to allocate
98 *
99 * Returns the actual number of buffers allocated.
104 */ 100 */
105static int cvm_oct_fill_hw_memory(int pool, int size, int elements) 101static int cvm_oct_fill_hw_memory(int pool, int size, int elements)
106{ 102{
107 char *memory; 103 char *memory;
104 char *fpa;
108 int freed = elements; 105 int freed = elements;
109 106
110 if (USE_32BIT_SHARED) { 107 while (freed) {
111 extern uint64_t octeon_reserve32_memory; 108 /*
112 109 * FPA memory must be 128 byte aligned. Since we are
113 memory = 110 * aligning we need to save the original pointer so we
114 cvmx_bootmem_alloc_range(elements * size, 128, 111 * can feed it to kfree when the memory is returned to
115 octeon_reserve32_memory, 112 * the kernel.
116 octeon_reserve32_memory + 113 *
117 (CONFIG_CAVIUM_RESERVE32 << 20) - 114 * We allocate an extra 256 bytes to allow for
118 1); 115 * alignment and space for the original pointer saved
119 if (memory == NULL) 116 * just before the block.
120 panic("Unable to allocate %u bytes for FPA pool %d\n", 117 */
121 elements * size, pool); 118 memory = kmalloc(size + 256, GFP_ATOMIC);
122 119 if (unlikely(memory == NULL)) {
123 pr_notice("Memory range %p - %p reserved for " 120 pr_warning("Unable to allocate %u bytes for FPA pool %d\n",
124 "hardware\n", memory, 121 elements * size, pool);
125 memory + elements * size - 1); 122 break;
126
127 while (freed) {
128 cvmx_fpa_free(memory, pool, 0);
129 memory += size;
130 freed--;
131 }
132 } else {
133 while (freed) {
134 /* We need to force alignment to 128 bytes here */
135 memory = kmalloc(size + 127, GFP_ATOMIC);
136 if (unlikely(memory == NULL)) {
137 pr_warning("Unable to allocate %u bytes for "
138 "FPA pool %d\n",
139 elements * size, pool);
140 break;
141 }
142 memory = (char *)(((unsigned long)memory + 127) & -128);
143 cvmx_fpa_free(memory, pool, 0);
144 freed--;
145 } 123 }
124 fpa = (char *)(((unsigned long)memory + 256) & ~0x7fUL);
125 *((char **)fpa - 1) = memory;
126 cvmx_fpa_free(fpa, pool, 0);
127 freed--;
146 } 128 }
147 return elements - freed; 129 return elements - freed;
148} 130}
149 131
150/** 132/**
151 * Free memory previously allocated with cvm_oct_fill_hw_memory 133 * cvm_oct_free_hw_memory - Free memory allocated by cvm_oct_fill_hw_memory
152 *
153 * @pool: FPA pool to free 134 * @pool: FPA pool to free
154 * @size: Size of each buffer in the pool 135 * @size: Size of each buffer in the pool
155 * @elements: Number of buffers that should be in the pool 136 * @elements: Number of buffers that should be in the pool
156 */ 137 */
157static void cvm_oct_free_hw_memory(int pool, int size, int elements) 138static void cvm_oct_free_hw_memory(int pool, int size, int elements)
158{ 139{
159 if (USE_32BIT_SHARED) { 140 char *memory;
160 pr_warning("Warning: 32 shared memory is not freeable\n"); 141 char *fpa;
161 } else { 142 do {
162 char *memory; 143 fpa = cvmx_fpa_alloc(pool);
163 do { 144 if (fpa) {
164 memory = cvmx_fpa_alloc(pool); 145 elements--;
165 if (memory) { 146 fpa = (char *)phys_to_virt(cvmx_ptr_to_phys(fpa));
166 elements--; 147 memory = *((char **)fpa - 1);
167 kfree(phys_to_virt(cvmx_ptr_to_phys(memory))); 148 kfree(memory);
168 } 149 }
169 } while (memory); 150 } while (fpa);
170 151
171 if (elements < 0) 152 if (elements < 0)
172 pr_warning("Freeing of pool %u had too many " 153 pr_warning("Freeing of pool %u had too many buffers (%d)\n",
173 "buffers (%d)\n", 154 pool, elements);
174 pool, elements); 155 else if (elements > 0)
175 else if (elements > 0) 156 pr_warning("Warning: Freeing of pool %u is missing %d buffers\n",
176 pr_warning("Warning: Freeing of pool %u is " 157 pool, elements);
177 "missing %d buffers\n",
178 pool, elements);
179 }
180} 158}
181 159
182int cvm_oct_mem_fill_fpa(int pool, int size, int elements) 160int cvm_oct_mem_fill_fpa(int pool, int size, int elements)
183{ 161{
184 int freed; 162 int freed;
185 if (USE_SKBUFFS_IN_HW) 163 if (USE_SKBUFFS_IN_HW && pool == CVMX_FPA_PACKET_POOL)
186 freed = cvm_oct_fill_hw_skbuff(pool, size, elements); 164 freed = cvm_oct_fill_hw_skbuff(pool, size, elements);
187 else 165 else
188 freed = cvm_oct_fill_hw_memory(pool, size, elements); 166 freed = cvm_oct_fill_hw_memory(pool, size, elements);
@@ -191,7 +169,7 @@ int cvm_oct_mem_fill_fpa(int pool, int size, int elements)
191 169
192void cvm_oct_mem_empty_fpa(int pool, int size, int elements) 170void cvm_oct_mem_empty_fpa(int pool, int size, int elements)
193{ 171{
194 if (USE_SKBUFFS_IN_HW) 172 if (USE_SKBUFFS_IN_HW && pool == CVMX_FPA_PACKET_POOL)
195 cvm_oct_free_hw_skbuff(pool, size, elements); 173 cvm_oct_free_hw_skbuff(pool, size, elements);
196 else 174 else
197 cvm_oct_free_hw_memory(pool, size, elements); 175 cvm_oct_free_hw_memory(pool, size, elements);
diff --git a/drivers/staging/octeon/ethernet-proc.c b/drivers/staging/octeon/ethernet-proc.c
deleted file mode 100644
index 16308d484d3b..000000000000
--- a/drivers/staging/octeon/ethernet-proc.c
+++ /dev/null
@@ -1,144 +0,0 @@
1/**********************************************************************
2 * Author: Cavium Networks
3 *
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
6 *
7 * Copyright (c) 2003-2007 Cavium Networks
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
23 *
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26**********************************************************************/
27#include <linux/kernel.h>
28#include <linux/seq_file.h>
29#include <linux/proc_fs.h>
30#include <net/dst.h>
31
32#include <asm/octeon/octeon.h>
33
34#include "octeon-ethernet.h"
35#include "ethernet-defines.h"
36
37#include "cvmx-helper.h"
38#include "cvmx-pip.h"
39
40/**
41 * User is reading /proc/octeon_ethernet_stats
42 *
43 * @m:
44 * @v:
45 * Returns
46 */
47static int cvm_oct_stats_show(struct seq_file *m, void *v)
48{
49 struct octeon_ethernet *priv;
50 int port;
51
52 for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) {
53
54 if (cvm_oct_device[port]) {
55 priv = netdev_priv(cvm_oct_device[port]);
56
57 seq_printf(m, "\nOcteon Port %d (%s)\n", port,
58 cvm_oct_device[port]->name);
59 seq_printf(m,
60 "rx_packets: %12lu\t"
61 "tx_packets: %12lu\n",
62 priv->stats.rx_packets,
63 priv->stats.tx_packets);
64 seq_printf(m,
65 "rx_bytes: %12lu\t"
66 "tx_bytes: %12lu\n",
67 priv->stats.rx_bytes, priv->stats.tx_bytes);
68 seq_printf(m,
69 "rx_errors: %12lu\t"
70 "tx_errors: %12lu\n",
71 priv->stats.rx_errors,
72 priv->stats.tx_errors);
73 seq_printf(m,
74 "rx_dropped: %12lu\t"
75 "tx_dropped: %12lu\n",
76 priv->stats.rx_dropped,
77 priv->stats.tx_dropped);
78 seq_printf(m,
79 "rx_length_errors: %12lu\t"
80 "tx_aborted_errors: %12lu\n",
81 priv->stats.rx_length_errors,
82 priv->stats.tx_aborted_errors);
83 seq_printf(m,
84 "rx_over_errors: %12lu\t"
85 "tx_carrier_errors: %12lu\n",
86 priv->stats.rx_over_errors,
87 priv->stats.tx_carrier_errors);
88 seq_printf(m,
89 "rx_crc_errors: %12lu\t"
90 "tx_fifo_errors: %12lu\n",
91 priv->stats.rx_crc_errors,
92 priv->stats.tx_fifo_errors);
93 seq_printf(m,
94 "rx_frame_errors: %12lu\t"
95 "tx_heartbeat_errors: %12lu\n",
96 priv->stats.rx_frame_errors,
97 priv->stats.tx_heartbeat_errors);
98 seq_printf(m,
99 "rx_fifo_errors: %12lu\t"
100 "tx_window_errors: %12lu\n",
101 priv->stats.rx_fifo_errors,
102 priv->stats.tx_window_errors);
103 seq_printf(m,
104 "rx_missed_errors: %12lu\t"
105 "multicast: %12lu\n",
106 priv->stats.rx_missed_errors,
107 priv->stats.multicast);
108 }
109 }
110
111 return 0;
112}
113
114/**
115 * /proc/octeon_ethernet_stats was openned. Use the single_open iterator
116 *
117 * @inode:
118 * @file:
119 * Returns
120 */
121static int cvm_oct_stats_open(struct inode *inode, struct file *file)
122{
123 return single_open(file, cvm_oct_stats_show, NULL);
124}
125
126static const struct file_operations cvm_oct_stats_operations = {
127 .open = cvm_oct_stats_open,
128 .read = seq_read,
129 .llseek = seq_lseek,
130 .release = single_release,
131};
132
133void cvm_oct_proc_initialize(void)
134{
135 struct proc_dir_entry *entry =
136 create_proc_entry("octeon_ethernet_stats", 0, NULL);
137 if (entry)
138 entry->proc_fops = &cvm_oct_stats_operations;
139}
140
141void cvm_oct_proc_shutdown(void)
142{
143 remove_proc_entry("octeon_ethernet_stats", NULL);
144}
diff --git a/drivers/staging/octeon/ethernet-proc.h b/drivers/staging/octeon/ethernet-proc.h
deleted file mode 100644
index 82c7d9f78bc4..000000000000
--- a/drivers/staging/octeon/ethernet-proc.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*********************************************************************
2 * Author: Cavium Networks
3 *
4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK
6 *
7 * Copyright (c) 2003-2007 Cavium Networks
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this file; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * or visit http://www.gnu.org/licenses/.
23 *
24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information
26*********************************************************************/
27
28void cvm_oct_proc_initialize(void);
29void cvm_oct_proc_shutdown(void);
diff --git a/drivers/staging/octeon/ethernet-rgmii.c b/drivers/staging/octeon/ethernet-rgmii.c
index 3820f1ec11d1..a0d4d4b98bdc 100644
--- a/drivers/staging/octeon/ethernet-rgmii.c
+++ b/drivers/staging/octeon/ethernet-rgmii.c
@@ -26,7 +26,7 @@
26**********************************************************************/ 26**********************************************************************/
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/netdevice.h> 28#include <linux/netdevice.h>
29#include <linux/mii.h> 29#include <linux/phy.h>
30#include <net/dst.h> 30#include <net/dst.h>
31 31
32#include <asm/octeon/octeon.h> 32#include <asm/octeon/octeon.h>
@@ -48,14 +48,20 @@ static int number_rgmii_ports;
48static void cvm_oct_rgmii_poll(struct net_device *dev) 48static void cvm_oct_rgmii_poll(struct net_device *dev)
49{ 49{
50 struct octeon_ethernet *priv = netdev_priv(dev); 50 struct octeon_ethernet *priv = netdev_priv(dev);
51 unsigned long flags; 51 unsigned long flags = 0;
52 cvmx_helper_link_info_t link_info; 52 cvmx_helper_link_info_t link_info;
53 int use_global_register_lock = (priv->phydev == NULL);
53 54
54 /* 55 BUG_ON(in_interrupt());
55 * Take the global register lock since we are going to touch 56 if (use_global_register_lock) {
56 * registers that affect more than one port. 57 /*
57 */ 58 * Take the global register lock since we are going to
58 spin_lock_irqsave(&global_register_lock, flags); 59 * touch registers that affect more than one port.
60 */
61 spin_lock_irqsave(&global_register_lock, flags);
62 } else {
63 mutex_lock(&priv->phydev->bus->mdio_lock);
64 }
59 65
60 link_info = cvmx_helper_link_get(priv->port); 66 link_info = cvmx_helper_link_get(priv->port);
61 if (link_info.u64 == priv->link_info) { 67 if (link_info.u64 == priv->link_info) {
@@ -115,7 +121,11 @@ static void cvm_oct_rgmii_poll(struct net_device *dev)
115 dev->name); 121 dev->name);
116 } 122 }
117 } 123 }
118 spin_unlock_irqrestore(&global_register_lock, flags); 124
125 if (use_global_register_lock)
126 spin_unlock_irqrestore(&global_register_lock, flags);
127 else
128 mutex_unlock(&priv->phydev->bus->mdio_lock);
119 return; 129 return;
120 } 130 }
121 131
@@ -151,7 +161,12 @@ static void cvm_oct_rgmii_poll(struct net_device *dev)
151 link_info = cvmx_helper_link_autoconf(priv->port); 161 link_info = cvmx_helper_link_autoconf(priv->port);
152 priv->link_info = link_info.u64; 162 priv->link_info = link_info.u64;
153 } 163 }
154 spin_unlock_irqrestore(&global_register_lock, flags); 164
165 if (use_global_register_lock)
166 spin_unlock_irqrestore(&global_register_lock, flags);
167 else {
168 mutex_unlock(&priv->phydev->bus->mdio_lock);
169 }
155 170
156 if (priv->phydev == NULL) { 171 if (priv->phydev == NULL) {
157 /* Tell core. */ 172 /* Tell core. */
@@ -213,8 +228,11 @@ static irqreturn_t cvm_oct_rgmii_rml_interrupt(int cpl, void *dev_id)
213 struct net_device *dev = 228 struct net_device *dev =
214 cvm_oct_device[cvmx_helper_get_ipd_port 229 cvm_oct_device[cvmx_helper_get_ipd_port
215 (interface, index)]; 230 (interface, index)];
216 if (dev) 231 struct octeon_ethernet *priv = netdev_priv(dev);
217 cvm_oct_rgmii_poll(dev); 232
233 if (dev && !atomic_read(&cvm_oct_poll_queue_stopping))
234 queue_work(cvm_oct_poll_queue, &priv->port_work);
235
218 gmx_rx_int_reg.u64 = 0; 236 gmx_rx_int_reg.u64 = 0;
219 gmx_rx_int_reg.s.phy_dupx = 1; 237 gmx_rx_int_reg.s.phy_dupx = 1;
220 gmx_rx_int_reg.s.phy_link = 1; 238 gmx_rx_int_reg.s.phy_link = 1;
@@ -252,8 +270,11 @@ static irqreturn_t cvm_oct_rgmii_rml_interrupt(int cpl, void *dev_id)
252 struct net_device *dev = 270 struct net_device *dev =
253 cvm_oct_device[cvmx_helper_get_ipd_port 271 cvm_oct_device[cvmx_helper_get_ipd_port
254 (interface, index)]; 272 (interface, index)];
255 if (dev) 273 struct octeon_ethernet *priv = netdev_priv(dev);
256 cvm_oct_rgmii_poll(dev); 274
275 if (dev && !atomic_read(&cvm_oct_poll_queue_stopping))
276 queue_work(cvm_oct_poll_queue, &priv->port_work);
277
257 gmx_rx_int_reg.u64 = 0; 278 gmx_rx_int_reg.u64 = 0;
258 gmx_rx_int_reg.s.phy_dupx = 1; 279 gmx_rx_int_reg.s.phy_dupx = 1;
259 gmx_rx_int_reg.s.phy_link = 1; 280 gmx_rx_int_reg.s.phy_link = 1;
@@ -302,6 +323,12 @@ int cvm_oct_rgmii_stop(struct net_device *dev)
302 return 0; 323 return 0;
303} 324}
304 325
326static void cvm_oct_rgmii_immediate_poll(struct work_struct *work)
327{
328 struct octeon_ethernet *priv = container_of(work, struct octeon_ethernet, port_work);
329 cvm_oct_rgmii_poll(cvm_oct_device[priv->port]);
330}
331
305int cvm_oct_rgmii_init(struct net_device *dev) 332int cvm_oct_rgmii_init(struct net_device *dev)
306{ 333{
307 struct octeon_ethernet *priv = netdev_priv(dev); 334 struct octeon_ethernet *priv = netdev_priv(dev);
@@ -309,7 +336,7 @@ int cvm_oct_rgmii_init(struct net_device *dev)
309 336
310 cvm_oct_common_init(dev); 337 cvm_oct_common_init(dev);
311 dev->netdev_ops->ndo_stop(dev); 338 dev->netdev_ops->ndo_stop(dev);
312 339 INIT_WORK(&priv->port_work, cvm_oct_rgmii_immediate_poll);
313 /* 340 /*
314 * Due to GMX errata in CN3XXX series chips, it is necessary 341 * Due to GMX errata in CN3XXX series chips, it is necessary
315 * to take the link down immediately when the PHY changes 342 * to take the link down immediately when the PHY changes
@@ -397,4 +424,5 @@ void cvm_oct_rgmii_uninit(struct net_device *dev)
397 number_rgmii_ports--; 424 number_rgmii_ports--;
398 if (number_rgmii_ports == 0) 425 if (number_rgmii_ports == 0)
399 free_irq(OCTEON_IRQ_RML, &number_rgmii_ports); 426 free_irq(OCTEON_IRQ_RML, &number_rgmii_ports);
427 cancel_work_sync(&priv->port_work);
400} 428}
diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
index 1b237b7e689d..cb38f9eb2cc0 100644
--- a/drivers/staging/octeon/ethernet-rx.c
+++ b/drivers/staging/octeon/ethernet-rx.c
@@ -4,7 +4,7 @@
4 * Contact: support@caviumnetworks.com 4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK 5 * This file is part of the OCTEON SDK
6 * 6 *
7 * Copyright (c) 2003-2007 Cavium Networks 7 * Copyright (c) 2003-2010 Cavium Networks
8 * 8 *
9 * This file is free software; you can redistribute it and/or modify 9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as 10 * it under the terms of the GNU General Public License, Version 2, as
@@ -27,16 +27,14 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/cache.h> 29#include <linux/cache.h>
30#include <linux/cpumask.h>
30#include <linux/netdevice.h> 31#include <linux/netdevice.h>
31#include <linux/init.h> 32#include <linux/init.h>
32#include <linux/etherdevice.h> 33#include <linux/etherdevice.h>
33#include <linux/ip.h> 34#include <linux/ip.h>
34#include <linux/string.h> 35#include <linux/string.h>
35#include <linux/prefetch.h> 36#include <linux/prefetch.h>
36#include <linux/ethtool.h> 37#include <linux/smp.h>
37#include <linux/mii.h>
38#include <linux/seq_file.h>
39#include <linux/proc_fs.h>
40#include <net/dst.h> 38#include <net/dst.h>
41#ifdef CONFIG_XFRM 39#ifdef CONFIG_XFRM
42#include <linux/xfrm.h> 40#include <linux/xfrm.h>
@@ -48,8 +46,9 @@
48#include <asm/octeon/octeon.h> 46#include <asm/octeon/octeon.h>
49 47
50#include "ethernet-defines.h" 48#include "ethernet-defines.h"
51#include "octeon-ethernet.h"
52#include "ethernet-mem.h" 49#include "ethernet-mem.h"
50#include "ethernet-rx.h"
51#include "octeon-ethernet.h"
53#include "ethernet-util.h" 52#include "ethernet-util.h"
54 53
55#include "cvmx-helper.h" 54#include "cvmx-helper.h"
@@ -61,62 +60,88 @@
61 60
62#include "cvmx-gmxx-defs.h" 61#include "cvmx-gmxx-defs.h"
63 62
64struct cvm_tasklet_wrapper { 63struct cvm_napi_wrapper {
65 struct tasklet_struct t; 64 struct napi_struct napi;
66}; 65} ____cacheline_aligned_in_smp;
67 66
68/* 67static struct cvm_napi_wrapper cvm_oct_napi[NR_CPUS] __cacheline_aligned_in_smp;
69 * Aligning the tasklet_struct on cachline boundries seems to decrease
70 * throughput even though in theory it would reduce contantion on the
71 * cache lines containing the locks.
72 */
73 68
74static struct cvm_tasklet_wrapper cvm_oct_tasklet[NR_CPUS]; 69struct cvm_oct_core_state {
70 int baseline_cores;
71 /*
72 * The number of additional cores that could be processing
73 * input packtes.
74 */
75 atomic_t available_cores;
76 cpumask_t cpu_state;
77} ____cacheline_aligned_in_smp;
75 78
76/** 79static struct cvm_oct_core_state core_state __cacheline_aligned_in_smp;
77 * Interrupt handler. The interrupt occurs whenever the POW 80
78 * transitions from 0->1 packets in our group. 81static void cvm_oct_enable_napi(void *_)
79 *
80 * @cpl:
81 * @dev_id:
82 * @regs:
83 * Returns
84 */
85irqreturn_t cvm_oct_do_interrupt(int cpl, void *dev_id)
86{ 82{
87 /* Acknowledge the interrupt */ 83 int cpu = smp_processor_id();
88 if (INTERRUPT_LIMIT) 84 napi_schedule(&cvm_oct_napi[cpu].napi);
89 cvmx_write_csr(CVMX_POW_WQ_INT, 1 << pow_receive_group); 85}
90 else 86
91 cvmx_write_csr(CVMX_POW_WQ_INT, 0x10001 << pow_receive_group); 87static void cvm_oct_enable_one_cpu(void)
92 preempt_disable(); 88{
93 tasklet_schedule(&cvm_oct_tasklet[smp_processor_id()].t); 89 int v;
94 preempt_enable(); 90 int cpu;
95 return IRQ_HANDLED; 91
92 /* Check to see if more CPUs are available for receive processing... */
93 v = atomic_sub_if_positive(1, &core_state.available_cores);
94 if (v < 0)
95 return;
96
97 /* ... if a CPU is available, Turn on NAPI polling for that CPU. */
98 for_each_online_cpu(cpu) {
99 if (!cpu_test_and_set(cpu, core_state.cpu_state)) {
100 v = smp_call_function_single(cpu, cvm_oct_enable_napi,
101 NULL, 0);
102 if (v)
103 panic("Can't enable NAPI.");
104 break;
105 }
106 }
107}
108
109static void cvm_oct_no_more_work(void)
110{
111 int cpu = smp_processor_id();
112
113 /*
114 * CPU zero is special. It always has the irq enabled when
115 * waiting for incoming packets.
116 */
117 if (cpu == 0) {
118 enable_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group);
119 return;
120 }
121
122 cpu_clear(cpu, core_state.cpu_state);
123 atomic_add(1, &core_state.available_cores);
96} 124}
97 125
98#ifdef CONFIG_NET_POLL_CONTROLLER
99/** 126/**
100 * This is called when the kernel needs to manually poll the 127 * cvm_oct_do_interrupt - interrupt handler.
101 * device. For Octeon, this is simply calling the interrupt 128 *
102 * handler. We actually poll all the devices, not just the 129 * The interrupt occurs whenever the POW has packets in our group.
103 * one supplied.
104 * 130 *
105 * @dev: Device to poll. Unused
106 */ 131 */
107void cvm_oct_poll_controller(struct net_device *dev) 132static irqreturn_t cvm_oct_do_interrupt(int cpl, void *dev_id)
108{ 133{
109 preempt_disable(); 134 /* Disable the IRQ and start napi_poll. */
110 tasklet_schedule(&cvm_oct_tasklet[smp_processor_id()].t); 135 disable_irq_nosync(OCTEON_IRQ_WORKQ0 + pow_receive_group);
111 preempt_enable(); 136 cvm_oct_enable_napi(NULL);
137
138 return IRQ_HANDLED;
112} 139}
113#endif
114 140
115/** 141/**
116 * This is called on receive errors, and determines if the packet 142 * cvm_oct_check_rcv_error - process receive errors
117 * can be dropped early-on in cvm_oct_tasklet_rx().
118 *
119 * @work: Work queue entry pointing to the packet. 143 * @work: Work queue entry pointing to the packet.
144 *
120 * Returns Non-zero if the packet can be dropped, zero otherwise. 145 * Returns Non-zero if the packet can be dropped, zero otherwise.
121 */ 146 */
122static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work) 147static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work)
@@ -199,19 +224,20 @@ static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work)
199} 224}
200 225
201/** 226/**
202 * Tasklet function that is scheduled on a core when an interrupt occurs. 227 * cvm_oct_napi_poll - the NAPI poll function.
228 * @napi: The NAPI instance, or null if called from cvm_oct_poll_controller
229 * @budget: Maximum number of packets to receive.
203 * 230 *
204 * @unused: 231 * Returns the number of packets processed.
205 */ 232 */
206void cvm_oct_tasklet_rx(unsigned long unused) 233static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
207{ 234{
208 const int coreid = cvmx_get_core_num(); 235 const int coreid = cvmx_get_core_num();
209 uint64_t old_group_mask; 236 uint64_t old_group_mask;
210 uint64_t old_scratch; 237 uint64_t old_scratch;
211 int rx_count = 0; 238 int rx_count = 0;
212 int number_to_free; 239 int did_work_request = 0;
213 int num_freed; 240 int packet_not_copied;
214 int packet_not_copied;
215 241
216 /* Prefetch cvm_oct_device since we know we need it soon */ 242 /* Prefetch cvm_oct_device since we know we need it soon */
217 prefetch(cvm_oct_device); 243 prefetch(cvm_oct_device);
@@ -227,59 +253,63 @@ void cvm_oct_tasklet_rx(unsigned long unused)
227 cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), 253 cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid),
228 (old_group_mask & ~0xFFFFull) | 1 << pow_receive_group); 254 (old_group_mask & ~0xFFFFull) | 1 << pow_receive_group);
229 255
230 if (USE_ASYNC_IOBDMA) 256 if (USE_ASYNC_IOBDMA) {
231 cvmx_pow_work_request_async(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT); 257 cvmx_pow_work_request_async(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT);
258 did_work_request = 1;
259 }
232 260
233 while (1) { 261 while (rx_count < budget) {
234 struct sk_buff *skb = NULL; 262 struct sk_buff *skb = NULL;
263 struct sk_buff **pskb = NULL;
235 int skb_in_hw; 264 int skb_in_hw;
236 cvmx_wqe_t *work; 265 cvmx_wqe_t *work;
237 266
238 if (USE_ASYNC_IOBDMA) { 267 if (USE_ASYNC_IOBDMA && did_work_request)
239 work = cvmx_pow_work_response_async(CVMX_SCR_SCRATCH); 268 work = cvmx_pow_work_response_async(CVMX_SCR_SCRATCH);
240 } else { 269 else
241 if ((INTERRUPT_LIMIT == 0) 270 work = cvmx_pow_work_request_sync(CVMX_POW_NO_WAIT);
242 || likely(rx_count < MAX_RX_PACKETS)) 271
243 work =
244 cvmx_pow_work_request_sync
245 (CVMX_POW_NO_WAIT);
246 else
247 work = NULL;
248 }
249 prefetch(work); 272 prefetch(work);
250 if (work == NULL) 273 did_work_request = 0;
274 if (work == NULL) {
275 union cvmx_pow_wq_int wq_int;
276 wq_int.u64 = 0;
277 wq_int.s.iq_dis = 1 << pow_receive_group;
278 wq_int.s.wq_int = 1 << pow_receive_group;
279 cvmx_write_csr(CVMX_POW_WQ_INT, wq_int.u64);
251 break; 280 break;
281 }
282 pskb = (struct sk_buff **)(cvm_oct_get_buffer_ptr(work->packet_ptr) - sizeof(void *));
283 prefetch(pskb);
252 284
253 /* 285 if (USE_ASYNC_IOBDMA && rx_count < (budget - 1)) {
254 * Limit each core to processing MAX_RX_PACKETS 286 cvmx_pow_work_request_async_nocheck(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT);
255 * packets without a break. This way the RX can't 287 did_work_request = 1;
256 * starve the TX task. 288 }
257 */ 289
258 if (USE_ASYNC_IOBDMA) { 290 if (rx_count == 0) {
259 291 /*
260 if ((INTERRUPT_LIMIT == 0) 292 * First time through, see if there is enough
261 || likely(rx_count < MAX_RX_PACKETS)) 293 * work waiting to merit waking another
262 cvmx_pow_work_request_async_nocheck 294 * CPU.
263 (CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT); 295 */
264 else { 296 union cvmx_pow_wq_int_cntx counts;
265 cvmx_scratch_write64(CVMX_SCR_SCRATCH, 297 int backlog;
266 0x8000000000000000ull); 298 int cores_in_use = core_state.baseline_cores - atomic_read(&core_state.available_cores);
267 cvmx_pow_tag_sw_null_nocheck(); 299 counts.u64 = cvmx_read_csr(CVMX_POW_WQ_INT_CNTX(pow_receive_group));
268 } 300 backlog = counts.s.iq_cnt + counts.s.ds_cnt;
301 if (backlog > budget * cores_in_use && napi != NULL)
302 cvm_oct_enable_one_cpu();
269 } 303 }
270 304
271 skb_in_hw = USE_SKBUFFS_IN_HW && work->word2.s.bufs == 1; 305 skb_in_hw = USE_SKBUFFS_IN_HW && work->word2.s.bufs == 1;
272 if (likely(skb_in_hw)) { 306 if (likely(skb_in_hw)) {
273 skb = 307 skb = *pskb;
274 *(struct sk_buff
275 **)(cvm_oct_get_buffer_ptr(work->packet_ptr) -
276 sizeof(void *));
277 prefetch(&skb->head); 308 prefetch(&skb->head);
278 prefetch(&skb->len); 309 prefetch(&skb->len);
279 } 310 }
280 prefetch(cvm_oct_device[work->ipprt]); 311 prefetch(cvm_oct_device[work->ipprt]);
281 312
282 rx_count++;
283 /* Immediately throw away all packets with receive errors */ 313 /* Immediately throw away all packets with receive errors */
284 if (unlikely(work->word2.snoip.rcv_error)) { 314 if (unlikely(work->word2.snoip.rcv_error)) {
285 if (cvm_oct_check_rcv_error(work)) 315 if (cvm_oct_check_rcv_error(work))
@@ -292,39 +322,27 @@ void cvm_oct_tasklet_rx(unsigned long unused)
292 * buffer. 322 * buffer.
293 */ 323 */
294 if (likely(skb_in_hw)) { 324 if (likely(skb_in_hw)) {
295 /* 325 skb->data = skb->head + work->packet_ptr.s.addr - cvmx_ptr_to_phys(skb->head);
296 * This calculation was changed in case the
297 * skb header is using a different address
298 * aliasing type than the buffer. It doesn't
299 * make any differnece now, but the new one is
300 * more correct.
301 */
302 skb->data =
303 skb->head + work->packet_ptr.s.addr -
304 cvmx_ptr_to_phys(skb->head);
305 prefetch(skb->data); 326 prefetch(skb->data);
306 skb->len = work->len; 327 skb->len = work->len;
307 skb_set_tail_pointer(skb, skb->len); 328 skb_set_tail_pointer(skb, skb->len);
308 packet_not_copied = 1; 329 packet_not_copied = 1;
309 } else { 330 } else {
310
311 /* 331 /*
312 * We have to copy the packet. First allocate 332 * We have to copy the packet. First allocate
313 * an skbuff for it. 333 * an skbuff for it.
314 */ 334 */
315 skb = dev_alloc_skb(work->len); 335 skb = dev_alloc_skb(work->len);
316 if (!skb) { 336 if (!skb) {
317 DEBUGPRINT("Port %d failed to allocate " 337 DEBUGPRINT("Port %d failed to allocate skbuff, packet dropped\n",
318 "skbuff, packet dropped\n", 338 work->ipprt);
319 work->ipprt);
320 cvm_oct_free_work(work); 339 cvm_oct_free_work(work);
321 continue; 340 continue;
322 } 341 }
323 342
324 /* 343 /*
325 * Check if we've received a packet that was 344 * Check if we've received a packet that was
326 * entirely stored in the work entry. This is 345 * entirely stored in the work entry.
327 * untested.
328 */ 346 */
329 if (unlikely(work->word2.s.bufs == 0)) { 347 if (unlikely(work->word2.s.bufs == 0)) {
330 uint8_t *ptr = work->packet_data; 348 uint8_t *ptr = work->packet_data;
@@ -343,15 +361,13 @@ void cvm_oct_tasklet_rx(unsigned long unused)
343 /* No packet buffers to free */ 361 /* No packet buffers to free */
344 } else { 362 } else {
345 int segments = work->word2.s.bufs; 363 int segments = work->word2.s.bufs;
346 union cvmx_buf_ptr segment_ptr = 364 union cvmx_buf_ptr segment_ptr = work->packet_ptr;
347 work->packet_ptr;
348 int len = work->len; 365 int len = work->len;
349 366
350 while (segments--) { 367 while (segments--) {
351 union cvmx_buf_ptr next_ptr = 368 union cvmx_buf_ptr next_ptr =
352 *(union cvmx_buf_ptr *) 369 *(union cvmx_buf_ptr *)cvmx_phys_to_ptr(segment_ptr.s.addr - 8);
353 cvmx_phys_to_ptr(segment_ptr.s. 370
354 addr - 8);
355 /* 371 /*
356 * Octeon Errata PKI-100: The segment size is 372 * Octeon Errata PKI-100: The segment size is
357 * wrong. Until it is fixed, calculate the 373 * wrong. Until it is fixed, calculate the
@@ -361,22 +377,18 @@ void cvm_oct_tasklet_rx(unsigned long unused)
361 * one: int segment_size = 377 * one: int segment_size =
362 * segment_ptr.s.size; 378 * segment_ptr.s.size;
363 */ 379 */
364 int segment_size = 380 int segment_size = CVMX_FPA_PACKET_POOL_SIZE -
365 CVMX_FPA_PACKET_POOL_SIZE - 381 (segment_ptr.s.addr - (((segment_ptr.s.addr >> 7) - segment_ptr.s.back) << 7));
366 (segment_ptr.s.addr - 382 /*
367 (((segment_ptr.s.addr >> 7) - 383 * Don't copy more than what
368 segment_ptr.s.back) << 7)); 384 * is left in the packet.
369 /* Don't copy more than what is left 385 */
370 in the packet */
371 if (segment_size > len) 386 if (segment_size > len)
372 segment_size = len; 387 segment_size = len;
373 /* Copy the data into the packet */ 388 /* Copy the data into the packet */
374 memcpy(skb_put(skb, segment_size), 389 memcpy(skb_put(skb, segment_size),
375 cvmx_phys_to_ptr(segment_ptr.s. 390 cvmx_phys_to_ptr(segment_ptr.s.addr),
376 addr),
377 segment_size); 391 segment_size);
378 /* Reduce the amount of bytes left
379 to copy */
380 len -= segment_size; 392 len -= segment_size;
381 segment_ptr = next_ptr; 393 segment_ptr = next_ptr;
382 } 394 }
@@ -389,16 +401,15 @@ void cvm_oct_tasklet_rx(unsigned long unused)
389 struct net_device *dev = cvm_oct_device[work->ipprt]; 401 struct net_device *dev = cvm_oct_device[work->ipprt];
390 struct octeon_ethernet *priv = netdev_priv(dev); 402 struct octeon_ethernet *priv = netdev_priv(dev);
391 403
392 /* Only accept packets for devices 404 /*
393 that are currently up */ 405 * Only accept packets for devices that are
406 * currently up.
407 */
394 if (likely(dev->flags & IFF_UP)) { 408 if (likely(dev->flags & IFF_UP)) {
395 skb->protocol = eth_type_trans(skb, dev); 409 skb->protocol = eth_type_trans(skb, dev);
396 skb->dev = dev; 410 skb->dev = dev;
397 411
398 if (unlikely 412 if (unlikely(work->word2.s.not_IP || work->word2.s.IP_exc || work->word2.s.L4_error))
399 (work->word2.s.not_IP
400 || work->word2.s.IP_exc
401 || work->word2.s.L4_error))
402 skb->ip_summed = CHECKSUM_NONE; 413 skb->ip_summed = CHECKSUM_NONE;
403 else 414 else
404 skb->ip_summed = CHECKSUM_UNNECESSARY; 415 skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -414,15 +425,13 @@ void cvm_oct_tasklet_rx(unsigned long unused)
414#endif 425#endif
415 } 426 }
416 netif_receive_skb(skb); 427 netif_receive_skb(skb);
428 rx_count++;
417 } else { 429 } else {
430 /* Drop any packet received for a device that isn't up */
418 /* 431 /*
419 * Drop any packet received for a 432 DEBUGPRINT("%s: Device not up, packet dropped\n",
420 * device that isn't up. 433 dev->name);
421 */ 434 */
422 /*
423 DEBUGPRINT("%s: Device not up, packet dropped\n",
424 dev->name);
425 */
426#ifdef CONFIG_64BIT 435#ifdef CONFIG_64BIT
427 atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped); 436 atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
428#else 437#else
@@ -435,9 +444,8 @@ void cvm_oct_tasklet_rx(unsigned long unused)
435 * Drop any packet received for a device that 444 * Drop any packet received for a device that
436 * doesn't exist. 445 * doesn't exist.
437 */ 446 */
438 DEBUGPRINT("Port %d not controlled by Linux, packet " 447 DEBUGPRINT("Port %d not controlled by Linux, packet dropped\n",
439 "dropped\n", 448 work->ipprt);
440 work->ipprt);
441 dev_kfree_skb_irq(skb); 449 dev_kfree_skb_irq(skb);
442 } 450 }
443 /* 451 /*
@@ -459,47 +467,93 @@ void cvm_oct_tasklet_rx(unsigned long unused)
459 cvm_oct_free_work(work); 467 cvm_oct_free_work(work);
460 } 468 }
461 } 469 }
462
463 /* Restore the original POW group mask */ 470 /* Restore the original POW group mask */
464 cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), old_group_mask); 471 cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), old_group_mask);
465 if (USE_ASYNC_IOBDMA) { 472 if (USE_ASYNC_IOBDMA) {
466 /* Restore the scratch area */ 473 /* Restore the scratch area */
467 cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch); 474 cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch);
468 } 475 }
476 cvm_oct_rx_refill_pool(0);
469 477
470 if (USE_SKBUFFS_IN_HW) { 478 if (rx_count < budget && napi != NULL) {
471 /* Refill the packet buffer pool */ 479 /* No more work */
472 number_to_free = 480 napi_complete(napi);
473 cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0); 481 cvm_oct_no_more_work();
474
475 if (number_to_free > 0) {
476 cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE,
477 -number_to_free);
478 num_freed =
479 cvm_oct_mem_fill_fpa(CVMX_FPA_PACKET_POOL,
480 CVMX_FPA_PACKET_POOL_SIZE,
481 number_to_free);
482 if (num_freed != number_to_free) {
483 cvmx_fau_atomic_add32
484 (FAU_NUM_PACKET_BUFFERS_TO_FREE,
485 number_to_free - num_freed);
486 }
487 }
488 } 482 }
483 return rx_count;
489} 484}
490 485
486#ifdef CONFIG_NET_POLL_CONTROLLER
487/**
488 * cvm_oct_poll_controller - poll for receive packets
489 * device.
490 *
491 * @dev: Device to poll. Unused
492 */
493void cvm_oct_poll_controller(struct net_device *dev)
494{
495 cvm_oct_napi_poll(NULL, 16);
496}
497#endif
498
491void cvm_oct_rx_initialize(void) 499void cvm_oct_rx_initialize(void)
492{ 500{
493 int i; 501 int i;
494 /* Initialize all of the tasklets */ 502 struct net_device *dev_for_napi = NULL;
495 for (i = 0; i < NR_CPUS; i++) 503 union cvmx_pow_wq_int_thrx int_thr;
496 tasklet_init(&cvm_oct_tasklet[i].t, cvm_oct_tasklet_rx, 0); 504 union cvmx_pow_wq_int_pc int_pc;
505
506 for (i = 0; i < TOTAL_NUMBER_OF_PORTS; i++) {
507 if (cvm_oct_device[i]) {
508 dev_for_napi = cvm_oct_device[i];
509 break;
510 }
511 }
512
513 if (NULL == dev_for_napi)
514 panic("No net_devices were allocated.");
515
516 if (max_rx_cpus > 1 && max_rx_cpus < num_online_cpus())
517 atomic_set(&core_state.available_cores, max_rx_cpus);
518 else
519 atomic_set(&core_state.available_cores, num_online_cpus());
520 core_state.baseline_cores = atomic_read(&core_state.available_cores);
521
522 core_state.cpu_state = CPU_MASK_NONE;
523 for_each_possible_cpu(i) {
524 netif_napi_add(dev_for_napi, &cvm_oct_napi[i].napi,
525 cvm_oct_napi_poll, rx_napi_weight);
526 napi_enable(&cvm_oct_napi[i].napi);
527 }
528 /* Register an IRQ hander for to receive POW interrupts */
529 i = request_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group,
530 cvm_oct_do_interrupt, 0, "Ethernet", cvm_oct_device);
531
532 if (i)
533 panic("Could not acquire Ethernet IRQ %d\n",
534 OCTEON_IRQ_WORKQ0 + pow_receive_group);
535
536 disable_irq_nosync(OCTEON_IRQ_WORKQ0 + pow_receive_group);
537
538 int_thr.u64 = 0;
539 int_thr.s.tc_en = 1;
540 int_thr.s.tc_thr = 1;
541 /* Enable POW interrupt when our port has at least one packet */
542 cvmx_write_csr(CVMX_POW_WQ_INT_THRX(pow_receive_group), int_thr.u64);
543
544 int_pc.u64 = 0;
545 int_pc.s.pc_thr = 5;
546 cvmx_write_csr(CVMX_POW_WQ_INT_PC, int_pc.u64);
547
548
549 /* Scheduld NAPI now. This will indirectly enable interrupts. */
550 cvm_oct_enable_one_cpu();
497} 551}
498 552
499void cvm_oct_rx_shutdown(void) 553void cvm_oct_rx_shutdown(void)
500{ 554{
501 int i; 555 int i;
502 /* Shutdown all of the tasklets */ 556 /* Shutdown all of the NAPIs */
503 for (i = 0; i < NR_CPUS; i++) 557 for_each_possible_cpu(i)
504 tasklet_kill(&cvm_oct_tasklet[i].t); 558 netif_napi_del(&cvm_oct_napi[i].napi);
505} 559}
diff --git a/drivers/staging/octeon/ethernet-rx.h b/drivers/staging/octeon/ethernet-rx.h
index a9b72b87a7a6..a0743b85d54e 100644
--- a/drivers/staging/octeon/ethernet-rx.h
+++ b/drivers/staging/octeon/ethernet-rx.h
@@ -24,10 +24,29 @@
24 * This file may also be available under a different license from Cavium. 24 * This file may also be available under a different license from Cavium.
25 * Contact Cavium Networks for more information 25 * Contact Cavium Networks for more information
26*********************************************************************/ 26*********************************************************************/
27#include "cvmx-fau.h"
27 28
28irqreturn_t cvm_oct_do_interrupt(int cpl, void *dev_id);
29void cvm_oct_poll_controller(struct net_device *dev); 29void cvm_oct_poll_controller(struct net_device *dev);
30void cvm_oct_tasklet_rx(unsigned long unused);
31
32void cvm_oct_rx_initialize(void); 30void cvm_oct_rx_initialize(void);
33void cvm_oct_rx_shutdown(void); 31void cvm_oct_rx_shutdown(void);
32
33static inline void cvm_oct_rx_refill_pool(int fill_threshold)
34{
35 int number_to_free;
36 int num_freed;
37 /* Refill the packet buffer pool */
38 number_to_free =
39 cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0);
40
41 if (number_to_free > fill_threshold) {
42 cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE,
43 -number_to_free);
44 num_freed = cvm_oct_mem_fill_fpa(CVMX_FPA_PACKET_POOL,
45 CVMX_FPA_PACKET_POOL_SIZE,
46 number_to_free);
47 if (num_freed != number_to_free) {
48 cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE,
49 number_to_free - num_freed);
50 }
51 }
52}
diff --git a/drivers/staging/octeon/ethernet-sgmii.c b/drivers/staging/octeon/ethernet-sgmii.c
index 6061d01eca2d..2d8589eb461e 100644
--- a/drivers/staging/octeon/ethernet-sgmii.c
+++ b/drivers/staging/octeon/ethernet-sgmii.c
@@ -26,7 +26,6 @@
26**********************************************************************/ 26**********************************************************************/
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/netdevice.h> 28#include <linux/netdevice.h>
29#include <linux/mii.h>
30#include <net/dst.h> 29#include <net/dst.h>
31 30
32#include <asm/octeon/octeon.h> 31#include <asm/octeon/octeon.h>
diff --git a/drivers/staging/octeon/ethernet-spi.c b/drivers/staging/octeon/ethernet-spi.c
index 00dc0f4bad19..b58b8971f939 100644
--- a/drivers/staging/octeon/ethernet-spi.c
+++ b/drivers/staging/octeon/ethernet-spi.c
@@ -26,7 +26,6 @@
26**********************************************************************/ 26**********************************************************************/
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/netdevice.h> 28#include <linux/netdevice.h>
29#include <linux/mii.h>
30#include <net/dst.h> 29#include <net/dst.h>
31 30
32#include <asm/octeon/octeon.h> 31#include <asm/octeon/octeon.h>
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 535294105f65..afc2b734d554 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -4,7 +4,7 @@
4 * Contact: support@caviumnetworks.com 4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK 5 * This file is part of the OCTEON SDK
6 * 6 *
7 * Copyright (c) 2003-2007 Cavium Networks 7 * Copyright (c) 2003-2010 Cavium Networks
8 * 8 *
9 * This file is free software; you can redistribute it and/or modify 9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as 10 * it under the terms of the GNU General Public License, Version 2, as
@@ -31,10 +31,6 @@
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/ip.h> 32#include <linux/ip.h>
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/ethtool.h>
35#include <linux/mii.h>
36#include <linux/seq_file.h>
37#include <linux/proc_fs.h>
38#include <net/dst.h> 34#include <net/dst.h>
39#ifdef CONFIG_XFRM 35#ifdef CONFIG_XFRM
40#include <linux/xfrm.h> 36#include <linux/xfrm.h>
@@ -52,11 +48,14 @@
52 48
53#include "cvmx-wqe.h" 49#include "cvmx-wqe.h"
54#include "cvmx-fau.h" 50#include "cvmx-fau.h"
51#include "cvmx-pip.h"
55#include "cvmx-pko.h" 52#include "cvmx-pko.h"
56#include "cvmx-helper.h" 53#include "cvmx-helper.h"
57 54
58#include "cvmx-gmxx-defs.h" 55#include "cvmx-gmxx-defs.h"
59 56
57#define CVM_OCT_SKB_CB(skb) ((u64 *)((skb)->cb))
58
60/* 59/*
61 * You can define GET_SKBUFF_QOS() to override how the skbuff output 60 * You can define GET_SKBUFF_QOS() to override how the skbuff output
62 * function determines which output queue is used. The default 61 * function determines which output queue is used. The default
@@ -68,12 +67,81 @@
68#define GET_SKBUFF_QOS(skb) 0 67#define GET_SKBUFF_QOS(skb) 0
69#endif 68#endif
70 69
70static void cvm_oct_tx_do_cleanup(unsigned long arg);
71static DECLARE_TASKLET(cvm_oct_tx_cleanup_tasklet, cvm_oct_tx_do_cleanup, 0);
72
73/* Maximum number of SKBs to try to free per xmit packet. */
74#define MAX_SKB_TO_FREE (MAX_OUT_QUEUE_DEPTH * 2)
75
76static inline int32_t cvm_oct_adjust_skb_to_free(int32_t skb_to_free, int fau)
77{
78 int32_t undo;
79 undo = skb_to_free > 0 ? MAX_SKB_TO_FREE : skb_to_free + MAX_SKB_TO_FREE;
80 if (undo > 0)
81 cvmx_fau_atomic_add32(fau, -undo);
82 skb_to_free = -skb_to_free > MAX_SKB_TO_FREE ? MAX_SKB_TO_FREE : -skb_to_free;
83 return skb_to_free;
84}
85
86static void cvm_oct_kick_tx_poll_watchdog(void)
87{
88 union cvmx_ciu_timx ciu_timx;
89 ciu_timx.u64 = 0;
90 ciu_timx.s.one_shot = 1;
91 ciu_timx.s.len = cvm_oct_tx_poll_interval;
92 cvmx_write_csr(CVMX_CIU_TIMX(1), ciu_timx.u64);
93}
94
95void cvm_oct_free_tx_skbs(struct net_device *dev)
96{
97 int32_t skb_to_free;
98 int qos, queues_per_port;
99 int total_freed = 0;
100 int total_remaining = 0;
101 unsigned long flags;
102 struct octeon_ethernet *priv = netdev_priv(dev);
103
104 queues_per_port = cvmx_pko_get_num_queues(priv->port);
105 /* Drain any pending packets in the free list */
106 for (qos = 0; qos < queues_per_port; qos++) {
107 if (skb_queue_len(&priv->tx_free_list[qos]) == 0)
108 continue;
109 skb_to_free = cvmx_fau_fetch_and_add32(priv->fau+qos*4, MAX_SKB_TO_FREE);
110 skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, priv->fau+qos*4);
111
112
113 total_freed += skb_to_free;
114 if (skb_to_free > 0) {
115 struct sk_buff *to_free_list = NULL;
116 spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
117 while (skb_to_free > 0) {
118 struct sk_buff *t = __skb_dequeue(&priv->tx_free_list[qos]);
119 t->next = to_free_list;
120 to_free_list = t;
121 skb_to_free--;
122 }
123 spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
124 /* Do the actual freeing outside of the lock. */
125 while (to_free_list) {
126 struct sk_buff *t = to_free_list;
127 to_free_list = to_free_list->next;
128 dev_kfree_skb_any(t);
129 }
130 }
131 total_remaining += skb_queue_len(&priv->tx_free_list[qos]);
132 }
133 if (total_freed >= 0 && netif_queue_stopped(dev))
134 netif_wake_queue(dev);
135 if (total_remaining)
136 cvm_oct_kick_tx_poll_watchdog();
137}
138
71/** 139/**
72 * Packet transmit 140 * cvm_oct_xmit - transmit a packet
73 *
74 * @skb: Packet to send 141 * @skb: Packet to send
75 * @dev: Device info structure 142 * @dev: Device info structure
76 * Returns Always returns zero 143 *
144 * Returns Always returns NETDEV_TX_OK
77 */ 145 */
78int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev) 146int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
79{ 147{
@@ -81,13 +149,15 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
81 union cvmx_buf_ptr hw_buffer; 149 union cvmx_buf_ptr hw_buffer;
82 uint64_t old_scratch; 150 uint64_t old_scratch;
83 uint64_t old_scratch2; 151 uint64_t old_scratch2;
84 int dropped;
85 int qos; 152 int qos;
86 int queue_it_up; 153 int i;
154 enum {QUEUE_CORE, QUEUE_HW, QUEUE_DROP} queue_type;
87 struct octeon_ethernet *priv = netdev_priv(dev); 155 struct octeon_ethernet *priv = netdev_priv(dev);
156 struct sk_buff *to_free_list;
88 int32_t skb_to_free; 157 int32_t skb_to_free;
89 int32_t undo;
90 int32_t buffers_to_free; 158 int32_t buffers_to_free;
159 u32 total_to_clean;
160 unsigned long flags;
91#if REUSE_SKBUFFS_WITHOUT_FREE 161#if REUSE_SKBUFFS_WITHOUT_FREE
92 unsigned char *fpa_head; 162 unsigned char *fpa_head;
93#endif 163#endif
@@ -98,9 +168,6 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
98 */ 168 */
99 prefetch(priv); 169 prefetch(priv);
100 170
101 /* Start off assuming no drop */
102 dropped = 0;
103
104 /* 171 /*
105 * The check on CVMX_PKO_QUEUES_PER_PORT_* is designed to 172 * The check on CVMX_PKO_QUEUES_PER_PORT_* is designed to
106 * completely remove "qos" in the event neither interface 173 * completely remove "qos" in the event neither interface
@@ -135,6 +202,28 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
135 } 202 }
136 203
137 /* 204 /*
205 * We have space for 6 segment pointers, If there will be more
206 * than that, we must linearize.
207 */
208 if (unlikely(skb_shinfo(skb)->nr_frags > 5)) {
209 if (unlikely(__skb_linearize(skb))) {
210 queue_type = QUEUE_DROP;
211 if (USE_ASYNC_IOBDMA) {
212 /* Get the number of skbuffs in use by the hardware */
213 CVMX_SYNCIOBDMA;
214 skb_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
215 } else {
216 /* Get the number of skbuffs in use by the hardware */
217 skb_to_free = cvmx_fau_fetch_and_add32(priv->fau + qos * 4,
218 MAX_SKB_TO_FREE);
219 }
220 skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, priv->fau + qos * 4);
221 spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
222 goto skip_xmit;
223 }
224 }
225
226 /*
138 * The CN3XXX series of parts has an errata (GMX-401) which 227 * The CN3XXX series of parts has an errata (GMX-401) which
139 * causes the GMX block to hang if a collision occurs towards 228 * causes the GMX block to hang if a collision occurs towards
140 * the end of a <68 byte packet. As a workaround for this, we 229 * the end of a <68 byte packet. As a workaround for this, we
@@ -162,13 +251,6 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
162 } 251 }
163 } 252 }
164 253
165 /* Build the PKO buffer pointer */
166 hw_buffer.u64 = 0;
167 hw_buffer.s.addr = cvmx_ptr_to_phys(skb->data);
168 hw_buffer.s.pool = 0;
169 hw_buffer.s.size =
170 (unsigned long)skb_end_pointer(skb) - (unsigned long)skb->head;
171
172 /* Build the PKO command */ 254 /* Build the PKO command */
173 pko_command.u64 = 0; 255 pko_command.u64 = 0;
174 pko_command.s.n2 = 1; /* Don't pollute L2 with the outgoing packet */ 256 pko_command.s.n2 = 1; /* Don't pollute L2 with the outgoing packet */
@@ -178,7 +260,31 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
178 pko_command.s.subone0 = 1; 260 pko_command.s.subone0 = 1;
179 261
180 pko_command.s.dontfree = 1; 262 pko_command.s.dontfree = 1;
181 pko_command.s.reg0 = priv->fau + qos * 4; 263
264 /* Build the PKO buffer pointer */
265 hw_buffer.u64 = 0;
266 if (skb_shinfo(skb)->nr_frags == 0) {
267 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)skb->data);
268 hw_buffer.s.pool = 0;
269 hw_buffer.s.size = skb->len;
270 } else {
271 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)skb->data);
272 hw_buffer.s.pool = 0;
273 hw_buffer.s.size = skb_headlen(skb);
274 CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64;
275 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
276 struct skb_frag_struct *fs = skb_shinfo(skb)->frags + i;
277 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)(page_address(fs->page) + fs->page_offset));
278 hw_buffer.s.size = fs->size;
279 CVM_OCT_SKB_CB(skb)[i + 1] = hw_buffer.u64;
280 }
281 hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)CVM_OCT_SKB_CB(skb));
282 hw_buffer.s.size = skb_shinfo(skb)->nr_frags + 1;
283 pko_command.s.segs = skb_shinfo(skb)->nr_frags + 1;
284 pko_command.s.gather = 1;
285 goto dont_put_skbuff_in_hw;
286 }
287
182 /* 288 /*
183 * See if we can put this skb in the FPA pool. Any strange 289 * See if we can put this skb in the FPA pool. Any strange
184 * behavior from the Linux networking stack will most likely 290 * behavior from the Linux networking stack will most likely
@@ -190,7 +296,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
190 * shown a 25% increase in performance under some loads. 296 * shown a 25% increase in performance under some loads.
191 */ 297 */
192#if REUSE_SKBUFFS_WITHOUT_FREE 298#if REUSE_SKBUFFS_WITHOUT_FREE
193 fpa_head = skb->head + 128 - ((unsigned long)skb->head & 0x7f); 299 fpa_head = skb->head + 256 - ((unsigned long)skb->head & 0x7f);
194 if (unlikely(skb->data < fpa_head)) { 300 if (unlikely(skb->data < fpa_head)) {
195 /* 301 /*
196 * printk("TX buffer beginning can't meet FPA 302 * printk("TX buffer beginning can't meet FPA
@@ -248,10 +354,9 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
248 * We can use this buffer in the FPA. We don't need the FAU 354 * We can use this buffer in the FPA. We don't need the FAU
249 * update anymore 355 * update anymore
250 */ 356 */
251 pko_command.s.reg0 = 0;
252 pko_command.s.dontfree = 0; 357 pko_command.s.dontfree = 0;
253 358
254 hw_buffer.s.back = (skb->data - fpa_head) >> 7; 359 hw_buffer.s.back = ((unsigned long)skb->data >> 7) - ((unsigned long)fpa_head >> 7);
255 *(struct sk_buff **)(fpa_head - sizeof(void *)) = skb; 360 *(struct sk_buff **)(fpa_head - sizeof(void *)) = skb;
256 361
257 /* 362 /*
@@ -272,16 +377,16 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
272 skb->tc_verd = 0; 377 skb->tc_verd = 0;
273#endif /* CONFIG_NET_CLS_ACT */ 378#endif /* CONFIG_NET_CLS_ACT */
274#endif /* CONFIG_NET_SCHED */ 379#endif /* CONFIG_NET_SCHED */
380#endif /* REUSE_SKBUFFS_WITHOUT_FREE */
275 381
276dont_put_skbuff_in_hw: 382dont_put_skbuff_in_hw:
277#endif /* REUSE_SKBUFFS_WITHOUT_FREE */
278 383
279 /* Check if we can use the hardware checksumming */ 384 /* Check if we can use the hardware checksumming */
280 if (USE_HW_TCPUDP_CHECKSUM && (skb->protocol == htons(ETH_P_IP)) && 385 if (USE_HW_TCPUDP_CHECKSUM && (skb->protocol == htons(ETH_P_IP)) &&
281 (ip_hdr(skb)->version == 4) && (ip_hdr(skb)->ihl == 5) && 386 (ip_hdr(skb)->version == 4) && (ip_hdr(skb)->ihl == 5) &&
282 ((ip_hdr(skb)->frag_off == 0) || (ip_hdr(skb)->frag_off == 1 << 14)) 387 ((ip_hdr(skb)->frag_off == 0) || (ip_hdr(skb)->frag_off == 1 << 14))
283 && ((ip_hdr(skb)->protocol == IP_PROTOCOL_TCP) 388 && ((ip_hdr(skb)->protocol == IPPROTO_TCP)
284 || (ip_hdr(skb)->protocol == IP_PROTOCOL_UDP))) { 389 || (ip_hdr(skb)->protocol == IPPROTO_UDP))) {
285 /* Use hardware checksum calc */ 390 /* Use hardware checksum calc */
286 pko_command.s.ipoffp1 = sizeof(struct ethhdr) + 1; 391 pko_command.s.ipoffp1 = sizeof(struct ethhdr) + 1;
287 } 392 }
@@ -299,89 +404,116 @@ dont_put_skbuff_in_hw:
299 cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0); 404 cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0);
300 } 405 }
301 406
302 /* 407 skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, priv->fau+qos*4);
303 * We try to claim MAX_SKB_TO_FREE buffers. If there were not
304 * that many available, we have to un-claim (undo) any that
305 * were in excess. If skb_to_free is positive we will free
306 * that many buffers.
307 */
308 undo = skb_to_free > 0 ?
309 MAX_SKB_TO_FREE : skb_to_free + MAX_SKB_TO_FREE;
310 if (undo > 0)
311 cvmx_fau_atomic_add32(priv->fau+qos*4, -undo);
312 skb_to_free = -skb_to_free > MAX_SKB_TO_FREE ?
313 MAX_SKB_TO_FREE : -skb_to_free;
314 408
315 /* 409 /*
316 * If we're sending faster than the receive can free them then 410 * If we're sending faster than the receive can free them then
317 * don't do the HW free. 411 * don't do the HW free.
318 */ 412 */
319 if ((buffers_to_free < -100) && !pko_command.s.dontfree) { 413 if ((buffers_to_free < -100) && !pko_command.s.dontfree)
320 pko_command.s.dontfree = 1; 414 pko_command.s.dontfree = 1;
321 pko_command.s.reg0 = priv->fau + qos * 4; 415
416 if (pko_command.s.dontfree) {
417 queue_type = QUEUE_CORE;
418 pko_command.s.reg0 = priv->fau+qos*4;
419 } else {
420 queue_type = QUEUE_HW;
322 } 421 }
422 if (USE_ASYNC_IOBDMA)
423 cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH, FAU_TOTAL_TX_TO_CLEAN, 1);
323 424
324 cvmx_pko_send_packet_prepare(priv->port, priv->queue + qos, 425 spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
325 CVMX_PKO_LOCK_CMD_QUEUE);
326 426
327 /* Drop this packet if we have too many already queued to the HW */ 427 /* Drop this packet if we have too many already queued to the HW */
328 if (unlikely 428 if (unlikely(skb_queue_len(&priv->tx_free_list[qos]) >= MAX_OUT_QUEUE_DEPTH)) {
329 (skb_queue_len(&priv->tx_free_list[qos]) >= MAX_OUT_QUEUE_DEPTH)) { 429 if (dev->tx_queue_len != 0) {
330 /* 430 /* Drop the lock when notifying the core. */
331 DEBUGPRINT("%s: Tx dropped. Too many queued\n", dev->name); 431 spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
332 */ 432 netif_stop_queue(dev);
333 dropped = 1; 433 spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
434 } else {
435 /* If not using normal queueing. */
436 queue_type = QUEUE_DROP;
437 goto skip_xmit;
438 }
334 } 439 }
440
441 cvmx_pko_send_packet_prepare(priv->port, priv->queue + qos,
442 CVMX_PKO_LOCK_NONE);
443
335 /* Send the packet to the output queue */ 444 /* Send the packet to the output queue */
336 else if (unlikely 445 if (unlikely(cvmx_pko_send_packet_finish(priv->port,
337 (cvmx_pko_send_packet_finish 446 priv->queue + qos,
338 (priv->port, priv->queue + qos, pko_command, hw_buffer, 447 pko_command, hw_buffer,
339 CVMX_PKO_LOCK_CMD_QUEUE))) { 448 CVMX_PKO_LOCK_NONE))) {
340 DEBUGPRINT("%s: Failed to send the packet\n", dev->name); 449 DEBUGPRINT("%s: Failed to send the packet\n", dev->name);
341 dropped = 1; 450 queue_type = QUEUE_DROP;
451 }
452skip_xmit:
453 to_free_list = NULL;
454
455 switch (queue_type) {
456 case QUEUE_DROP:
457 skb->next = to_free_list;
458 to_free_list = skb;
459 priv->stats.tx_dropped++;
460 break;
461 case QUEUE_HW:
462 cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, -1);
463 break;
464 case QUEUE_CORE:
465 __skb_queue_tail(&priv->tx_free_list[qos], skb);
466 break;
467 default:
468 BUG();
469 }
470
471 while (skb_to_free > 0) {
472 struct sk_buff *t = __skb_dequeue(&priv->tx_free_list[qos]);
473 t->next = to_free_list;
474 to_free_list = t;
475 skb_to_free--;
476 }
477
478 spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
479
480 /* Do the actual freeing outside of the lock. */
481 while (to_free_list) {
482 struct sk_buff *t = to_free_list;
483 to_free_list = to_free_list->next;
484 dev_kfree_skb_any(t);
342 } 485 }
343 486
344 if (USE_ASYNC_IOBDMA) { 487 if (USE_ASYNC_IOBDMA) {
488 CVMX_SYNCIOBDMA;
489 total_to_clean = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
345 /* Restore the scratch area */ 490 /* Restore the scratch area */
346 cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch); 491 cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch);
347 cvmx_scratch_write64(CVMX_SCR_SCRATCH + 8, old_scratch2); 492 cvmx_scratch_write64(CVMX_SCR_SCRATCH + 8, old_scratch2);
348 }
349
350 queue_it_up = 0;
351 if (unlikely(dropped)) {
352 dev_kfree_skb_any(skb);
353 priv->stats.tx_dropped++;
354 } else { 493 } else {
355 if (USE_SKBUFFS_IN_HW) { 494 total_to_clean = cvmx_fau_fetch_and_add32(FAU_TOTAL_TX_TO_CLEAN, 1);
356 /* Put this packet on the queue to be freed later */
357 if (pko_command.s.dontfree)
358 queue_it_up = 1;
359 else
360 cvmx_fau_atomic_add32
361 (FAU_NUM_PACKET_BUFFERS_TO_FREE, -1);
362 } else {
363 /* Put this packet on the queue to be freed later */
364 queue_it_up = 1;
365 }
366 } 495 }
367 496
368 if (queue_it_up) { 497 if (total_to_clean & 0x3ff) {
369 spin_lock(&priv->tx_free_list[qos].lock); 498 /*
370 __skb_queue_tail(&priv->tx_free_list[qos], skb); 499 * Schedule the cleanup tasklet every 1024 packets for
371 cvm_oct_free_tx_skbs(priv, skb_to_free, qos, 0); 500 * the pathological case of high traffic on one port
372 spin_unlock(&priv->tx_free_list[qos].lock); 501 * delaying clean up of packets on a different port
373 } else { 502 * that is blocked waiting for the cleanup.
374 cvm_oct_free_tx_skbs(priv, skb_to_free, qos, 1); 503 */
504 tasklet_schedule(&cvm_oct_tx_cleanup_tasklet);
375 } 505 }
376 506
377 return 0; 507 cvm_oct_kick_tx_poll_watchdog();
508
509 return NETDEV_TX_OK;
378} 510}
379 511
380/** 512/**
381 * Packet transmit to the POW 513 * cvm_oct_xmit_pow - transmit a packet to the POW
382 *
383 * @skb: Packet to send 514 * @skb: Packet to send
384 * @dev: Device info structure 515 * @dev: Device info structure
516
385 * Returns Always returns zero 517 * Returns Always returns zero
386 */ 518 */
387int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev) 519int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
@@ -459,8 +591,8 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
459 work->word2.s.dec_ipcomp = 0; /* FIXME */ 591 work->word2.s.dec_ipcomp = 0; /* FIXME */
460#endif 592#endif
461 work->word2.s.tcp_or_udp = 593 work->word2.s.tcp_or_udp =
462 (ip_hdr(skb)->protocol == IP_PROTOCOL_TCP) 594 (ip_hdr(skb)->protocol == IPPROTO_TCP)
463 || (ip_hdr(skb)->protocol == IP_PROTOCOL_UDP); 595 || (ip_hdr(skb)->protocol == IPPROTO_UDP);
464#if 0 596#if 0
465 /* FIXME */ 597 /* FIXME */
466 work->word2.s.dec_ipsec = 0; 598 work->word2.s.dec_ipsec = 0;
@@ -529,116 +661,63 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
529} 661}
530 662
531/** 663/**
532 * Transmit a work queue entry out of the ethernet port. Both 664 * cvm_oct_tx_shutdown_dev - free all skb that are currently queued for TX.
533 * the work queue entry and the packet data can optionally be 665 * @dev: Device being shutdown
534 * freed. The work will be freed on error as well.
535 *
536 * @dev: Device to transmit out.
537 * @work_queue_entry:
538 * Work queue entry to send
539 * @do_free: True if the work queue entry and packet data should be
540 * freed. If false, neither will be freed.
541 * @qos: Index into the queues for this port to transmit on. This
542 * is used to implement QoS if their are multiple queues per
543 * port. This parameter must be between 0 and the number of
544 * queues per port minus 1. Values outside of this range will
545 * be change to zero.
546 * 666 *
547 * Returns Zero on success, negative on failure.
548 */ 667 */
549int cvm_oct_transmit_qos(struct net_device *dev, void *work_queue_entry, 668void cvm_oct_tx_shutdown_dev(struct net_device *dev)
550 int do_free, int qos)
551{ 669{
552 unsigned long flags;
553 union cvmx_buf_ptr hw_buffer;
554 cvmx_pko_command_word0_t pko_command;
555 int dropped;
556 struct octeon_ethernet *priv = netdev_priv(dev); 670 struct octeon_ethernet *priv = netdev_priv(dev);
557 cvmx_wqe_t *work = work_queue_entry; 671 unsigned long flags;
672 int qos;
558 673
559 if (!(dev->flags & IFF_UP)) { 674 for (qos = 0; qos < 16; qos++) {
560 DEBUGPRINT("%s: Device not up\n", dev->name); 675 spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
561 if (do_free) 676 while (skb_queue_len(&priv->tx_free_list[qos]))
562 cvm_oct_free_work(work); 677 dev_kfree_skb_any(__skb_dequeue
563 return -1; 678 (&priv->tx_free_list[qos]));
679 spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
564 } 680 }
681}
565 682
566 /* The check on CVMX_PKO_QUEUES_PER_PORT_* is designed to completely 683static void cvm_oct_tx_do_cleanup(unsigned long arg)
567 remove "qos" in the event neither interface supports 684{
568 multiple queues per port */ 685 int port;
569 if ((CVMX_PKO_QUEUES_PER_PORT_INTERFACE0 > 1) ||
570 (CVMX_PKO_QUEUES_PER_PORT_INTERFACE1 > 1)) {
571 if (qos <= 0)
572 qos = 0;
573 else if (qos >= cvmx_pko_get_num_queues(priv->port))
574 qos = 0;
575 } else
576 qos = 0;
577
578 /* Start off assuming no drop */
579 dropped = 0;
580
581 local_irq_save(flags);
582 cvmx_pko_send_packet_prepare(priv->port, priv->queue + qos,
583 CVMX_PKO_LOCK_CMD_QUEUE);
584
585 /* Build the PKO buffer pointer */
586 hw_buffer.u64 = 0;
587 hw_buffer.s.addr = work->packet_ptr.s.addr;
588 hw_buffer.s.pool = CVMX_FPA_PACKET_POOL;
589 hw_buffer.s.size = CVMX_FPA_PACKET_POOL_SIZE;
590 hw_buffer.s.back = work->packet_ptr.s.back;
591 686
592 /* Build the PKO command */ 687 for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) {
593 pko_command.u64 = 0; 688 if (cvm_oct_device[port]) {
594 pko_command.s.n2 = 1; /* Don't pollute L2 with the outgoing packet */ 689 struct net_device *dev = cvm_oct_device[port];
595 pko_command.s.dontfree = !do_free; 690 cvm_oct_free_tx_skbs(dev);
596 pko_command.s.segs = work->word2.s.bufs; 691 }
597 pko_command.s.total_bytes = work->len; 692 }
693}
598 694
599 /* Check if we can use the hardware checksumming */ 695static irqreturn_t cvm_oct_tx_cleanup_watchdog(int cpl, void *dev_id)
600 if (unlikely(work->word2.s.not_IP || work->word2.s.IP_exc)) 696{
601 pko_command.s.ipoffp1 = 0; 697 /* Disable the interrupt. */
602 else 698 cvmx_write_csr(CVMX_CIU_TIMX(1), 0);
603 pko_command.s.ipoffp1 = sizeof(struct ethhdr) + 1; 699 /* Do the work in the tasklet. */
700 tasklet_schedule(&cvm_oct_tx_cleanup_tasklet);
701 return IRQ_HANDLED;
702}
604 703
605 /* Send the packet to the output queue */ 704void cvm_oct_tx_initialize(void)
606 if (unlikely 705{
607 (cvmx_pko_send_packet_finish 706 int i;
608 (priv->port, priv->queue + qos, pko_command, hw_buffer,
609 CVMX_PKO_LOCK_CMD_QUEUE))) {
610 DEBUGPRINT("%s: Failed to send the packet\n", dev->name);
611 dropped = -1;
612 }
613 local_irq_restore(flags);
614 707
615 if (unlikely(dropped)) { 708 /* Disable the interrupt. */
616 if (do_free) 709 cvmx_write_csr(CVMX_CIU_TIMX(1), 0);
617 cvm_oct_free_work(work); 710 /* Register an IRQ hander for to receive CIU_TIMX(1) interrupts */
618 priv->stats.tx_dropped++; 711 i = request_irq(OCTEON_IRQ_TIMER1,
619 } else if (do_free) 712 cvm_oct_tx_cleanup_watchdog, 0,
620 cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, DONT_WRITEBACK(1)); 713 "Ethernet", cvm_oct_device);
621 714
622 return dropped; 715 if (i)
716 panic("Could not acquire Ethernet IRQ %d\n", OCTEON_IRQ_TIMER1);
623} 717}
624EXPORT_SYMBOL(cvm_oct_transmit_qos);
625 718
626/** 719void cvm_oct_tx_shutdown(void)
627 * This function frees all skb that are currently queued for TX.
628 *
629 * @dev: Device being shutdown
630 */
631void cvm_oct_tx_shutdown(struct net_device *dev)
632{ 720{
633 struct octeon_ethernet *priv = netdev_priv(dev); 721 /* Free the interrupt handler */
634 unsigned long flags; 722 free_irq(OCTEON_IRQ_TIMER1, cvm_oct_device);
635 int qos;
636
637 for (qos = 0; qos < 16; qos++) {
638 spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
639 while (skb_queue_len(&priv->tx_free_list[qos]))
640 dev_kfree_skb_any(__skb_dequeue
641 (&priv->tx_free_list[qos]));
642 spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
643 }
644} 723}
diff --git a/drivers/staging/octeon/ethernet-tx.h b/drivers/staging/octeon/ethernet-tx.h
index c0bebf750bc0..547680c6c371 100644
--- a/drivers/staging/octeon/ethernet-tx.h
+++ b/drivers/staging/octeon/ethernet-tx.h
@@ -29,29 +29,6 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev);
29int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev); 29int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev);
30int cvm_oct_transmit_qos(struct net_device *dev, void *work_queue_entry, 30int cvm_oct_transmit_qos(struct net_device *dev, void *work_queue_entry,
31 int do_free, int qos); 31 int do_free, int qos);
32void cvm_oct_tx_shutdown(struct net_device *dev); 32void cvm_oct_tx_initialize(void);
33 33void cvm_oct_tx_shutdown(void);
34/** 34void cvm_oct_tx_shutdown_dev(struct net_device *dev);
35 * Free dead transmit skbs.
36 *
37 * @priv: The driver data
38 * @skb_to_free: The number of SKBs to free (free none if negative).
39 * @qos: The queue to free from.
40 * @take_lock: If true, acquire the skb list lock.
41 */
42static inline void cvm_oct_free_tx_skbs(struct octeon_ethernet *priv,
43 int skb_to_free,
44 int qos, int take_lock)
45{
46 /* Free skbuffs not in use by the hardware. */
47 if (skb_to_free > 0) {
48 if (take_lock)
49 spin_lock(&priv->tx_free_list[qos].lock);
50 while (skb_to_free > 0) {
51 dev_kfree_skb(__skb_dequeue(&priv->tx_free_list[qos]));
52 skb_to_free--;
53 }
54 if (take_lock)
55 spin_unlock(&priv->tx_free_list[qos].lock);
56 }
57}
diff --git a/drivers/staging/octeon/ethernet-util.h b/drivers/staging/octeon/ethernet-util.h
index 37b665918000..23467563fe57 100644
--- a/drivers/staging/octeon/ethernet-util.h
+++ b/drivers/staging/octeon/ethernet-util.h
@@ -30,10 +30,9 @@
30 } while (0) 30 } while (0)
31 31
32/** 32/**
33 * Given a packet data address, return a pointer to the 33 * cvm_oct_get_buffer_ptr - convert packet data address to pointer
34 * beginning of the packet buffer.
35 *
36 * @packet_ptr: Packet data hardware address 34 * @packet_ptr: Packet data hardware address
35 *
37 * Returns Packet buffer pointer 36 * Returns Packet buffer pointer
38 */ 37 */
39static inline void *cvm_oct_get_buffer_ptr(union cvmx_buf_ptr packet_ptr) 38static inline void *cvm_oct_get_buffer_ptr(union cvmx_buf_ptr packet_ptr)
@@ -43,9 +42,7 @@ static inline void *cvm_oct_get_buffer_ptr(union cvmx_buf_ptr packet_ptr)
43} 42}
44 43
45/** 44/**
46 * Given an IPD/PKO port number, return the logical interface it is 45 * INTERFACE - convert IPD port to locgical interface
47 * on.
48 *
49 * @ipd_port: Port to check 46 * @ipd_port: Port to check
50 * 47 *
51 * Returns Logical interface 48 * Returns Logical interface
@@ -65,9 +62,7 @@ static inline int INTERFACE(int ipd_port)
65} 62}
66 63
67/** 64/**
68 * Given an IPD/PKO port number, return the port's index on a 65 * INDEX - convert IPD/PKO port number to the port's interface index
69 * logical interface.
70 *
71 * @ipd_port: Port to check 66 * @ipd_port: Port to check
72 * 67 *
73 * Returns Index into interface port list 68 * Returns Index into interface port list
diff --git a/drivers/staging/octeon/ethernet-xaui.c b/drivers/staging/octeon/ethernet-xaui.c
index ee3dc41b2c53..3fca1cc31ed8 100644
--- a/drivers/staging/octeon/ethernet-xaui.c
+++ b/drivers/staging/octeon/ethernet-xaui.c
@@ -26,7 +26,6 @@
26**********************************************************************/ 26**********************************************************************/
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/netdevice.h> 28#include <linux/netdevice.h>
29#include <linux/mii.h>
30#include <net/dst.h> 29#include <net/dst.h>
31 30
32#include <asm/octeon/octeon.h> 31#include <asm/octeon/octeon.h>
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index 220de133a6a5..4a2161f70c7f 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -29,7 +29,6 @@
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/netdevice.h> 30#include <linux/netdevice.h>
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/delay.h>
33#include <linux/phy.h> 32#include <linux/phy.h>
34 33
35#include <net/dst.h> 34#include <net/dst.h>
@@ -43,8 +42,6 @@
43#include "ethernet-tx.h" 42#include "ethernet-tx.h"
44#include "ethernet-mdio.h" 43#include "ethernet-mdio.h"
45#include "ethernet-util.h" 44#include "ethernet-util.h"
46#include "ethernet-proc.h"
47
48 45
49#include "cvmx-pip.h" 46#include "cvmx-pip.h"
50#include "cvmx-pko.h" 47#include "cvmx-pko.h"
@@ -104,13 +101,15 @@ MODULE_PARM_DESC(pow_send_list, "\n"
104 "\t\"eth2,spi3,spi7\" would cause these three devices to transmit\n" 101 "\t\"eth2,spi3,spi7\" would cause these three devices to transmit\n"
105 "\tusing the pow_send_group."); 102 "\tusing the pow_send_group.");
106 103
107static int disable_core_queueing = 1; 104int max_rx_cpus = -1;
108module_param(disable_core_queueing, int, 0444); 105module_param(max_rx_cpus, int, 0444);
109MODULE_PARM_DESC(disable_core_queueing, "\n" 106MODULE_PARM_DESC(max_rx_cpus, "\n"
110 "\tWhen set the networking core's tx_queue_len is set to zero. This\n" 107 "\t\tThe maximum number of CPUs to use for packet reception.\n"
111 "\tallows packets to be sent without lock contention in the packet\n" 108 "\t\tUse -1 to use all available CPUs.");
112 "\tscheduler resulting in some cases in improved throughput.\n");
113 109
110int rx_napi_weight = 32;
111module_param(rx_napi_weight, int, 0444);
112MODULE_PARM_DESC(rx_napi_weight, "The NAPI WEIGHT parameter.");
114 113
115/* 114/*
116 * The offset from mac_addr_base that should be used for the next port 115 * The offset from mac_addr_base that should be used for the next port
@@ -122,9 +121,16 @@ MODULE_PARM_DESC(disable_core_queueing, "\n"
122static unsigned int cvm_oct_mac_addr_offset; 121static unsigned int cvm_oct_mac_addr_offset;
123 122
124/** 123/**
125 * Periodic timer to check auto negotiation 124 * cvm_oct_poll_queue - Workqueue for polling operations.
125 */
126struct workqueue_struct *cvm_oct_poll_queue;
127
128/**
129 * cvm_oct_poll_queue_stopping - flag to indicate polling should stop.
130 *
131 * Set to one right before cvm_oct_poll_queue is destroyed.
126 */ 132 */
127static struct timer_list cvm_oct_poll_timer; 133atomic_t cvm_oct_poll_queue_stopping = ATOMIC_INIT(0);
128 134
129/** 135/**
130 * Array of every ethernet device owned by this driver indexed by 136 * Array of every ethernet device owned by this driver indexed by
@@ -132,65 +138,44 @@ static struct timer_list cvm_oct_poll_timer;
132 */ 138 */
133struct net_device *cvm_oct_device[TOTAL_NUMBER_OF_PORTS]; 139struct net_device *cvm_oct_device[TOTAL_NUMBER_OF_PORTS];
134 140
135/** 141u64 cvm_oct_tx_poll_interval;
136 * Periodic timer tick for slow management operations 142
137 * 143static void cvm_oct_rx_refill_worker(struct work_struct *work);
138 * @arg: Device to check 144static DECLARE_DELAYED_WORK(cvm_oct_rx_refill_work, cvm_oct_rx_refill_worker);
139 */ 145
140static void cvm_do_timer(unsigned long arg) 146static void cvm_oct_rx_refill_worker(struct work_struct *work)
141{ 147{
142 int32_t skb_to_free, undo; 148 /*
143 int queues_per_port; 149 * FPA 0 may have been drained, try to refill it if we need
144 int qos; 150 * more than num_packet_buffers / 2, otherwise normal receive
145 struct octeon_ethernet *priv; 151 * processing will refill it. If it were drained, no packets
146 static int port; 152 * could be received so cvm_oct_napi_poll would never be
153 * invoked to do the refill.
154 */
155 cvm_oct_rx_refill_pool(num_packet_buffers / 2);
147 156
148 if (port >= CVMX_PIP_NUM_INPUT_PORTS) { 157 if (!atomic_read(&cvm_oct_poll_queue_stopping))
149 /* 158 queue_delayed_work(cvm_oct_poll_queue,
150 * All ports have been polled. Start the next 159 &cvm_oct_rx_refill_work, HZ);
151 * iteration through the ports in one second. 160}
152 */ 161
153 port = 0; 162static void cvm_oct_periodic_worker(struct work_struct *work)
154 mod_timer(&cvm_oct_poll_timer, jiffies + HZ); 163{
155 return; 164 struct octeon_ethernet *priv = container_of(work,
156 } 165 struct octeon_ethernet,
157 if (!cvm_oct_device[port]) 166 port_periodic_work.work);
158 goto out;
159 167
160 priv = netdev_priv(cvm_oct_device[port]);
161 if (priv->poll) 168 if (priv->poll)
162 priv->poll(cvm_oct_device[port]); 169 priv->poll(cvm_oct_device[priv->port]);
163
164 queues_per_port = cvmx_pko_get_num_queues(port);
165 /* Drain any pending packets in the free list */
166 for (qos = 0; qos < queues_per_port; qos++) {
167 if (skb_queue_len(&priv->tx_free_list[qos]) == 0)
168 continue;
169 skb_to_free = cvmx_fau_fetch_and_add32(priv->fau + qos * 4,
170 MAX_SKB_TO_FREE);
171 undo = skb_to_free > 0 ?
172 MAX_SKB_TO_FREE : skb_to_free + MAX_SKB_TO_FREE;
173 if (undo > 0)
174 cvmx_fau_atomic_add32(priv->fau+qos*4, -undo);
175 skb_to_free = -skb_to_free > MAX_SKB_TO_FREE ?
176 MAX_SKB_TO_FREE : -skb_to_free;
177 cvm_oct_free_tx_skbs(priv, skb_to_free, qos, 1);
178 }
179 cvm_oct_device[port]->netdev_ops->ndo_get_stats(cvm_oct_device[port]);
180 170
181out: 171 cvm_oct_device[priv->port]->netdev_ops->ndo_get_stats(cvm_oct_device[priv->port]);
182 port++; 172
183 /* Poll the next port in a 50th of a second. 173 if (!atomic_read(&cvm_oct_poll_queue_stopping))
184 This spreads the polling of ports out a little bit */ 174 queue_delayed_work(cvm_oct_poll_queue, &priv->port_periodic_work, HZ);
185 mod_timer(&cvm_oct_poll_timer, jiffies + HZ / 50); 175 }
186}
187 176
188/**
189 * Configure common hardware for all interfaces
190 */
191static __init void cvm_oct_configure_common_hw(void) 177static __init void cvm_oct_configure_common_hw(void)
192{ 178{
193 int r;
194 /* Setup the FPA */ 179 /* Setup the FPA */
195 cvmx_fpa_enable(); 180 cvmx_fpa_enable();
196 cvm_oct_mem_fill_fpa(CVMX_FPA_PACKET_POOL, CVMX_FPA_PACKET_POOL_SIZE, 181 cvm_oct_mem_fill_fpa(CVMX_FPA_PACKET_POOL, CVMX_FPA_PACKET_POOL_SIZE,
@@ -205,28 +190,13 @@ static __init void cvm_oct_configure_common_hw(void)
205 cvmx_helper_setup_red(num_packet_buffers / 4, 190 cvmx_helper_setup_red(num_packet_buffers / 4,
206 num_packet_buffers / 8); 191 num_packet_buffers / 8);
207 192
208 /* Enable the MII interface */
209 if (!octeon_is_simulation())
210 cvmx_write_csr(CVMX_SMIX_EN(0), 1);
211
212 /* Register an IRQ hander for to receive POW interrupts */
213 r = request_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group,
214 cvm_oct_do_interrupt, IRQF_SHARED, "Ethernet",
215 cvm_oct_device);
216
217#if defined(CONFIG_SMP) && 0
218 if (USE_MULTICORE_RECEIVE) {
219 irq_set_affinity(OCTEON_IRQ_WORKQ0 + pow_receive_group,
220 cpu_online_mask);
221 }
222#endif
223} 193}
224 194
225/** 195/**
226 * Free a work queue entry received in a intercept callback. 196 * cvm_oct_free_work- Free a work queue entry
197 *
198 * @work_queue_entry: Work queue entry to free
227 * 199 *
228 * @work_queue_entry:
229 * Work queue entry to free
230 * Returns Zero on success, Negative on failure. 200 * Returns Zero on success, Negative on failure.
231 */ 201 */
232int cvm_oct_free_work(void *work_queue_entry) 202int cvm_oct_free_work(void *work_queue_entry)
@@ -253,9 +223,9 @@ int cvm_oct_free_work(void *work_queue_entry)
253EXPORT_SYMBOL(cvm_oct_free_work); 223EXPORT_SYMBOL(cvm_oct_free_work);
254 224
255/** 225/**
256 * Get the low level ethernet statistics 226 * cvm_oct_common_get_stats - get the low level ethernet statistics
257 *
258 * @dev: Device to get the statistics from 227 * @dev: Device to get the statistics from
228 *
259 * Returns Pointer to the statistics 229 * Returns Pointer to the statistics
260 */ 230 */
261static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev) 231static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
@@ -299,8 +269,7 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
299} 269}
300 270
301/** 271/**
302 * Change the link MTU. Unimplemented 272 * cvm_oct_common_change_mtu - change the link MTU
303 *
304 * @dev: Device to change 273 * @dev: Device to change
305 * @new_mtu: The new MTU 274 * @new_mtu: The new MTU
306 * 275 *
@@ -364,8 +333,7 @@ static int cvm_oct_common_change_mtu(struct net_device *dev, int new_mtu)
364} 333}
365 334
366/** 335/**
367 * Set the multicast list. Currently unimplemented. 336 * cvm_oct_common_set_multicast_list - set the multicast list
368 *
369 * @dev: Device to work on 337 * @dev: Device to work on
370 */ 338 */
371static void cvm_oct_common_set_multicast_list(struct net_device *dev) 339static void cvm_oct_common_set_multicast_list(struct net_device *dev)
@@ -420,10 +388,10 @@ static void cvm_oct_common_set_multicast_list(struct net_device *dev)
420} 388}
421 389
422/** 390/**
423 * Set the hardware MAC address for a device 391 * cvm_oct_common_set_mac_address - set the hardware MAC address for a device
424 * 392 * @dev: The device in question.
425 * @dev: Device to change the MAC address for 393 * @addr: Address structure to change it too.
426 * @addr: Address structure to change it too. MAC address is addr + 2. 394
427 * Returns Zero on success 395 * Returns Zero on success
428 */ 396 */
429static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr) 397static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr)
@@ -470,9 +438,9 @@ static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr)
470} 438}
471 439
472/** 440/**
473 * Per network device initialization 441 * cvm_oct_common_init - per network device initialization
474 *
475 * @dev: Device to initialize 442 * @dev: Device to initialize
443 *
476 * Returns Zero on success 444 * Returns Zero on success
477 */ 445 */
478int cvm_oct_common_init(struct net_device *dev) 446int cvm_oct_common_init(struct net_device *dev)
@@ -510,8 +478,11 @@ int cvm_oct_common_init(struct net_device *dev)
510 && (always_use_pow || strstr(pow_send_list, dev->name))) 478 && (always_use_pow || strstr(pow_send_list, dev->name)))
511 priv->queue = -1; 479 priv->queue = -1;
512 480
513 if (priv->queue != -1 && USE_HW_TCPUDP_CHECKSUM) 481 if (priv->queue != -1) {
514 dev->features |= NETIF_F_IP_CSUM; 482 dev->features |= NETIF_F_SG;
483 if (USE_HW_TCPUDP_CHECKSUM)
484 dev->features |= NETIF_F_IP_CSUM;
485 }
515 486
516 /* We do our own locking, Linux doesn't need to */ 487 /* We do our own locking, Linux doesn't need to */
517 dev->features |= NETIF_F_LLTX; 488 dev->features |= NETIF_F_LLTX;
@@ -625,12 +596,6 @@ static const struct net_device_ops cvm_oct_pow_netdev_ops = {
625 596
626extern void octeon_mdiobus_force_mod_depencency(void); 597extern void octeon_mdiobus_force_mod_depencency(void);
627 598
628/**
629 * Module/ driver initialization. Creates the linux network
630 * devices.
631 *
632 * Returns Zero on success
633 */
634static int __init cvm_oct_init_module(void) 599static int __init cvm_oct_init_module(void)
635{ 600{
636 int num_interfaces; 601 int num_interfaces;
@@ -648,8 +613,12 @@ static int __init cvm_oct_init_module(void)
648 else 613 else
649 cvm_oct_mac_addr_offset = 0; 614 cvm_oct_mac_addr_offset = 0;
650 615
651 cvm_oct_proc_initialize(); 616 cvm_oct_poll_queue = create_singlethread_workqueue("octeon-ethernet");
652 cvm_oct_rx_initialize(); 617 if (cvm_oct_poll_queue == NULL) {
618 pr_err("octeon-ethernet: Cannot create workqueue");
619 return -ENOMEM;
620 }
621
653 cvm_oct_configure_common_hw(); 622 cvm_oct_configure_common_hw();
654 623
655 cvmx_helper_initialize_packet_io_global(); 624 cvmx_helper_initialize_packet_io_global();
@@ -682,6 +651,9 @@ static int __init cvm_oct_init_module(void)
682 */ 651 */
683 cvmx_fau_atomic_write32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0); 652 cvmx_fau_atomic_write32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0);
684 653
654 /* Initialize the FAU used for counting tx SKBs that need to be freed */
655 cvmx_fau_atomic_write32(FAU_TOTAL_TX_TO_CLEAN, 0);
656
685 if ((pow_send_group != -1)) { 657 if ((pow_send_group != -1)) {
686 struct net_device *dev; 658 struct net_device *dev;
687 pr_info("\tConfiguring device for POW only access\n"); 659 pr_info("\tConfiguring device for POW only access\n");
@@ -689,7 +661,6 @@ static int __init cvm_oct_init_module(void)
689 if (dev) { 661 if (dev) {
690 /* Initialize the device private structure. */ 662 /* Initialize the device private structure. */
691 struct octeon_ethernet *priv = netdev_priv(dev); 663 struct octeon_ethernet *priv = netdev_priv(dev);
692 memset(priv, 0, sizeof(struct octeon_ethernet));
693 664
694 dev->netdev_ops = &cvm_oct_pow_netdev_ops; 665 dev->netdev_ops = &cvm_oct_pow_netdev_ops;
695 priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED; 666 priv->imode = CVMX_HELPER_INTERFACE_MODE_DISABLED;
@@ -700,19 +671,16 @@ static int __init cvm_oct_init_module(void)
700 skb_queue_head_init(&priv->tx_free_list[qos]); 671 skb_queue_head_init(&priv->tx_free_list[qos]);
701 672
702 if (register_netdev(dev) < 0) { 673 if (register_netdev(dev) < 0) {
703 pr_err("Failed to register ethernet " 674 pr_err("Failed to register ethernet device for POW\n");
704 "device for POW\n");
705 kfree(dev); 675 kfree(dev);
706 } else { 676 } else {
707 cvm_oct_device[CVMX_PIP_NUM_INPUT_PORTS] = dev; 677 cvm_oct_device[CVMX_PIP_NUM_INPUT_PORTS] = dev;
708 pr_info("%s: POW send group %d, receive " 678 pr_info("%s: POW send group %d, receive group %d\n",
709 "group %d\n", 679 dev->name, pow_send_group,
710 dev->name, pow_send_group, 680 pow_receive_group);
711 pow_receive_group);
712 } 681 }
713 } else { 682 } else {
714 pr_err("Failed to allocate ethernet device " 683 pr_err("Failed to allocate ethernet device for POW\n");
715 "for POW\n");
716 } 684 }
717 } 685 }
718 686
@@ -730,17 +698,15 @@ static int __init cvm_oct_init_module(void)
730 struct net_device *dev = 698 struct net_device *dev =
731 alloc_etherdev(sizeof(struct octeon_ethernet)); 699 alloc_etherdev(sizeof(struct octeon_ethernet));
732 if (!dev) { 700 if (!dev) {
733 pr_err("Failed to allocate ethernet device " 701 pr_err("Failed to allocate ethernet device for port %d\n", port);
734 "for port %d\n", port);
735 continue; 702 continue;
736 } 703 }
737 if (disable_core_queueing)
738 dev->tx_queue_len = 0;
739 704
740 /* Initialize the device private structure. */ 705 /* Initialize the device private structure. */
741 priv = netdev_priv(dev); 706 priv = netdev_priv(dev);
742 memset(priv, 0, sizeof(struct octeon_ethernet));
743 707
708 INIT_DELAYED_WORK(&priv->port_periodic_work,
709 cvm_oct_periodic_worker);
744 priv->imode = imode; 710 priv->imode = imode;
745 priv->port = port; 711 priv->port = port;
746 priv->queue = cvmx_pko_get_base_queue(priv->port); 712 priv->queue = cvmx_pko_get_base_queue(priv->port);
@@ -803,44 +769,25 @@ static int __init cvm_oct_init_module(void)
803 fau -= 769 fau -=
804 cvmx_pko_get_num_queues(priv->port) * 770 cvmx_pko_get_num_queues(priv->port) *
805 sizeof(uint32_t); 771 sizeof(uint32_t);
772 queue_delayed_work(cvm_oct_poll_queue,
773 &priv->port_periodic_work, HZ);
806 } 774 }
807 } 775 }
808 } 776 }
809 777
810 if (INTERRUPT_LIMIT) { 778 cvm_oct_tx_initialize();
811 /* 779 cvm_oct_rx_initialize();
812 * Set the POW timer rate to give an interrupt at most
813 * INTERRUPT_LIMIT times per second.
814 */
815 cvmx_write_csr(CVMX_POW_WQ_INT_PC,
816 octeon_bootinfo->eclock_hz / (INTERRUPT_LIMIT *
817 16 * 256) << 8);
818 780
819 /* 781 /*
820 * Enable POW timer interrupt. It will count when 782 * 150 uS: about 10 1500-byte packtes at 1GE.
821 * there are packets available. 783 */
822 */ 784 cvm_oct_tx_poll_interval = 150 * (octeon_get_clock_rate() / 1000000);
823 cvmx_write_csr(CVMX_POW_WQ_INT_THRX(pow_receive_group),
824 0x1ful << 24);
825 } else {
826 /* Enable POW interrupt when our port has at least one packet */
827 cvmx_write_csr(CVMX_POW_WQ_INT_THRX(pow_receive_group), 0x1001);
828 }
829 785
830 /* Enable the poll timer for checking RGMII status */ 786 queue_delayed_work(cvm_oct_poll_queue, &cvm_oct_rx_refill_work, HZ);
831 init_timer(&cvm_oct_poll_timer);
832 cvm_oct_poll_timer.data = 0;
833 cvm_oct_poll_timer.function = cvm_do_timer;
834 mod_timer(&cvm_oct_poll_timer, jiffies + HZ);
835 787
836 return 0; 788 return 0;
837} 789}
838 790
839/**
840 * Module / driver shutdown
841 *
842 * Returns Zero on success
843 */
844static void __exit cvm_oct_cleanup_module(void) 791static void __exit cvm_oct_cleanup_module(void)
845{ 792{
846 int port; 793 int port;
@@ -853,22 +800,31 @@ static void __exit cvm_oct_cleanup_module(void)
853 /* Free the interrupt handler */ 800 /* Free the interrupt handler */
854 free_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group, cvm_oct_device); 801 free_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group, cvm_oct_device);
855 802
856 del_timer(&cvm_oct_poll_timer); 803 atomic_inc_return(&cvm_oct_poll_queue_stopping);
804 cancel_delayed_work_sync(&cvm_oct_rx_refill_work);
805
857 cvm_oct_rx_shutdown(); 806 cvm_oct_rx_shutdown();
807 cvm_oct_tx_shutdown();
808
858 cvmx_pko_disable(); 809 cvmx_pko_disable();
859 810
860 /* Free the ethernet devices */ 811 /* Free the ethernet devices */
861 for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) { 812 for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) {
862 if (cvm_oct_device[port]) { 813 if (cvm_oct_device[port]) {
863 cvm_oct_tx_shutdown(cvm_oct_device[port]); 814 struct net_device *dev = cvm_oct_device[port];
864 unregister_netdev(cvm_oct_device[port]); 815 struct octeon_ethernet *priv = netdev_priv(dev);
865 kfree(cvm_oct_device[port]); 816 cancel_delayed_work_sync(&priv->port_periodic_work);
817
818 cvm_oct_tx_shutdown_dev(dev);
819 unregister_netdev(dev);
820 kfree(dev);
866 cvm_oct_device[port] = NULL; 821 cvm_oct_device[port] = NULL;
867 } 822 }
868 } 823 }
869 824
825 destroy_workqueue(cvm_oct_poll_queue);
826
870 cvmx_pko_shutdown(); 827 cvmx_pko_shutdown();
871 cvm_oct_proc_shutdown();
872 828
873 cvmx_ipd_free_ptr(); 829 cvmx_ipd_free_ptr();
874 830
diff --git a/drivers/staging/octeon/octeon-ethernet.h b/drivers/staging/octeon/octeon-ethernet.h
index 402a15b9bb0e..d58192563552 100644
--- a/drivers/staging/octeon/octeon-ethernet.h
+++ b/drivers/staging/octeon/octeon-ethernet.h
@@ -4,7 +4,7 @@
4 * Contact: support@caviumnetworks.com 4 * Contact: support@caviumnetworks.com
5 * This file is part of the OCTEON SDK 5 * This file is part of the OCTEON SDK
6 * 6 *
7 * Copyright (c) 2003-2007 Cavium Networks 7 * Copyright (c) 2003-2010 Cavium Networks
8 * 8 *
9 * This file is free software; you can redistribute it and/or modify 9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as 10 * it under the terms of the GNU General Public License, Version 2, as
@@ -57,58 +57,12 @@ struct octeon_ethernet {
57 uint64_t link_info; 57 uint64_t link_info;
58 /* Called periodically to check link status */ 58 /* Called periodically to check link status */
59 void (*poll) (struct net_device *dev); 59 void (*poll) (struct net_device *dev);
60 struct delayed_work port_periodic_work;
61 struct work_struct port_work; /* may be unused. */
60}; 62};
61 63
62/**
63 * Free a work queue entry received in a intercept callback.
64 *
65 * @work_queue_entry:
66 * Work queue entry to free
67 * Returns Zero on success, Negative on failure.
68 */
69int cvm_oct_free_work(void *work_queue_entry); 64int cvm_oct_free_work(void *work_queue_entry);
70 65
71/**
72 * Transmit a work queue entry out of the ethernet port. Both
73 * the work queue entry and the packet data can optionally be
74 * freed. The work will be freed on error as well.
75 *
76 * @dev: Device to transmit out.
77 * @work_queue_entry:
78 * Work queue entry to send
79 * @do_free: True if the work queue entry and packet data should be
80 * freed. If false, neither will be freed.
81 * @qos: Index into the queues for this port to transmit on. This
82 * is used to implement QoS if their are multiple queues per
83 * port. This parameter must be between 0 and the number of
84 * queues per port minus 1. Values outside of this range will
85 * be change to zero.
86 *
87 * Returns Zero on success, negative on failure.
88 */
89int cvm_oct_transmit_qos(struct net_device *dev, void *work_queue_entry,
90 int do_free, int qos);
91
92/**
93 * Transmit a work queue entry out of the ethernet port. Both
94 * the work queue entry and the packet data can optionally be
95 * freed. The work will be freed on error as well. This simply
96 * wraps cvmx_oct_transmit_qos() for backwards compatability.
97 *
98 * @dev: Device to transmit out.
99 * @work_queue_entry:
100 * Work queue entry to send
101 * @do_free: True if the work queue entry and packet data should be
102 * freed. If false, neither will be freed.
103 *
104 * Returns Zero on success, negative on failure.
105 */
106static inline int cvm_oct_transmit(struct net_device *dev,
107 void *work_queue_entry, int do_free)
108{
109 return cvm_oct_transmit_qos(dev, work_queue_entry, do_free, 0);
110}
111
112extern int cvm_oct_rgmii_init(struct net_device *dev); 66extern int cvm_oct_rgmii_init(struct net_device *dev);
113extern void cvm_oct_rgmii_uninit(struct net_device *dev); 67extern void cvm_oct_rgmii_uninit(struct net_device *dev);
114extern int cvm_oct_rgmii_open(struct net_device *dev); 68extern int cvm_oct_rgmii_open(struct net_device *dev);
@@ -134,5 +88,11 @@ extern int pow_send_group;
134extern int pow_receive_group; 88extern int pow_receive_group;
135extern char pow_send_list[]; 89extern char pow_send_list[];
136extern struct net_device *cvm_oct_device[]; 90extern struct net_device *cvm_oct_device[];
91extern struct workqueue_struct *cvm_oct_poll_queue;
92extern atomic_t cvm_oct_poll_queue_stopping;
93extern u64 cvm_oct_tx_poll_interval;
94
95extern int max_rx_cpus;
96extern int rx_napi_weight;
137 97
138#endif 98#endif
diff --git a/drivers/staging/sm7xx/smtc2d.c b/drivers/staging/sm7xx/smtc2d.c
index 133b86c6a678..2fff0a0052d1 100644
--- a/drivers/staging/sm7xx/smtc2d.c
+++ b/drivers/staging/sm7xx/smtc2d.c
@@ -5,7 +5,7 @@
5 * Author: Boyod boyod.yang@siliconmotion.com.cn 5 * Author: Boyod boyod.yang@siliconmotion.com.cn
6 * 6 *
7 * Copyright (C) 2009 Lemote, Inc. 7 * Copyright (C) 2009 Lemote, Inc.
8 * Author: Wu Zhangjin, wuzj@lemote.com 8 * Author: Wu Zhangjin, wuzhangjin@gmail.com
9 * 9 *
10 * This file is subject to the terms and conditions of the GNU General Public 10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive for 11 * License. See the file COPYING in the main directory of this archive for
diff --git a/drivers/staging/sm7xx/smtc2d.h b/drivers/staging/sm7xx/smtc2d.h
index 38d0c335322b..02b4fa29136c 100644
--- a/drivers/staging/sm7xx/smtc2d.h
+++ b/drivers/staging/sm7xx/smtc2d.h
@@ -5,7 +5,7 @@
5 * Author: Ge Wang, gewang@siliconmotion.com 5 * Author: Ge Wang, gewang@siliconmotion.com
6 * 6 *
7 * Copyright (C) 2009 Lemote, Inc. 7 * Copyright (C) 2009 Lemote, Inc.
8 * Author: Wu Zhangjin, wuzj@lemote.com 8 * Author: Wu Zhangjin, wuzhangjin@gmail.com
9 * 9 *
10 * This file is subject to the terms and conditions of the GNU General Public 10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive for 11 * License. See the file COPYING in the main directory of this archive for
diff --git a/drivers/staging/sm7xx/smtcfb.c b/drivers/staging/sm7xx/smtcfb.c
index 161dbc9c1397..a4f6f49aef48 100644
--- a/drivers/staging/sm7xx/smtcfb.c
+++ b/drivers/staging/sm7xx/smtcfb.c
@@ -6,7 +6,7 @@
6 * Boyod boyod.yang@siliconmotion.com.cn 6 * Boyod boyod.yang@siliconmotion.com.cn
7 * 7 *
8 * Copyright (C) 2009 Lemote, Inc. 8 * Copyright (C) 2009 Lemote, Inc.
9 * Author: Wu Zhangjin, wuzj@lemote.com 9 * Author: Wu Zhangjin, wuzhangjin@gmail.com
10 * 10 *
11 * This file is subject to the terms and conditions of the GNU General Public 11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file COPYING in the main directory of this archive for 12 * License. See the file COPYING in the main directory of this archive for
diff --git a/drivers/staging/sm7xx/smtcfb.h b/drivers/staging/sm7xx/smtcfb.h
index 7f2c34138215..7ee565c2c952 100644
--- a/drivers/staging/sm7xx/smtcfb.h
+++ b/drivers/staging/sm7xx/smtcfb.h
@@ -6,7 +6,7 @@
6 * Boyod boyod.yang@siliconmotion.com.cn 6 * Boyod boyod.yang@siliconmotion.com.cn
7 * 7 *
8 * Copyright (C) 2009 Lemote, Inc. 8 * Copyright (C) 2009 Lemote, Inc.
9 * Author: Wu Zhangjin, wuzj@lemote.com 9 * Author: Wu Zhangjin, wuzhangjin@gmail.com
10 * 10 *
11 * This file is subject to the terms and conditions of the GNU General Public 11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file COPYING in the main directory of this archive for 12 * License. See the file COPYING in the main directory of this archive for
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 60a45f1e3a67..f2f055eb6831 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1022,6 +1022,14 @@ static int usb_resume_device(struct usb_device *udev, pm_message_t msg)
1022 goto done; 1022 goto done;
1023 } 1023 }
1024 1024
1025 /* Non-root devices on a full/low-speed bus must wait for their
1026 * companion high-speed root hub, in case a handoff is needed.
1027 */
1028 if (!(msg.event & PM_EVENT_AUTO) && udev->parent &&
1029 udev->bus->hs_companion)
1030 device_pm_wait_for_dev(&udev->dev,
1031 &udev->bus->hs_companion->root_hub->dev);
1032
1025 if (udev->quirks & USB_QUIRK_RESET_RESUME) 1033 if (udev->quirks & USB_QUIRK_RESET_RESUME)
1026 udev->reset_resume = 1; 1034 udev->reset_resume = 1;
1027 1035
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index fdfaa7885515..d26b9ea981f9 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -186,6 +186,7 @@ int usb_create_ep_devs(struct device *parent,
186 ep_dev->dev.parent = parent; 186 ep_dev->dev.parent = parent;
187 ep_dev->dev.release = ep_device_release; 187 ep_dev->dev.release = ep_device_release;
188 dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress); 188 dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress);
189 device_enable_async_suspend(&ep_dev->dev);
189 190
190 retval = device_register(&ep_dev->dev); 191 retval = device_register(&ep_dev->dev);
191 if (retval) 192 if (retval)
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 2dcf906df569..15286533c15a 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -19,6 +19,7 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/pm_runtime.h>
22#include <linux/usb.h> 23#include <linux/usb.h>
23 24
24#include <asm/io.h> 25#include <asm/io.h>
@@ -37,6 +38,122 @@
37 38
38/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ 39/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
39 40
41#ifdef CONFIG_PM_SLEEP
42
43/* Coordinate handoffs between EHCI and companion controllers
44 * during system resume
45 */
46
47static DEFINE_MUTEX(companions_mutex);
48
49#define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI
50#define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI
51#define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI
52
53enum companion_action {
54 SET_HS_COMPANION, CLEAR_HS_COMPANION, WAIT_FOR_COMPANIONS
55};
56
57static void companion_common(struct pci_dev *pdev, struct usb_hcd *hcd,
58 enum companion_action action)
59{
60 struct pci_dev *companion;
61 struct usb_hcd *companion_hcd;
62 unsigned int slot = PCI_SLOT(pdev->devfn);
63
64 /* Iterate through other PCI functions in the same slot.
65 * If pdev is OHCI or UHCI then we are looking for EHCI, and
66 * vice versa.
67 */
68 companion = NULL;
69 for (;;) {
70 companion = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, companion);
71 if (!companion)
72 break;
73 if (companion->bus != pdev->bus ||
74 PCI_SLOT(companion->devfn) != slot)
75 continue;
76
77 companion_hcd = pci_get_drvdata(companion);
78 if (!companion_hcd)
79 continue;
80
81 /* For SET_HS_COMPANION, store a pointer to the EHCI bus in
82 * the OHCI/UHCI companion bus structure.
83 * For CLEAR_HS_COMPANION, clear the pointer to the EHCI bus
84 * in the OHCI/UHCI companion bus structure.
85 * For WAIT_FOR_COMPANIONS, wait until the OHCI/UHCI
86 * companion controllers have fully resumed.
87 */
88
89 if ((pdev->class == CL_OHCI || pdev->class == CL_UHCI) &&
90 companion->class == CL_EHCI) {
91 /* action must be SET_HS_COMPANION */
92 dev_dbg(&companion->dev, "HS companion for %s\n",
93 dev_name(&pdev->dev));
94 hcd->self.hs_companion = &companion_hcd->self;
95
96 } else if (pdev->class == CL_EHCI &&
97 (companion->class == CL_OHCI ||
98 companion->class == CL_UHCI)) {
99 switch (action) {
100 case SET_HS_COMPANION:
101 dev_dbg(&pdev->dev, "HS companion for %s\n",
102 dev_name(&companion->dev));
103 companion_hcd->self.hs_companion = &hcd->self;
104 break;
105 case CLEAR_HS_COMPANION:
106 companion_hcd->self.hs_companion = NULL;
107 break;
108 case WAIT_FOR_COMPANIONS:
109 device_pm_wait_for_dev(&pdev->dev,
110 &companion->dev);
111 break;
112 }
113 }
114 }
115}
116
117static void set_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd)
118{
119 mutex_lock(&companions_mutex);
120 dev_set_drvdata(&pdev->dev, hcd);
121 companion_common(pdev, hcd, SET_HS_COMPANION);
122 mutex_unlock(&companions_mutex);
123}
124
125static void clear_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd)
126{
127 mutex_lock(&companions_mutex);
128 dev_set_drvdata(&pdev->dev, NULL);
129
130 /* If pdev is OHCI or UHCI, just clear its hs_companion pointer */
131 if (pdev->class == CL_OHCI || pdev->class == CL_UHCI)
132 hcd->self.hs_companion = NULL;
133
134 /* Otherwise search for companion buses and clear their pointers */
135 else
136 companion_common(pdev, hcd, CLEAR_HS_COMPANION);
137 mutex_unlock(&companions_mutex);
138}
139
140static void wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd)
141{
142 /* Only EHCI controllers need to wait.
143 * No locking is needed because a controller cannot be resumed
144 * while one of its companions is getting unbound.
145 */
146 if (pdev->class == CL_EHCI)
147 companion_common(pdev, hcd, WAIT_FOR_COMPANIONS);
148}
149
150#else /* !CONFIG_PM_SLEEP */
151
152static inline void set_hs_companion(struct pci_dev *d, struct usb_hcd *h) {}
153static inline void clear_hs_companion(struct pci_dev *d, struct usb_hcd *h) {}
154static inline void wait_for_companions(struct pci_dev *d, struct usb_hcd *h) {}
155
156#endif /* !CONFIG_PM_SLEEP */
40 157
41/*-------------------------------------------------------------------------*/ 158/*-------------------------------------------------------------------------*/
42 159
@@ -123,7 +240,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
123 if (region == PCI_ROM_RESOURCE) { 240 if (region == PCI_ROM_RESOURCE) {
124 dev_dbg(&dev->dev, "no i/o regions available\n"); 241 dev_dbg(&dev->dev, "no i/o regions available\n");
125 retval = -EBUSY; 242 retval = -EBUSY;
126 goto err1; 243 goto err2;
127 } 244 }
128 } 245 }
129 246
@@ -132,6 +249,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
132 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); 249 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
133 if (retval != 0) 250 if (retval != 0)
134 goto err4; 251 goto err4;
252 set_hs_companion(dev, hcd);
135 return retval; 253 return retval;
136 254
137 err4: 255 err4:
@@ -142,6 +260,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
142 } else 260 } else
143 release_region(hcd->rsrc_start, hcd->rsrc_len); 261 release_region(hcd->rsrc_start, hcd->rsrc_len);
144 err2: 262 err2:
263 clear_hs_companion(dev, hcd);
145 usb_put_hcd(hcd); 264 usb_put_hcd(hcd);
146 err1: 265 err1:
147 pci_disable_device(dev); 266 pci_disable_device(dev);
@@ -180,6 +299,7 @@ void usb_hcd_pci_remove(struct pci_dev *dev)
180 } else { 299 } else {
181 release_region(hcd->rsrc_start, hcd->rsrc_len); 300 release_region(hcd->rsrc_start, hcd->rsrc_len);
182 } 301 }
302 clear_hs_companion(dev, hcd);
183 usb_put_hcd(hcd); 303 usb_put_hcd(hcd);
184 pci_disable_device(dev); 304 pci_disable_device(dev);
185} 305}
@@ -344,6 +464,11 @@ static int resume_common(struct device *dev, bool hibernated)
344 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 464 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
345 465
346 if (hcd->driver->pci_resume) { 466 if (hcd->driver->pci_resume) {
467 /* This call should be made only during system resume,
468 * not during runtime resume.
469 */
470 wait_for_companions(pci_dev, hcd);
471
347 retval = hcd->driver->pci_resume(hcd, hibernated); 472 retval = hcd->driver->pci_resume(hcd, hibernated);
348 if (retval) { 473 if (retval) {
349 dev_err(dev, "PCI post-resume error %d!\n", retval); 474 dev_err(dev, "PCI post-resume error %d!\n", retval);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 35cc8b9ba1f5..20ecb4cec8de 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1817,6 +1817,7 @@ int usb_new_device(struct usb_device *udev)
1817 /* Tell the world! */ 1817 /* Tell the world! */
1818 announce_device(udev); 1818 announce_device(udev);
1819 1819
1820 device_enable_async_suspend(&udev->dev);
1820 /* Register the device. The device driver is responsible 1821 /* Register the device. The device driver is responsible
1821 * for configuring the device and invoking the add-device 1822 * for configuring the device and invoking the add-device
1822 * notifier chain (used by usbfs and possibly others). 1823 * notifier chain (used by usbfs and possibly others).
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 9bc95fec793f..df73574a9cc9 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1867,6 +1867,7 @@ free_interfaces:
1867 "adding %s (config #%d, interface %d)\n", 1867 "adding %s (config #%d, interface %d)\n",
1868 dev_name(&intf->dev), configuration, 1868 dev_name(&intf->dev), configuration,
1869 intf->cur_altsetting->desc.bInterfaceNumber); 1869 intf->cur_altsetting->desc.bInterfaceNumber);
1870 device_enable_async_suspend(&intf->dev);
1870 ret = device_add(&intf->dev); 1871 ret = device_add(&intf->dev);
1871 if (ret != 0) { 1872 if (ret != 0) {
1872 dev_err(&dev->dev, "device_add(%s) --> %d\n", 1873 dev_err(&dev->dev, "device_add(%s) --> %d\n",
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index e9f995486ec1..bbeeb92a2131 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -78,7 +78,7 @@ MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
78MODULE_DESCRIPTION("USB Mass Storage driver for Linux"); 78MODULE_DESCRIPTION("USB Mass Storage driver for Linux");
79MODULE_LICENSE("GPL"); 79MODULE_LICENSE("GPL");
80 80
81static unsigned int delay_use = 5; 81static unsigned int delay_use = 1;
82module_param(delay_use, uint, S_IRUGO | S_IWUSR); 82module_param(delay_use, uint, S_IRUGO | S_IWUSR);
83MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device"); 83MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device");
84 84
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index e4e4d433b007..9ee67d6da710 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -1931,22 +1931,22 @@ static int __devinit aty128_init(struct pci_dev *pdev, const struct pci_device_i
1931 * PowerMac2,2 summer 2000 iMacs 1931 * PowerMac2,2 summer 2000 iMacs
1932 * PowerMac4,1 january 2001 iMacs "flower power" 1932 * PowerMac4,1 january 2001 iMacs "flower power"
1933 */ 1933 */
1934 if (machine_is_compatible("PowerMac2,1") || 1934 if (of_machine_is_compatible("PowerMac2,1") ||
1935 machine_is_compatible("PowerMac2,2") || 1935 of_machine_is_compatible("PowerMac2,2") ||
1936 machine_is_compatible("PowerMac4,1")) 1936 of_machine_is_compatible("PowerMac4,1"))
1937 default_vmode = VMODE_1024_768_75; 1937 default_vmode = VMODE_1024_768_75;
1938 1938
1939 /* iBook SE */ 1939 /* iBook SE */
1940 if (machine_is_compatible("PowerBook2,2")) 1940 if (of_machine_is_compatible("PowerBook2,2"))
1941 default_vmode = VMODE_800_600_60; 1941 default_vmode = VMODE_800_600_60;
1942 1942
1943 /* PowerBook Firewire (Pismo), iBook Dual USB */ 1943 /* PowerBook Firewire (Pismo), iBook Dual USB */
1944 if (machine_is_compatible("PowerBook3,1") || 1944 if (of_machine_is_compatible("PowerBook3,1") ||
1945 machine_is_compatible("PowerBook4,1")) 1945 of_machine_is_compatible("PowerBook4,1"))
1946 default_vmode = VMODE_1024_768_60; 1946 default_vmode = VMODE_1024_768_60;
1947 1947
1948 /* PowerBook Titanium */ 1948 /* PowerBook Titanium */
1949 if (machine_is_compatible("PowerBook3,2")) 1949 if (of_machine_is_compatible("PowerBook3,2"))
1950 default_vmode = VMODE_1152_768_60; 1950 default_vmode = VMODE_1152_768_60;
1951 1951
1952 if (default_cmode > 16) 1952 if (default_cmode > 16)
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 1ddeb4c34763..e45ab8db2ddc 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2439,7 +2439,7 @@ static int __devinit aty_init(struct fb_info *info)
2439 * The Apple iBook1 uses non-standard memory frequencies. 2439 * The Apple iBook1 uses non-standard memory frequencies.
2440 * We detect it and set the frequency manually. 2440 * We detect it and set the frequency manually.
2441 */ 2441 */
2442 if (machine_is_compatible("PowerBook2,1")) { 2442 if (of_machine_is_compatible("PowerBook2,1")) {
2443 par->pll_limits.mclk = 70; 2443 par->pll_limits.mclk = 70;
2444 par->pll_limits.xclk = 53; 2444 par->pll_limits.xclk = 53;
2445 } 2445 }
@@ -2659,7 +2659,7 @@ static int __devinit aty_init(struct fb_info *info)
2659 FBINFO_HWACCEL_YPAN; 2659 FBINFO_HWACCEL_YPAN;
2660 2660
2661#ifdef CONFIG_PMAC_BACKLIGHT 2661#ifdef CONFIG_PMAC_BACKLIGHT
2662 if (M64_HAS(G3_PB_1_1) && machine_is_compatible("PowerBook1,1")) { 2662 if (M64_HAS(G3_PB_1_1) && of_machine_is_compatible("PowerBook1,1")) {
2663 /* 2663 /*
2664 * these bits let the 101 powerbook 2664 * these bits let the 101 powerbook
2665 * wake up from sleep -- paulus 2665 * wake up from sleep -- paulus
@@ -2690,9 +2690,9 @@ static int __devinit aty_init(struct fb_info *info)
2690 if (M64_HAS(G3_PB_1024x768)) 2690 if (M64_HAS(G3_PB_1024x768))
2691 /* G3 PowerBook with 1024x768 LCD */ 2691 /* G3 PowerBook with 1024x768 LCD */
2692 default_vmode = VMODE_1024_768_60; 2692 default_vmode = VMODE_1024_768_60;
2693 else if (machine_is_compatible("iMac")) 2693 else if (of_machine_is_compatible("iMac"))
2694 default_vmode = VMODE_1024_768_75; 2694 default_vmode = VMODE_1024_768_75;
2695 else if (machine_is_compatible("PowerBook2,1")) 2695 else if (of_machine_is_compatible("PowerBook2,1"))
2696 /* iBook with 800x600 LCD */ 2696 /* iBook with 800x600 LCD */
2697 default_vmode = VMODE_800_600_60; 2697 default_vmode = VMODE_800_600_60;
2698 else 2698 else
@@ -3104,7 +3104,7 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
3104 } 3104 }
3105 3105
3106 dp = pci_device_to_OF_node(pdev); 3106 dp = pci_device_to_OF_node(pdev);
3107 if (node == dp->node) { 3107 if (node == dp->phandle) {
3108 struct fb_var_screeninfo *var = &default_var; 3108 struct fb_var_screeninfo *var = &default_var;
3109 unsigned int N, P, Q, M, T, R; 3109 unsigned int N, P, Q, M, T, R;
3110 u32 v_total, h_total; 3110 u32 v_total, h_total;
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
index 1a056adb61c8..fa1198c4ccc5 100644
--- a/drivers/video/aty/radeon_backlight.c
+++ b/drivers/video/aty/radeon_backlight.c
@@ -175,9 +175,9 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
175 175
176#ifdef CONFIG_PMAC_BACKLIGHT 176#ifdef CONFIG_PMAC_BACKLIGHT
177 pdata->negative = pdata->negative || 177 pdata->negative = pdata->negative ||
178 machine_is_compatible("PowerBook4,3") || 178 of_machine_is_compatible("PowerBook4,3") ||
179 machine_is_compatible("PowerBook6,3") || 179 of_machine_is_compatible("PowerBook6,3") ||
180 machine_is_compatible("PowerBook6,5"); 180 of_machine_is_compatible("PowerBook6,5");
181#endif 181#endif
182 182
183 rinfo->info->bl_dev = bd; 183 rinfo->info->bl_dev = bd;
diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
index eb12182b2059..d25df51bb0d2 100644
--- a/drivers/video/efifb.c
+++ b/drivers/video/efifb.c
@@ -161,8 +161,17 @@ static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
161 return 0; 161 return 0;
162} 162}
163 163
164static void efifb_destroy(struct fb_info *info)
165{
166 if (info->screen_base)
167 iounmap(info->screen_base);
168 release_mem_region(info->aperture_base, info->aperture_size);
169 framebuffer_release(info);
170}
171
164static struct fb_ops efifb_ops = { 172static struct fb_ops efifb_ops = {
165 .owner = THIS_MODULE, 173 .owner = THIS_MODULE,
174 .fb_destroy = efifb_destroy,
166 .fb_setcolreg = efifb_setcolreg, 175 .fb_setcolreg = efifb_setcolreg,
167 .fb_fillrect = cfb_fillrect, 176 .fb_fillrect = cfb_fillrect,
168 .fb_copyarea = cfb_copyarea, 177 .fb_copyarea = cfb_copyarea,
@@ -281,7 +290,7 @@ static int __init efifb_probe(struct platform_device *dev)
281 info->par = NULL; 290 info->par = NULL;
282 291
283 info->aperture_base = efifb_fix.smem_start; 292 info->aperture_base = efifb_fix.smem_start;
284 info->aperture_size = size_total; 293 info->aperture_size = size_remap;
285 294
286 info->screen_base = ioremap(efifb_fix.smem_start, efifb_fix.smem_len); 295 info->screen_base = ioremap(efifb_fix.smem_start, efifb_fix.smem_len);
287 if (!info->screen_base) { 296 if (!info->screen_base) {
diff --git a/drivers/video/fsl-diu-fb.c b/drivers/video/fsl-diu-fb.c
index 72d68b3dc478..4637bcbe03a4 100644
--- a/drivers/video/fsl-diu-fb.c
+++ b/drivers/video/fsl-diu-fb.c
@@ -1633,6 +1633,11 @@ static int __init fsl_diu_setup(char *options)
1633#endif 1633#endif
1634 1634
1635static struct of_device_id fsl_diu_match[] = { 1635static struct of_device_id fsl_diu_match[] = {
1636#ifdef CONFIG_PPC_MPC512x
1637 {
1638 .compatible = "fsl,mpc5121-diu",
1639 },
1640#endif
1636 { 1641 {
1637 .compatible = "fsl,diu", 1642 .compatible = "fsl,diu",
1638 }, 1643 },
diff --git a/drivers/video/macfb.c b/drivers/video/macfb.c
index d66887e8cbb1..43207cc6cc19 100644
--- a/drivers/video/macfb.c
+++ b/drivers/video/macfb.c
@@ -1,29 +1,33 @@
1/* macfb.c: Generic framebuffer for Macs whose colourmaps/modes we 1/*
2 don't know how to set */ 2 * macfb.c: Generic framebuffer for Macs whose colourmaps/modes we
3 3 * don't know how to set.
4/* (c) 1999 David Huggins-Daines <dhd@debian.org> 4 *
5 5 * (c) 1999 David Huggins-Daines <dhd@debian.org>
6 Primarily based on vesafb.c, by Gerd Knorr 6 *
7 (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> 7 * Primarily based on vesafb.c, by Gerd Knorr
8 8 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
9 Also uses information and code from: 9 *
10 10 * Also uses information and code from:
11 The original macfb.c from Linux/mac68k 2.0, by Alan Cox, Juergen 11 *
12 Mellinger, Mikael Forselius, Michael Schmitz, and others. 12 * The original macfb.c from Linux/mac68k 2.0, by Alan Cox, Juergen
13 13 * Mellinger, Mikael Forselius, Michael Schmitz, and others.
14 valkyriefb.c, by Martin Costabel, Kevin Schoedel, Barry Nathan, Dan 14 *
15 Jacobowitz, Paul Mackerras, Fabio Riccardi, and Geert Uytterhoeven. 15 * valkyriefb.c, by Martin Costabel, Kevin Schoedel, Barry Nathan, Dan
16 16 * Jacobowitz, Paul Mackerras, Fabio Riccardi, and Geert Uytterhoeven.
17 This code is free software. You may copy, modify, and distribute 17 *
18 it subject to the terms and conditions of the GNU General Public 18 * The VideoToolbox "Bugs" web page at
19 License, version 2, or any later version, at your convenience. */ 19 * http://rajsky.psych.nyu.edu/Tips/VideoBugs.html
20 *
21 * This code is free software. You may copy, modify, and distribute
22 * it subject to the terms and conditions of the GNU General Public
23 * License, version 2, or any later version, at your convenience.
24 */
20 25
21#include <linux/module.h> 26#include <linux/module.h>
22#include <linux/kernel.h> 27#include <linux/kernel.h>
23#include <linux/errno.h> 28#include <linux/errno.h>
24#include <linux/string.h> 29#include <linux/string.h>
25#include <linux/mm.h> 30#include <linux/mm.h>
26#include <linux/slab.h>
27#include <linux/delay.h> 31#include <linux/delay.h>
28#include <linux/nubus.h> 32#include <linux/nubus.h>
29#include <linux/init.h> 33#include <linux/init.h>
@@ -31,9 +35,6 @@
31 35
32#include <asm/setup.h> 36#include <asm/setup.h>
33#include <asm/bootinfo.h> 37#include <asm/bootinfo.h>
34#include <asm/uaccess.h>
35#include <asm/pgtable.h>
36#include <asm/irq.h>
37#include <asm/macintosh.h> 38#include <asm/macintosh.h>
38#include <asm/io.h> 39#include <asm/io.h>
39 40
@@ -44,7 +45,7 @@
44#define DAFB_BASE 0xf9800200 45#define DAFB_BASE 0xf9800200
45 46
46/* Address for the built-in Civic framebuffer in Quadra AVs */ 47/* Address for the built-in Civic framebuffer in Quadra AVs */
47#define CIVIC_BASE 0x50f30800 /* Only tested on 660AV! */ 48#define CIVIC_BASE 0x50f30800
48 49
49/* GSC (Gray Scale Controller) base address */ 50/* GSC (Gray Scale Controller) base address */
50#define GSC_BASE 0x50F20000 51#define GSC_BASE 0x50F20000
@@ -52,37 +53,9 @@
52/* CSC (Color Screen Controller) base address */ 53/* CSC (Color Screen Controller) base address */
53#define CSC_BASE 0x50F20000 54#define CSC_BASE 0x50F20000
54 55
55static int (*macfb_setpalette) (unsigned int regno, unsigned int red, 56static int (*macfb_setpalette)(unsigned int regno, unsigned int red,
56 unsigned int green, unsigned int blue, 57 unsigned int green, unsigned int blue,
57 struct fb_info *info) = NULL; 58 struct fb_info *info);
58static int valkyrie_setpalette (unsigned int regno, unsigned int red,
59 unsigned int green, unsigned int blue,
60 struct fb_info *info);
61static int dafb_setpalette (unsigned int regno, unsigned int red,
62 unsigned int green, unsigned int blue,
63 struct fb_info *fb_info);
64static int rbv_setpalette (unsigned int regno, unsigned int red,
65 unsigned int green, unsigned int blue,
66 struct fb_info *fb_info);
67static int mdc_setpalette (unsigned int regno, unsigned int red,
68 unsigned int green, unsigned int blue,
69 struct fb_info *fb_info);
70static int toby_setpalette (unsigned int regno, unsigned int red,
71 unsigned int green, unsigned int blue,
72 struct fb_info *fb_info);
73static int civic_setpalette (unsigned int regno, unsigned int red,
74 unsigned int green, unsigned int blue,
75 struct fb_info *fb_info);
76static int csc_setpalette (unsigned int regno, unsigned int red,
77 unsigned int green, unsigned int blue,
78 struct fb_info *fb_info);
79
80static struct {
81 unsigned char addr;
82 /* Note: word-aligned */
83 char pad[3];
84 unsigned char lut;
85} __iomem *valkyrie_cmap_regs;
86 59
87static struct { 60static struct {
88 unsigned char addr; 61 unsigned char addr;
@@ -116,15 +89,15 @@ static struct {
116} __iomem *civic_cmap_regs; 89} __iomem *civic_cmap_regs;
117 90
118static struct { 91static struct {
119 char pad1[0x40]; 92 char pad1[0x40];
120 unsigned char clut_waddr; /* 0x40 */ 93 unsigned char clut_waddr; /* 0x40 */
121 char pad2; 94 char pad2;
122 unsigned char clut_data; /* 0x42 */ 95 unsigned char clut_data; /* 0x42 */
123 char pad3[0x3]; 96 char pad3[0x3];
124 unsigned char clut_raddr; /* 0x46 */ 97 unsigned char clut_raddr; /* 0x46 */
125} __iomem *csc_cmap_regs; 98} __iomem *csc_cmap_regs;
126 99
127/* We will leave these the way they are for the time being */ 100/* The registers in these structs are in NuBus slot space */
128struct mdc_cmap_regs { 101struct mdc_cmap_regs {
129 char pad1[0x200200]; 102 char pad1[0x200200];
130 unsigned char addr; 103 unsigned char addr;
@@ -145,13 +118,10 @@ struct jet_cmap_regs {
145 unsigned char lut; 118 unsigned char lut;
146}; 119};
147 120
148#define PIXEL_TO_MM(a) (((a)*10)/28) /* width in mm at 72 dpi */ 121#define PIXEL_TO_MM(a) (((a)*10)/28) /* width in mm at 72 dpi */
149
150/* mode */
151static int video_slot = 0;
152 122
153static struct fb_var_screeninfo macfb_defined = { 123static struct fb_var_screeninfo macfb_defined = {
154 .bits_per_pixel = 8, 124 .bits_per_pixel = 8,
155 .activate = FB_ACTIVATE_NOW, 125 .activate = FB_ACTIVATE_NOW,
156 .width = -1, 126 .width = -1,
157 .height = -1, 127 .height = -1,
@@ -167,181 +137,152 @@ static struct fb_fix_screeninfo macfb_fix = {
167 .accel = FB_ACCEL_NONE, 137 .accel = FB_ACCEL_NONE,
168}; 138};
169 139
140static void *slot_addr;
170static struct fb_info fb_info; 141static struct fb_info fb_info;
171static u32 pseudo_palette[16]; 142static u32 pseudo_palette[16];
172static int inverse = 0; 143static int inverse;
173static int vidtest = 0; 144static int vidtest;
174 145
175static int valkyrie_setpalette (unsigned int regno, unsigned int red, 146/*
176 unsigned int green, unsigned int blue, 147 * Unlike the Valkyrie, the DAFB cannot set individual colormap
177 struct fb_info *info) 148 * registers. Therefore, we do what the MacOS driver does (no
178{ 149 * kidding!) and simply set them one by one until we hit the one we
179 unsigned long flags; 150 * want.
180 151 */
181 red >>= 8; 152static int dafb_setpalette(unsigned int regno, unsigned int red,
182 green >>= 8; 153 unsigned int green, unsigned int blue,
183 blue >>= 8; 154 struct fb_info *info)
184
185 local_irq_save(flags);
186
187 /* tell clut which address to fill */
188 nubus_writeb(regno, &valkyrie_cmap_regs->addr);
189 nop();
190
191 /* send one color channel at a time */
192 nubus_writeb(red, &valkyrie_cmap_regs->lut);
193 nop();
194 nubus_writeb(green, &valkyrie_cmap_regs->lut);
195 nop();
196 nubus_writeb(blue, &valkyrie_cmap_regs->lut);
197
198 local_irq_restore(flags);
199 return 0;
200}
201
202/* Unlike the Valkyrie, the DAFB cannot set individual colormap
203 registers. Therefore, we do what the MacOS driver does (no
204 kidding!) and simply set them one by one until we hit the one we
205 want. */
206static int dafb_setpalette (unsigned int regno, unsigned int red,
207 unsigned int green, unsigned int blue,
208 struct fb_info *info)
209{ 155{
210 /* FIXME: really, really need to use ioremap() here,
211 phys_to_virt() doesn't work anymore */
212 static int lastreg = -1; 156 static int lastreg = -1;
213 unsigned long flags; 157 unsigned long flags;
214
215 red >>= 8;
216 green >>= 8;
217 blue >>= 8;
218 158
219 local_irq_save(flags); 159 local_irq_save(flags);
220 160
221 /* fbdev will set an entire colourmap, but X won't. Hopefully 161 /*
222 this should accommodate both of them */ 162 * fbdev will set an entire colourmap, but X won't. Hopefully
223 if (regno != lastreg+1) { 163 * this should accommodate both of them
164 */
165 if (regno != lastreg + 1) {
224 int i; 166 int i;
225 167
226 /* Stab in the dark trying to reset the CLUT pointer */ 168 /* Stab in the dark trying to reset the CLUT pointer */
227 nubus_writel(0, &dafb_cmap_regs->reset); 169 nubus_writel(0, &dafb_cmap_regs->reset);
228 nop(); 170 nop();
229 171
230 /* Loop until we get to the register we want */ 172 /* Loop until we get to the register we want */
231 for (i = 0; i < regno; i++) { 173 for (i = 0; i < regno; i++) {
232 nubus_writeb(info->cmap.red[i] >> 8, &dafb_cmap_regs->lut); 174 nubus_writeb(info->cmap.red[i] >> 8,
175 &dafb_cmap_regs->lut);
233 nop(); 176 nop();
234 nubus_writeb(info->cmap.green[i] >> 8, &dafb_cmap_regs->lut); 177 nubus_writeb(info->cmap.green[i] >> 8,
178 &dafb_cmap_regs->lut);
235 nop(); 179 nop();
236 nubus_writeb(info->cmap.blue[i] >> 8, &dafb_cmap_regs->lut); 180 nubus_writeb(info->cmap.blue[i] >> 8,
181 &dafb_cmap_regs->lut);
237 nop(); 182 nop();
238 } 183 }
239 } 184 }
240 185
241 nubus_writeb(red, &dafb_cmap_regs->lut); 186 nubus_writeb(red, &dafb_cmap_regs->lut);
242 nop(); 187 nop();
243 nubus_writeb(green, &dafb_cmap_regs->lut); 188 nubus_writeb(green, &dafb_cmap_regs->lut);
244 nop(); 189 nop();
245 nubus_writeb(blue, &dafb_cmap_regs->lut); 190 nubus_writeb(blue, &dafb_cmap_regs->lut);
246 191
247 local_irq_restore(flags); 192 local_irq_restore(flags);
248 lastreg = regno; 193 lastreg = regno;
249 return 0; 194 return 0;
250} 195}
251 196
252/* V8 and Brazil seem to use the same DAC. Sonora does as well. */ 197/* V8 and Brazil seem to use the same DAC. Sonora does as well. */
253static int v8_brazil_setpalette (unsigned int regno, unsigned int red, 198static int v8_brazil_setpalette(unsigned int regno, unsigned int red,
254 unsigned int green, unsigned int blue, 199 unsigned int green, unsigned int blue,
255 struct fb_info *info) 200 struct fb_info *info)
256{ 201{
257 unsigned int bpp = info->var.bits_per_pixel; 202 unsigned int bpp = info->var.bits_per_pixel;
258 unsigned char _red =red>>8;
259 unsigned char _green=green>>8;
260 unsigned char _blue =blue>>8;
261 unsigned char _regno;
262 unsigned long flags; 203 unsigned long flags;
263 204
264 if (bpp > 8) return 1; /* failsafe */ 205 if (bpp > 8)
206 return 1; /* failsafe */
265 207
266 local_irq_save(flags); 208 local_irq_save(flags);
267 209
268 /* On these chips, the CLUT register numbers are spread out 210 /* On these chips, the CLUT register numbers are spread out
269 across the register space. Thus: 211 * across the register space. Thus:
270 212 * In 8bpp, all regnos are valid.
271 In 8bpp, all regnos are valid. 213 * In 4bpp, the regnos are 0x0f, 0x1f, 0x2f, etc, etc
272 214 * In 2bpp, the regnos are 0x3f, 0x7f, 0xbf, 0xff
273 In 4bpp, the regnos are 0x0f, 0x1f, 0x2f, etc, etc 215 */
274 216 regno = (regno << (8 - bpp)) | (0xFF >> bpp);
275 In 2bpp, the regnos are 0x3f, 0x7f, 0xbf, 0xff */ 217 nubus_writeb(regno, &v8_brazil_cmap_regs->addr);
276 _regno = (regno << (8 - bpp)) | (0xFF >> bpp); 218 nop();
277 nubus_writeb(_regno, &v8_brazil_cmap_regs->addr); nop();
278 219
279 /* send one color channel at a time */ 220 /* send one color channel at a time */
280 nubus_writeb(_red, &v8_brazil_cmap_regs->lut); nop(); 221 nubus_writeb(red, &v8_brazil_cmap_regs->lut);
281 nubus_writeb(_green, &v8_brazil_cmap_regs->lut); nop(); 222 nop();
282 nubus_writeb(_blue, &v8_brazil_cmap_regs->lut); 223 nubus_writeb(green, &v8_brazil_cmap_regs->lut);
224 nop();
225 nubus_writeb(blue, &v8_brazil_cmap_regs->lut);
283 226
284 local_irq_restore(flags); 227 local_irq_restore(flags);
285 return 0; 228 return 0;
286} 229}
287 230
288static int rbv_setpalette (unsigned int regno, unsigned int red, 231/* RAM-Based Video */
289 unsigned int green, unsigned int blue, 232static int rbv_setpalette(unsigned int regno, unsigned int red,
290 struct fb_info *info) 233 unsigned int green, unsigned int blue,
234 struct fb_info *info)
291{ 235{
292 /* use MSBs */
293 unsigned char _red =red>>8;
294 unsigned char _green=green>>8;
295 unsigned char _blue =blue>>8;
296 unsigned char _regno;
297 unsigned long flags; 236 unsigned long flags;
298 237
299 if (info->var.bits_per_pixel > 8) return 1; /* failsafe */ 238 if (info->var.bits_per_pixel > 8)
239 return 1; /* failsafe */
300 240
301 local_irq_save(flags); 241 local_irq_save(flags);
302 242
303 /* From the VideoToolbox driver. Seems to be saying that 243 /* From the VideoToolbox driver. Seems to be saying that
304 * regno #254 and #255 are the important ones for 1-bit color, 244 * regno #254 and #255 are the important ones for 1-bit color,
305 * regno #252-255 are the important ones for 2-bit color, etc. 245 * regno #252-255 are the important ones for 2-bit color, etc.
306 */ 246 */
307 _regno = regno + (256-(1 << info->var.bits_per_pixel)); 247 regno += 256 - (1 << info->var.bits_per_pixel);
308 248
309 /* reset clut? (VideoToolbox sez "not necessary") */ 249 /* reset clut? (VideoToolbox sez "not necessary") */
310 nubus_writeb(0xFF, &rbv_cmap_regs->cntl); nop(); 250 nubus_writeb(0xFF, &rbv_cmap_regs->cntl);
311 251 nop();
252
312 /* tell clut which address to use. */ 253 /* tell clut which address to use. */
313 nubus_writeb(_regno, &rbv_cmap_regs->addr); nop(); 254 nubus_writeb(regno, &rbv_cmap_regs->addr);
314 255 nop();
256
315 /* send one color channel at a time. */ 257 /* send one color channel at a time. */
316 nubus_writeb(_red, &rbv_cmap_regs->lut); nop(); 258 nubus_writeb(red, &rbv_cmap_regs->lut);
317 nubus_writeb(_green, &rbv_cmap_regs->lut); nop(); 259 nop();
318 nubus_writeb(_blue, &rbv_cmap_regs->lut); 260 nubus_writeb(green, &rbv_cmap_regs->lut);
319 261 nop();
320 local_irq_restore(flags); /* done. */ 262 nubus_writeb(blue, &rbv_cmap_regs->lut);
263
264 local_irq_restore(flags);
321 return 0; 265 return 0;
322} 266}
323 267
324/* Macintosh Display Card (8x24) */ 268/* Macintosh Display Card (8*24) */
325static int mdc_setpalette(unsigned int regno, unsigned int red, 269static int mdc_setpalette(unsigned int regno, unsigned int red,
326 unsigned int green, unsigned int blue, 270 unsigned int green, unsigned int blue,
327 struct fb_info *info) 271 struct fb_info *info)
328{ 272{
329 volatile struct mdc_cmap_regs *cmap_regs = 273 struct mdc_cmap_regs *cmap_regs = slot_addr;
330 nubus_slot_addr(video_slot);
331 /* use MSBs */
332 unsigned char _red =red>>8;
333 unsigned char _green=green>>8;
334 unsigned char _blue =blue>>8;
335 unsigned char _regno=regno;
336 unsigned long flags; 274 unsigned long flags;
337 275
338 local_irq_save(flags); 276 local_irq_save(flags);
339 277
340 /* the nop's are there to order writes. */ 278 /* the nop's are there to order writes. */
341 nubus_writeb(_regno, &cmap_regs->addr); nop(); 279 nubus_writeb(regno, &cmap_regs->addr);
342 nubus_writeb(_red, &cmap_regs->lut); nop(); 280 nop();
343 nubus_writeb(_green, &cmap_regs->lut); nop(); 281 nubus_writeb(red, &cmap_regs->lut);
344 nubus_writeb(_blue, &cmap_regs->lut); 282 nop();
283 nubus_writeb(green, &cmap_regs->lut);
284 nop();
285 nubus_writeb(blue, &cmap_regs->lut);
345 286
346 local_irq_restore(flags); 287 local_irq_restore(flags);
347 return 0; 288 return 0;
@@ -350,24 +291,26 @@ static int mdc_setpalette(unsigned int regno, unsigned int red,
350/* Toby frame buffer */ 291/* Toby frame buffer */
351static int toby_setpalette(unsigned int regno, unsigned int red, 292static int toby_setpalette(unsigned int regno, unsigned int red,
352 unsigned int green, unsigned int blue, 293 unsigned int green, unsigned int blue,
353 struct fb_info *info) 294 struct fb_info *info)
354{ 295{
355 volatile struct toby_cmap_regs *cmap_regs = 296 struct toby_cmap_regs *cmap_regs = slot_addr;
356 nubus_slot_addr(video_slot);
357 unsigned int bpp = info->var.bits_per_pixel; 297 unsigned int bpp = info->var.bits_per_pixel;
358 /* use MSBs */
359 unsigned char _red =~(red>>8);
360 unsigned char _green=~(green>>8);
361 unsigned char _blue =~(blue>>8);
362 unsigned char _regno = (regno << (8 - bpp)) | (0xFF >> bpp);
363 unsigned long flags; 298 unsigned long flags;
364 299
300 red = ~red;
301 green = ~green;
302 blue = ~blue;
303 regno = (regno << (8 - bpp)) | (0xFF >> bpp);
304
365 local_irq_save(flags); 305 local_irq_save(flags);
366 306
367 nubus_writeb(_regno, &cmap_regs->addr); nop(); 307 nubus_writeb(regno, &cmap_regs->addr);
368 nubus_writeb(_red, &cmap_regs->lut); nop(); 308 nop();
369 nubus_writeb(_green, &cmap_regs->lut); nop(); 309 nubus_writeb(red, &cmap_regs->lut);
370 nubus_writeb(_blue, &cmap_regs->lut); 310 nop();
311 nubus_writeb(green, &cmap_regs->lut);
312 nop();
313 nubus_writeb(blue, &cmap_regs->lut);
371 314
372 local_irq_restore(flags); 315 local_irq_restore(flags);
373 return 0; 316 return 0;
@@ -378,20 +321,18 @@ static int jet_setpalette(unsigned int regno, unsigned int red,
378 unsigned int green, unsigned int blue, 321 unsigned int green, unsigned int blue,
379 struct fb_info *info) 322 struct fb_info *info)
380{ 323{
381 volatile struct jet_cmap_regs *cmap_regs = 324 struct jet_cmap_regs *cmap_regs = slot_addr;
382 nubus_slot_addr(video_slot);
383 /* use MSBs */
384 unsigned char _red = (red>>8);
385 unsigned char _green = (green>>8);
386 unsigned char _blue = (blue>>8);
387 unsigned long flags; 325 unsigned long flags;
388 326
389 local_irq_save(flags); 327 local_irq_save(flags);
390 328
391 nubus_writeb(regno, &cmap_regs->addr); nop(); 329 nubus_writeb(regno, &cmap_regs->addr);
392 nubus_writeb(_red, &cmap_regs->lut); nop(); 330 nop();
393 nubus_writeb(_green, &cmap_regs->lut); nop(); 331 nubus_writeb(red, &cmap_regs->lut);
394 nubus_writeb(_blue, &cmap_regs->lut); 332 nop();
333 nubus_writeb(green, &cmap_regs->lut);
334 nop();
335 nubus_writeb(blue, &cmap_regs->lut);
395 336
396 local_irq_restore(flags); 337 local_irq_restore(flags);
397 return 0; 338 return 0;
@@ -400,53 +341,27 @@ static int jet_setpalette(unsigned int regno, unsigned int red,
400/* 341/*
401 * Civic framebuffer -- Quadra AV built-in video. A chip 342 * Civic framebuffer -- Quadra AV built-in video. A chip
402 * called Sebastian holds the actual color palettes, and 343 * called Sebastian holds the actual color palettes, and
403 * apparently, there are two different banks of 512K RAM 344 * apparently, there are two different banks of 512K RAM
404 * which can act as separate framebuffers for doing video 345 * which can act as separate framebuffers for doing video
405 * input and viewing the screen at the same time! The 840AV 346 * input and viewing the screen at the same time! The 840AV
406 * Can add another 1MB RAM to give the two framebuffers 347 * Can add another 1MB RAM to give the two framebuffers
407 * 1MB RAM apiece. 348 * 1MB RAM apiece.
408 *
409 * FIXME: this doesn't seem to work anymore.
410 */ 349 */
411static int civic_setpalette (unsigned int regno, unsigned int red, 350static int civic_setpalette(unsigned int regno, unsigned int red,
412 unsigned int green, unsigned int blue, 351 unsigned int green, unsigned int blue,
413 struct fb_info *info) 352 struct fb_info *info)
414{ 353{
415 static int lastreg = -1;
416 unsigned long flags; 354 unsigned long flags;
417 int clut_status; 355 int clut_status;
418 356
419 if (info->var.bits_per_pixel > 8) return 1; /* failsafe */ 357 if (info->var.bits_per_pixel > 8)
420 358 return 1; /* failsafe */
421 red >>= 8;
422 green >>= 8;
423 blue >>= 8;
424 359
425 local_irq_save(flags); 360 local_irq_save(flags);
426
427 /*
428 * Set the register address
429 */
430 nubus_writeb(regno, &civic_cmap_regs->addr); nop();
431 361
432 /* 362 /* Set the register address */
433 * Wait for VBL interrupt here; 363 nubus_writeb(regno, &civic_cmap_regs->addr);
434 * They're usually not enabled from Penguin, so we won't check 364 nop();
435 */
436#if 0
437 {
438#define CIVIC_VBL_OFFSET 0x120
439 volatile unsigned long *vbl = nubus_readl(civic_cmap_regs->vbl_addr + CIVIC_VBL_OFFSET);
440 /* do interrupt setup stuff here? */
441 *vbl = 0L; nop(); /* clear */
442 *vbl = 1L; nop(); /* set */
443 while (*vbl != 0L) /* wait for next vbl */
444 {
445 usleep(10); /* needed? */
446 }
447 /* do interrupt shutdown stuff here? */
448 }
449#endif
450 365
451 /* 366 /*
452 * Grab a status word and do some checking; 367 * Grab a status word and do some checking;
@@ -459,39 +374,52 @@ static int civic_setpalette (unsigned int regno, unsigned int red,
459#if 0 374#if 0
460 if ((clut_status & 0x000D) != 0) 375 if ((clut_status & 0x000D) != 0)
461 { 376 {
462 nubus_writeb(0x00, &civic_cmap_regs->lut); nop(); 377 nubus_writeb(0x00, &civic_cmap_regs->lut);
463 nubus_writeb(0x00, &civic_cmap_regs->lut); nop(); 378 nop();
379 nubus_writeb(0x00, &civic_cmap_regs->lut);
380 nop();
464 } 381 }
465#endif 382#endif
466 383
467 nubus_writeb( red, &civic_cmap_regs->lut); nop(); 384 nubus_writeb(red, &civic_cmap_regs->lut);
468 nubus_writeb(green, &civic_cmap_regs->lut); nop(); 385 nop();
469 nubus_writeb( blue, &civic_cmap_regs->lut); nop(); 386 nubus_writeb(green, &civic_cmap_regs->lut);
470 nubus_writeb( 0x00, &civic_cmap_regs->lut); nop(); 387 nop();
388 nubus_writeb(blue, &civic_cmap_regs->lut);
389 nop();
390 nubus_writeb(0x00, &civic_cmap_regs->lut);
471 } 391 }
472 else 392 else
473 { 393 {
474 unsigned char junk; 394 unsigned char junk;
475 395
476 junk = nubus_readb(&civic_cmap_regs->lut); nop(); 396 junk = nubus_readb(&civic_cmap_regs->lut);
477 junk = nubus_readb(&civic_cmap_regs->lut); nop(); 397 nop();
478 junk = nubus_readb(&civic_cmap_regs->lut); nop(); 398 junk = nubus_readb(&civic_cmap_regs->lut);
479 junk = nubus_readb(&civic_cmap_regs->lut); nop(); 399 nop();
400 junk = nubus_readb(&civic_cmap_regs->lut);
401 nop();
402 junk = nubus_readb(&civic_cmap_regs->lut);
403 nop();
480 404
481 if ((clut_status & 0x000D) != 0) 405 if ((clut_status & 0x000D) != 0)
482 { 406 {
483 nubus_writeb(0x00, &civic_cmap_regs->lut); nop(); 407 nubus_writeb(0x00, &civic_cmap_regs->lut);
484 nubus_writeb(0x00, &civic_cmap_regs->lut); nop(); 408 nop();
409 nubus_writeb(0x00, &civic_cmap_regs->lut);
410 nop();
485 } 411 }
486 412
487 nubus_writeb( red, &civic_cmap_regs->lut); nop(); 413 nubus_writeb(red, &civic_cmap_regs->lut);
488 nubus_writeb(green, &civic_cmap_regs->lut); nop(); 414 nop();
489 nubus_writeb( blue, &civic_cmap_regs->lut); nop(); 415 nubus_writeb(green, &civic_cmap_regs->lut);
490 nubus_writeb( junk, &civic_cmap_regs->lut); nop(); 416 nop();
417 nubus_writeb(blue, &civic_cmap_regs->lut);
418 nop();
419 nubus_writeb(junk, &civic_cmap_regs->lut);
491 } 420 }
492 421
493 local_irq_restore(flags); 422 local_irq_restore(flags);
494 lastreg = regno;
495 return 0; 423 return 0;
496} 424}
497 425
@@ -500,16 +428,21 @@ static int civic_setpalette (unsigned int regno, unsigned int red,
500 * (and the 5300 too, but that's a PowerMac). This function 428 * (and the 5300 too, but that's a PowerMac). This function
501 * brought to you in part by the ECSC driver for MkLinux. 429 * brought to you in part by the ECSC driver for MkLinux.
502 */ 430 */
503 431static int csc_setpalette(unsigned int regno, unsigned int red,
504static int csc_setpalette (unsigned int regno, unsigned int red, 432 unsigned int green, unsigned int blue,
505 unsigned int green, unsigned int blue, 433 struct fb_info *info)
506 struct fb_info *info)
507{ 434{
508 mdelay(1); 435 unsigned long flags;
436
437 local_irq_save(flags);
438
439 udelay(1); /* mklinux on PB 5300 waits for 260 ns */
509 nubus_writeb(regno, &csc_cmap_regs->clut_waddr); 440 nubus_writeb(regno, &csc_cmap_regs->clut_waddr);
510 nubus_writeb(red, &csc_cmap_regs->clut_data); 441 nubus_writeb(red, &csc_cmap_regs->clut_data);
511 nubus_writeb(green, &csc_cmap_regs->clut_data); 442 nubus_writeb(green, &csc_cmap_regs->clut_data);
512 nubus_writeb(blue, &csc_cmap_regs->clut_data); 443 nubus_writeb(blue, &csc_cmap_regs->clut_data);
444
445 local_irq_restore(flags);
513 return 0; 446 return 0;
514} 447}
515 448
@@ -518,10 +451,10 @@ static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
518 struct fb_info *fb_info) 451 struct fb_info *fb_info)
519{ 452{
520 /* 453 /*
521 * Set a single color register. The values supplied are 454 * Set a single color register. The values supplied are
522 * already rounded down to the hardware's capabilities 455 * already rounded down to the hardware's capabilities
523 * (according to the entries in the `var' structure). Return 456 * (according to the entries in the `var' structure).
524 * != 0 for invalid regno. 457 * Return non-zero for invalid regno.
525 */ 458 */
526 459
527 if (regno >= fb_info->cmap.len) 460 if (regno >= fb_info->cmap.len)
@@ -536,8 +469,8 @@ static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
536 case 4: 469 case 4:
537 case 8: 470 case 8:
538 if (macfb_setpalette) 471 if (macfb_setpalette)
539 macfb_setpalette(regno, red, green, blue, 472 macfb_setpalette(regno, red >> 8, green >> 8,
540 fb_info); 473 blue >> 8, fb_info);
541 else 474 else
542 return 1; 475 return 1;
543 break; 476 break;
@@ -555,28 +488,22 @@ static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green,
555 } else { 488 } else {
556 /* 0:5:6:5 */ 489 /* 0:5:6:5 */
557 ((u32*) (fb_info->pseudo_palette))[regno] = 490 ((u32*) (fb_info->pseudo_palette))[regno] =
558 ((red & 0xf800) ) | 491 ((red & 0xf800) >> 0) |
559 ((green & 0xfc00) >> 5) | 492 ((green & 0xfc00) >> 5) |
560 ((blue & 0xf800) >> 11); 493 ((blue & 0xf800) >> 11);
561 } 494 }
562 break; 495 break;
563 /* I'm pretty sure that one or the other of these 496 /*
564 doesn't exist on 68k Macs */ 497 * 24-bit colour almost doesn't exist on 68k Macs --
498 * http://support.apple.com/kb/TA28634 (Old Article: 10992)
499 */
565 case 24: 500 case 24:
566 red >>= 8;
567 green >>= 8;
568 blue >>= 8;
569 ((u32 *)(fb_info->pseudo_palette))[regno] =
570 (red << fb_info->var.red.offset) |
571 (green << fb_info->var.green.offset) |
572 (blue << fb_info->var.blue.offset);
573 break;
574 case 32: 501 case 32:
575 red >>= 8; 502 red >>= 8;
576 green >>= 8; 503 green >>= 8;
577 blue >>= 8; 504 blue >>= 8;
578 ((u32 *)(fb_info->pseudo_palette))[regno] = 505 ((u32 *)(fb_info->pseudo_palette))[regno] =
579 (red << fb_info->var.red.offset) | 506 (red << fb_info->var.red.offset) |
580 (green << fb_info->var.green.offset) | 507 (green << fb_info->var.green.offset) |
581 (blue << fb_info->var.blue.offset); 508 (blue << fb_info->var.blue.offset);
582 break; 509 break;
@@ -597,25 +524,24 @@ static struct fb_ops macfb_ops = {
597static void __init macfb_setup(char *options) 524static void __init macfb_setup(char *options)
598{ 525{
599 char *this_opt; 526 char *this_opt;
600 527
601 if (!options || !*options) 528 if (!options || !*options)
602 return; 529 return;
603 530
604 while ((this_opt = strsep(&options, ",")) != NULL) { 531 while ((this_opt = strsep(&options, ",")) != NULL) {
605 if (!*this_opt) continue; 532 if (!*this_opt)
606 533 continue;
607 if (! strcmp(this_opt, "inverse")) 534
608 inverse=1; 535 if (!strcmp(this_opt, "inverse"))
609 /* This means "turn on experimental CLUT code" */ 536 inverse = 1;
610 else if (!strcmp(this_opt, "vidtest")) 537 else
611 vidtest=1; 538 if (!strcmp(this_opt, "vidtest"))
539 vidtest = 1; /* enable experimental CLUT code */
612 } 540 }
613} 541}
614 542
615static void __init iounmap_macfb(void) 543static void __init iounmap_macfb(void)
616{ 544{
617 if (valkyrie_cmap_regs)
618 iounmap(valkyrie_cmap_regs);
619 if (dafb_cmap_regs) 545 if (dafb_cmap_regs)
620 iounmap(dafb_cmap_regs); 546 iounmap(dafb_cmap_regs);
621 if (v8_brazil_cmap_regs) 547 if (v8_brazil_cmap_regs)
@@ -642,48 +568,55 @@ static int __init macfb_init(void)
642 if (!MACH_IS_MAC) 568 if (!MACH_IS_MAC)
643 return -ENODEV; 569 return -ENODEV;
644 570
645 /* There can only be one internal video controller anyway so 571 if (mac_bi_data.id == MAC_MODEL_Q630 ||
646 we're not too worried about this */ 572 mac_bi_data.id == MAC_MODEL_P588)
573 return -ENODEV; /* See valkyriefb.c */
574
647 macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF; 575 macfb_defined.xres = mac_bi_data.dimensions & 0xFFFF;
648 macfb_defined.yres = mac_bi_data.dimensions >> 16; 576 macfb_defined.yres = mac_bi_data.dimensions >> 16;
649 macfb_defined.bits_per_pixel = mac_bi_data.videodepth; 577 macfb_defined.bits_per_pixel = mac_bi_data.videodepth;
578
650 macfb_fix.line_length = mac_bi_data.videorow; 579 macfb_fix.line_length = mac_bi_data.videorow;
651 macfb_fix.smem_len = macfb_fix.line_length * macfb_defined.yres; 580 macfb_fix.smem_len = macfb_fix.line_length * macfb_defined.yres;
652 /* Note: physical address (since 2.1.127) */ 581 /* Note: physical address (since 2.1.127) */
653 macfb_fix.smem_start = mac_bi_data.videoaddr; 582 macfb_fix.smem_start = mac_bi_data.videoaddr;
654 /* This is actually redundant with the initial mappings. 583
655 However, there are some non-obvious aspects to the way
656 those mappings are set up, so this is in fact the safest
657 way to ensure that this driver will work on every possible
658 Mac */
659 fb_info.screen_base = ioremap(mac_bi_data.videoaddr, macfb_fix.smem_len);
660
661 printk("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk\n",
662 macfb_fix.smem_start, fb_info.screen_base, macfb_fix.smem_len/1024);
663 printk("macfb: mode is %dx%dx%d, linelength=%d\n",
664 macfb_defined.xres, macfb_defined.yres, macfb_defined.bits_per_pixel, macfb_fix.line_length);
665
666 /* 584 /*
667 * Fill in the available video resolution 585 * This is actually redundant with the initial mappings.
586 * However, there are some non-obvious aspects to the way
587 * those mappings are set up, so this is in fact the safest
588 * way to ensure that this driver will work on every possible Mac
668 */ 589 */
669 590 fb_info.screen_base = ioremap(mac_bi_data.videoaddr,
670 macfb_defined.xres_virtual = macfb_defined.xres; 591 macfb_fix.smem_len);
671 macfb_defined.yres_virtual = macfb_defined.yres; 592 if (!fb_info.screen_base)
672 macfb_defined.height = PIXEL_TO_MM(macfb_defined.yres); 593 return -ENODEV;
673 macfb_defined.width = PIXEL_TO_MM(macfb_defined.xres);
674 594
675 printk("macfb: scrolling: redraw\n"); 595 printk("macfb: framebuffer at 0x%08lx, mapped to 0x%p, size %dk\n",
596 macfb_fix.smem_start, fb_info.screen_base,
597 macfb_fix.smem_len / 1024);
598 printk("macfb: mode is %dx%dx%d, linelength=%d\n",
599 macfb_defined.xres, macfb_defined.yres,
600 macfb_defined.bits_per_pixel, macfb_fix.line_length);
601
602 /* Fill in the available video resolution */
603 macfb_defined.xres_virtual = macfb_defined.xres;
676 macfb_defined.yres_virtual = macfb_defined.yres; 604 macfb_defined.yres_virtual = macfb_defined.yres;
605 macfb_defined.height = PIXEL_TO_MM(macfb_defined.yres);
606 macfb_defined.width = PIXEL_TO_MM(macfb_defined.xres);
677 607
678 /* some dummy values for timing to make fbset happy */ 608 /* Some dummy values for timing to make fbset happy */
679 macfb_defined.pixclock = 10000000 / macfb_defined.xres * 1000 / macfb_defined.yres; 609 macfb_defined.pixclock = 10000000 / macfb_defined.xres *
610 1000 / macfb_defined.yres;
680 macfb_defined.left_margin = (macfb_defined.xres / 8) & 0xf8; 611 macfb_defined.left_margin = (macfb_defined.xres / 8) & 0xf8;
681 macfb_defined.hsync_len = (macfb_defined.xres / 8) & 0xf8; 612 macfb_defined.hsync_len = (macfb_defined.xres / 8) & 0xf8;
682 613
683 switch (macfb_defined.bits_per_pixel) { 614 switch (macfb_defined.bits_per_pixel) {
684 case 1: 615 case 1:
685 /* XXX: I think this will catch any program that tries 616 /*
686 to do FBIO_PUTCMAP when the visual is monochrome */ 617 * XXX: I think this will catch any program that tries
618 * to do FBIO_PUTCMAP when the visual is monochrome.
619 */
687 macfb_defined.red.length = macfb_defined.bits_per_pixel; 620 macfb_defined.red.length = macfb_defined.bits_per_pixel;
688 macfb_defined.green.length = macfb_defined.bits_per_pixel; 621 macfb_defined.green.length = macfb_defined.bits_per_pixel;
689 macfb_defined.blue.length = macfb_defined.bits_per_pixel; 622 macfb_defined.blue.length = macfb_defined.bits_per_pixel;
@@ -708,53 +641,52 @@ static int __init macfb_init(void)
708 macfb_defined.green.length = 5; 641 macfb_defined.green.length = 5;
709 macfb_defined.blue.offset = 0; 642 macfb_defined.blue.offset = 0;
710 macfb_defined.blue.length = 5; 643 macfb_defined.blue.length = 5;
711 printk("macfb: directcolor: "
712 "size=1:5:5:5, shift=15:10:5:0\n");
713 video_cmap_len = 16; 644 video_cmap_len = 16;
714 /* Should actually be FB_VISUAL_DIRECTCOLOR, but this 645 /*
715 works too */ 646 * Should actually be FB_VISUAL_DIRECTCOLOR, but this
647 * works too
648 */
716 macfb_fix.visual = FB_VISUAL_TRUECOLOR; 649 macfb_fix.visual = FB_VISUAL_TRUECOLOR;
717 break; 650 break;
718 case 24: 651 case 24:
719 case 32: 652 case 32:
720 /* XXX: have to test these... can any 68k Macs
721 actually do this on internal video? */
722 macfb_defined.red.offset = 16; 653 macfb_defined.red.offset = 16;
723 macfb_defined.red.length = 8; 654 macfb_defined.red.length = 8;
724 macfb_defined.green.offset = 8; 655 macfb_defined.green.offset = 8;
725 macfb_defined.green.length = 8; 656 macfb_defined.green.length = 8;
726 macfb_defined.blue.offset = 0; 657 macfb_defined.blue.offset = 0;
727 macfb_defined.blue.length = 8; 658 macfb_defined.blue.length = 8;
728 printk("macfb: truecolor: "
729 "size=0:8:8:8, shift=0:16:8:0\n");
730 video_cmap_len = 16; 659 video_cmap_len = 16;
731 macfb_fix.visual = FB_VISUAL_TRUECOLOR; 660 macfb_fix.visual = FB_VISUAL_TRUECOLOR;
661 break;
732 default: 662 default:
733 video_cmap_len = 0; 663 video_cmap_len = 0;
734 macfb_fix.visual = FB_VISUAL_MONO01; 664 macfb_fix.visual = FB_VISUAL_MONO01;
735 printk("macfb: unknown or unsupported bit depth: %d\n", macfb_defined.bits_per_pixel); 665 printk("macfb: unknown or unsupported bit depth: %d\n",
666 macfb_defined.bits_per_pixel);
736 break; 667 break;
737 } 668 }
738 669
739 /* Hardware dependent stuff */ 670 /*
740 /* We take a wild guess that if the video physical address is 671 * We take a wild guess that if the video physical address is
741 * in nubus slot space, that the nubus card is driving video. 672 * in nubus slot space, that the nubus card is driving video.
742 * Penguin really ought to tell us whether we are using internal 673 * Penguin really ought to tell us whether we are using internal
743 * video or not. 674 * video or not.
675 * Hopefully we only find one of them. Otherwise our NuBus
676 * code is really broken :-)
744 */ 677 */
745 /* Hopefully we only find one of them. Otherwise our NuBus
746 code is really broken :-) */
747 678
748 while ((ndev = nubus_find_type(NUBUS_CAT_DISPLAY, NUBUS_TYPE_VIDEO, ndev)) 679 while ((ndev = nubus_find_type(NUBUS_CAT_DISPLAY,
749 != NULL) 680 NUBUS_TYPE_VIDEO, ndev)))
750 { 681 {
751 if (!(mac_bi_data.videoaddr >= ndev->board->slot_addr 682 unsigned long base = ndev->board->slot_addr;
752 && (mac_bi_data.videoaddr < 683
753 (unsigned long)nubus_slot_addr(ndev->board->slot+1)))) 684 if (mac_bi_data.videoaddr < base ||
685 mac_bi_data.videoaddr - base > 0xFFFFFF)
754 continue; 686 continue;
687
755 video_is_nubus = 1; 688 video_is_nubus = 1;
756 /* We should probably just use the slot address... */ 689 slot_addr = (unsigned char *)base;
757 video_slot = ndev->board->slot;
758 690
759 switch(ndev->dr_hw) { 691 switch(ndev->dr_hw) {
760 case NUBUS_DRHW_APPLE_MDC: 692 case NUBUS_DRHW_APPLE_MDC:
@@ -771,7 +703,7 @@ static int __init macfb_init(void)
771 strcpy(macfb_fix.id, "Jet"); 703 strcpy(macfb_fix.id, "Jet");
772 macfb_setpalette = jet_setpalette; 704 macfb_setpalette = jet_setpalette;
773 macfb_defined.activate = FB_ACTIVATE_NOW; 705 macfb_defined.activate = FB_ACTIVATE_NOW;
774 break; 706 break;
775 default: 707 default:
776 strcpy(macfb_fix.id, "Generic NuBus"); 708 strcpy(macfb_fix.id, "Generic NuBus");
777 break; 709 break;
@@ -779,30 +711,19 @@ static int __init macfb_init(void)
779 } 711 }
780 712
781 /* If it's not a NuBus card, it must be internal video */ 713 /* If it's not a NuBus card, it must be internal video */
782 /* FIXME: this function is getting way too big. (this driver
783 is too...) */
784 if (!video_is_nubus) 714 if (!video_is_nubus)
785 switch( mac_bi_data.id ) 715 switch (mac_bi_data.id) {
786 { 716 /*
787 /* Valkyrie Quadras */ 717 * DAFB Quadras
788 case MAC_MODEL_Q630: 718 * Note: these first four have the v7 DAFB, which is
789 /* I'm not sure about this one */ 719 * known to be rather unlike the ones used in the
790 case MAC_MODEL_P588: 720 * other models
791 strcpy(macfb_fix.id, "Valkyrie"); 721 */
792 macfb_setpalette = valkyrie_setpalette;
793 macfb_defined.activate = FB_ACTIVATE_NOW;
794 valkyrie_cmap_regs = ioremap(DAC_BASE, 0x1000);
795 break;
796
797 /* DAFB Quadras */
798 /* Note: these first four have the v7 DAFB, which is
799 known to be rather unlike the ones used in the
800 other models */
801 case MAC_MODEL_P475: 722 case MAC_MODEL_P475:
802 case MAC_MODEL_P475F: 723 case MAC_MODEL_P475F:
803 case MAC_MODEL_P575: 724 case MAC_MODEL_P575:
804 case MAC_MODEL_Q605: 725 case MAC_MODEL_Q605:
805 726
806 case MAC_MODEL_Q800: 727 case MAC_MODEL_Q800:
807 case MAC_MODEL_Q650: 728 case MAC_MODEL_Q650:
808 case MAC_MODEL_Q610: 729 case MAC_MODEL_Q610:
@@ -817,17 +738,21 @@ static int __init macfb_init(void)
817 dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000); 738 dafb_cmap_regs = ioremap(DAFB_BASE, 0x1000);
818 break; 739 break;
819 740
820 /* LC II uses the V8 framebuffer */ 741 /*
742 * LC II uses the V8 framebuffer
743 */
821 case MAC_MODEL_LCII: 744 case MAC_MODEL_LCII:
822 strcpy(macfb_fix.id, "V8"); 745 strcpy(macfb_fix.id, "V8");
823 macfb_setpalette = v8_brazil_setpalette; 746 macfb_setpalette = v8_brazil_setpalette;
824 macfb_defined.activate = FB_ACTIVATE_NOW; 747 macfb_defined.activate = FB_ACTIVATE_NOW;
825 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000); 748 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
826 break; 749 break;
827 750
828 /* IIvi, IIvx use the "Brazil" framebuffer (which is 751 /*
829 very much like the V8, it seems, and probably uses 752 * IIvi, IIvx use the "Brazil" framebuffer (which is
830 the same DAC) */ 753 * very much like the V8, it seems, and probably uses
754 * the same DAC)
755 */
831 case MAC_MODEL_IIVI: 756 case MAC_MODEL_IIVI:
832 case MAC_MODEL_IIVX: 757 case MAC_MODEL_IIVX:
833 case MAC_MODEL_P600: 758 case MAC_MODEL_P600:
@@ -836,12 +761,14 @@ static int __init macfb_init(void)
836 macfb_defined.activate = FB_ACTIVATE_NOW; 761 macfb_defined.activate = FB_ACTIVATE_NOW;
837 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000); 762 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
838 break; 763 break;
839 764
840 /* LC III (and friends) use the Sonora framebuffer */ 765 /*
841 /* Incidentally this is also used in the non-AV models 766 * LC III (and friends) use the Sonora framebuffer
842 of the x100 PowerMacs */ 767 * Incidentally this is also used in the non-AV models
843 /* These do in fact seem to use the same DAC interface 768 * of the x100 PowerMacs
844 as the LC II. */ 769 * These do in fact seem to use the same DAC interface
770 * as the LC II.
771 */
845 case MAC_MODEL_LCIII: 772 case MAC_MODEL_LCIII:
846 case MAC_MODEL_P520: 773 case MAC_MODEL_P520:
847 case MAC_MODEL_P550: 774 case MAC_MODEL_P550:
@@ -852,9 +779,11 @@ static int __init macfb_init(void)
852 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000); 779 v8_brazil_cmap_regs = ioremap(DAC_BASE, 0x1000);
853 break; 780 break;
854 781
855 /* IIci and IIsi use the infamous RBV chip 782 /*
856 (the IIsi is just a rebadged and crippled 783 * IIci and IIsi use the infamous RBV chip
857 IIci in a different case, BTW) */ 784 * (the IIsi is just a rebadged and crippled
785 * IIci in a different case, BTW)
786 */
858 case MAC_MODEL_IICI: 787 case MAC_MODEL_IICI:
859 case MAC_MODEL_IISI: 788 case MAC_MODEL_IISI:
860 macfb_setpalette = rbv_setpalette; 789 macfb_setpalette = rbv_setpalette;
@@ -863,7 +792,9 @@ static int __init macfb_init(void)
863 rbv_cmap_regs = ioremap(DAC_BASE, 0x1000); 792 rbv_cmap_regs = ioremap(DAC_BASE, 0x1000);
864 break; 793 break;
865 794
866 /* AVs use the Civic framebuffer */ 795 /*
796 * AVs use the Civic framebuffer
797 */
867 case MAC_MODEL_Q840: 798 case MAC_MODEL_Q840:
868 case MAC_MODEL_C660: 799 case MAC_MODEL_C660:
869 macfb_setpalette = civic_setpalette; 800 macfb_setpalette = civic_setpalette;
@@ -873,15 +804,10 @@ static int __init macfb_init(void)
873 break; 804 break;
874 805
875 806
876 /* Write a setpalette function for your machine, then 807 /*
877 you can add something similar here. These are 808 * Assorted weirdos
878 grouped by classes of video chipsets. Some of this 809 * We think this may be like the LC II
879 information is from the VideoToolbox "Bugs" web 810 */
880 page at
881 http://rajsky.psych.nyu.edu/Tips/VideoBugs.html */
882
883 /* Assorted weirdos */
884 /* We think this may be like the LC II */
885 case MAC_MODEL_LC: 811 case MAC_MODEL_LC:
886 if (vidtest) { 812 if (vidtest) {
887 macfb_setpalette = v8_brazil_setpalette; 813 macfb_setpalette = v8_brazil_setpalette;
@@ -891,7 +817,10 @@ static int __init macfb_init(void)
891 } 817 }
892 strcpy(macfb_fix.id, "LC"); 818 strcpy(macfb_fix.id, "LC");
893 break; 819 break;
894 /* We think this may be like the LC II */ 820
821 /*
822 * We think this may be like the LC II
823 */
895 case MAC_MODEL_CCL: 824 case MAC_MODEL_CCL:
896 if (vidtest) { 825 if (vidtest) {
897 macfb_setpalette = v8_brazil_setpalette; 826 macfb_setpalette = v8_brazil_setpalette;
@@ -902,31 +831,42 @@ static int __init macfb_init(void)
902 strcpy(macfb_fix.id, "Color Classic"); 831 strcpy(macfb_fix.id, "Color Classic");
903 break; 832 break;
904 833
905 /* And we *do* mean "weirdos" */ 834 /*
835 * And we *do* mean "weirdos"
836 */
906 case MAC_MODEL_TV: 837 case MAC_MODEL_TV:
907 strcpy(macfb_fix.id, "Mac TV"); 838 strcpy(macfb_fix.id, "Mac TV");
908 break; 839 break;
909 840
910 /* These don't have colour, so no need to worry */ 841 /*
842 * These don't have colour, so no need to worry
843 */
911 case MAC_MODEL_SE30: 844 case MAC_MODEL_SE30:
912 case MAC_MODEL_CLII: 845 case MAC_MODEL_CLII:
913 strcpy(macfb_fix.id, "Monochrome"); 846 strcpy(macfb_fix.id, "Monochrome");
914 break; 847 break;
915 848
916 /* Powerbooks are particularly difficult. Many of 849 /*
917 them have separate framebuffers for external and 850 * Powerbooks are particularly difficult. Many of
918 internal video, which is admittedly pretty cool, 851 * them have separate framebuffers for external and
919 but will be a bit of a headache to support here. 852 * internal video, which is admittedly pretty cool,
920 Also, many of them are grayscale, and we don't 853 * but will be a bit of a headache to support here.
921 really support that. */ 854 * Also, many of them are grayscale, and we don't
922 855 * really support that.
856 */
857
858 /*
859 * Slot 0 ROM says TIM. No external video. B&W.
860 */
923 case MAC_MODEL_PB140: 861 case MAC_MODEL_PB140:
924 case MAC_MODEL_PB145: 862 case MAC_MODEL_PB145:
925 case MAC_MODEL_PB170: 863 case MAC_MODEL_PB170:
926 strcpy(macfb_fix.id, "DDC"); 864 strcpy(macfb_fix.id, "DDC");
927 break; 865 break;
928 866
929 /* Internal is GSC, External (if present) is ViSC */ 867 /*
868 * Internal is GSC, External (if present) is ViSC
869 */
930 case MAC_MODEL_PB150: /* no external video */ 870 case MAC_MODEL_PB150: /* no external video */
931 case MAC_MODEL_PB160: 871 case MAC_MODEL_PB160:
932 case MAC_MODEL_PB165: 872 case MAC_MODEL_PB165:
@@ -936,13 +876,17 @@ static int __init macfb_init(void)
936 strcpy(macfb_fix.id, "GSC"); 876 strcpy(macfb_fix.id, "GSC");
937 break; 877 break;
938 878
939 /* Internal is TIM, External is ViSC */ 879 /*
880 * Internal is TIM, External is ViSC
881 */
940 case MAC_MODEL_PB165C: 882 case MAC_MODEL_PB165C:
941 case MAC_MODEL_PB180C: 883 case MAC_MODEL_PB180C:
942 strcpy(macfb_fix.id, "TIM"); 884 strcpy(macfb_fix.id, "TIM");
943 break; 885 break;
944 886
945 /* Internal is CSC, External is Keystone+Ariel. */ 887 /*
888 * Internal is CSC, External is Keystone+Ariel.
889 */
946 case MAC_MODEL_PB190: /* external video is optional */ 890 case MAC_MODEL_PB190: /* external video is optional */
947 case MAC_MODEL_PB520: 891 case MAC_MODEL_PB520:
948 case MAC_MODEL_PB250: 892 case MAC_MODEL_PB250:
@@ -954,7 +898,7 @@ static int __init macfb_init(void)
954 strcpy(macfb_fix.id, "CSC"); 898 strcpy(macfb_fix.id, "CSC");
955 csc_cmap_regs = ioremap(CSC_BASE, 0x1000); 899 csc_cmap_regs = ioremap(CSC_BASE, 0x1000);
956 break; 900 break;
957 901
958 default: 902 default:
959 strcpy(macfb_fix.id, "Unknown"); 903 strcpy(macfb_fix.id, "Unknown");
960 break; 904 break;
@@ -969,7 +913,7 @@ static int __init macfb_init(void)
969 err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0); 913 err = fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
970 if (err) 914 if (err)
971 goto fail_unmap; 915 goto fail_unmap;
972 916
973 err = register_framebuffer(&fb_info); 917 err = register_framebuffer(&fb_info);
974 if (err) 918 if (err)
975 goto fail_dealloc; 919 goto fail_dealloc;
diff --git a/drivers/video/macmodes.c b/drivers/video/macmodes.c
index 083f60321ed8..af86c081d2be 100644
--- a/drivers/video/macmodes.c
+++ b/drivers/video/macmodes.c
@@ -33,6 +33,10 @@
33 33
34static const struct fb_videomode mac_modedb[] = { 34static const struct fb_videomode mac_modedb[] = {
35 { 35 {
36 /* 512x384, 60Hz, Non-Interlaced (15.67 MHz dot clock) */
37 "mac2", 60, 512, 384, 63828, 80, 16, 19, 1, 32, 3,
38 0, FB_VMODE_NONINTERLACED
39 }, {
36 /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */ 40 /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */
37 "mac5", 60, 640, 480, 39722, 32, 32, 33, 10, 96, 2, 41 "mac5", 60, 640, 480, 39722, 32, 32, 33, 10, 96, 2,
38 0, FB_VMODE_NONINTERLACED 42 0, FB_VMODE_NONINTERLACED
@@ -41,6 +45,10 @@ static const struct fb_videomode mac_modedb[] = {
41 "mac6", 67, 640, 480, 33334, 80, 80, 39, 3, 64, 3, 45 "mac6", 67, 640, 480, 33334, 80, 80, 39, 3, 64, 3,
42 0, FB_VMODE_NONINTERLACED 46 0, FB_VMODE_NONINTERLACED
43 }, { 47 }, {
48 /* 640x870, 75Hz (portrait), Non-Interlaced (57.28 MHz dot clock) */
49 "mac7", 75, 640, 870, 17457, 80, 32, 42, 3, 80, 3,
50 0, FB_VMODE_NONINTERLACED
51 }, {
44 /* 800x600, 56 Hz, Non-Interlaced (36.00 MHz dotclock) */ 52 /* 800x600, 56 Hz, Non-Interlaced (36.00 MHz dotclock) */
45 "mac9", 56, 800, 600, 27778, 112, 40, 22, 1, 72, 2, 53 "mac9", 56, 800, 600, 27778, 112, 40, 22, 1, 72, 2,
46 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED 54 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
@@ -105,10 +113,6 @@ static const struct fb_videomode mac_modedb[] = {
105 "mac1", 60, 512, 384, pixclock, left, right, upper, lower, hslen, vslen, 113 "mac1", 60, 512, 384, pixclock, left, right, upper, lower, hslen, vslen,
106 sync, FB_VMODE_INTERLACED 114 sync, FB_VMODE_INTERLACED
107 }, { 115 }, {
108 /* VMODE_512_384_60: 512x384, 60Hz, Non-Interlaced */
109 "mac2", 60, 512, 384, pixclock, left, right, upper, lower, hslen, vslen,
110 sync, FB_VMODE_NONINTERLACED
111 }, {
112 /* VMODE_640_480_50I: 640x480, 50Hz, Interlaced (PAL) */ 116 /* VMODE_640_480_50I: 640x480, 50Hz, Interlaced (PAL) */
113 "mac3", 50, 640, 480, pixclock, left, right, upper, lower, hslen, vslen, 117 "mac3", 50, 640, 480, pixclock, left, right, upper, lower, hslen, vslen,
114 sync, FB_VMODE_INTERLACED 118 sync, FB_VMODE_INTERLACED
@@ -117,10 +121,6 @@ static const struct fb_videomode mac_modedb[] = {
117 "mac4", 60, 640, 480, pixclock, left, right, upper, lower, hslen, vslen, 121 "mac4", 60, 640, 480, pixclock, left, right, upper, lower, hslen, vslen,
118 sync, FB_VMODE_INTERLACED 122 sync, FB_VMODE_INTERLACED
119 }, { 123 }, {
120 /* VMODE_640_870_75P: 640x870, 75Hz (portrait), Non-Interlaced */
121 "mac7", 75, 640, 870, pixclock, left, right, upper, lower, hslen, vslen,
122 sync, FB_VMODE_NONINTERLACED
123 }, {
124 /* VMODE_768_576_50I: 768x576, 50Hz (PAL full frame), Interlaced */ 124 /* VMODE_768_576_50I: 768x576, 50Hz (PAL full frame), Interlaced */
125 "mac8", 50, 768, 576, pixclock, left, right, upper, lower, hslen, vslen, 125 "mac8", 50, 768, 576, pixclock, left, right, upper, lower, hslen, vslen,
126 sync, FB_VMODE_INTERLACED 126 sync, FB_VMODE_INTERLACED
@@ -134,38 +134,42 @@ static const struct fb_videomode mac_modedb[] = {
134 * 134 *
135 * These MUST be ordered in 135 * These MUST be ordered in
136 * - increasing resolution 136 * - increasing resolution
137 * - decreasing refresh rate 137 * - decreasing pixel clock period
138 */ 138 */
139 139
140static const struct mode_map { 140static const struct mode_map {
141 int vmode; 141 int vmode;
142 const struct fb_videomode *mode; 142 const struct fb_videomode *mode;
143} mac_modes[] = { 143} mac_modes[] = {
144 /* 512x384 */
145 { VMODE_512_384_60, &mac_modedb[0] },
144 /* 640x480 */ 146 /* 640x480 */
145 { VMODE_640_480_67, &mac_modedb[1] }, 147 { VMODE_640_480_60, &mac_modedb[1] },
146 { VMODE_640_480_60, &mac_modedb[0] }, 148 { VMODE_640_480_67, &mac_modedb[2] },
149 /* 640x870 */
150 { VMODE_640_870_75P, &mac_modedb[3] },
147 /* 800x600 */ 151 /* 800x600 */
148 { VMODE_800_600_75, &mac_modedb[5] }, 152 { VMODE_800_600_56, &mac_modedb[4] },
149 { VMODE_800_600_72, &mac_modedb[4] }, 153 { VMODE_800_600_60, &mac_modedb[5] },
150 { VMODE_800_600_60, &mac_modedb[3] }, 154 { VMODE_800_600_75, &mac_modedb[7] },
151 { VMODE_800_600_56, &mac_modedb[2] }, 155 { VMODE_800_600_72, &mac_modedb[6] },
152 /* 832x624 */ 156 /* 832x624 */
153 { VMODE_832_624_75, &mac_modedb[6] }, 157 { VMODE_832_624_75, &mac_modedb[8] },
154 /* 1024x768 */ 158 /* 1024x768 */
155 { VMODE_1024_768_75, &mac_modedb[10] }, 159 { VMODE_1024_768_60, &mac_modedb[9] },
156 { VMODE_1024_768_75V, &mac_modedb[9] }, 160 { VMODE_1024_768_70, &mac_modedb[10] },
157 { VMODE_1024_768_70, &mac_modedb[8] }, 161 { VMODE_1024_768_75V, &mac_modedb[11] },
158 { VMODE_1024_768_60, &mac_modedb[7] }, 162 { VMODE_1024_768_75, &mac_modedb[12] },
159 /* 1152x768 */ 163 /* 1152x768 */
160 { VMODE_1152_768_60, &mac_modedb[14] }, 164 { VMODE_1152_768_60, &mac_modedb[16] },
161 /* 1152x870 */ 165 /* 1152x870 */
162 { VMODE_1152_870_75, &mac_modedb[11] }, 166 { VMODE_1152_870_75, &mac_modedb[13] },
163 /* 1280x960 */ 167 /* 1280x960 */
164 { VMODE_1280_960_75, &mac_modedb[12] }, 168 { VMODE_1280_960_75, &mac_modedb[14] },
165 /* 1280x1024 */ 169 /* 1280x1024 */
166 { VMODE_1280_1024_75, &mac_modedb[13] }, 170 { VMODE_1280_1024_75, &mac_modedb[15] },
167 /* 1600x1024 */ 171 /* 1600x1024 */
168 { VMODE_1600_1024_60, &mac_modedb[15] }, 172 { VMODE_1600_1024_60, &mac_modedb[17] },
169 { -1, NULL } 173 { -1, NULL }
170}; 174};
171 175
@@ -299,7 +303,6 @@ EXPORT_SYMBOL(mac_vmode_to_var);
299int mac_var_to_vmode(const struct fb_var_screeninfo *var, int *vmode, 303int mac_var_to_vmode(const struct fb_var_screeninfo *var, int *vmode,
300 int *cmode) 304 int *cmode)
301{ 305{
302 const struct fb_videomode *mode = NULL;
303 const struct mode_map *map; 306 const struct mode_map *map;
304 307
305 if (var->bits_per_pixel <= 8) 308 if (var->bits_per_pixel <= 8)
@@ -311,8 +314,13 @@ int mac_var_to_vmode(const struct fb_var_screeninfo *var, int *vmode,
311 else 314 else
312 return -EINVAL; 315 return -EINVAL;
313 316
317 /*
318 * Find the mac_mode with a matching resolution or failing that, the
319 * closest larger resolution. Skip modes with a shorter pixel clock period.
320 */
314 for (map = mac_modes; map->vmode != -1; map++) { 321 for (map = mac_modes; map->vmode != -1; map++) {
315 mode = map->mode; 322 const struct fb_videomode *mode = map->mode;
323
316 if (var->xres > mode->xres || var->yres > mode->yres) 324 if (var->xres > mode->xres || var->yres > mode->yres)
317 continue; 325 continue;
318 if (var->xres_virtual > mode->xres || var->yres_virtual > mode->yres) 326 if (var->xres_virtual > mode->xres || var->yres_virtual > mode->yres)
@@ -322,6 +330,24 @@ int mac_var_to_vmode(const struct fb_var_screeninfo *var, int *vmode,
322 if ((var->vmode & FB_VMODE_MASK) != mode->vmode) 330 if ((var->vmode & FB_VMODE_MASK) != mode->vmode)
323 continue; 331 continue;
324 *vmode = map->vmode; 332 *vmode = map->vmode;
333
334 /*
335 * Having found a good resolution, find the matching pixel clock
336 * or failing that, the closest longer pixel clock period.
337 */
338 map++;
339 while (map->vmode != -1) {
340 const struct fb_videomode *clk_mode = map->mode;
341
342 if (mode->xres != clk_mode->xres || mode->yres != clk_mode->yres)
343 break;
344 if (var->pixclock > mode->pixclock)
345 break;
346 if (mode->vmode != clk_mode->vmode)
347 continue;
348 *vmode = map->vmode;
349 map++;
350 }
325 return 0; 351 return 0;
326 } 352 }
327 return -EINVAL; 353 return -EINVAL;
diff --git a/drivers/video/pvr2fb.c b/drivers/video/pvr2fb.c
index 53f8f1100e81..f9975100d56d 100644
--- a/drivers/video/pvr2fb.c
+++ b/drivers/video/pvr2fb.c
@@ -831,7 +831,7 @@ static int __devinit pvr2fb_common_init(void)
831 printk(KERN_NOTICE "fb%d: registering with SQ API\n", fb_info->node); 831 printk(KERN_NOTICE "fb%d: registering with SQ API\n", fb_info->node);
832 832
833 pvr2fb_map = sq_remap(fb_info->fix.smem_start, fb_info->fix.smem_len, 833 pvr2fb_map = sq_remap(fb_info->fix.smem_start, fb_info->fix.smem_len,
834 fb_info->fix.id, pgprot_val(PAGE_SHARED)); 834 fb_info->fix.id, PAGE_SHARED);
835 835
836 printk(KERN_NOTICE "fb%d: Mapped video memory to SQ addr 0x%lx\n", 836 printk(KERN_NOTICE "fb%d: Mapped video memory to SQ addr 0x%lx\n",
837 fb_info->node, pvr2fb_map); 837 fb_info->node, pvr2fb_map);
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index a69830d26f7f..8d7653e56df5 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -19,6 +19,7 @@
19#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/vmalloc.h> 21#include <linux/vmalloc.h>
22#include <linux/ioctl.h>
22#include <video/sh_mobile_lcdc.h> 23#include <video/sh_mobile_lcdc.h>
23#include <asm/atomic.h> 24#include <asm/atomic.h>
24 25
@@ -106,6 +107,7 @@ static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
106#define LDRCNTR_SRC 0x00010000 107#define LDRCNTR_SRC 0x00010000
107#define LDRCNTR_MRS 0x00000002 108#define LDRCNTR_MRS 0x00000002
108#define LDRCNTR_MRC 0x00000001 109#define LDRCNTR_MRC 0x00000001
110#define LDSR_MRS 0x00000100
109 111
110struct sh_mobile_lcdc_priv; 112struct sh_mobile_lcdc_priv;
111struct sh_mobile_lcdc_chan { 113struct sh_mobile_lcdc_chan {
@@ -122,8 +124,8 @@ struct sh_mobile_lcdc_chan {
122 struct scatterlist *sglist; 124 struct scatterlist *sglist;
123 unsigned long frame_end; 125 unsigned long frame_end;
124 unsigned long pan_offset; 126 unsigned long pan_offset;
125 unsigned long new_pan_offset;
126 wait_queue_head_t frame_end_wait; 127 wait_queue_head_t frame_end_wait;
128 struct completion vsync_completion;
127}; 129};
128 130
129struct sh_mobile_lcdc_priv { 131struct sh_mobile_lcdc_priv {
@@ -366,19 +368,8 @@ static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
366 } 368 }
367 369
368 /* VSYNC End */ 370 /* VSYNC End */
369 if (ldintr & LDINTR_VES) { 371 if (ldintr & LDINTR_VES)
370 unsigned long ldrcntr = lcdc_read(priv, _LDRCNTR); 372 complete(&ch->vsync_completion);
371 /* Set the source address for the next refresh */
372 lcdc_write_chan_mirror(ch, LDSA1R, ch->dma_handle +
373 ch->new_pan_offset);
374 if (lcdc_chan_is_sublcd(ch))
375 lcdc_write(ch->lcdc, _LDRCNTR,
376 ldrcntr ^ LDRCNTR_SRS);
377 else
378 lcdc_write(ch->lcdc, _LDRCNTR,
379 ldrcntr ^ LDRCNTR_MRS);
380 ch->pan_offset = ch->new_pan_offset;
381 }
382 } 373 }
383 374
384 return IRQ_HANDLED; 375 return IRQ_HANDLED;
@@ -767,25 +758,69 @@ static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
767 struct fb_info *info) 758 struct fb_info *info)
768{ 759{
769 struct sh_mobile_lcdc_chan *ch = info->par; 760 struct sh_mobile_lcdc_chan *ch = info->par;
761 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
762 unsigned long ldrcntr;
763 unsigned long new_pan_offset;
764
765 new_pan_offset = (var->yoffset * info->fix.line_length) +
766 (var->xoffset * (info->var.bits_per_pixel / 8));
770 767
771 if (info->var.xoffset == var->xoffset && 768 if (new_pan_offset == ch->pan_offset)
772 info->var.yoffset == var->yoffset)
773 return 0; /* No change, do nothing */ 769 return 0; /* No change, do nothing */
774 770
775 ch->new_pan_offset = (var->yoffset * info->fix.line_length) + 771 ldrcntr = lcdc_read(priv, _LDRCNTR);
776 (var->xoffset * (info->var.bits_per_pixel / 8));
777 772
778 if (ch->new_pan_offset != ch->pan_offset) { 773 /* Set the source address for the next refresh */
779 unsigned long ldintr; 774 lcdc_write_chan_mirror(ch, LDSA1R, ch->dma_handle + new_pan_offset);
780 ldintr = lcdc_read(ch->lcdc, _LDINTR); 775 if (lcdc_chan_is_sublcd(ch))
781 ldintr |= LDINTR_VEE; 776 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
782 lcdc_write(ch->lcdc, _LDINTR, ldintr); 777 else
783 sh_mobile_lcdc_deferred_io_touch(info); 778 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
784 } 779
780 ch->pan_offset = new_pan_offset;
781
782 sh_mobile_lcdc_deferred_io_touch(info);
783
784 return 0;
785}
786
787static int sh_mobile_wait_for_vsync(struct fb_info *info)
788{
789 struct sh_mobile_lcdc_chan *ch = info->par;
790 unsigned long ldintr;
791 int ret;
792
793 /* Enable VSync End interrupt */
794 ldintr = lcdc_read(ch->lcdc, _LDINTR);
795 ldintr |= LDINTR_VEE;
796 lcdc_write(ch->lcdc, _LDINTR, ldintr);
797
798 ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
799 msecs_to_jiffies(100));
800 if (!ret)
801 return -ETIMEDOUT;
785 802
786 return 0; 803 return 0;
787} 804}
788 805
806static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
807 unsigned long arg)
808{
809 int retval;
810
811 switch (cmd) {
812 case FBIO_WAITFORVSYNC:
813 retval = sh_mobile_wait_for_vsync(info);
814 break;
815
816 default:
817 retval = -ENOIOCTLCMD;
818 break;
819 }
820 return retval;
821}
822
823
789static struct fb_ops sh_mobile_lcdc_ops = { 824static struct fb_ops sh_mobile_lcdc_ops = {
790 .owner = THIS_MODULE, 825 .owner = THIS_MODULE,
791 .fb_setcolreg = sh_mobile_lcdc_setcolreg, 826 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
@@ -795,6 +830,7 @@ static struct fb_ops sh_mobile_lcdc_ops = {
795 .fb_copyarea = sh_mobile_lcdc_copyarea, 830 .fb_copyarea = sh_mobile_lcdc_copyarea,
796 .fb_imageblit = sh_mobile_lcdc_imageblit, 831 .fb_imageblit = sh_mobile_lcdc_imageblit,
797 .fb_pan_display = sh_mobile_fb_pan_display, 832 .fb_pan_display = sh_mobile_fb_pan_display,
833 .fb_ioctl = sh_mobile_ioctl,
798}; 834};
799 835
800static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp) 836static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp)
@@ -962,8 +998,8 @@ static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
962 goto err1; 998 goto err1;
963 } 999 }
964 init_waitqueue_head(&priv->ch[i].frame_end_wait); 1000 init_waitqueue_head(&priv->ch[i].frame_end_wait);
1001 init_completion(&priv->ch[i].vsync_completion);
965 priv->ch[j].pan_offset = 0; 1002 priv->ch[j].pan_offset = 0;
966 priv->ch[j].new_pan_offset = 0;
967 1003
968 switch (pdata->ch[i].chan) { 1004 switch (pdata->ch[i].chan) {
969 case LCDC_CHAN_MAINLCD: 1005 case LCDC_CHAN_MAINLCD:
diff --git a/drivers/video/valkyriefb.c b/drivers/video/valkyriefb.c
index 4bb9a0b18950..6b52bf65f0b5 100644
--- a/drivers/video/valkyriefb.c
+++ b/drivers/video/valkyriefb.c
@@ -69,7 +69,7 @@
69#ifdef CONFIG_MAC 69#ifdef CONFIG_MAC
70/* We don't yet have functions to read the PRAM... perhaps we can 70/* We don't yet have functions to read the PRAM... perhaps we can
71 adapt them from the PPC code? */ 71 adapt them from the PPC code? */
72static int default_vmode = VMODE_640_480_67; 72static int default_vmode = VMODE_CHOOSE;
73static int default_cmode = CMODE_8; 73static int default_cmode = CMODE_8;
74#else 74#else
75static int default_vmode = VMODE_NVRAM; 75static int default_vmode = VMODE_NVRAM;
@@ -326,11 +326,11 @@ int __init valkyriefb_init(void)
326 326
327#ifdef CONFIG_MAC 327#ifdef CONFIG_MAC
328 if (!MACH_IS_MAC) 328 if (!MACH_IS_MAC)
329 return 0; 329 return -ENODEV;
330 if (!(mac_bi_data.id == MAC_MODEL_Q630 330 if (!(mac_bi_data.id == MAC_MODEL_Q630
331 /* I'm not sure about this one */ 331 /* I'm not sure about this one */
332 || mac_bi_data.id == MAC_MODEL_P588)) 332 || mac_bi_data.id == MAC_MODEL_P588))
333 return 0; 333 return -ENODEV;
334 334
335 /* Hardcoded addresses... welcome to 68k Macintosh country :-) */ 335 /* Hardcoded addresses... welcome to 68k Macintosh country :-) */
336 frame_buffer_phys = 0xf9000000; 336 frame_buffer_phys = 0xf9000000;
diff --git a/drivers/video/valkyriefb.h b/drivers/video/valkyriefb.h
index 97aaf7bb6417..d787441e5a42 100644
--- a/drivers/video/valkyriefb.h
+++ b/drivers/video/valkyriefb.h
@@ -134,15 +134,7 @@ static struct valkyrie_regvals valkyrie_reg_init_14 = {
134 { 1024, 0 }, 134 { 1024, 0 },
135 1024, 768 135 1024, 768
136}; 136};
137 137#endif /* !defined CONFIG_MAC */
138/* Register values for 800x600, 72Hz mode (11) */
139static struct valkyrie_regvals valkyrie_reg_init_11 = {
140 13,
141 { 17, 27, 3 }, /* pixel clock = 49.63MHz for V=71.66Hz */
142 { 800, 0 },
143 800, 600
144};
145#endif /* CONFIG_MAC */
146 138
147/* Register values for 832x624, 75Hz mode (13) */ 139/* Register values for 832x624, 75Hz mode (13) */
148static struct valkyrie_regvals valkyrie_reg_init_13 = { 140static struct valkyrie_regvals valkyrie_reg_init_13 = {
@@ -152,6 +144,14 @@ static struct valkyrie_regvals valkyrie_reg_init_13 = {
152 832, 624 144 832, 624
153}; 145};
154 146
147/* Register values for 800x600, 72Hz mode (11) */
148static struct valkyrie_regvals valkyrie_reg_init_11 = {
149 13,
150 { 17, 27, 3 }, /* pixel clock = 49.63MHz for V=71.66Hz */
151 { 800, 0 },
152 800, 600
153};
154
155/* Register values for 800x600, 60Hz mode (10) */ 155/* Register values for 800x600, 60Hz mode (10) */
156static struct valkyrie_regvals valkyrie_reg_init_10 = { 156static struct valkyrie_regvals valkyrie_reg_init_10 = {
157 12, 157 12,
@@ -188,24 +188,13 @@ static struct valkyrie_regvals *valkyrie_reg_init[VMODE_MAX] = {
188 NULL, 188 NULL,
189 NULL, 189 NULL,
190 &valkyrie_reg_init_10, 190 &valkyrie_reg_init_10,
191#ifdef CONFIG_MAC
192 NULL,
193 NULL,
194 &valkyrie_reg_init_13,
195 NULL,
196 NULL,
197 NULL,
198 NULL,
199#else
200 &valkyrie_reg_init_11, 191 &valkyrie_reg_init_11,
201 NULL, 192 NULL,
202 &valkyrie_reg_init_13, 193 &valkyrie_reg_init_13,
194#ifndef CONFIG_MAC
203 &valkyrie_reg_init_14, 195 &valkyrie_reg_init_14,
204 &valkyrie_reg_init_15, 196 &valkyrie_reg_init_15,
205 NULL, 197 NULL,
206 &valkyrie_reg_init_17, 198 &valkyrie_reg_init_17,
207#endif 199#endif
208 NULL,
209 NULL,
210 NULL
211}; 200};
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 505be88c82ae..369f2eebbad1 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -28,7 +28,7 @@
28struct virtio_balloon 28struct virtio_balloon
29{ 29{
30 struct virtio_device *vdev; 30 struct virtio_device *vdev;
31 struct virtqueue *inflate_vq, *deflate_vq; 31 struct virtqueue *inflate_vq, *deflate_vq, *stats_vq;
32 32
33 /* Where the ballooning thread waits for config to change. */ 33 /* Where the ballooning thread waits for config to change. */
34 wait_queue_head_t config_change; 34 wait_queue_head_t config_change;
@@ -49,6 +49,10 @@ struct virtio_balloon
49 /* The array of pfns we tell the Host about. */ 49 /* The array of pfns we tell the Host about. */
50 unsigned int num_pfns; 50 unsigned int num_pfns;
51 u32 pfns[256]; 51 u32 pfns[256];
52
53 /* Memory statistics */
54 int need_stats_update;
55 struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR];
52}; 56};
53 57
54static struct virtio_device_id id_table[] = { 58static struct virtio_device_id id_table[] = {
@@ -154,6 +158,72 @@ static void leak_balloon(struct virtio_balloon *vb, size_t num)
154 } 158 }
155} 159}
156 160
161static inline void update_stat(struct virtio_balloon *vb, int idx,
162 u16 tag, u64 val)
163{
164 BUG_ON(idx >= VIRTIO_BALLOON_S_NR);
165 vb->stats[idx].tag = tag;
166 vb->stats[idx].val = val;
167}
168
169#define pages_to_bytes(x) ((u64)(x) << PAGE_SHIFT)
170
171static void update_balloon_stats(struct virtio_balloon *vb)
172{
173 unsigned long events[NR_VM_EVENT_ITEMS];
174 struct sysinfo i;
175 int idx = 0;
176
177 all_vm_events(events);
178 si_meminfo(&i);
179
180 update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
181 pages_to_bytes(events[PSWPIN]));
182 update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT,
183 pages_to_bytes(events[PSWPOUT]));
184 update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]);
185 update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]);
186 update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE,
187 pages_to_bytes(i.freeram));
188 update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT,
189 pages_to_bytes(i.totalram));
190}
191
192/*
193 * While most virtqueues communicate guest-initiated requests to the hypervisor,
194 * the stats queue operates in reverse. The driver initializes the virtqueue
195 * with a single buffer. From that point forward, all conversations consist of
196 * a hypervisor request (a call to this function) which directs us to refill
197 * the virtqueue with a fresh stats buffer. Since stats collection can sleep,
198 * we notify our kthread which does the actual work via stats_handle_request().
199 */
200static void stats_request(struct virtqueue *vq)
201{
202 struct virtio_balloon *vb;
203 unsigned int len;
204
205 vb = vq->vq_ops->get_buf(vq, &len);
206 if (!vb)
207 return;
208 vb->need_stats_update = 1;
209 wake_up(&vb->config_change);
210}
211
212static void stats_handle_request(struct virtio_balloon *vb)
213{
214 struct virtqueue *vq;
215 struct scatterlist sg;
216
217 vb->need_stats_update = 0;
218 update_balloon_stats(vb);
219
220 vq = vb->stats_vq;
221 sg_init_one(&sg, vb->stats, sizeof(vb->stats));
222 if (vq->vq_ops->add_buf(vq, &sg, 1, 0, vb) < 0)
223 BUG();
224 vq->vq_ops->kick(vq);
225}
226
157static void virtballoon_changed(struct virtio_device *vdev) 227static void virtballoon_changed(struct virtio_device *vdev)
158{ 228{
159 struct virtio_balloon *vb = vdev->priv; 229 struct virtio_balloon *vb = vdev->priv;
@@ -190,8 +260,11 @@ static int balloon(void *_vballoon)
190 try_to_freeze(); 260 try_to_freeze();
191 wait_event_interruptible(vb->config_change, 261 wait_event_interruptible(vb->config_change,
192 (diff = towards_target(vb)) != 0 262 (diff = towards_target(vb)) != 0
263 || vb->need_stats_update
193 || kthread_should_stop() 264 || kthread_should_stop()
194 || freezing(current)); 265 || freezing(current));
266 if (vb->need_stats_update)
267 stats_handle_request(vb);
195 if (diff > 0) 268 if (diff > 0)
196 fill_balloon(vb, diff); 269 fill_balloon(vb, diff);
197 else if (diff < 0) 270 else if (diff < 0)
@@ -204,10 +277,10 @@ static int balloon(void *_vballoon)
204static int virtballoon_probe(struct virtio_device *vdev) 277static int virtballoon_probe(struct virtio_device *vdev)
205{ 278{
206 struct virtio_balloon *vb; 279 struct virtio_balloon *vb;
207 struct virtqueue *vqs[2]; 280 struct virtqueue *vqs[3];
208 vq_callback_t *callbacks[] = { balloon_ack, balloon_ack }; 281 vq_callback_t *callbacks[] = { balloon_ack, balloon_ack, stats_request };
209 const char *names[] = { "inflate", "deflate" }; 282 const char *names[] = { "inflate", "deflate", "stats" };
210 int err; 283 int err, nvqs;
211 284
212 vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL); 285 vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL);
213 if (!vb) { 286 if (!vb) {
@@ -219,14 +292,31 @@ static int virtballoon_probe(struct virtio_device *vdev)
219 vb->num_pages = 0; 292 vb->num_pages = 0;
220 init_waitqueue_head(&vb->config_change); 293 init_waitqueue_head(&vb->config_change);
221 vb->vdev = vdev; 294 vb->vdev = vdev;
295 vb->need_stats_update = 0;
222 296
223 /* We expect two virtqueues. */ 297 /* We expect two virtqueues: inflate and deflate,
224 err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names); 298 * and optionally stat. */
299 nvqs = virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ) ? 3 : 2;
300 err = vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names);
225 if (err) 301 if (err)
226 goto out_free_vb; 302 goto out_free_vb;
227 303
228 vb->inflate_vq = vqs[0]; 304 vb->inflate_vq = vqs[0];
229 vb->deflate_vq = vqs[1]; 305 vb->deflate_vq = vqs[1];
306 if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
307 struct scatterlist sg;
308 vb->stats_vq = vqs[2];
309
310 /*
311 * Prime this virtqueue with one buffer so the hypervisor can
312 * use it to signal us later.
313 */
314 sg_init_one(&sg, vb->stats, sizeof vb->stats);
315 if (vb->stats_vq->vq_ops->add_buf(vb->stats_vq,
316 &sg, 1, 0, vb) < 0)
317 BUG();
318 vb->stats_vq->vq_ops->kick(vb->stats_vq);
319 }
230 320
231 vb->thread = kthread_run(balloon, vb, "vballoon"); 321 vb->thread = kthread_run(balloon, vb, "vballoon");
232 if (IS_ERR(vb->thread)) { 322 if (IS_ERR(vb->thread)) {
@@ -264,7 +354,10 @@ static void __devexit virtballoon_remove(struct virtio_device *vdev)
264 kfree(vb); 354 kfree(vb);
265} 355}
266 356
267static unsigned int features[] = { VIRTIO_BALLOON_F_MUST_TELL_HOST }; 357static unsigned int features[] = {
358 VIRTIO_BALLOON_F_MUST_TELL_HOST,
359 VIRTIO_BALLOON_F_STATS_VQ,
360};
268 361
269static struct virtio_driver virtio_balloon_driver = { 362static struct virtio_driver virtio_balloon_driver = {
270 .feature_table = features, 363 .feature_table = features,
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 28d9cf7cf72f..1d5191fab62e 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -702,7 +702,7 @@ static struct pci_driver virtio_pci_driver = {
702 .name = "virtio-pci", 702 .name = "virtio-pci",
703 .id_table = virtio_pci_id_table, 703 .id_table = virtio_pci_id_table,
704 .probe = virtio_pci_probe, 704 .probe = virtio_pci_probe,
705 .remove = virtio_pci_remove, 705 .remove = __devexit_p(virtio_pci_remove),
706#ifdef CONFIG_PM 706#ifdef CONFIG_PM
707 .suspend = virtio_pci_suspend, 707 .suspend = virtio_pci_suspend,
708 .resume = virtio_pci_resume, 708 .resume = virtio_pci_resume,
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 71929ee00d69..0db906b3c95d 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -21,6 +21,24 @@
21#include <linux/virtio_config.h> 21#include <linux/virtio_config.h>
22#include <linux/device.h> 22#include <linux/device.h>
23 23
24/* virtio guest is communicating with a virtual "device" that actually runs on
25 * a host processor. Memory barriers are used to control SMP effects. */
26#ifdef CONFIG_SMP
27/* Where possible, use SMP barriers which are more lightweight than mandatory
28 * barriers, because mandatory barriers control MMIO effects on accesses
29 * through relaxed memory I/O windows (which virtio does not use). */
30#define virtio_mb() smp_mb()
31#define virtio_rmb() smp_rmb()
32#define virtio_wmb() smp_wmb()
33#else
34/* We must force memory ordering even if guest is UP since host could be
35 * running on another CPU, but SMP barriers are defined to barrier() in that
36 * configuration. So fall back to mandatory barriers instead. */
37#define virtio_mb() mb()
38#define virtio_rmb() rmb()
39#define virtio_wmb() wmb()
40#endif
41
24#ifdef DEBUG 42#ifdef DEBUG
25/* For development, we want to crash whenever the ring is screwed. */ 43/* For development, we want to crash whenever the ring is screwed. */
26#define BAD_RING(_vq, fmt, args...) \ 44#define BAD_RING(_vq, fmt, args...) \
@@ -36,10 +54,9 @@
36 panic("%s:in_use = %i\n", \ 54 panic("%s:in_use = %i\n", \
37 (_vq)->vq.name, (_vq)->in_use); \ 55 (_vq)->vq.name, (_vq)->in_use); \
38 (_vq)->in_use = __LINE__; \ 56 (_vq)->in_use = __LINE__; \
39 mb(); \
40 } while (0) 57 } while (0)
41#define END_USE(_vq) \ 58#define END_USE(_vq) \
42 do { BUG_ON(!(_vq)->in_use); (_vq)->in_use = 0; mb(); } while(0) 59 do { BUG_ON(!(_vq)->in_use); (_vq)->in_use = 0; } while(0)
43#else 60#else
44#define BAD_RING(_vq, fmt, args...) \ 61#define BAD_RING(_vq, fmt, args...) \
45 do { \ 62 do { \
@@ -221,13 +238,13 @@ static void vring_kick(struct virtqueue *_vq)
221 START_USE(vq); 238 START_USE(vq);
222 /* Descriptors and available array need to be set before we expose the 239 /* Descriptors and available array need to be set before we expose the
223 * new available array entries. */ 240 * new available array entries. */
224 wmb(); 241 virtio_wmb();
225 242
226 vq->vring.avail->idx += vq->num_added; 243 vq->vring.avail->idx += vq->num_added;
227 vq->num_added = 0; 244 vq->num_added = 0;
228 245
229 /* Need to update avail index before checking if we should notify */ 246 /* Need to update avail index before checking if we should notify */
230 mb(); 247 virtio_mb();
231 248
232 if (!(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY)) 249 if (!(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY))
233 /* Prod other side to tell it about changes. */ 250 /* Prod other side to tell it about changes. */
@@ -286,7 +303,7 @@ static void *vring_get_buf(struct virtqueue *_vq, unsigned int *len)
286 } 303 }
287 304
288 /* Only get used array entries after they have been exposed by host. */ 305 /* Only get used array entries after they have been exposed by host. */
289 rmb(); 306 virtio_rmb();
290 307
291 i = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].id; 308 i = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].id;
292 *len = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].len; 309 *len = vq->vring.used->ring[vq->last_used_idx%vq->vring.num].len;
@@ -324,7 +341,7 @@ static bool vring_enable_cb(struct virtqueue *_vq)
324 /* We optimistically turn back on interrupts, then check if there was 341 /* We optimistically turn back on interrupts, then check if there was
325 * more to do. */ 342 * more to do. */
326 vq->vring.avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT; 343 vq->vring.avail->flags &= ~VRING_AVAIL_F_NO_INTERRUPT;
327 mb(); 344 virtio_mb();
328 if (unlikely(more_used(vq))) { 345 if (unlikely(more_used(vq))) {
329 END_USE(vq); 346 END_USE(vq);
330 return false; 347 return false;
@@ -431,8 +448,11 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
431 /* Put everything in free lists. */ 448 /* Put everything in free lists. */
432 vq->num_free = num; 449 vq->num_free = num;
433 vq->free_head = 0; 450 vq->free_head = 0;
434 for (i = 0; i < num-1; i++) 451 for (i = 0; i < num-1; i++) {
435 vq->vring.desc[i].next = i+1; 452 vq->vring.desc[i].next = i+1;
453 vq->data[i] = NULL;
454 }
455 vq->data[i] = NULL;
436 456
437 return &vq->vq; 457 return &vq->vq;
438} 458}
diff --git a/drivers/watchdog/ar7_wdt.c b/drivers/watchdog/ar7_wdt.c
index 2e94b71b20d9..2bb95cd308c1 100644
--- a/drivers/watchdog/ar7_wdt.c
+++ b/drivers/watchdog/ar7_wdt.c
@@ -34,6 +34,7 @@
34#include <linux/ioport.h> 34#include <linux/ioport.h>
35#include <linux/io.h> 35#include <linux/io.h>
36#include <linux/uaccess.h> 36#include <linux/uaccess.h>
37#include <linux/clk.h>
37 38
38#include <asm/addrspace.h> 39#include <asm/addrspace.h>
39#include <asm/mach-ar7/ar7.h> 40#include <asm/mach-ar7/ar7.h>
@@ -80,6 +81,8 @@ static struct resource *ar7_regs_wdt;
80/* Pointer to the remapped WDT IO space */ 81/* Pointer to the remapped WDT IO space */
81static struct ar7_wdt *ar7_wdt; 82static struct ar7_wdt *ar7_wdt;
82 83
84static struct clk *vbus_clk;
85
83static void ar7_wdt_kick(u32 value) 86static void ar7_wdt_kick(u32 value)
84{ 87{
85 WRITE_REG(ar7_wdt->kick_lock, 0x5555); 88 WRITE_REG(ar7_wdt->kick_lock, 0x5555);
@@ -138,17 +141,19 @@ static void ar7_wdt_disable(u32 value)
138static void ar7_wdt_update_margin(int new_margin) 141static void ar7_wdt_update_margin(int new_margin)
139{ 142{
140 u32 change; 143 u32 change;
144 u32 vbus_rate;
141 145
142 change = new_margin * (ar7_vbus_freq() / prescale_value); 146 vbus_rate = clk_get_rate(vbus_clk);
147 change = new_margin * (vbus_rate / prescale_value);
143 if (change < 1) 148 if (change < 1)
144 change = 1; 149 change = 1;
145 if (change > 0xffff) 150 if (change > 0xffff)
146 change = 0xffff; 151 change = 0xffff;
147 ar7_wdt_change(change); 152 ar7_wdt_change(change);
148 margin = change * prescale_value / ar7_vbus_freq(); 153 margin = change * prescale_value / vbus_rate;
149 printk(KERN_INFO DRVNAME 154 printk(KERN_INFO DRVNAME
150 ": timer margin %d seconds (prescale %d, change %d, freq %d)\n", 155 ": timer margin %d seconds (prescale %d, change %d, freq %d)\n",
151 margin, prescale_value, change, ar7_vbus_freq()); 156 margin, prescale_value, change, vbus_rate);
152} 157}
153 158
154static void ar7_wdt_enable_wdt(void) 159static void ar7_wdt_enable_wdt(void)
@@ -298,6 +303,13 @@ static int __devinit ar7_wdt_probe(struct platform_device *pdev)
298 goto out_mem_region; 303 goto out_mem_region;
299 } 304 }
300 305
306 vbus_clk = clk_get(NULL, "vbus");
307 if (IS_ERR(vbus_clk)) {
308 printk(KERN_ERR DRVNAME ": could not get vbus clock\n");
309 rc = PTR_ERR(vbus_clk);
310 goto out_mem_region;
311 }
312
301 ar7_wdt_disable_wdt(); 313 ar7_wdt_disable_wdt();
302 ar7_wdt_prescale(prescale_value); 314 ar7_wdt_prescale(prescale_value);
303 ar7_wdt_update_margin(margin); 315 ar7_wdt_update_margin(margin);
diff --git a/drivers/watchdog/bfin_wdt.c b/drivers/watchdog/bfin_wdt.c
index c7b3f9df2317..2159e668751c 100644
--- a/drivers/watchdog/bfin_wdt.c
+++ b/drivers/watchdog/bfin_wdt.c
@@ -1,9 +1,8 @@
1/* 1/*
2 * Blackfin On-Chip Watchdog Driver 2 * Blackfin On-Chip Watchdog Driver
3 * Supports BF53[123]/BF53[467]/BF54[2489]/BF561
4 * 3 *
5 * Originally based on softdog.c 4 * Originally based on softdog.c
6 * Copyright 2006-2007 Analog Devices Inc. 5 * Copyright 2006-2010 Analog Devices Inc.
7 * Copyright 2006-2007 Michele d'Amico 6 * Copyright 2006-2007 Michele d'Amico
8 * Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk> 7 * Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>
9 * 8 *
@@ -137,13 +136,15 @@ static int bfin_wdt_running(void)
137 */ 136 */
138static int bfin_wdt_set_timeout(unsigned long t) 137static int bfin_wdt_set_timeout(unsigned long t)
139{ 138{
140 u32 cnt; 139 u32 cnt, max_t, sclk;
141 unsigned long flags; 140 unsigned long flags;
142 141
143 stampit(); 142 sclk = get_sclk();
143 max_t = -1 / sclk;
144 cnt = t * sclk;
145 stamp("maxtimeout=%us newtimeout=%lus (cnt=%#x)", max_t, t, cnt);
144 146
145 cnt = t * get_sclk(); 147 if (t > max_t) {
146 if (cnt < get_sclk()) {
147 printk(KERN_WARNING PFX "timeout value is too large\n"); 148 printk(KERN_WARNING PFX "timeout value is too large\n");
148 return -EINVAL; 149 return -EINVAL;
149 } 150 }